예제 #1
0
파일: news.php 프로젝트: erico-deh/ocPortal
 /**
  * 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'));
 }
예제 #2
0
파일: news.php 프로젝트: erico-deh/ocPortal
 /**
  * Standard modular run function for newsletter hooks.
  *
  * @param  TIME				The time that the entries found must be newer than
  * @param  LANGUAGE_NAME	The language the entries found must be in
  * @param  string				Category filter to apply
  * @param  BINARY				Whether to use full article instead of summary
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter, $in_full = 1)
 {
     if (!addon_installed('news')) {
         return array();
     }
     require_lang('news');
     $new = new ocp_tempcode();
     require_code('ocfiltering');
     $or_list = ocfilter_to_sqlfragment($filter, 'news_category');
     $or_list_2 = ocfilter_to_sqlfragment($filter, 'news_entry_category');
     $rows = $GLOBALS['SITE_DB']->query('SELECT title,news,news_article,id,date_and_time,submitter FROM ' . get_table_prefix() . 'news LEFT JOIN ' . get_table_prefix() . 'news_category_entries ON news_entry=id WHERE validated=1 AND date_and_time>' . strval((int) $cutoff_time) . ' AND ((' . $or_list . ') OR (' . $or_list_2 . ')) ORDER BY date_and_time DESC', 300);
     if (count($rows) == 300) {
         return array();
     }
     $rows = remove_duplicate_rows($rows, 'id');
     foreach ($rows as $row) {
         $_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), get_module_zone('news'), NULL, false, false, true);
         $url = $_url->evaluate();
         $name = get_translated_text($row['title'], NULL, $lang);
         $description = get_translated_text($row[$in_full == 1 ? 'news_article' : 'news'], NULL, $lang);
         if ($description == '') {
             $description = get_translated_text($row[$in_full == 1 ? 'news' : 'news_article'], NULL, $lang);
         }
         $member_id = is_guest($row['submitter']) ? NULL : strval($row['submitter']);
         $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => '4eaf5ec00db1f0b89cef5120c2486521', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description)));
     }
     return array($new, do_lang('NEWS', '', '', '', $lang));
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * Actulizer to build csv from the selected filters
  *
  * @param  boolean	Whether to avoid exit (useful for unit test).
  */
 function _order_export($inline = false)
 {
     require_code('shopping');
     $start_date = get_input_date('start_date', true);
     $end_date = get_input_date('end_date', true);
     $order_status = post_param('order_status');
     $filename = 'Orders_' . $order_status . '__' . get_timezoned_date($start_date, false, false, false, true) . '-' . get_timezoned_date($end_date, false, false, false, true) . '.csv';
     $orders = array();
     $data = array();
     $cond = "t1.add_date BETWEEN " . strval($start_date) . " AND " . strval($end_date);
     if ($order_status != 'all') {
         $cond .= " AND t1.order_status='" . db_escape_string($order_status) . "'";
     }
     $qry = "SELECT t1.*,(t2.included_tax*t2.p_quantity) as \t\n\t\t\t\t\t\t\t\ttax_amt,t3.address_name,t3.address_street,t3.address_city,t3.address_zip,\n\t\t\t\t\t\t\t\tt3.address_country,t3.receiver_email\n\t\t\t\t\t\t\t\tFROM " . get_table_prefix() . "shopping_order t1\n\t\t\t\t\t\t\t\tLEFT JOIN " . get_table_prefix() . "shopping_order_details t2 ON t1.id = t2.order_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . get_table_prefix() . "shopping_order_addresses t3 ON t1.id = t3.order_id\n\t\t\t\t\t\t\t\tWHERE " . $cond;
     $row = $GLOBALS['SITE_DB']->query($qry);
     remove_duplicate_rows($row);
     foreach ($row as $order) {
         $orders[do_lang('ORDER_NUMBER')] = strval($order['id']);
         $orders[do_lang('ORDERED_DATE')] = get_timezoned_date($order['add_date'], true, false, true, true);
         $orders[do_lang('ORDER_PRICE')] = $order['tot_price'];
         $orders[do_lang('ORDER_STATUS')] = do_lang($order['order_status']);
         $orders[do_lang('ORDER_TAX_OPT_OUT')] = $order['tax_opted_out'] ? do_lang('YES') : do_lang('NO');
         $orders[do_lang('TOTAL_TAX_PAID')] = is_null($order['tax_amt']) ? float_format(0.0, 2) : float_format($order['tax_amt'], 2);
         $orders[do_lang('ORDERED_PRODUCTS')] = get_ordered_product_list_string($order['id']);
         $orders[do_lang('ORDERED_BY')] = $GLOBALS['FORUM_DRIVER']->get_username($order['c_member']);
         $address = array();
         $address['name'] = array_key_exists('address_name', $order) ? $order['address_name'] : NULL;
         $address['city'] = array_key_exists('address_city', $order) ? $order['address_city'] : NULL;
         $address['zip'] = array_key_exists('address_zip', $order) ? $order['address_zip'] : NULL;
         $address['country'] = array_key_exists('address_country', $order) ? $order['address_country'] : NULL;
         if (!is_null($address['name'])) {
             $full_address = implode(chr(10), $address);
         } else {
             $full_address = "";
         }
         $orders[do_lang('FULL_ADDRESS')] = $full_address;
         $data[] = $orders;
     }
     require_code('files2');
     make_csv($data, $filename, !$inline, !$inline);
 }
