Exemplo n.º 1
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (!addon_installed('news')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'news')) {
         return NULL;
     }
     $filters_1 = ocfilter_to_sqlfragment($_filters, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($_filters, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id WHERE date_and_time>' . strval($cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1 ' : '') . ' AND ' . $filters . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC', $max);
     $rows = remove_duplicate_rows($rows, 'id');
     $_categories = $GLOBALS['SITE_DB']->query_select('news_categories', array('id', 'nc_title'), array('nc_owner' => NULL));
     foreach ($_categories as $i => $_category) {
         $_categories[$i]['text_original'] = get_translated_text($_category['nc_title']);
     }
     $categories = collapse_2d_complexity('id', 'text_original', $_categories);
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (has_category_access(get_member(), 'news', strval($row['news_category']))) {
             $id = strval($row['id']);
             $author = $row['author'];
             $news_date = date($date_string, $row['date_and_time']);
             $edit_date = is_null($row['edit_date']) ? '' : date($date_string, $row['edit_date']);
             $_title = get_translated_tempcode($row['title']);
             $news_title = xmlentities($_title->evaluate());
             $_summary = get_translated_tempcode($row['news']);
             if ($_summary->is_empty()) {
                 $_summary = get_translated_tempcode($row['news_article']);
             }
             $summary = xmlentities($_summary->evaluate());
             if (!is_null($row['news_article'])) {
                 $_news = get_translated_tempcode($row['news_article']);
                 if ($_news->is_empty()) {
                     $news = '';
                 } else {
                     $news = xmlentities($_news->evaluate());
                 }
             } else {
                 $news = '';
             }
             if (!array_key_exists($row['news_category'], $categories)) {
                 $categories[$row['news_category']] = get_translated_text($GLOBALS['SITE_DB']->query_value('news_categories', 'nc_title', array('id' => $row['news_category'])));
             }
             $category = $categories[$row['news_category']];
             $category_raw = strval($row['news_category']);
             $view_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), get_module_zone('news'), NULL, false, false, true);
             if ($prefix == 'RSS_' && get_option('is_on_comments') == '1' && $row['allow_comments'] >= 1) {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'b4f25f5cf68304f8d402bb06851489d6', 'COMMENT_URL' => $view_url, 'ID' => strval($row['id'])));
             } else {
                 $if_comments = new ocp_tempcode();
             }
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     return array($content, do_lang('NEWS'));
 }
Exemplo n.º 2
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     $number = array_key_exists('max', $map) ? intval($map['max']) : 10;
     $filter = array_key_exists('filter', $map) ? $map['filter'] : '*';
     $out = new ocp_tempcode();
     require_code('ocf_members');
     require_code('ocf_members2');
     require_code('ocfiltering');
     $sql_filter = ocfilter_to_sqlfragment($filter, 'm_primary_group');
     $sql_filter_2 = ocfilter_to_sqlfragment($filter, 'gm_group_id');
     $rows = $GLOBALS['FORUM_DB']->query('SELECT m.* FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members m LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_group_members g ON (m.id=g.gm_member_id AND gm_validated=1) LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_member_custom_fields f ON m.id=f.mf_member_id WHERE ((' . $sql_filter . ') OR (' . $sql_filter_2 . ')) AND id<>' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . (can_arbitrary_groupby() ? ' GROUP BY m.id' : '') . ' ORDER BY m.m_join_time DESC', $number);
     $rows = remove_duplicate_rows($rows, 'id');
     if (count($rows) == 0) {
         return do_template('BLOCK_NO_ENTRIES', array('HIGH' => false, 'TITLE' => do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('MEMBERS')), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => '', 'SUBMIT_URL' => ''));
     } else {
         foreach ($rows as $i => $row) {
             if ($i != 0) {
                 $out->attach(do_template('BLOCK_SEPARATOR'));
             }
             $out->attach(ocf_show_member_box($row['id'], true));
         }
     }
     return $out;
 }
Exemplo n.º 3
0
 /**
  * The UI to translate content.
  *
  * @return tempcode		The UI
  */
 function interface_content()
 {
     $title = get_page_title('TRANSLATE_CONTENT');
     if (!multi_lang()) {
         warn_exit(do_lang_tempcode('MULTILANG_OFF'));
     }
     $max = get_param_integer('max', 100);
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     // Fiddle around in order to find what we haven't translated. Subqueries and self joins don't work well enough across different db's
     if (!db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $_done_id_list = collapse_2d_complexity('id', 'text_original', $GLOBALS['SITE_DB']->query_select('translate', array('id', 'text_original'), array('language' => $lang, 'broken' => 0)));
         $done_id_list = '';
         foreach (array_keys($_done_id_list) as $done_id) {
             if ($done_id_list != '') {
                 $done_id_list .= ',';
             }
             $done_id_list .= strval($done_id);
         }
         $and_clause = $done_id_list == '' ? '' : 'AND id NOT IN (' . $done_id_list . ')';
         $query = 'FROM ' . get_table_prefix() . 'translate WHERE ' . db_string_not_equal_to('language', $lang) . ' ' . $and_clause . ' AND ' . db_string_not_equal_to('text_original', '') . ' ORDER BY importance_level';
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT * ' . $query, $max);
     } else {
         $query = 'FROM ' . get_table_prefix() . 'translate a LEFT JOIN ' . get_table_prefix() . 'translate b ON a.id=b.id AND b.broken=0 AND ' . db_string_equal_to('b.language', $lang) . ' WHERE b.id IS NULL AND ' . db_string_not_equal_to('a.language', $lang) . ' AND ' . db_string_not_equal_to('a.text_original', '');
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT a.* ' . $query . (can_arbitrary_groupby() ? ' GROUP BY a.id' : '') . ' ORDER BY a.importance_level', $max);
     }
     $total = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     if (count($to_translate) == 0) {
         inform_exit(do_lang_tempcode('NOTHING_TO_TRANSLATE'));
     }
     require_all_lang($lang, true);
     require_all_open_lang_files($lang);
     // Make our translation page
     require_code('lang2');
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = make_string_tempcode('&nbsp;');
     $last_level = NULL;
     $too_many = count($to_translate) == $max;
     $ids_to_lookup = array();
     foreach ($to_translate as $it) {
         $ids_to_lookup[] = $it['id'];
     }
     $names = find_lang_content_names($ids_to_lookup);
     foreach ($to_translate as $i => $it) {
         if ($it['importance_level'] == 0) {
             continue;
         }
         // Corrupt data
         $id = $it['id'];
         $old = $it['text_original'];
         $current = $this->find_lang_matches($old, $lang);
         $priority = $last_level === $it['importance_level'] ? NULL : do_lang('PRIORITY_' . strval($it['importance_level']));
         $name = $names[$id];
         if (is_null($name)) {
             continue;
         }
         // Orphaned string
         if ($intertrans != '') {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => 'f625cf15c9db5e5af30fc772a7f0d5ff', 'LANG_FROM' => $it['language'], 'LANG_TO' => $lang, 'NAME' => 'trans_' . strval($id), 'OLD' => $old));
         }
         $line = do_template('TRANSLATE_LINE_CONTENT', array('_GUID' => '87a0f5298ce9532839f3206cd0e06051', 'NAME' => $name, 'ID' => strval($id), 'OLD' => $old, 'CURRENT' => $current, 'ACTIONS' => $actions, 'PRIORITY' => $priority));
         $lines .= $line->evaluate();
         /*XHTMLXHTML*/
         $last_level = $it['importance_level'];
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_content', 'lang' => $lang), '_SELF');
     require_code('lang2');
     return do_template('TRANSLATE_SCREEN_CONTENT_SCREEN', array('_GUID' => 'af732c5e595816db1c6f025c4b8fa6a2', 'MAX' => integer_format($max), 'TOTAL' => integer_format($total - $max), 'LANG_ORIGINAL_NAME' => get_site_default_lang(), 'LANG_NICE_ORIGINAL_NAME' => lookup_language_full_name(get_site_default_lang()), 'LANG_NICE_NAME' => lookup_language_full_name($lang), 'TOO_MANY' => $too_many, 'INTERTRANS' => $intertrans, 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Exemplo n.º 4
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news');
     $filter = array_key_exists('filter', $map) ? $map['filter'] : '*';
     require_code('ocfiltering');
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     $rows = $GLOBALS['SITE_DB']->query('SELECT p.id,p.date_and_time FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id WHERE ' . $q_filter . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1' : '') . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC');
     $rows = remove_duplicate_rows($rows, 'id');
     $rows = array_reverse($rows);
     if (count($rows) == 0) {
         return new ocp_tempcode();
     }
     // Nothing
     $first = $rows[0]['date_and_time'];
     $last = $rows[count($rows) - 1]['date_and_time'];
     $current_month = intval(date('m', utctime_to_usertime($first)));
     $current_year = intval(date('Y', utctime_to_usertime($first)));
     $last_month = intval(date('m', utctime_to_usertime($last)));
     $last_year = intval(date('Y', utctime_to_usertime($last)));
     $years = array();
     $years[$current_year] = array('YEAR' => strval($current_year), 'TIMES' => array());
     require_lang('dates');
     $offset = 0;
     $period_start = $first;
     while (true) {
         $period_start = usertime_to_utctime(mktime(0, 0, 0, $current_month, 0, $current_year));
         $period_end = usertime_to_utctime(mktime(0, 0, 0, $current_month + 1, 0, $current_year)) - 1;
         while ($rows[$offset]['date_and_time'] < $period_start) {
             $offset++;
             if (!isset($rows[$offset]['date_and_time'])) {
                 break 2;
             }
         }
         if ($rows[$offset]['date_and_time'] <= $period_end) {
             while (isset($rows[$offset]['date_and_time']) && $rows[$offset]['date_and_time'] <= $period_end) {
                 $offset++;
             }
             $offset--;
             $month_string = '';
             switch (strval($current_month)) {
                 case '1':
                     $month_string = do_lang('JANUARY');
                     break;
                 case '2':
                     $month_string = do_lang('FEBRUARY');
                     break;
                 case '3':
                     $month_string = do_lang('MARCH');
                     break;
                 case '4':
                     $month_string = do_lang('APRIL');
                     break;
                 case '5':
                     $month_string = do_lang('MAY');
                     break;
                 case '6':
                     $month_string = do_lang('JUNE');
                     break;
                 case '7':
                     $month_string = do_lang('JULY');
                     break;
                 case '8':
                     $month_string = do_lang('AUGUST');
                     break;
                 case '9':
                     $month_string = do_lang('SEPTEMBER');
                     break;
                 case '10':
                     $month_string = do_lang('OCTOBER');
                     break;
                 case '11':
                     $month_string = do_lang('NOVEMBER');
                     break;
                 case '12':
                     $month_string = do_lang('DECEMBER');
                     break;
             }
             $url = build_url(array('page' => 'news', 'type' => 'misc', 'filter' => $filter, 'start' => count($rows) - $offset - 1), $zone);
             array_unshift($years[$current_year]['TIMES'], array('URL' => $url, 'MONTH' => strval($current_month), 'MONTH_STRING' => $month_string));
         }
         if ($current_month != 12) {
             $current_month++;
         } else {
             $current_month = 1;
             $current_year++;
             $years[$current_year] = array('YEAR' => strval($current_year), 'TIMES' => array());
         }
     }
     $years = array_reverse($years);
     $title = array_key_exists('title', $map) ? $map['title'] : do_lang('ARCHIVES');
     return do_template('BLOCK_SIDE_NEWS_ARCHIVE', array('YEARS' => $years, 'TITLE' => $title));
 }
Exemplo n.º 5
0
/**
 * Get a nice, formatted, XHTML list of all the catalogues.
 *
 * @param  ?ID_TEXT		The name of the currently selected catalogue (NULL: none selected)
 * @param  boolean		If there are too many to list prefer to get ones with entries rather than just the newest
 * @param  boolean		Whether to only show catalogues that can be submitted to
 * @return tempcode		Catalogue selection list
 */
function nice_get_catalogues($it = NULL, $prefer_ones_with_entries = false, $only_submittable = false)
{
    $query = 'SELECT c.* FROM ' . get_table_prefix() . 'catalogues c';
    if ($prefer_ones_with_entries) {
        if (can_arbitrary_groupby()) {
            $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name';
        }
    }
    $query .= ' ORDER BY c_add_date DESC';
    $rows = $GLOBALS['SITE_DB']->query($query, 100);
    if (count($rows) == 100) {
        attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__ALPHABETICAL', escape_html(integer_format(100))), 'warn');
    }
    $out = new ocp_tempcode();
    foreach ($rows as $row) {
        if (substr($row['c_name'], 0, 1) == '_') {
            continue;
        }
        if (!has_category_access(get_member(), 'catalogues_catalogue', $row['c_name'])) {
            continue;
        }
        if ($only_submittable && !has_specific_permission(get_member(), 'submit_midrange_content', 'cms_catalogues', array('catalogues_catalogue', $row['c_name']))) {
            continue;
        }
        if ($row['c_ecommerce'] == 0 || addon_installed('shopping')) {
            $selected = $row['c_name'] == $it;
            $out->attach(form_input_list_entry($row['c_name'], $selected, get_translated_text($row['c_title'])));
        }
    }
    return $out;
}
Exemplo n.º 6
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_post_files($db, $table_prefix, $file_base)
 {
     global $STRICT_FILE;
     require_code('attachments2');
     require_code('attachments3');
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'attachments a JOIN ' . $table_prefix . 'messages m ON a.id_msg=m.id_msg WHERE a.id_msg<>0' . (can_arbitrary_groupby() ? ' GROUP BY id_attach' : ''), 200, $row_start);
         $rows = remove_duplicate_rows($rows, 'id_attach');
         foreach ($rows as $row) {
             if (substr($row['filename'], -5) == 'thumb') {
                 continue;
             }
             if (import_check_if_imported('post_files', strval($row['id_attach']))) {
                 continue;
             }
             $post_id = import_id_remap_get('post', strval($row['id_msg']));
             $post_row = $GLOBALS['FORUM_DB']->query_select('f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON p.p_post=t.id', array('p_time', 'text_original', 'p_poster', 'p_post'), array('p.id' => $post_id), '', 1);
             if (!array_key_exists(0, $post_row)) {
                 import_id_remap_put('post_files', strval($row['id_attach']), 1);
                 continue;
                 // Orphaned post
             }
             $post = $post_row[0]['text_original'];
             $lang_id = $post_row[0]['p_post'];
             $member_id = $post_row[0]['p_poster'];
             $ext = '.' . $row['fileext'];
             $filename = $row['id_attach'] . '_' . $row['file_hash'];
             $url = $this->data_to_disk('', $filename, 'attachments', $db, $table_prefix, $row['filename'], $file_base, $row['id_attach'], $ext);
             $a_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => $row['size'], 'a_url' => $url, 'a_thumb_url' => $url, 'a_original_filename' => $row['filename'], 'a_num_downloads' => $row['downloads'], 'a_last_downloaded_time' => NULL, 'a_add_time' => $row['poster_time'], 'a_description' => ''), true);
             $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => 'ocf_post', 'r_referer_id' => strval($post_id), 'a_id' => $a_id));
             $post .= "\n\n" . '[attachment]' . strval($a_id) . '[/attachment]';
             update_lang_comcode_attachments($lang_id, $post, 'ocf_post', strval($post_id));
             import_id_remap_put('post_files', strval($row['id_attach']), 1);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemplo n.º 7
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (!addon_installed('catalogues')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'catalogues')) {
         return NULL;
     }
     $filters_1 = ocfilter_to_sqlfragment($_filters, 'id', 'catalogue_categories', 'cc_parent_id', 'id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters = ocfilter_to_sqlfragment($_filters, 'cc_id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     require_code('catalogues');
     $_categories = $GLOBALS['SITE_DB']->query('SELECT id,c_name,cc_title FROM ' . get_table_prefix() . 'catalogue_categories WHERE ' . $filters_1, 300);
     foreach ($_categories as $i => $_category) {
         $_categories[$i]['text_original'] = get_translated_text($_category['cc_title']);
     }
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries WHERE ce_add_date>' . strval(time() - $cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND ce_validated=1 ' : '') . ' AND ' . $filters . ' ORDER BY ce_add_date DESC', $max);
     $categories = array();
     foreach ($_categories as $category) {
         $categories[$category['id']] = $category;
     }
     $query = 'SELECT c.* FROM ' . get_table_prefix() . 'catalogues c';
     if (can_arbitrary_groupby()) {
         $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name';
     }
     $_catalogues = $GLOBALS['SITE_DB']->query($query);
     $catalogues = array();
     foreach ($_catalogues as $catalogue) {
         $catalogues[$catalogue['c_name']] = $catalogue;
     }
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (count($_categories) == 300 && !array_key_exists($row['cc_id'], $categories)) {
             $val = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT cc_title FROM ' . get_table_prefix() . 'catalogue_categories WHERE id=' . strval($row['cc_id']) . ' AND (' . $filters_1 . ')');
             if (!is_null($val)) {
                 $categories[$row['cc_id']] = get_translated_text($val);
             }
         }
         if (!array_key_exists($row['cc_id'], $categories)) {
             continue;
         }
         // The catalogue was filtered out, thus category not known
         $_category = $categories[$row['cc_id']];
         if (has_category_access(get_member(), 'catalogues_catalogue', $_category['c_name']) && (get_value('disable_cat_cat_perms') === '1' || has_category_access(get_member(), 'catalogues_category', strval($row['cc_id'])))) {
             if (!isset($catalogues[$_category['c_name']])) {
                 continue;
             }
             $id = strval($row['id']);
             $author = $GLOBALS['FORUM_DRIVER']->get_username($row['ce_submitter']);
             if (is_null($author)) {
                 $author = '';
             }
             $news_date = date($date_string, $row['ce_add_date']);
             $edit_date = is_null($row['ce_edit_date']) ? '' : date($date_string, $row['ce_edit_date']);
             $tpl_set = $_category['c_name'];
             $map = get_catalogue_entry_map($row, $catalogues[$_category['c_name']], 'PAGE', $tpl_set, db_get_first_id());
             $_title = $map['FIELD_0'];
             $news_title = xmlentities(is_object($_title) ? $_title->evaluate() : escape_html($_title));
             if (array_key_exists('FIELD_1', $map)) {
                 $summary = xmlentities(is_object($map['FIELD_1']) ? $map['FIELD_1']->evaluate() : escape_html($map['FIELD_1']));
             } else {
                 $summary = '';
             }
             $news = '';
             $category = $_category['text_original'];
             $category_raw = strval($row['cc_id']);
             $view_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $row['id']), get_module_zone('catalogues'), NULL, false, false, true);
             if ($prefix == 'RSS_' && get_option('is_on_comments') == '1' && $row['allow_comments'] >= 1) {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'ee850d0e7f50b21f2dbe17cc49494baa', 'COMMENT_URL' => $view_url, 'ID' => strval($row['id'])));
             } else {
                 $if_comments = new ocp_tempcode();
             }
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     require_lang('catalogues');
     return array($content, do_lang('CATALOGUE_ENTRIES'));
 }
