'c.*', 'FROM' => 'config AS c' ); ($hook = get_hook('ch_fn_generate_config_cache_qr_get_config')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $output = array(); while ($cur_config_item = $forum_db->fetch_row($result)) $output[$cur_config_item[0]] = $cur_config_item[1]; // Output config as PHP code $fh = @fopen(FORUM_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 $forum_db; $return = ($hook = get_hook('ch_fn_generate_bans_cache_start')) ? eval($hook) : null; if ($return != null) return; // 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_fn_generate_bans_cache_qr_get_bans')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $output = array(); while ($cur_ban = $forum_db->fetch_assoc($result)) $output[] = $cur_ban; // Output ban list as PHP code $fh = @fopen(FORUM_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 $forum_db; $return = ($hook = get_hook('ch_fn_generate_ranks_cache_start')) ? eval($hook) : null; if ($return != null) return; // Get the rank list from the DB $query = array( 'SELECT' => 'r.*', 'FROM' => 'ranks AS r', 'ORDER BY' => 'r.min_posts' ); ($hook = get_hook('ch_fn_generate_ranks_cache_qr_get_ranks')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $output = array(); while ($cur_rank = $forum_db->fetch_assoc($result)) $output[] = $cur_rank; // Output ranks list as PHP code $fh = @fopen(FORUM_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 $forum_db; $return = ($hook = get_hook('ch_fn_generate_censors_cache_start')) ? eval($hook) : null; if ($return != null) return; // Get the censor list from the DB $query = array( 'SELECT' => 'c.*', 'FROM' => 'censoring AS c', 'ORDER BY' => 'c.search_for' ); ($hook = get_hook('ch_fn_generate_censors_cache_qr_get_censored_words')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $output = array(); while ($cur_censor = $forum_db->fetch_assoc($result)) $output[] = $cur_censor; // Output censors list as PHP code $fh = @fopen(FORUM_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 $forum_db, $lang_common, $forum_url, $forum_config, $forum_user, $base_url; $return = ($hook = get_hook('ch_fn_generate_quickjump_cache_start')) ? eval($hook) : null; if ($return != null) return; // 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_fn_generate_quickjump_cache_qr_get_groups')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $num_groups = $forum_db->num_rows($result); for ($i = 0; $i < $num_groups; ++$i) $groups[] = $forum_db->result($result, $i); } // Loop through the groups in $groups and output the cache for each of them foreach ($groups as $group_id) { // Output quickjump as PHP code $fh = @fopen(FORUM_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 .= '
'."\n"; $output .= ''."\n"; if ($forum_count < 2) $output = ' 'eh.id, eh.code, eh.extension_id, e.dependencies', '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.priority, eh.installed' ); ($hook = get_hook('ch_fn_generate_hooks_cache_qr_get_hooks')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $output = array(); while ($cur_hook = $forum_db->fetch_assoc($result)) { $load_ext_info = '$ext_info_stack[] = array('."\n". '\'id\' => \''.$cur_hook['extension_id'].'\','."\n". '\'path\' => FORUM_ROOT.\'extensions/'.$cur_hook['extension_id'].'\','."\n". '\'url\' => $GLOBALS[\'base_url\'].\'/extensions/'.$cur_hook['extension_id'].'\','."\n". '\'dependencies\' => array ('."\n"; $dependencies = explode('|', substr($cur_hook['dependencies'], 1, -1)); foreach ($dependencies as $cur_dependency) { // This happens if there are no dependencies because explode ends up returning an array with one empty element if (empty($cur_dependency)) continue; $load_ext_info .= '\''.$cur_dependency.'\' => array('."\n". '\'id\' => \''.$cur_dependency.'\','."\n". '\'path\' => FORUM_ROOT.\'extensions/'.$cur_dependency.'\','."\n". '\'url\' => $GLOBALS[\'base_url\'].\'/extensions/'.$cur_dependency.'\'),'."\n"; } $load_ext_info .= ')'."\n".');'."\n".'$ext_info = $ext_info_stack[count($ext_info_stack) - 1];'; $unload_ext_info = 'array_pop($ext_info_stack);'."\n".'$ext_info = empty($ext_info_stack) ? array() : $ext_info_stack[count($ext_info_stack) - 1];'; $output[$cur_hook['id']][] = $load_ext_info."\n\n".$cur_hook['code']."\n\n".$unload_ext_info."\n"; } // Output hooks as PHP code $fh = @fopen(FORUM_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 $forum_db, $forum_config; $return = ($hook = get_hook('ch_fn_generate_updates_cache_start')) ? eval($hook) : null; if ($return != null) return; // 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_fn_generate_updates_cache_qr_get_hotfixes')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $num_hotfixes = $forum_db->num_rows($result); $hotfixes = array(); for ($i = 0; $i < $num_hotfixes; ++$i) $hotfixes[] = urlencode($forum_db->result($result, $i)); // Contact the punbb.informer.com updates service $result = get_remote_file('http://punbb.informer.com/update/?type=xml&version='.urlencode($forum_config['o_cur_version']).'&hotfixes='.implode(',', $hotfixes), 8); // Make sure we got everything we need if ($result != null && strpos($result['content'], '') !== false) { if (!defined('FORUM_XML_FUNCTIONS_LOADED')) require FORUM_ROOT.'include/xml.php'; $output = xml_to_array(forum_trim($result['content'])); $output = current($output); if (is_array($output['hotfix']) && !is_array(current($output['hotfix']))) $output['hotfix'] = array($output['hotfix']); $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_fn_generate_updates_cache_write')) ? eval($hook) : null; // Output update status as PHP code $fh = @fopen(FORUM_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); } function generate_ext_versions_cache($inst_exts, $repository_urls, $repository_url_by_extension) { $forum_ext_last_versions = array(); $forum_ext_repos = array(); foreach ( array_unique( array_merge($repository_urls, $repository_url_by_extension) ) as $url) { //Get repository timestamp $remote_file = get_remote_file( $url.'/timestamp', 2); $repository_timestamp = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']); unset($remote_file); if (!is_numeric($repository_timestamp)) continue; if (!isset( $forum_ext_repos[ $url ][ 'timestamp' ] )) $forum_ext_repos[ $url ][ 'timestamp' ] = $repository_timestamp; if ($forum_ext_repos[ $url ][ 'timestamp' ] <= $repository_timestamp) { foreach ($inst_exts as $ext) { $remote_file = get_remote_file($url.'/'.$ext['id'].'/lastversion', 2); $version = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']); unset($remote_file); if (empty($version) || !preg_match('~^[0-9a-zA-Z\. +-]+$~u', $version)) continue; $forum_ext_repos[ $url ][ 'extension_versions' ][ $ext['id'] ] = $version; //If key with current extension exist in array, compare it with version in rep-ry if (!isset($forum_ext_last_versions[ $ext['id'] ]) || ( version_compare($forum_ext_last_versions[ $ext['id'] ][ 'version' ], $version, '<') ) ) { $forum_ext_last_versions[ $ext['id'] ] = array('version' => $version, 'repo_url' => $url); $remote_file = get_remote_file($url.'/'.$ext['id'].'/lastchanges', 2); $last_changes = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']); unset($remote_file); if ( !empty($last_changes) ) $forum_ext_last_versions[ $ext['id'] ][ 'changes' ] = $last_changes; } } //Write timestamp to cache $forum_ext_repos[ $url ][ 'timestamp' ] = $repository_timestamp; } } if (array_keys($forum_ext_last_versions) != array_keys($inst_exts)) foreach ($inst_exts as $ext) if ( !in_array($ext['id'], array_keys($forum_ext_last_versions)) ) $forum_ext_last_versions[$ext['id']] = array('version' => $ext['version'], 'repo_url' => '', 'changes' => ''); ($hook = get_hook('ch_generate_ext_versions_cache_check_repository')) ? eval($hook) : null; // Output config as PHP code $fh = @fopen(FORUM_CACHE_DIR.'cache_ext_version_notifications.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); } define('FORUM_CACHE_FUNCTIONS_LOADED', 1);