Пример #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('galleries')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'galleries')) {
         return NULL;
     }
     $filters_1 = ocfilter_to_sqlfragment($_filters, 'name', 'galleries', 'parent_id', 'name', 'name', false, false);
     // 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, 'cat', 'galleries', 'parent_id', 'cat', 'name', false, false);
     // 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_lang('galleries');
     $content = new ocp_tempcode();
     $_galleries = array();
     if ($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'galleries WHERE ' . $filters_1) < 3000) {
         $_galleries = $GLOBALS['SITE_DB']->query('SELECT fullname,name FROM ' . get_table_prefix() . 'galleries WHERE ' . $filters_1);
         foreach ($_galleries as $i => $_gallery) {
             $_galleries[$i]['text_original'] = get_translated_text($_gallery['fullname']);
         }
     }
     $galleries = collapse_2d_complexity('name', 'text_original', $_galleries);
     $rows1 = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'videos WHERE add_date>' . strval((int) $cutoff) . ' AND ' . $filters . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1 ' : '') . ' ORDER BY add_date DESC', $max);
     $rows2 = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'images WHERE add_date>' . strval((int) $cutoff) . ' AND ' . $filters . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1 ' : '') . ' ORDER BY add_date DESC', $max);
     $rows = array_merge($rows1, $rows2);
     foreach ($rows as $row) {
         $id = strval($row['id']);
         $author = $GLOBALS['FORUM_DRIVER']->get_username($row['submitter']);
         if (is_null($author)) {
             $author = '';
         }
         $news_date = date($date_string, $row['add_date']);
         $edit_date = is_null($row['edit_date']) ? '' : date($date_string, $row['edit_date']);
         $news_title = xmlentities(do_lang('THIS_WITH_SIMPLE', array_key_exists('video_views', $row) ? do_lang('VIDEO') : do_lang('IMAGE'), strval($row['id'])));
         $_summary = get_translated_tempcode($row['comments']);
         $summary = xmlentities($_summary->evaluate());
         $news = '';
         if (!array_key_exists($row['cat'], $galleries)) {
             $_fullname = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'fullname', array('name' => $row['cat']));
             if (is_null($_fullname)) {
                 continue;
             }
             $galleries[$row['cat']] = get_translated_text($_fullname);
         }
         $category = $galleries[$row['cat']];
         $category_raw = $row['cat'];
         $view_url = build_url(array('page' => 'galleries', 'type' => array_key_exists('video_views', $row) ? 'video' : 'image', 'id' => $row['id']), get_module_zone('galleries'), 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' => '65dc0cec8c75f565c58c95fa1667aa1e', 'COMMENT_URL' => $view_url, 'ID' => strval($row['id'])));
         } else {
             $if_comments = new ocp_tempcode();
         }
         require_code('images');
         $enclosure_url = ensure_thumbnail($row['url'], $row['thumb_url'], 'galleries', array_key_exists('video_views', $row) ? 'videos' : 'images', $row['id']);
         list($enclosure_length, $enclosure_type) = get_enclosure_details($row['url'], $enclosure_url);
         $content->attach(do_template($prefix . 'ENTRY', array('ENCLOSURE_URL' => $enclosure_url, 'ENCLOSURE_LENGTH' => $enclosure_length, 'ENCLOSURE_TYPE' => $enclosure_type, '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('galleries');
     return array($content, do_lang('GALLERIES'));
 }
Пример #2
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('downloads');
     require_css('downloads');
     require_lang('downloads');
     require_code('ocfiltering');
     $number = array_key_exists('param', $map) ? intval($map['param']) : 10;
     $filter = array_key_exists('filter', $map) ? $map['filter'] : '*';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('downloads');
     $sql_filter = ocfilter_to_sqlfragment($filter, 'p.category_id', 'download_categories', 'parent_id', 'p.category_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)
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'download_downloads p WHERE validated=1 AND (' . $sql_filter . ') ORDER BY add_date DESC', $number);
     $title = do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('SECTION_DOWNLOADS'));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $title = protect_from_escaping(escape_html($map['title']));
     }
     $out = new ocp_tempcode();
     foreach ($rows as $i => $row) {
         if ($i != 0) {
             $out->attach(do_template('BLOCK_SEPARATOR'));
         }
         $out->attach(get_download_html($row, true, true, $zone));
     }
     if ($out->is_empty()) {
         if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads')) {
             $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads'));
         } else {
             $submit_url = new ocp_tempcode();
         }
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '74399763a51102bdd6e6d92c2c11354f', 'HIGH' => false, 'TITLE' => $title, 'MESSAGE' => do_lang_tempcode('NO_DOWNLOADS_YET'), 'ADD_NAME' => do_lang_tempcode('ADD_DOWNLOAD'), 'SUBMIT_URL' => $submit_url));
     }
     return do_template('BLOCK_MAIN_RECENT_DOWNLOADS', array('_GUID' => '257fa1b83d1b6fe3acbceb2b618e6d7f', 'TITLE' => $title, 'CONTENT' => $out, 'NUMBER' => integer_format($number)));
 }
