diff -r 5e1f1e916419 -r 98bbc533541c punbb/include/cache.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/punbb/include/cache.php Sun Apr 06 00:28:50 2008 -0400 @@ -0,0 +1,346 @@ + 'c.*', + 'FROM' => 'config AS c' + ); + + ($hook = get_hook('ch_qr_get_config')) ? eval($hook) : null; + $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__); + + $output = array(); + while ($cur_config_item = $pun_db->fetch_row($result)) + $output[$cur_config_item[0]] = $cur_config_item[1]; + + // Output config as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_config.php', 'wb'); + if (!$fh) + error('Unable to write configuration cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +} + + +// +// Generate the bans cache PHP script +// +function generate_bans_cache() +{ + global $pun_db; + + // Get the ban list from the DB + $query = array( + 'SELECT' => 'b.*, u.username AS ban_creator_username', + 'FROM' => 'bans AS b', + 'JOINS' => array( + array( + 'LEFT JOIN' => 'users AS u', + 'ON' => 'u.id=b.ban_creator' + ) + ), + 'ORDER BY' => 'b.id' + ); + + ($hook = get_hook('ch_qr_get_bans')) ? eval($hook) : null; + $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__); + + $output = array(); + while ($cur_ban = $pun_db->fetch_assoc($result)) + $output[] = $cur_ban; + + // Output ban list as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_bans.php', 'wb'); + if (!$fh) + error('Unable to write bans cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +} + + +// +// Generate the ranks cache PHP script +// +function generate_ranks_cache() +{ + global $pun_db; + + // Get the rank list from the DB + $query = array( + 'SELECT' => 'r.*', + 'FROM' => 'ranks AS r', + 'ORDER BY' => 'r.min_posts' + ); + + ($hook = get_hook('ch_qr_get_ranks')) ? eval($hook) : null; + $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__); + + $output = array(); + while ($cur_rank = $pun_db->fetch_assoc($result)) + $output[] = $cur_rank; + + // Output ranks list as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_ranks.php', 'wb'); + if (!$fh) + error('Unable to write ranks cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +} + + +// +// Generate the censor cache PHP script +// +function generate_censors_cache() +{ + global $pun_db; + + // Get the censor list from the DB + $query = array( + 'SELECT' => 'c.*', + 'FROM' => 'censoring AS c', + 'ORDER BY' => 'c.id' + ); + + ($hook = get_hook('ch_qr_get_censored_words')) ? eval($hook) : null; + $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__); + + $output = array(); + while ($cur_censor = $pun_db->fetch_assoc($result)) + $output[] = $cur_censor; + + // Output censors list as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_censors.php', 'wb'); + if (!$fh) + error('Unable to write censor cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +} + + +// +// Generate quickjump cache PHP scripts +// +function generate_quickjump_cache($group_id = false) +{ + global $pun_db, $lang_common, $pun_url, $pun_config, $pun_user, $base_url; + + // If a group_id was supplied, we generate the quickjump cache for that group only + if ($group_id !== false) + $groups[0] = $group_id; + else + { + // A group_id was not supplied, so we generate the quickjump cache for all groups + $query = array( + 'SELECT' => 'g.g_id', + 'FROM' => 'groups AS g' + ); + + ($hook = get_hook('ch_qr_get_groups')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $num_groups = $pun_db->num_rows($result); + + for ($i = 0; $i < $num_groups; ++$i) + $groups[] = $pun_db->result($result, $i); + } + + // Loop through the groups in $groups and output the cache for each of them + while (list(, $group_id) = @each($groups)) + { + // Output quickjump as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_quickjump_'.$group_id.'.php', 'wb'); + if (!$fh) + error('Unable to write quickjump cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + $output = ''; + $output .= "\t".'
'."\n\t\t".'
'."\n\t\t\t".''.$lang_common['Quick jump legend'].''."\n\t\t\t".'
'."\n\t\t\t".''."\n\t\t\t".''."\n\t\t".'
'."\n\t".'
'."\n"; + + if ($forum_count < 2) + $output = ' 'eh.id, eh.code, eh.extension_id', + 'FROM' => 'extension_hooks AS eh', + 'JOINS' => array( + array( + 'INNER JOIN' => 'extensions AS e', + 'ON' => 'e.id=eh.extension_id' + ) + ), + 'WHERE' => 'e.disabled=0', + 'ORDER BY' => 'eh.installed' + ); + + ($hook = get_hook('ch_qr_get_hooks')) ? eval($hook) : null; + $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__); + + $output = array(); + while ($cur_hook = $pun_db->fetch_assoc($result)) + { + $ext_info = '$ext_info = array('."\n". + '\'id\' => \''.$cur_hook['extension_id'].'\','."\n". + '\'path\' => PUN_ROOT.\'extensions/'.$cur_hook['extension_id'].'\','."\n". + '\'url\' => $base_url.\'/extensions/'.$cur_hook['extension_id'].'\');'; + $output[$cur_hook['id']][] = $ext_info."\n\n".$cur_hook['code']."\n"; + } + + // Output hooks as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_hooks.php', 'wb'); + if (!$fh) + error('Unable to write hooks cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +} + + +// +// Generate the updates cache PHP script +// +function generate_updates_cache() +{ + global $pun_db, $pun_config; + + // Get a list of installed hotfix extensions + $query = array( + 'SELECT' => 'e.id', + 'FROM' => 'extensions AS e', + 'WHERE' => 'e.id LIKE \'hotfix_%\'' + ); + + ($hook = get_hook('ch_qr_get_hotfixes')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $num_hotfixes = $pun_db->num_rows($result); + + $hotfixes = array(); + for ($i = 0; $i < $num_hotfixes; ++$i) + $hotfixes[] = urlencode($pun_db->result($result, $i)); + + // Contact the punbb.org updates service + $result = get_remote_file('http://punbb.org/update/?type=xml&version='.urlencode($pun_config['o_cur_version']).'&hotfixes='.implode(',', $hotfixes), 8); + + // Make sure we got everything we need + if ($result != null && strpos($result['content'], '') !== false) + { + require PUN_ROOT.'/include/xml.php'; + + $output = xml_to_array($result['content']); + $output = current($output); + $output['cached'] = time(); + $output['fail'] = false; + } + else // If the update check failed, set the fail flag + $output = array('cached' => time(), 'fail' => true); + + // This hook could potentially (and responsibly) be used by an extension to do its own little update check + ($hook = get_hook('ch_generate_updates_cache_write')) ? eval($hook) : null; + + // Output update status as PHP code + $fh = @fopen(PUN_CACHE_DIR.'cache_updates.php', 'wb'); + if (!$fh) + error('Unable to write updates cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); + + fwrite($fh, ''); + + fclose($fh); +}