Example #1
0
 protected function export_to_cache($name = null)
 {
     if (!method_exists($this, '__set_state')) {
         Poodle_Report::error('Class missing method', 'Class ' . get_class($this) . ' is missing public static function __set_state');
         return;
     }
     $path = Poodle::$DIR_CACHE;
     if (is_dir($path) && is_writable($path)) {
         $file = "<?php\nif (!class_exists('" . get_class($this) . "', false)) { exit; }\nreturn " . var_export($this, true) . ';';
         return Poodle_Cache::file_write('C_' . ($name ? $name : get_class($this)) . '.php', $file);
     }
     return false;
 }
Example #2
0
 public function search($fields, $text)
 {
     static $min_word_len = 0;
     /*
     # Short words are ignored, the default minimum length is 4 characters. You can change the min and max word length with the variables ft_min_word_len and ft_max_word_len
     # Words called stopwords are ignored, you can specify your own stopwords, but default words include the, have, some - see default stopwords list.
     # You can disable stopwords by setting the variable ft_stopword_file to an empty string.
     */
     if (!$min_word_len) {
         $min_word_len = u_fetch_row('SHOW VARIABLES LIKE \'ft_min_word_len\'');
         $min_word_len = max(intval($min_word_len[0]), 3);
     }
     preg_match_all('#[^\\s]{' . $min_word_len . ',}#', $text, $text);
     return ' MATCH(' . implode(',', $fields) . ') AGAINST(' . $this->quote(implode(' ', $text[0])) . ') ';
     $text = Poodle_Unicode::as_search_txt($text);
     $prefix = $this->server_info < 8.300000000000001 ? "'default'," : '';
     //		$searchstring = $this->parseQuery($text);
     # We need a separate query here so gin does not complain about empty searches
     $res = pg_query($this->connection, "SELECT to_tsquery({$prefix} {$text})");
     if (!$res) {
         Poodle_Report::error('Sorry, that was not a valid search string. Please go back and try again');
     }
     $top = pg_fetch_result($res, 0, 0);
     # e.g. if only stopwords are used XXX return something better
     if (!$top) {
         $query = "SELECT page_id, page_namespace, page_title, 0 AS score " . "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " . "AND r.rev_text_id = c.old_id AND 1=0";
     } else {
         $m = array();
         if (preg_match_all("/'([^']+)'/", $top, $m, PREG_SET_ORDER)) {
             foreach ($m as $terms) {
                 $this->searchTerms[$terms[1]] = $terms[1];
             }
         }
         $score = $this->server_info > 8.199999999999999 ? 5 : 1;
         $rank = $this->server_info < 8.300000000000001 ? 'rank' : 'ts_rank';
         $query = "SELECT page_id, page_namespace, page_title, " . "{$rank}({$fulltext}, to_tsquery({$prefix} {$searchstring}), {$score}) AS score " . "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " . "AND r.rev_text_id = c.old_id AND {$fulltext} @@ to_tsquery({$prefix} {$searchstring})";
     }
     ## Redirects
     if (!$this->showRedirects) {
         $query .= ' AND page_is_redirect = 0';
     }
     ## Namespaces - defaults to 0
     if (!is_null($this->namespaces)) {
         // null -> search all
         if (count($this->namespaces) < 1) {
             $query .= ' AND page_namespace = 0';
         } else {
             $namespaces = implode(',', $this->namespaces);
             $query .= " AND page_namespace IN ({$namespaces})";
         }
     }
     $query .= " ORDER BY score DESC, page_id DESC";
     $query .= $this->db->limitResult('', $this->limit, $this->offset);
     return $query;
 }
Example #3
0
 public static function close_request($msg, $status_code = 200, $uri = null, $box_msg = null)
 {
     if (POODLE_CLI) {
         echo $status_code . ' ' . $msg;
         exit;
     }
     if (XMLHTTPRequest) {
         header('Pragma: no-cache');
         header('Cache-Control: no-cache');
         Poodle_HTTP_Headers::set_status($status_code);
         switch ($status_code) {
             case 201:
                 if ($uri) {
                     header('Location: ' . $uri);
                 }
                 break;
             case 204:
                 exit;
         }
         if ($box_msg) {
             Poodle_Session::msg($box_msg);
         }
         exit($msg);
     }
     if ($status_code > 400) {
         Poodle_Report::error($status_code, $msg);
     }
     if ($msg) {
         Poodle_Session::msg($msg);
     }
     Poodle_URI::redirect($uri);
 }