Exemplo n.º 8
0
/**
 * Get the personal post rows for the current member.
 *
 * @param  integer	The maximum number of rows to get (gets newest first).
 * @return array		The personal post rows (with corresponding topic details).
 */
function ocf_get_pp_rows($limit = 5)
{
    global $PP_ROWS;
    if (!is_null($PP_ROWS)) {
        return $PP_ROWS;
    }
    $member_id = get_member();
    //	return $GLOBALS['FORUM_DB']->query_select('f_topics t LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p ON p.p_topic_id=t.id',array('*'),NULL,'',1); // For testing
    $query = '';
    global $SITE_INFO;
    if (isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old')) {
        $query .= 'SELECT t.*,l.*,p.*,p.id AS p_id,t.id as t_id FROM
		' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON ( t.id = l_topic_id AND l_member_id =' . strval($member_id) . ' )
		JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON (p.id=t.t_cache_last_post_id OR p_intended_solely_for =' . strval($member_id) . ')
		WHERE
		t_cache_last_time > ' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND
		(t_pt_from =' . strval($member_id) . ' OR t_pt_to =' . strval($member_id) . ' OR p_intended_solely_for =' . strval($member_id) . ')
		AND (l_time IS NULL OR l_time < p_time)
		' . (can_arbitrary_groupby() ? ' GROUP BY t.id' : '');
    } else {
        // PT sent
        $query .= 'SELECT t.*,l.*,p.*,p.id AS p_id,t.id as t_id FROM
		' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON ( t.id = l_topic_id AND l_member_id =' . strval($member_id) . ' )
		JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON (p.id=t.t_cache_last_post_id)
		WHERE
		t_cache_last_time > ' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND
		t_pt_from =' . strval($member_id) . '
		AND (l_time IS NULL OR l_time < p_time)
		' . (can_arbitrary_groupby() ? ' GROUP BY t.id' : '');
        $query .= ' UNION ';
        // PT received
        $query .= 'SELECT t.*,l.*,p.*,p.id AS p_id,t.id as t_id FROM
		' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON ( t.id = l_topic_id AND l_member_id =' . strval($member_id) . ' )
		JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON (p.id=t.t_cache_last_post_id)
		WHERE
		t_cache_last_time > ' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND
		t_pt_to =' . strval($member_id) . '
		AND (l_time IS NULL OR l_time < p_time)
		' . (can_arbitrary_groupby() ? ' GROUP BY t.id' : '');
        $query .= ' UNION ';
        // Inline personal post
        $query .= 'SELECT t.*,l.*,p.*,p.id AS p_id,t.id as t_id FROM
		' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON ( t.id = l_topic_id AND l_member_id =' . strval($member_id) . ' )
		JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON (p_topic_id=t.id AND p_intended_solely_for =' . strval($member_id) . ')
		WHERE
		t_cache_last_time > ' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND
		p_intended_solely_for =' . strval($member_id) . '
		AND (l_time IS NULL OR l_time < p_time)
		' . (can_arbitrary_groupby() ? ' GROUP BY t.id' : '');
        $query .= ' UNION ';
        // Invited to PT
        $query .= 'SELECT t.*,l.*,p.*,p.id AS p_id,t.id as t_id FROM
		' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_special_pt_access i ON (i.s_topic_id=t.id)
		LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON ( t.id = l_topic_id AND l_member_id =' . strval($member_id) . ' )
		JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON (p.id=t.t_cache_last_post_id)
		WHERE
		t_cache_last_time > ' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND
		i.s_member_id =' . strval($member_id) . '
		AND (l_time IS NULL OR l_time < p_time)
		' . (can_arbitrary_groupby() ? ' GROUP BY t.id' : '');
    }
    $query .= ' ORDER BY t_cache_last_time DESC';
    $PP_ROWS = $GLOBALS['FORUM_DB']->query($query, $limit, NULL, false, true);
    $PP_ROWS = remove_duplicate_rows($PP_ROWS, 't_id');
    return $PP_ROWS;
}
Exemplo n.º 9
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($limit_to);
     if (!module_installed('catalogues')) {
         return array();
     }
     $remapped_orderer = '';
     switch ($sort) {
         case 'rating':
             $remapped_orderer = '_rating:catalogues:id';
             break;
         case 'title':
             $remapped_orderer = 'b_cv_value';
             break;
         case 'add_date':
             $remapped_orderer = 'ce_add_date';
             break;
         case 'relevance':
             break;
         default:
             $remapped_orderer = preg_replace('#[^\\w]#', '', $sort);
             break;
     }
     require_code('catalogues');
     require_lang('catalogues');
     // Calculate our where clause (search)
     $sq = build_search_submitter_clauses('ce_submitter', $author_id, $author);
     if (is_null($sq)) {
         return array();
     } else {
         $where_clause .= $sq;
     }
     if (!is_null($cutoff)) {
         $where_clause .= ' AND ';
         $where_clause .= 'r.ce_add_date>' . strval($cutoff);
     }
     if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $where_clause .= ' AND ';
         $where_clause .= 'z.category_name IS NOT NULL';
         $where_clause .= ' AND ';
         $where_clause .= 'p.category_name IS NOT NULL';
     }
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $where_clause .= ' AND ';
         $where_clause .= 'ce_validated=1';
     }
     $g_or = _get_where_clause_groups(get_member());
     // Calculate and perform query
     $catalogue_name = get_param('catalogue_name', '');
     $ranges = array();
     if ($catalogue_name != '') {
         $extra_select = '';
         $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id', 'cf_name', 'cf_type', 'cf_default'), array('c_name' => $catalogue_name, 'cf_searchable' => 1), 'ORDER BY cf_order');
         $table = 'catalogue_entries r';
         $trans_fields = array('!');
         $nontrans_fields = array();
         $title_field = mixed();
         require_code('fields');
         foreach ($rows as $i => $row) {
             $ob = get_fields_hook($row['cf_type']);
             $temp = $ob->inputted_to_sql_for_search($row, $i);
             if (is_null($temp)) {
                 list(, , $row_type) = $ob->get_field_value_row_bits($row);
                 switch ($row_type) {
                     case 'long_trans':
                         $trans_fields[] = 'f' . strval($i) . '.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_long_trans f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 't' . strval(count($trans_fields) - 1) . '.text_original';
                         //$extra_select.=',t'.strval(count($trans_fields)-1).'.text_original AS f'.strval($i).'_actual_value';
                         break;
                     case 'short_trans':
                         $trans_fields[] = 'f' . strval($i) . '.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_short_trans f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 't' . strval(count($trans_fields) - 1) . '.text_original';
                         //$extra_select.=',t'.strval(count($trans_fields)-1).'.text_original AS f'.strval($i).'_actual_value';
                         break;
                     case 'long':
                         $nontrans_fields[] = 'f' . strval($i) . '.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_long f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 'f' . strval($i) . '.cv_value';
                         //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value';
                         break;
                     case 'short':
                         $nontrans_fields[] = 'f' . strval($i) . '.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_short f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 'f' . strval($i) . '.cv_value';
                         //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value';
                         break;
                     case 'float':
                         //$nontrans_fields[]='f'.strval($i).'.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_float f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 'f' . strval($i) . '.cv_value';
                         //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value';
                         break;
                     case 'integer':
                         //$nontrans_fields[]='f'.strval($i).'.cv_value';
                         $table .= ' JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_integer f' . strval($i) . ' ON (f' . strval($i) . '.ce_id=r.id AND f' . strval($i) . '.cf_id=' . strval($row['id']) . ')';
                         $search_field = 'f' . strval($i) . '.cv_value';
                         //$extra_select.=',f'.strval($i).'.cv_value AS f'.strval($i).'_actual_value';
                         break;
                 }
                 $param = get_param('option_' . strval($row['id']), '');
                 if ($param != '') {
                     $where_clause .= ' AND ';
                     if (substr($param, 0, 1) == '=') {
                         $where_clause .= db_string_equal_to($search_field, substr($param, 1));
                     } elseif ($row_type == 'integer' || $row_type == 'float') {
                         if (is_numeric($param)) {
                             $where_clause .= $search_field . '=' . $param;
                         } else {
                             $where_clause .= db_string_equal_to($search_field, $param);
                         }
                     } else {
                         if (db_has_full_text($GLOBALS['SITE_DB']->connection_read) && method_exists($GLOBALS['SITE_DB']->static_ob, 'db_has_full_text_boolean') && $GLOBALS['SITE_DB']->static_ob->db_has_full_text_boolean() && !is_under_radar($param)) {
                             $temp = db_full_text_assemble($param, true);
                         } else {
                             $temp = db_like_assemble($param);
                         }
                         $where_clause .= preg_replace('#\\?#', $search_field, $temp);
                     }
                 } else {
                     $param = get_param('option_' . strval($row['id']) . '_ranged', '');
                     if ($param != '') {
                         $ranges[$row['id']] = $param;
                     }
                 }
             } else {
                 $table .= $temp[2];
                 $search_field = $temp[3];
                 if ($temp[4] != '') {
                     $where_clause .= ' AND ';
                     $where_clause .= $temp[4];
                 } else {
                     $trans_fields = array_merge($trans_fields, $temp[0]);
                     $non_trans_fields = array_merge($nontrans_fields, $temp[1]);
                 }
             }
             if ($i == 0) {
                 $title_field = $search_field;
             }
         }
         $where_clause .= ' AND ';
         $where_clause .= db_string_equal_to('r.c_name', $catalogue_name);
         if (is_null($title_field)) {
             return array();
         }
         // No fields in catalogue -- very odd
         if ($g_or == '') {
             $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, $table, $trans_fields, $where_clause, $content_where, str_replace('b_cv_value', $title_field, $remapped_orderer), 'r.*,r.id AS id,r.cc_id AS r_cc_id,' . $title_field . ' AS b_cv_value' . $extra_select, $nontrans_fields);
         } else {
             $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, $table . ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access z ON (' . db_string_equal_to('z.module_the_name', 'catalogues_category') . ' AND z.category_name=r.cc_id AND ' . str_replace('group_id', 'z.group_id', $g_or) . ') LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access p ON (' . db_string_equal_to('p.module_the_name', 'catalogues_catalogue') . ' AND p.category_name=r.c_name AND ' . str_replace('group_id', 'p.group_id', $g_or) . ')', $trans_fields, $where_clause, $content_where, str_replace('b_cv_value', $title_field, $remapped_orderer), 'r.*,r.id AS id,r.cc_id AS r_cc_id,' . $title_field . ' AS b_cv_value' . $extra_select, $nontrans_fields);
         }
     } else {
         if ($GLOBALS['SITE_DB']->query_value('translate', 'COUNT(*)') > 10000) {
             $trans_fields = array();
             $join = ' JOIN ' . get_table_prefix() . 'catalogue_efv_short c ON (r.id=c.ce_id AND f.id=c.cf_id)';
             $_remapped_orderer = str_replace('b_cv_value', 'c.cv_value', $remapped_orderer);
             $extra_select = '';
             $non_trans_fields = array('c.cv_value');
         } else {
             $join = ' LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_short_trans a ON (r.id=a.ce_id AND f.id=a.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_long_trans b ON (r.id=b.ce_id AND f.id=b.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_long d ON (r.id=d.ce_id AND f.id=d.cf_id) LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_short c ON (r.id=c.ce_id AND f.id=c.cf_id)';
             //' LEFT JOIN '.get_table_prefix().'catalogue_efv_float g ON (r.id=g.ce_id AND f.id=g.cf_id) LEFT JOIN '.get_table_prefix().'catalogue_efv_integer h ON (r.id=h.ce_id AND f.id=h.cf_id)';
             $trans_fields = array('a.cv_value', 'b.cv_value');
             $_remapped_orderer = str_replace('b_cv_value', 'b.cv_value', $remapped_orderer);
             $extra_select = ',b.cv_value AS b_cv_value';
             $non_trans_fields = array('c.cv_value', 'd.cv_value');
         }
         $where_clause .= ' AND ';
         $where_clause .= 'r.c_name NOT LIKE \'\\_%\'';
         // Don't want results drawn from the hidden custom-field catalogues
         if ($g_or == '') {
             $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'catalogue_fields f LEFT JOIN ' . get_table_prefix() . 'catalogue_entries r ON (r.c_name=f.c_name)' . $join, $trans_fields, $where_clause, $content_where, $_remapped_orderer, 'r.*,r.id AS id,r.cc_id AS r_cc_id' . $extra_select, $non_trans_fields);
         } else {
             $rows = get_search_rows('catalogue_entry', 'id', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'catalogue_fields f LEFT JOIN ' . get_table_prefix() . 'catalogue_entries r ON (r.c_name=f.c_name)' . $join . ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access z ON (' . db_string_equal_to('z.module_the_name', 'catalogues_category') . ' AND z.category_name=r.cc_id AND ' . str_replace('group_id', 'z.group_id', $g_or) . ') LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access p ON (' . db_string_equal_to('p.module_the_name', 'catalogues_catalogue') . ' AND p.category_name=r.c_name AND ' . str_replace('group_id', 'p.group_id', $g_or) . ')', $trans_fields, $where_clause, $content_where, $_remapped_orderer, 'r.*,r.id AS id,r.cc_id AS r_cc_id' . $extra_select, $non_trans_fields);
         }
     }
     $out = array();
     if (count($rows) == 0) {
         return array();
     }
     global $SEARCH_CATALOGUE_ENTRIES_CATALOGUES;
     $query = 'SELECT c.* FROM ' . get_table_prefix() . 'catalogues c';
     if (can_arbitrary_groupby()) {
         $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name';
     }
     $_catalogues = $GLOBALS['SITE_DB']->query($query);
     foreach ($_catalogues as $catalogue) {
         $SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue['c_name']] = $catalogue;
     }
     if (count($ranges) != 0) {
         foreach ($rows as $i => $row) {
             $out[$i]['data'] = $row;
             unset($rows[$i]);
             $catalogue_name = $row['c_name'];
             $tpl_set = $catalogue_name;
             $display = get_catalogue_entry_map($row, $SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue_name], 'PAGE', $tpl_set, -1);
             foreach ($ranges as $range_id => $range_key) {
                 $bits = explode('-', $display['_FIELD_' . strval($range_id)]);
                 if (count($bits) == 2) {
                     if (intval($bits[0]) >= intval($range_key) || intval($bits[1]) <= intval($range_key)) {
                         $out[$i]['restricted'] = true;
                         continue 2;
                     }
                 }
             }
             //$out[$i]['template']=do_template('CATALOGUE_'.$tpl_set.'_ENTRY_EMBED',$display,NULL,false,'CATALOGUE_DEFAULT_ENTRY_EMBED');//put_in_table(hyperlink($url,do_lang('_HERE')),'internal','middle','WIDE',1,do_lang('CATALOGUE_ENTRY').' ('.do_lang('IN',get_translated_text($catalogue['c_title'])).')');
             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'];
             }
         }
     } else {
         foreach ($rows as $i => $row) {
             $out[$i]['data'] = $row;
             unset($rows[$i]);
             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'];
             }
         }
     }
     return $out;
 }