Пример #3
0
 /**
  * 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
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter)
 {
     $new = new ocp_tempcode();
     require_code('ocfiltering');
     if ($filter == '') {
         $filter = ',';
     }
     // Just welcome zone
     $or_list = ocfilter_to_sqlfragment($filter, 'b.the_zone', NULL, NULL, NULL, NULL, false);
     $_rows = $GLOBALS['SITE_DB']->query('SELECT a.* FROM ' . get_table_prefix() . 'cached_comcode_pages a JOIN ' . get_table_prefix() . 'comcode_pages b ON a.the_page=b.the_page AND a.the_zone=b.the_zone WHERE p_add_date>' . strval($cutoff_time) . ' AND (' . $or_list . ')', 300);
     if (count($_rows) == 300) {
         return array();
     }
     $rows = array();
     foreach ($_rows as $row) {
         $rows[$row['the_zone'] . ':' . $row['the_page']] = $row;
     }
     $_rows2 = $GLOBALS['SITE_DB']->query_select('seo_meta', array('*'), array('meta_for_type' => 'comcode_page'));
     $rows2 = array();
     foreach ($_rows2 as $row) {
         $rows2[$row['meta_for_id']] = $row;
     }
     $zones = explode(',', $filter);
     //find_all_zones();
     foreach ($zones as $zone) {
         if ($zone == 'cms') {
             continue;
         }
         if ($zone == 'adminzone') {
             continue;
         }
         $pages = find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt', false, $cutoff_time);
         foreach (array_keys($pages) as $page) {
             if (!is_string($page)) {
                 $page = strval($page);
             }
             // PHP can be weird when things like '404' are put in arrays
             if (substr($page, 0, 6) == 'panel_') {
                 continue;
             }
             $id = $zone . ':' . $page;
             $_url = build_url(array('page' => $page), $zone, NULL, false, false, true);
             $url = $_url->evaluate();
             $name = ucfirst(str_replace('_', ' ', $page));
             if (array_key_exists($id, $rows)) {
                 $_name = get_translated_text($rows[$id]['cc_page_title'], NULL, NULL, true);
                 if (!is_null($_name)) {
                     $name = $_name;
                 }
             }
             $description = '';
             $member_id = NULL;
             if (array_key_exists($id, $rows2)) {
                 $description = get_translated_text($rows2[$id]['meta_description']);
             }
             $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => '67f165847dacd54d2965686d561b57ee', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description)));
         }
     }
     return array($new, do_lang('PAGES', '', '', '', $lang));
 }
Пример #4
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('cedi')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'cedi')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'id', 'seedy_children', 'parent_id', 'parent_id', 'child_id');
     $content = new ocp_tempcode();
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'seedy_pages WHERE ' . $filters . ' AND add_date>' . strval((int) $cutoff) . ' ORDER BY add_date DESC', $max);
     foreach ($rows as $row) {
         $id = strval($row['id']);
         if (!has_category_access(get_member(), 'seedy_page', strval($row['id']))) {
             continue;
         }
         $author = '';
         $news_date = date($date_string, $row['add_date']);
         $edit_date = '';
         $news_title = xmlentities(escape_html(get_translated_text($row['title'])));
         $_summary = get_translated_tempcode($row['description']);
         $summary = xmlentities($_summary->evaluate());
         $news = '';
         $category = '';
         $category_raw = '';
         $view_url = build_url(array('page' => 'cedi', 'type' => 'misc', 'id' => $row['id'] == db_get_first_id() ? NULL : $row['id']), get_module_zone('cedi'), NULL, false, false, true);
         $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('cedi');
     return array($content, do_lang('CEDI_PAGES'));
 }
Пример #5
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'max';
     $category_id = array_key_exists('param', $map) ? intval($map['param']) : db_get_first_id();
     $max = get_param_integer('max', array_key_exists('max', $map) ? intval($map['max']) : 30);
     $start = get_param_integer('start', 0);
     $root = array_key_exists('root', $map) && $map['root'] != '' ? intval($map['root']) : get_param_integer('root', NULL);
     $sort = array_key_exists('sort', $map) ? $map['sort'] : '';
     $search = array_key_exists('search', $map) ? $map['search'] : '';
     require_lang('catalogues');
     require_code('catalogues');
     require_code('feedback');
     require_css('catalogues');
     $select = NULL;
     if (!is_null($map) && array_key_exists('select', $map)) {
         require_code('ocfiltering');
         $select = ocfilter_to_sqlfragment($map['select'], 'e.id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id');
     }
     $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $category_id), '', 1);
     if (!array_key_exists(0, $categories)) {
         return do_lang_tempcode('MISSING_RESOURCE');
     }
     $category = $categories[0];
     $catalogue_name = $category['c_name'];
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     $catalogue = $catalogues[0];
     $tpl_set = array_key_exists('template_set', $map) ? $map['template_set'] : $catalogue_name;
     $display_type = array_key_exists('display_type', $map) ? intval($map['display_type']) : NULL;
     list($entry_buildup, , , ) = get_catalogue_category_entry_buildup(is_null($select) ? $category_id : NULL, $catalogue_name, $catalogue, 'CATEGORY', $tpl_set, $max, $start, $select, $root, $display_type, true, NULL, $search, $sort);
     return do_template('CATALOGUE_' . $tpl_set . '_CATEGORY_EMBED', array('ROOT' => strval($root), 'CATALOGUE' => $catalogue_name, 'ENTRIES' => $entry_buildup), NULL, false, 'CATALOGUE_DEFAULT_CATEGORY_EMBED');
 }
Пример #6
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'));
 }
Пример #7
0
 /**
  * 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));
 }
Пример #8
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('chat')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'chat')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'room_id', 'chat_rooms', NULL, 'room_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('chat');
     $rows = $GLOBALS['SITE_DB']->query('SELECT m.* FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'chat_messages m LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'chat_rooms r ON r.id=m.room_id WHERE r.is_im=0 AND date_and_time>' . strval(time() - $cutoff) . ' AND ' . $filters . ' ORDER BY date_and_time DESC', $max);
     $count = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'COUNT(*)', array('is_im' => 0));
     $categories = array();
     if ($count < 100) {
         $_categories = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('is_im' => 0));
         foreach ($_categories as $category) {
             $categories[$category['id']] = $category;
         }
     }
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (!array_key_exists($row['room_id'], $categories) && $count >= 100) {
             $_categories = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $row['room_id']), '', 1);
             if (array_key_exists(0, $_categories)) {
                 $categories[$row['room_id']] = $_categories[0];
             }
         }
         if (!array_key_exists($row['room_id'], $categories)) {
             continue;
         }
         // Message is in deleted room (although should not exist in DB anymore!)
         if (check_chatroom_access($categories[$row['room_id']], true)) {
             $id = strval($row['id']);
             $author = $GLOBALS['FORUM_DRIVER']->get_username($row['user_id']);
             if (is_null($author)) {
                 $author = '';
             }
             $news_date = date($date_string, $row['date_and_time']);
             $edit_date = '';
             $_title = get_translated_tempcode($row['the_message']);
             $news_title = xmlentities($_title->evaluate());
             $summary = '';
             $news = '';
             $category = $categories[$row['room_id']]['room_name'];
             $category_raw = strval($row['room_id']);
             $view_url = build_url(array('page' => 'chat', 'type' => 'room', 'id' => $row['room_id']), get_module_zone('chat'), NULL, false, false, true);
             $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('chat');
     return array($content, do_lang('MESSAGES'));
 }
Пример #9
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('ocf_forum')) {
         return NULL;
     }
     if (get_forum_type() != 'ocf') {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'forumview')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'p_topic_id', 'f_forums', 'f_parent_forum', 'p_cache_forum_id', 'id', true, true, $GLOBALS['FORUM_DB']);
     $cutoff = max($cutoff, time() - 60 * 60 * 24 * 60);
     if (!is_guest()) {
         $filters .= ' AND (p_poster<>' . strval(get_member()) . ')';
     }
     $rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_time>' . strval($cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND p_validated=1 ' : '') . ' AND ' . $filters . ' ORDER BY p_time DESC,id DESC', $max);
     $categories = list_to_map('id', $GLOBALS['FORUM_DB']->query('SELECT id,t_cache_first_title,t_pt_from,t_pt_to FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE t_cache_last_time>' . strval((int) $cutoff)));
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (!array_key_exists($row['p_topic_id'], $categories)) {
             continue;
         }
         $category = $categories[$row['p_topic_id']]['t_cache_first_title'];
         if ((!is_null($row['p_cache_forum_id']) || $categories[$row['p_topic_id']]['t_pt_from'] == get_member() || $categories[$row['p_topic_id']]['t_pt_to'] == get_member()) && (is_null($row['p_intended_solely_for']) || $row['p_intended_solely_for'] == get_member()) && has_category_access(get_member(), 'forums', strval($row['p_cache_forum_id']))) {
             $id = strval($row['id']);
             $author = $row['p_poster_name_if_guest'];
             $news_date = date($date_string, $row['p_time']);
             $edit_date = is_null($row['p_last_edit_time']) ? '' : date($date_string, $row['p_last_edit_time']);
             if ($edit_date == $news_date) {
                 $edit_date = '';
             }
             $news_title = xmlentities($row['p_title']);
             $_summary = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']);
             $summary = xmlentities($_summary->evaluate());
             $news = '';
             $category_raw = strval($row['p_topic_id']);
             $view_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $row['id']), get_module_zone('forumview'), NULL, false, false, true);
             if ($prefix == 'RSS_') {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'ed06bc8f174a5427e1789820666fdd81', 'COMMENT_URL' => $view_url, 'ID' => strval($row['p_topic_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('ocf');
     return array($content, do_lang('FORUM_TOPICS'));
 }
Пример #10
0
 /**
  * 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
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter)
 {
     if (!addon_installed('galleries')) {
         return array();
     }
     require_lang('galleries');
     $new = new ocp_tempcode();
     $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'galleries WHERE name NOT LIKE \'' . db_encode_like('download\\_%') . '\'');
     if ($count < 500) {
         $_galleries = $GLOBALS['SITE_DB']->query('SELECT name,fullname FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'galleries WHERE name NOT LIKE \'' . db_encode_like('download\\_%') . '\'', 300);
         if (count($_galleries) == 300) {
             return array();
         }
         foreach ($_galleries as $i => $_gallery) {
             $_galleries[$i]['text_original'] = get_translated_text($_gallery['fullname']);
         }
         $galleries = collapse_2d_complexity('name', 'text_original', $_galleries);
     } else {
         $galleries = array();
     }
     require_code('ocfiltering');
     $or_list = ocfilter_to_sqlfragment($filter, 'cat', NULL, NULL, NULL, NULL, false);
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'videos WHERE add_date>' . strval((int) $cutoff_time) . ' AND validated=1 AND (' . $or_list . ') ORDER BY add_date DESC', 300);
     if (count($rows) == 300) {
         return array();
     }
     foreach ($rows as $row) {
         $_url = build_url(array('page' => 'galleries', 'type' => 'video', 'id' => $row['id']), get_module_zone('galleries'), NULL, false, false, true);
         $url = $_url->evaluate();
         if (!array_key_exists($row['cat'], $galleries)) {
             $galleries[$row['cat']] = get_translated_text($GLOBALS['SITE_DB']->query_value('galleries', 'fullname', array('name' => $row['cat'])));
         }
         $name = $galleries[$row['cat']];
         $_name = get_translated_text($row['title']);
         if ($_name != '') {
             $name = $_name;
         }
         $description = get_translated_text($row['comments'], NULL, $lang);
         $member_id = is_guest($row['submitter']) ? NULL : strval($row['submitter']);
         $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => 'dfe5850aa67c0cd00ff7d465248b87a5', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description)));
     }
     return array($new, do_lang('GALLERIES', '', '', '', $lang));
 }
Пример #11
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('ocf_forum')) {
         return NULL;
     }
     if (get_forum_type() != 'ocf') {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'forumview')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 't_forum_id', 'f_forums', 'f_parent_forum', 't_forum_id', 'id', true, true, $GLOBALS['FORUM_DB']);
     // 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)
     $rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE t_cache_last_time>' . strval($cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND t_validated=1 ' : '') . ' AND ' . $filters . ' ORDER BY t_cache_last_time DESC', $max);
     $categories = collapse_2d_complexity('id', 'f_name', $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0'));
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if ((!is_null($row['t_forum_id']) || $row['t_pt_to'] == get_member()) && has_category_access(get_member(), 'forums', strval($row['t_forum_id']))) {
             $id = strval($row['id']);
             $author = $row['t_cache_first_username'];
             $news_date = date($date_string, $row['t_cache_first_time']);
             $edit_date = date($date_string, $row['t_cache_last_time']);
             if ($edit_date == $news_date) {
                 $edit_date = '';
             }
             $news_title = xmlentities($row['t_cache_first_title']);
             $_summary = get_translated_tempcode($row['t_cache_first_post'], $GLOBALS['FORUM_DB']);
             $summary = xmlentities($_summary->evaluate());
             $news = '';
             $category = array_key_exists($row['t_forum_id'], $categories) ? $categories[$row['t_forum_id']] : do_lang('NA');
             $category_raw = strval($row['t_forum_id']);
             $view_url = build_url(array('page' => 'topicview', 'id' => $row['id']), get_module_zone('forumview'), NULL, false, false, true);
             if ($prefix == 'RSS_') {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'f5dd7ba612b989bba5e2d496da5bf161', '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('ocf');
     return array($content, do_lang('SECTION_FORUMS'));
 }
Пример #12
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('points')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'points')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'gift_to', 'f_members', NULL, 'gift_to', 'id', true, true, $GLOBALS['FORUM_DB']);
     // 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_lang('points');
     $content = new ocp_tempcode();
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'gifts WHERE ' . $filters . ' AND date_and_time>' . strval((int) $cutoff) . ' ORDER BY date_and_time DESC', $max);
     foreach ($rows as $row) {
         $id = strval($row['id']);
         $author = '';
         if ($row['anonymous'] == 0) {
             $from = $GLOBALS['FORUM_DRIVER']->get_username($row['gift_from']);
             if (is_null($from)) {
                 $from = '';
             }
         }
         $news_date = date($date_string, $row['date_and_time']);
         $edit_date = '';
         $to = $GLOBALS['FORUM_DRIVER']->get_username($row['gift_to']);
         if (is_null($to)) {
             $to = do_lang('UNKNOWN');
         }
         $news_title = xmlentities(do_lang('POINTS_RSS_LINE', $to, integer_format($row['amount'])));
         $summary = xmlentities(get_translated_text($row['reason']));
         $news = '';
         $category = '';
         $category_raw = '';
         $view_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $row['gift_to']), get_module_zone('points'), NULL, false, false, true);
         $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('points');
     return array($content, do_lang('POINTS'));
 }
Пример #13
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 (!has_actual_page_access(get_member(), 'admin_actionlog')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'the_user', 'f_members', NULL, 'the_user', 'id');
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'adminlogs WHERE date_and_time>' . strval($cutoff) . ' AND ' . $filters . ' ORDER BY date_and_time DESC', $max);
     require_all_lang();
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         $id = strval($row['id']);
         $author = $GLOBALS['FORUM_DRIVER']->get_username($row['the_user']);
         if (is_null($author)) {
             $author = do_lang('UNKNOWN');
         }
         $author .= ' / ' . $row['ip'];
         $news_date = date($date_string, $row['date_and_time']);
         $edit_date = escape_html('');
         $type = do_lang($row['the_type'], NULL, NULL, NULL, NULL, false);
         if (is_null($type)) {
             $type = $row['the_type'];
         }
         $news_title = xmlentities($type);
         $_summary = $row['param_a'] . ($row['param_b'] == '' ? '' : ' / ') . $row['param_b'];
         $summary = xmlentities($_summary);
         $news = escape_html('');
         $category = $type;
         $category_raw = $type;
         $view_url = build_url(array('page' => 'admin_actionlog', 'type' => 'view', 'mode' => 'ocp', 'id' => $row['id']), 'adminzone');
         if ($prefix == 'RSS_') {
             $if_comments = do_template('RSS_ENTRY_COMMENTS', array('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('VIEW_ACTION_LOGS'));
 }
Пример #14
0
 /**
  * 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
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter)
 {
     if (!addon_installed('calendar')) {
         return array();
     }
     require_lang('calendar');
     $new = new ocp_tempcode();
     require_code('ocfiltering');
     $or_list = ocfilter_to_sqlfragment($filter, 'e_type');
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_events WHERE e_add_date>' . strval((int) $cutoff_time) . ' AND e_is_public=1 AND (' . $or_list . ') ORDER BY e_add_date DESC', 300);
     if (count($rows) == 300) {
         return array();
     }
     foreach ($rows as $row) {
         $_url = build_url(array('page' => 'calendar', 'type' => 'view', 'id' => $row['id']), get_module_zone('calendar'), NULL, false, false, true);
         $url = $_url->evaluate();
         $name = get_translated_text($row['e_title'], NULL, $lang);
         $description = get_translated_text($row['e_content'], NULL, $lang);
         $member_id = is_guest($row['e_submitter']) ? NULL : strval($row['e_submitter']);
         $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => '654cafa75ec9f9b8e0e0fb666f28fb37', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description)));
     }
     return array($new, do_lang('CALENDAR', '', '', '', $lang));
 }
Пример #15
0
 /**
  * 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
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter)
 {
     if (!addon_installed('downloads')) {
         return array();
     }
     require_lang('downloads');
     $new = new ocp_tempcode();
     require_code('ocfiltering');
     $or_list = ocfilter_to_sqlfragment($filter, 'category_id');
     $rows = $GLOBALS['SITE_DB']->query('SELECT name,description,id,add_date,submitter FROM ' . get_table_prefix() . 'download_downloads WHERE validated=1 AND add_date>' . strval((int) $cutoff_time) . ' AND (' . $or_list . ') ORDER BY add_date DESC', 300);
     if (count($rows) == 300) {
         return array();
     }
     foreach ($rows as $row) {
         $_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $row['id']), get_module_zone('downloads'), NULL, false, false, true);
         $url = $_url->evaluate();
         $name = get_translated_text($row['name'], NULL, $lang);
         $description = get_translated_text($row['description'], NULL, $lang);
         $member_id = is_guest($row['submitter']) ? NULL : strval($row['submitter']);
         $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => 'bbd85ed54500b9d6df998e3c835b45e9', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => $description)));
     }
     return array($new, do_lang('SECTION_DOWNLOADS', '', '', '', $lang));
 }
Пример #16
0
 /**
  * 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
  * @return array				Tuple of result details
  */
 function run($cutoff_time, $lang, $filter)
 {
     $new = new ocp_tempcode();
     if (get_forum_type() != 'ocf') {
         return array();
     }
     require_code('ocfiltering');
     $or_list = ocfilter_to_sqlfragment($filter, 't_forum_id');
     $rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE t_cache_last_time>' . strval($cutoff_time) . ' AND t_validated=1 AND t_pt_to IS NULL AND t_pt_from IS NULL AND (' . $or_list . ') ORDER BY t_cache_last_time DESC', 300);
     if (count($rows) == 300) {
         return array();
     }
     foreach ($rows as $row) {
         if (has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forums', strval($row['t_forum_id']))) {
             $_url = build_url(array('page' => 'topicview', 'type' => 'misc', 'id' => $row['id']), get_module_zone('topicview'), NULL, false, false, true);
             $url = $_url->evaluate();
             $name = $row['t_cache_first_title'];
             $member_id = is_guest($row['t_cache_first_member_id']) ? NULL : strval($row['t_cache_first_member_id']);
             $new->attach(do_template('NEWSLETTER_NEW_RESOURCE_FCOMCODE', array('_GUID' => '14a328f973ac44eb54aa9b31e5a4ae34', 'MEMBER_ID' => $member_id, 'URL' => $url, 'NAME' => $name)));
         }
     }
     return array($new, do_lang('SECTION_FORUMS', '', '', '', $lang));
 }
