/** * Returns a merged name/value array of config elements. * * @return Array Merged name/value array of config elements. */ function getConfig() { $globalConf = $this->_fileFactory->getConfig(); $rootpath = $this->_fileFactory->getRootPath(); // Not cached config if (!$this->_config) { $localConfig = array(); $this->_config = $globalConf; // Get files up the tree $accessFiles = array(); $file =& $this; if ($file->isFile()) { $file =& $file->getParentFile(); } while ($file->exists() && $file->getAbsolutePath() != "/") { $accessFile =& new LocalFileImpl($this->_fileFactory, $file->getAbsolutePath(), $globalConf["filesystem.local.access_file_name"]); if ($accessFile->exists()) { $accessFiles[] = $accessFile; } if (strpos(strtolower(toOSPath($file->getParent())), strtolower(toOSPath($rootpath))) === false) { break; } $file =& $file->getParentFile(); } // Parse and merge $allowoverrideKeys = array(); foreach ($this->_config as $key => $value) { $keyChunks = explode('.', $key); if ($keyChunks[count($keyChunks) - 1] == "allow_override") { foreach (explode(',', $value) as $keySuffix) { $keyChunks[count($keyChunks) - 1] = $keySuffix; $allowoverrideKeys[] = implode('.', $keyChunks); } } } foreach (array_reverse($accessFiles) as $accessFile) { $config = array(); // Parse ini file if ($fp = fopen(toOSPath($accessFile->getAbsolutePath()), "r")) { while (!feof($fp)) { $line = trim(fgets($fp)); // Skip comments if (substr($line, 0, 1) == "#") { continue; } // Split rows if (($pos = strpos($line, "=")) !== FALSE) { $config[substr($line, 0, $pos)] = substr($line, $pos + 1); } } fclose($fp); } // Handle local config values $curDir = $this->isFile() ? $this->getParent() : $this->getAbsolutePath(); if ($accessFile->getParent() == $curDir) { foreach ($config as $key => $value) { if (substr($key, 0, 1) == '_') { $localConfig[substr($key, 1)] = $value; } } } // Parse allow keys and deny keys $denyOverrideKeys = array(); foreach ($config as $key => $value) { $keyChunks = explode('.', $key); $lastChunk = $keyChunks[count($keyChunks) - 1]; if ($lastChunk == "allow_override" || $lastChunk == "deny_override") { foreach (explode(',', $value) as $keySuffix) { $keyChunks[count($keyChunks) - 1] = $keySuffix; $allowDenyKey = implode('.', $keyChunks); if (in_array($allowDenyKey, $allowoverrideKeys)) { if ($lastChunk == "allow_override") { $allowoverrideKeys[] = $allowDenyKey; } else { $denyOverrideKeys[] = $allowDenyKey; } } } } } // Remove the denied keys from the allow list /* foreach ($denyOverrideKeys as $denyKey) { for ($i=0; $i<count($allowoverrideKeys); $i++) { if ($denyKey == $allowoverrideKeys[$i]) unset($allowoverrideKeys[$i]); } }*/ // Add all overriden values foreach ($config as $key => $value) { $validAllKey = false; foreach ($allowoverrideKeys as $allowkey) { if (strpos($allowkey, "*") > 0) { $allowkey = str_replace("*", "", $allowkey); // echo $allowkey . "," . $key . strpos($allowkey, $key) . "<br>"; if (strpos($key, $allowkey) === 0) { $validAllKey = true; break; } } } if ((in_array($key, $allowoverrideKeys) || $validAllKey) && !in_array($key, $denyOverrideKeys)) { if (strpos($value, '${') !== false) { $value = str_replace('${configpath}', $accessFile->getParent(), $value); } $this->_config[$key] = $value; } } } // Variable substitute the values foreach ($this->_config as $key => $value) { if (!is_array($value) && strpos($value, '${') !== false) { if ($this->isFile()) { $path = $this->getAbsolutePath(); } else { $path = $this->getParent(); } $this->_config[$key] = str_replace('${path}', $path, $value); $this->_config[$key] = str_replace('${rootpath}', toUnixPath(getRealPath($this->_config, 'filesystem.rootpath')), $value); } } // Force local config foreach ($localConfig as $key => $value) { $this->_config[$key] = $value; } /* foreach ($this->_config as $key => $value) { if (in_array($key, $allowoverrideKeys)) { // Seems to be a variable if (strpos($value, '${') !== false) { $matches = array(); preg_match_all('/\${(.*)}/i', $value, $matches); var_dump($matches); foreach ($matches as $match) $this->_config[$key] = str_replace('${' . $match . '}', $this->_config[$match], $this->_config[$key]); } } }*/ } return $this->_config; }
function _logMsg($message) { $logFile = toOSPath($this->_logPath . "/" . $this->_logPrefix . ".log"); // Check filesize $size = @filesize($logFile); $roll = false; if ($size > $this->_logMaxSizeBytes) { $roll = true; } // Roll if the size is right if ($roll) { for ($i = $this->_logMaxFiles - 1; $i >= 1; $i--) { $rfile = toOSPath($this->_logPath . "/" . $this->_logPrefix . ".log." . $i); $nfile = toOSPath($this->_logPath . "/" . $this->_logPrefix . ".log." . ($i + 1)); if (file_exists($rfile)) { rename($rfile, $nfile); } } rename($logFile, toOSPath($this->_logPath . "/" . $this->_logPrefix . ".log.1")); // Delete last logfile $delfile = toOSPath($this->_logPath . "/" . $this->_logPrefix . ".log." . ($this->_logMaxFiles + 1)); if (file_exists($delfile)) { unlink($delfile); } } // Append log line if (($fp = fopen($logFile, "a")) != null) { fputs($fp, "[" . date("Y-m-d H:i:s") . "] " . $message . "\r\n"); fflush($fp); fclose($fp); } }
/** * Returns the wwwroot or null string if it was impossible to get. * * @return String wwwroot or null string if it was impossible to get. */ function getWWWRoot($config) { if (isset($config['preview.wwwroot']) && $config['preview.wwwroot']) { return getRealPath($config, 'preview.wwwroot'); } // Check document root if (isset($_SERVER['DOCUMENT_ROOT'])) { return resolvePath($_SERVER['DOCUMENT_ROOT']); } // Try script file if (isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["SCRIPT_FILENAME"])) { $path = str_replace(toUnixPath($_SERVER["SCRIPT_NAME"]), "", toUnixPath($_SERVER["SCRIPT_FILENAME"])); if (is_dir($path)) { return toOSPath($path); } } // If all else fails, try this. if (isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["PATH_TRANSLATED"])) { $path = str_replace(toUnixPath($_SERVER["SCRIPT_NAME"]), "", str_replace("//", "/", toUnixPath($_SERVER["PATH_TRANSLATED"]))); if (is_dir($path)) { return toOSPath($path); } } die("Could not resolve WWWROOT path, please set an absolute path in preview.wwwroot config option."); return null; }