function _global_Load() { $ret = cache_Fetch(_SH_GLOBAL_CACHE_KEY); if ($ret === null) { // Fetch the newest version of every key // $ret = db_QueryFetchPair("SELECT `key`,`value` FROM " . SH_TABLE_PREFIX . SH_TABLE_GLOBAL . "\n\t\t\tWHERE id IN (\n\t\t\t\tSELECT MAX(id) FROM " . SH_TABLE_PREFIX . SH_TABLE_GLOBAL . " GROUP BY `key`\n\t\t\t);"); if (!is_array($ret)) { return []; } // Convert types of the values of certain keys found in globals // foreach ($ret as $key => &$value) { if (strcmp($key, "active") === 0) { $value = intval($value); continue; } else { if (strpos($key, "-active") !== false) { $value = intval($value); continue; } else { if (strpos($key, "SH_TABLE_") === 0) { $value = intval($value); continue; } } } } if ($ret) { cache_Store(_SH_GLOBAL_CACHE_KEY, $ret, _SH_GLOBAL_CACHE_TTL); } else { $ret = []; } } return $ret; }
function _config_Load() { $ret = cache_Fetch(_CONFIG_CACHE_KEY); if ($ret === null) { $ret = db_QueryFetchPair("SELECT `key`,`value` FROM " . CMW_TABLE_CONFIG . "\n\t\t\tWHERE id IN (\n\t\t\t\tSELECT MAX(id) FROM " . CMW_TABLE_CONFIG . " GROUP BY `key`\n\t\t\t);"); cache_Store(_CONFIG_CACHE_KEY, $ret, _CONFIG_CACHE_TTL); } return $ret; }
function legacy_GetUser($id) { $ret = cache_Fetch(_LEGACY_USER_CACHE_KEY . $id); if ($ret === null) { $ret = db_QueryFetchFirst("SELECT id," . MYSQL_ISO_FORMAT('timestamp') . ",hash\n\t\t\tFROM " . CMW_TABLE_LEGACY_USER . " WHERE id=? LIMIT 1;", $id); cache_Store(_LEGACY_USER_CACHE_KEY . $id, $ret, _LEGACY_USER_CACHE_TTL); } return $ret; }
function GetEventNodes() { $cache_key = CACHE_KEY_PREFIX . "GetEventNodes"; $ret = cache_Fetch($cache_key); if (!isset($ret)) { $ret = node_GetIdByType(SH_NODE_TYPE_EVENT); cache_Store($cache_key, $ret, CACHE_TTL); } return $ret; }
function _user_CheckSession() { global $USER_ID; if (isset($_COOKIE['SID'])) { $user = user_DecodeSIDToken($_COOKIE['SID']); $key = user_EncodeSIDKey($user['id'], $user['unique']); $value = cache_Fetch($key); if ($value === $user['hash']) { //cache_Touch($key,60*60*24*7); // One week // $USER_ID = intval($user['id']); // TODO: Regenerate hash if it's been a few hours } } }
$change_output = $jpeg || $png; // If we were given an operation // if ($change_size || $change_output) { $docroot = $_SERVER['DOCUMENT_ROOT']; $filename = $docroot . $base . $image; // TODO: add "p" character for percentages // // TODO: strip non-ascii characters from $image // $cache_key = "img\$" . $image . ($out_width ? "\$w" . $out_width : "") . ($out_height ? "\$h" . $out_height : "") . ($crop ? "\$crop" : "") . ($jpeg ? "\$jpeg" : "") . ($png ? "\$png" : "") . ""; // For compatibility with Memcached, keys must be: // - no more than to 250 characters // - not null (0x0) // - not space or tab (0x20,0x09) // - not newline or carriage-return (0x0a,0x0d) // - UTF-8 symbols are ok (but I want to avoid them) // If cached, output data // $cached = cache_Fetch($cache_key); if ($cached) { header($cached['header']); header("X-Cache-Key: " . $cache_key); echo $cached['data']; die; } // Otherwise, we have to generate the file. Check if it exists first. // if (file_exists($filename)) { // Fetch File Info // $info = getimagesize($filename); $in_width = $info[0]; // ['width'] is a string, but the index is not $in_height = $info[1]; // ['height'] is a string, but the index is not // If one of the dimensions is zero //
function node_GetPublishedNodeIdsByTypes($types, $limit = 50, $offset = 0) { // Sort the types, to make sure we get a consistent key name // if (is_array($types)) { sort($types, SORT_STRING); } else { $types = [$types]; } $cache_key = "published-ids\$" . $offset . "\$" . $limit . "\$" . implode("\$", $types); // Fetch from cache // $cached = cache_Fetch($cache_key); if ($cached) { return $cached; } // Fetch from database // global $NODE_SCHEMA; db_Connect(); $items = db_FetchSingle("SELECT `id` FROM `" . CMW_TABLE_NODE . "` WHERE " . ("`time_published` != " . "'0000-00-00 00:00:00'" . " AND ") . (is_array($types) ? "`type` in (\"" . implode("\",\"", $types) . "\")" : "`type`=" . "\"post\"") . " ORDER BY `time_published` DESC" . (" LIMIT " . $limit . " OFFSET " . $offset) . ";", $NODE_SCHEMA); // Cache it // cache_Store($cache_key, $items, CACHE_TTL_PUBLISHED_IDS); return $items; }
function theme_GetFinalVotingList($node) { $ret = cache_Fetch(_THEME_CACHE_KEY . "FINAL_VOTE_LIST"); if ($ret === null) { $ret = db_DoFetch("SELECT id,theme FROM " . CMW_TABLE_THEME_FINAL . " \n\t\t\tWHERE node=?\n\t\t\tORDER BY score DESC,id ASC", $node); cache_Store(_THEME_CACHE_KEY . "FINAL_VOTE_LIST", $ret, _THEME_CACHE_TTL); } return $ret; }
function theme_GetHistory() { $ret = cache_Fetch(_THEME_CACHE_KEY . "THEME_HISTORY"); if ($ret === null) { $ret = db_QueryFetch("SELECT node,shorthand,name,theme FROM " . CMW_TABLE_THEME_HISTORY); if (is_array($ret)) { cache_Store(_THEME_CACHE_KEY . "THEME_HISTORY", $ret, _THEME_CACHE_TTL); } else { return null; } } return $ret; }