Exemplo n.º 10
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_css('news');
     require_css('side_blocks');
     $max = array_key_exists('param', $map) ? intval($map['param']) : 5;
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news');
     require_lang('news');
     $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1;
     $historic = array_key_exists('historic', $map) ? $map['historic'] : '';
     $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : '';
     global $NEWS_CATS;
     if (!isset($NEWS_CATS)) {
         $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
         $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     }
     $content = new ocp_tempcode();
     // News Query
     require_code('ocfiltering');
     $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*');
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     if ($blogs === 0) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= 'nc_owner IS NULL';
     } elseif ($blogs === 1) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= '(nc_owner IS NOT NULL)';
     }
     if ($blogs != -1) {
         $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     } else {
         $join = '';
     }
     if ($filter_and != '') {
         $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
         // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
         $filters_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
         // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
         $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')';
     }
     if ($historic == '') {
         $news = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC', $max);
     } else {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         do {
             $_rows = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start);
             $news = array();
             foreach ($_rows as $row) {
                 $ok = false;
                 switch ($historic) {
                     case 'month':
                         if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'week':
                         if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'day':
                         if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                 }
                 if ($ok) {
                     if (count($news) < $max) {
                         $news[] = $row;
                     } else {
                         break;
                     }
                 }
             }
             $start += 200;
         } while (count($_rows) == 200 && count($news) < $max);
         unset($_rows);
     }
     $news = remove_duplicate_rows($news, 'id');
     $_title = do_lang_tempcode($blogs === 1 ? 'BLOGS_POSTS' : 'NEWS');
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     foreach ($news as $myrow) {
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $url_map = array('page' => 'news', 'type' => 'view', 'id' => $myrow['id']);
             if ($filter != '*') {
                 $url_map['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $url_map['filter_and'] = $filter_and;
             }
             if ($blogs === 1) {
                 $url_map['blog'] = 1;
             }
             $full_url = build_url($url_map, $zone);
             $news_title = get_translated_tempcode($myrow['title']);
             $date = locale_filter(date('d M', utctime_to_usertime($myrow['date_and_time'])));
             $summary = get_translated_tempcode($myrow['news']);
             if ($summary->is_empty()) {
                 $summary = get_translated_tempcode($myrow['news_article']);
             }
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1);
                 if (array_key_exists(0, $_news_cats)) {
                     $NEWS_CATS[$myrow['news_category']] = $_news_cats[0];
                 }
             }
             $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']);
             $content->attach(do_template('BLOCK_SIDE_NEWS_SUMMARY', array('_GUID' => 'f7bc5288680e68641ca94ca4a3111d4a', 'IMG_URL' => find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']), 'AUTHOR' => $myrow['author'], 'ID' => strval($myrow['id']), 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'BLOG' => $blogs === 1, 'FULL_URL' => $full_url, 'NEWS' => $summary, 'NEWS_TITLE' => $news_title, '_DATE' => strval($myrow['date_and_time']), 'DATE' => $date)));
         }
     }
     $tmp = array('page' => 'news', 'type' => 'misc');
     if ($filter != '*') {
         $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter;
     }
     if ($filter_and != '*' && $filter_and != '') {
         $tmp['filter_and'] = $filter_and;
     }
     if ($blogs != -1) {
         $tmp['blog'] = $blogs;
     }
     $archive_url = build_url($tmp, $zone);
     $_is_on_rss = get_option('is_rss_advertised', true);
     $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss);
     // Set to zero if we don't want to show RSS links
     $submit_url = new ocp_tempcode();
     if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) {
         $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT);
         if (is_numeric($filter)) {
             $map2['cat'] = $filter;
             // select news cat by default, if we are only showing one news cat in this block
         } elseif ($filter != '*') {
             $pos_a = strpos($filter, ',');
             $pos_b = strpos($filter, '-');
             if ($pos_a !== false) {
                 $first_cat = substr($filter, 0, $pos_a);
             } elseif ($pos_b !== false) {
                 $first_cat = substr($filter, 0, $pos_b);
             } else {
                 $first_cat = '';
             }
             if (is_numeric($first_cat)) {
                 $map2['cat'] = $first_cat;
             }
         }
         $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news'));
     }
     return do_template('BLOCK_SIDE_NEWS', array('_GUID' => '611b83965c4b6e42fb4a709d94c332f7', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $content, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url));
 }
