[6109] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Theme : Gally/default |
---|
| 4 | Author : Grum |
---|
| 5 | email : grum@piwigo.org |
---|
| 6 | website : http://photos.grum.fr |
---|
| 7 | |
---|
| 8 | << May the Little SpaceFrog be with you ! >> |
---|
| 9 | ------------------------------------------------------------------------------ |
---|
| 10 | |
---|
| 11 | This is the class for read&write the conf files |
---|
| 12 | |
---|
| 13 | --------------------------------------------------------------------------- */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class Conf |
---|
| 17 | { |
---|
| 18 | protected $fileName=""; |
---|
| 19 | protected $values=Array(); |
---|
| 20 | |
---|
| 21 | public function __construct($fileName="") |
---|
| 22 | { |
---|
| 23 | $this->setFileName($fileName); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public function __destruct() |
---|
| 27 | { |
---|
| 28 | unset($this->values); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | public function read($reset=true) |
---|
| 32 | { |
---|
| 33 | if(file_exists($this->fileName) and (filesize($this->fileName)>0)) |
---|
| 34 | { |
---|
| 35 | $fHandle=fopen($this->fileName, "r"); |
---|
| 36 | if($fHandle) |
---|
| 37 | { |
---|
| 38 | $fileContent=fread($fHandle, filesize($this->fileName)); |
---|
| 39 | fclose($fHandle); |
---|
| 40 | |
---|
| 41 | //replace all the '#' char by a ';' char |
---|
| 42 | $fileContent=preg_replace('/^(\s*#)/im', ';', $fileContent); |
---|
| 43 | |
---|
| 44 | $tmpFile=tempnam(dirname(__FILE__), "INI"); |
---|
| 45 | $fHandle=fopen($tmpFile, "w"); |
---|
| 46 | fwrite($fHandle, $fileContent); |
---|
| 47 | fclose($fHandle); |
---|
| 48 | |
---|
| 49 | if($reset) |
---|
| 50 | { |
---|
| 51 | unset($this->values); |
---|
| 52 | $this->values=Array(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | $values=parse_ini_file($tmpFile); |
---|
| 56 | foreach($values as $key => $val) |
---|
| 57 | { |
---|
| 58 | $this->values[$key] = html_entity_decode($val); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | unlink($tmpFile); |
---|
| 62 | |
---|
| 63 | return(true); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | return(false); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public function write() |
---|
| 70 | { |
---|
| 71 | if(!file_exists(dirname($this->fileName))) |
---|
| 72 | { |
---|
| 73 | mkdir(dirname($this->fileName),0777,true); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | $fHandle=fopen($this->fileName, "w"); |
---|
| 77 | if($fHandle) |
---|
| 78 | { |
---|
| 79 | foreach($this->values as $key => $val) |
---|
| 80 | { |
---|
| 81 | if(is_string($val)) |
---|
| 82 | { |
---|
| 83 | fwrite($fHandle, $key.'="'.htmlentities(str_replace(Array("\r\n", "\n", "\r"),"",$val))."\"\n"); |
---|
| 84 | } |
---|
| 85 | elseif(is_bool($val)) |
---|
| 86 | { |
---|
| 87 | fwrite($fHandle, $key.'='.($val?'true':'false')."\n"); |
---|
| 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
| 91 | fwrite($fHandle, $key.'='.$val."\n"); |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | fclose($fHandle); |
---|
| 95 | return(true); |
---|
| 96 | } |
---|
| 97 | return(false); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public function setFileName($fileName) |
---|
| 101 | { |
---|
| 102 | if($fileName!="") |
---|
| 103 | { |
---|
| 104 | $this->fileName=$fileName; |
---|
| 105 | } |
---|
| 106 | return($this->fileName); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | public function getFileName($fileName) |
---|
| 110 | { |
---|
| 111 | return($this->fileName); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | public function getConf() |
---|
| 115 | { |
---|
| 116 | return($this->values); |
---|
| 117 | } |
---|
| 118 | |
---|
[8528] | 119 | public function confExists($key) |
---|
| 120 | { |
---|
| 121 | return(array_key_exists($key, $this->values)); |
---|
| 122 | } |
---|
| 123 | |
---|
[6109] | 124 | public function getConfValue($key) |
---|
| 125 | { |
---|
| 126 | if(array_key_exists($key, $this->values)) |
---|
| 127 | { |
---|
| 128 | return($this->values[$key]); |
---|
| 129 | } |
---|
| 130 | return(""); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | public function setConf($values, $reset=true) |
---|
| 134 | { |
---|
| 135 | if(is_array($values)) |
---|
| 136 | { |
---|
| 137 | if($reset) |
---|
| 138 | { |
---|
| 139 | unset($this->values); |
---|
| 140 | $this->values=Array(); |
---|
| 141 | } |
---|
| 142 | foreach($values as $key => $val) |
---|
| 143 | { |
---|
| 144 | $this->values[$key]=$val; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | return($this->values); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
[8528] | 151 | /** |
---|
| 152 | * function used to initialize config file |
---|
| 153 | * |
---|
| 154 | */ |
---|
| 155 | static public function init($theme) |
---|
| 156 | { |
---|
| 157 | $forcedToDefault=array( |
---|
[17686] | 158 | "imageAutoScroll" => '', |
---|
| 159 | "imageSimulateHighRes" => '', |
---|
[8528] | 160 | "imageCenterMode" => '', |
---|
| 161 | "imageCenterOffset" => '', |
---|
| 162 | "imageCenterTopMin" => '', |
---|
| 163 | "imageCenterTopBorder" => '', |
---|
[17686] | 164 | "imageScrollMinDeadArea" => '', |
---|
[8528] | 165 | "interfaceAnimated" => '', |
---|
[17686] | 166 | "interfaceCanSwitch" => '', |
---|
| 167 | "interfaceHidden" => '', |
---|
| 168 | "interfaceOnImage" => '', |
---|
| 169 | "interfaceTimerDelay" => '', |
---|
[8528] | 170 | "animateDelay" => '', |
---|
| 171 | "marginContainer" => '', |
---|
| 172 | "paddingContainer" => '', |
---|
| 173 | "tabsAnimated" => '', |
---|
| 174 | "tabsHidden" => '', |
---|
| 175 | "tabsVisible" => '', |
---|
| 176 | "tabsPosition" => '', |
---|
[17686] | 177 | "displayBanner" => '', |
---|
| 178 | "alternateBannerContent" => '', |
---|
[8528] | 179 | "commentRows" => '', |
---|
[17686] | 180 | "metaNumCols" => '', |
---|
| 181 | "defaultZoomSize" => '', |
---|
| 182 | "highResClickMode" => '', |
---|
| 183 | "manageTips" => '', |
---|
| 184 | "manageTipsPos" => '', |
---|
| 185 | "tipsSize" => '', |
---|
[8528] | 186 | "menuAnimated" => '', |
---|
| 187 | "menuWidth" => '', |
---|
| 188 | "menuMaxWidth" => '', |
---|
| 189 | "menuMSIEMaxWidth" => '', |
---|
[17686] | 190 | "expandMenu" => '', |
---|
| 191 | "commentAnimated" => '', |
---|
[16016] | 192 | "randomPositionBoxX" => '', |
---|
| 193 | "randomPositionBoxY" => '', |
---|
[17686] | 194 | "displayHighResIcon" => '' |
---|
[8528] | 195 | ); |
---|
| 196 | $gallyDefault = new Conf(); |
---|
| 197 | $gallyDefault->setFileName(PHPWG_ROOT_PATH."themes/gally-default/conf/default.conf"); |
---|
| 198 | $gallyDefault->read(); |
---|
| 199 | |
---|
| 200 | $configDefault = new Conf(); |
---|
| 201 | $configDefault->setFileName(PHPWG_ROOT_PATH."themes/$theme/conf/default.conf"); |
---|
| 202 | $configDefault->read(); |
---|
| 203 | |
---|
| 204 | $configLocal = new Conf(); |
---|
[10937] | 205 | $configLocal->setFileName(PHPWG_ROOT_PATH.PWG_LOCAL_DIR."themes/$theme/conf/local.conf"); |
---|
[8528] | 206 | $configLocal->read(); |
---|
| 207 | |
---|
| 208 | foreach($forcedToDefault as $key => $param) |
---|
| 209 | { |
---|
| 210 | if($gallyDefault->confExists($key)) $forcedToDefault[$key]=$gallyDefault->getConfValue($key); |
---|
| 211 | if($configDefault->confExists($key)) $forcedToDefault[$key]=$configDefault->getConfValue($key); |
---|
| 212 | } |
---|
| 213 | $configLocal->setConf($forcedToDefault, false); |
---|
| 214 | $configLocal->write(); |
---|
| 215 | } |
---|
| 216 | |
---|
[6109] | 217 | } |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | ?> |
---|