public static function relativePath($from, $to) { $arFrom = explode(DIRECTORY_SEPARATOR, rtrim($from, DIRECTORY_SEPARATOR)); $arTo = explode(DIRECTORY_SEPARATOR, rtrim($to, DIRECTORY_SEPARATOR)); while (count($arFrom) && count($arTo) && $arFrom[0] == $arTo[0]) { array_shift($arFrom); array_shift($arTo); } $p = array(); Logger::Debug(print_r($arFrom, true)); if (count($arFrom) > 0) { $p = array_fill(0, count($arFrom), '..'); } $p = array_merge($p, $arTo); return implode(DIRECTORY_SEPARATOR, $p); }
function Query($querid, $query, $postfields = NULL, $extras = NULL) { if (!empty($query) && preg_match("/^https?:\\/\\//", $query)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($postfields) { # $custom_request="POST /boomsvc30/SimpleTxEmail.asmx HTTP/1.1"; # curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom_request); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); } else { curl_setopt($ch, CURLOPT_HTTPGET, 1); } if ($extras['timeout']) { curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $extras['timeout']); } if ($extras['headers']) { curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array($extras['headers'])); } else { curl_setopt($ch, CURLOPT_HEADER, 0); } #echo "[QUERY]".$query."[QUERY]"; #echo "[POSTFIELDS]".$postfields ."[POSTFIELDS]"; #echo "[HEADERS]".$extras['headers']."[HEADERS]"; Logger::Notice("Remotefile Wrapper requesting URL: {$query}"); if (!empty($postfields)) { Logger::Debug($postfields); } if (!empty($extras['headers'])) { Logger::Debug($extras['headers']); } $ret = curl_exec($ch); if (curl_errno($ch)) { $ret = curl_errno($ch) . "<br />" . curl_error($ch); Logger::Error($ret); } curl_close($ch); } #echo "[RETURN]".($ret)."[RETURN]"; return $ret; }
public static function minify_images() { $path = Cli::addOption("path", WWW_PATH, "Path where to find images"); $norun = Cli::addSwitch("n", "Do not run the scripts, only print files to process"); Cli::enableHelp(); Cli::pinfo("Minify images"); foreach (self::globRecursive($path . "/*.[pP][nN][gG]", GLOB_NOSORT) as $png) { Cli::pinfo(" * {$png}"); $output = ""; $return_var = -1; $cmd = "pngcrush -ow -brute -reduce {$png}"; if ($norun) { Logger::Debug(" > {$cmd}"); } else { exec("{$cmd} 2>& 1", $output, $return_var); if ($return_var != 0) { Cli::perr(implode($output, "\n")); } else { Logger::Debug(implode($output, "\n")); } } } foreach (self::globRecursive($path . "/{*.[jJ][pP][gG], *.[jJ][pP][eE][gG]}", GLOB_BRACE | GLOB_NOSORT) as $jpg) { Cli::pinfo(" * {$jpg}"); $output = ""; $return_var = -1; $cmd = "jpegoptim -s -v -v {$jpg}"; if ($norun) { Logger::Debug(" > {$cmd}"); } else { exec("{$cmd} 2>& 1", $output, $return_var); if ($return_var != 0) { Cli::perr(implode($output, "\n")); } else { Logger::Debug(implode($output, "\n")); } } } }
/** * Opens Connection * Prepares the statment * Binds ParameterCollection on Post * Executes a Query * Closes Connection * Returns true if the multiple queries are executed correctly otherwise false * @param string $query The query string * @param array $params The query params * @return void */ public function ExecuteMultipleNonQuery($query, $params = null) { try { if ($this->Connect()) { $this->Statement = $this->PDO->prepare($query); foreach ($params as $param) { $this->AddParametersCollection($query, $param); $this->Statement->execute(); } $this->Disconnect(); $this->DBResult = true; } else { $this->DBResult = false; } } catch (PDOException $e) { Logger::Database($e); Logger::Debug($query); Logger::Request(); $this->DBResult = false; } catch (Exception $e) { Logger::Database($e); Logger::Debug($query); Logger::Request(); $this->DBResult = false; } }
/** * This method is used to do a select query. * @param string the sql query * @return DataBaseStatement */ public function query($sql) { // execute the SQL statement try { $stmt = $this->db->query($sql); Logger::Debug("Database::query() - {$sql}"); } catch (PDOException $e) { //throw new DataBaseException($e->getMessage(), $e->getCode(), $sql, $bind_vars=array()); throw $e; } return $stmt; }
public function loadFromCache() { $cachekey = "config.{$this->role}.{$this->name}"; $data = DataManager::singleton(); $cachewrapper =& $data->caches["apc"]["default"]; if (($cachedresult = $cachewrapper->get($cachekey)) !== false) { $configobj = unserialize($cachedresult); Logger::Info("Found '{$cachekey}' in apc cache (revision=" . $cacheobj->revision . ")"); $allversions = $this->GetAllRevisions($role); Logger::Debug($allversions); foreach ($cacheobj->heirarchy as $i => $inc) { if ($cacheobj->versions[$inc] < $allversions[$inc]) { Logger::Warn("Revision number for '{$name}' parent '{$inc}' is out of date (old revision=" . $cacheobj->versions[$inc] . " new revision=" . $allversions[$inc] . ")"); $ret = array(); $skipcache = true; for ($j = $i; $j >= 0; $j--) { // Clear cache entries for anything above this one Logger::Info("Delete cache: {$includes[$j]}"); /* // FIXME - need to invalidate instead of deleting $cachewrapper->delete("config.$role.{$includes[$j]}"); $cachewrapper->delete("config.$role.{$includes[$j]}.heirarchy"); $cachewrapper->delete("config.$role.{$includes[$j]}.versions"); */ } } } } }
function AddSource($sourcetype, $cfg) { if (!empty($cfg)) { Profiler::StartTimer("DataManager::Init() - Add source: {$sourcetype}", 3); // Check to see if we have a wrapper for this sourcetype in include/datawrappers/*wrapper_class.php // If it exists, include the code for it and initialize $includefile = "include/datawrappers/" . strtolower($sourcetype) . "wrapper_class.php"; if (file_exists_in_path($includefile)) { include_once $includefile; foreach ($cfg as $sourcename => $sourcecfg) { Profiler::StartTimer(" - {$sourcetype}({$sourcename})", 3); // Server groups get special handling at this level so they can be applied to all types if (!empty($sourcecfg["group"]) && ($group = $this->GetGroup($sourcecfg["group"])) !== NULL) { Logger::Notice("Merged source group '{$sourcecfg['group']}' into {$sourcename}"); $sourcecfg = array_merge_recursive($sourcecfg, $group); } $classname = $sourcetype . "wrapper"; $sourcewrapper = new $classname($sourcename, $sourcecfg, true); if (!empty($sourcecfg["cache"]) && $sourcecfg["cache"] != "none") { if ($cacheobj = array_get($this->caches, $sourcecfg["cache"])) { $sourcewrapper->SetCacheServer($cacheobj, any($sourcecfg["cachepolicy"], true)); } } array_set($this->sources, $sourcetype . "." . $sourcename, $sourcewrapper); $sourcelocation = isset($sourcecfg["host"]) ? $sourcecfg["host"] : $sourcecfg["file"]; Logger::Notice("Added source '{$sourcetype}.{$sourcename}': " . $sourcelocation); Profiler::StopTimer(" - {$sourcetype}({$sourcename})"); } } else { Logger::Debug("Tried to instantiate source '{$sourcetype}', but couldn't find class"); } Profiler::StopTimer("DataManager::Init() - Add source: {$sourcetype}"); } }
public function openWrite() { System::ensureDir(dirname($this->filename_cache)); Logger::Debug("Write cache {$this->filename_cache}"); return fopen($this->filename_cache, "w"); }