Exemplo n.º 11
0
 /**
  * The UI to choose a page to edit.
  *
  * @return tempcode		The UI
  */
 function ed()
 {
     $title = get_page_title('COMCODE_PAGE_EDIT');
     $lang = choose_language($title, true);
     if (is_object($lang)) {
         return $lang;
     }
     require_code('form_templates');
     $add_new_permission = has_specific_permission(get_member(), 'submit_highrange_content');
     if (!$add_new_permission && !has_specific_permission(get_member(), 'edit_highrange_content') && !has_specific_permission(get_member(), 'edit_own_highrange_content')) {
         check_edit_permission('high', NULL);
     }
     $fields = new ocp_tempcode();
     if ($add_new_permission) {
         $fields->attach(form_input_line(do_lang_tempcode('NEW'), do_lang_tempcode('DESCRIPTION_NEW_COMCODE_PAGE'), 'page_link_2', '', true));
         $submit_name = do_lang_tempcode('ADD');
     } else {
         $submit_name = NULL;
     }
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('lang', $lang));
     $hidden->attach(form_input_hidden('type', '_ed'));
     $hidden->attach(build_keep_form_fields('_SELF'));
     $map = array('page' => '_SELF', 'type' => '_ed', 'lang' => $lang);
     $post_url = build_url($map, '_SELF', NULL, false, true);
     breadcrumb_set_self(do_lang_tempcode('CHOOSE'));
     $search_url = build_url(array('page' => 'search', 'id' => 'comcode_pages'), get_module_zone('search'));
     $sitemap_zone = get_page_zone('sitemap', false);
     if ($sitemap_zone !== NULL) {
         $archive_url = build_url(array('page' => 'sitemap'), $sitemap_zone);
     } else {
         $archive_url = build_url(array('page' => ''), '');
     }
     $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_LIST_EXTRA', escape_html($search_url->evaluate()), escape_html($archive_url->evaluate())));
     if (addon_installed('page_management')) {
         if (has_actual_page_access(get_member(), 'admin_sitetree')) {
             $page_wizard = build_url(array('page' => 'admin_sitetree', 'type' => 'pagewizard'), get_module_zone('admin_sitetree'));
             $site_tree_editor = build_url(array('page' => 'admin_sitetree', 'type' => 'site_tree'), get_module_zone('admin_sitetree'));
             attach_message(do_lang_tempcode('SUGGEST_PAGE_WIZARD', escape_html($page_wizard->evaluate()), escape_html($site_tree_editor->evaluate())), 'inform');
         }
     }
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'page_title ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('page_title' => do_lang_tempcode('TITLE'), 'page' => do_lang_tempcode('PAGE'), 'zone_name' => do_lang_tempcode('ZONE'), 'pagelink' => do_lang_tempcode('PAGE_LINK'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('TITLE'), do_lang_tempcode('PAGE'), do_lang_tempcode('ZONE'), do_lang_tempcode('PAGE_LINK'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $all_zones = find_all_zones(false, true);
     $number_pages_parsed_for_titles = 0;
     $GLOBALS['NO_QUERY_LIMIT'] = true;
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 50);
     $filesarray = $this->get_comcode_files_array($lang);
     if (count($filesarray) >= 300) {
         $orderer = 'p_add_date ASC';
         switch ($sortable) {
             case 'page_title':
                 $orderer = 't.text_original ' . $sort_order;
                 break;
             case 'page':
                 $orderer = 'c.the_page ' . $sort_order;
                 break;
             case 'zone_name':
                 $orderer = 'c.the_zone ' . $sort_order;
                 break;
             case 'pagelink':
                 $orderer = 'c.the_zone ' . $sort_order . ',c.the_page ' . $sort_order;
                 break;
         }
         $group_by = '';
         if (can_arbitrary_groupby()) {
             $group_by = 'GROUP BY c.the_zone,c.the_page';
         }
         $where_map = '(' . db_string_equal_to('language', $lang) . ' OR language IS NULL)';
         if (!has_specific_permission(get_member(), 'edit_highrange_content')) {
             $where_map .= ' AND submitter=' . strval(get_member());
         }
         $ttable = get_table_prefix() . 'comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=a.cc_page_title';
         $page_rows = $GLOBALS['SITE_DB']->query('SELECT c.*,cc_page_title FROM ' . $ttable . ' WHERE ' . $where_map . $group_by . ' ORDER BY ' . $orderer, $max, $start);
         $max_rows = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(DISTINCT c.the_zone,c.the_page) FROM ' . $ttable . ' WHERE ' . $where_map);
         $filesarray = array();
         foreach ($page_rows as $row) {
             $located = _request_page($row['the_page'], $row['the_zone'], NULL, $lang);
             if ($located !== false) {
                 $filesarray[$row['the_zone'] . ':' . $row['the_page']] = array($row['the_zone'] . '/pages/' . strtolower($located[0]) . '/' . $row['the_page'], NULL, $row);
             }
         }
         $found_via_query = true;
     } else {
         $max_rows = 0;
         ksort($filesarray);
         $found_via_query = false;
     }
     // Render table rows
     $_table_rows = array();
     foreach ($filesarray as $pagelink => $path_bits) {
         list($zone, $page) = explode(':', $pagelink, 2);
         if (!is_string($page)) {
             $page = strval($page);
         }
         $edit_link = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $pagelink, 'lang' => $lang), '_SELF');
         $clone_link = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':', 'restore_from' => $path_bits[0] . '.txt', 'lang' => $lang), '_SELF');
         $zone_name = array_key_exists($zone, $all_zones) ? $all_zones[$zone][1] : $zone;
         // We need to separately read from DB to work out meta data?
         $row = mixed();
         if (!array_key_exists(2, $path_bits)) {
             $rows = $GLOBALS['SITE_DB']->query_select('comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone', array('c.*', 'cc_page_title'), array('c.the_zone' => $zone, 'c.the_page' => $page), '', 1);
             if (!array_key_exists(0, $rows) && $number_pages_parsed_for_titles < 15) {
                 $result = request_page($page, false, $zone, 'comcode_custom', true);
                 $rows = $GLOBALS['SITE_DB']->query_select('comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone', array('c.*', 'cc_page_title'), array('c.the_zone' => $zone, 'c.the_page' => $page), '', 1);
                 $number_pages_parsed_for_titles++;
             }
             $row = array_key_exists(0, $rows) ? $rows[0] : NULL;
         } else {
             $row = $path_bits[2];
         }
         // Work out meta data
         $page_title = do_lang_tempcode('NA_EM');
         if (!is_null($row)) {
             $username = protect_from_escaping($GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($row['p_submitter']));
             $parent_page = $row['p_parent_page'];
             $add_date = get_timezoned_date($row['p_add_date']);
             $validated = $row['p_validated'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('YES');
             if (!is_null($row['cc_page_title'])) {
                 $_page_title = get_translated_text($row['cc_page_title'], NULL, NULL, true);
                 if (!is_null($_page_title)) {
                     if ($_page_title != '') {
                         $page_title = make_string_tempcode($_page_title);
                     }
                 }
             }
         } else {
             $username = do_lang('UNKNOWN');
             $parent_page = '';
             $add_date = get_timezoned_date(filectime(get_file_base() . '/index.php'));
             $validated = do_lang_tempcode('YES');
         }
         $wrappable_pagelink = preg_replace('#([^ ]):([\\w\\-]{10,})$#', '${1}: ${2}', preg_replace('#(^[\\w\\-]{10,}):#', '${1}: ', $pagelink));
         $actions = do_template('COMCODE_PAGE_EDIT_ACTIONS', array('EDIT_URL' => $edit_link, 'CLONE_URL' => $clone_link));
         $_table_rows[] = array('page_title' => $page_title, 'page' => $page, 'zone' => $zone, 'zone_name' => $zone_name, 'pagelink' => $pagelink, 'wrappable_pagelink' => $wrappable_pagelink, 'actions' => $actions);
     }
     // Manual sorting
     global $M_SORT_KEY;
     $M_SORT_KEY = $sortable;
     usort($_table_rows, 'multi_sort');
     if ($sort_order == 'DESC') {
         $_table_rows = array_reverse($_table_rows);
     }
     $table_rows = new ocp_tempcode();
     if (!$found_via_query) {
         $max_rows = count($_table_rows);
     }
     foreach ($_table_rows as $i => $table_row) {
         if (!$found_via_query) {
             if ($i < $start) {
                 continue;
             }
             if ($i > $max + $start) {
                 break;
             }
         }
         $table_rows->attach(results_entry(array(protect_from_escaping(hyperlink(build_url(array('page' => $table_row['page']), $table_row['zone']), $table_row['page_title'])), protect_from_escaping(do_template('COMCODE_TELETYPE', array('CONTENT' => preg_replace('#([\\w\\d\\_]{22})#', '${1}<br />', escape_html($table_row['page']))))), protect_from_escaping(hyperlink(build_url(array('page' => ''), $table_row['zone']), $table_row['zone_name'], false, true)), protect_from_escaping(do_template('COMCODE_TELETYPE', array('CONTENT' => preg_replace('#([\\w\\d\\_]{22})#', '${1}<br />', escape_html($table_row['wrappable_pagelink']))))), protect_from_escaping($table_row['actions'])), true));
     }
     $table = results_table(do_lang('COMCODE_PAGES'), $start, 'start', $max, 'max', $max_rows, $header_row, $table_rows, $sortables, $sortable, $sort_order, 'sort', NULL, NULL, NULL, 8, 'fdgfdfdfdggfd', true);
     return do_template('TABLE_TABLE_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'TABLE' => $table, 'FIELDS' => $fields, 'POST_URL' => $post_url, 'GET' => true, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => $submit_name));
 }
