Example #1
0
function search_keyword($terms)
{
    con();
    $terms = search_split_terms($terms);
    $terms_db = search_db_escape_terms($terms);
    $terms_rx = search_rx_escape_terms($terms);
    $parts = array();
    foreach ($terms_db as $term_db) {
        $parts[] = "article_keywords.keywords RLIKE '{$term_db}'";
    }
    //search for similar items on the keywords table
    $parts = implode(' AND ', $parts);
    $sql = "SELECT article_keywords.articleID FROM article_keywords WHERE {$parts}";
    $rows = array();
    //perform query to the database
    $result = mysql_query($sql);
    //start fetching results
    if (!$result) {
        return false;
    } else {
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $rows[] = $row;
        }
        //print_r($rows);
        return $rows;
        //return array of id numbers
    }
}
Example #2
0
 private function search()
 {
     $this->load->helper('text');
     $this->data['can_edit'] = false;
     $this->data['sq'] = @$_GET['sq'];
     $this->data['terms'] = search_split_terms($this->data['sq']);
     $this->data['result'] = $this->pages->search($this->data['book']->book_id, $this->data['terms']);
     usort($this->data['result'], "sortSearchResults");
     $this->data['view'] = __FUNCTION__;
 }
Example #3
0
 /**
  * Search the info from the DB
  *
  * Uses a smarter search engine to search through the fields and return certain fields, puts the results in a local $results array
  *
  * @param $keywords A string that we are going to be searching the DB for
  * @param $search_fields An array of the field keys that we are going to be searching through
  * @param $return_fields An array of the field keys that are going to be returned
  * @return int
  */
 public function Search($keywords, $search_fields, $return_fields)
 {
     // Use the global db class
     global $db;
     $returns = array();
     // Push $this into the array
     array_unshift($this->join_class, $this);
     array_unshift($this->join_type, '');
     array_unshift($this->join_on, '');
     // Setup the return fields
     if (!isMultiArray($return_fields)) {
         array_unshift($returns, $return_fields);
     } else {
         $returns = $return_fields;
     }
     // Split up the terms
     $terms = search_split_terms($keywords);
     $terms_db = search_db_escape_terms($terms);
     $terms_rx = search_rx_escape_terms($terms);
     // Create list of statements
     $parts = array();
     foreach ($terms_db as $term_db) {
         if (is_array($search_fields)) {
             foreach ($search_fields as $field) {
                 $parts[] = '`' . $this->database . '`.`' . $this->table . '`.' . $field . ' RLIKE \'' . $term_db . '\'';
             }
         } else {
             $parts[] = '`' . $this->database . '`.`' . $this->table . '`.' . $search_fields . ' RLIKE \'' . $term_db . '\'';
         }
     }
     $parts = '(' . implode(' OR ', $parts) . ')';
     if ($this->conditions != '') {
         $parts .= ' AND ' . $this->conditions;
     }
     // Loop through all the joined classes
     foreach ($this->join_class as $key => $class) {
         // Create the return fields
         if (is_array($returns[$key]) && count($returns[$key]) > 0) {
             // Require primary key returned
             if (!in_array($class->primary, $returns[$key])) {
                 $return .= '`' . $class->database . '`.`' . $class->table . '`.' . $class->primary . ', ';
             }
             // List all other fields to be returned
             foreach ($returns[$key] as $field) {
                 if (!is_array($field)) {
                     $return .= trim($field) != '' ? '`' . $class->database . '`.`' . $class->table . '`.' . $field . ', ' : '';
                 } else {
                     foreach ($field as $sub_field) {
                         $return .= trim($sub_field) != '' ? '`' . $class->database . '`.`' . $class->table . '`.' . $sub_field . ', ' : '';
                     }
                 }
             }
         } else {
             // Local class return values
             if (is_array($returns[$key])) {
                 foreach ($returns[$key] as $field) {
                     $fields[] = '`' . $this->database . '`.`' . $this->table . '`.' . $field;
                 }
                 $return .= implode(', ', $fields);
             } else {
                 $return .= '`' . $class->database . '`.`' . $class->table . '`.*, ';
             }
         }
         // Create the Joins
         if ($key > 0) {
             $join .= ' ' . $this->join_type[$key] . ' JOIN `' . $this->join_class[$key]->database . '`.`' . $this->join_class[$key]->table . '` ON (`' . $this->join_class[$key]->database . '`.`' . $this->join_class[$key]->table . '`.' . $this->join_on[$key][0] . ' = `' . $this->database . '`.`' . $this->table . '`.' . $this->join_on[$key][1] . ') ';
         }
     }
     $query = 'SELECT ' . substr($return, 0, -2) . ' FROM `' . $this->database . '`.`' . $this->table . '`' . $join . ' WHERE ' . $parts;
     $query .= $this->group_by != '' ? ' GROUP BY ' . $this->group_by : '';
     $result = $db->Query($query, $this->database);
     $results = array();
     while ($info = $db->FetchArray($result)) {
         $info['score'] = 0;
         foreach ($terms_rx as $term_rx) {
             if (is_array($search_fields)) {
                 foreach ($search_fields as $field) {
                     $info['score'] += preg_match_all("/{$term_rx}/i", $info[$field], $null);
                 }
             } else {
                 $info['score'] += preg_match_all("/{$term_rx}/i", $info[$search_fields], $null);
             }
         }
         $results[] = $info;
     }
     // Pop $this from the array
     array_shift($this->join_class);
     array_shift($this->join_type);
     array_shift($this->join_on);
     uasort($results, 'search_sort_results');
     $this->results = $results;
     return count($results);
 }
