예제 #1
0
파일: news.php 프로젝트: erico-deh/ocPortal
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (!addon_installed('news')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'news')) {
         return NULL;
     }
     $filters_1 = ocfilter_to_sqlfragment($_filters, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters_2 = ocfilter_to_sqlfragment($_filters, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id WHERE date_and_time>' . strval($cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND validated=1 ' : '') . ' AND ' . $filters . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC', $max);
     $rows = remove_duplicate_rows($rows, 'id');
     $_categories = $GLOBALS['SITE_DB']->query_select('news_categories', array('id', 'nc_title'), array('nc_owner' => NULL));
     foreach ($_categories as $i => $_category) {
         $_categories[$i]['text_original'] = get_translated_text($_category['nc_title']);
     }
     $categories = collapse_2d_complexity('id', 'text_original', $_categories);
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (has_category_access(get_member(), 'news', strval($row['news_category']))) {
             $id = strval($row['id']);
             $author = $row['author'];
             $news_date = date($date_string, $row['date_and_time']);
             $edit_date = is_null($row['edit_date']) ? '' : date($date_string, $row['edit_date']);
             $_title = get_translated_tempcode($row['title']);
             $news_title = xmlentities($_title->evaluate());
             $_summary = get_translated_tempcode($row['news']);
             if ($_summary->is_empty()) {
                 $_summary = get_translated_tempcode($row['news_article']);
             }
             $summary = xmlentities($_summary->evaluate());
             if (!is_null($row['news_article'])) {
                 $_news = get_translated_tempcode($row['news_article']);
                 if ($_news->is_empty()) {
                     $news = '';
                 } else {
                     $news = xmlentities($_news->evaluate());
                 }
             } else {
                 $news = '';
             }
             if (!array_key_exists($row['news_category'], $categories)) {
                 $categories[$row['news_category']] = get_translated_text($GLOBALS['SITE_DB']->query_value('news_categories', 'nc_title', array('id' => $row['news_category'])));
             }
             $category = $categories[$row['news_category']];
             $category_raw = strval($row['news_category']);
             $view_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), get_module_zone('news'), NULL, false, false, true);
             if ($prefix == 'RSS_' && get_option('is_on_comments') == '1' && $row['allow_comments'] >= 1) {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'b4f25f5cf68304f8d402bb06851489d6', 'COMMENT_URL' => $view_url, 'ID' => strval($row['id'])));
             } else {
                 $if_comments = new ocp_tempcode();
             }
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     return array($content, do_lang('NEWS'));
 }
예제 #2
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     require_lang('leader_board');
     require_code('points');
     require_css('points');
     $title = get_page_title('POINT_LEADERBOARD');
     $start_date = intval(get_option('leaderboard_start_date'));
     $weeks = $GLOBALS['SITE_DB']->query('SELECT DISTINCT date_and_time FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'leader_board WHERE date_and_time>=' . strval($start_date) . ' ORDER BY date_and_time DESC');
     if (count($weeks) == 0) {
         warn_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $first_week = $weeks[count($weeks) - 1]['date_and_time'];
     $weeks = collapse_1d_complexity('date_and_time', $weeks);
     $out = new ocp_tempcode();
     foreach ($weeks as $week) {
         $rows = collapse_2d_complexity('lb_member', 'lb_points', $GLOBALS['SITE_DB']->query_select('leader_board', array('lb_member', 'lb_points'), array('date_and_time' => $week)));
         $week_tpl = new ocp_tempcode();
         foreach ($rows as $member => $points) {
             $points_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $member), get_module_zone('points'));
             $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member, false, true);
             $name = $GLOBALS['FORUM_DRIVER']->get_username($member);
             if (is_null($name)) {
                 $name = do_lang('UNKNOWN');
             }
             $week_tpl->attach(do_template('POINTS_LEADERBOARD_ROW', array('_GUID' => '6d323b4b5abea0e82a14cb4745c4af4f', 'POINTS_URL' => $points_url, 'PROFILE_URL' => $profile_url, 'POINTS' => integer_format($points), 'NAME' => $name, 'ID' => strval($member))));
         }
         $nice_week = intval(($week - $first_week) / (7 * 24 * 60 * 60) + 1);
         $out->attach(do_template('POINTS_LEADERBOARD_WEEK', array('_GUID' => '3a0f71bf20f9098e5711e85cf25f6549', 'WEEK' => integer_format($nice_week), 'ROWS' => $week_tpl)));
     }
     return do_template('POINTS_LEADERBOARD_SCREEN', array('_GUID' => 'bab5f7b661435b83800532d3eebd0d54', 'TITLE' => $title, 'WEEKS' => $out));
 }
예제 #3
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'));
 }
예제 #4
0
 /**
  * Standard modular run function for ajax-tree hooks. Generates XML for a tree list, which is interpreted by Javascript and expanded on-demand (via new calls).
  *
  * @param  ?ID_TEXT		The ID to do under (NULL: root)
  * @param  array			Options being passed through
  * @param  ?ID_TEXT		The ID to select by default (NULL: none)
  * @return string			XML in the special category,entry format
  */
 function run($id, $options, $default = NULL)
 {
     require_code('ocf_forums');
     require_code('ocf_forums2');
     $compound_list = array_key_exists('compound_list', $options) ? $options['compound_list'] : false;
     $addable_filter = array_key_exists('addable_filter', $options) ? $options['addable_filter'] : false;
     $stripped_id = $compound_list ? preg_replace('#,.*$#', '', $id) : $id;
     $tree = ocf_get_forum_tree_secure(NULL, is_null($id) ? NULL : intval($id), false, NULL, '', NULL, NULL, $compound_list, 1, true);
     $out = '';
     if (!has_actual_page_access(NULL, 'forumview')) {
         $tree = $compound_list ? array(array(), '') : array();
     }
     $categories = collapse_2d_complexity('id', 'c_title', $GLOBALS['FORUM_DB']->query_select('f_categories', array('id', 'c_title')));
     if ($compound_list) {
         list($tree, ) = $tree;
     }
     foreach ($tree as $t) {
         if ($compound_list) {
             $_id = $t['compound_list'];
         } else {
             $_id = strval($t['id']);
         }
         if ($stripped_id === strval($t['id'])) {
             continue;
         }
         // Possible when we look under as a root
         $title = $t['title'];
         $description = array_key_exists($t['group'], $categories) ? $categories[$t['group']] : '';
         $has_children = $t['child_count'] != 0;
         $selectable = !$addable_filter || ocf_may_post_topic($t['id']);
         $tag = 'category';
         // category
         $out .= '<' . $tag . ' id="' . $_id . '" title="' . xmlentities($title) . '" description="' . xmlentities($description) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="' . ($selectable ? 'true' : 'false') . '"></' . $tag . '>';
     }
     // Mark parent cats for pre-expansion
     if (!is_null($default) && $default != '') {
         $cat = intval($default);
         while (!is_null($cat)) {
             $out .= '<expand>' . strval($cat) . '</expand>';
             $cat = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_parent_forum', array('id' => $cat));
         }
     }
     $tag = 'result';
     // result
     return '<' . $tag . '>' . $out . '</' . $tag . '>';
 }
예제 #5
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 (get_forum_type() != 'ocf') {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'forumview')) {
         return NULL;
     }
     if (is_guest()) {
         return NULL;
     }
     $condition = 'l_time<t_cache_last_time OR (l_time IS NULL AND t_cache_last_time>' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ')';
     $query = ' FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics top LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (top.id=l.l_topic_id AND l.l_member_id=' . strval((int) get_member()) . ') LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND top.t_cache_first_post=t.id WHERE (' . $condition . ') AND t_forum_id IS NOT NULL ' . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND t_validated=1 ' : '') . ' ORDER BY t_cache_last_time DESC';
     $rows = $GLOBALS['FORUM_DB']->query('SELECT *,top.id AS t_id ' . $query, $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['t_id']), get_module_zone('topicview'));
             if ($prefix == 'RSS_') {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('COMMENT_URL' => $view_url, 'ID' => strval($row['t_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('TOPICS_UNREAD'));
 }
예제 #6
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));
 }
예제 #7
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (!addon_installed('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'));
 }
예제 #8
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;
}
예제 #9
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('galleries');
     require_lang('galleries');
     $number = array_key_exists('param', $map) ? intval($map['param']) : 10;
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('galleries');
     $out = new ocp_tempcode();
     $rows1 = $GLOBALS['SITE_DB']->query('SELECT DISTINCT g.name,g.add_date FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'galleries g JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'images i ON g.name=i.cat WHERE i.add_date IS NOT NULL AND name NOT LIKE \'' . db_encode_like('download\\_%') . '\' ORDER BY g.add_date DESC', $number);
     $rows2 = $GLOBALS['SITE_DB']->query('SELECT DISTINCT g.name,g.add_date FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'galleries g JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'videos i ON g.name=i.cat WHERE i.add_date IS NOT NULL AND name NOT LIKE \'' . db_encode_like('download\\_%') . '\' ORDER BY g.add_date DESC', $number);
     $galleries = array_unique(collapse_2d_complexity('name', 'add_date', array_merge($rows1, $rows2)));
     arsort($galleries);
     if (count($galleries) == 0) {
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'e6d16782037d35949646f95656382783', 'HIGH' => false, 'TITLE' => do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('GALLERIES')), 'MESSAGE' => do_lang_tempcode('NO_CATEGORIES'), 'ADD_NAME' => '', 'SUBMIT_URL' => ''));
     } else {
         foreach (array_keys($galleries) as $i => $gallery) {
             if ($i == $number) {
                 break;
             }
             $row = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $gallery), '', 1);
             $out->attach(do_template('GALLERY_SUBGALLERY_WRAP', array('CONTENT' => show_gallery_box($row[0], 'root', true, $zone, false, true))));
         }
     }
     return do_template('BLOCK_MAIN_RECENT_GALLERIES', array('_GUID' => 'a7fca7d625a3d3af362735dad670f6eb', 'CONTENT' => $out, 'NUMBER' => integer_format($number)));
 }