Пример #17
0
/**
 * List all the multi moderations that may be used in a certain forum.
 *
 * @param  ?AUTO_LINK	The forum we are listing for (NULL: private topics).
 * @return array 			List of multi moderations.
 */
function ocf_list_multi_moderations($forum_id)
{
    if (!addon_installed('ocf_multi_moderations')) {
        return array();
    }
    if (is_null($forum_id)) {
        return array();
    }
    $rows = $GLOBALS['FORUM_DB']->query_select('f_multi_moderations m LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND m.mm_name=t.id', array('mm_forum_multi_code', 'm.id', 'm.mm_name', 'text_original AS _mm_name'), NULL, 'ORDER BY text_original');
    $out = array();
    if (count($rows) == 0) {
        return $out;
    }
    $lots_of_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)') > 200;
    if (!$lots_of_forums) {
        $all_forums = collapse_2d_complexity('id', 'f_parent_forum', $GLOBALS['FORUM_DB']->query_select('f_forums', array('id', 'f_parent_forum')));
    }
    foreach ($rows as $row) {
        if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($row['_mm_name'])) {
            $row['_mm_name'] = get_translated_text($row['mm_name'], $GLOBALS['FORUM_DB']);
        }
        require_code('ocfiltering');
        if ($lots_of_forums) {
            $sql = ocfilter_to_sqlfragment($row['mm_forum_multi_code'], 'id', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
            if (!is_null($GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval($forum_id) . ' AND (' . $sql . ')'))) {
                $out[$row['id']] = $row['_mm_name'];
            }
        } else {
            $idlist = ocfilter_to_idlist_using_memory($row['mm_forum_multi_code'], $all_forums, 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
            if (in_array($forum_id, $idlist)) {
                $out[$row['id']] = $row['_mm_name'];
            }
        }
    }
    return $out;
}
Пример #18
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;
 }