Example #4
0
 /**
  * URL information and load the current book
  */
 public function __construct()
 {
     parent::__construct();
     $this->load->model('book_model', 'books');
     $this->load->model('page_model', 'pages');
     $this->load->model('version_model', 'versions');
     $this->load->model('reference_model', 'references');
     $this->load->model('annotation_model', 'annotations');
     $this->load->model('path_model', 'paths');
     $this->load->model('tag_model', 'tags');
     $this->load->model('reply_model', 'replies');
     $this->load->library('RDF_Object', 'rdf_object');
     $this->load->library('statusCodes');
     $this->load->helper('inflector');
     $this->models = $this->config->item('rel');
     // Determine the current book being asked for (if applicable)
     $this->scope = strtolower(get_class($this)) == strtolower($this->uri->segment('1')) ? null : strtolower($this->uri->segment('1'));
     // Load book beind asked for (if applicable)
     $this->data['book'] = !empty($this->scope) ? $this->books->get_by_slug($this->scope) : null;
     if (empty($this->data['book'])) {
         // Book couldn't be found
         $this->data['base_uri'] = confirm_slash(base_url());
     } else {
         // Book was found
         $this->data['base_uri'] = confirm_slash(base_url()) . confirm_slash($this->data['book']->slug);
         // Protect book; TODO: provide api_key authentication like api.php
         $this->set_user_book_perms();
         if (!$this->data['book']->url_is_public && !$this->login_is_book_admin('reader')) {
             header(StatusCodes::httpHeaderFor(StatusCodes::HTTP_NOT_FOUND));
             exit;
         }
     }
     // Format (e.g., 'xml', 'json')
     $allowable_formats = array('xml' => 'xml', 'json' => 'json', 'rdfxml' => 'xml', 'rdfjson' => 'json', 'turtle' => 'turtle');
     $this->data['format'] = isset($_REQUEST['format']) && array_key_exists($_REQUEST['format'], $allowable_formats) ? $allowable_formats[$_REQUEST['format']] : $allowable_formats[key($allowable_formats)];
     $ext = get_ext($this->uri->uri_string());
     $this->data['format'] = !empty($ext) && array_key_exists($ext, $allowable_formats) ? $allowable_formats[$ext] : $this->data['format'];
     // Recursion level
     $this->data['recursion'] = isset($_REQUEST['rec']) && is_numeric($_REQUEST['rec']) ? (int) $_REQUEST['rec'] : 0;
     // Display references?
     $this->data['references'] = isset($_REQUEST['ref']) && $_REQUEST['ref'] ? true : false;
     // Restrict relationships to a certain relationship or set of relationships (seperated by a comma)?
     $this->data['restrict'] = array();
     $restrict = isset($_REQUEST['res']) && !empty($_REQUEST['res']) ? explode(',', $_REQUEST['res']) : array();
     foreach ($restrict as $res) {
         if (!in_array(plural(strtolower($res)), $this->models)) {
             continue;
         }
         $this->data['restrict'][] = (string) plural(strtolower($res));
     }
     // Display all versions?
     $this->data['versions'] = isset($_REQUEST['versions']) && $_REQUEST['versions'] ? true : false;
     // Search terms
     $this->data['sq'] = isset($_REQUEST['sq']) && !empty($_REQUEST['sq']) ? search_split_terms($_REQUEST['sq']) : null;
     // Provenance
     $this->data['provenance'] = isset($_REQUEST['prov']) && !empty($_REQUEST['prov']) ? 1 : null;
     // Show hidden content
     $this->data['hidden'] = isset($_REQUEST['hidden']) && !empty($_REQUEST['hidden']) ? (int) $_REQUEST['hidden'] : 0;
     $this->set_user_book_perms();
     if (!$this->data['login'] || !$this->login_is_book_admin()) {
         $this->data['hidden'] = 0;
     }
     // Pagination
     $start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : null;
     $results = isset($_REQUEST['results']) && !empty($_REQUEST['results']) ? (int) $_REQUEST['results'] : null;
     if (empty($results)) {
         $start = $results = null;
     }
     $this->data['pagination'] = array();
     if (!empty($start) || $start === 0) {
         $this->data['pagination']['start'] = $start;
     }
     if (!empty($results)) {
         $this->data['pagination']['results'] = $results;
     }
 }