예제 #10
0
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
예제 #11
0
 /**
  * The UI to translate content.
  *
  * @return tempcode		The UI
  */
 function interface_content()
 {
     $title = get_page_title('TRANSLATE_CONTENT');
     if (!multi_lang()) {
         warn_exit(do_lang_tempcode('MULTILANG_OFF'));
     }
     $max = get_param_integer('max', 100);
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     // Fiddle around in order to find what we haven't translated. Subqueries and self joins don't work well enough across different db's
     if (!db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $_done_id_list = collapse_2d_complexity('id', 'text_original', $GLOBALS['SITE_DB']->query_select('translate', array('id', 'text_original'), array('language' => $lang, 'broken' => 0)));
         $done_id_list = '';
         foreach (array_keys($_done_id_list) as $done_id) {
             if ($done_id_list != '') {
                 $done_id_list .= ',';
             }
             $done_id_list .= strval($done_id);
         }
         $and_clause = $done_id_list == '' ? '' : 'AND id NOT IN (' . $done_id_list . ')';
         $query = 'FROM ' . get_table_prefix() . 'translate WHERE ' . db_string_not_equal_to('language', $lang) . ' ' . $and_clause . ' AND ' . db_string_not_equal_to('text_original', '') . ' ORDER BY importance_level';
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT * ' . $query, $max);
     } else {
         $query = 'FROM ' . get_table_prefix() . 'translate a LEFT JOIN ' . get_table_prefix() . 'translate b ON a.id=b.id AND b.broken=0 AND ' . db_string_equal_to('b.language', $lang) . ' WHERE b.id IS NULL AND ' . db_string_not_equal_to('a.language', $lang) . ' AND ' . db_string_not_equal_to('a.text_original', '');
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT a.* ' . $query . (can_arbitrary_groupby() ? ' GROUP BY a.id' : '') . ' ORDER BY a.importance_level', $max);
     }
     $total = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     if (count($to_translate) == 0) {
         inform_exit(do_lang_tempcode('NOTHING_TO_TRANSLATE'));
     }
     require_all_lang($lang, true);
     require_all_open_lang_files($lang);
     // Make our translation page
     require_code('lang2');
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = make_string_tempcode('&nbsp;');
     $last_level = NULL;
     $too_many = count($to_translate) == $max;
     $ids_to_lookup = array();
     foreach ($to_translate as $it) {
         $ids_to_lookup[] = $it['id'];
     }
     $names = find_lang_content_names($ids_to_lookup);
     foreach ($to_translate as $i => $it) {
         if ($it['importance_level'] == 0) {
             continue;
         }
         // Corrupt data
         $id = $it['id'];
         $old = $it['text_original'];
         $current = $this->find_lang_matches($old, $lang);
         $priority = $last_level === $it['importance_level'] ? NULL : do_lang('PRIORITY_' . strval($it['importance_level']));
         $name = $names[$id];
         if (is_null($name)) {
             continue;
         }
         // Orphaned string
         if ($intertrans != '') {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => 'f625cf15c9db5e5af30fc772a7f0d5ff', 'LANG_FROM' => $it['language'], 'LANG_TO' => $lang, 'NAME' => 'trans_' . strval($id), 'OLD' => $old));
         }
         $line = do_template('TRANSLATE_LINE_CONTENT', array('_GUID' => '87a0f5298ce9532839f3206cd0e06051', 'NAME' => $name, 'ID' => strval($id), 'OLD' => $old, 'CURRENT' => $current, 'ACTIONS' => $actions, 'PRIORITY' => $priority));
         $lines .= $line->evaluate();
         /*XHTMLXHTML*/
         $last_level = $it['importance_level'];
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_content', 'lang' => $lang), '_SELF');
     require_code('lang2');
     return do_template('TRANSLATE_SCREEN_CONTENT_SCREEN', array('_GUID' => 'af732c5e595816db1c6f025c4b8fa6a2', 'MAX' => integer_format($max), 'TOTAL' => integer_format($total - $max), 'LANG_ORIGINAL_NAME' => get_site_default_lang(), 'LANG_NICE_ORIGINAL_NAME' => lookup_language_full_name(get_site_default_lang()), 'LANG_NICE_NAME' => lookup_language_full_name($lang), 'TOO_MANY' => $too_many, 'INTERTRANS' => $intertrans, 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
예제 #12
0
 /**
  * The UI to confirm which subscribers to prune.
  *
  * @return tempcode		The UI
  */
 function bounce_filter_c()
 {
     $title = get_page_title('BOUNCE_FILTER');
     disable_php_memory_limit();
     // In case of a huge number
     $username = post_param('username');
     $password = post_param('password');
     $server = post_param('server');
     $port = post_param_integer('port');
     $box = post_param('box');
     $mbox = @imap_open($box, $username, $password);
     if ($mbox === false) {
         warn_exit(do_lang_tempcode('IMAP_ERROR', imap_last_error()));
     }
     $fields = '';
     //new ocp_tempcode();
     require_code('form_templates');
     $all_subscribers = array();
     $all_subscribers += collapse_2d_complexity('email', 'id', $GLOBALS['SITE_DB']->query_select('newsletter', array('email', 'id')));
     if (get_forum_type() == 'ocf') {
         $all_subscribers += collapse_2d_complexity('m_email_address', 'id', $GLOBALS['FORUM_DB']->query_select('f_members', array('m_email_address', 'id'), array('m_allow_emails_from_staff' => 1)));
     }
     $headers = imap_search($mbox, 'UNDELETED');
     if ($headers === false) {
         $headers = array();
     }
     $num = 0;
     foreach ($headers as $val) {
         $msg = imap_body($mbox, $val);
         $matches = array();
         $num_matches = preg_match_all("#<([^\n<>@]+@[^\n<>@]+)>#", $msg, $matches);
         if ($num_matches != 0) {
             $overview = imap_headerinfo($mbox, $val);
             $body = imap_body($mbox, $val);
             $checked = strpos($body, 'X-Failed-Recipients') !== false || strpos($body, '5.1.1') !== false || strpos($body, '5.1.6') !== false || strpos($body, '5.7.1') !== false;
             for ($i = 0; $i < $num_matches; $i++) {
                 $m = $matches[1][$i];
                 $m = str_replace('@localhost.localdomain', '', $m);
                 if ($m != get_option('staff_address') && array_key_exists($m, $all_subscribers)) {
                     $tick = form_input_tick($m, $overview->subject . '.', 'email_' . strval($num), $checked, NULL, $m);
                     $fields .= $tick->evaluate();
                     // HTMLHTML
                     //$fields->attach($tick);
                     $num++;
                     unset($all_subscribers[$m]);
                     // So as to make the list no longer than needed; each subscriber only considered once
                 }
             }
         }
     }
     imap_close($mbox);
     if ($num == 0) {
         warn_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $submit_name = do_lang_tempcode('PROCEED');
     $post_url = get_self_url();
     $post_url = build_url(array('page' => '_SELF', 'type' => 'bounce_filter_d'), '_SELF');
     return do_template('FORM_SCREEN', array('SKIP_VALIDATION' => true, 'HIDDEN' => build_keep_post_fields(), 'TITLE' => $title, 'TEXT' => do_lang_tempcode('BOUNCE_WHICH'), 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
예제 #13
0
 /**
  * Get the forum usergroup list.
  *
  * @return array			The usergroup list
  */
 function _get_usergroup_list()
 {
     $results = $this->connection->query('SELECT group_id,group_name FROM ' . $this->connection->get_table_prefix() . 'groups');
     $results2 = collapse_2d_complexity('group_id', 'group_name', $results);
     return $results2;
 }
예제 #14
0
/**
 * Generate a tempcode tree based selection list (ala nice_get_*) for choosing a forum OR a map of details. Also capable of getting comma-separated ancester forum lists. Also capable of displaying topic lists in the tree. In other words... this function is incredibly powerful, and complex.
 *
 * @param  ?MEMBER		The member that the view privileges are done for (NULL: current member).
 * @param  ?AUTO_LINK	The forum we are starting from (NULL: capture the whole tree).
 * @param  boolean		Whether to get a tempcode list (as opposed to a list of maps).
 * @param  ?array			The forum(s) to select by default (NULL: no preference). Only applies if !$topics_too. An array of AUTO_LINK's (for IDs) or strings (for names).
 * @param  string			The ancester list at this point of the recursion (blank for the start).
 * @param  ?AUTO_LINK	ID of a forum to skip display/recursion for (NULL: none).
 * @param  ?boolean		Whether the child forums are ordered alphabetically (NULL: find from DB).
 * @param  boolean		Whether to generate a compound list (a list of all the ancesters, for each point in the forum tree) as well as the tree.
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  boolean		Whether to generate tree statistics.
 * @return mixed			Each tempcode of the tree if $field_format or else a list of maps, OR (if $use_compound_list) a pair of the tempcode and the compound list.
 */
function ocf_get_forum_tree_secure($member_id = NULL, $base_forum = NULL, $field_format = false, $selected_forum = NULL, $tree = '', $skip = NULL, $order_sub_alpha = NULL, $use_compound_list = false, $levels = NULL, $do_stats = false)
{
    if ($levels == -1 && !$use_compound_list) {
        return $use_compound_list ? array(array(), '') : array();
    }
    global $FORUM_TREE_SECURE_CACHE;
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    if (is_null($order_sub_alpha)) {
        if (is_null($base_forum)) {
            $order_sub_alpha = false;
        } else {
            $order_sub_alpha = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_order_sub_alpha', array('id' => $base_forum));
        }
    }
    $out = array();
    $order = $order_sub_alpha ? 'f_name' : 'f_position,id';
    $forums = array();
    if (is_null($FORUM_TREE_SECURE_CACHE)) {
        $FORUM_TREE_SECURE_CACHE = mixed();
        $num_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)');
        $FORUM_TREE_SECURE_CACHE = $num_forums >= 300;
        // Mark it as 'huge'
    }
    if ($FORUM_TREE_SECURE_CACHE === true) {
        $forums = $GLOBALS['FORUM_DB']->query('SELECT id,f_order_sub_alpha,f_name,f_category_id,f_parent_forum,f_position FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id IS NOT NULL AND ' . db_string_equal_to('f_redirection', '') . ' AND ' . (is_null($base_forum) ? 'f_parent_forum IS NULL' : 'f_parent_forum=' . strval($base_forum)) . ' ORDER BY f_position', 200);
    } else {
        if (is_null($FORUM_TREE_SECURE_CACHE) || $FORUM_TREE_SECURE_CACHE === false) {
            $FORUM_TREE_SECURE_CACHE = $GLOBALS['FORUM_DB']->query('SELECT id,f_order_sub_alpha,f_name,f_category_id,f_parent_forum,f_position FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id IS NOT NULL AND ' . db_string_equal_to('f_redirection', '') . ' ORDER BY f_position');
        }
        foreach ($FORUM_TREE_SECURE_CACHE as $x) {
            if ($x['f_parent_forum'] === $base_forum) {
                $forums[] = $x;
            }
        }
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = $order;
    uasort($forums, 'multi_sort');
    $compound_list = '';
    foreach ($forums as $forum) {
        $access = has_category_access($member_id, 'forums', strval($forum['id']));
        $cat_sort_key = '!' . (is_null($forum['f_category_id']) ? '' : strval($forum['f_category_id']));
        if ($access && $skip !== $forum['id'] && $levels !== 0) {
            $cat_bit = '';
            if (!is_null($forum['f_category_id'])) {
                global $CATEGORY_TITLES;
                if (is_null($CATEGORY_TITLES)) {
                    $CATEGORY_TITLES = collapse_2d_complexity('id', 'c_title', $GLOBALS['FORUM_DB']->query_select('f_categories', array('id', 'c_title')));
                }
                $cat_bit = array_key_exists($forum['f_category_id'], $CATEGORY_TITLES) ? $CATEGORY_TITLES[$forum['f_category_id']] : do_lang('NA');
                //if (strlen($pre.$cat_bit)>26) $cat_bit='...';
            }
            if ($field_format) {
                $pre = $tree == '' ? '' : $tree . ' > ';
                $below = ocf_get_forum_tree_secure($member_id, $forum['id'], true, $selected_forum, $pre . $forum['f_name'], $skip, $forum['f_order_sub_alpha'], $use_compound_list, NULL, $do_stats);
                if ($use_compound_list) {
                    list($below, $_compound_list) = $below;
                    $compound_list .= strval($forum['id']) . ',' . $_compound_list;
                }
                $selected = false;
                if (!is_null($selected_forum)) {
                    foreach ($selected_forum as $s) {
                        if (is_integer($s) && $s == $forum['id']) {
                            $selected = true;
                        }
                        if (is_string($s) && $s == $forum['f_name']) {
                            $selected = true;
                        }
                    }
                }
                $line = do_template('OCF_FORUM_LIST_LINE', array('_GUID' => '2fb4bd9ed5c875de6155bef588c877f9', 'PRE' => $pre, 'NAME' => $forum['f_name'], 'CAT_BIT' => $cat_bit));
                if (!array_key_exists($cat_sort_key, $out)) {
                    $out[$cat_sort_key] = '';
                }
                $out[$cat_sort_key] .= '<option value="' . (!$use_compound_list ? strval($forum['id']) : strval($forum['id']) . ',' . $_compound_list) . '"' . ($selected ? ' selected="selected"' : '') . '>' . $line->evaluate() . '</option>';
                //$out.=$below;
                if ($levels !== 0) {
                    $out[$cat_sort_key] .= $below->evaluate();
                }
            } else {
                if ($use_compound_list) {
                    $below = ocf_get_forum_tree_secure($member_id, $forum['id'], true, $selected_forum, $forum['f_name'], $skip, $forum['f_order_sub_alpha'], $use_compound_list, NULL, $do_stats);
                    list($below, $_compound_list) = $below;
                    $compound_list .= strval($forum['id']) . ',' . $_compound_list;
                }
                $element = array('id' => $forum['id'], 'compound_list' => !$use_compound_list ? strval($forum['id']) : strval($forum['id']) . ',' . $_compound_list, 'second_cat' => $cat_bit, 'title' => $forum['f_name'], 'group' => $forum['f_category_id'], 'children' => ocf_get_forum_tree_secure($member_id, $forum['id'], false, $selected_forum, $tree, $skip, false, false, $levels, $do_stats));
                if ($do_stats) {
                    $element['child_count'] = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)', array('f_parent_forum' => $forum['id']));
                }
                if (!array_key_exists($cat_sort_key, $out)) {
                    $out[$cat_sort_key] = array();
                }
                $out[$cat_sort_key][] = $element;
            }
        }
    }
    // Up to now we worked into an array, so we could benefit from how it would auto-sort into the category>forum-position ordering ocPortal uses. Now we need to unzip it
    $real_out = mixed();
    if ($field_format) {
        $real_out = '';
        foreach ($out as $str) {
            $real_out .= $str;
        }
    } else {
        $real_out = array();
        foreach ($out as $arr) {
            $real_out = array_merge($real_out, $arr);
        }
    }
    if ($field_format) {
        if ($GLOBALS['XSS_DETECT']) {
            ocp_mark_as_escaped($real_out);
        }
        $real_out = make_string_tempcode($real_out);
    }
    if ($use_compound_list) {
        return array($real_out, $compound_list);
    } else {
        return $real_out;
    }
}
예제 #15
0
 /**
  * The actualiser to do an import.
  *
  * @return tempcode		The UI
  */
 function do_import()
 {
     $refresh_url = get_self_url(true, false, array('type' => 'import'), true);
     $refresh_time = either_param_integer('refresh_time', 15);
     // Shouldn't default, but reported on some systems to do so
     if (function_exists('set_time_limit')) {
         @set_time_limit($refresh_time);
     }
     header('Content-type: text/html; charset=' . get_charset());
     @ini_set('log_errors', '0');
     global $I_REFRESH_URL;
     $I_REFRESH_URL = $refresh_url;
     require_code('database_action');
     $title = get_page_title('IMPORT');
     $importer = get_param('importer');
     require_code('hooks/modules/admin_import/' . filter_naughty_harsh($importer));
     $object = object_factory('Hook_' . filter_naughty_harsh($importer));
     // Get data
     $old_base_dir = either_param('old_base_dir');
     if (method_exists($object, 'verify_base_path') && !$object->verify_base_path($old_base_dir)) {
         warn_exit(do_lang_tempcode('BAD_IMPORT_PATH', escape_html($old_base_dir)));
     }
     if (method_exists($object, 'probe_db_access')) {
         list($db_name, $db_user, $db_password, $db_table_prefix) = $object->probe_db_access(either_param('old_base_dir'));
     } else {
         $db_name = either_param('db_name');
         $db_user = either_param('db_user');
         $db_password = either_param('db_password');
         $db_table_prefix = either_param('db_table_prefix');
     }
     if ($db_name == get_db_site() && $importer == 'ocp_merge' && $db_table_prefix == $GLOBALS['SITE_DB']->get_table_prefix()) {
         warn_exit(do_lang_tempcode('IMPORT_SELF_NO'));
     }
     $import_source = is_null($db_name) ? NULL : new database_driver($db_name, get_db_site_host(), $db_user, $db_password, $db_table_prefix);
     // Some preliminary tests
     $happy = get_param_integer('happy', 0);
     if (method_exists($object, 'pre_import_tests') && $happy == 0) {
         $ui = $object->pre_import_tests($import_source, $db_table_prefix, $old_base_dir);
         if (!is_null($ui)) {
             return $ui;
         }
     }
     // Save data
     $GLOBALS['SITE_DB']->query_delete('import_session', array('imp_session' => get_session_id()), '', 1);
     $GLOBALS['SITE_DB']->query_insert('import_session', array('imp_hook' => '', 'imp_old_base_dir' => $old_base_dir, 'imp_db_name' => is_null($db_name) ? '' : $db_name, 'imp_db_user' => is_null($db_user) ? '' : $db_user, 'imp_db_table_prefix' => is_null($db_table_prefix) ? '' : $db_table_prefix, 'imp_refresh_time' => $refresh_time, 'imp_session' => get_session_id()));
     $info = $object->info();
     $_import_list = $info['import'];
     $out = new ocp_tempcode();
     $parts_done = collapse_2d_complexity('imp_id', 'imp_session', $GLOBALS['SITE_DB']->query_select('import_parts_done', array('imp_id', 'imp_session'), array('imp_session' => get_session_id())));
     $import_last = '-1';
     if (get_forum_type() != 'ocf') {
         require_code('forum/ocf');
         $GLOBALS['OCF_DRIVER'] = new forum_driver_ocf();
         $GLOBALS['OCF_DRIVER']->connection = $GLOBALS['SITE_DB'];
         $GLOBALS['OCF_DRIVER']->MEMBER_ROWS_CACHED = array();
     }
     $_import_list[] = 'ocf_switch';
     $all_skipped = true;
     $lang_array = array();
     $hooks = find_all_hooks('modules', 'admin_import_types');
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/modules/admin_import_types/' . filter_naughty_harsh($hook));
         $_hook = object_factory('Hook_admin_import_types_' . filter_naughty_harsh($hook));
         $lang_array += $_hook->run();
     }
     foreach ($_import_list as $import) {
         $import_this = either_param_integer('import_' . $import, 0);
         if ($import_this == 1) {
             $dependency = NULL;
             if (array_key_exists('dependencies', $info) && array_key_exists($import, $info['dependencies'])) {
                 foreach ($info['dependencies'][$import] as $_dependency) {
                     if (!array_key_exists($_dependency, $parts_done) && isset($lang_array[$_dependency])) {
                         $dependency = $_dependency;
                     }
                 }
             }
             if (is_null($dependency)) {
                 if ($import == 'ocf_switch') {
                     $out->attach($this->ocf_switch());
                 } else {
                     $function_name = 'import_' . $import;
                     ocf_over_local();
                     $func_output = call_user_func_array(array($object, $function_name), array($import_source, $db_table_prefix, $old_base_dir));
                     if (!is_null($func_output)) {
                         $out->attach($func_output);
                     }
                     ocf_over_msn();
                 }
                 $parts_done[$import] = get_session_id();
                 $import_last = $import;
                 $all_skipped = false;
                 $GLOBALS['SITE_DB']->query_delete('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id()), '', 1);
                 $GLOBALS['SITE_DB']->query_insert('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id()));
             } else {
                 $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => 'b2a853f5fb93beada51a3eb8fbd1575f', 'MESSAGE' => do_lang_tempcode('IMPORT_OF_SKIPPED', escape_html($import), escape_html($dependency)))));
             }
         }
     }
     if (!$all_skipped) {
         $lang_code = 'SUCCESS';
         if (count($GLOBALS['ATTACHED_MESSAGES_RAW']) != 0) {
             $lang_code = 'SOME_ERRORS_OCCURRED';
         }
         $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => '4c4860d021814ffd1df6e21e712c7b44', 'MESSAGE' => do_lang_tempcode($lang_code))));
     }
     log_it('IMPORT');
     // Quick and simple decacheing. No need to be smart about this.
     delete_value('ocf_member_count');
     delete_value('ocf_topic_count');
     delete_value('ocf_post_count');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IMPORT')), array('_SELF:_SELF:session', do_lang_tempcode('IMPORT_SESSION')), array('_SELF:_SELF:hook:importer=' . $importer . ':session=' . get_param('session'), do_lang_tempcode('IMPORT'))));
     breadcrumb_set_self(do_lang_tempcode('START'));
     $back_url = build_url(array('page' => '_SELF', 'type' => 'hook', 'importer' => get_param('importer'), 'just' => $import_last), '_SELF');
     $_GET['just'] = $import_last;
     return $this->choose_actions($out);
 }