Exemplo n.º 12
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_lang('ocf');
     require_css('news');
     $days = array_key_exists('param', $map) ? intval($map['param']) : 14;
     $multiplier = array_key_exists('multiplier', $map) ? floatval($map['multiplier']) : 0.5;
     $fallback_full = array_key_exists('fallback_full', $map) ? intval($map['fallback_full']) : 3;
     $fallback_archive = array_key_exists('fallback_archive', $map) ? intval($map['fallback_archive']) : 6;
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news');
     $historic = array_key_exists('historic', $map) ? $map['historic'] : '';
     $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : '';
     $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1;
     $member_based = array_key_exists('member_based', $map) && $map['member_based'] == '1';
     global $NEWS_CATS;
     if (!isset($NEWS_CATS)) {
         $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
         $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     }
     $days_full = floatval($days) * $multiplier;
     $days_outline = floatval($days) - $days_full;
     // News Query
     require_code('ocfiltering');
     $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*');
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     if ($blogs === 0) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= 'nc_owner IS NULL';
     } elseif ($blogs === 1) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= '(nc_owner IS NOT NULL)';
     }
     if ($blogs != -1) {
         $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     } else {
         $join = '';
     }
     if ($filter_and != '') {
         $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
         // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
         $filters_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
         // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
         $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')';
     }
     if ($historic == '') {
         $rows = $days_full == 0.0 ? array() : $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300);
         if (!array_key_exists(0, $rows)) {
             $rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_full);
             $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_archive, $fallback_full);
         } else {
             $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full + $days_outline)) . ' AND date_and_time<' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300);
         }
     } else {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         do {
             $_rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start);
             $rows = array();
             $rows2 = array();
             foreach ($_rows as $row) {
                 $ok = false;
                 switch ($historic) {
                     case 'month':
                         if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'week':
                         if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'day':
                         if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                 }
                 if ($ok) {
                     if (count($rows) < $fallback_full) {
                         $rows[] = $row;
                     } elseif (count($rows2) < $fallback_archive) {
                         $rows2[] = $row;
                     } else {
                         break 2;
                     }
                 }
             }
             $start += 200;
         } while (count($_rows) == 200);
         unset($_rows);
     }
     $rows = remove_duplicate_rows($rows, 'p_id');
     $i = 0;
     $news_text = new ocp_tempcode();
     while (array_key_exists($i, $rows)) {
         $myrow = $rows[$i];
         //		$categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['p_id']));
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $id = $myrow['p_id'];
             $date = get_timezoned_date($myrow['date_and_time']);
             $author_url = addon_installed('authors') && !$member_based ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $myrow['author']), get_module_zone('authors')) : new ocp_tempcode();
             $author = $myrow['author'];
             $news_title = get_translated_tempcode($myrow['title']);
             if (array_key_exists('show_in_full', $map) && $map['show_in_full'] == '1') {
                 $news = get_translated_tempcode($myrow['news_article']);
                 $truncate = false;
                 if ($news->is_empty()) {
                     $news = get_translated_tempcode($myrow['news']);
                 }
             } else {
                 $news = get_translated_tempcode($myrow['news']);
                 if ($news->is_empty()) {
                     $news = get_translated_tempcode($myrow['news_article']);
                     $truncate = true;
                 } else {
                     $truncate = false;
                 }
             }
             $tmp = array('page' => 'news', 'type' => 'view', 'id' => $id);
             if ($filter != '*') {
                 $tmp['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $tmp['filter_and'] = $filter_and;
             }
             if ($blogs != -1) {
                 $tmp['blog'] = $blogs;
             }
             $full_url = build_url($tmp, $zone);
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1);
                 if (array_key_exists(0, $_news_cats)) {
                     $NEWS_CATS[$myrow['news_category']] = $_news_cats[0];
                 }
             }
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS) || !array_key_exists('nc_title', $NEWS_CATS[$myrow['news_category']])) {
                 $myrow['news_category'] = db_get_first_id();
             }
             $img = find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']);
             if (is_null($img)) {
                 $img = '';
             }
             if ($myrow['news_image'] != '') {
                 $img = $myrow['news_image'];
                 if (url_is_local($img)) {
                     $img = get_custom_base_url() . '/' . $img;
                 }
             }
             $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']);
             $seo_bits = seo_meta_get_for('news', strval($id));
             $map2 = array('TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'ID' => strval($id), 'TRUNCATE' => $truncate, 'BLOG' => $blogs === 1, 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'IMG' => $img, 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'NEWS_TITLE' => $news_title, 'AUTHOR' => $author, 'AUTHOR_URL' => $author_url, 'NEWS' => $news, 'FULL_URL' => $full_url);
             if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
                 $map2['COMMENT_COUNT'] = '1';
             }
             $news_text->attach(do_template('NEWS_PIECE_SUMMARY', $map2));
         }
         $i++;
     }
     $j = 0;
     $news_text2 = new ocp_tempcode();
     while (array_key_exists($j, $rows2)) {
         $myrow = $rows2[$j];
         //		$categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['id']));
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $date = get_timezoned_date($myrow['date_and_time']);
             $tmp = array('page' => 'news', 'type' => 'view', 'id' => $myrow['p_id']);
             if ($filter != '*') {
                 $tmp['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $tmp['filter_and'] = $filter_and;
             }
             if ($blogs != -1) {
                 $tmp['blog'] = $blogs;
             }
             $url = build_url($tmp, $zone);
             $title = get_translated_tempcode($myrow['title']);
             $title_plain = get_translated_text($myrow['title']);
             $seo_bits = seo_meta_get_for('news', strval($myrow['p_id']));
             $map2 = array('_GUID' => 'd81bda3a0912a1e708af6bb1f503b296', 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'BLOG' => $blogs === 1, 'ID' => strval($myrow['p_id']), 'SUBMITTER' => strval($myrow['submitter']), 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'URL' => $url, 'TITLE_PLAIN' => $title_plain, 'TITLE' => $title);
             if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
                 $map2['COMMENT_COUNT'] = '1';
             }
             $news_text2->attach(do_template('NEWS_BRIEF', $map2));
         }
         $j++;
     }
     $tmp = array('page' => 'news', 'type' => 'misc');
     if ($filter != '*') {
         $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter;
     }
     if ($filter_and != '*' && $filter_and != '') {
         $tmp['filter_and'] = $filter_and;
     }
     if ($blogs != -1) {
         $tmp['blog'] = $blogs;
     }
     $archive_url = build_url($tmp, $zone);
     $_is_on_rss = get_option('is_rss_advertised', true);
     $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss);
     // Set to zero if we don't want to show RSS links
     $submit_url = new ocp_tempcode();
     if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) {
         $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT);
         if (is_numeric($filter)) {
             $map2['cat'] = $filter;
             // select news cat by default, if we are only showing one news cat in this block
         } elseif ($filter != '*') {
             $pos_a = strpos($filter, ',');
             $pos_b = strpos($filter, '-');
             if ($pos_a !== false) {
                 $first_cat = substr($filter, 0, $pos_a);
             } elseif ($pos_b !== false) {
                 $first_cat = substr($filter, 0, $pos_b);
             } else {
                 $first_cat = '';
             }
             if (is_numeric($first_cat)) {
                 $map2['cat'] = $first_cat;
             }
         }
         $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news'));
     }
     $_title = do_lang_tempcode($blogs == 1 ? 'BLOGS_POSTS' : 'NEWS');
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     if ($i == 0 && $j == 0) {
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '9d7065af4dd4026ffb34243fd931f99d', 'HIGH' => false, 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($blogs == 1 ? 'BLOG_NO_NEWS' : 'NO_NEWS'), 'ADD_NAME' => do_lang_tempcode($blogs == 1 ? 'ADD_NEWS_BLOG' : 'ADD_NEWS'), 'SUBMIT_URL' => $submit_url));
     }
     $atom_url = new ocp_tempcode();
     $rss_url = new ocp_tempcode();
     if ($is_on_rss == 1) {
         $atom_url = make_string_tempcode(find_script('backend') . '?type=atom&mode=news&filter=' . $filter);
         $atom_url->attach(symbol_tempcode('KEEP'));
         $rss_url = make_string_tempcode(find_script('backend') . '?type=rss2&mode=news&filter=' . $filter);
         $rss_url->attach(symbol_tempcode('KEEP'));
     }
     return do_template('BLOCK_MAIN_NEWS', array('_GUID' => '01f5fbd2b0c7c8f249023ecb4254366e', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $news_text, 'BRIEF' => $news_text2, 'FILTER' => $filter, 'ARCHIVE_URL' => $archive_url, 'SUBMIT_URL' => $submit_url, 'RSS_URL' => $rss_url, 'ATOM_URL' => $atom_url));
 }