Пример #19
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('calendar')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'calendar')) {
         return NULL;
     }
     $filters = ocfilter_to_sqlfragment($_filters, 'c.id', 'calendar_types', NULL, 'e_type', 'id');
     $content = new ocp_tempcode();
     $_categories = $GLOBALS['SITE_DB']->query('SELECT c.id,c.t_title FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_types c WHERE ' . $filters, NULL, NULL, false, false, array('t_title'));
     foreach ($_categories as $i => $_category) {
         $_categories[$i]['text_original'] = get_translated_text($_category['t_title']);
     }
     $categories = collapse_2d_complexity('id', 'text_original', $_categories);
     //$rows=$GLOBALS['SITE_DB']->query('SELECT * FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'calendar_events WHERE e_add_date>'.strval((integer)$cutoff).' ORDER BY e_add_date DESC',$max);
     $period_start = utctime_to_usertime($cutoff);
     $period_end = utctime_to_usertime(time() * 2 - $cutoff);
     if (is_float($period_end)) {
         $period_end = intval($period_end);
     }
     require_code('calendar');
     $rows = calendar_matches(get_member(), true, $period_start, $period_end, NULL, false);
     $rows = array_reverse($rows);
     foreach ($rows as $i => $_row) {
         if ($i == $max) {
             break;
         }
         $row = $_row[1];
         if (!array_key_exists('id', $row)) {
             continue;
         }
         // RSS event
         $id = strval($row['id']);
         $author = '';
         // The "add" date'll be actually used for the event time
         //$_news_date=mktime($row['e_start_hour'],$row['e_start_minute'],0,$row['e_start_month'],$row['e_start_day'],$row['e_start_year']);
         $_news_date = $_row[2];
         $news_date = date($date_string, usertime_to_utctime($_news_date));
         // The edit date'll be the latest of add/edit
         $edit_date = is_null($row['e_edit_date']) ? date($date_string, $row['e_add_date']) : date($date_string, $row['e_edit_date']);
         $news_title = xmlentities(escape_html(get_translated_text($row['e_title'])));
         $_summary = get_translated_tempcode($row['e_content']);
         $summary = xmlentities($_summary->evaluate());
         $news = '';
         $category = array_key_exists($row['e_type'], $categories) ? $categories[$row['e_type']] : '';
         $category_raw = strval($row['e_type']);
         $view_url = build_url(array('page' => 'calendar', 'type' => 'view', 'id' => $row['id']), get_module_zone('calendar'), NULL, false, false, true);
         if (!array_key_exists('allow_comments', $row)) {
             $row['allow_comments'] = 1;
         }
         if ($prefix == 'RSS_' && get_option('is_on_comments') == '1' && $row['allow_comments'] >= 1) {
             $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => '202a32693ce54d9ce960b72e66714df0', '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('calendar');
     return array($content, do_lang('CALENDAR'));
 }
Пример #20
0
 /**
  * The UI to show the member directory.
  *
  * @return tempcode		The UI
  */
 function directory()
 {
     require_javascript('javascript_ajax');
     require_javascript('javascript_ajax_people_lists');
     $title = get_page_title('MEMBERS');
     require_code('templates_internalise_screen');
     $test_tpl = internalise_own_screen($title);
     if (is_object($test_tpl)) {
         return $test_tpl;
     }
     if (running_script('iframe')) {
         $get_url = find_script('iframe');
     } else {
         $get_url = find_script('index');
     }
     $hidden = new ocp_tempcode();
     $hidden->attach(build_keep_form_fields('_SELF', true, array('filter')));
     $hidden->attach(form_input_hidden('zone', get_zone_name()));
     $start = get_param_integer('md_start', 0);
     $max = get_param_integer('md_max', 50);
     $sortables = array('m_username' => do_lang_tempcode('USERNAME'), 'm_primary_group' => do_lang_tempcode('PRIMARY_GROUP'), 'm_cache_num_posts' => do_lang_tempcode('COUNT_POSTS'), 'm_join_time' => do_lang_tempcode('JOIN_DATE'));
     $default_sort_order = get_value('md_default_sort_order');
     if (is_null($default_sort_order)) {
         $default_sort_order = 'm_join_time DESC';
     }
     $test = explode(' ', get_param('md_sort', $default_sort_order), 2);
     if (count($test) == 1) {
         $test[] = 'ASC';
     }
     list($sortable, $sort_order) = $test;
     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[] = 'md_sort';
     $group_filter = get_param('group_filter', '');
     $_usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, $group_filter == '' ? NULL : array(intval($group_filter)));
     $usergroups = array();
     require_code('ocf_groups2');
     foreach ($_usergroups as $group_id => $group) {
         $num = ocf_get_group_members_raw_count($group_id, true);
         $usergroups[$group_id] = array('USERGROUP' => $group, 'NUM' => strval($num));
     }
     $query = 'FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE id<>' . strval(db_get_first_id());
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $query .= ' AND m_validated=1';
     }
     if ($group_filter != '') {
         if (is_numeric($group_filter)) {
             $title = get_page_title('USERGROUP', true, array(escape_html($usergroups[intval($group_filter)]['USERGROUP'])));
         }
         require_code('ocfiltering');
         $filter = ocfilter_to_sqlfragment($group_filter, 'm_primary_group', 'f_groups', NULL, 'm_primary_group', 'id');
         $query .= ' AND ' . $filter;
     }
     $search = get_param('filter', '');
     $sup = $search != '' ? ' AND m_username LIKE \'' . db_encode_like(str_replace('*', '%', $search)) . '\'' : '';
     if ($sortable == 'm_join_time') {
         $query .= $sup . ' ORDER BY m_join_time ' . $sort_order . ',' . 'id ' . $sort_order;
     } else {
         $query .= $sup . ' ORDER BY ' . $sortable . ' ' . $sort_order;
     }
     $max_rows = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     $rows = $GLOBALS['FORUM_DB']->query('SELECT * ' . $query, $max, $start);
     if (count($rows) == 0) {
         return inform_screen($title, do_lang_tempcode('NO_RESULTS'));
     }
     $members = new ocp_tempcode();
     $member_boxes = array();
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('USERNAME'), do_lang_tempcode('PRIMARY_GROUP'), do_lang_tempcode('COUNT_POSTS'), do_lang_tempcode('JOIN_DATE')), $sortables, 'md_sort', $sortable . ' ' . $sort_order);
     require_code('ocf_members2');
     foreach ($rows as $row) {
         $link = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($row['id'], true, $row['m_username']);
         if ($row['m_validated'] == 0) {
             $link->attach(do_lang_tempcode('MEMBER_IS_UNVALIDATED'));
         }
         if ($row['m_validated_email_confirm_code'] != '') {
             $link->attach(do_lang_tempcode('MEMBER_IS_UNCONFIRMED'));
         }
         $member_primary_group = ocf_get_member_primary_group($row['id']);
         $primary_group = ocf_get_group_link($member_primary_group);
         $members->attach(results_entry(array($link, $primary_group, escape_html(integer_format($row['m_cache_num_posts'])), escape_html(get_timezoned_date($row['m_join_time'])))));
         $member_boxes[] = ocf_show_member_box($row['id'], true);
     }
     $results_table = results_table(do_lang_tempcode('MEMBERS'), $start, 'md_start', $max, 'md_max', $max_rows, $fields_title, $members, $sortables, $sortable, $sort_order, 'md_sort');
     $results_browser = results_browser(do_lang_tempcode('MEMBERS'), NULL, $start, 'md_start', $max, 'md_max', $max_rows, NULL, NULL, true, true);
     $symbols = NULL;
     if (get_option('allow_alpha_search') == '1') {
         $alpha_query = $GLOBALS['FORUM_DB']->query('SELECT m_username FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE id<>' . strval(db_get_first_id()) . ' ORDER BY m_username ASC');
         $symbols = array(array('START' => '0', 'SYMBOL' => do_lang('ALL')), array('START' => '0', 'SYMBOL' => '#'));
         foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z') as $s) {
             foreach ($alpha_query as $i => $q) {
                 if (strtolower(substr($q['m_username'], 0, 1)) == $s) {
                     break;
                 }
             }
             if (substr(strtolower($q['m_username']), 0, 1) != $s) {
                 $i = intval($symbols[count($symbols) - 1]['START']);
             }
             $symbols[] = array('START' => strval(intval($max * floor(floatval($i) / floatval($max)))), 'SYMBOL' => $s);
         }
     }
     return do_template('OCF_MEMBER_DIRECTORY_SCREEN', array('_GUID' => '096767e9aaabce9cb3e6591b7bcf95b8', 'MAX' => strval($max), 'RESULTS_BROWSER' => $results_browser, 'MEMBER_BOXES' => $member_boxes, 'USERGROUPS' => $usergroups, 'HIDDEN' => $hidden, 'SYMBOLS' => $symbols, 'SEARCH' => $search, 'GET_URL' => $get_url, 'TITLE' => $title, 'RESULTS_TABLE' => $results_table));
 }