예제 #16
0
파일: aef.php 프로젝트: erico-deh/ocPortal
 /**
  * Get the forum usergroup list.
  *
  * @return array			The usergroup list
  */
 function _get_usergroup_list()
 {
     $results = $this->connection->query('SELECT member_group,mem_gr_name FROM ' . $this->connection->get_table_prefix() . 'user_groups WHERE post_count=-1');
     $mod_results = array();
     foreach ($results as $key => $value) {
         $mod_results[] = array('group_id' => $value['member_group'], 'group_name' => $value['mem_gr_name']);
     }
     $results2 = collapse_2d_complexity('group_id', 'group_name', $mod_results);
     return $results2;
 }
global $THEME_WIZARD_IMAGES, $THEME_WIZARD_IMAGES_NO_WILD, $IMG_CODES;
if (function_exists('imagecolorallocatealpha')) {
    require_code('themes2');
    require_code('abstract_file_manager');
    $full_img_set = array();
    foreach ($THEME_WIZARD_IMAGES as $expression) {
        if (substr($expression, -1) == '*') {
            $expression = substr($expression, 0, strlen($expression) - 2);
            // remove "/*"
            $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/' . filter_naughty('default') . '/default/images', $expression)));
            $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty('default') . '/images/' . fallback_lang(), $expression)));
        } else {
            $full_img_set[] = $expression;
        }
    }
    $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $theme)));
    foreach ($full_img_set as $image_code) {
        if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
            if (array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $theme . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
                continue;
            }
            $orig_path = find_theme_image($image_code, true, true, 'default', 'EN');
            if ($orig_path == '') {
                continue;
            }
            // Theme has specified non-existent image as themewizard-compatible
            if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                $composite = 'themes/' . filter_naughty($theme) . '/images/EN/';
            } else {
                $composite = 'themes/' . filter_naughty($theme) . '/images/';
            }
예제 #18
0
파일: wbb2.php 프로젝트: erico-deh/ocPortal
 /**
  * Get the forum usergroup list.
  *
  * @return array			The usergroup list
  */
 function _get_usergroup_list()
 {
     return collapse_2d_complexity('groupid', 'title', $this->connection->query_select('groups', array('groupid', 'title')));
 }
예제 #19
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	Results
  */
 function run()
 {
     // Script to fix db_meta registration for adhoc created tables
     $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
     $db_meta = list_to_map_2('m_table', $GLOBALS['SITE_DB']->query_select('db_meta', array('m_table', 'm_name', 'm_type')));
     $db_meta_indices = list_to_map_2('i_table', $GLOBALS['SITE_DB']->query_select('db_meta_indices', array('i_table', 'i_name', 'i_fields')));
     $sql = '';
     $tables = $GLOBALS['SITE_DB']->query('SHOW TABLES');
     foreach ($tables as $_table) {
         $table = array_shift($_table);
         if (substr($table, 0, strlen(get_table_prefix())) != get_table_prefix()) {
             continue;
         }
         $indexes = list_to_map_2('Key_name', $GLOBALS['SITE_DB']->query('SHOW INDEXES FROM ' . $table));
         $columns = $GLOBALS['SITE_DB']->query('SHOW COLUMNS FROM ' . $table);
         $table = substr($table, strlen(get_table_prefix()));
         if ($table == 'db_meta') {
             continue;
         }
         if ($table == 'db_meta_indices') {
             continue;
         }
         foreach ($indexes as $name => $_index) {
             if ($name == 'PRIMARY') {
                 continue;
             }
             if ($name == '') {
                 $name = uniqid('', true);
             }
             $fulltext = $_index[0]['Index_type'] == 'FULLTEXT';
             $fields = '';
             foreach ($_index as $_field) {
                 if ($fields != '') {
                     $fields .= ',';
                 }
                 $fields .= $_field['Column_name'];
             }
             if (array_key_exists($table, $db_meta_indices)) {
                 foreach ($db_meta_indices[$table] as $index) {
                     if ($index['i_fields'] == $fields) {
                         continue 2;
                     }
                 }
             }
             $sql .= 'INSERT INTO ' . get_table_prefix() . 'db_meta_indices (i_table,i_name,i_fields) VALUES (\'' . db_escape_string($table) . '\',\'' . db_escape_string($name) . '\',\'' . db_escape_string($fields) . '\');' . "\n";
         }
         if (!array_key_exists($table, $db_meta)) {
             $db_table = array();
         } else {
             $db_table = collapse_2d_complexity('m_name', 'm_type', $db_meta[$table]);
         }
         foreach ($columns as $column) {
             $field = $column['Field'];
             $_type = $column['Type'];
             $null_ok = $column['Null'] != 'NO';
             $key = $column['Key'] == 'PRI';
             $auto = $column['Extra'] == 'auto_increment';
             $type = strpos($_type, 'int') !== false ? 'INTEGER' : 'SHORT_TEXT';
             switch ($_type) {
                 case 'varchar(5)':
                     //$type='LANGUAGE_NAME';	Ideally, but we cannot assume
                     $type = 'ID_TEXT';
                     break;
                 case 'varchar(33)':
                     //$type='MD5';	Ideally, but we cannot assume
                     $type = 'ID_TEXT';
                     break;
                 case 'varchar(40)':
                     if (strpos($field, 'ip_address') !== false) {
                         $type = 'IP';
                     } else {
                         $type = 'MINIID_TEXT';
                     }
                     break;
                 case 'varchar(80)':
                     $type = 'ID_TEXT';
                     break;
                 case 'varchar(255)':
                     if (strpos($field, 'url') !== false) {
                         $type = 'URLPATH';
                     } else {
                         $type = 'SHORT_TEXT';
                     }
                     break;
                 case 'tinyint(1)':
                     $type = 'BINARY';
                     break;
                 case 'tinyint(4)':
                     $type = 'SHORT_INTEGER';
                     break;
                 case 'int(10) unsigned':
                     if (strpos($field, 'date') !== false || strpos($field, 'time') !== false) {
                         $type = 'TIME';
                     } else {
                         $type = $auto ? 'AUTO' : 'LONG_TRANS';
                         // Also could be... SHORT_TRANS or UINTEGER... but we can't tell this at all
                     }
                     break;
                 case 'int(11)':
                     if ($auto) {
                         $type = 'AUTO';
                     } else {
                         if (strpos($field, 'group') !== false) {
                             $type = 'GROUP';
                         } elseif (strpos($field, 'user') !== false || strpos($field, 'member') !== false) {
                             $type = 'USER';
                         } elseif (strpos($field, '_id') !== false) {
                             $type = 'AUTO_LINK';
                         } else {
                             $type = 'INTEGER';
                         }
                         $type = 'INTEGER';
                     }
                     break;
                 case 'real':
                 case 'double':
                     $type = 'REAL';
                     break;
                 case 'longtext':
                     $type = 'LONG_TEXT';
                     break;
             }
             if ($key) {
                 $type = '*' . $type;
             } elseif ($null_ok) {
                 $type = '?' . $type;
             }
             if (!array_key_exists($field, $db_table)) {
                 $micro_sql = 'INSERT INTO ' . get_table_prefix() . 'db_meta (m_table,m_name,m_type) VALUES (\'' . db_escape_string($table) . '\',\'' . db_escape_string($field) . '\',\'' . db_escape_string($type) . '\');' . "\n";
                 $sql .= $micro_sql;
                 $GLOBALS['SITE_DB']->query($micro_sql);
             }
         }
     }
     if ($sql == '') {
         return do_lang_tempcode('NO_MYSQL_QUERY_CHANGES_MADE');
     }
     return do_lang_tempcode('MYSQL_QUERY_CHANGES_MADE', escape_html($sql));
 }
예제 #20
0
/**
 * Make a theme. Note that this will trigger the AFM.
 *
 * @param  string		Name of the theme.
 * @param  ID_TEXT	The theme it's being generated from
 * @param  ID_TEXT	The algorithm to use
 * @set equations hsv
 * @param  string		Seed colour to use.
 * @param  boolean	Whether to use the theme immediately.
 * @param  ?boolean  Whether it will be a dark theme (NULL: autodetect).
 * @param  boolean	Whether to inherit the CSS, for easier theme upgrading.
 */