Exemplo n.º 13
0
 /**
  * Standard modular new-style deep page-link finder function (does not return the main entry-points).
  *
  * @param  string  	Callback function to send discovered page-links to.
  * @param  MEMBER		The member we are finding stuff for (we only find what the member can view).
  * @param  integer	Code for how deep we are tunnelling down, in terms of whether we are getting entries as well as categories.
  * @param  string		Stub used to create page-links. This is passed in because we don't want to assume a zone or page name within this function.
  * @param  ?string	Where we're looking under (NULL: root of tree). We typically will NOT show a root node as there's often already an entry-point representing it.
  * @param  integer	Our recursion depth (used to calculate importance of page-link, used for instance by Google sitemap). Deeper is typically less important.
  * @param  ?array		Non-standard for API [extra parameter tacked on] (NULL: yet unknown). Contents of database table for performance.
  * @param  ?array		Non-standard for API [extra parameter tacked on] (NULL: yet unknown). Contents of database table for performance.
  */
 function get_sitemap_pagelinks($callback, $member_id, $depth, $pagelink_stub, $parent_pagelink = NULL, $recurse_level = 0, $category_data = NULL, $entry_data = NULL)
 {
     $parent_pagelink = $pagelink_stub . ':misc';
     // This is the entry-point we're under
     $_hooks = find_all_hooks('modules', 'search');
     foreach (array_keys($_hooks) as $hook) {
         require_code('hooks/modules/search/' . filter_naughty_harsh($hook));
         $object = object_factory('Hook_search_' . filter_naughty_harsh($hook), true);
         if (is_null($object)) {
             continue;
         }
         $info = $object->info();
         if (is_null($info)) {
             continue;
         }
         if ($hook == 'catalogue_entries' || array_key_exists('special_on', $info) || array_key_exists('special_off', $info) || method_exists($object, 'get_tree') || method_exists($object, 'ajax_tree')) {
             $kids = array();
             if ($hook == 'catalogue_entries') {
                 $query = 'SELECT c.c_title,c.c_name,t.text_original FROM ' . get_table_prefix() . 'catalogues c';
                 if (can_arbitrary_groupby()) {
                     $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name';
                 }
                 $query .= ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND c.c_title=t.id';
                 if (can_arbitrary_groupby()) {
                     $query .= ' GROUP BY c.c_name';
                 }
                 $rows = $GLOBALS['SITE_DB']->query($query);
                 foreach ($rows as $row) {
                     if (!has_category_access($member_id, 'catalogues_catalogue', $row['c_name'])) {
                         continue;
                     }
                     if (is_null($row['text_original'])) {
                         $row['text_original'] = get_translated_text($row['c_title']);
                     }
                     $pagelink = $pagelink_stub . 'misc:id=' . $hook . ':catalogue_name=' . $row['c_name'];
                     call_user_func_array($callback, array($pagelink, $pagelink_stub . 'misc:id=' . $hook, NULL, NULL, 0.2, $row['text_original']));
                     // Callback
                 }
             }
             $pagelink = $pagelink_stub . 'misc:id=' . $hook;
             call_user_func_array($callback, array($pagelink, $parent_pagelink, NULL, NULL, 0.2, $info['lang']));
             // Callback
         }
     }
 }
Exemplo n.º 14
0
 /**
  * The UI to show a list of catalogues to choose from.
  *
  * @return tempcode		The UI
  */
 function list_catalogues()
 {
     $title = get_page_title('CATALOGUES');
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=';
     $ecommerce = get_param_integer('ecommerce', NULL);
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 30);
     $query = 'FROM ' . get_table_prefix() . 'catalogues c';
     if (can_arbitrary_groupby()) {
         $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name';
     }
     $query .= ' WHERE ';
     $query .= is_null($ecommerce) ? '1=1' : 'c_ecommerce=' . strval($ecommerce);
     $query .= ' AND c.c_name NOT LIKE \'' . db_encode_like('\\_%') . '\'';
     $rows = $GLOBALS['SITE_DB']->query('SELECT c.* ' . $query . (can_arbitrary_groupby() ? ' GROUP BY c.c_name' : ''), $max, $start);
     $max_rows = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(DISTINCT c.c_name) ' . $query);
     $out = new ocp_tempcode();
     foreach ($rows as $myrow) {
         $first_category = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'MIN(id)', array('c_name' => $myrow['c_name'], 'cc_parent_id' => NULL));
         if (is_null($first_category)) {
             continue;
         }
         if (!has_category_access(get_member(), 'catalogues_catalogue', $myrow['c_name'])) {
             continue;
         }
         if ($myrow['c_is_tree'] == 1) {
             $url = build_url(array('page' => '_SELF', 'catalogue_name' => $myrow['c_name'], 'type' => 'category', 'id' => $first_category), '_SELF');
         } else {
             $url = build_url(array('page' => '_SELF', 'id' => $myrow['c_name'], 'type' => 'index'), '_SELF');
         }
         $name = get_translated_text($myrow['c_title']);
         $num_entries = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'COUNT(*)', array('c_name' => $myrow['c_name'], 'ce_validated' => 1));
         $num_children = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)', array('c_name' => $myrow['c_name']));
         if ($myrow['c_is_tree'] == 1) {
             $num_children--;
         }
         $description = get_translated_tempcode($myrow['c_description']);
         $display_string = do_lang_tempcode($myrow['c_is_tree'] == 1 ? 'CATEGORY_SUBORDINATE' : 'CATEGORY_SUBORDINATE_2', integer_format($num_entries), integer_format($num_children));
         $out->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('_GUID' => '082993547f051894a6b70eea8194df5f', 'NAME' => $name, 'DESCRIPTION' => $description, 'URL' => $url, 'TITLE' => '', 'COUNT' => $display_string)));
     }
     require_code('templates_results_browser');
     $results_browser = results_browser(do_lang_tempcode('CATALOGUES'), NULL, $start, 'start', $max, 'max', $max_rows, NULL, 'misc');
     return do_template('INDEX_SCREEN_FANCIER_SCREEN', array('_GUID' => '5af7dcb5bd26550ca6f26c2f9108f478', 'PRE' => '', 'POST' => '', 'RESULTS_BROWSER' => $results_browser, 'TITLE' => $title, 'CONTENT' => $out));
 }
Exemplo n.º 15
0
/**
 * Get some rows, queried from the database according to the search parameters.
 *
 * @param  ?ID_TEXT		The META type used by our content (NULL: Cannot support META search)
 * @param  ?ID_TEXT		The name of the field that retrieved META IDs will relate to (NULL: Cannot support META search)
 * @param  string			Search string
 * @param  boolean		Whether to do a boolean search.
 * @param  ID_TEXT		Boolean operator
 * @set OR AND
 * @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 to only search titles (as opposed to both titles and content)
 * @param  ID_TEXT		The table name
 * @param  array			The translateable fields to search over (or an ! which is skipped). The first of these must be the title field or an '!'; if it is '!' then the title field will be the first raw-field
 * @param  string			The WHERE clause
 * @param  string			The WHERE clause that applies specifically for content (this will be duplicated to check against multiple fields). ? refers to the yet-unknown field name
 * @param  ID_TEXT		What to order by
 * @param  string			What to select
 * @param  ?array			The non-translateable fields to search over (NULL: there are none)
 * @param  ?string		The permission module to check category access for (NULL: none)
 * @param  ?string		The field that specifies the permissions ID to check category access for (NULL: none)
 * @param  boolean		Whether the permissions field is a string
 * @return array			The rows found
 */
