public static function saveContent($name, $content, $cacheFor = 0) { if (self::isMysqlMode()) { // mysql cache if (!self::initMySql()) { return false; } else { $md5 = md5($name); $now = gmdate('Y/m/d H:i:s'); if (!@mysql_query("REPLACE INTO `" . self::cacheTableName() . "` (id, cached_on, content) VALUES ('{$md5}', '{$now}', '" . mysql_escape_string($content) . "')", self::$mysqlConnection) && ($error = mysql_error(self::$mysqlConnection))) { clAPI::error("Failed to cache <b>{$md5}</b>. See server error log for details."); error_log("Failed to cache [{$md5}]: {$error}"); return false; } else { return true; } } } else { // file system cache if (!($init = self::initFileSystem($name))) { return false; } else { list($fileName, $cachePath, $pathToFile) = $init; } if (@file_put_contents($pathToFile, $content) === false) { clAPI::error("Failed to save cache file {$pathToFile}."); return false; } else { return true; } } }
function get($path = null, $limit = null, $forceReturnWrapper = false) { if ($path) { clAPI::trace("Searching for <b>"{$path}"</b>"); } if ($path === null) { return $forceReturnWrapper ? $this : $this->__value; } $node = $this; foreach (split('\\/', $path) as $childName) { $index = $attribute = null; if (preg_match('/^@(.*)?$/', $childName, $matches)) { // attribute only $childName = null; $attribute = $matches[1]; clAPI::trace("Searching for attribute named {$attribute}"); } else { if (preg_match('/(.*)\\[(\\d+)\\](@(.*))?$/', $childName, $matches)) { // array request with/out attribute $childName = $matches[1]; $index = (int) $matches[2]; $attribute = isset($matches[4]) ? $matches[4] : null; clAPI::trace("Searching for element <b>{$childName}" . '[' . "{$index}]</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : '')); } else { if (preg_match('/([^@]+)(@(.*))?$/', $childName, $matches)) { // element request with/out attribute $childName = $matches[1]; $attribute = isset($matches[3]) ? $matches[3] : null; clAPI::trace("Searching for element <b>{$childName}</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : '')); } } } if (!$childName && $attribute) { /* if (!isset($node->__attributes[$attribute])) { clAPI::error("<b>$node->__name</b> does not have an attribute named <b>$attribute</b>"); return null; } */ return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null; } if ($childName && is_array($node)) { clAPI::error("You are looking for <b>{$childName}</b> in an array of elements, which isn't possible"); return null; } else { if (!isset($node->__children[$childName])) { clAPI::error("{$childName} is not a child of {$node->__name}"); return null; } else { $node = $node->__children[$childName]; if ($index !== null) { if (!is_array($node)) { clAPI::error("{$node->__name} is not an array of elements or {$index} does not exist"); return null; } else { $node = $node[$index]; } } if ($attribute !== null) { /* this won't work because sometimes feeds just drop the attribute definition... boo. if (!count($node->__attributes)) { clAPI::error("$childName does not have any attributes"); return null; } if (!isset($node->__attributes[$attribute])) { clAPI::error("$node->__name does not have an attribute named $attribute"); return null; } */ return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null; } } } } if (is_object($node)) { if (!count($node->__children) && !$forceReturnWrapper) { return $node->__value; } else { return $node; } } else { if (is_array($node) && is_numeric($limit)) { return array_slice($node, 0, $limit); } else { return $node; } } }