function make_theme($themename, $source_theme, $algorithm, $seed, $use, $dark = false, $inherit_css = false)
{
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    load_themewizard_params_from_theme($source_theme, $algorithm == 'hsv');
    if (file_exists(get_custom_file_base() . '/themes/' . $themename)) {
        require_code('abstract_file_manager');
        force_have_afm_details();
        $extending_existing = true;
    } else {
        if ($source_theme == 'default') {
            actual_add_theme($themename);
        } else {
            require_code('themes3');
            actual_copy_theme($source_theme, $themename);
        }
        $extending_existing = false;
    }
    if ($seed != find_theme_seed($source_theme) || $dark != find_theme_dark($source_theme)) {
        list($colours, $landscape) = calculate_theme($seed, $source_theme, $algorithm, 'colours', $dark);
        // Make images
        global $THEME_WIZARD_IMAGES, $THEME_WIZARD_IMAGES_NO_WILD, $IMG_CODES;
        if (function_exists('imagecolorallocatealpha')) {
            require_code('themes2');
            $full_img_set = array();
            foreach ($THEME_WIZARD_IMAGES as $expression) {
                if (substr($expression, -1) == '*') {
                    $expression = substr($expression, 0, strlen($expression) - 2);
                    // remove "/*"
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images', $expression)));
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images/' . fallback_lang(), $expression)));
                } else {
                    $full_img_set[] = $expression;
                }
            }
            if ($extending_existing) {
                $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $themename)));
            } else {
                $temp_all_ids = array();
            }
            $_langs = find_all_langs(true);
            foreach ($full_img_set as $image_code) {
                if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
                    if ($extending_existing && array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $themename . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
                        continue;
                    }
                    foreach (array_keys($_langs) as $lang) {
                        $orig_path = find_theme_image($image_code, true, true, $source_theme, $lang);
                        if ($orig_path == '') {
                            continue;
                        }
                        // Theme has specified non-existent image as themewizard-compatible
                        if (strpos($orig_path, '/' . $lang . '/') === false && $lang != fallback_lang()) {
                            continue;
                        }
                        if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/' . $lang . '/';
                        } else {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/';
                        }
                        $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
                        $saveat_url = $composite . $image_code . '.png';
                        // Wipe out ones that might have been copied from source theme
                        if ($source_theme != 'default' && strpos($orig_path, 'images_custom') !== false) {
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.png');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpg');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.gif');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpeg');
                        }
                        if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                            $image = calculate_theme($seed, $source_theme, $algorithm, $image_code, $dark, $colours, $landscape, $lang);
                            if (!is_null($image)) {
                                $pos = strpos($image_code, '/');
                                if ($pos !== false || strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                                    afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                                }
                                @imagepng($image, $saveat) or intelligent_write_error($saveat);
                                imagedestroy($image);
                                fix_permissions($saveat);
                                sync_file($saveat);
                                actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                                //if ($lang==fallback_lang()) $IMG_CODES['site'][$image_code]=$saveat_url;
                            }
                        } else {
                            actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                        }
                    }
                }
            }
        }
        // Make sheets
        $dh = opendir(get_file_base() . '/themes/' . filter_naughty($source_theme) . ($source_theme == 'default' ? '/css/' : '/css_custom/'));
        while (($sheet = readdir($dh)) !== false) {
            if (substr($sheet, -4) == '.css') {
                $saveat = get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet;
                if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                    $fp = @fopen($saveat, 'wt') or intelligent_write_error(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet);
                    if ($inherit_css) {
                        $output = '{+START,CSS_INHERIT,' . basename($sheet, '.css') . ',' . filter_naughty($source_theme) . ',' . $seed . ',' . ($dark ? '1' : '0') . ',' . $algorithm . '}{+END}';
                    } else {
                        $output = theme_wizard_colours_to_sheet($sheet, $landscape, $source_theme, $algorithm, $seed);
                    }
                    if (fwrite($fp, $output) < strlen($output)) {
                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                    }
                    fclose($fp);
                    fix_permissions($saveat);
                    sync_file($saveat);
                    if (!$inherit_css) {
                        $c_success = @copy(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/css/' . $sheet, $saveat . '.editfrom');
                        if ($c_success !== false) {
                            fix_permissions($saveat . '.editfrom');
                            sync_file($saveat . '.editfrom');
                        }
                    } else {
                        @unlink($saveat . '.editfrom');
                    }
                }
            }
        }
    }
    // Use it, if requested
    if ($use) {
        $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'zones SET zone_theme=\'' . db_escape_string($themename) . '\' WHERE ' . db_string_not_equal_to('zone_name', 'cms') . ' AND ' . db_string_not_equal_to('zone_name', 'adminzone'));
        $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
        $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename));
        foreach (array_keys($groups) as $group_id) {
            if (in_array($group_id, $admin_groups)) {
                continue;
            }
            $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename, 'group_id' => $group_id));
        }
        persistant_cache_empty();
    }
}
예제 #21
0
/**
 * Get a map of details relating to the view of a certain forum of a certain member.
 *
 * @param  integer	The start row for getting details of topics in the forum (i.e. 0 is newest, higher is starting further back in time).
 * @param  ?integer	The maximum number of topics to get detail of (NULL: default).
 * @param  ?MEMBER	The member viewing (NULL: current member).
 * @return array		The details.
 */
function ocf_get_forum_view($start = 0, $max = NULL, $forum_id = NULL)
{
    if (is_null($max)) {
        $max = intval(get_option('forum_topics_per_page'));
    }
    $member_id = get_member();
    load_up_all_module_category_permissions($member_id, 'forums');
    if (is_null($forum_id)) {
        /*$forum_info[0]['f_name']=do_lang('ROOT_FORUM'); This optimisation was more trouble that it was worth, and constraining
        		$forum_info[0]['f_description']='';
        		$forum_info[0]['f_parent_forum']=NULL;*/
        $forum_id = db_get_first_id();
    }
    $forum_info = $GLOBALS['FORUM_DB']->query_select('f_forums f', array('f_redirection', 'f_intro_question', 'f_intro_answer', 'f_order_sub_alpha', 'f_parent_forum', 'f_name', 'f_description', 'f_order'), array('f.id' => $forum_id), '', 1, NULL, false, array('f_description', 'f_intro_question'));
    if (!array_key_exists(0, $forum_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    if ($forum_info[0]['f_redirection'] != '' && looks_like_url($forum_info[0]['f_redirection'])) {
        header('Location: ' . $forum_info[0]['f_redirection']);
        exit;
    }
    if (!is_null($forum_id)) {
        if (!has_category_access($member_id, 'forums', strval($forum_id))) {
            access_denied('CATEGORY_ACCESS_LEVEL');
        }
        // We're only allowed to view it existing from a parent forum, or nothing at all -- so access denied brother!
    }
    // Find our subforums first
    $order = $forum_info[0]['f_order_sub_alpha'] ? 'f_name' : 'f_position';
    $_max_forum_detail = get_value('max_forum_detail');
    $max_forum_detail = is_null($_max_forum_detail) ? 100 : intval($_max_forum_detail);
    $huge_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)') > $max_forum_detail;
    if ($huge_forums) {
        $_max_forum_inspect = get_value('max_forum_inspect');
        $max_forum_inspect = is_null($_max_forum_inspect) ? 300 : intval($_max_forum_inspect);
        $subforum_rows = $GLOBALS['FORUM_DB']->query('SELECT f.* FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums f WHERE f.id=' . strval($forum_id) . ' OR f_parent_forum=' . strval($forum_id) . ' ORDER BY f_parent_forum,' . $order, $max_forum_inspect, NULL, false, false, array('f_description', 'f_intro_question'));
        if (count($subforum_rows) == $max_forum_inspect) {
            $subforum_rows = array();
        }
        // Will cause performance breakage
    } else {
        $subforum_rows = $GLOBALS['FORUM_DB']->query_select('f_forums f', array('f.*'), NULL, 'ORDER BY f_parent_forum,' . $order, NULL, NULL, false, array('f_description', 'f_intro_question'));
    }
    $unread_forums = array();
    if (!is_null($forum_id) && get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        // Where are there unread topics in subforums?
        $tree = array();
        $subforum_rows_copy = $subforum_rows;
        $tree = ocf_organise_into_tree($subforum_rows_copy, $forum_id);
        if ($forum_id != db_get_first_id()) {
            $child_or_list = ocf_get_all_subordinate_forums($forum_id, 't_forum_id', $tree);
        } else {
            $child_or_list = '';
        }
        if ($child_or_list != '') {
            $child_or_list .= ' AND ';
        }
        $query = 'SELECT DISTINCT t_forum_id,t.id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (t.id=l_topic_id AND l_member_id=' . strval((int) get_member()) . ') WHERE ' . $child_or_list . 't_cache_last_time>' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND (l_time<t_cache_last_time OR l_time IS NULL)';
        if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
            $query .= ' AND t_validated=1';
        }
        $unread_forums = collapse_2d_complexity('t_forum_id', 'id', $GLOBALS['FORUM_DB']->query($query));
    }
    // Find all the categories that are used
    $categories = array();
    $or_list = '';
    foreach ($subforum_rows as $tmp_key => $subforum_row) {
        if ($subforum_row['f_parent_forum'] != $forum_id) {
            continue;
        }
        if (!has_category_access($member_id, 'forums', strval($subforum_row['id']))) {
            unset($subforum_rows[$tmp_key]);
            continue;
        }
        $category_id = $subforum_row['f_category_id'];
        if (!array_key_exists($category_id, $categories)) {
            $categories[$category_id] = array('subforums' => array());
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $category_id);
        }
    }
    if ($or_list != '') {
        $category_rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_categories WHERE ' . $or_list);
        foreach ($category_rows as $category_row) {
            $category_id = $category_row['id'];
            $title = $category_row['c_title'];
            $description = $category_row['c_description'];
            $expanded_by_default = $category_row['c_expanded_by_default'];
            $categories[$category_id]['title'] = $title;
            $categories[$category_id]['description'] = $description;
            $categories[$category_id]['expanded_by_default'] = $expanded_by_default;
        }
        $categories[NULL]['title'] = '';
        $categories[NULL]['description'] = '';
        $categories[NULL]['expanded_by_default'] = true;
        foreach ($subforum_rows as $subforum_row) {
            if ($subforum_row['f_parent_forum'] != $forum_id) {
                continue;
            }
            $category_id = $subforum_row['f_category_id'];
            //			if (!array_key_exists('position',$categories[$category_id])) $categories[$category_id]['position']=$subforum_row['f_position'];
            $subforum = array();
            $subforum['id'] = $subforum_row['id'];
            $subforum['name'] = $subforum_row['f_name'];
            $subforum['description'] = get_translated_tempcode($subforum_row['f_description'], $GLOBALS['FORUM_DB']);
            $subforum['redirection'] = $subforum_row['f_redirection'];
            $subforum['intro_question'] = get_translated_tempcode($subforum_row['f_intro_question'], $GLOBALS['FORUM_DB']);
            $subforum['intro_answer'] = $subforum_row['f_intro_answer'];
            if (is_numeric($subforum_row['f_redirection'])) {
                $subforum_row = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => intval($subforum_row['f_redirection'])), '', 1);
                $subforum_row = $subforum_row[0];
            }
            if ($subforum_row['f_redirection'] == '' || is_numeric($subforum_row['f_redirection'])) {
                $subforum['num_topics'] = $subforum_row['f_cache_num_topics'];
                $subforum['num_posts'] = $subforum_row['f_cache_num_posts'];
                $subforum['has_new'] = false;
                if (get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
                    $subforums_recurse = ocf_get_all_subordinate_forums($subforum['id'], NULL, $tree[$subforum['id']]['children']);
                    foreach ($subforums_recurse as $subforum_potential) {
                        if (array_key_exists($subforum_potential, $unread_forums)) {
                            $subforum['has_new'] = true;
                        }
                    }
                }
                if (is_null($subforum_row['f_cache_last_forum_id']) || has_category_access($member_id, 'forums', strval($subforum_row['f_cache_last_forum_id']))) {
                    $subforum['last_topic_id'] = $subforum_row['f_cache_last_topic_id'];
                    $subforum['last_title'] = $subforum_row['f_cache_last_title'];
                    $subforum['last_time'] = $subforum_row['f_cache_last_time'];
                    $subforum['last_username'] = $subforum_row['f_cache_last_username'];
                    $subforum['last_member_id'] = $subforum_row['f_cache_last_member_id'];
                    $subforum['last_forum_id'] = $subforum_row['f_cache_last_forum_id'];
                } else {
                    $subforum['protected_last_post'] = true;
                }
                // Subsubforums
                $subforum['children'] = array();
                foreach ($subforum_rows as $tmp_key_2 => $subforum_row2) {
                    if ($subforum_row2['f_parent_forum'] == $subforum_row['id'] && has_category_access($member_id, 'forums', strval($subforum_row2['id']))) {
                        $subforum['children'][$subforum_row2['f_name'] . '__' . strval($subforum_row2['id'])] = array('id' => $subforum_row2['id'], 'name' => $subforum_row2['f_name'], 'redirection' => $subforum_row2['f_redirection']);
                    }
                }
                global $M_SORT_KEY;
                $M_SORT_KEY = 'name';
                uasort($subforum['children'], 'multi_sort');
            }
            $categories[$category_id]['subforums'][] = $subforum;
        }
    }
    // Find topics
    $extra = '';
    if (!has_specific_permission(get_member(), 'see_unvalidated') && !ocf_may_moderate_forum($forum_id, $member_id)) {
        $extra = 't_validated=1 AND ';
    }
    if (is_null($forum_info[0]['f_parent_forum'])) {
        $where = $extra . ' (t_forum_id=' . strval((int) $forum_id) . ')';
    } else {
        $extra2 = '';
        $parent_or_list = ocf_get_forum_parent_or_list($forum_id, $forum_info[0]['f_parent_forum']);
        if ($parent_or_list != '') {
            $extra2 = 'AND (' . $parent_or_list . ')';
        }
        $where = $extra . ' (t_forum_id=' . strval((int) $forum_id) . ' OR (t_cascading=1 ' . $extra2 . '))';
    }
    $order = get_param('order', $forum_info[0]['f_order']);
    $order2 = 't_cache_last_time DESC';
    if ($order == 'first_post') {
        $order2 = 't_cache_first_time DESC';
    } elseif ($order == 'title') {
        $order2 = 't_cache_first_title ASC';
    }
    if (get_value('disable_sunk') !== '1') {
        $order2 = 't_sunk ASC,' . $order2;
    }
    if (is_guest()) {
        $query = 'SELECT ttop.*,t.text_parsed AS _trans_post,NULL AS l_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics ttop LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND ttop.t_cache_first_post=t.id WHERE ' . $where . ' ORDER BY t_cascading DESC,t_pinned DESC,' . $order2;
    } else {
        $query = 'SELECT ttop.*,t.text_parsed AS _trans_post,l_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics ttop LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (ttop.id=l.l_topic_id AND l.l_member_id=' . strval((int) get_member()) . ') LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND ttop.t_cache_first_post=t.id WHERE ' . $where . ' ORDER BY t_cascading DESC,t_pinned DESC,' . $order2;
    }
    $topic_rows = $GLOBALS['FORUM_DB']->query($query, $max, $start);
    if ($start == 0 && count($topic_rows) < $max) {
        $max_rows = $max;
    } else {
        $max_rows = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $where);
    }
    $topics = array();
    $hot_topic_definition = intval(get_option('hot_topic_definition'));
    $or_list = '';
    foreach ($topic_rows as $topic_row) {
        if ($or_list != '') {
            $or_list .= ' OR ';
        }
        $or_list .= 'p_topic_id=' . strval((int) $topic_row['id']);
    }
    if ($or_list != '' && !is_guest()) {
        $involved = $GLOBALS['FORUM_DB']->query('SELECT DISTINCT p_topic_id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list . ') AND p_poster=' . strval((int) get_member()));
        $involved = collapse_1d_complexity('p_topic_id', $involved);
    } else {
        $involved = array();
    }
    foreach ($topic_rows as $topic_row) {
        $topics[] = ocf_get_topic_array($topic_row, $member_id, $hot_topic_definition, in_array($topic_row['id'], $involved));
    }
    $description = get_translated_tempcode($forum_info[0]['f_description'], $GLOBALS['FORUM_DB']);
    $description_text = get_translated_text($forum_info[0]['f_description'], $GLOBALS['FORUM_DB']);
    $out = array('name' => $forum_info[0]['f_name'], 'description' => $description, 'categories' => $categories, 'topics' => $topics, 'max_rows' => $max_rows, 'order' => $order, 'parent_forum' => $forum_info[0]['f_parent_forum']);
    $GLOBALS['META_DATA'] += array('created' => '', 'creator' => '', 'publisher' => '', 'modified' => '', 'type' => 'Forum', 'title' => $forum_info[0]['f_name'], 'identifier' => '_SEARCH:forumview:misc:' . strval($forum_id), 'description' => $description_text, 'image' => find_theme_image('bigicons/forums'));
    // Is there a question/answer situation?
    $question = get_translated_tempcode($forum_info[0]['f_intro_question'], $GLOBALS['FORUM_DB']);
    if (!$question->is_empty()) {
        $is_guest = $member_id == $GLOBALS['OCF_DRIVER']->get_guest_id();
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_ip', 'i_ip', array('i_forum_id' => $forum_id, 'i_ip' => get_ip_address(3)));
        if (is_null($test) && !$is_guest) {
            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_member', 'i_member_id', array('i_forum_id' => $forum_id, 'i_member_id' => $member_id));
        }
        if (is_null($test)) {
            $out['question'] = $question;
            $out['answer'] = $forum_info[0]['f_intro_answer'];
        }
    }
    if (ocf_may_post_topic($forum_id, $member_id)) {
        $out['may_post_topic'] = 1;
    }
    if (ocf_may_moderate_forum($forum_id, $member_id)) {
        $out['may_change_max'] = 1;
        $out['may_move_topics'] = 1;
        if (has_specific_permission(get_member(), 'multi_delete_topics')) {
            $out['may_delete_topics'] = 1;
        }
        // Only super admins can casually delete topics - other staff are expected to trash them. At least deleted posts or trashed topics can be restored!
    }
    return $out;
}
예제 #22
0
/**
 * Find whether a certain gallery has any content (images, videos, or subgalleries).
 *
 * @param  ID_TEXT		The name of the gallery
 * @return boolean		The answer
 */