예제 #5
0
/**
 * Get a map of members viewing the specified ocPortal location.
 *
 * @param  ?ID_TEXT		The page they need to be viewing (NULL: don't care)
 * @param  ?ID_TEXT		The page-type they need to be viewing (NULL: don't care)
 * @param  ?SHORT_TEXT	The type-id they need to be viewing (NULL: don't care)
 * @param  boolean		Whether this has to be done over the forum driver (multi site network)
 * @return ?array			A map of member-ids to rows about them (except for guest, which is a count) (NULL: Too many)
 */
function get_members_viewing($page = NULL, $type = NULL, $id = NULL, $forum_layer = false)
{
    // Update the member tracking
    member_tracking_update();
    global $ZONE;
    if ($page === NULL) {
        $page = get_param('page', $ZONE['zone_default_page']);
    }
    if ($type === NULL) {
        $type = get_param('type', '/');
    }
    if ($id === NULL) {
        $id = get_param('id', '/', true);
    }
    if ($type == '/') {
        $type = '';
    }
    if ($id == '/') {
        $id = '';
    }
    $map = array();
    if ($page !== NULL && $page != '') {
        $map['mt_page'] = $page;
    }
    if ($type !== NULL && $type != '') {
        $map['mt_type'] = $type;
    }
    if ($id !== NULL && $id != '') {
        $map['mt_id'] = $id;
    }
    $map['session_invisible'] = 0;
    $db = $forum_layer ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $results = $db->query_select('member_tracking t LEFT JOIN ' . $db->get_table_prefix() . 'sessions s ON t.mt_member_id=s.the_user', array('*'), $map, ' AND mt_member_id<>' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' ORDER BY mt_member_id', 200);
    if (count($results) == 200) {
        return NULL;
    }
    unset($map['session_invisible']);
    $num_guests = $db->query_value('member_tracking t', 'COUNT(*)', $map, ' AND mt_member_id=' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()));
    $results = remove_duplicate_rows($results, 'mt_member_id');
    $out = array($GLOBALS['FORUM_DRIVER']->get_guest_id() => $num_guests);
    foreach ($results as $row) {
        if (!member_blocked(get_member(), $row['mt_member_id'])) {
            $out[$row['mt_member_id']] = $row;
        }
    }
    return $out;
}
예제 #6
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));
 }
예제 #7
0
파일: smf2.php 프로젝트: erico-deh/ocPortal
 /**
  * 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);
 }
예제 #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;
}
예제 #9
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));
 }
예제 #10
0
파일: ipb.php 프로젝트: erico-deh/ocPortal
 /**
  * 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_wordfilter($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'badwords');
     $rows = remove_duplicate_rows($rows, 'type');
     foreach ($rows as $row) {
         add_wordfilter_word($row['type'], $row['swop'], $row['m_exact']);
     }
 }
예제 #11
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));
 }
예제 #12
0
파일: news.php 프로젝트: erico-deh/ocPortal
 /**
  * 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));
 }