function get_search_rows($meta_type, $meta_id_field, $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, $table, $fields, $where_clause, $content_where, $order, $select = '*', $raw_fields = NULL, $permissions_module = NULL, $permissions_field = NULL, $permissions_field_is_string = false)
{
    if (substr($where_clause, 0, 5) == ' AND ') {
        $where_clause = substr($where_clause, 5);
    }
    if (substr($where_clause, -5) == ' AND ') {
        $where_clause = substr($where_clause, 0, strlen($where_clause) - 5);
    }
    $where_alternative_matches = array();
    $had_limit_imposed = false;
    if (!is_null($permissions_module) && !$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
        $g_or = _get_where_clause_groups(get_member());
        // this destroys mysqls query optimiser by forcing complexed OR's into the join, so we'll do this in PHP code
        //		$table.=' LEFT JOIN '.$GLOBALS['SITE_DB']->get_table_prefix().'group_category_access z ON ('.db_string_equal_to('z.module_the_name',$permissions_module).' AND z.category_name='.$permissions_field.(($g_or!='')?(' AND '.str_replace('group_id','z.group_id',$g_or)):'').')';
        //		$where_clause.=' AND ';
        //		$where_clause.='z.category_name IS NOT NULL';
        $cat_access = list_to_map('category_name', $GLOBALS['SITE_DB']->query('SELECT category_name FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_category_access WHERE ' . db_string_equal_to('module_the_name', $permissions_module) . ($g_or != '' ? ' AND (' . $g_or . ')' : '')));
    }
    if ($only_titles && array_key_exists(0, $fields) && $fields[0] == '') {
        return array();
    }
    if (is_null($raw_fields)) {
        $raw_fields = array();
    }
    $db = substr($table, 0, 2) != 'f_' ? $GLOBALS['SITE_DB'] : $GLOBALS['FORUM_DB'];
    // This is so for example catalogue_entries.php can use brackets in it's table specifier whilst avoiding the table prefix after the first bracket. A bit weird, but that's our convention and it does save a small amount of typing
    $table_clause = $db->get_table_prefix() . ($table[0] == '(' ? substr($table, 1) : $table);
    if ($table[0] == '(') {
        $table_clause = '(' . $table_clause;
    }
    $t_rows = array();
    $t_count = 0;
    // Rating ordering, via special encoding
    if (substr($order, 0, 7) == '_rating') {
        list(, $rating_type, $meta_rating_id_field) = explode(':', $order);
        $select .= ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', $rating_type) . ' AND rating_for_id=' . $meta_rating_id_field . ') AS compound_rating';
        $order = 'compound_rating';
    }
    $translate_join_type = get_value('alternate_search_join_type') === '1' ? 'LEFT JOIN' : 'JOIN';
    // Defined-keywords/tags search
    if (get_param_integer('keep_just_show_query', 0) == 0 && !is_null($meta_type) && $content != '') {
        $keywords_where = preg_replace('#\\?#', 'tm.text_original', build_content_where($content, $boolean_search, $boolean_operator, true));
        $keywords_where = str_replace(' AND (tm.text_original IS NOT NULL)', '', $keywords_where);
        // Not needed for translate joins, as these won't be NULL's. Fixes performance issue.
        if ($keywords_where != '') {
            if ($meta_id_field == 'the_zone:the_page') {
                $meta_join = 'm.meta_for_id=CONCAT(r.the_zone,\':\',r.the_page)';
            } else {
                $meta_join = 'm.meta_for_id=r.' . $meta_id_field;
            }
            $extra_join = '';
            foreach ($fields as $i => $field) {
                if ($field == '' || $field == '!' || strpos($select, 't1.text_original') === false) {
                    continue;
                }
                $extra_join .= ' ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate t' . strval($i) . ' ON t' . strval($i) . '.id=' . $field . ' AND ' . db_string_equal_to('t' . strval($i) . '.language', user_lang());
            }
            if (!db_has_subqueries($db->connection_read) || true) {
                $_keywords_query = $table_clause . ' LEFT JOIN ' . $db->get_table_prefix() . 'seo_meta m ON (' . db_string_equal_to('m.meta_for_type', $meta_type) . ' AND ' . $meta_join . ') ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate tm ON tm.id=m.meta_keywords AND ' . db_string_equal_to('tm.language', user_lang()) . $extra_join;
                $_keywords_query .= ' WHERE ' . $keywords_where;
                $_keywords_query .= $where_clause != '' ? ' AND ' . $where_clause : '';
            } else {
                $_keywords_query = $table_clause . ' LEFT JOIN ' . $db->get_table_prefix() . 'seo_meta m ON (' . db_string_equal_to('m.meta_for_type', $meta_type) . ' AND ' . $meta_join . ') ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate tm ON tm.id=m.meta_keywords AND ' . db_string_equal_to('tm.language', user_lang()) . $extra_join;
                $_keywords_query .= ' WHERE ' . $keywords_where;
                $_keywords_query .= $where_clause != '' ? ' AND tm.id IN (SELECT m.id FROM ' . $table_clause . ' LEFT JOIN ' . $db->get_table_prefix() . 'seo_meta m ON (' . db_string_equal_to('m.meta_for_type', $meta_type) . ' AND ' . $meta_join . ') ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate tm ON tm.id=m.meta_keywords AND ' . db_string_equal_to('tm.language', user_lang()) . ' WHERE ' . $where_clause . ' AND ' . $keywords_where . ')' : '';
            }
            $keywords_query = 'SELECT ' . $select . ' FROM ' . $_keywords_query;
            $_count_query_keywords_search = 'SELECT COUNT(*) FROM ' . $_keywords_query;
            $group_by_ok = can_arbitrary_groupby() && $meta_id_field === 'id';
            if (strpos($table, ' LEFT JOIN') === false) {
                $group_by_ok = false;
            }
            // Don't actually need to do a group by, as no duplication possible
            $keywords_query .= $group_by_ok ? ' GROUP BY r.id' : '';
            if ($order != '' && $order . ' ' . $direction != 'contextual_relevance DESC') {
                $keywords_query .= ' ORDER BY ' . $order;
                if ($direction == 'DESC') {
                    $keywords_query .= ' DESC';
                }
            }
            if ($group_by_ok) {
                $_count_query_keywords_search = str_replace('COUNT(*)', 'COUNT(DISTINCT r.id)', $_count_query_keywords_search);
            }
            $t_keyword_search_rows_count = $db->query_value_null_ok_full($_count_query_keywords_search);
            if ($t_keyword_search_rows_count > 500) {
                $t_keyword_search_rows = $db->query($keywords_query, $max + $start);
                $had_limit_imposed = true;
            } else {
                $t_keyword_search_rows = $db->query($keywords_query);
            }
            $t_count += $t_keyword_search_rows_count;
            $t_rows = array_merge($t_rows, $t_keyword_search_rows);
        } else {
            $_count_query_keywords_search = NULL;
        }
    } else {
        $_count_query_keywords_search = NULL;
    }
    $orig_table_clause = $table_clause;
    // Main content search
    if (!$only_search_meta) {
        if ($content_where != '' || preg_match('#t\\d+\\.text_original#', $where_clause) != 0 || preg_match('#t\\d+\\.text_original#', $select) != 0) {
            // Each of the fields represents an 'OR' match, so we put it together into a list ($where_alternative_matches) of specifiers for each. Hopefully we will 'UNION' them rather than 'OR' them as it is much more efficient in terms of table index usage
            $where_alternative_matches = array();
            foreach ($fields as $i => $field) {
                if (strpos($select, 't' . strval($i) . '.text_original') !== false || strpos($where_clause, 't' . strval($i) . '.text_original') !== false) {
                    $tc_add = ' ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate t' . strval($i) . ' ON t' . strval($i) . '.id=' . $field . ' AND ' . db_string_equal_to('t' . strval($i) . '.language', user_lang());
                    $orig_table_clause .= $tc_add;
                }
            }
            foreach ($fields as $i => $field) {
                if ($field == '' || $field == '!') {
                    continue;
                }
                if ($field == $order) {
                    $order = 't' . $i . '.text_original';
                }
                // Ah, remap to the textual equivalent then
                $tc_add = ' ' . $translate_join_type . ' ' . $db->get_table_prefix() . 'translate t' . strval($i) . ' ON t' . strval($i) . '.id=' . $field . ' AND ' . db_string_equal_to('t' . strval($i) . '.language', user_lang());
                if (strpos($orig_table_clause, $tc_add) !== false) {
                    $tc_add = '';
                }
                if (!$only_titles || $i == 0) {
                    $where_clause_2 = preg_replace('#\\?#', 't' . strval($i) . '.text_original', $content_where);
                    $where_clause_2 = str_replace(' AND (t' . strval($i) . '.text_original IS NOT NULL)', '', $where_clause_2);
                    // Not needed for translate joins, as these won't be NULL's. Fixes performance issue.
                    $where_clause_3 = $where_clause;
                    if ($table == 'f_members' && substr($field, 0, 6) == 'field_' && db_has_subqueries($db->connection_read)) {
                        $where_clause_3 .= ($where_clause == '' ? '' : ' AND ') . 'NOT EXISTS (SELECT * FROM ' . $db->get_table_prefix() . 'f_cpf_perms cpfp WHERE cpfp.member_id=r.id AND cpfp.field_id=' . substr($field, 6) . ' AND cpfp.guest_view=0)';
                    }
                    if ($order == '' && db_has_expression_ordering($db->connection_read) && $content_where != '') {
                        $_select = preg_replace('#\\?#', 't' . strval($i) . '.text_original', $content_where) . ' AS contextual_relevance';
                        $_select = str_replace(' AND (t' . strval($i) . '.text_original IS NOT NULL)', '', $_select);
                        // Not needed for translate joins, as these won't be NULL's. Fixes performance issue.
                    } else {
                        $_select = '1';
                    }
                    $_table_clause = $orig_table_clause . $tc_add;
                    $where_alternative_matches[] = array($where_clause_2, $where_clause_3, $_select, $_table_clause, 't' . strval($i));
                } else {
                    $_table_clause = $orig_table_clause . $tc_add;
                    $where_alternative_matches[] = array('1=0', '', '1', $_table_clause, 't' . strval($i));
                }
            }
            if ($content_where != '') {
                foreach ($raw_fields as $i => $field) {
                    if ($only_titles && $i != 0) {
                        break;
                    }
                    $where_clause_2 = preg_replace('#\\?#', $field, $content_where);
                    $where_clause_3 = $where_clause;
                    if ($table == 'f_members' && substr($field, 0, 6) == 'field_' && db_has_subqueries($db->connection_read)) {
                        $where_clause_3 .= ($where_clause == '' ? '' : ' AND ') . 'NOT EXISTS (SELECT * FROM ' . $db->get_table_prefix() . 'f_cpf_perms cpfp WHERE cpfp.member_id=r.id AND cpfp.field_id=' . substr($field, 6) . ' AND cpfp.guest_view=0)';
                    }
                    if ($order == '' && db_has_expression_ordering($db->connection_read) && $content_where != '') {
                        $_select = preg_replace('#\\?#', $field, $content_where) . ' AS contextual_relevance';
                    } else {
                        $_select = '1';
                    }
                    $_table_clause = $orig_table_clause;
                    $where_alternative_matches[] = array($where_clause_2, $where_clause_3, $_select, $_table_clause, NULL);
                }
            }
        }
        if (count($where_alternative_matches) == 0) {
            $where_alternative_matches[] = array($where_clause, '', '', $table_clause, NULL);
        } else {
            if ($order == '' && db_has_expression_ordering($db->connection_read) && $content_where != '') {
                $order = 'contextual_relevance DESC';
            }
        }
        // Work out main query
        global $SITE_INFO;
        if (isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old')) {
            $_query = '';
            foreach ($where_alternative_matches as $parts) {
                list($where_clause_2, $where_clause_3, $_select, , ) = $parts;
                $where_clause_3 = $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3);
                $select .= ($_select == '' ? '' : ',') . $_select;
                $_query .= $where_clause_3 != '' ? ($_query == '' ? ' WHERE ' : ' OR ') . $where_clause_3 : '';
            }
            $query = 'SELECT ' . $select . ' FROM ' . $table_clause . $_query;
        } else {
            $query = '';
            foreach ($where_alternative_matches as $parts) {
                list($where_clause_2, $where_clause_3, $_select, $_table_clause, $tid) = $parts;
                if ($query != '') {
                    $query .= ' LIMIT ' . strval($max);
                    $query .= ' UNION ';
                }
                if (!db_has_subqueries($db->connection_read) || is_null($tid) || $content_where == '' || true) {
                    $where_clause_3 = $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3);
                    $query .= 'SELECT ' . $select . ($_select == '' ? '' : ',') . $_select . ' FROM ' . $_table_clause . ($where_clause_3 == '' ? '' : ' WHERE ' . $where_clause_3);
                } else {
                    $query .= 'SELECT ' . $select . ($_select == '' ? '' : ',') . $_select . ' FROM ' . $_table_clause;
                    if ($where_clause_2 != '' || $where_clause_3 != '') {
                        $query .= ' WHERE ' . $where_clause_2;
                        $query .= $where_clause_3 != '' ? ($where_clause_2 == '' ? '' : ' AND ') . $tid . '.id IN (SELECT ' . $tid . '.id FROM ' . $_table_clause . ' WHERE ' . $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3) . ')' : '';
                    }
                }
            }
        }
        // Work out COUNT(*) query using one of a few possible methods. It's not efficient and stops us doing proper merge-sorting between content types (and possible not accurate - if we use an efficient but non-deduping COUNT strategy) if we have to use this, so we only do it if there are too many rows to fetch in one go.
        $_query = '';
        if (isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old') || strpos(get_db_type(), 'mysql') === false) {
            foreach ($where_alternative_matches as $parts) {
                list($where_clause_2, $where_clause_3, , $_table_clause, $tid) = $parts;
                if (!db_has_subqueries($db->connection_read) || is_null($tid) || $content_where == '' || true) {
                    $where_clause_3 = $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3);
                    $_query .= $where_clause_3 != '' ? ($_query == '' ? ' WHERE ' : ' OR ') . $where_clause_3 : '';
                } else {
                    if ($where_clause_2 != '' || $where_clause_3 != '') {
                        $_query .= ($_query == '' ? ' WHERE ' : ' OR ') . $where_clause_2;
                        $_query .= $where_clause_3 != '' ? ($where_clause_2 == '' ? '' : ' AND ') . $tid . '.id IN (SELECT ' . $tid . '.id FROM ' . $_table_clause . ' WHERE ' . $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3) . ')' : '';
                    }
                }
            }
            $_count_query_main_search = 'SELECT COUNT(*) FROM ' . $table_clause . $_query;
        } else {
            foreach ($where_alternative_matches as $parts) {
                list($where_clause_2, $where_clause_3, $_select, $_table_clause, $tid) = $parts;
                if ($_query != '') {
                    $_query .= '+';
                }
                if (!db_has_subqueries($db->connection_read) || is_null($tid) || $content_where == '' || true) {
                    $where_clause_3 = $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3);
                    $_query .= '(SELECT COUNT(*) FROM ' . $_table_clause . ($where_clause_3 == '' ? '' : ' WHERE ' . $where_clause_3) . ')';
                } else {
                    $_query .= '(SELECT COUNT(*) FROM ' . $_table_clause;
                    if ($where_clause_2 != '' || $where_clause_3 != '') {
                        $_query .= ' WHERE ' . $where_clause_2;
                        $_query .= $where_clause_3 != '' ? ($where_clause_2 == '' ? '' : ' AND ') . $tid . '.id IN (SELECT ' . $tid . '.id FROM ' . $_table_clause . ' WHERE ' . $where_clause_2 . ($where_clause_3 == '' ? '' : ($where_clause_2 == '' ? '' : ' AND ') . $where_clause_3) . ')' : '';
                    }
                    $_query .= ')';
                }
            }
            $_count_query_main_search = 'SELECT (' . $_query . ')';
        }
        $group_by_ok = can_arbitrary_groupby() && $meta_id_field === 'id';
        if (strpos($table, ' LEFT JOIN') === false) {
            $group_by_ok = false;
        }
        // Don't actually need to do a group by, as no duplication possible. We want to avoid GROUP BY as it forces MySQL to create a temporary table, slowing things down a lot.
        $query .= $group_by_ok ? ' GROUP BY r.id' : '';
        if ($order != '' && $order . ' ' . $direction != 'contextual_relevance DESC') {
            $query .= ' ORDER BY ' . $order;
            if ($direction == 'DESC' && substr($order, -4) != ' ASC' && substr($order, -5) != ' DESC') {
                $query .= ' DESC';
            }
        }
        if (get_param_integer('keep_show_query', 0) == 1) {
            attach_message($query, 'inform');
        }
        if (get_param_integer('keep_just_show_query', 0) == 1) {
            @ini_set('ocproducts.xss_detect', '0');
            header('Content-type: text/plain; charset=' . get_charset());
            exit($query);
        }
        if ($group_by_ok) {
            $_count_query_main_search = str_replace('COUNT(*)', 'COUNT(DISTINCT r.id)', $_count_query_main_search);
        }
        $t_main_search_rows_count = $db->query_value_null_ok_full($_count_query_main_search);
        if ($t_main_search_rows_count > 500) {
            $t_main_search_rows = $db->query($query, $max + $start, NULL, false, true);
            $had_limit_imposed = true;
        } else {
            $t_main_search_rows = $db->query($query, NULL, NULL, false, true);
        }
        if ($t_main_search_rows === NULL) {
            $t_main_search_rows = array();
        }
        // In case of a failed search query
        $t_count += $t_main_search_rows_count;
        $t_rows = array_merge($t_rows, $t_main_search_rows);
    } else {
        $t_main_search_rows = array();
    }
    // Clean results and return
    // NB: We don't use the count_query's any more (except when using huge data sets, see above), because you can't actually just add them because they overlap. So instead we fetch all results and throw some away.
    $t_rows = array_merge($t_rows, $t_main_search_rows);
    if (count($t_rows) > 0) {
        $t_rows_new = array();
        if (array_key_exists('id', $t_rows[0]) || array_key_exists('_primary_id', $t_rows[0])) {
            $done = array();
            foreach ($t_rows as $t_row) {
                if (array_key_exists('id', $t_row)) {
                    if (array_key_exists($t_row['id'], $done)) {
                        continue;
                    }
                    $done[$t_row['id']] = 1;
                } elseif (array_key_exists('_primary_id', $t_row)) {
                    if (array_key_exists($t_row['_primary_id'], $done)) {
                        continue;
                    }
                    $done[$t_row['_primary_id']] = 1;
                }
                $t_rows_new[] = $t_row;
            }
        } else {
            foreach ($t_rows as $t_row) {
                unset($t_row['contextual_relevance']);
                foreach ($t_rows_new as $_t_row) {
                    if ($_t_row == $t_row || array_key_exists('id', $t_row) && array_key_exists('id', $_t_row) && !array_key_exists('_primary_id', $t_row) && !array_key_exists('_primary_id', $_t_row) && $t_row['id'] == $_t_row['id'] || array_key_exists('_primary_id', $t_row) && array_key_exists('_primary_id', $_t_row) && $t_row['_primary_id'] == $_t_row['_primary_id']) {
                        continue 2;
                    }
                }
                $t_rows_new[] = $t_row;
            }
        }
        $t_rows = $t_rows_new;
    }
    if (get_param_integer('keep_show_query', 0) == 1) {
        if (array_key_exists(0, $t_rows) && array_key_exists('id', $t_rows[0])) {
            $results = var_export(array_unique(collapse_1d_complexity('id', $t_rows)), true);
        } else {
            $results = var_export($t_rows, true);
        }
        attach_message(do_lang('_RESULTS') . ': ' . $results, 'inform');
    }
    if (isset($cat_access)) {
        $before = count($t_rows);
        foreach ($t_rows as $i => $row) {
            if (!array_key_exists(@strval($row[$permissions_field]), $cat_access)) {
                unset($t_rows[$i]);
            }
        }
    }
    $final_result_rows = $t_rows;
    if (!$had_limit_imposed) {
        // More accurate, as filtered for dupes
        $t_count = count($t_rows);
    }
    $GLOBALS['TOTAL_RESULTS'] += $t_count;
    array_splice($final_result_rows, $max * 2 + $start);
    // We return more than max in case our search hook does some extra in-code filtering (Catalogues, Comcode pages). It shouldn't really but sometimes it has to, and it certainly shouldn't filter more than 50%. Also so our overall ordering can be better.
    return $final_result_rows;
}
Exemplo n.º 16
0
 /**
  * The UI to view the news archive.
  *
  * @return tempcode		The UI
  */
 function news_archive()
 {
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 20);
     $blog = get_param_integer('blog', NULL);
     require_code('ocfiltering');
     $filter = get_param('id', get_param('filter', '*'));
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     if ($blog === 1) {
         $title = get_page_title('BLOG_NEWS_ARCHIVE');
     } else {
         if (is_numeric($filter)) {
             $news_cat_title = $GLOBALS['SITE_DB']->query_select('news_categories', array('nc_title'), array('id' => intval($filter)), '', 1);
             if (array_key_exists(0, $news_cat_title)) {
                 $news_cat_title[0]['text_original'] = get_translated_text($news_cat_title[0]['nc_title']);
                 $title = get_page_title($news_cat_title[0]['text_original'], false);
             } else {
                 $title = get_page_title('NEWS_ARCHIVE');
             }
         } else {
             $title = get_page_title('NEWS_ARCHIVE');
         }
     }
     $filter_and = get_param('filter_and', '*');
     $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')';
     $join = $q_filter == '' ? '' : ' LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id';
     if ($blog === 1) {
         $q_filter .= ' AND c.nc_owner IS NOT NULL';
         $join .= ' LEFT JOIN ' . get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     } elseif ($blog === 0) {
         $q_filter .= ' AND c.nc_owner IS NULL AND c.id IS NOT NULL';
         $join .= ' LEFT JOIN ' . get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     }
     $query = 'SELECT *,p.id AS p_id FROM ' . get_table_prefix() . 'news p' . $join . ' WHERE ' . $q_filter . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1' : '') . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC';
     $rows = $GLOBALS['SITE_DB']->query($query, $max, $start);
     $rows = remove_duplicate_rows($rows, 'p_id');
     $max_rows = count(remove_duplicate_rows($GLOBALS['SITE_DB']->query($query), 'p_id'));
     // Not doing COUNT(*) because of the "GROUP BY" which messes with the query counting
     $rcount = count($rows);
     $blogger = NULL;
     $content = new ocp_tempcode();
     $inline = get_param_integer('inline', 0) == 1;
     $truncate = true;
     $member_based = $blog === 1;
     global $NEWS_CATS;
     if (!isset($NEWS_CATS)) {
         $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
         $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     }
     foreach ($rows as $myrow) {
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $date = get_timezoned_date($myrow['date_and_time']);
             $map = array('page' => '_SELF', 'type' => 'view', 'id' => $myrow['p_id']);
             if ($filter != '*') {
                 $map['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $map['filter_and'] = $filter_and;
             }
             if (!is_null($blog)) {
                 $map['blog'] = $blog;
             }
             $url = build_url($map, '_SELF');
             $_title = get_translated_tempcode($myrow['title']);
             $_title_plain = get_translated_text($myrow['title']);
             $author_url = addon_installed('authors') && !$member_based ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $myrow['author']), get_module_zone('authors')) : new ocp_tempcode();
             $author = $myrow['author'];
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1);
                 if (array_key_exists(0, $_news_cats)) {
                     $NEWS_CATS[$myrow['news_category']] = $_news_cats[0];
                 }
             }
             if (array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']);
                 $img = find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']);
             } else {
                 $category = '';
                 $img = '';
             }
             if (is_null($img)) {
                 $img = '';
             }
             if ($myrow['news_image'] != '') {
                 $img = $myrow['news_image'];
                 if (url_is_local($img)) {
                     $img = get_custom_base_url() . '/' . $img;
                 }
             }
             $summary = get_translated_tempcode($myrow['news']);
             if ($summary->is_empty()) {
                 $summary = get_translated_tempcode($myrow['news_article']);
             }
             $seo_bits = seo_meta_get_for('news', strval($myrow['id']));
             $map = array('_GUID' => 'a29bbea4a703287793e2b3b190114ec3', 'TAGS' => get_option('show_content_tagging_inline') == '1' ? get_loaded_tags('news', explode(',', $seo_bits[0])) : NULL, 'CATEGORY' => $category, 'IMG' => $img, 'AUTHOR_URL' => $author_url, 'AUTHOR' => $author, 'TRUNCATE' => $truncate, 'BLOG' => $blog === 1, 'NEWS' => $summary, 'SUMMARY' => $summary, 'ID' => strval($myrow['p_id']), 'VIEWS' => strval($myrow['news_views']), 'SUBMITTER' => strval($myrow['submitter']), 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'EDIT_DATE_RAW' => is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']), 'FULL_URL' => $url, 'URL' => $url, 'TITLE_PLAIN' => $_title_plain, 'NEWS_TITLE' => $_title, 'TITLE' => $_title);
             if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
                 $map['COMMENT_COUNT'] = '1';
             }
             $content->attach(do_template($inline ? 'NEWS_PIECE_SUMMARY' : 'NEWS_BRIEF', $map));
             if (array_key_exists('nc_owner', $myrow) && is_numeric($filter)) {
                 $blogger = $myrow['nc_owner'];
             }
         }
     }
     $page_num = intval(floor(floatval($start) / floatval($max))) + 1;
     $num_pages = intval(ceil(floatval($max_rows) / floatval($max)));
     $previous_url = $start == 0 ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'type' => 'misc', 'blog' => $blog, 'start' => $start - $max == 0 ? NULL : $start - $max) + ($filter == '*' ? array() : array('filter' => $filter)) + (($filter_and == '*' ? array() : array('filter_and' => $filter_and)) + ($max == 20 ? array() : array('max' => $max))), '_SELF');
     $next_url = $rcount != $max ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'type' => 'misc', 'blog' => $blog, 'start' => $start + $max) + ($filter == '*' ? array() : array('filter' => $filter)) + (($filter_and == '*' ? array() : array('filter_and' => $filter_and)) + ($max == 20 ? array() : array('max' => $max))), '_SELF');
     $browse = do_template('NEXT_BROWSER_BROWSE_NEXT', array('_GUID' => '264a8412dfd0b5bb80cd767702bdd600', 'NEXT_LINK' => $next_url, 'PREVIOUS_LINK' => $previous_url, 'PAGE_NUM' => integer_format($page_num), 'NUM_PAGES' => integer_format($num_pages)));
     if ($blog === 1) {
         $first_bc = array('_SELF:_SELF:blog_select', do_lang_tempcode('BLOGS'));
     } elseif ($blog === 0) {
         $first_bc = array('_SELF:_SELF:cat_select', do_lang_tempcode('JUST_NEWS_CATEGORIES'));
     } else {
         $first_bc = array('_SELF:_SELF:select', do_lang_tempcode('NEWS_CATEGORIES'));
     }
     breadcrumb_set_parents(array($first_bc));
     if (($blog !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blog === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), 'cms_news')) {
         $map = array('page' => $blog === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad');
         if (is_numeric($filter)) {
             $map['cat'] = $filter;
         }
         $submit_url = build_url($map, get_module_zone('cms_news'));
     } else {
         $submit_url = new ocp_tempcode();
     }
     return do_template('NEWS_ARCHIVE_SCREEN', array('_GUID' => '228918169ab1db445ee0c2d71f85983c', 'CAT' => is_numeric($filter) ? $filter : NULL, 'SUBMIT_URL' => $submit_url, 'BLOGGER' => is_null($blogger) ? NULL : strval($blogger), 'BLOG' => $blog === 1, 'TITLE' => $title, 'CONTENT' => $content, 'BROWSE' => $browse));
 }