if (!$override_weblog) { piv_error("Weblog doesn't exist", "Selected weblog \"" . htmlspecialchars($Pivot_Vars['w']) . "\" doesn't exist."); } else { $Current_weblog = $override_weblog; } } } else { reset($Weblogs); $Current_weblog = key($Weblogs); } // Display the search results. LoadWeblogLanguage($Weblogs[$Current_weblog]['language']); $db = new db(); $result = "\n<div class='pivot-search-result'>\n"; $result .= search_result(); $result .= "<!-- Search took " . timetaken() . " seconds -->\n"; $result .= "</div>\n"; unset($db->entry); // Set the template for the tags page if (!isset($Pivot_Vars['t']) || empty($Pivot_Vars['t'])) { if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") { $template = $Weblogs[$Current_weblog]['extra_template']; } else { $template = $Weblogs[$Current_weblog]['archive_template']; } } else { $template = $Pivot_Vars['t']; } $template_html = load_template($template); $template_html = replace_subweblogs_templates($template_html, $result); if (!$template_html) {
/** * Prints a line of output to the debug window * * @param string $output */ function debug($output) { global $debug_fp, $debug_last, $Cfg; if ($Cfg['debug'] == 1) { if (!$debug_fp) { open_debug(); } $date = date("Y-m-d H:i:s"); if (function_exists('memory_get_usage')) { $mem = " ( " . memory_get_usage() . " ) "; } else { $mem = ""; } // fix the filename if (function_exists("debug_backtrace")) { $backtrace = debug_backtrace(); $file = basename(dirname($backtrace[0]['file'])) . '/' . basename($backtrace[0]['file']); $line = $backtrace[0]['line']; $function = $backtrace[1]['function']; } // $output = "<span class='timetaken'> -- ".timetaken()."- ".nl2br(htmlspecialchars($line))." -- $mem</span><br />\n". $output; if (function_exists("timetaken")) { $timetaken = timetaken(); } else { $timetaken = 0; } if ($file . $function != $debug_last) { $output = sprintf("<div class='timetaken'>%s - %s -- %s:%s / %s() -- %s </div>%s\n", $date, $timetaken, $file, $line, $function, $mem, $output); $debug_last = $file . $function; } else { $output = sprintf("%s\n", $output); } fwrite($debug_fp, $output); } }
/** * Performs a query. Either pass the query to e executed as a parameter, * * @param string query */ function query($query = "") { global $PIVOTX, $timetaken; // If there's no DB connection yet, set one up if we can. if (!$this->connection()) { return false; } // perhaps use the cached query if ($query == "") { $query = $this->cached_query; } // Set the last_query $this->last_query = $query; $now = timeTaken('int'); // execute it. $this->sql_result = @$this->sql_doquery($query, $this->sql_link); // If we're profiling, we use the following to get an array of all queries. // We also debug queries that took relatively long to perform. if ($PIVOTX['config']->get('debug')) { $querytimetaken = round(timeTaken('int') - $now, 4); if (timeTaken('int') - $now > 0.4) { debug("\nStart: " . $now . " - timetaken: " . $querytimetaken); debug(htmlentities($query) . "\n\n"); debug_printbacktrace(); } $query = preg_replace("/\\s+/", " ", $query); // If debug is enabled, we add a small comment to the query, so that it's // easier to track where it came from if (function_exists('debug_backtrace')) { $trace = debug_backtrace(); $comment = sprintf(" -- %s - %s():%s ", basename($trace[0]['file']), $trace[1]['function'], $trace[0]['line']); $query .= $comment; } //echo "<pre>\n"; print_r($query); echo "</pre>"; $GLOBALS['query_log'][] = $query . " -- {$querytimetaken} sec. "; } if ($this->sql_result === false) { // If an error occured, we output the error. $this->error('', $this->last_query, $this->sql_errno($this->sql_link)); $this->num_affected_rows = 0; return false; } else { // Count the num of results, and raise the total query count. $timetaken['query_count']++; $timetaken['sql'] += timetaken('int') - $now; $this->num_affected_rows = $this->affected_rows(); return true; } }
/** * Indexes entries in the Pivot database and returns true * if there are more entries to index. * * @param int $start Code for first entry to index * @param int $stop Code for last entry to index * @param int $time Indexing time. * @return boolean */ function start_index($start, $stop, $time) { $db = new db(); $entries = $db->db_lowlevel->date_index; $count = 0; // 2004/10/17 =*=*= JM - doing these in loop will slow things $date = date('Y-m-d-H-i'); $cats = cfg_cat_nosearchindex(); debug("index excludes cats: " . implode(',', $cats)); foreach ($entries as $key => $value) { if ($count++ < $start) { continue; } if ($count > $stop) { break; } // 2004/10/17 =*=*= JM - New searchIndex tests... $entry = $db->read_entry($key); // rules: index if all are true: // - ( status == 'publish' )or(( status == 'timed')&&( publish_date <= date )) // - at least one category is not in exclusion array // check status and date if ('publish' == $entry['status'] || 'timed' == $entry['status'] && $entry['publish_date'] <= $date) { // categories... if (can_search_cats($cats, $entry['category'])) { if ($count % 50 == 0) { printf("%1.2f sec: Processed %d entries.." . "<br />\n", timetaken('int') + $time, $count); flush(); } strip_words($entry); } } } echo "<br /><br />"; // decide if we need to do some more. if (count($entries) > $stop) { return TRUE; } else { return FALSE; } }
/** * The screen that's shown when we rebuild the search index. * */ function build_search() { global $Cfg, $filtered_words, $Pivot_Vars; PageHeader(lang('adminbar', 'buildsearchindex'), 1); PageAnkeiler(lang('adminbar', 'buildsearchindex') . ' » ' . lang('adminbar', 'buildsearchindex_title')); /* JM - Bob said was 300, and was lowered to 200 because of a user with large entries going over PHP's 8Mb variables limit... wow! Is there a more elegant/flexible solution? he asks. */ // initialise the threshold.. Initially it's set to 10 * the rebuild_threshold, // roughly assuming we index 10 entries per second. if (isset($Cfg['rebuild_threshold']) && $Cfg['rebuild_threshold'] > 4) { $chunksize = 10 * $Cfg['rebuild_threshold']; } else { $chunksize = 280; } @set_time_limit(0); echo "<p><strong>" . lang('adminbar', 'buildsearchindex_start') . "</strong><br /><br />\n"; flush(); makedir("db/search"); include_once "modules/module_search.php"; $start = isset($Pivot_Vars['start']) ? $Pivot_Vars['start'] : 0; $stop = $start + $chunksize; $time = isset($Pivot_Vars['time']) ? $Pivot_Vars['time'] : 0; if ($start == 0) { clear_index(); } $continue = start_index($start, $stop, $time); write_index(FALSE); $time = isset($Pivot_Vars['time']) ? $Pivot_Vars['time'] : 0; $time += timetaken('int'); if ($continue) { $myurl = sprintf("index.php?session=%s&menu=admin&func=admin&do=build_search&start=%s&time=%s", $Pivot_Vars['session'], $stop, $time); printf('<script> self.location = "%s"; </script>', $myurl); //printf('<a href="%s">%s</a>',$myurl,$myurl); } else { echo "<br /><br />\n\n<p><b>" . str_replace("%num%", $time, lang('adminbar', 'buildindex_finished')) . "</b><br /><br /></p>\n"; } // stuff stops here.. PageFooter(); }
/** * Screen that's shown when rebuilding all pages. */ function regen() { global $Cfg, $db, $Weblogs, $Pivot_Vars, $VerboseGenerate, $Allow_RSS, $totalfiles, $done_archives, $archive_array_next, $archive_array_prev, $Archive_array; PageHeader(lang('adminbar', 'regen_title'), 1); PageAnkeiler(lang('userbar', 'admin') . ' » ' . lang('adminbar', 'regen_title')); // initialise the threshold.. if (isset($Cfg['rebuild_threshold']) && $Cfg['rebuild_threshold'] > 4) { $threshold = $Cfg['rebuild_threshold']; } else { $threshold = 28; } $db = new db(); // also force the archive index file to be updated @unlink('db/ser-archives.php'); // Make a new archive array. $Archive_array = make_archive_array(); // ugly hack, to get a big slice of mem back.. $entries_arr = $db->getcodes_range("0000-00-00-00-00", "2010-01-01-00-00", "", "", FALSE); $totalfiles = 0; $count = 0; if (isset($Pivot_Vars['count'])) { $count = $Pivot_Vars['count']; $totalfiles = $Pivot_Vars['totalfiles']; reset($entries_arr); do { next($entries_arr); $key = key($entries_arr); //echo "(k $key)"; } while ($key < $Pivot_Vars['count']); } do { $key = key($entries_arr); $loopentry = current($entries_arr); // Generate only archive pages and static entry pages, not // frontpage or RSS. generate_pages($loopentry, TRUE, FALSE, TRUE, FALSE, FALSE); $count++; if ($count % 10 == 0) { printf("%1.2f sec: Processed %d entries.." . "<br />\n", timetaken('int'), $count); flush(); } // server friendly generate all.. if (timetaken("int") > $threshold) { $myurl = sprintf("index.php?session=%s&menu=admin&func=admin&do=regen&count=%s&totalfiles=%s", $Pivot_Vars['session'], $count, $totalfiles); printf('<script> self.location = "%s"; </script>', $myurl); die; } } while (next($entries_arr)); printf("<br />A total of <b>%s</b> entries have been processed, and <b>%s</b> files have been created" . "<br />\n", $count, $totalfiles); // Generate frontpages and feeds. echo "<p>" . lang('adminbar', 'buildfrontpage_title') . "</p>"; $VerboseGenerate = true; $Allow_RSS = true; foreach ($Weblogs as $name => $weblog) { generate_frontpage($name); } echo "<p>" . lang('general', 'done') . "</p>"; PageFooter(); }
/** * executes & returns or displays the template results * * @param string $resource_name * @param string $cache_id * @param string $compile_id * @param boolean $display */ function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) { global $timetaken; $timenow = timetaken('int'); static $_cache_info = array(); $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) ? $this->error_reporting : error_reporting() & ~E_NOTICE); if (!$this->debugging && $this->debugging_ctrl == 'URL') { $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; if (@strstr($_query_string, $this->_smarty_debug_id)) { if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { // enable debugging for this browser session @setcookie('SMARTY_DEBUG', true); $this->debugging = true; } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { // disable debugging for this browser session @setcookie('SMARTY_DEBUG', false); $this->debugging = false; } else { // enable debugging for this page $this->debugging = true; } } else { $this->debugging = (bool) ($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); } } if ($this->debugging) { // capture time for debugging info $_params = array(); require_once SMARTY_CORE_DIR . 'core.get_microtime.php'; $_debug_start_time = smarty_core_get_microtime($_params, $this); $this->_smarty_debug_info[] = array('type' => 'template', 'filename' => $resource_name, 'depth' => 0); $_included_tpls_idx = count($this->_smarty_debug_info) - 1; } if (!isset($compile_id)) { $compile_id = $this->compile_id; } $this->_compile_id = $compile_id; $this->_inclusion_depth = 0; if ($this->caching) { // save old cache_info, initialize cache_info array_push($_cache_info, $this->_cache_info); $this->_cache_info = array(); $_params = array('tpl_file' => $resource_name, 'cache_id' => $cache_id, 'compile_id' => $compile_id, 'results' => null); require_once SMARTY_CORE_DIR . 'core.read_cache_file.php'; if (smarty_core_read_cache_file($_params, $this)) { $_smarty_results = $_params['results']; if (!empty($this->_cache_info['insert_tags'])) { $_params = array('plugins' => $this->_cache_info['insert_tags']); require_once SMARTY_CORE_DIR . 'core.load_plugins.php'; smarty_core_load_plugins($_params, $this); $_params = array('results' => $_smarty_results); require_once SMARTY_CORE_DIR . 'core.process_cached_inserts.php'; $_smarty_results = smarty_core_process_cached_inserts($_params, $this); } if (!empty($this->_cache_info['cache_serials'])) { $_params = array('results' => $_smarty_results); require_once SMARTY_CORE_DIR . 'core.process_compiled_include.php'; $_smarty_results = smarty_core_process_compiled_include($_params, $this); } if ($display) { if ($this->debugging) { // capture time for debugging info $_params = array(); require_once SMARTY_CORE_DIR . 'core.get_microtime.php'; $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; require_once SMARTY_CORE_DIR . 'core.display_debug_console.php'; $_smarty_results .= smarty_core_display_debug_console($_params, $this); } if ($this->cache_modified_check) { $_server_vars = $this->request_use_auto_globals ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']) . ' GMT'; if (@count($this->_cache_info['insert_tags']) == 0 && !$this->_cache_serials && $_gmt_mtime == $_last_modified_date) { if (php_sapi_name() == 'cgi') { header('Status: 304 Not Modified'); } else { header('HTTP/1.1 304 Not Modified'); } } else { header('Last-Modified: ' . $_gmt_mtime); echo $_smarty_results; } } else { echo $_smarty_results; } error_reporting($_smarty_old_error_level); // restore initial cache_info $this->_cache_info = array_pop($_cache_info); return true; } else { error_reporting($_smarty_old_error_level); // restore initial cache_info $this->_cache_info = array_pop($_cache_info); return $_smarty_results; } } else { $this->_cache_info['template'][$resource_name] = true; if ($this->cache_modified_check && $display) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); } } } // load filters that are marked as autoload if (count($this->autoload_filters)) { foreach ($this->autoload_filters as $_filter_type => $_filters) { foreach ($_filters as $_filter) { $this->load_filter($_filter_type, $_filter); } } } $_smarty_compile_path = $this->_get_compile_path($resource_name); // if we just need to display the results, don't perform output // buffering - for speed $_cache_including = $this->_cache_including; $this->_cache_including = false; if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { if ($this->_is_compiled($resource_name, $_smarty_compile_path) || $this->_compile_resource($resource_name, $_smarty_compile_path)) { include $_smarty_compile_path; } } else { ob_start(); if ($this->_is_compiled($resource_name, $_smarty_compile_path) || $this->_compile_resource($resource_name, $_smarty_compile_path)) { include $_smarty_compile_path; } $_smarty_results = ob_get_contents(); ob_end_clean(); foreach ((array) $this->_plugins['outputfilter'] as $_output_filter) { $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); } } if ($this->caching) { $_params = array('tpl_file' => $resource_name, 'cache_id' => $cache_id, 'compile_id' => $compile_id, 'results' => $_smarty_results); require_once SMARTY_CORE_DIR . 'core.write_cache_file.php'; smarty_core_write_cache_file($_params, $this); require_once SMARTY_CORE_DIR . 'core.process_cached_inserts.php'; $_smarty_results = smarty_core_process_cached_inserts($_params, $this); if ($this->_cache_serials) { // strip nocache-tags from output $_smarty_results = preg_replace('!(\\{/?nocache\\:[0-9a-f]{32}#\\d+\\})!s', '', $_smarty_results); } // restore initial cache_info $this->_cache_info = array_pop($_cache_info); } $this->_cache_including = $_cache_including; if ($display) { if (isset($_smarty_results)) { echo $_smarty_results; } if ($this->debugging) { // capture time for debugging info $_params = array(); require_once SMARTY_CORE_DIR . 'core.get_microtime.php'; $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; require_once SMARTY_CORE_DIR . 'core.display_debug_console.php'; echo smarty_core_display_debug_console($_params, $this); } error_reporting($_smarty_old_error_level); // Added for PivotX: keeping track of time. $timetaken['templates'] += timetaken('int') - $timenow; $timetaken['template_count']++; return; } else { error_reporting($_smarty_old_error_level); // Added for PivotX: keeping track of time. $timetaken['templates'] += timetaken('int') - $timenow; $timetaken['template_count']++; if (isset($_smarty_results)) { return $_smarty_results; } } }
/** * Stops the timer. * * @param string $label The label/id for the stoping timer. */ function stop_timer($label) { global $timer_running_array, $timer_stopped_array, $timer_stack, $stopped_count; $stopped_count[] = $label; if (!isset($timer_stopped_array[$label])) { $timer_stopped_array[$label] = 0; } if (isset($timer_running_array[$label])) { //debug("stop $label:" . ( timetaken('int') - $timer_running_array[$label])); $timer_stopped_array[$label] += timetaken('int') - $timer_running_array[$label]; unset($timer_running_array[$label]); array_pop($timer_stack); $continue = end($timer_stack); //debug("continue: ". $continue); $timer_running_array[$continue] = timetaken('int'); } }
function PageFooter() { echo "</div>\n"; if (function_exists('memory_get_usage')) { echo "<div style='color:#FFF;' class='main'>" . timetaken() . " - " . memory_get_usage() . "</div>\n"; } else { echo "<div style='color:#FFF;' class='main'>" . timetaken() . "</div>\n"; } echo "</body>\n</html>\n"; //exit; }