Пример #21
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));
 }
Пример #22
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('catalogues');
     require_lang('main_google_map');
     // Set up config/defaults
     if (!array_key_exists('title', $map)) {
         $map['title'] = '';
     }
     if (!array_key_exists('region', $map)) {
         $map['region'] = '';
     }
     if (!array_key_exists('latitude', $map)) {
         $map['latitude'] = '0';
     }
     if (!array_key_exists('longitude', $map)) {
         $map['longitude'] = '0';
     }
     $mapwidth = array_key_exists('width', $map) ? $map['width'] : '100%';
     $mapheight = array_key_exists('height', $map) ? $map['height'] : '300px';
     $api_key = array_key_exists('api_key', $map) ? $map['api_key'] : '';
     $set_zoom = array_key_exists('zoom', $map) ? $map['zoom'] : '3';
     $set_center = array_key_exists('center', $map) ? $map['center'] : '0';
     $set_show_links = array_key_exists('show_links', $map) ? $map['show_links'] : '1';
     $cluster = array_key_exists('cluster', $map) ? $map['cluster'] : '0';
     if (!array_key_exists('catalogue', $map)) {
         $map['catalogue'] = '';
     }
     if (!array_key_exists('longfield', $map)) {
         $map['longfield'] = 'Longitude';
     }
     if (!array_key_exists('latfield', $map)) {
         $map['latfield'] = 'Latitude';
     }
     $min_latitude = array_key_exists('min_latitude', $map) ? $map['min_latitude'] : '';
     $max_latitude = array_key_exists('max_latitude', $map) ? $map['max_latitude'] : '';
     $min_longitude = array_key_exists('min_longitude', $map) ? $map['min_longitude'] : '';
     $max_longitude = array_key_exists('max_longitude', $map) ? $map['max_longitude'] : '';
     $longitude_key = $map['longfield'];
     $latitude_key = $map['latfield'];
     $catalogue_name = $map['catalogue'];
     $star_entry = array_key_exists('star_entry', $map) ? $map['star_entry'] : '';
     $max_results = array_key_exists('max_results', $map) && $map['max_results'] != '' ? intval($map['max_results']) : 1000;
     $icon = array_key_exists('icon', $map) ? $map['icon'] : '';
     if (!array_key_exists('filter_category', $map)) {
         $map['filter_category'] = '';
     }
     if (!array_key_exists('filter_rating', $map)) {
         $map['filter_rating'] = '';
     }
     if (!array_key_exists('filter_term', $map)) {
         $map['filter_term'] = '';
     }
     if (!array_key_exists('filter_hours', $map)) {
         $map['filter_hours'] = '';
     }
     $data = array();
     if ($catalogue_name != '') {
         // Data query
         $query = 'SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries WHERE ce_validated=1 AND ' . db_string_equal_to('c_name', $catalogue_name);
         // Filtering
         if ($map['filter_category'] != '') {
             require_code('ocfiltering');
             $query .= ' AND (' . ocfilter_to_sqlfragment($map['filter_category'], 'id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id') . ')';
         }
         if ($map['filter_hours'] != '') {
             $query .= ' AND ce_add_date>' . strval(time() - 60 * 60 * intval($map['filter_hours']));
         }
         if ($map['filter_rating'] != '') {
             $query .= ' AND (SELECT AVG(rating) FROM rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogue_entry') . ' AND rating_for_id=id)>' . strval(intval($map['filter_rating']));
         }
         // Info about our catalogue
         $catalogue_rows = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
         if (!array_key_exists(0, $catalogue_rows)) {
             return paragraph('Could not find the catalogue named "' . escape_html($catalogue_name) . '".', '', 'nothing_here');
         }
         $catalogue_row = $catalogue_rows[0];
         // Get results
         $entries_to_show = array();
         if ($star_entry != '') {
             $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' AND id=' . strval(intval($star_entry))));
             $query .= ' AND id<>' . strval(intval($star_entry));
         }
         $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' ORDER BY ce_add_date DESC', $max_results));
         if (count($entries_to_show) == 0 && ($min_latitude == '' || $max_latitude == '' || $min_longitude == '' || $max_longitude == '')) {
             //return paragraph(do_lang_tempcode('NO_ENTRIES'),'','nothing_here');
         }
         // Make marker data Javascript-friendly
         foreach ($entries_to_show as $i => $entry_row) {
             $entry_row['allow_rating'] = 0;
             // Performance: So rating is not loaded
             $details = get_catalogue_entry_map($entry_row, $catalogue_row, 'CATEGORY', $catalogue_name, NULL);
             $two_d_list = $details['FIELDS_2D'];
             $longitude = NULL;
             $latitude = NULL;
             $entry_title = '';
             $all_output = '';
             foreach ($two_d_list as $index => $l) {
                 if ($l['NAME'] == $longitude_key) {
                     $longitude = $l['VALUE'];
                 }
                 if ($l['NAME'] == $latitude_key) {
                     $latitude = $l['VALUE'];
                 }
                 if ($index == 0) {
                     $entry_title = $l['VALUE'];
                 }
                 $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' ';
             }
             if (is_object($longitude)) {
                 $longitude = $longitude->evaluate();
             }
             if (is_object($latitude)) {
                 $latitude = $latitude->evaluate();
             }
             if (is_object($entry_title)) {
                 $entry_title = $entry_title->evaluate();
             }
             if (is_numeric($longitude) && is_numeric($latitude)) {
                 if ($map['filter_term'] == '' || strpos(strtolower($all_output), strtolower($map['filter_term'])) !== false) {
                     $details['LONGITUDE'] = float_to_raw_string(floatval($longitude));
                     $details['LATITUDE'] = float_to_raw_string(floatval($latitude));
                     $details['ENTRY_TITLE'] = $entry_title;
                     $entry_content = do_template('CATALOGUE_googlemap_ENTRY_EMBED', $details, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED');
                     //put_in_standard_box(hyperlink($url,do_lang_tempcode('VIEW')),do_lang_tempcode('CATALOGUE_ENTRY').' ('.do_lang_tempcode('IN',get_translated_text($catalogue['c_title'])).')');
                     $details['ENTRY_CONTENT'] = $entry_content;
                     $details['STAR'] = '0';
                     if ($star_entry != '') {
                         if ($entry_row['id'] == intval($star_entry)) {
                             $details['STAR'] = '1';
                         }
                     }
                     $details['CC_ID'] = strval($entry_row['cc_id']);
                     $details['ICON'] = '';
                     $data[] = $details;
                 }
             }
         }
     }
     $hooks_to_use = explode('|', array_key_exists('extra_sources', $map) ? $map['extra_sources'] : '');
     $hooks = find_all_hooks('blocks', 'main_google_map');
     foreach (array_keys($hooks) as $hook) {
         if (in_array($hook, $hooks_to_use)) {
             require_code('hooks/blocks/main_google_map/' . $hook);
             $ob = object_factory('Hook_Map_' . $hook);
             $data = array_merge($data, $ob->get_data($map, $max_results, $min_latitude, $max_latitude, $min_longitude, $max_longitude, $latitude_key, $longitude_key, $catalogue_row, $catalogue_name));
         }
     }
     $uniqid = uniqid('', true);
     $div_id = 'div_' . $catalogue_name . '_' . $uniqid;
     return do_template('BLOCK_MAIN_GOOGLE_MAP', array('TITLE' => $map['title'], 'ICON' => $icon, 'MIN_LATITUDE' => $min_latitude, 'MAX_LATITUDE' => $max_latitude, 'MIN_LONGITUDE' => $min_longitude, 'MAX_LONGITUDE' => $max_longitude, 'DATA' => $data, 'SHOW_LINKS' => $set_show_links, 'DIV_ID' => $div_id, 'CLUSTER' => $cluster, 'REGION' => $map['region'], 'WIDTH' => $mapwidth, 'HEIGHT' => $mapheight, 'LATITUDE' => $map['latitude'], 'LONGITUDE' => $map['longitude'], 'ZOOM' => $set_zoom, 'CENTER' => $set_center));
 }