function gallery_has_content($name)
{
    $num_galleries = NULL;
    global $GALLERY_ENTRIES_CATS_USED;
    if (is_null($GALLERY_ENTRIES_CATS_USED)) {
        $num_galleries = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)');
        $GALLERY_ENTRIES_CATS_USED = array();
        $images_cats = $GLOBALS['SITE_DB']->query_select('images', array('DISTINCT cat'), $num_galleries < 300 ? array('validated' => 1) : array('validated' => 1, 'cat' => $name));
        foreach ($images_cats as $images_cat) {
            $GALLERY_ENTRIES_CATS_USED[$images_cat['cat']] = 1;
        }
        $videos_cats = $GLOBALS['SITE_DB']->query_select('videos', array('DISTINCT cat'), $num_galleries < 300 ? array('validated' => 1) : array('validated' => 1, 'cat' => $name));
        foreach ($videos_cats as $videos_cat) {
            $GALLERY_ENTRIES_CATS_USED[$videos_cat['cat']] = 1;
        }
    }
    if (array_key_exists($name, $GALLERY_ENTRIES_CATS_USED)) {
        if ($num_galleries >= 300) {
            $GALLERY_ENTRIES_CATS_USED = NULL;
        }
        // It's not right so reset it
        return true;
    }
    if ($num_galleries >= 300) {
        $GALLERY_ENTRIES_CATS_USED = NULL;
    }
    // It's not right so reset it
    global $GALLERY_PAIRS;
    if (is_null($GALLERY_PAIRS)) {
        if (is_null($num_galleries)) {
            $num_galleries = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)');
        }
        if ($num_galleries < 300) {
            $GALLERY_PAIRS = collapse_2d_complexity('name', 'parent_id', $GLOBALS['SITE_DB']->query_select('galleries', array('name', 'parent_id')));
        } else {
            return !is_null($GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('parent_id' => $name)));
        }
    }
    foreach ($GALLERY_PAIRS as $_parent_id) {
        if ($_parent_id == $name) {
            return true;
        }
    }
    return false;
}
예제 #23
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'));
 }
예제 #24
0
 /**
  * The UI to show a virtual forum.
  *
  * @param  SHORT_TEXT	The title to show for the v-forum
  * @param  mixed			The condition (a fragment of an SQL query that gets embedded in the context of a topic selection query). May be string, or array of strings (separate queries to run and merge; done for performance reasons relating to DB indexing)
  * @param  string			The ordering of the results
  * @param  boolean		Whether to not show pinning in a separate section
  * @return tempcode		The UI
  */
 function _vforum($title, $condition, $order, $no_pin = false)
 {
     $max = get_param_integer('max', intval(get_option('forum_topics_per_page')));
     $start = get_param_integer('start', 0);
     $type = get_param('type', 'misc');
     $forum_name = do_lang_tempcode('VIRTUAL_FORUM');
     // Find topics
     $extra = '';
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $extra = 't_validated=1';
     }
     if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(get_member(), false, true);
         $group_or_list = '';
         foreach ($groups as $group) {
             if ($group_or_list != '') {
                 $group_or_list .= ' OR ';
             }
             $group_or_list .= 'group_id=' . strval((int) $group);
         }
         if ($extra != '') {
             $extra .= ' AND ';
         }
         $or_list = '';
         global $SITE_INFO;
         if (isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old')) {
             $forum_access = $GLOBALS['FORUM_DB']->query('SELECT category_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'group_category_access WHERE (' . $group_or_list . ') AND ' . db_string_equal_to('module_the_name', 'forums'), NULL, NULL, false, true);
         } else {
             $forum_access = $GLOBALS['FORUM_DB']->query('SELECT category_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'group_category_access WHERE (' . $group_or_list . ') AND ' . db_string_equal_to('module_the_name', 'forums') . ' UNION ALL SELECT category_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'member_category_access WHERE (member_id=' . strval((int) get_member()) . ' AND active_until>' . strval(time()) . ') AND ' . db_string_equal_to('module_the_name', 'forums'), NULL, NULL, false, true);
         }
         foreach ($forum_access as $access) {
             if ($or_list != '') {
                 $or_list .= ' OR ';
             }
             $or_list .= 't_forum_id=' . strval((int) $access['category_name']);
         }
         $extra .= '(' . $or_list . ')';
     }
     if ($extra != '') {
         $extra = ' AND (' . $extra . ') ';
     }
     $max_rows = 0;
     $topic_rows = array();
     foreach (is_array($condition) ? $condition : array($condition) as $_condition) {
         $query = ' FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics top LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (top.id=l.l_topic_id AND l.l_member_id=' . strval((int) get_member()) . ') LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND top.t_cache_first_post=t.id WHERE ((' . $_condition . ')' . $extra . ') AND t_forum_id IS NOT NULL ORDER BY ' . $order;
         $topic_rows = array_merge($topic_rows, $GLOBALS['FORUM_DB']->query('SELECT top.*,t.text_parsed AS _trans_post,l_time' . $query, $max, $start));
         //if (($start==0) && (count($topic_rows)<$max)) $max_rows+=$max; // We know that they're all on this screen
         /*else */
         $max_rows += $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     }
     $hot_topic_definition = intval(get_option('hot_topic_definition'));
     $or_list = '';
     foreach ($topic_rows as $topic_row) {
         if ($or_list != '') {
             $or_list .= ' OR ';
         }
         $or_list .= 'p_topic_id=' . strval((int) $topic_row['id']);
     }
     if ($or_list != '') {
         $involved = $GLOBALS['FORUM_DB']->query('SELECT DISTINCT p_topic_id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list . ') AND p_poster=' . strval((int) get_member()));
         $involved = collapse_1d_complexity('p_topic_id', $involved);
     }
     $topics_array = array();
     foreach ($topic_rows as $topic_row) {
         $topics_array[] = ocf_get_topic_array($topic_row, get_member(), $hot_topic_definition, in_array($topic_row['id'], $involved));
     }
     // Display topics
     $topics = new ocp_tempcode();
     $pinned = false;
     require_code('templates_results_browser');
     $topic_wrapper = new ocp_tempcode();
     $forum_name_map = 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'));
     foreach ($topics_array as $topic) {
         if (!$no_pin && $pinned && !in_array('pinned', $topic['modifiers'])) {
             $topics->attach(do_template('OCF_PINNED_DIVIDER'));
         }
         $pinned = in_array('pinned', $topic['modifiers']);
         $forum_id = array_key_exists('forum_id', $topic) ? $topic['forum_id'] : NULL;
         $_forum_name = array_key_exists($forum_id, $forum_name_map) ? $forum_name_map[$forum_id] : do_lang_tempcode('PERSONAL_TOPICS');
         $topics->attach(ocf_render_topic($topic, true, false, $_forum_name));
     }
     $tree = ocf_forum_breadcrumbs(db_get_first_id(), $title, get_param_integer('keep_forum_root', db_get_first_id()));
     if (!$topics->is_empty()) {
         $results_browser = results_browser(do_lang_tempcode('FORUM_TOPICS'), NULL, $start, 'start', $max, 'max', $max_rows, NULL, $type, true);
         $moderator_actions = '';
         $moderator_actions .= '<option value="mark_topics_read">' . do_lang('MARK_READ') . '</option>';
         if ($title != do_lang('TOPICS_UNREAD')) {
             $moderator_actions .= '<option value="mark_topics_unread">' . do_lang('MARK_UNREAD') . '</option>';
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($moderator_actions);
         }
         $action_url = build_url(array('page' => 'topics', 'redirect' => get_self_url(true)), get_module_zone('topics'));
         $topic_wrapper = do_template('OCF_FORUM_TOPIC_WRAPPER', array('_GUID' => '67356b4daacbed3e3d960d89a57d0a4a', 'MAX' => strval($max), 'ORDER' => '', 'MAY_CHANGE_MAX' => false, 'TREE' => $tree, 'BUTTONS' => '', 'STARTER_TITLE' => '', 'RESULTS_BROWSER' => $results_browser, 'MODERATOR_ACTIONS' => $moderator_actions, 'ACTION_URL' => $action_url, 'TOPICS' => $topics, 'FORUM_NAME' => $forum_name));
     }
     $_buttons = new ocp_tempcode();
     $archive_url = $GLOBALS['FORUM_DRIVER']->forum_url(db_get_first_id(), true);
     $_buttons->attach(do_template('SCREEN_BUTTON', array('TITLE' => do_lang_tempcode('ROOT_FORUM'), 'IMG' => 'all', 'IMMEDIATE' => false, 'URL' => $archive_url)));
     breadcrumb_add_segment($tree);
     return do_template('OCF_FORUM', array('_GUID' => 'd3fa84575727af935eadb2ce2b7c7b3e', 'FILTERS' => '', 'FORUM_NAME' => $forum_name, 'STARTER_TITLE' => '', 'BUTTONS' => $_buttons, 'TOPIC_WRAPPER' => $topic_wrapper, 'CATEGORIES' => ''));
 }