Example #5
0
     }
     $contentresults = array_merge($contentresults, $eventresults);
     $numcontentresults += $numeventresults;
 }
 if ($_POST['pm'] == 1 && $check['id'] != -1) {
     $username = safesql($check['id'], "int");
     $sql = $data->select_query("pms", "WHERE (MATCH(subject, text) AGAINST ({$safe_search} IN BOOLEAN MODE)) HAVING score > 0.1 AND (((type=1 OR type=3) AND touser={$username}) OR ((type=2 OR type=4) AND fromuser={$username})) ORDER BY score DESC", "*, MATCH(subject, text) AGAINST ({$safe_search}) AS score");
     $numcontentresults += $data->num_rows($sql);
     while ($temp = $data->fetch_array($sql)) {
         $temp['itemtype'] = 7;
         $contentresults[] = $temp;
     }
 }
 $tpl->assign("results", $numcontentresults);
 $tpl->assign('term_list', stripslashes($search));
 $tpl->assign('terms', HtmlSpecialChars(serialize(search_html_escape_terms(search_split_terms($search)))));
 $tpl->assign("searched", 1);
 $tpl->assign("search", stripslashes($search));
 $tpl->assign("forumcheck", $_POST['forum']);
 $tpl->assign("articlecheck", $_POST['article']);
 $tpl->assign("contentcheck", $_POST['content']);
 $tpl->assign("newscheck", $_POST['news']);
 $tpl->assign("eventscheck", $_POST['events']);
 $tpl->assign("pmcheck", $_POST['pm']);
 function cmp($a, $b)
 {
     if ($a['score'] == $b['score']) {
         return 0;
     }
     return $a['score'] < $b['score'] ? 1 : -1;
 }