Пример #23
0
 /**
  * Allow the user to choose what to book, on a high level - what bookables, what dates.
  *
  * @return tempcode	The result of execution.
  */
 function choose_bookables_and_dates()
 {
     $title = get_page_title('CREATE_BOOKING');
     $query = 'SELECT * FROM ' . get_table_prefix() . 'bookable WHERE enabled=1';
     $filter = get_param('filter', '*');
     require_code('ocfiltering');
     $query .= ' AND ' . ocfilter_to_sqlfragment($filter, 'id');
     $bookables = $GLOBALS['SITE_DB']->query($query . ' ORDER BY sort_order');
     $has_date_ranges = false;
     $has_single_dates = false;
     $has_details = false;
     $min_min_date = time();
     $max_max_date = mixed();
     $date_from = time();
     $date_to = time();
     $categories = array();
     foreach ($bookables as $bookable) {
         $active_from = mktime(0, 0, 0, $bookable['active_from_month'], $bookable['active_from_day'], $bookable['active_from_year']);
         $active_to = mixed();
         $active_to = is_null($bookable['active_to_year']) ? NULL : mktime(0, 0, 0, $bookable['active_to_month'], $bookable['active_to_day'], $bookable['active_to_year']);
         $min_date = $active_from;
         $max_date = $active_to;
         if ($min_date < $min_min_date) {
             $min_min_date = $min_date;
         }
         if (is_null($max_max_date) || !is_null($active_to)) {
             if ($max_date > $max_max_date) {
                 $max_max_date = $max_date;
             }
         }
         if ($bookable['dates_are_ranges'] == 1) {
             $has_date_ranges = true;
         } elseif ($bookable['dates_are_ranges'] == 0) {
             $has_single_ranges = true;
         }
         $messages = array();
         // Message if not currently active
         if ($active_from > time()) {
             $messages[] = do_lang_tempcode('NOTE_BOOKING_IMPOSSIBLE_NOT_STARTED', get_timezoned_date($active_from, false, true, false, true));
         }
         // Message if becomes inactive within next 6 months
         if (!is_null($active_to) && $active_to < SHOW_WARNINGS_UNTIL) {
             $messages[] = do_lang_tempcode('NOTE_BOOKING_IMPOSSIBLE_ENDED', get_timezoned_date($active_to, false, true, false, true));
         }
         // Message about any black-outs within next 6 months
         $blacked = $GLOBALS['SITE_DB']->query_select('bookable_blacked b JOIN ' . get_table_prefix() . 'bookable_blacked_for f ON f.blacked_id=b.id', array('blacked_from_day', 'blacked_from_month', 'blacked_from_year', 'blacked_to_day', 'blacked_to_month', 'blacked_to_year', 'blacked_explanation'), array('bookable_id' => $bookable['id']), 'ORDER BY id');
         foreach ($blacked as $black) {
             $black_from = mktime(0, 0, 0, $black['blacked_from_month'], $black['blacked_from_day'], $black['blacked_from_year']);
             $black_to = mixed();
             $black_to = is_null($black['blacked_to_year']) ? NULL : mktime(0, 0, 0, $black['blacked_to_month'], $black['blacked_to_day'], $black['blacked_to_year']);
             if ($black_from > time() && $black_to < SHOW_WARNINGS_UNTIL) {
                 $messages[] = do_lang_tempcode($black_from == $black_to ? 'NOTE_BOOKING_IMPOSSIBLE_BLACKED_ONEOFF' : 'NOTE_BOOKING_IMPOSSIBLE_BLACKED_PERIOD', get_timezoned_date($black_from, false, true, false, true), get_timezoned_date($black_to, false, true, false, true), get_translated_tempcode($black['blacked_explanation']));
             }
         }
         $category = get_translated_text($bookable['categorisation']);
         if (!array_key_exists($category, $categories)) {
             $categories[$category] = array('CATEGORY_TITLE' => $category, 'BOOKABLES' => array());
         }
         $quantity_available = $GLOBALS['SITE_DB']->query_value('bookable_codes', 'COUNT(*)', array('bookable_id' => $bookable['id']));
         list($quantity, $date_from, $date_to) = $this->_read_chosen_bookable_settings($bookable);
         if (is_null($max_max_date)) {
             $max_max_date = MAX_AHEAD_BOOKING_DATE;
         }
         $description = get_translated_tempcode($bookable['description']);
         if (!$description->is_empty() || count($messages) > 0) {
             $has_details = true;
         }
         $categories[$category]['BOOKABLES'][] = array('BOOKABLE_ID' => strval($bookable['id']), 'BOOKABLE_QUANTITY_AVAILABLE' => strval($quantity_available), 'BOOKABLE_MESSAGES' => $messages, 'BOOKABLE_TITLE' => get_translated_text($bookable['title']), 'BOOKABLE_DESCRIPTION' => $description, 'BOOKABLE_PRICE' => float_format($bookable['price']), 'BOOKABLE_PRICE_RAW' => float_to_raw_string($bookable['price']), 'BOOKABLE_SELECT_DATE_RANGE' => $bookable['dates_are_ranges'] == 1, 'BOOKABLE_MIN_DATE_DAY' => date('d', $min_date), 'BOOKABLE_MIN_DATE_MONTH' => date('m', $min_date), 'BOOKABLE_MIN_DATE_YEAR' => date('Y', $min_date), 'BOOKABLE_MAX_DATE_DAY' => date('d', $max_date), 'BOOKABLE_MAX_DATE_MONTH' => date('m', $max_date), 'BOOKABLE_MAX_DATE_YEAR' => date('Y', $max_date), 'BOOKABLE_QUANTITY' => strval($quantity), 'BOOKABLE_DATE_FROM_DAY' => date('d', $date_from), 'BOOKABLE_DATE_FROM_MONTH' => date('m', $date_from), 'BOOKABLE_DATE_FROM_YEAR' => date('Y', $date_from), 'BOOKABLE_DATE_TO_DAY' => date('d', $date_to), 'BOOKABLE_DATE_TO_MONTH' => date('m', $date_to), 'BOOKABLE_DATE_TO_YEAR' => date('Y', $date_to));
         /*$M_SORT_KEY='BOOKABLE_TITLE';	Wrong - we're sorting by sort_order
         		usort($categories[$category]['BOOKABLES'],'multi_sort');*/
     }
     ksort($categories);
     // Messages shared by all bookables will be transferred so as to avoid repetition
     $shared_messages = array();
     $done_one = false;
     foreach ($categories as $category_title => $bookables) {
         foreach ($bookables['BOOKABLES'] as $i => $bookable) {
             foreach ($bookable['BOOKABLE_MESSAGES'] as $j => $message) {
                 if (!$done_one) {
                     $in_all = true;
                     foreach ($categories as $_category_title => $_bookables) {
                         foreach ($bookables['BOOKABLES'] as $_i => $_bookable) {
                             if (!in_array($message, $_bookable['BOOKABLE_MESSAGES'])) {
                                 $in_all = false;
                                 break 2;
                             }
                         }
                     }
                     if ($in_all) {
                         $shared_messages[] = $message;
                     }
                     $done_one = true;
                 }
                 if (in_array($message, $shared_messages)) {
                     unset($categories[$category_title]['BOOKABLES'][$i]['BOOKABLE_MESSAGES'][$j]);
                 }
             }
         }
     }
     return do_template('BOOKING_START_SCREEN', array('TITLE' => $title, 'CATEGORIES' => $categories, 'POST_URL' => build_url(array('page' => '_SELF', 'type' => 'flesh_out', 'usergroup' => get_param_integer('usergroup', NULL)), '_SELF'), 'SHARED_MESSAGES' => $shared_messages, 'HAS_DATE_RANGES' => $has_date_ranges, 'HAS_SINGLE_DATES' => $has_single_dates, 'HAS_DETAILS' => $has_details, 'HAS_MIXED_DATE_TYPES' => $has_single_dates && $has_date_ranges, 'MIN_DATE_DAY' => date('d', $min_min_date), 'MIN_DATE_MONTH' => date('m', $min_min_date), 'MIN_DATE_YEAR' => date('Y', $min_min_date), 'MAX_DATE_DAY' => date('d', $max_max_date), 'MAX_DATE_MONTH' => date('m', $max_max_date), 'MAX_DATE_YEAR' => date('Y', $max_max_date), 'DATE_FROM_DAY' => date('d', $date_from), 'DATE_FROM_MONTH' => date('m', $date_from), 'DATE_FROM_YEAR' => date('Y', $date_from), 'DATE_TO_DAY' => date('d', $date_to), 'DATE_TO_MONTH' => date('m', $date_to), 'DATE_TO_YEAR' => date('Y', $date_to), 'HIDDEN' => build_keep_post_fields()));
 }