예제 #25
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (has_no_forum()) {
         return new ocp_tempcode();
     }
     require_css('news');
     // Read in variables
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     $limit = array_key_exists('limit', $map) ? intval($map['limit']) : 6;
     $hot = array_key_exists('hot', $map) ? intval($map['hot']) : 0;
     $date_key = array_key_exists('date_key', $map) ? $map['date_key'] : 'lasttime';
     if ($date_key != 'lasttime' && $date_key != 'firsttime') {
         $date_key = 'firsttime';
     }
     $username_key = array_key_exists('username_key', $map) ? $map['username_key'] : 'firstusername';
     if ($username_key != 'lastusername' && $username_key != 'firstusername') {
         $username_key = 'firstusername';
     }
     $memberid_key = $username_key == 'firstusername' ? 'firstmemberid' : 'lastmemberid';
     // Work out exactly what forums we're reading
     $forum_ids = array();
     if (get_forum_type() == 'ocf' && (strpos($forum_name, ',') !== false || strpos($forum_name, '*') !== false || preg_match('#\\d[-\\*\\+]#', $forum_name) != 0 || is_numeric($forum_name))) {
         require_code('ocfiltering');
         $forum_names = ocfilter_to_idlist_using_db($forum_name, 'id', 'f_forums', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
     } else {
         $forum_names = explode(',', $forum_name);
     }
     foreach ($forum_names as $forum_name) {
         if (!is_string($forum_name)) {
             $forum_name = strval($forum_name);
         }
         $forum_name = trim($forum_name);
         if ($forum_name == '<announce>') {
             $forum_id = NULL;
         } else {
             $forum_id = is_numeric($forum_name) ? intval($forum_name) : $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
         }
         if (get_forum_type() == 'ocf' && array_key_exists('check', $map) && $map['check'] == '1') {
             if (!has_category_access(get_member(), 'forums', strval($forum_id))) {
                 continue;
             }
         }
         if (!is_null($forum_id)) {
             $forum_ids[$forum_id] = $forum_name;
         }
     }
     // Block title
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     if (is_numeric($forum_name) && get_forum_type() == 'ocf') {
         $forum_name = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_name', array('id' => intval($forum_name)));
         if (is_null($forum_name)) {
             return paragraph(do_lang_tempcode('MISSING_RESOURCE'));
         }
     }
     $_title = do_lang_tempcode('ACTIVE_TOPICS_IN', escape_html($forum_name));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     // Add topic link
     if (count($forum_names) == 1 && get_forum_type() == 'ocf' && !is_null($forum_id)) {
         $submit_url = build_url(array('page' => 'topics', 'type' => 'new_topic', 'id' => $forum_id), get_module_zone('topics'));
         $add_name = do_lang_tempcode('ADD_TOPIC');
     } else {
         $submit_url = new ocp_tempcode();
         $add_name = new ocp_tempcode();
     }
     // Show all topics
     if (get_forum_type() == 'ocf') {
         $forum_names_map = 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'));
     } else {
         $forum_names_map = NULL;
     }
     if (!has_no_forum()) {
         $max_rows = 0;
         $topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key, $hot == 1);
         $out = new ocp_tempcode();
         if (!is_null($topics)) {
             global $M_SORT_KEY;
             $M_SORT_KEY = $date_key;
             usort($topics, 'multi_sort');
             $topics = array_reverse($topics, false);
             if (count($topics) < $limit && $hot == 1) {
                 $more_topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key);
                 if (is_null($more_topics)) {
                     $more_topics = array();
                 }
                 $topics = array_merge($topics, $more_topics);
             }
             $done = 0;
             $seen = array();
             foreach ($topics as $topic) {
                 if (array_key_exists($topic['id'], $seen)) {
                     continue;
                 }
                 $seen[$topic['id']] = 1;
                 $topic_url = $GLOBALS['FORUM_DRIVER']->topic_url($topic['id'], $forum_name);
                 $topic_url_unread = mixed();
                 if (get_forum_type() == 'ocf') {
                     $topic_url_unread = build_url(array('page' => 'topicview', 'id' => $topic['id'], 'type' => 'first_unread'), get_module_zone('topicview'), NULL, false, false, false, 'first_unread');
                 }
                 $title = escape_html($topic['title']);
                 $date = get_timezoned_date($topic[$date_key]);
                 $username = $topic[$username_key];
                 $member_id = array_key_exists($memberid_key, $topic) ? $topic[$memberid_key] : NULL;
                 if (!is_null($forum_names_map) && !array_key_exists($topic['forum_id'], $forum_names_map)) {
                     continue;
                 }
                 // Maybe Private Topic, slipped in via reference to a missing forum
                 $forum_name = is_null($forum_names_map) ? NULL : $forum_names_map[$topic['forum_id']];
                 $out->attach(do_template('BLOCK_MAIN_FORUM_TOPICS_TOPIC', array('_GUID' => 'ae4e351b3fa5422bf8ecdfb7e49076d1', 'POST' => $topic['firstpost'], 'FORUM_ID' => is_null($forum_names_map) ? NULL : strval($topic['forum_id']), 'FORUM_NAME' => $forum_name, 'TOPIC_LINK' => $topic_url, 'TOPIC_LINK_UNREAD' => $topic_url_unread, 'TITLE' => $title, 'DATE' => $date, 'DATE_RAW' => strval($topic[$date_key]), 'USERNAME' => $username, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'NUM_POSTS' => integer_format($topic['num']))));
                 $done++;
                 if ($done == $limit) {
                     break;
                 }
             }
         }
         if ($out->is_empty()) {
             return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'c76ab018a0746c2875c6cf69c92a01fb', 'HIGH' => false, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($hot == 1 ? 'NO_TOPICS_HOT' : 'NO_TOPICS'), 'ADD_NAME' => $add_name, 'SUBMIT_URL' => $submit_url));
         }
         return do_template('BLOCK_MAIN_FORUM_TOPICS', array('_GUID' => '368b80c49a335ad035b00510681d5008', 'TITLE' => $_title, 'CONTENT' => $out, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'SUBMIT_URL' => $submit_url));
     } else {
         return new ocp_tempcode();
     }
 }
예제 #26
0
 /**
  * Get a list of members who have enabled this notification (i.e. have chosen to or are defaulted to).
  * (No pagination supported, as assumed there are only a small set of members here.)
  *
  * @param  ID_TEXT		Notification code
  * @param  ?SHORT_TEXT	The category within the notification code (NULL: none)
  * @param  ?array			List of member IDs we are restricting to (NULL: no restriction). This effectively works as a intersection set operator against those who have enabled.
  * @param  integer		Start position (for pagination)
  * @param  integer		Maximum (for pagination)
  * @return array			A pair: Map of members to their notification setting, and whether there may be more
  */
 function _all_members_who_have_enabled($only_if_enabled_on__notification_code, $only_if_enabled_on__category, $to_member_ids, $start, $max)
 {
     global $NO_DB_SCOPE_CHECK;
     $bak = $NO_DB_SCOPE_CHECK;
     $NO_DB_SCOPE_CHECK = true;
     $initial_setting = $this->get_initial_setting($only_if_enabled_on__notification_code, $only_if_enabled_on__category);
     $has_by_default = $initial_setting != A_NA;
     $clause_1 = db_string_equal_to('l_notification_code', substr($only_if_enabled_on__notification_code, 0, 80));
     $clause_2 = is_null($only_if_enabled_on__category) ? db_string_equal_to('l_code_category', '') : '(' . db_string_equal_to('l_code_category', '') . ' OR ' . db_string_equal_to('l_code_category', $only_if_enabled_on__category) . ')';
     $clause_3 = '1=1';
     if (!is_null($to_member_ids)) {
         if (count($to_member_ids) == 0) {
             return array(array(), false);
         }
         $clause_3 = '(';
         foreach ($to_member_ids as $member_id) {
             if ($clause_3 != '(') {
                 $clause_3 .= ' OR ';
             }
             $clause_3 .= 'l_member_id=' . strval($member_id);
         }
         $clause_3 .= ')';
     }
     $db = substr($only_if_enabled_on__notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
     $test = $GLOBALS['SITE_DB']->query_value_null_ok('notification_lockdown', 'l_setting', array('l_notification_code' => substr($only_if_enabled_on__notification_code, 0, 80)));
     if (!is_null($test) && get_forum_type() == 'ocf') {
         $query_stub = 'SELECT m.id AS l_member_id,' . strval($test) . ' AS l_setting FROM ' . $db->get_table_prefix() . 'f_members m WHERE ' . str_replace('l_member_id', 'id', $clause_3);
         $query_stem = '';
     } else {
         if ($has_by_default && get_forum_type() == 'ocf' && db_has_subqueries($db->connection_read)) {
             $query_stub = 'SELECT m.id AS l_member_id,l_setting FROM ' . $db->get_table_prefix() . 'f_members m LEFT JOIN ' . $db->get_table_prefix() . 'notifications_enabled l ON ' . $clause_1 . ' AND ' . $clause_2 . ' AND ' . $clause_3 . ' AND m.id=l.l_member_id WHERE ' . str_replace('l_member_id', 'm.id', $clause_3) . ' AND ';
             $query_stem = 'NOT EXISTS(SELECT * FROM ' . $db->get_table_prefix() . 'notifications_enabled l WHERE m.id=l.l_member_id AND ' . $clause_1 . ' AND ' . $clause_2 . ' AND ' . $clause_3 . ' AND l_setting=' . strval(A_NA) . ')';
         } else {
             $query_stub = 'SELECT l_member_id,l_setting FROM ' . $db->get_table_prefix() . 'notifications_enabled WHERE ';
             $query_stem = $clause_1 . ' AND ' . $clause_2 . ' AND ' . $clause_3 . ' AND l_setting<>' . strval(A_NA);
         }
     }
     $results = $db->query($query_stub . $query_stem, $max, $start);
     foreach ($results as $i => $r) {
         if (is_null($results[$i]['l_setting'])) {
             $results[$i]['l_setting'] = $initial_setting;
         }
     }
     $NO_DB_SCOPE_CHECK = $bak;
     $possibly_has_more = count($results) == $max;
     return array(collapse_2d_complexity('l_member_id', 'l_setting', $results), $possibly_has_more);
 }
예제 #27
0
/**
 * Force a members post count to be recalculated.
 *
 * @param  MEMBER		The member.
 * @param  ?integer	The amount to add to the post count (NULL: fully recalculate the post count).
 */
function ocf_force_update_member_post_count($member_id, $member_post_count_dif = NULL)
{
    if ($GLOBALS['OCF_DRIVER']->get_guest_id() == $member_id) {
        return;
    }
    if (get_db_type() == 'xml') {
        return;
    }
    if (is_null($member_post_count_dif)) {
        // This is gonna take a while!!
        global $ALL_FORUM_POST_COUNT_INFO;
        if (is_null($ALL_FORUM_POST_COUNT_INFO)) {
            $ALL_FORUM_POST_COUNT_INFO = collapse_2d_complexity('id', 'f_post_count_increment', $GLOBALS['FORUM_DB']->query('SELECT id,f_post_count_increment FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0'));
        }
        $member_post_count = 0;
        foreach ($ALL_FORUM_POST_COUNT_INFO as $forum_id => $post_count_increment) {
            if ($post_count_increment == 1) {
                $where = array('p_poster' => $member_id, 'p_cache_forum_id' => $forum_id);
                if (addon_installed('unvalidated')) {
                    $where['p_validated'] = 1;
                }
                $member_post_count += $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)', $where);
            }
        }
        $where = array('p_poster' => $member_id, 'p_cache_forum_id' => NULL);
        if (addon_installed('unvalidated')) {
            $where['p_validated'] = 1;
        }
        $member_post_count += $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)', $where);
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members SET m_cache_num_posts=' . strval((int) $member_post_count) . ' WHERE id=' . strval((int) $member_id));
    } else {
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members SET m_cache_num_posts=(m_cache_num_posts+' . strval((int) $member_post_count_dif) . ') WHERE id=' . strval((int) $member_id));
    }
}
예제 #28
0
 /**
  * The UI to set privileges.
  *
  * @return tempcode		The UI
  */
 function interface_specific_permissions()
 {
     require_all_lang();
     require_code('zones2');
     $title = get_page_title('SPECIFIC_PERMISSIONS');
     $p_section = get_param('id', NULL);
     if (is_null($p_section) || $p_section == '') {
         $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges';
         $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions';
         $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges';
         $fields = new ocp_tempcode();
         require_code('form_templates');
         $_sections = $this->_get_ordered_sections();
         $sections = new ocp_tempcode();
         foreach ($_sections as $s) {
             if (is_null($s)) {
                 $sections->attach(form_input_list_entry('', false, '', false, true));
             } else {
                 if (!is_null($s['trans'])) {
                     $sections->attach(form_input_list_entry($s['p_section'], false, $s['trans']));
                 }
             }
         }
         $fields->attach(form_input_list(do_lang_tempcode('SECTION'), '', 'id', $sections, NULL, true));
         $post_url = get_self_url(false, false, NULL, false, true);
         return do_template('FORM_SCREEN', array('_GUID' => 'e5d457a49a76706afebc92da3d846e74', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'SUBMIT_NAME' => do_lang_tempcode('CHOOSE'), 'TITLE' => $title, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => ''));
     }
     $title = get_page_title('_SPECIFIC_PERMISSIONS', true, array(do_lang_tempcode($p_section)));
     $url = build_url(array('page' => '_SELF', 'type' => '_specific', 'id' => $p_section), '_SELF');
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $moderator_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $header_cells = $this->_access_header($admin_groups, $groups);
     $cols = new ocp_tempcode();
     foreach ($groups as $id => $g_name) {
         if (in_array($id, $admin_groups)) {
             continue;
         }
         $cols->attach(do_template('PERMISSION_COLUMN_SIZER'));
     }
     // Find all module permission overrides
     $all_module_overrides = array();
     foreach (find_all_zones() as $zone) {
         $all_modules = array();
         $all_modules += find_all_pages($zone, 'modules_custom', 'php', false);
         $all_modules += find_all_pages($zone, 'modules', 'php', false);
         foreach ($all_modules as $module => $module_type) {
             $functions = extract_module_functions(zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone == '' ? '' : '/') . 'pages/' . $module_type . '/' . $module . '.php'), array('get_sp_overrides'));
             if (!is_null($functions[0])) {
                 $overrides = is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]);
                 foreach (array_keys($overrides) as $override) {
                     if (!array_key_exists($override, $all_module_overrides)) {
                         $all_module_overrides[$override] = array();
                     }
                     $all_module_overrides[$override][] = $module;
                 }
             }
         }
     }
     $all_page_permission_overridding = $GLOBALS['SITE_DB']->query_select('gsp', array('the_page', 'specific_permission'), array('category_name' => ''));
     // Rows (pages)
     $rows = new ocp_tempcode();
     $where = array('p_section' => $p_section);
     // Added in because it was eating up too much memory
     $_permissions = collapse_2d_complexity('the_name', 'p_section', $GLOBALS['SITE_DB']->query_select('sp_list', array('p_section', 'the_name'), $where, 'ORDER BY p_section,the_name'));
     $access_rows = $GLOBALS['SITE_DB']->query_select('gsp', array('specific_permission', 'group_id'), array('the_page' => '', 'module_the_name' => '', 'category_name' => ''));
     $current_section = '';
     $sections = new ocp_tempcode();
     $_false = do_template('PERMISSION_CELL', array('_GUID' => '61aa7fa739e19caa1efb3695a5e2ab5d', 'CHECKED' => false, 'HUMAN' => '__human__', 'NAME' => '__name__'));
     $_true = do_template('PERMISSION_CELL', array('_GUID' => '44a888b40d7a34aed6ed2bf8ff47f1de', 'CHECKED' => true, 'HUMAN' => '__human__', 'NAME' => '__name__'));
     $true = $_true->evaluate();
     $false = $_false->evaluate();
     // Ad-hoc sorting?
     $orderings = array('submit_low', 'edit_own_low', 'edit_low', 'delete_own_low', 'delete_low', 'bypass_validation_low', 'submit_mid', 'edit_own_mid', 'edit_mid', 'delete_own_mid', 'delete_mid', 'bypass_validation_mid', 'submit_high', 'edit_own_high', 'edit_high', 'delete_own_high', 'delete_high', 'bypass_validation_high', 'submit_cat_low', 'edit_own_cat_low', 'edit_cat_low', 'delete_own_cat_low', 'delete_cat_low', 'bypass_cat_validation_low', 'submit_cat_mid', 'edit_own_cat_mid', 'edit_cat_mid', 'delete_own_cat_mid', 'delete_cat_mid', 'bypass_cat_validation_mid', 'submit_cat_high', 'edit_own_cat_high', 'edit_cat_high', 'delete_own_cat_high', 'delete_cat_high', 'bypass_cat_validation_high');
     $permissions_first = array();
     foreach ($orderings as $stub) {
         foreach ($_permissions as $permission => $section) {
             if (substr($permission, 0, strlen($stub)) == $stub) {
                 $permissions_first[$permission] = $section;
                 unset($_permissions[$permission]);
             }
         }
     }
     $_permissions = array_merge($permissions_first, $_permissions);
     // Display
     foreach ($_permissions as $permission => $section) {
         $permission_text = do_lang('PT_' . $permission, NULL, NULL, NULL, NULL, false);
         if (is_null($permission_text)) {
             continue;
         }
         if ($section != $current_section && $current_section != '') {
             $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => '36bc9dfbeb7ee3d91f2a18057cd30551', 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section))));
             $rows = new ocp_tempcode();
         }
         $cells = '';
         $code = '';
         $has = true;
         foreach ($groups as $id => $g_name) {
             if (in_array($id, $admin_groups)) {
                 continue;
             }
             $has_permission = false;
             foreach ($access_rows as $access_row) {
                 if ($access_row['specific_permission'] == $permission && $access_row['group_id'] == $id) {
                     $has_permission = true;
                     break;
                 }
             }
             if (!$has_permission) {
                 $has = false;
             }
             $cells .= str_replace('__human__', escape_html(addslashes(do_lang('PERMISSION_CELL', $permission_text, $g_name))), str_replace('__name__', $permission . '__' . strval($id), $has_permission ? $true : $false));
             if (in_array($id, $moderator_groups)) {
                 $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=true;';
             } else {
                 $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=this.value==\'+\';';
             }
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($cells);
         }
         $tpl_map = array('_GUID' => '075f8855f0fed36b0d0f9c61108dd3de', 'HAS' => $has, 'ABBR' => $permission, 'PERMISSION' => $permission_text, 'CELLS' => $cells, 'CODE' => $code);
         // See if any modules can override this
         if (array_key_exists($permission, $all_module_overrides)) {
             $m_list = '';
             $has_actual_overriding = false;
             foreach ($all_module_overrides[$permission] as $module) {
                 $this_overrides = false;
                 foreach ($all_page_permission_overridding as $po_row) {
                     if ($po_row['the_page'] == $module && $po_row['specific_permission'] == $permission) {
                         $this_overrides = true;
                         break;
                     }
                 }
                 if ($m_list != '') {
                     $m_list .= escape_html(', ');
                 }
                 if ($this_overrides) {
                     $has_actual_overriding = true;
                     $m_list .= '<s>' . escape_html($module) . '</s>';
                 } else {
                     $m_list .= '<strong>' . escape_html($module) . '</strong>';
                 }
                 if ($module == 'topics') {
                     $m_list .= ' (' . strtolower(do_lang(strpos($permission, 'lowrange') !== false ? 'FORUM_POSTS' : 'FORUM_TOPICS')) . ')';
                 }
             }
             if (function_exists('ocp_mark_as_escaped')) {
                 ocp_mark_as_escaped($m_list);
             }
             $tpl_map['DESCRIPTION'] = do_lang_tempcode($has_actual_overriding ? 'SP_USED_IN_SLASHED' : 'SP_USED_IN', $m_list);
         }
         // Render row
         $rows->attach(do_template('PERMISSION_ROW', $tpl_map));
         $current_section = $section;
     }
     $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => 'c75a07373f54c0fa31d18e360fcf26f6', 'COLS' => $cols, 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section))));
     breadcrumb_set_parents(array(array('_SELF:_SELF:specific', do_lang_tempcode('CHOOSE'))));
     return do_template('PERMISSION_S_PERMISSIONS_SCREEN', array('_GUID' => '11974f0a137266a625991d3611b8e587', 'TITLE' => $title, 'URL' => $url, 'SECTIONS' => $sections));
 }
