results = self::$instance->parse_ini_file(Ide::CONFIGURE_DIR.DS.self::$instance->filename); } return self::$instance; } public function get_value($section, $key) { if(!($this->loaded)) { $this->parse_ini_file(Ide::CONFIGURE_DIR.DS.$this->filename); } if(isset($this->results[$section])) { $sectionValues = $this->results[$section]; if(is_array($sectionValues)) { if(isset($sectionValues[$key])) { if (strtolower($sectionValues[$key]) == 'true') { return true; } if (strtolower($sectionValues[$key]) == 'false') { return false; } return $sectionValues[$key]; } else { return null; } } else { return $sectionValues; } } else { return null; } } public function set_value($section, $key, $value, $write = true) { if($section != "") { switch ($value){ case true: $this->results[$section][$key] = 'true'; break; case false: $this->results[$section][$key] = 'false'; break; default: $this->results[$section][$key] = $value; break; } } else { switch ($value){ case true: $this->results[$key] = 'true'; break; case false: $this->results[$key] = 'false'; break; default: $this->results[$key] = $value; break; } } if($write == true) { return $this->write_changes(); } return true; } public function write_changes() { $ok = true; $fp = fopen(Ide::CONFIGURE_DIR.DS.$this->filename,"wb"); if(!$fp) { $ok = false; } else { if(isset($this->results)) { while(list($section, $values) = each($this->results)) { if(is_array($values)) { $res = fwrite($fp,"[$section]".$this->lineseparator); if($res == -1) { $ok = false; break; } while(list($option, $value) = each($values)) { $res = fwrite($fp,"$option=$value".$this->lineseparator); if($res == -1) { $ok = false; break; } } $res = fwrite($fp,$this->lineseparator); if($res == -1) { $ok = false; break; } if($ok == false) break; } else { $res = fwrite($fp,"$section=$values".$this->lineseparator); if($res == -1) { $ok = false; break; } } } } if(fclose($fp) == false) { $ok = false; } } return $ok; } public function parse_ini_file($filename) { $res = array(); if(file_exists($filename) && is_readable($filename)) { $section = ""; $fd = fopen($filename,"r"); while(!feof($fd)) { $line = trim(fgets($fd,$this->maxlength)); $len = strlen($line); if($len != 0) { if($line[0] != ';') { if(($line[0] == '[') && ($line[$len-1] == ']')) { $section = substr($line,1,$len-2); if(!isset($res[$section])){ $res[$section] = array(); } } $pos = strpos($line,'='); if($pos != false) { $name = substr($line,0,$pos); $value = substr($line,$pos+1,$len-$pos-1); if($section != "") { $res[$section][$name] = $value; } else { $res[$name] = $value; } } } } } fclose($fd); } return $res; } } IdeIni::get_instance(); ?>