Пример #24
0
 /**
  * Sort out gallery back/next navigation.
  *
  * @param  string			Where clause for doing set query
  * @param  string			Join clause for doing set query
  * @param  tempcode		The actual title for the gallery we are using
  * @param  ?AUTO_LINK	The ID of the current entry of the type we are browsing in the gallery we are using (NULL: assume first)
  * @param  ID_TEXT		The root gallery (the gallery we are considering as an adhoc root, to allow gallery splitting-up)
  * @param  ?ID_TEXT		The current type being browsed (NULL: assume first)
  * @set image video
  * @param  BINARY			If in slideshow
  * @param  BINARY			If panels hidden
  * @param  integer		Start position when returning to category
  * @param  integer		Max to show when returning to category
  * @param  ID_TEXT		Category
  * @param  ID_TEXT		Sort order
  * @param  ID_TEXT		Sort order for reverse sorting
  * @param  string			Select clause query suffix for images
  * @param  string			Select clause query suffix for videos
  * @param  string			ocFilter for limiting images displayed
  * @param  string			ocFilter for limiting videos displayed
  * @return array			A tuple of the navigation bits
  */
 function build_set_navigation($where, $join, $category_name, $current_id, $root, $current_type, $slideshow, $wide_high, $start, $max, $cat, $sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos, $image_select, $video_select)
 {
     $sv = has_specific_permission(get_member(), 'see_unvalidated');
     if (!$sv) {
         $where .= ' AND validated=1';
     }
     $days = get_param('days', '');
     if ($days != '') {
         $where .= ' AND add_date>=' . strval(time() - intval($days) * 60 * 60 * 24);
     }
     require_code('ocfiltering');
     $image_select_sql = ocfilter_to_sqlfragment($image_select, 'r.id');
     $where_images = $where . ' AND ' . $image_select_sql;
     $video_select_sql = ocfilter_to_sqlfragment($video_select, 'r.id');
     $where_videos = $where . ' AND ' . $video_select_sql;
     $total_images = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'images r' . $join . ' WHERE ' . $where_images);
     $total_videos = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'videos r' . $join . ' WHERE ' . $where_videos);
     // These will hopefully be replaced with proper values
     $position = 1;
     $back_id = NULL;
     $back_type = $current_type;
     $next_id = NULL;
     $next_type = $current_type;
     $first_id = $current_id;
     $first_type = $current_type;
     $total = $total_videos + $total_images;
     if ($total < 500) {
         $rows_images = $GLOBALS['SITE_DB']->query('SELECT r.id,add_date,url' . $sql_suffix_images . ',title FROM ' . get_table_prefix() . 'images r' . $join . ' WHERE ' . $where_images . ' ORDER BY ' . $sort);
         $rows_videos = $GLOBALS['SITE_DB']->query('SELECT r.id,add_date,url' . $sql_suffix_videos . ',title FROM ' . get_table_prefix() . 'videos r' . $join . ' WHERE ' . $where_videos . ' ORDER BY ' . $sort);
         list($_sort, $_dir) = explode(' ', $sort, 2);
         // Sort
         $combined = array();
         foreach ($rows_images as $row_image) {
             $combined[] = array($row_image, 'image', $row_image[$_sort]);
         }
         foreach ($rows_videos as $row_video) {
             $combined[] = array($row_video, 'video', $row_video[$_sort]);
         }
         global $M_SORT_KEY;
         $M_SORT_KEY = 2;
         usort($combined, 'multi_sort');
         if ($_dir == 'DESC') {
             $combined = array_reverse($combined);
         }
         // Find current position in navigation set, and neighbour positions
         foreach ($combined as $position => $c) {
             if ($position == 0) {
                 $first_id = $c[0]['id'];
                 $first_type = $c[1];
             }
             if (is_null($current_id) || $c[1] == $current_type && $c[0]['id'] == $current_id) {
                 if ($position != 0) {
                     $back_id = $combined[$position - 1][0]['id'];
                     $back_type = $combined[$position - 1][1];
                 }
                 if ($position != count($combined) - 1) {
                     $next_id = $combined[$position + 1][0]['id'];
                     $next_type = $combined[$position + 1][1];
                 }
                 $position++;
                 // We're not counting from zero
                 break;
             }
         }
     }
     // UI for navigating all this
     $nav_ui = is_null($first_id) ? new ocp_tempcode() : $this->show_nav($category_name, $where, $join, $current_id, $first_id, $back_id, $next_id, $root, $position, $total, $current_type, $first_type, $back_type, $next_type, $slideshow, $wide_high, $start, $max, $cat, $sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos, $image_select, $video_select);
     return array($total, $position, $nav_ui, $first_id, $back_id, $next_id, $first_type, $back_type, $next_type);
 }
Пример #25
0
 /**
  * The UI to view a download index.
  *
  * @return tempcode		The UI
  */
 function show_all_downloads()
 {
     $title = get_page_title('SECTION_DOWNLOADS');
     $id = get_param('id', strval(db_get_first_id()));
     require_code('ocfiltering');
     $sql_filter = ocfilter_to_sqlfragment(is_numeric($id) ? $id . '*' : $id, 'p.category_id', 'download_categories', 'parent_id', 'p.category_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)
     if ($GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)') > 1000) {
         warn_exit(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'));
     }
     $cats = array();
     $rows = $GLOBALS['SITE_DB']->query('SELECT p.*,text_original FROM ' . get_table_prefix() . 'download_downloads p LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=p.name AND ' . db_string_equal_to('language', user_lang()) . ' WHERE validated=1 AND (' . $sql_filter . ') ORDER BY text_original ASC');
     foreach ($rows as $row) {
         if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($row['text_original'])) {
             $row['text_original'] = get_translated_text($row['name']);
         }
         $letter = strtoupper(substr($row['text_original'], 0, 1));
         if (!has_category_access(get_member(), 'downloads', strval($row['category_id']))) {
             continue;
         }
         if (!array_key_exists($letter, $cats)) {
             $cats[$letter] = array();
         }
         $cats[$letter][] = $row;
     }
     unset($rows);
     $subcats = array();
     foreach ($cats as $letter => $rows) {
         if (!is_string($letter)) {
             $letter = strval($letter);
         }
         // Numbers come out as numbers not strings, even if they went in as strings- darned PHP
         $has_download = false;
         $data = array();
         $data['CAT_TITLE'] = $letter;
         $data['LETTER'] = $letter;
         $out = new ocp_tempcode();
         foreach ($rows as $myrow) {
             $out->attach(get_download_html($myrow));
             $has_download = true;
         }
         $data['DOWNLOADS'] = $out;
         $subcats[] = $data;
     }
     if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'submit_midrange_content')) {
         $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'cat' => $id), get_module_zone('cms_downloads'));
     } else {
         $submit_url = new ocp_tempcode();
     }
     if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'submit_cat_midrange_content')) {
         $add_cat_url = build_url(array('page' => 'cms_downloads', 'type' => 'ac', 'parent_id' => $id), get_module_zone('cms_downloads'));
     } else {
         $add_cat_url = new ocp_tempcode();
     }
     if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'edit_cat_midrange_content')) {
         $edit_cat_url = build_url(array('page' => 'cms_downloads', 'type' => '_ec', 'id' => $id), get_module_zone('cms_downloads'));
     } else {
         $edit_cat_url = new ocp_tempcode();
     }
     return do_template('DOWNLOAD_ALL_SCREEN', array('TITLE' => $title, 'SUBMIT_URL' => $submit_url, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'SUB_CATEGORIES' => $subcats));
 }