예제 #29
0
 /**
  * Standard modular render function for profile tab hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return array			A triple: The tab title, the tab contents, the suggested tab order
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     $title = do_lang_tempcode('PROFILE');
     $order = 10;
     $photo_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_url');
     if ($photo_url != '' && addon_installed('ocf_member_photos') && has_specific_permission($member_id_viewing, 'view_member_photos')) {
         require_code('images');
         $photo_thumb_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_thumb_url');
         $photo_thumb_url = ensure_thumbnail($photo_url, $photo_thumb_url, strpos($photo_url, 'uploads/photos') !== false ? 'photos' : 'ocf_photos', 'f_members', $member_id_of, 'm_photo_thumb_url');
         if (url_is_local($photo_url)) {
             $photo_url = get_complex_base_url($photo_url) . '/' . $photo_url;
         }
         if (url_is_local($photo_thumb_url)) {
             $photo_thumb_url = get_complex_base_url($photo_thumb_url) . '/' . $photo_thumb_url;
         }
     } else {
         $photo_url = '';
         $photo_thumb_url = '';
     }
     $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id_of);
     $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
     // Things staff can do with this user
     $modules = array();
     if (has_specific_permission($member_id_viewing, 'warn_members') && has_actual_page_access($member_id_viewing, 'warnings') && addon_installed('ocf_warnings')) {
         $redir_url = get_self_url(true);
         $modules[] = array('usage', do_lang_tempcode('WARN_MEMBER'), build_url(array('page' => 'warnings', 'type' => 'ad', 'id' => $member_id_of, 'redirect' => $redir_url), get_module_zone('warnings')));
         $modules[] = array('usage', do_lang_tempcode('PUNITIVE_HISTORY'), build_url(array('page' => 'warnings', 'type' => 'history', 'id' => $member_id_of), get_module_zone('warnings')));
     }
     if (has_specific_permission($member_id_viewing, 'view_content_history') && has_actual_page_access($member_id_viewing, 'admin_ocf_history')) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('usage', do_lang_tempcode('POST_HISTORY'), build_url(array('page' => 'admin_ocf_history', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_lookup')) {
         require_lang('submitban');
         $modules[] = array('usage', do_lang_tempcode('INVESTIGATE_USER'), build_url(array('page' => 'admin_lookup', 'param' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_security')) {
         require_lang('security');
         $modules[] = array('usage', do_lang_tempcode('SECURITY_LOGGING'), build_url(array('page' => 'admin_security', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (addon_installed('actionlog')) {
         if (has_actual_page_access($member_id_viewing, 'admin_actionlog')) {
             require_lang('submitban');
             $modules[] = array('usage', do_lang_tempcode('VIEW_ACTION_LOGS'), build_url(array('page' => 'admin_actionlog', 'type' => 'list', 'id' => $member_id_of), 'adminzone'));
         }
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('ocf_forum') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH_POSTS'), build_url(array('page' => 'search', 'type' => 'results', 'id' => 'ocf_posts', 'author' => $username, 'sort' => 'add_date', 'direction' => 'DESC', 'content' => ''), get_module_zone('search')), 'search');
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH'), build_url(array('page' => 'search', 'type' => 'misc', 'author' => $username), get_module_zone('search')), 'search');
     }
     if (addon_installed('authors')) {
         $author = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT author FROM ' . get_table_prefix() . 'authors WHERE (forum_handle=' . strval($member_id_viewing) . ') OR (forum_handle IS NULL AND ' . db_string_equal_to('author', $username) . ')');
         if (has_actual_page_access($member_id_viewing, 'authors') && !is_null($author)) {
             $modules[] = array('content', do_lang_tempcode('AUTHOR'), build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $author), get_module_zone('authors')), 'me');
         }
     }
     require_code('ocf_members2');
     if (!is_guest() && ocf_may_whisper($member_id_of) && has_actual_page_access($member_id_viewing, 'topics') && ocf_may_make_personal_topic() && $member_id_viewing != $member_id_of) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('contact', do_lang_tempcode('ADD_PERSONAL_TOPIC'), build_url(array('page' => 'topics', 'type' => 'new_pt', 'id' => $member_id_of), get_module_zone('topics')), 'reply');
     }
     $extra_sections = array();
     $info_details = array();
     $hooks = find_all_hooks('modules', 'members');
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/modules/members/' . filter_naughty_harsh($hook));
         $object = object_factory('Hook_members_' . filter_naughty_harsh($hook), true);
         if (is_null($object)) {
             continue;
         }
         if (method_exists($object, 'run')) {
             $hook_result = $object->run($member_id_of);
             $modules = array_merge($modules, $hook_result);
         }
         if (method_exists($object, 'get_info_details')) {
             $hook_result = $object->get_info_details($member_id_of);
             $info_details = array_merge($info_details, $hook_result);
         }
         if (method_exists($object, 'get_sections')) {
             $hook_result = $object->get_sections($member_id_of);
             $extra_sections = array_merge($extra_sections, $hook_result);
         }
     }
     if (addon_installed('ocf_contactmember')) {
         if (($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_allow_emails') == 1 || get_option('allow_email_disable') == '0') && $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address') != '' && !is_guest($member_id_of) && has_actual_page_access($member_id_viewing, 'contactmember') && $member_id_viewing != $member_id_of) {
             $redirect = get_self_url(true);
             $modules[] = array('contact', do_lang_tempcode('_EMAIL_MEMBER'), build_url(array('page' => 'contactmember', 'redirect' => $redirect, 'id' => $member_id_of), get_module_zone('contactmember')), 'reply');
         }
     }
     require_lang('menus');
     $sections = array('contact' => do_lang_tempcode('CONTACT'), 'profile' => do_lang_tempcode('EDIT_PROFILE'), 'views' => do_lang_tempcode('ACCOUNT'), 'usage' => do_lang_tempcode('USAGE'), 'content' => do_lang_tempcode('CONTENT'));
     $actions = array();
     global $M_SORT_KEY;
     $M_SORT_KEY = mixed();
     $M_SORT_KEY = 1;
     @uasort($modules, 'multi_sort');
     /* @ is to stop PHP bug warning about altered array contents when Tempcode copies are evaluated internally */
     foreach ($sections as $section_code => $section_title) {
         $links = new ocp_tempcode();
         foreach ($modules as $module) {
             if (count($module) == 3) {
                 list($_section_code, $lang, $url) = $module;
                 $rel = NULL;
             } else {
                 list($_section_code, $lang, $url, $rel) = $module;
             }
             if ($section_code == $_section_code) {
                 $links->attach(do_template('OCF_MEMBER_ACTION', array('_GUID' => '67b2a640a368c6f53f1b1fa10f922fd0', 'ID' => strval($member_id_of), 'URL' => $url, 'LANG' => $lang, 'REL' => $rel)));
             }
         }
         $actions[$section_code] = $links;
     }
     // Custom fields
     $_custom_fields = ocf_get_all_custom_fields_match_member($member_id_of, $member_id_viewing != $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL, $member_id_viewing == $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL);
     $custom_fields = array();
     require_code('encryption');
     $value = mixed();
     foreach ($_custom_fields as $name => $_value) {
         $value = $_value['RAW'];
         $rendered_value = $_value['RENDERED'];
         $encrypted_value = '';
         if (is_data_encrypted($value)) {
             $encrypted_value = remove_magic_encryption_marker($value);
         } elseif (is_integer($value)) {
             $value = strval($value);
         } elseif (is_float($value)) {
             $value = float_to_raw_string($value);
         }
         if (!is_object($value) && $value != '' || is_object($value) && !$value->is_empty()) {
             $custom_fields[] = array('NAME' => $name, 'RAW_VALUE' => $value, 'VALUE' => $rendered_value, 'ENCRYPTED_VALUE' => $encrypted_value);
             if ($name == do_lang('KEYWORDS')) {
                 $GLOBALS['SEO_KEYWORDS'] = is_object($value) ? $value->evaluate() : $value;
             }
             if ($name == do_lang('DESCRIPTION')) {
                 $GLOBALS['SEO_DESCRIPTION'] = is_object($value) ? $value->evaluate() : $value;
             }
         }
     }
     // Birthday
     $dob = '';
     if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_reveal_age') == 1) {
         $day = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_day');
         $month = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_month');
         $year = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_year');
         if (!is_null($day)) {
             if (@strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) != '1963') {
                 $dob = strval($year) . '-' . str_pad(strval($month), 2, '0', STR_PAD_LEFT) . '-' . str_pad(strval($day), 2, '0', STR_PAD_LEFT);
             } else {
                 $dob = get_timezoned_date(mktime(12, 0, 0, $month, $day, $year), false, true, true);
             }
         }
     }
     // Find forum with most posts
     $forums = $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0');
     $best_yet_forum = 0;
     // Initialise to integer type
     $best_yet_forum = NULL;
     $most_active_forum = NULL;
     $_best_yet_forum = $GLOBALS['FORUM_DB']->query_select('f_posts', array('COUNT(*) as cnt', 'p_cache_forum_id'), array('p_poster' => $member_id_of), 'GROUP BY p_cache_forum_id');
     $_best_yet_forum = collapse_2d_complexity('p_cache_forum_id', 'cnt', $_best_yet_forum);
     foreach ($forums as $forum) {
         if (array_key_exists($forum['id'], $_best_yet_forum) && (is_null($best_yet_forum) || $_best_yet_forum[$forum['id']] > $best_yet_forum)) {
             $most_active_forum = has_category_access($member_id_viewing, 'forums', strval($forum['id'])) ? protect_from_escaping(escape_html($forum['f_name'])) : do_lang_tempcode('PROTECTED_FORUM');
             $best_yet_forum = $_best_yet_forum[$forum['id']];
         }
     }
     $post_count = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_cache_num_posts');
     $best_post_fraction = $post_count == 0 ? do_lang_tempcode('NA_EM') : make_string_tempcode(integer_format(100 * $best_yet_forum / $post_count));
     $most_active_forum = is_null($best_yet_forum) ? new ocp_tempcode() : do_lang_tempcode('_MOST_ACTIVE_FORUM', $most_active_forum, make_string_tempcode(integer_format($best_yet_forum)), array($best_post_fraction));
     $time_for_them_raw = tz_time(time(), get_users_timezone($member_id_of));
     $time_for_them = get_timezoned_time(time(), true, $member_id_of);
     $banned = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_is_perm_banned') == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
     $last_submit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_submit_time');
     $submit_days_ago = intval(floor(floatval(time() - $last_submit_time) / 60.0 / 60.0 / 24.0));
     require_code('ocf_groups');
     $primary_group_id = ocf_get_member_primary_group($member_id_of);
     $primary_group = ocf_get_group_link($primary_group_id);
     $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_signature'), $GLOBALS['FORUM_DB']);
     $last_visit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_visit_time');
     if (member_is_online($member_id_of)) {
         $online_now = do_lang_tempcode('YES');
         $_online_now = true;
     } else {
         $_online_now = false;
         $minutes_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0));
         $hours_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0));
         $days_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0));
         $months_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0 / 31.0));
         if ($minutes_ago < 180) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MINUTES', integer_format($minutes_ago));
         } elseif ($hours_ago < 72) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_HOURS', integer_format($hours_ago));
         } elseif ($days_ago < 93) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_DAYS', integer_format($days_ago));
         } else {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MONTHS', integer_format($months_ago));
         }
     }
     $join_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_join_time');
     $days_joined = intval(round((time() - $join_time) / 60 / 60 / 24));
     $total_posts = $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)');
     $join_date = $join_time == 0 ? '' : get_timezoned_date($join_time, false);
     $count_posts = do_lang_tempcode('_COUNT_POSTS', integer_format($post_count), float_format(floatval($post_count) / floatval($days_joined == 0 ? 1 : $days_joined)), array(float_format(floatval(100 * $post_count) / floatval($total_posts == 0 ? 1 : $total_posts))));
     $a = $avatar_url == '' ? 0 : ocf_get_member_best_group_property($member_id_of, 'max_avatar_width');
     $b = $photo_thumb_url == '' ? 0 : intval(get_option('thumb_width'));
     $right_margin = max($a, $b) == 0 ? 'auto' : strval(max($a, $b) + 6) . 'px';
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MEMBERS'))));
     if (has_specific_permission($member_id_viewing, 'see_ip')) {
         $ip_address = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_ip_address');
     } else {
         $ip_address = '';
     }
     $secondary_groups = ocf_get_members_groups($member_id_of, true);
     unset($secondary_groups[$primary_group_id]);
     if (count($secondary_groups) > 0) {
         $_secondary_groups = array();
         $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, array_keys($secondary_groups), $member_id_of);
         foreach (array_keys($secondary_groups) as $key) {
             $_secondary_groups[$key] = $all_groups[$key];
         }
         $secondary_groups = $_secondary_groups;
     }
     if (addon_installed('points')) {
         require_code('points');
         $count_points = integer_format(total_points($member_id_of));
     } else {
         $count_points = '';
     }
     $user_agent = NULL;
     $operating_system = NULL;
     if (has_specific_permission($member_id_viewing, 'show_user_browsing') && addon_installed('stats')) {
         $last_stats = $GLOBALS['SITE_DB']->query_select('stats', array('browser', 'operating_system'), array('the_user' => $member_id_of), 'ORDER BY date_and_time DESC', 1);
         if (array_key_exists(0, $last_stats)) {
             $user_agent = $last_stats[0]['browser'];
             $operating_system = $last_stats[0]['operating_system'];
         }
     }
     /*if ((get_option('allow_member_integration')!='off') && (get_option('allow_member_integration')!='hidden'))
     		{
     			$remote=$GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of,'m_password_compat_scheme')=='remote';
     		} else */
     $remote = NULL;
     $_on_probation = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_on_probation_until');
     if (is_null($_on_probation) || $_on_probation <= time()) {
         $on_probation = NULL;
     } else {
         $on_probation = strval($_on_probation);
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $join_time), 'creator' => $username, 'publisher' => '', 'modified' => '', 'type' => 'Member', 'title' => '', 'identifier' => '_SEARCH:members:view:' . strval($member_id_of), 'description' => '', 'image' => $avatar_url == '' && has_specific_permission($member_id_viewing, 'view_member_photos') ? $photo_url : $avatar_url);
     // Look up member's clubs
     $clubs = array();
     if (addon_installed('ocf_clubs')) {
         $club_ids = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id_of, true);
         $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1), '', 200));
         if (count($club_rows) == 200) {
             $club_rows = NULL;
         }
         foreach ($club_ids as $club_id) {
             if (is_null($club_rows)) {
                 $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1, 'id' => $club_id), '', 200));
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
                 $club_rows = NULL;
             } else {
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
             }
             $club_name = get_translated_text($club_row['g_name'], $GLOBALS['FORUM_DB']);
             $club_forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.f_description', 'f.id', array('text_original' => do_lang('FORUM_FOR_CLUB', $club_name)));
             $clubs[] = array('CLUB_NAME' => $club_name, 'CLUB_ID' => strval($club_row['id']), 'CLUB_FORUM' => is_null($club_forum) ? '' : strval($club_forum));
         }
     }
     $content = do_template('OCF_MEMBER_PROFILE_ABOUT', array('_GUID' => 'fodfjdsfjsdljfdls', 'CLUBS' => $clubs, 'REMOTE' => $remote, 'RIGHT_MARGIN' => $right_margin, 'AVATAR_WIDTH' => strval($a) . 'px', 'PHOTO_WIDTH' => strval($b) . 'px', 'MOST_ACTIVE_FORUM' => $most_active_forum, 'TIME_FOR_THEM' => $time_for_them, 'TIME_FOR_THEM_RAW' => strval($time_for_them_raw), 'SUBMIT_DAYS_AGO' => integer_format($submit_days_ago), 'SUBMIT_TIME_RAW' => strval($last_submit_time), 'LAST_VISIT_TIME_RAW' => strval($last_visit_time), 'ONLINE_NOW' => $online_now, '_ONLINE_NOW' => $_online_now, 'BANNED' => $banned, 'USER_AGENT' => $user_agent, 'OPERATING_SYSTEM' => $operating_system, 'DOB' => $dob, 'IP_ADDRESS' => $ip_address, 'COUNT_POSTS' => $count_posts, 'COUNT_POINTS' => $count_points, 'PRIMARY_GROUP' => $primary_group, 'PRIMARY_GROUP_ID' => strval($primary_group_id), 'PHOTO_URL' => $photo_url, 'PHOTO_THUMB_URL' => $photo_thumb_url, 'EMAIL_ADDRESS' => $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address'), 'AVATAR_URL' => $avatar_url, 'SIGNATURE' => $signature, 'JOIN_DATE' => $join_date, 'JOIN_DATE_RAW' => strval($join_time), 'CUSTOM_FIELDS' => $custom_fields, 'ACTIONS_contact' => $actions['contact'], 'ACTIONS_profile' => $actions['profile'], 'ACTIONS_views' => $actions['views'], 'ACTIONS_usage' => $actions['usage'], 'ACTIONS_content' => $actions['content'], 'USERNAME' => $username, 'MEMBER_ID' => strval($member_id_of), 'SECONDARY_GROUPS' => $secondary_groups, 'VIEW_PROFILES' => $member_id_viewing == $member_id_of || has_specific_permission($member_id_viewing, 'view_profiles'), 'ON_PROBATION' => $on_probation, 'EXTRA_INFO_DETAILS' => $info_details, 'EXTRA_SECTIONS' => $extra_sections));
     return array($title, $content, $order);
 }
예제 #30
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_members($db, $table_prefix, $file_base)
 {
     if ($this->on_same_msn($file_base)) {
         return;
     }
     $cpf_types = collapse_2d_complexity('id', 'cf_type', $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type')));
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_members ORDER BY id', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['id']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['m_username']);
             if (!is_null($test)) {
                 // Fix usergroup leadership
                 $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $test), array('g_group_leader' => -$row['id']));
                 import_id_remap_put('member', strval($row['id']), $test);
                 continue;
             }
             $primary_group = import_id_remap_get('group', strval($row['m_primary_group']));
             $custom_fields = array();
             $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id'];
             $timezone = $row['m_timezone_offset'];
             if (is_integer($timezone)) {
                 $timezone = strval($timezone);
             }
             if (!isset($row['m_auto_monitor_contrib_content'])) {
                 $row['m_auto_monitor_contrib_content'] = $row['m_track_contributed_topics'];
             }
             $id_new = ocf_make_member($row['m_username'], $row['m_pass_hash_salted'], $row['m_email_address'], NULL, $row['m_dob_day'], $row['m_dob_month'], $row['m_dob_year'], $custom_fields, $timezone, $primary_group, $row['m_validated'], $row['m_join_time'], $row['m_last_visit_time'], $row['m_theme'], $row['m_avatar_url'], $this->get_lang_string($db, $row['m_signature']), $row['m_is_perm_banned'], $row['m_preview_posts'], $row['m_reveal_age'], $row['m_title'], $row['m_photo_url'], $row['m_photo_thumb_url'], $row['m_views_signatures'], $row['m_auto_monitor_contrib_content'], $row['m_language'], $row['m_allow_emails'], array_key_exists('m_allow_emails_from_staff', $row) ? $row['m_allow_emails_from_staff'] : $row['m_allow_emails'], $row['m_notes'], $row['m_ip_address'], $row['m_validated_email_confirm_code'], false, array_key_exists('m_password_compat_scheme', $row) ? $row['m_password_compat_scheme'] : $row['m_password_compatibility_scheme'], $row['m_pass_salt'], $row['m_zone_wide'], $row['m_last_submit_time'], $id, array_key_exists('m_highlighted_name', $row) ? $row['m_highlighted_name'] : 0, array_key_exists('m_pt_allow', $row) ? $row['m_pt_allow'] : '*', array_key_exists('m_pt_rules_text', $row) ? $this->get_lang_string($db, $row['m_pt_rules_text']) : '');
             $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'f_member_custom_fields WHERE mf_member_id=' . strval((int) $row['id']), 1);
             if (array_key_exists(0, $rows2)) {
                 $row2 = array();
                 foreach ($rows2[0] as $key => $val) {
                     if (is_null($val)) {
                         $val = '';
                     }
                     if (substr($key, 0, 6) == 'field_') {
                         $cpf_id = import_id_remap_get('cpf', substr($key, 6), true);
                         if (is_null($cpf_id)) {
                             continue;
                         }
                         $cpf_type = $cpf_types[$cpf_id];
                         if ($cpf_type == 'short_trans' || $cpf_type == 'long_trans') {
                             $val = strval(insert_lang($this->get_lang_string($db, intval($val)), 3));
                         }
                         $row2['field_' . strval($cpf_id)] = $val;
                     }
                 }
                 $GLOBALS['SITE_DB']->query_update('f_member_custom_fields', $row2, array('mf_member_id' => $id_new), '', 1);
             }
             // Fix some tricky dependences that we shoved to one side
             $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $id_new), array('g_group_leader' => -$row['id']));
             $GLOBALS['SITE_DB']->query_update('attachments', array('a_member_id' => $id_new), array('a_member_id' => -$row['id']));
             import_id_remap_put('member', strval($row['id']), $id_new);
         }
         $row_start += 200;
     } while (count($rows) > 0);
     // Group membership
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_group_members');
     foreach ($rows as $row) {
         $row['gm_group_id'] = import_id_remap_get('group', strval($row['gm_group_id']), true);
         if (is_null($row['gm_group_id'])) {
             continue;
         }
         $row['gm_member_id'] = import_id_remap_get('member', strval($row['gm_member_id']), true);
         if (is_null($row['gm_member_id'])) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_insert('f_group_members', $row, false, true);
     }
     // Known login IPs
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_member_known_login_ips');
     foreach ($rows as $row) {
         $row['i_member_id'] = import_id_remap_get('member', strval($row['i_member_id']), true);
         if (is_null($row['i_member_id'])) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_insert('f_member_known_login_ips', $row);
     }
     // Group member timeouts
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_group_member_timeouts');
     foreach ($rows as $row) {
         $member_id = import_id_remap_get('member', strval($row['member_id']));
         if (is_null($member_id)) {
             continue;
         }
         $group_id = import_id_remap_get('group', strval($row['group_id']));
         if (is_null($group_id)) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_insert('f_group_member_timeouts', array('member_id' => $member_id, 'group_id' => $group_id, 'timeout' => $row['timeout']));
     }
     // Invites
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_invites ORDER BY id', NULL, NULL, true);
     if (!is_null($rows)) {
         foreach ($rows as $row) {
             $i_inviter = import_id_remap_get('member', strval($row['i_inviter']), true);
             if (is_null($i_inviter)) {
                 continue;
             }
             $GLOBALS['SITE_DB']->query_insert('f_invites', array('i_inviter' => $i_inviter, 'i_email_address' => $row['i_email_address'], 'i_time' => $row['i_time'], 'i_taken' => $row['i_taken']), false, true);
         }
     }
 }