Exemple #1
0
 /**
  * Standard modular run function for search results.
  *
  * @param  string			Search string
  * @param  boolean		Whether to only do a META (tags) search
  * @param  ID_TEXT		Order direction
  * @param  integer		Start position in total results
  * @param  integer		Maximum results to return in total
  * @param  boolean		Whether only to search titles (as opposed to both titles and content)
  * @param  string			Where clause that selects the content according to the main search string (SQL query fragment) (blank: full-text search)
  * @param  SHORT_TEXT	Username/Author to match for
  * @param  ?MEMBER		Member-ID to match for (NULL: unknown)
  * @param  TIME			Cutoff date
  * @param  string			The sort type (gets remapped to a field in this function)
  * @set    title add_date
  * @param  integer		Limit to this number of results
  * @param  string			What kind of boolean search to do
  * @set    or and
  * @param  string			Where constraints known by the main search code (SQL query fragment)
  * @param  string			Comma-separated list of categories to search under
  * @param  boolean		Whether it is a boolean search
  * @return array			List of maps (template, orderer)
  */
 function run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $limit_to, $boolean_operator, $where_clause, $search_under, $boolean_search)
 {
     $remapped_orderer = '';
     switch ($sort) {
         case 'title':
             $remapped_orderer = 'the_page';
             break;
         case 'add_date':
             $remapped_orderer = 'the_zone';
             // Stucked
             break;
     }
     load_up_all_self_page_permissions(get_member());
     $sq = build_search_submitter_clauses('p_submitter', $author_id, $author);
     if (is_null($sq)) {
         return array();
     } else {
         $where_clause .= $sq;
     }
     if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $where_clause .= ' AND ';
         $where_clause .= 'z.zone_name IS NOT NULL';
     }
     if (strpos($content, 'panel_') === false) {
         $where_clause .= ' AND ';
         $where_clause .= '(r.the_page NOT LIKE \'' . db_encode_like('panel\\_%') . '\') AND (r.the_page NOT LIKE \'' . db_encode_like('\\_%') . '\')';
     }
     if (!is_null($search_under) && $search_under != '!') {
         $where_clause .= ' AND ';
         $where_clause .= '(' . db_string_equal_to('r.the_zone', $search_under) . ')';
     }
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $where_clause .= ' AND ';
         $where_clause .= 'p_validated=1';
     }
     require_lang('zones');
     $g_or = _get_where_clause_groups(get_member(), false);
     // Calculate and perform query
     if ($g_or == '') {
         $rows = get_search_rows('comcode_page', 'the_zone:the_page', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'cached_comcode_pages r LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages q ON (q.the_zone=r.the_zone AND q.the_page=r.the_page)', array('r.cc_page_title', 'r.string_index'), $where_clause, $content_where, $remapped_orderer, 'r.*');
     } else {
         $rows = get_search_rows('comcode_page', 'the_zone:the_page', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'cached_comcode_pages r LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages q ON (q.the_zone=r.the_zone AND q.the_page=r.the_page) LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_zone_access z ON (z.zone_name=r.the_zone AND (' . str_replace('group_id', 'z.group_id', $g_or) . '))', array('r.cc_page_title', 'r.string_index'), $where_clause, $content_where, $remapped_orderer, 'r.*');
     }
     if (addon_installed('redirects_editor')) {
         $redirects = $GLOBALS['SITE_DB']->query_select('redirects', array('*'));
     } else {
         $redirects = array();
     }
     $out = array();
     $pages_found = array();
     foreach ($rows as $i => $row) {
         foreach ($redirects as $redirect) {
             if ($redirect['r_from_page'] == $row['the_page'] && $redirect['r_from_zone'] == $row['the_zone']) {
                 continue 2;
             }
         }
         if ($row['the_zone'] == '!') {
             continue;
         }
         if (array_key_exists($row['the_zone'] . ':' . $row['the_page'], $pages_found)) {
             continue;
         }
         $pages_found[$row['the_zone'] . ':' . $row['the_page']] = 1;
         $out[$i]['data'] = $row + array('extra' => array($row['the_zone'], $row['the_page'], $limit_to));
         if ($remapped_orderer != '' && array_key_exists($remapped_orderer, $row)) {
             $out[$i]['orderer'] = $row[$remapped_orderer];
         } elseif (substr($remapped_orderer, 0, 7) == '_rating') {
             $out[$i]['orderer'] = $row['compound_rating'];
         }
         if (!has_page_access(get_member(), $row['the_page'], $row['the_zone'])) {
             $out[$i]['restricted'] = true;
         }
     }
     if ($author == '') {
         // Make sure we record that for all cached Comcode pages, we know of them (only those not cached would not have been under the scope of the current search)
         $all_pages = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('the_zone', 'the_page'));
         foreach ($all_pages as $row) {
             $pages_found[$row['the_zone'] . ':' . $row['the_page']] = 1;
         }
         // Now, look on disk for non-cached comcode pages
         $zones = find_all_zones();
         $i = count($out);
         if (!is_null($search_under) && $search_under != '!') {
             $zones = array($search_under);
         }
         foreach ($zones as $zone) {
             if (!has_zone_access(get_member(), $zone)) {
                 continue;
             }
             $pages = find_all_pages($zone, 'comcode/' . user_lang(), 'txt') + find_all_pages($zone, 'comcode_custom/' . user_lang(), 'txt') + find_all_pages($zone, 'comcode/' . get_site_default_lang(), 'txt') + find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt');
             foreach ($pages as $page => $dir) {
                 if (!is_string($page)) {
                     $page = strval($page);
                 }
                 if (!array_key_exists($zone . ':' . $page, $pages_found)) {
                     if (!has_page_access(get_member(), $page, $zone)) {
                         continue;
                     }
                     if (strpos($content, 'panel_') === false) {
                         if (substr($page, 0, 6) == 'panel_') {
                             continue;
                         }
                     }
                     if (substr($page, 0, 1) == '_') {
                         continue;
                     }
                     foreach ($redirects as $redirect) {
                         if ($redirect['r_from_page'] == $page && $redirect['r_from_zone'] == $zone) {
                             continue 2;
                         }
                     }
                     $path = zone_black_magic_filterer(($dir == 'comcode_custom' ? get_custom_file_base() : get_file_base()) . '/' . $zone . '/pages/' . $dir . '/' . $page . '.txt');
                     if (!is_null($cutoff) && filemtime($path) < $cutoff) {
                         continue;
                     }
                     $contents = file_get_contents($path, FILE_TEXT);
                     if ($only_titles) {
                         $contents = preg_replace('#^.*\\[title(="1")?\\](.*)\\[/title\\].*$#Us', '${2}', $contents);
                     }
                     if (in_memory_search_match(array('content' => $content, 'conjunctive_operator' => $boolean_operator), $contents)) {
                         $out[$i]['data'] = array('the_zone' => $zone, 'the_page' => $page) + array('extra' => array($zone, $page, $limit_to));
                         if ($remapped_orderer == 'the_page') {
                             $out[$i]['orderer'] = $page;
                         } elseif ($remapped_orderer == 'the_zone') {
                             $out[$i]['orderer'] = $zone;
                         }
                         $i++;
                         $GLOBALS['TOTAL_RESULTS']++;
                         // Let it cache for next time
                         if (get_option('is_on_comcode_page_cache') == '1') {
                             request_page($page, false, $zone, $dir, false, true);
                         }
                     }
                 }
             }
         }
     }
     return $out;
 }