Пример #26
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));
 }
Пример #27
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));
 }
Пример #28
0
 /**
  * Make a filter SQL fragment.
  *
  * @param  string		The filter string.
  * @param  array		Map of details of our content type.
  * @param  string		The field name of the category to filter against.
  * @return string		SQL fragment.
  */
 function build_filter($filter, $info, $category_field_filter)
 {
     $parent_spec__table_name = array_key_exists('parent_spec__table_name', $info) ? $info['parent_spec__table_name'] : $info['table'];
     $parent_field_name = array_key_exists('parent_field_name', $info) ? 'r.' . $info['parent_field_name'] : NULL;
     if (is_null($parent_field_name)) {
         $parent_spec__table_name = NULL;
     }
     $parent_spec__parent_name = array_key_exists('parent_spec__parent_name', $info) ? $info['parent_spec__parent_name'] : NULL;
     $parent_spec__field_name = array_key_exists('parent_spec__field_name', $info) ? $info['parent_spec__field_name'] : NULL;
     $id_is_string = array_key_exists('id_is_string', $info) && $info['id_is_string'];
     $category_is_string = array_key_exists('category_is_string', $info) && $info['category_is_string'];
     require_code('ocfiltering');
     return ocfilter_to_sqlfragment($filter, $category_field_filter, $parent_spec__table_name, $parent_spec__parent_name, $parent_field_name, $parent_spec__field_name, !$id_is_string, !$category_is_string);
 }
Пример #29
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'));
 }
Пример #30
0
/**
 * Show bookables ical feed.
 */
function bookables_ical_script()
{
    require_code('calendar_ical');
    require_lang('booking');
    @ini_set('ocproducts.xss_detect', '0');
    //	header('Content-Type: text/calendar');
    //	header('Content-Disposition: filename="bookables_export.ics"');
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $query = 'SELECT * FROM ' . get_table_prefix() . 'bookable WHERE enabled=1';
    $filter = get_param('filter', '*');
    require_code('ocfiltering');
    $query .= ' AND ' . ocfilter_to_sqlfragment($filter, 'id');
    $events = $GLOBALS['SITE_DB']->query($query);
    echo "BEGIN:VCALENDAR\n";
    echo "VERSION:2.0\n";
    echo "PRODID:-//ocProducts/ocPortal//NONSGML v1.0//EN\n";
    echo "CALSCALE:GREGORIAN\n";
    echo "X-WR-CALNAME:" . ical_escape(get_site_name() . ': ' . do_lang('BOOKABLE_EVENTS')) . "\n";
    foreach ($events as $event) {
        echo "BEGIN:VEVENT\n";
        echo "DTSTAMP:" . date('Ymd', $event['add_date']) . "T" . date('His', $event['add_date']) . "\n";
        echo "CREATED:" . date('Ymd', $event['add_date']) . "T" . date('His', $event['add_date']) . "\n";
        if (!is_null($event['edit_date'])) {
            echo "LAST-MODIFIED:" . date('Ymd', time()) . "T" . date('His', $event['edit_date']) . "\n";
        }
        echo "SUMMARY:" . ical_escape(get_translated_text($event['title'])) . "\n";
        $description = get_translated_text($event['description']);
        echo "DESCRIPTION:" . ical_escape($description) . "\n";
        if (!is_guest($event['submitter'])) {
            echo "ORGANIZER;CN=" . ical_escape($GLOBALS['FORUM_DRIVER']->get_username($event['submitter'])) . ";DIR=" . ical_escape($GLOBALS['FORUM_DRIVER']->member_profile_url($event['submitter'])) . ":MAILTO:" . ical_escape($GLOBALS['FORUM_DRIVER']->get_member_email_address($event['submitter'])) . "\n";
        }
        echo "CATEGORIES:" . ical_escape(get_translated_text($event['categorisation'])) . "\n";
        echo "CLASS:" . ($event['price'] == 0.0 ? 'PUBLIC' : 'PRIVATE') . "\n";
        echo "STATUS:" . ($event['enabled'] == 1 ? 'CONFIRMED' : 'TENTATIVE') . "\n";
        echo "UID:" . ical_escape(strval($event['id']) . '-bookable@' . get_base_url()) . "\n";
        $_url = build_url(array('page' => 'booking', 'type' => 'misc', 'filter' => $event['id']), get_module_zone('booking'), NULL, false, false, true);
        $url = $_url->evaluate();
        echo "URL:" . ical_escape($url) . "\n";
        $time = mktime(0, 0, 0, $event['active_from_month'], $event['active_from_day'], $event['active_from_year']);
        $time2 = mixed();
        if ($event['cycle_type'] != 'none') {
            $parts = explode(' ', $event['cycle_type']);
            if (count($parts) == 1) {
                echo "DTSTART;TZ=" . get_site_timezone() . ":" . date('Ymd', $time) . "\n";
                $recurrence_code = 'FREQ=' . strtoupper($parts[0]);
                echo "RRULE:" . $recurrence_code . "\n";
            } else {
                for ($i = 0; $i < strlen($parts[1]); $i++) {
                    switch ($parts[0]) {
                        case 'daily':
                            $time += 60 * 60 * 24;
                            if (!is_null($time2)) {
                                $time2 += 60 * 60 * 24;
                            }
                            break;
                        case 'weekly':
                            $time += 60 * 60 * 24 * 7;
                            if (!is_null($time2)) {
                                $time2 += 60 * 60 * 24 * 7;
                            }
                            break;
                        case 'monthly':
                            $days_in_month = intval(date('D', mktime(0, 0, 0, intval(date('m', $time)) + 1, 0, intval(date('Y', $time)))));
                            $time += 60 * 60 * $days_in_month;
                            if (!is_null($time2)) {
                                $time2 += 60 * 60 * $days_in_month;
                            }
                            break;
                        case 'yearly':
                            $days_in_year = intval(date('Y', mktime(0, 0, 0, 0, 0, intval(date('Y', $time)) + 1)));
                            $time += 60 * 60 * 24 * $days_in_year;
                            if (!is_null($time2)) {
                                $time2 += 60 * 60 * 24 * $days_in_year;
                            }
                            break;
                    }
                    if ($parts[1][$i] != '0') {
                        echo "DTSTART:" . date('Ymd', $time) . "\n";
                        $recurrence_code = 'FREQ=' . strtoupper($parts[0]);
                        echo "RRULE:" . $recurrence_code . ";INTERVAL=" . strval(strlen($parts[1])) . ";COUNT=1\n";
                    }
                }
            }
        } else {
            echo "DTSTART:" . date('Ymd', $time) . "\n";
            if ($GLOBALS['FORUM_DRIVER']->is_staff(get_member())) {
                $attendees = $GLOBALS['SITE_DB']->query_select('booking', array('*'), array('bookable_id' => $event['id']), '', 5000);
                if (count($attendees) == 5000) {
                    $attendees = array();
                }
                foreach ($attendees as $attendee) {
                    if (!is_guest($event['member_id'])) {
                        echo "ATTENDEE;CN=" . ical_escape($GLOBALS['FORUM_DRIVER']->get_username($attendee['member_id'])) . ";DIR=" . ical_escape($GLOBALS['FORUM_DRIVER']->member_profile_url($attendee['member_id'])) . ":MAILTO:" . ical_escape($GLOBALS['FORUM_DRIVER']->get_member_email_address($attendee['member_id'])) . "\n";
                    }
                }
            }
        }
        echo "END:VEVENT\n";
    }
    echo "END:VCALENDAR\n";
    exit;
}