# HG changeset patch # User Dan # Date 1195697028 18000 # Node ID 8acd77a6c19db6d02eba65537bae11918f2bbcd9 # Parent 53ba55d33abb392992e67f6c5c2a52ce79b24e19# Parent ebcc138fe4e62f70b8f7d979bee4db88df70b2d7 Merging in updates and improvements from stable diff -r 53ba55d33abb -r 8acd77a6c19d includes/clientside/css/enano-shared.css --- a/includes/clientside/css/enano-shared.css Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/clientside/css/enano-shared.css Wed Nov 21 21:03:48 2007 -0500 @@ -175,11 +175,19 @@ div.jswindow div.content { padding: 10px; margin: 0; background-color: #FFFFFF; } /* Search results */ +div.search-result, div.search-hibar, div.search-lobar { + font-family: arial, helvetica, sans-serif; + font-size: 8pt; +} div.search-result h3 { font-size: 14pt; margin: 10px 0 0 0; } div.search-result h3 a { color: blue !important; font-weight: normal; padding-bottom: 0; } -div.search-result p { margin: 10px 0 0 0 !important; font-family: arial, helvetica, sans-serif; font-size: 10pt; } -div.search-result span.search-result-info { color: green; } +div.search-result p { margin: 10px 0 0 0 !important; font-family: arial, helvetica, sans-serif; font-size: small; } +div.search-result span.search-result-info { color: #7777CC; } +div.search-result span.search-result-url { color: green; } div.search-result span.search-term, div.search-result span.title-search-term { background-color: #FFFFC0; font-weight: bold; } +div.search-result span.search-result-annotation { font-size: 8pt; } +div.search-hibar { border-top: 1px solid #3366CC; margin-top: 10px; color: #000; background-color: #D5DFF3; padding: 3px; vertical-align: middle; } +div.search-lobar { background-color: #E5EFFF; margin: 0; padding: 5px; } /* * Search box diff -r 53ba55d33abb -r 8acd77a6c19d includes/common.php --- a/includes/common.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/common.php Wed Nov 21 21:03:48 2007 -0500 @@ -158,14 +158,6 @@ // Low level maintenance // -// If the search algorithm backend has been changed, empty out the search cache (the two cache formats are incompatible with each other) -if ( getConfig('last_search_algo') != SEARCH_MODE ) -{ - if ( !$db->sql_query('DELETE FROM '.table_prefix.'search_cache;') ) - $db->_die(); - setConfig('last_search_algo', SEARCH_MODE); -} - // If the AES key size has been changed, bail out and fast if ( !getConfig('aes_key_size') ) { @@ -235,7 +227,6 @@ table_prefix.'groups', table_prefix.'group_members', table_prefix.'acl', - table_prefix.'search_cache', table_prefix.'page_groups', table_prefix.'page_group_members', table_prefix.'tags' diff -r 53ba55d33abb -r 8acd77a6c19d includes/constants.php --- a/includes/constants.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/constants.php Wed Nov 21 21:03:48 2007 -0500 @@ -73,7 +73,6 @@ define('MAX_PMS_PER_BATCH', 7); // The maximum number of users that users can send PMs to in one go; restriction does not apply to users with mod_misc rights define('SEARCH_RESULTS_PER_PAGE', 10); define('MYSQL_MAX_PACKET_SIZE', 1048576); // 1MB; this is the default in MySQL 4.x I think -define('SEARCH_MODE', 'FULLTEXT'); // Can be FULLTEXT or BUILTIN // Sidebar diff -r 53ba55d33abb -r 8acd77a6c19d includes/dbal.php --- a/includes/dbal.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/dbal.php Wed Nov 21 21:03:48 2007 -0500 @@ -142,7 +142,21 @@ if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') ) { dc_here('dbal: oops, looks like Enano isn\'t set up. Constants ENANO_INSTALLED, MIDGET_INSTALLED, and IN_ENANO_INSTALL are all undefined.'); - header('Location: install.php'); + // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects + if ( !defined('scriptPath') ) + { + if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) ) + { + $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']); + } + $sp = dirname($_SERVER['REQUEST_URI']); + if($sp == '/' || $sp == '\\') $sp = ''; + define('scriptPath', $sp); + define('contentPath', "$sp/index.php?title="); + } + $loc = scriptPath . '/install.php'; + // header("Location: $loc"); + redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3); exit; } $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd); diff -r 53ba55d33abb -r 8acd77a6c19d includes/functions.php --- a/includes/functions.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/functions.php Wed Nov 21 21:03:48 2007 -0500 @@ -284,8 +284,15 @@ header('HTTP/1.1 307 Temporary Redirect'); } - $title = $lang->get($title); - $message = $lang->get($message); + if ( !is_object($template) ) + { + $template = new template_nodb(); + $template->load_theme('oxygen', 'bleu', false); + $template->tpl_strings['SITE_NAME'] = 'Enano'; + $template->tpl_strings['SITE_DESC'] = 'This site is experiencing a critical error and cannot load.'; + $template->tpl_strings['COPYRIGHT'] = 'Powered by Enano CMS - © 2007 Dan Fuhry. This program is Free Software; see the GPL file included with this package for details.'; + $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($title); + } $template->add_header(''); $template->add_header(' '); + + if ( get_class($template) == 'template_nodb' ) + $template->init_vars(); $template->tpl_strings['PAGE_NAME'] = $title; $template->header(true); @@ -2325,6 +2335,7 @@ $blk = $template->makeParserText($block); $inner = ''; $cls = 'row2'; + $total = $num_pages * $perpage - $perpage; if ( $start > 0 ) { $url = sprintf($result_url, abs($start - $perpage)); @@ -2407,8 +2418,6 @@ $inner .= $blk->run(); } - $total = $num_pages * $perpage - $perpage; - if ( $this_page < $num_pages ) { // $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; @@ -2431,7 +2440,8 @@ if ( $start < $total ) { - $url = sprintf($result_url, abs($start + $perpage)); + $link_offset = abs($start + $perpage); + $url = htmlspecialchars(sprintf($result_url, strval($link_offset))); $link = "Next »"; $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; $blk->assign_vars(array( @@ -2445,7 +2455,9 @@ $paginator = "\n$begin$inner$end\n"; if ( $total > 1 ) + { $out .= $paginator; + } $cls = 'row2'; diff -r 53ba55d33abb -r 8acd77a6c19d includes/paths.php --- a/includes/paths.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/paths.php Wed Nov 21 21:03:48 2007 -0500 @@ -663,14 +663,14 @@ } /** - * Fetches a MySQL search query to use for Searcher::searchMySQL() + * Generates an SQL query to grab all of the text */ function fetch_page_search_resource() { global $db, $session, $paths, $template, $plugins; // Common objects // sha1('') returns "da39a3ee5e6b4b0d3255bfef95601890afd80709" - $texts = 'SELECT t.page_text,CONCAT(\'ns=\',t.namespace,\';pid=\',t.page_id) FROM '.table_prefix.'page_text AS t + $texts = 'SELECT t.page_text, CONCAT(\'ns=\',t.namespace,\';pid=\',t.page_id) AS page_idstring, t.page_id, t.namespace FROM '.table_prefix.'page_text AS t LEFT JOIN '.table_prefix.'pages AS p ON ( t.page_id=p.urlname AND t.namespace=p.namespace ) WHERE p.namespace=t.namespace @@ -690,9 +690,25 @@ $texts = Array(); $textq = $db->sql_unbuffered_query($this->fetch_page_search_resource()); if(!$textq) $db->_die(''); - while($row = $db->fetchrow_num()) + while($row = $db->fetchrow()) { - $texts[(string)$row[1]] = $row[0]; + if ( isset($this->nslist[$row['namespace']]) ) + { + $idstring = $this->nslist[$row['namespace']] . sanitize_page_id($row['page_id']); + if ( isset($this->pages[$idstring]) ) + { + $page = $this->pages[$idstring]; + } + else + { + $page = array('name' => dirtify_page_id($row['page_id'])); + } + } + else + { + $page = array('name' => dirtify_page_id($row['page_id'])); + } + $texts[(string)$row['page_idstring']] = $row['page_text'] . ' ' . $page['name']; } $search->buildIndex($texts); // echo '
'.print_r($search->index, true).''; @@ -730,10 +746,17 @@ { return $db->get_error(); } + if ( $db->numrows() < 1 ) + return 'E: No rows'; + $idstring = $this->nslist[$namespace] . sanitize_page_id($page_id); + if ( !isset($this->pages[$idstring]) ) + { + return 'E: Can\'t find page metadata'; + } $row = $db->fetchrow(); $db->free_result(); $search = new Searcher(); - $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text'])); + $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text'] . ' ' . $this->pages[$idstring]['name'])); $new_index = $search->index; $keys = array_keys($search->index); @@ -744,20 +767,6 @@ } $keys = "word=0x" . implode ( " OR word=0x", $keys ) . ""; - // Zap the cache - $cache = array_keys($search->index); - if ( count($cache) < 1 ) - { - return false; - } - foreach ( $cache as $key => $_unused ) - { - $cache[$key] = $db->escape( $cache[$key] ); - } - $cache = "query LIKE '%" . implode ( "%' OR query LIKE '%", $cache ) . "%'"; - $sql = 'DELETE FROM '.table_prefix.'search_cache WHERE '.$cache; - $db->sql_query($sql); - $query = $db->sql_query('SELECT word,page_names FROM '.table_prefix.'search_index WHERE '.$keys.';'); while($row = $db->fetchrow()) diff -r 53ba55d33abb -r 8acd77a6c19d includes/search.php --- a/includes/search.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/search.php Wed Nov 21 21:03:48 2007 -0500 @@ -31,15 +31,13 @@ } /** - * Algorithm to actually do the searching. This system usually works pretty fast (tested and developed on a site with 22 pages) but one - * caveat of this algorithm is that it has to load the entire index into memory. It also requires manual parsing of the search query - * which can be quite CPU-intensive. On the flip side this algorithm is extremely flexible and can be adapted for other uses very easily. + * In Enano versions prior to 1.0.2, this class provided a search function that was keyword-based and allowed boolean searches. It was + * cut from Coblynau and replaced with perform_search(), later in this file, because of speed issues. Now mostly deprecated. The only + * thing remaining is the buildIndex function, which is still used by the path manager and the new search framework. * - * Most of the time, this system is disabled. It is only used when MySQL can't or won't allow FULLTEXT indices. - * * @package Enano * @subpackage Page management frontend - * @license GNU General Public License http://enanocms.org/Special:GNU_General_Public_License + * @license GNU General Public License
'.print_r($query, true).''); - foreach($query['trm'] as $q) - { - foreach($this->results as $k => $r) - { - $startplace = 0; - //$this->results[$k] = htmlspecialchars($this->results[$k]); - for($i = 0; $i < strlen($r); $i++) - { - $word = substr($r, $i, strlen($q)); - if($this->convertCase($word) == $this->convertCase($q)) - { - $word = $starttag . $word . $endtag; - $this->results[$k] = substr($r, 0, $i) . $word . substr($r, $i + strlen($q), strlen($r)+999999); - $startplace = $i - 75; - if($startplace < 0) $startplace = 0; - $this->results[$k] = '...'.trim(substr($this->results[$k], $startplace, strlen($word) + 150)).'...'; - continue 2; - } + unset($word_tracking[$i], $scores[$i]); } } } } + // + // STAGE 3: PHRASE SEARCHING + // Use LIKE to find pages with specified phrases. We can do a super-picky single query without another elimination round because + // at this stage we can search the full page_text column instead of relying on a word list. + // + + // We can skip this stage if none of these special terms apply + + $text_col = ( $case_sensitive ) ? 'page_text' : 'lcase(page_text)'; + + if ( count($query_phrase['any']) > 0 || count($query_phrase['req']) > 0 ) + { + + $where_any = array(); + foreach ( $query_phrase['any'] as $term ) + { + $term = escape_string_like($term); + if ( !$case_sensitive ) + $term = strtolower($term); + $where_any[] = $term; + } + + $where_any = ( count($where_any) > 0 ) ? "( $text_col LIKE '%" . implode("%' OR $text_col LIKE '%", $where_any) . "%' )" : ''; + + // Also do required columns, but use AND to ensure that all required terms are included + $where_req = array(); + foreach ( $query_phrase['req'] as $term ) + { + $term = escape_string_like($term); + if ( !$case_sensitive ) + $term = strtolower($term); + $where_req[] = $term; + } + $and_clause = ( $where_any != '' ) ? 'AND ' : ''; + $where_req = ( count($where_req) > 0 ) ? "{$and_clause}$text_col LIKE '%" . implode("%' AND $text_col LIKE '%", $where_req) . "%'" : ''; + + $sql = 'SELECT CONCAT("ns=",namespace,";pid=",page_id) AS id FROM ' . table_prefix . "page_text WHERE $where_any $where_req;"; + if ( !($q = $db->sql_unbuffered_query($sql)) ) + $db->_die('Error is in perform_search(), includes/search.php, query 2. Parsed query dump follows:
(indexable) ' . htmlspecialchars(print_r($query, true)) . '(non-indexable) ' . htmlspecialchars(print_r($query_phrase, true)) . ''); + + if ( $row = $db->fetchrow() ) + { + do + { + $id =& $row['id']; + if ( isset($scores[$id]) ) + { + $scores[$id]++; + } + else + { + $scores[$id] = 1; + } + } + while ( $row = $db->fetchrow() ); + } + $db->free_result(); + } + + // + // STAGE 4 - SELECT PAGE TEXT AND ELIMINATE NOTS + // At this point, we have a complete list of all the possible pages. Now we want to obtain the page text, and within the same query + // eliminate any terms that shouldn't be in there. + // + + // Generate master word list for the highlighter + $word_list = array_values(array_merge($query['any'], $query['req'], $query_phrase['any'], $query_phrase['req'])); + + $text_where = array(); + foreach ( $scores as $page_id => $_ ) + { + $text_where[] = $db->escape($page_id); + } + $text_where = '( CONCAT("ns=",t.namespace,";pid=",t.page_id) = \'' . implode('\' OR CONCAT("ns=",t.namespace,";pid=",t.page_id) = \'', $text_where) . '\' )'; + + if ( count($query['not']) > 0 ) + $text_where .= ' AND'; + + $where_not = array(); + foreach ( $query['not'] as $term ) + { + $term = escape_string_like($term); + if ( !$case_sensitive ) + $term = strtolower($term); + $where_not[] = $term; + } + $where_not = ( count($where_not) > 0 ) ? "$text_col NOT LIKE '%" . implode("%' AND $text_col NOT LIKE '%", $where_not) . "%'" : ''; + + $sql = 'SELECT CONCAT("ns=",t.namespace,";pid=",t.page_id) AS id, t.page_id, t.namespace, CHAR_LENGTH(t.page_text) AS page_length, t.page_text, p.name AS page_name FROM ' . table_prefix . "page_text AS t + LEFT JOIN " . table_prefix . "pages AS p + ON ( p.urlname = t.page_id AND p.namespace = t.namespace ) + WHERE $text_where $where_not;"; + if ( !($q = $db->sql_unbuffered_query($sql)) ) + $db->_die('Error is in perform_search(), includes/search.php, query 3'); + + $page_data = array(); + if ( $row = $db->fetchrow() ) + { + do + { + $row['page_text'] = htmlspecialchars($row['page_text']); + $row['page_name'] = htmlspecialchars($row['page_name']); + + // Highlight results (this is wonderfully automated) + $row['page_text'] = highlight_and_clip_search_result($row['page_text'], $word_list, $case_sensitive); + if ( strlen($row['page_text']) > 250 && !preg_match('/^\.\.\.(.+)\.\.\.$/', $row['page_text']) ) + { + $row['page_text'] = substr($row['page_text'], 0, 150) . '...'; + } + $row['page_name'] = highlight_search_result($row['page_name'], $word_list, $case_sensitive); + + $page_data[$row['id']] = $row; + } + while ( $row = $db->fetchrow() ); + } + $db->free_result(); + + // + // STAGE 5 - SPECIAL PAGE TITLE SEARCH + // Iterate through $paths->pages and check the titles for search terms. Score accordingly. + // + + foreach ( $paths->pages as $page ) + { + if ( $page['namespace'] != 'Special' ) + continue; + $idstring = 'ns=' . $page['namespace'] . ';pid=' . $page['urlname_nons']; + $any = array_merge($query['any'], $query_phrase['any']); + foreach ( $any as $term ) + { + if ( $case_sensitive ) + { + if ( strstr($page['name'], $term) || strstr($page['urlname_nons'], $term) ) + { + ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1; + } + } + else + { + if ( strstr(strtolower($page['name']), strtolower($term)) || strstr(strtolower($page['urlname_nons']), strtolower($term)) ) + { + ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1; + } + } + } + if ( isset($scores[$idstring]) ) + { + $page_data[$idstring] = array( + 'page_name' => $page['name'], + 'page_text' => '', + 'page_id' => $page['urlname_nons'], + 'namespace' => $page['namespace'], + 'score' => $scores[$idstring], + 'page_length' => 1, + 'page_note' => '[Special page]' + ); + } + } + + // + // STAGE 6 - SECOND ELIMINATION ROUND + // Iterate through the list of required terms. If a given page is not found to have the required term, eliminate it + // + + $required = array_merge($query['req'], $query_phrase['req']); + foreach ( $required as $term ) + { + foreach ( $page_data as $id => $page ) + { + if ( ( $page['namespace'] == 'Special' || ( $page['namespace'] != 'Special' && !strstr($page['page_text'], $term) ) ) && !strstr($page['page_id'], $term) && !strstr($page['page_name'], $term) ) + { + unset($page_data[$id]); + } + } + } + + // At this point, all of our normal results are in. However, we can also allow plugins to hook into the system and score their own + // pages and add text, etc. as necessary. + // Plugins are COMPLETELY responsible for using the search terms and handling Boolean logic properly + + $code = $plugins->setHook('search_global_inner'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + + // a marvelous debugging aid :-) + // die('
' . htmlspecialchars(print_r($page_data, true)) . ''); + + // + // STAGE 7 - HIGHLIGHT, TRIM, AND SCORE RESULTS + // We now have the complete results of the search. We need to trim text down to show only portions of the page containing search + // terms, highlight any search terms within the page, and sort the final results array in descending order of score. + // + + // Sort scores array + arsort($scores); + + // Divisor for calculating relevance scores + $divisor = count($query['any']) + count($query_phrase['any']) + count($query['req']) + count($query_phrase['not']); + + foreach ( $scores as $page_id => $score ) + { + if ( !isset($page_data[$page_id]) ) + // It's possible that $scores contains a score for a page that was later eliminated because it contained a disallowed term + continue; + + // Make a copy of the datum, then delete the original (it frees up a LOT of RAM) + $datum = $page_data[$page_id]; + unset($page_data[$page_id]); + + // This is an internal value used for sorting - it's no longer needed. + unset($datum['id']); + + // Calculate score + if ( $score > $divisor ) + $score = $divisor; + $datum['score'] = round($score / $divisor, 2) * 100; + + // Store it in our until-now-unused results array + $results[] = $datum; + } + + // Our work here is done. :-D + return $results; } /** - * Developer-friendly way to do searches. :-) Uses the MySQL FULLTEXT index type. - * @package Enano - * @subpackage Search + * Parses a search query into an associative array. The resultant array will be filled with the following values, each an array: + * any: Search terms that can optionally be present + * req: Search terms that must be present + * not: Search terms that should not be present + * @param string Search query + * @param array Will be filled with parser warnings, such as query too short, words too short, etc. + * @return array */ -class MySQL_Fulltext_Search { - - /** - * Performs a search. - * @param string The search query - * @return resource MySQL result resource - this is an UNBUFFERED query. - */ - - function search($query) +function parse_search_query($query, &$warnings) +{ + $stopwords = get_stopwords(); + $ret = array( + 'any' => array(), + 'req' => array(), + 'not' => array() + ); + $warnings = array(); + $terms = array(); + $in_quote = false; + $start_term = 0; + $just_finished = false; + for ( $i = 0; $i < strlen($query); $i++ ) { - global $db, $session, $paths, $template, $plugins; // Common objects + $chr = $query{$i}; + $prev = ( $i > 0 ) ? $query{ $i - 1 } : ''; + $next = ( ( $i + 1 ) < strlen($query) ) ? $query{ $i + 1 } : ''; - $fulltext_col = 'MATCH(t.page_id,t.namespace,p.name,t.page_text) AGAINST (\'' . $db->escape($query) . '\' IN BOOLEAN MODE)'; - $sql = "SELECT t.page_text,CONCAT('ns=',t.namespace,';pid=',t.page_id) AS page_identifier, $fulltext_col AS score, CHAR_LENGTH(t.page_text) AS length FROM ".table_prefix."page_text AS t - LEFT JOIN ".table_prefix."pages AS p - ON ( p.urlname=t.page_id AND p.namespace=t.namespace) - WHERE $fulltext_col > 0 - AND p.visible=1 - ORDER BY score DESC;"; - $q = $db->sql_unbuffered_query($sql); - if ( !$q ) - $db->_die(); + if ( ( $chr == ' ' && !$in_quote ) || ( $i + 1 == strlen ( $query ) ) ) + { + $len = ( $next == '' ) ? $i + 1 : $i - $start_term; + $word = substr ( $query, $start_term, $len ); + $terms[] = $word; + $start_term = $i + 1; + } - return $q; + elseif ( $chr == '"' && $in_quote && $prev != '\\' ) + { + $word = substr ( $query, $start_term, $i - $start_term + 1 ); + $start_pos = ( $next == ' ' ) ? $i + 2 : $i + 1; + $in_quote = false; + } + + elseif ( $chr == '"' && !$in_quote ) + { + $in_quote = true; + $start_pos = $i; + } + } - function highlight_result($query, $result) + $ticker = 0; + + foreach ( $terms as $element => $__unused ) { - global $db, $session, $paths, $template, $plugins; // Common objects - $search = new Searcher(); - $parsed_query = $search->parseQuery($query); - return $this->highlight_result_inner($query, $result); + $atom =& $terms[$element]; + + $ticker++; + + if ( $ticker == 20 ) + { + $warnings[] = 'Some of your search terms were excluded because searches are limited to 20 terms to prevent excessive server load.'; + break; + } + + if ( substr ( $atom, 0, 2 ) == '+"' && substr ( $atom, ( strlen ( $atom ) - 1 ), 1 ) == '"' ) + { + $word = substr ( $atom, 2, ( strlen( $atom ) - 3 ) ); + if ( strlen ( $word ) < 2 || in_array($word, $stopwords) ) + { + $warnings[] = 'One or more of your search terms was excluded because either it was less than 2 characters in length or is a common word (a stopword) that is typically found on a large number of pages. Examples of stopwords include "the", "this", "which", "with", etc.'; + $ticker--; + continue; + } + if(in_array($word, $ret['req'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['req'][] = $word; + } + elseif ( substr ( $atom, 0, 2 ) == '-"' && substr ( $atom, ( strlen ( $atom ) - 1 ), 1 ) == '"' ) + { + $word = substr ( $atom, 2, ( strlen( $atom ) - 3 ) ); + if ( strlen ( $word ) < 4 ) + { + $warnings[] = 'One or more of your search terms was excluded because terms must be at least 4 characters in length.'; + $ticker--; + continue; + } + if(in_array($word, $ret['not'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['not'][] = $word; + } + elseif ( substr ( $atom, 0, 1 ) == '+' ) + { + $word = substr ( $atom, 1 ); + if ( strlen ( $word ) < 2 || in_array($word, $stopwords) ) + { + $warnings[] = 'One or more of your search terms was excluded because either it was less than 2 characters in length or is a common word (a stopword) that is typically found on a large number of pages. Examples of stopwords include "the", "this", "which", "with", etc.'; + $ticker--; + continue; + } + if(in_array($word, $ret['req'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['req'][] = $word; + } + elseif ( substr ( $atom, 0, 1 ) == '-' ) + { + $word = substr ( $atom, 1 ); + if ( strlen ( $word ) < 2 || in_array($word, $stopwords) ) + { + $warnings[] = 'One or more of your search terms was excluded because either it was less than 2 characters in length or is a common word (a stopword) that is typically found on a large number of pages. Examples of stopwords include "the", "this", "which", "with", etc.'; + $ticker--; + continue; + } + if(in_array($word, $ret['not'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['not'][] = $word; + } + elseif ( substr ( $atom, 0, 1 ) == '"' && substr ( $atom, ( strlen($atom) - 1 ), 1 ) == '"' ) + { + $word = substr ( $atom, 1, ( strlen ( $atom ) - 2 ) ); + if ( strlen ( $word ) < 2 || in_array($word, $stopwords) ) + { + $warnings[] = 'One or more of your search terms was excluded because either it was less than 2 characters in length or is a common word (a stopword) that is typically found on a large number of pages. Examples of stopwords include "the", "this", "which", "with", etc.'; + $ticker--; + continue; + } + if(in_array($word, $ret['any'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['any'][] = $word; + } + else + { + $word = $atom; + if ( strlen ( $word ) < 2 || in_array($word, $stopwords) ) + { + $warnings[] = 'One or more of your search terms was excluded because either it was less than 2 characters in length or is a common word (a stopword) that is typically found on a large number of pages. Examples of stopwords include "the", "this", "which", "with", etc.'; + $ticker--; + continue; + } + if(in_array($word, $ret['any'])) + { + $warnings[] = 'One or more of your search terms was excluded because duplicate terms were encountered.'; + $ticker--; + continue; + } + $ret['any'][] = $word; + } + } + return $ret; +} + +/** + * Escapes a string for use in a LIKE clause. + * @param string + * @return string + */ + +function escape_string_like($string) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + $string = $db->escape($string); + $string = str_replace(array('%', '_'), array('\%', '\_'), $string); + return $string; +} + +/** + * Wraps
'.print_r($query, true).''); - foreach($query['trm'] as $q) + // Boldface searched words + $ptlen = strlen($pt); + for ( $i = 0; $i < $ptlen; $i++ ) { - $startplace = 0; - //$this->results[$k] = htmlspecialchars($this->results[$k]); - for($i = 0; $i < strlen($r); $i++) + $len = strlen($word); + if ( strtolower(substr($pt, $i, $len)) == strtolower($word) ) { - $word = substr($r, $i, strlen($q)); - if($this->convertCase($word) == $this->convertCase($q)) + $chunk1 = substr($pt, 0, $i); + $chunk2 = substr($pt, $i, $len); + $chunk3 = substr($pt, ( $i + $len )); + $pt = $chunk1 . $chunk2 . $chunk3; + $ptlen = strlen($pt); + // Cut off text to 150 chars or so + if ( !$cut_off ) { - $word = $starttag . $word . $endtag; - $result = substr($fulltext, 0, $i) . $word . substr($r, $i + strlen($q), strlen($r)+99999999); - $startplace = $i - 75; - if($startplace < 0) $startplace = 0; - $result = '...'.trim(substr($result, $startplace, strlen($word) + 150)).'...'; - continue 2; + $cut_off = true; + if ( $i - 75 > 0 ) + { + // Navigate backwards until a space character is found + $chunk = substr($pt, 0, ( $i - 75 )); + $final_chunk = $chunk; + for ( $j = strlen($chunk); $j > 0; $j = $j - 1 ) + { + if ( in_array($chunk{$j}, $space_chars) ) + { + $final_chunk = substr($chunk, $j + 1); + break; + } + } + $mid_chunk = substr($pt, ( $i - 75 ), 75); + + $clipped = '...' . $final_chunk . $mid_chunk . $chunk2; + + $chunk = substr($pt, ( $i + strlen($chunk2) + 75 )); + $final_chunk = $chunk; + for ( $j = 0; $j < strlen($chunk); $j++ ) + { + if ( in_array($chunk{$j}, $space_chars) ) + { + $final_chunk = substr($chunk, 0, $j); + break; + } + } + + $end_chunk = substr($pt, ( $i + strlen($chunk2) ), 75 ); + + $clipped .= $end_chunk . $final_chunk . '...'; + + $pt = $clipped; + } + else if ( strlen($pt) > 200 ) + { + $mid_chunk = substr($pt, ( $i - 75 ), 75); + + $clipped = $chunk1 . $chunk2; + + $chunk = substr($pt, ( $i + strlen($chunk2) + 75 )); + $final_chunk = $chunk; + for ( $j = 0; $j < strlen($chunk); $j++ ) + { + if ( in_array($chunk{$j}, $space_chars) ) + { + $final_chunk = substr($chunk, 0, $j); + break; + } + } + + $end_chunk = substr($pt, ( $i + strlen($chunk2) ), 75 ); + + $clipped .= $end_chunk . $final_chunk . '...'; + + $pt = $clipped; + + } + break 2; } } } - return $result; + $cut_off = false; } + return $pt; +} + +/** + * Returns a list of words that shouldn't under most circumstances be indexed for searching. Kudos to MySQL. + * @return array + * @see http://dev.mysql.com/doc/refman/5.0/en/fulltext-stopwords.html + */ + +function get_stopwords() +{ + static $stopwords; + if ( is_array($stopwords) ) + return $stopwords; + $stopwords = array('a\'s', 'able', 'after', 'afterwards', 'again', + 'against', 'ain\'t', 'all', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always', + 'am', 'among', 'amongst', 'an', 'and', 'another', 'any', 'anybody', 'anyhow', 'anyone', 'anything', 'anyway', + 'anyways', 'anywhere', 'apart', 'appear', 'appreciate', 'appropriate', 'are', 'aren\'t', 'around', 'as', 'aside', + 'ask', 'asking', 'associated', 'at', 'available', 'away', 'awfully', 'be', 'became', 'because', 'become', 'becomes', + 'becoming', 'been', 'before', 'beforehand', 'behind', 'being', 'believe', 'below', 'beside', 'besides', 'best', + 'better', 'between', 'beyond', 'both', 'brief', 'but', 'by', 'c\'mon', 'c\'s', 'came', 'can', 'can\'t', 'cannot', + 'cant', 'cause', 'causes', 'certain', 'certainly', 'changes', 'clearly', 'co', 'com', 'come', 'comes', 'concerning', + 'consequently', 'consider', 'considering', 'contain', 'containing', 'contains', 'corresponding', 'could', + 'couldn\'t', 'course', 'despite', 'did', 'didn\'t', 'different', 'do', + 'does', 'doesn\'t', 'doing', 'don\'t', 'done', 'down', 'downwards', 'during', 'each', 'edu', 'eg', 'eight', + 'either', 'else', 'elsewhere', 'enough', 'entirely', 'especially', 'et', 'etc', 'even', 'ever', 'every', + 'everybody', 'everyone', 'everything', 'everywhere', 'ex', 'exactly', 'example', 'except', 'far', 'few', 'fifth', + 'first', 'five', 'followed', 'following', 'follows', 'for', 'former', 'formerly', 'forth', 'four', 'from', + 'further', 'get', 'gets', 'getting', 'given', 'gives', 'go', 'goes', 'going', 'gone', 'got', + 'gotten', 'had', 'hadn\'t', 'happens', 'hardly', 'has', 'hasn\'t', 'have', 'haven\'t', 'having', + 'he', 'he\'s', 'hello', 'help', 'hence', 'her', 'here', 'here\'s', 'hereafter', 'hereby', 'herein', 'hereupon', + 'hers', 'herself', 'hi', 'him', 'himself', 'his', 'hither', 'hopefully', 'how', 'howbeit', 'however', 'i\'d', + 'i\'ll', 'i\'m', 'i\'ve', 'ie', 'if', 'ignored', 'immediate', 'in', 'inasmuch', 'inc', 'indeed', 'indicate', + 'indicated', 'indicates', 'inner', 'insofar', 'instead', 'into', 'inward', 'is', 'isn\'t', 'it', 'it\'d', 'it\'ll', + 'it\'s', 'its', 'itself', 'just', 'keep', 'keeps', 'kept', 'know', 'knows', 'known', 'last', 'lately', 'later', + 'latter', 'latterly', 'least', 'less', 'lest', 'let', 'let\'s', 'like', 'liked', 'likely', 'little', 'look', + 'looking', 'looks', 'ltd', 'mainly', 'many', 'may', 'maybe', 'me', 'mean', 'meanwhile', 'merely', 'might', 'more', + 'moreover', 'most', 'mostly', 'much', 'must', 'my', 'myself', 'name', 'namely', 'nd', 'near', 'nearly', 'necessary', + 'need', 'needs', 'neither', 'never', 'nevertheless', 'new', 'next', 'nine', 'no', 'nobody', 'non', 'none', 'noone', + 'nor', 'normally', 'not', 'nothing', 'novel', 'now', 'nowhere', 'obviously', 'of', 'off', 'often', 'oh', 'ok', + 'okay', 'old', 'on', 'once', 'one', 'ones', 'only', 'onto', 'or', 'other', 'others', 'otherwise', 'ought', 'our', + 'ours', 'ourselves', 'out', 'outside', 'over', 'overall', 'own', 'particular', 'particularly', 'per', 'perhaps', + 'placed', 'please', 'plus', 'possible', 'presumably', 'probably', 'provides', 'que', 'quite', 'qv', 'rather', 'rd', + 're', 'really', 'reasonably', 'regarding', 'regardless', 'regards', 'relatively', 'respectively', 'right', 'said', + 'same', 'saw', 'say', 'saying', 'says', 'second', 'secondly', 'see', 'seeing', 'seem', 'seemed', 'seeming', 'seems', + 'seen', 'self', 'selves', 'sensible', 'sent', 'serious', 'seriously', 'seven', 'several', 'shall', 'she', 'should', + 'shouldn\'t', 'since', 'six', 'so', 'some', 'somebody', 'somehow', 'someone', 'something', 'sometime', 'sometimes', + 'somewhat', 'somewhere', 'soon', 'sorry', 'specified', 'specify', 'specifying', 'still', 'sub', 'such', 'sup', + 'sure', 't\'s', 'take', 'taken', 'tell', 'tends', 'th', 'than', 'thank', 'thanks', 'thanx', 'that', 'that\'s', + 'thats', 'the', 'their', 'theirs', 'them', 'themselves', 'then', 'thence', 'there', 'there\'s', 'thereafter', + 'thereby', 'therefore', 'therein', 'theres', 'thereupon', 'these', 'they', 'they\'d', 'they\'ll', 'they\'re', + 'they\'ve', 'think', 'third', 'this', 'thorough', 'thoroughly', 'those', 'though', 'three', 'through', 'throughout', + 'thru', 'thus', 'to', 'together', 'too', 'took', 'toward', 'towards', 'tried', 'tries', 'truly', 'try', 'trying', + 'twice', 'two', 'un', 'under', 'unfortunately', 'unless', 'unlikely', 'until', 'unto', 'up', 'upon', 'us', 'use', + 'used', 'useful', 'uses', 'using', 'usually', 'value', 'various', 'very', 'via', 'viz', 'vs', 'want', 'wants', + 'was', 'wasn\'t', 'way', 'we', 'we\'d', 'we\'ll', 'we\'re', 'we\'ve', 'welcome', 'well', 'went', 'were', 'weren\'t', + 'what', 'what\'s', 'whatever', 'when', 'whence', 'whenever', 'where', 'where\'s', 'whereafter', 'whereas', + 'whereby', 'wherein', 'whereupon', 'wherever', 'whether', 'which', 'while', 'whither', 'who', 'who\'s', 'whoever', + 'whole', 'whom', 'whose', 'why', 'will', 'willing', 'wish', 'with', 'within', 'without', 'won\'t', 'wonder', + 'would', 'would', 'wouldn\'t', 'yes', 'yet', 'you', 'you\'d', 'you\'ll', 'you\'re', 'you\'ve', 'your', 'yours', + 'yourself', 'yourselves', 'zero'); + return $stopwords; } ?> diff -r 53ba55d33abb -r 8acd77a6c19d includes/template.php --- a/includes/template.php Wed Nov 21 20:45:50 2007 -0500 +++ b/includes/template.php Wed Nov 21 21:03:48 2007 -0500 @@ -851,7 +851,7 @@ if(isset($_GET['sqldbg']) && $session->get_permissions('mod_misc')) { echo '
'; - echo $db->sql_backtrace(); + echo htmlspecialchars($db->sql_backtrace()); echo ''; } @@ -1856,7 +1856,7 @@ */ class template_nodb { - var $tpl_strings, $tpl_bool, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list; + var $fading_button, $tpl_strings, $tpl_bool, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list; function __construct() { $this->tpl_bool = Array(); @@ -1864,7 +1864,11 @@ $this->sidebar_extra = ''; $this->sidebar_widgets = ''; $this->toolbar_menu = ''; - $this->additional_headers = ''; + $this->additional_headers = ''; + + $this->fading_button = ''; $this->theme_list = Array(Array( 'theme_id'=>'oxygen', @@ -1890,6 +1894,10 @@ if ( $auto_init ) $this->init_vars(); } + function add_header($html) + { + $this->additional_headers .= "\n\n\n " . $html; + } function init_vars() { global $sideinfo; @@ -1946,7 +1954,7 @@ 'ADMIN_SID_QUES'=>$asq, 'ADMIN_SID_AMP'=>$asa, 'ADMIN_SID_AMP_HTML'=>'', - 'ADDITIONAL_HEADERS'=>$headers, + 'ADDITIONAL_HEADERS'=>$this->additional_headers, 'SIDEBAR_EXTRA'=>'', 'COPYRIGHT'=>$lang->get('meta_enano_copyright'), 'TOOLBAR_EXTRAS'=>'', @@ -1994,11 +2002,15 @@ $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility $this->tpl_bool['stupid_mode'] = true; } - function header() + function header($simple = false) { - if(!$this->no_headers) echo $this->process_template('header.tpl'); + $filename = ( $simple ) ? 'simple-header.tpl' : 'header.tpl'; + if ( !$this->no_headers ) + { + echo $this->process_template($filename); + } } - function footer() + function footer($simple = false) { global $db, $session, $paths, $template, $plugins; // Common objects if(!$this->no_headers) { @@ -2011,7 +2023,8 @@ else $nq = $db->num_queries; if($nq == 0) $nq = 'N/A'; $dbg = 'Time: '.$f.'s | Queries: '.$nq; - $t = $this->process_template('footer.tpl'); + $filename = ( $simple ) ? 'simple-footer.tpl' : 'footer.tpl'; + $t = $this->process_template($filename); $t = str_replace('[[Stats]]', $dbg, $t); if ( is_object($db) ) { diff -r 53ba55d33abb -r 8acd77a6c19d install.php --- a/install.php Wed Nov 21 20:45:50 2007 -0500 +++ b/install.php Wed Nov 21 21:03:48 2007 -0500 @@ -14,7 +14,7 @@ */ @include('config.php'); -if( ( defined('ENANO_INSTALLED') || defined('MIDGET_INSTALLED') ) && ((isset($_GET['mode']) && ($_GET['mode']!='finish' && $_GET['mode']!='css')) || !isset($_GET['mode']))) +if( ( defined('ENANO_INSTALLED') || defined('MIDGET_INSTALLED') ) && ((isset($_GET['mode']) && ($_GET['mode']!='finish' && $_GET['mode']!='css') && $_GET['mode']!='showlicense') || !isset($_GET['mode']))) { $_GET['title'] = 'Enano:Installation_locked'; require('includes/common.php'); @@ -319,7 +319,7 @@ if ( !$conn ) return false; // Our list of tables included in Enano - $tables = Array( 'categories', 'comments', 'config', 'logs', 'page_text', 'session_keys', 'pages', 'users', 'users_extra', 'themes', 'buddies', 'banlist', 'files', 'privmsgs', 'sidebar', 'hits', 'search_index', 'groups', 'group_members', 'acl', 'search_cache', 'tags', 'page_groups', 'page_group_members' ); + $tables = Array( 'categories', 'comments', 'config', 'logs', 'page_text', 'session_keys', 'pages', 'users', 'users_extra', 'themes', 'buddies', 'banlist', 'files', 'privmsgs', 'sidebar', 'hits', 'search_index', 'groups', 'group_members', 'acl', 'tags', 'page_groups', 'page_group_members' ); // Drop each table individually; if it fails, it probably means we're trying to drop a // table that didn't exist in the Enano version we're deleting the database for. @@ -572,6 +572,14 @@ return true; } +function stg_build_index() +{ + global $db, $session, $paths, $template, $plugins; // Common objects; + if ( $paths->rebuild_search_index() ) + return true; + return false; +} + function stg_rename_config() { if ( !@rename('./config.new.php', './config.php') ) @@ -692,26 +700,50 @@ $failed = true; } } -function is_apache() +function is_apache() { $r = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? true : false; return $r; } + +function show_license($fb = false) { - return strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? true : false; + ?> +
get('license_info_unstable_body'); ?>
+ +get('license_gpl_blurb_inenglish'); ?>
+ + + Because I could never find the Create a Page button in PHP-Nuke.'; + echo '' . str_replace('http://enanocms.org/', 'http://www.2robots.com/2003/10/15/web-portals-suck/', $template->fading_button) . '
'; + echo 'It\'s not a portal, my friends.
'; + } + ?> +get('license_blurb_thankyou'); ?>
get('license_blurb_pleaseread'); ?>
-get('license_info_unstable_body'); ?>
- -get('license_gpl_blurb_inenglish'); ?>
- - -