Exemple #2
0
 /**
  * Standard modular run function for search results.
  *
  * @param  string			Search string
  * @param  boolean		Whether to only do a META (tags) search
  * @param  ID_TEXT		Order direction
  * @param  integer		Start position in total results
  * @param  integer		Maximum results to return in total
  * @param  boolean		Whether only to search titles (as opposed to both titles and content)
  * @param  string			Where clause that selects the content according to the main search string (SQL query fragment) (blank: full-text search)
  * @param  SHORT_TEXT	Username/Author to match for
  * @param  ?MEMBER		Member-ID to match for (NULL: unknown)
  * @param  TIME			Cutoff date
  * @param  string			The sort type (gets remapped to a field in this function)
  * @set    title add_date
  * @param  integer		Limit to this number of results
  * @param  string			What kind of boolean search to do
  * @set    or and
  * @param  string			Where constraints known by the main search code (SQL query fragment)
  * @param  string			Comma-separated list of categories to search under
  * @param  boolean		Whether it is a boolean search
  * @return array			List of maps (template, orderer)
  */
 function run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $limit_to, $boolean_operator, $where_clause, $search_under, $boolean_search)
 {
     unset($author_id);
     unset($where_clause);
     require_lang('zones');
     // Calculate our where clause (search)
     if ($author != '') {
         return array();
     }
     require_code('files2');
     if ($search_under == '!') {
         $search_under = '';
     }
     $files = get_directory_contents(get_custom_file_base() . '/uploads/filedump/' . ($search_under == '' ? '' : $search_under . '/'));
     $_rows = $GLOBALS['SITE_DB']->query_select('filedump');
     $rows = array();
     foreach ($_rows as $row) {
         $rows[$row['path']] = $row;
     }
     $i = 0;
     $out = array();
     foreach ($files as $_path) {
         if ($search_under != '') {
             $_path = $search_under . '/' . $_path;
         }
         $path = get_custom_file_base() . '/uploads/filedump/' . $_path;
         if (filemtime($path) < $cutoff) {
             continue;
         }
         if (in_memory_search_match(array('content' => $content, 'conjunctive_operator' => $boolean_operator), $path)) {
             $caption = array_key_exists($_path, $rows) ? $rows[$_path] : $_path;
             $dirs = explode('/', dirname($_path));
             $pre = '';
             $file_breadcrumbs = new ocp_tempcode();
             $breadcrumbs_url = build_url(array('page' => 'filedump', 'place' => $pre . '/'), get_module_zone('filedump'));
             $file_breadcrumbs->attach(hyperlink($breadcrumbs_url, do_lang('ROOT')));
             foreach ($dirs as $dir) {
                 $file_breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR', array('_GUID' => '7ee62e230d53344a7d9667dc59be21c4')));
                 $breadcrumbs_url = build_url(array('page' => 'filedump', 'place' => $pre . $dir . '/'), get_module_zone('filedump'));
                 $file_breadcrumbs->attach(hyperlink($breadcrumbs_url, $dir));
                 $pre .= $dir . '/';
             }
             $url = get_custom_base_url() . '/uploads/filedump/' . $_path;
             require_code('images');
             if (!is_image($url)) {
                 $tpl = paragraph(hyperlink($url, escape_html($caption), true), 'dfdsfu09wl;f');
                 if (!$file_breadcrumbs->is_empty()) {
                     $tpl->attach(paragraph(do_lang_tempcode('LOCATED_IN', $file_breadcrumbs)));
                 }
                 $out[$i]['template'] = do_template('SIMPLE_PREVIEW_BOX', array('_GUID' => '51bc0cf751f4ccbd0b7f1a247b092368', 'TITLE' => basename($_path), 'SUMMARY' => $tpl));
             } else {
                 if (function_exists('set_time_limit')) {
                     @set_time_limit(5);
                 }
                 $tpl = do_image_thumb($url, $caption, true, true);
                 $out[$i]['template'] = do_template('SIMPLE_PREVIEW_BOX', array('_GUID' => '61bc0cf751f4ccbd0b7f1a247b092368', 'TITLE' => basename($_path), 'SUMMARY' => $tpl, 'BREADCRUMBS' => $file_breadcrumbs, 'URL' => $url));
             }
             if ($sort == 'title') {
                 $out[$i]['orderer'] = $path;
             } elseif ($sort == 'add_date') {
                 $out[$i]['orderer'] = filectime($path);
             } elseif ($sort == 'file_size') {
                 $out[$i]['orderer'] = filesize($path);
             }
             $i++;
         }
     }
     return $out;
 }