예제 #1
0
/**
 * Get a list of the default usergroups (the usergroups a member is put in when they join).
 *
 * @param  boolean	Whether to include the default primary (at the end of the list).
 * @param  boolean	The functionality does not usually consider configured default groups [unless there's just one], because this is a layer of uncertainity (the user PICKS one of these). If you want to return all configured default groups, set this parameter to true.
 * @return array 		The list of default IDs.
 */
function ocf_get_all_default_groups($include_primary = false, $include_all_configured_default_groups = false)
{
    if (!$include_primary && $include_all_configured_default_groups) {
        warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    global $ALL_DEFAULT_GROUPS;
    if (array_key_exists($include_primary ? 1 : 0, $ALL_DEFAULT_GROUPS)) {
        return $ALL_DEFAULT_GROUPS[$include_primary ? 1 : 0];
    }
    $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id'), array('g_is_default' => 1, 'g_is_presented_at_install' => 0), 'ORDER BY g_order');
    $groups = collapse_1d_complexity('id', $rows);
    if ($include_primary) {
        $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id'), array('g_is_presented_at_install' => 1), 'ORDER BY g_order');
        if ($include_all_configured_default_groups || count($rows) == 1 || get_option('show_first_join_page') == '0') {
            $groups = array_merge($groups, collapse_1d_complexity('id', $rows));
        }
        if (count($rows) == 0) {
            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups', 'id', array('id' => db_get_first_id() + 8));
            if (!is_null($test)) {
                $groups[] = db_get_first_id() + 8;
            }
        }
    }
    $ALL_DEFAULT_GROUPS[$include_primary ? 1 : 0] = $groups;
    return $groups;
}
예제 #2
0
 /**
  * Standard interface stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action()
 {
     require_code('database_action');
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     $title = get_page_title('OCGIFTS_TITLE');
     require_code('form_templates');
     $map = NULL;
     $category = either_param('category', '');
     if ($category != '') {
         $map = array('category' => $category);
     }
     $max_rows = $GLOBALS['SITE_DB']->query_value('ocgifts', 'COUNT(*)', $map);
     $max = get_param_integer('max', 20);
     $start = get_param_integer('start', 0);
     require_code('templates_results_browser');
     $results_browser = results_browser(do_lang_tempcode('OCGIFTS_TITLE'), get_param('id'), $start, 'start', $max, 'max', $max_rows, NULL, NULL, true, true);
     $rows = $GLOBALS['SITE_DB']->query_select('ocgifts g', array('*', '(SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'members_gifts m WHERE m.gift_id=g.id) AS popularity'), $map, 'ORDER BY popularity DESC', $max, $start);
     $username = get_param('username', '');
     $gifts = array();
     foreach ($rows as $gift) {
         $gift_url = build_url(array('page' => 'pointstore', 'type' => 'action_done', 'id' => 'ocgifts', 'gift' => $gift['id'], 'username' => $username), '_SEARCH');
         $image_url = '';
         if (is_file(get_custom_file_base() . '/' . rawurldecode($gift['image']))) {
             $image_url = get_custom_base_url() . '/' . $gift['image'];
         }
         $gifts[] = array('NAME' => $gift['name'], 'PRICE' => integer_format($gift['price']), 'POPULARITY' => integer_format($gift['popularity']), 'GIFT_URL' => $gift_url, 'IMAGE_URL' => $image_url);
     }
     $categories = collapse_1d_complexity('category', $GLOBALS['SITE_DB']->query_select('ocgifts', array('DISTINCT category'), NULL, 'ORDER BY category'));
     return do_template('POINTSTORE_OCGIFTS_GIFTS', array('TITLE' => $title, 'GIFTS' => $gifts, 'RESULTS_BROWSER' => $results_browser, 'CATEGORY' => $category, 'CATEGORIES' => $categories));
 }
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (get_value('implicit_usergroup_sync') === '1') {
         $last = get_value('last_implicit_sync');
         if (is_null($last) || intval($last) < time() - 60 * 60) {
             $hooks = find_all_hooks('systems', 'ocf_implicit_usergroups');
             foreach (array_keys($hooks) as $hook) {
                 require_code('hooks/systems/ocf_implicit_usergroups/' . $hook);
                 $ob = object_factory('Hook_implicit_usergroups_' . $hook);
                 $group_id = $ob->get_bound_group_id();
                 $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_group_id' => $group_id));
                 $list = $ob->get_member_list();
                 if (!is_null($list)) {
                     foreach ($list as $member_row) {
                         $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $group_id, 'gm_member_id' => $member_row['id'], 'gm_validated' => 1));
                     }
                 } else {
                     $start = 0;
                     do {
                         $members = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_members', array('id'), NULL, '', 400, $start));
                         foreach ($members as $member_id) {
                             if ($ob->is_member_within($member_id)) {
                                 $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $group_id, 'gm_member_id' => $member_id, 'gm_validated' => 1));
                             }
                         }
                         $start += 400;
                     } while (count($members) == 400);
                 }
             }
             set_value('last_implicit_sync', strval(time()));
         }
     }
 }
예제 #4
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));
 }
예제 #5
0
 /**
  * The UI to choose a ticket type to edit, or to add a ticket.
  *
  * @return tempcode		The UI
  */
 function ticket_type_interface()
 {
     $title = get_page_title('MANAGE_TICKET_TYPES');
     require_lang('permissions');
     $list = new ocp_tempcode();
     require_code('form_templates');
     $ticket_types = collapse_1d_complexity('ticket_type', $GLOBALS['SITE_DB']->query_select('ticket_types', array('*'), NULL, 'ORDER BY ticket_type'));
     foreach ($ticket_types as $ticket_type) {
         $list->attach(form_input_list_entry(strval($ticket_type), false, get_translated_text($ticket_type)));
     }
     if (!$list->is_empty()) {
         $edit_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF', NULL, false, true);
         $submit_name = do_lang_tempcode('CHOOSE');
         $fields = form_input_list(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TICKET_TYPE'), 'ticket_type', $list);
         $tpl = do_template('FORM', array('TABINDEX' => strval(get_form_field_tabindex()), 'GET' => true, 'HIDDEN' => '', 'TEXT' => '', 'FIELDS' => $fields, 'URL' => $edit_url, 'SUBMIT_NAME' => $submit_name));
     } else {
         $tpl = new ocp_tempcode();
     }
     // Do a form so people can add
     $post_url = build_url(array('page' => '_SELF', 'type' => 'add'), '_SELF');
     $submit_name = do_lang_tempcode('ADD_TICKET_TYPE');
     $fields = form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TICKET_TYPE'), 'ticket_type_2', '', false);
     $fields->attach(form_input_tick(do_lang_tempcode('TICKET_GUEST_EMAILS_MANDATORY'), do_lang_tempcode('DESCRIPTION_TICKET_GUEST_EMAILS_MANDATORY'), 'guest_emails_mandatory', false));
     $fields->attach(form_input_tick(do_lang_tempcode('TICKET_SEARCH_FAQ'), do_lang_tempcode('DESCRIPTION_TICKET_SEARCH_FAQ'), 'search_faq', false));
     // Permissions
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     foreach ($groups as $id => $group_name) {
         if (in_array($id, $admin_groups)) {
             continue;
         }
         $fields->attach(form_input_tick(do_lang_tempcode('ACCESS_FOR', escape_html($group_name)), do_lang_tempcode('DESCRIPTION_ACCESS_FOR', escape_html($group_name)), 'access_' . strval($id), true));
     }
     $add_form = do_template('FORM', array('_GUID' => '382f6fab6c563d81303ecb26495e76ec', 'TABINDEX' => strval(get_form_field_tabindex()), 'SECONDARY_FORM' => true, 'HIDDEN' => '', 'TEXT' => '', 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_TICKET_TYPES'))));
     return do_template('SUPPORT_TICKET_TYPE_SCREEN', array('_GUID' => '28645dc4a86086fa865ec7e166b84bb6', 'TITLE' => $title, 'TPL' => $tpl, 'ADD_FORM' => $add_form));
 }
예제 #6
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     $this_birthday_day = date('d/m/Y');
     if (get_long_value('last_birthday_day') !== $this_birthday_day) {
         set_long_value('last_birthday_day', $this_birthday_day);
         require_lang('ocf');
         require_code('ocf_general');
         $_birthdays = ocf_find_birthdays();
         $birthdays = new ocp_tempcode();
         foreach ($_birthdays as $_birthday) {
             $member_url = $GLOBALS['OCF_DRIVER']->member_profile_url($_birthday['id'], false, true);
             $username = $_birthday['username'];
             $birthday_url = build_url(array('page' => 'topics', 'type' => 'birthday', 'id' => $_birthday['username']), get_module_zone('topics'));
             require_code('notifications');
             $subject = do_lang('BIRTHDAY_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $username);
             $mail = do_lang('BIRTHDAY_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($username), array($member_url->evaluate(), $birthday_url->evaluate()));
             if (addon_installed('chat')) {
                 $friends = $GLOBALS['SITE_DB']->query_select('chat_buddies', array('member_likes'), array('member_liked' => $_birthday['id']));
                 dispatch_notification('ocf_friend_birthday', NULL, $subject, $mail, collapse_1d_complexity('member_likes', $friends));
             }
             dispatch_notification('ocf_birthday', NULL, $subject, $mail);
         }
     }
 }
예제 #7
0
 /**
  * Get a list of staff members who have enabled this notification (i.e. have permission to AND have chosen to or are defaulted to).
  *
  * @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_staff_who_have_enabled($only_if_enabled_on__notification_code, $only_if_enabled_on__category, $to_member_ids, $start, $max)
 {
     $initial_setting = $this->get_initial_setting($only_if_enabled_on__notification_code, $only_if_enabled_on__category);
     $db = substr($only_if_enabled_on__notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
     $admin_groups = array_merge($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), collapse_1d_complexity('group_id', $db->query_select('gsp', array('group_id'), array('specific_permission' => 'may_enable_staff_notifications'))));
     $rows = $GLOBALS['FORUM_DRIVER']->member_group_query($admin_groups, $max, $start);
     $possibly_has_more = count($rows) >= $max;
     if (!is_null($to_member_ids)) {
         $new_rows = array();
         foreach ($rows as $row) {
             if (in_array($GLOBALS['FORUM_DRIVER']->pname_id($row), $to_member_ids)) {
                 $new_rows[] = $row;
             }
         }
         $rows = $new_rows;
     }
     $new_rows = array();
     foreach ($rows as $row) {
         $test = notifications_setting($only_if_enabled_on__notification_code, $only_if_enabled_on__category, $GLOBALS['FORUM_DRIVER']->pname_id($row));
         if ($test != A_NA) {
             $new_rows[$GLOBALS['FORUM_DRIVER']->pname_id($row)] = $test;
         }
     }
     return array($new_rows, $possibly_has_more);
 }
예제 #8
0
    $FILE_BASE = substr($FILE_BASE, 0, $a > $b ? $a : $b);
} else {
    $RELATIVE_PATH = '';
}
@chdir($FILE_BASE);
global $NON_PAGE_SCRIPT;
$NON_PAGE_SCRIPT = 1;
global $FORCE_INVISIBLE_GUEST;
$FORCE_INVISIBLE_GUEST = 0;
if (!is_file($FILE_BASE . '/sources/global.php')) {
    exit('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . chr(10) . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"><head><title>Critical startup error</title></head><body><h1>ocPortal startup error</h1><p>The second most basic ocPortal startup file, sources/global.php, could not be located. This is almost always due to an incomplete upload of the ocPortal system, so please check all files are uploaded correctly.</p><p>Once all ocPortal files are in place, ocPortal must actually be installed by running the installer. You must be seeing this message either because your system has become corrupt since installation, or because you have uploaded some but not all files from our manual installer package: the quick installer is easier, so you might consider using that instead.</p><p>ocProducts maintains full documentation for all procedures and tools, especially those for installation. These may be found on the <a href="http://ocportal.com">ocPortal website</a>. If you are unable to easily solve this problem, we may be contacted from our website and can help resolve it for you.</p><hr /><p style="font-size: 0.8em">ocPortal is a website engine created by ocProducts.</p></body></html>');
}
require $FILE_BASE . '/sources/global.php';
if (uninstall_check_master_password(post_param('given_password', ''))) {
    $uninstalled = do_template('BASIC_HTML_WRAP', array('_GUID' => '5614c65c4f388fd47aabb24b9624ce65', 'TITLE' => do_lang_tempcode('UNINSTALL'), 'CONTENT' => do_lang_tempcode('UNINSTALLED')));
    $tables = collapse_1d_complexity('m_table', $GLOBALS['SITE_DB']->query_select('db_meta', array('DISTINCT m_table')));
    foreach ($tables as $table) {
        $GLOBALS['SITE_DB']->drop_if_exists($table);
    }
    $GLOBALS['SITE_DB']->drop_if_exists('db_meta_indices');
    $GLOBALS['SITE_DB']->drop_if_exists('db_meta');
    $uninstalled->evaluate_echo();
} else {
    $echo = do_template('BASIC_HTML_WRAP', array('_GUID' => '009e7517e7df76167b4d13ca77308704', 'NOFOLLOW' => true, 'TITLE' => do_lang_tempcode('UNINSTALL'), 'CONTENT' => do_template('UNINSTALL_SCREEN')));
    $echo->evaluate_echo();
}
/**
 * Check the given master password is valid.
 *
 * @param  SHORT_TEXT	Given master password
 * @return boolean		Whether it is valid
예제 #9
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_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'poll_questions');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['poll_id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['topic_id']), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['poll_id']), -1);
             continue;
         }
         $is_open = $row['poll_ends'] < time();
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'poll_options WHERE poll_id=' . strval((int) $row['poll_id']) . ' ORDER BY poll_option_id');
         $answers = array();
         $answer_map = array();
         foreach ($rows2 as $answer) {
             $answer_map[$answer['poll_option_id']] = count($answers);
             $answers[] = $answer['option_text'];
         }
         $maximum = $row['multiple_choice'] == 1 ? count($answers) : 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_votes WHERE poll_id=' . $row['poll_id']);
         foreach ($rows2 as $row2) {
             $row2['user_id'] = import_id_remap_get('member', strval($row2['user_id']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open ? 1 : 0, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from IPB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['user_id'];
             if (!is_null($member_id) && $member_id != 0) {
                 if ($row2['poll_option_id'] == 0) {
                     $answer = -1;
                 } else {
                     $answer = $answers[$answer_map[$row2['poll_option_id']]];
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['poll_id']), $id_new);
     }
 }
예제 #10
0
파일: ocf.php 프로젝트: erico-deh/ocPortal
 /**
  * Get the ids of the moderator usergroups.
  * It should not be assumed that a member only has one usergroup - this depends upon the forum the driver works for. It also does not take the staff site filter into account.
  *
  * @return array			The moderator usergroup ids
  */
 function _get_moderator_groups()
 {
     return collapse_1d_complexity('id', $this->connection->query_select('f_groups', array('id'), array('g_is_super_moderator' => 1)));
 }
예제 #11
0
 /**
  * Get a list to choose a tester.
  *
  * @param  ?MEMBER		The member to select by default (NULL: Select N/A)
  * @return tempcode		The list
  */
 function get_tester_list($it)
 {
     $tester_groups = collapse_1d_complexity('group_id', $GLOBALS['SITE_DB']->query_select('gsp', array('group_id'), array('specific_permission' => 'perform_tests')));
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $moderator_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $groups = array_unique(array_merge($tester_groups, $admin_groups, $moderator_groups));
     $members = $GLOBALS['FORUM_DRIVER']->member_group_query($groups, 2000);
     $list = form_input_list_entry('-1', is_null($it), do_lang_tempcode('NA_EM'));
     foreach ($members as $member => $details) {
         $username = $GLOBALS['FORUM_DRIVER']->pname_name($details);
         $list->attach(form_input_list_entry(strval($member), $member == $it, $username));
     }
     return $list;
 }
예제 #12
0
/**
 * Send out a notification, as a topic just got a new post.
 *
 * @param  URLPATH		The URL to view the new post.
 * @param  AUTO_LINK		The ID of the topic that got posted in.
 * @param  ?AUTO_LINK	The forum that the topic is in (NULL: find out from the DB).
 * @param  MEMBER			The member that made the post triggering this tracking notification.
 * @param  boolean		Whether the post started a new topic.
 * @param  LONG_TEXT		The post, in Comcode format.
 * @param  SHORT_TEXT	The topic title (blank: look it up from the $topic_id). If non-blank we must use it as it is implying the database might not have the correct value yet.
 * @param  ?MEMBER		Only send the notification to this member (NULL: no such limit).
 * @param  boolean		Whether this is for a Private Topic.
 * @param  ?ID_TEXT		DO NOT send notifications to: The notification code (NULL: no restriction)
 * @param  ?SHORT_TEXT	DO NOT send notifications to: The category within the notification code (NULL: none / no restriction)
 */
function ocf_send_topic_notification($url, $topic_id, $forum_id, $sender_member_id, $is_starter, $post, $topic_title, $_limit_to = NULL, $is_pt = false, $no_notify_for__notification_code = NULL, $no_notify_for__code_category = NULL)
{
    if (is_null($forum_id) && $is_starter) {
        return;
    }
    if ($topic_title == '') {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_pt_to', 't_pt_from', 't_cache_first_title'), array('id' => $topic_id), '', 1);
        if (!array_key_exists(0, $topic_info)) {
            return;
        }
        // Topic's gone missing somehow (e.g. race condition)
        $topic_title = $topic_info[0]['t_cache_first_title'];
    }
    $sender_username = $GLOBALS['FORUM_DRIVER']->get_username($sender_member_id);
    $subject = do_lang($is_starter ? 'TOPIC_NOTIFICATION_MAIL_SUBJECT' : 'POST_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $topic_title);
    $mail = do_lang($is_starter ? 'TOPIC_NOTIFICATION_MAIL' : 'POST_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($url), array(comcode_escape($sender_username), $post, $topic_title));
    $limit_to = is_null($_limit_to) ? array() : array($_limit_to);
    if ($is_pt) {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_pt_to', 't_pt_from', 't_cache_first_title'), array('id' => $topic_id), '', 1);
        if (!array_key_exists(0, $topic_info)) {
            return;
        }
        // Topic's gone missing somehow (e.g. race condition)
        $limit_to[] = $topic_info[0]['t_pt_to'];
        $limit_to[] = $topic_info[0]['t_pt_from'];
        $limit_to = array_merge($limit_to, collapse_1d_complexity('s_member_id', $GLOBALS['FORUM_DB']->query_select('f_special_pt_access', array('s_member_id'), array('s_topic_id' => $topic_id))));
    }
    require_code('notifications');
    dispatch_notification('ocf_topic', strval($topic_id), $subject, $mail, count($limit_to) == 0 ? NULL : $limit_to, $sender_member_id, 3, false, false, $no_notify_for__notification_code, $no_notify_for__code_category);
}
예제 #13
0
/**
 * Find if a member is blocked by a member.
 *
 * @param  MEMBER				The member being checked
 * @param  ?MEMBER			The member who may be blocking (NULL: current member)
 * @return boolean			Whether the member is blocked
 */
function member_blocked($member_id, $member_blocker = NULL)
{
    if (!addon_installed('chat')) {
        return false;
    }
    if (is_null($member_blocker)) {
        $member_blocker = get_member();
    }
    if ($member_blocker == $member_id) {
        return false;
    }
    if (is_guest($member_id)) {
        return false;
    }
    if (is_guest($member_blocker)) {
        return false;
    }
    if ($member_id == get_member()) {
        global $MEMBERS_BLOCKING_US;
        if (is_null($MEMBERS_BLOCKING_US)) {
            $rows = $GLOBALS['SITE_DB']->query_select('chat_blocking', array('member_blocker'), array('member_blocked' => get_member()), '', NULL, NULL, true);
            if (is_null($rows)) {
                $MEMBERS_BLOCKING_US = array();
                return false;
            }
            $MEMBERS_BLOCKING_US = collapse_1d_complexity('member_blocker', $rows);
        }
        return in_array($member_blocker, $MEMBERS_BLOCKING_US);
    }
    global $MEMBERS_BLOCKED;
    if (is_null($MEMBERS_BLOCKED)) {
        $rows = $GLOBALS['SITE_DB']->query_select('chat_blocking', array('member_blocked'), array('member_blocker' => get_member()), '', NULL, NULL, true);
        if (is_null($rows)) {
            $MEMBERS_BLOCKED = array();
            return false;
        }
        $MEMBERS_BLOCKED = collapse_1d_complexity('member_blocked', $rows);
    }
    return in_array($member_id, $MEMBERS_BLOCKED);
}
예제 #14
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_news_and_categories($db, $table_prefix, $old_base_dir)
 {
     require_code('news');
     $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'news')));
     $categories = $db->query("SELECT id,title,description,image FROM " . $table_prefix . "sections WHERE title='News'");
     foreach ($categories as $category) {
         $title = $category['title'];
         $cat_id = $GLOBALS['SITE_DB']->query_select('news_categories', array('id'), array('nc_title' => $title), '', 1);
         if (count($cat_id) == 0) {
             $cat_title = $category['title'];
             $category_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate  AS T INNER JOIN  " . $GLOBALS['SITE_DB']->get_table_prefix() . "news_categories AS N ON T.id=N.nc_title AND " . db_string_equal_to('T.text_original', $cat_title));
             if (count($category_id) == 0) {
                 $desc = html_to_comcode($category['description']);
                 $id = add_news_category($category['title'], $category['image'], $desc, NULL, NULL);
             } else {
                 $id = $category_id[0]['id'];
             }
         } else {
             $id = $cat_id[0]['id'];
         }
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'content WHERE sectionid=' . strval($category['id']));
         foreach ($rows as $row) {
             $val = $row['title'];
             $news_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate  AS T INNER JOIN  " . $GLOBALS['SITE_DB']->get_table_prefix() . "news AS N ON T.id=N.title AND " . db_string_equal_to('T.text_original', $val) . " AND news_category=" . strval($id) . " AND news_category<>''");
             if (count($news_id) == 0) {
                 $title = $row['title'];
                 $news = html_to_comcode($row['introtext']);
                 $author = $db->query_value_null_ok('users', 'name', array('id' => $row['created_by']));
                 if (is_null($author)) {
                     $author = do_lang('UNKNOWN');
                 }
                 $access = $row['access'];
                 if ($access == 0) {
                     $validated = 1;
                 } else {
                     $validated = 0;
                 }
                 $allow_rating = 1;
                 $allow_comments = 1;
                 $allow_trackbacks = 1;
                 $notes = '';
                 $news_article = '';
                 $main_news_category = $id;
                 $news_category = NULL;
                 $datetimearr = explode(' ', $row['created']);
                 $datearr = explode('-', $datetimearr[0]);
                 $timearr = explode(':', $datetimearr[1]);
                 $date = intval($datearr[2]);
                 $month = intval($datearr[1]);
                 $year = intval($datearr[0]);
                 $hour = intval($timearr[0]);
                 $min = intval($timearr[1]);
                 $sec = intval($timearr[2]);
                 $time = mktime($hour, $min, $sec, $month, $date, $year);
                 $submitter = import_id_remap_get('member', strval($row['created_by']));
                 $views = $row['hits'];
                 $datetimearr = explode(' ', $row['modified']);
                 $datearr = explode('-', $datetimearr[0]);
                 $timearr = explode(':', $datetimearr[1]);
                 $date = intval($datearr[2]);
                 $month = intval($datearr[1]);
                 $year = intval($datearr[0]);
                 $hour = intval($timearr[0]);
                 $min = intval($timearr[1]);
                 $sec = intval($timearr[2]);
                 $edit_date = mktime($hour, $min, $sec, $month, $date, $year);
                 $nid = NULL;
                 $image = 'newscats/' . preg_replace('#\\..*$#', '', $row['images']);
                 @mkdir(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777);
                 fix_permissions(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777);
                 sync_file(get_custom_file_base() . '/themes/default/images_custom/newscats');
                 $newimagepath = get_custom_file_base() . '/themes/default/images_custom/newscats/' . rawurldecode($row['images']);
                 $oldimagepath = $old_base_dir . "/images/stories/" . rawurldecode($row['images']);
                 @copy($oldimagepath, $newimagepath);
                 fix_permissions($newimagepath);
                 sync_file($newimagepath);
                 add_news($title, $news, $author, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, $time, $submitter, $views, $edit_date, $nid, $image);
             }
         }
     }
 }
예제 #15
0
 /**
  * The actualiser to set privileges.
  *
  * @return tempcode		The UI
  */
 function set_specific_permissions()
 {
     require_all_lang();
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions';
     if (count($_POST) == 0 && strtolower(ocp_srv('REQUEST_METHOD')) != 'post') {
         warn_exit(do_lang_tempcode('PERMISSION_TRAGEDY_PREVENTED'));
     }
     $title = get_page_title('SPECIFIC_PERMISSIONS');
     $p_section = get_param('id');
     $_sections = $this->_get_ordered_sections();
     $array_keys = array_keys($_sections);
     $next_section = $array_keys[0];
     $counter = 0;
     foreach ($_sections as $s) {
         if (is_null($s)) {
             continue;
         }
         if ($counter > array_search($p_section, $array_keys)) {
             $next_section = $s['p_section'];
             break;
         }
         $counter++;
     }
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $permissions = collapse_1d_complexity('the_name', $GLOBALS['SITE_DB']->query_select('sp_list', array('the_name'), array('p_section' => $p_section)));
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     foreach ($permissions as $permission) {
         foreach (array_keys($groups) as $id) {
             if (in_array($id, $admin_groups)) {
                 continue;
             }
             $val = post_param_integer($permission . '__' . strval($id), 0);
             // Delete to cleanup
             $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $permission, 'group_id' => $id, 'the_page' => '', 'module_the_name' => '', 'category_name' => ''), '', 1);
             if ($val == 1) {
                 $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $permission, 'group_id' => $id, 'the_page' => '', 'module_the_name' => '', 'category_name' => '', 'the_value' => 1));
             }
         }
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:specific', do_lang_tempcode('CHOOSE'))));
     decache('main_sitemap');
     $GLOBALS['SITE_DB']->query_delete('cache');
     if (function_exists('persistant_cache_empty')) {
         persistant_cache_empty();
     }
     // Show it worked / Refresh
     $url = build_url(array('page' => '_SELF', 'type' => 'specific', 'id' => $next_section), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS_NOW_NEXT_SCREEN'));
 }
예제 #16
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_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'vote_desc');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['vote_id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['topic_id']), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['vote_id']), -1);
             continue;
         }
         $is_open = $row['vote_start'] > time() && ($row['vote_length'] == 0 || $row['vote_start'] + $row['vote_length'] < time());
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_results WHERE vote_id=' . strval($row['vote_id'] . ' ORDER BY vote_option_id'));
         $answers = array();
         foreach ($rows2 as $answer) {
             $answers[] = $answer['vote_option_text'];
         }
         $maximum = 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_voters WHERE vote_id=' . $row['vote_id']);
         foreach ($rows2 as $row2) {
             $row2['vote_user_id'] = import_id_remap_get('member', strval($row2['vote_user_id']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['vote_text'], 0, $is_open ? 1 : 0, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from IPB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['vote_user_id'];
             if (!is_null($member_id) && $member_id != 0) {
                 if ($row2['vote_cast'] == 0 || !array_key_exists($row2['vote_cast'] - 1, $answers)) {
                     $answer = -1;
                 } else {
                     $answer = $answers[$row2['vote_cast'] - 1];
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['vote_id']), $id_new);
     }
 }
예제 #17
0
파일: wbb2.php 프로젝트: erico-deh/ocPortal
 /**
  * Get the ids of the moderator usergroups.
  * It should not be assumed that a member only has one usergroup - this depends upon the forum the driver works for. It also does not take the staff site filter into account.
  *
  * @return array			The moderator usergroup ids
  */
 function _get_moderator_groups()
 {
     return collapse_1d_complexity('groupid', $this->connection->query_select('groups', array('groupid'), array('canuseacp' => 0, 'ismod' => 1)));
 }
예제 #18
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;
}
예제 #19
0
 /**
  * The actualiser for managing banned IPs.
  *
  * @return tempcode		The UI
  */
 function actual()
 {
     require_code('failure');
     $old_bans = collapse_1d_complexity('ip', $GLOBALS['SITE_DB']->query_select('usersubmitban_ip'));
     $bans = post_param('bans');
     $_bans = explode(chr(10), $bans);
     foreach ($old_bans as $ban) {
         if (preg_match('#^' . preg_quote($ban, '#') . '(\\s|$)#m', $bans) == 0) {
             remove_ip_ban($ban);
         }
     }
     $matches = array();
     foreach ($_bans as $ban) {
         if (trim($ban) == '') {
             continue;
         }
         preg_match('#^([^\\s]+)(.*)$#', $ban, $matches);
         $ip = $matches[1];
         if (preg_match('#^[a-f0-9\\.\\*:]+$#U', $ip) == 0) {
             attach_message(do_lang_tempcode('IP_ADDRESS_NOT_VALID', $ban), 'warn');
         } else {
             if ($ip == get_ip_address()) {
                 attach_message(do_lang_tempcode('WONT_BAN_SELF', $ban), 'warn');
             } elseif ($ip == ocp_srv('SERVER_ADDR')) {
                 attach_message(do_lang_tempcode('WONT_BAN_SERVER', $ban), 'warn');
             }
             if (!in_array($ip, $old_bans)) {
                 ban_ip($ip, trim($matches[2]));
                 $old_bans[] = $ip;
             }
         }
     }
     // Show it worked / Refresh
     $title = get_page_title('IP_BANS');
     $refresh_url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $refresh_url, do_lang_tempcode('SUCCESS'));
 }
예제 #20
0
/**
 * Find an available code for a booking for the bookable on a given date.
 *
 * @param  AUTO_LINK	Bookable ID.
 * @param  integer	Day.
 * @param  integer	Month.
 * @param  integer	Year.
 * @param  ID_TEXT	Preferred code (often passed in as the last code provided, in order to provide continuity to guests).
 * @return ?ID_TEXT	The code (NULL: could not find a code).
 */
function find_free_bookable_code($bookable_id, $day, $month, $year, $preferred_code)
{
    $_available = $GLOBALS['SITE_DB']->query_select('bookable_codes a LEFT JOIN ' . get_table_prefix() . 'booking b ON a.code=b.code_allocation AND a.bookable_id=b.bookable_id AND b.b_day=' . strval($day) . ' AND b.b_month=' . strval($month) . ' AND b.b_year=' . strval($year), array('code'), array('b.id' => NULL, 'a.bookable_id' => $bookable_id));
    $available = collapse_1d_complexity('code', $_available);
    if (in_array($preferred_code, $available)) {
        return $preferred_code;
    }
    if (!array_key_exists(0, $available)) {
        return NULL;
    }
    return $available[0];
}
예제 #21
0
 /**
  * Get the forum usergroup relating to the specified member id.
  *
  * @param  MEMBER			The member id
  * @return array			The array of forum usergroups
  */
 function _get_members_groups($member)
 {
     //if ($member==$this->get_guest_id()) return array(1); May not hold true
     $groups = collapse_1d_complexity('group_id', $this->connection->query_select('user_group', array('group_id'), array('user_pending' => 0, 'user_id' => $member)));
     $groups[] = $this->get_member_row_field($member, 'group_id');
     if (count($groups) <= 1) {
         $all_groups = $this->get_usergroup_list();
         if (count($groups) == 0 || !array_key_exists($groups[0], $all_groups)) {
             $groups[] = 1;
         }
     }
     return $groups;
 }
예제 #22
0
파일: ipb1.php 프로젝트: erico-deh/ocPortal
 /**
  * Find a list of all forum skins (aka themes).
  *
  * @return array			The list of skins
  */
 function get_skin_list()
 {
     $table = 'skins';
     $codename = 'img_dir';
     $rows = $this->connection->query_select($table, array($codename));
     return collapse_1d_complexity($codename, $rows);
 }
예제 #23
0
파일: aef.php 프로젝트: erico-deh/ocPortal
 /**
  * Get the forum usergroup relating to the specified member id.
  *
  * @param  MEMBER			The member id
  * @return array			The array of forum usergroups
  */
 function _get_members_groups($member)
 {
     if ($member == $this->get_guest_id()) {
         return array(-1);
     }
     $groups = collapse_1d_complexity('u_member_group', $this->connection->query_select('users', array('u_member_group'), array('id' => $member)));
     if (count($groups) <= 1) {
         $all_groups = $this->get_usergroup_list();
         $group = !empty($groups[0]) || $groups[0] == 0 ? $groups[0] : '';
         if (!array_key_exists($group, $all_groups)) {
             $groups[] = -1;
         }
     }
     return $groups;
 }
예제 #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
/**
 * Place a vote on a specified poll.
 *
 * @param  AUTO_LINK The ID of the poll we're voting in.
 * @param  array 		A list of poll answers that are being voted for.
 * @param  ?MEMBER	The member that's voting (NULL: current member).
 * @param  ?array		The row of the topic the poll is for (NULL: get it from the DB).
 */
function ocf_vote_in_poll($poll_id, $votes, $member_id = NULL, $topic_info = NULL)
{
    // Who's voting
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    if ($member_id == $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        warn_exit(do_lang_tempcode('GUESTS_CANT_VOTE_IN_POLLS'));
    }
    // Check they're allowed to vote
    if (!has_specific_permission($member_id, 'vote_in_polls')) {
        warn_exit(do_lang_tempcode('VOTE_DENIED'));
    }
    if (is_null($topic_info)) {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_forum_id'), array('t_poll_id' => $poll_id), '', 1);
    }
    if (!array_key_exists(0, $topic_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $topic_id = $topic_info[0]['id'];
    $forum_id = $topic_info[0]['t_forum_id'];
    if (!has_category_access($member_id, 'forums', strval($forum_id)) && !is_null($forum_id)) {
        warn_exit(do_lang_tempcode('VOTE_CHEAT'));
    }
    $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_poll_votes', 'pv_member_id', array('pv_poll_id' => $poll_id, 'pv_member_id' => $member_id));
    if (!is_null($test)) {
        warn_exit(do_lang_tempcode('NOVOTE'));
    }
    // Check their vote is valid
    $rows = $GLOBALS['FORUM_DB']->query_select('f_polls', array('po_is_open', 'po_minimum_selections', 'po_maximum_selections', 'po_requires_reply'), array('id' => $poll_id), '', 1);
    if (!array_key_exists(0, $rows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    if (count($votes) < $rows[0]['po_minimum_selections'] || count($votes) > $rows[0]['po_maximum_selections'] || $rows[0]['po_is_open'] == 0) {
        warn_exit(do_lang_tempcode('VOTE_CHEAT'));
    }
    $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $poll_id)));
    if ($rows[0]['po_requires_reply'] == 1 && !ocf_has_replied_topic($topic_id, $member_id)) {
        warn_exit(do_lang_tempcode('POLL_REQUIRES_REPLY'));
    }
    foreach ($votes as $vote) {
        if (!in_array($vote, $answers)) {
            warn_exit(do_lang_tempcode('VOTE_CHEAT'));
        }
        $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $poll_id, 'pv_member_id' => $member_id, 'pv_answer_id' => $vote));
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_poll_answers SET pa_cache_num_votes=(pa_cache_num_votes+1) WHERE id=' . strval((int) $vote), 1);
    }
    $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_polls SET po_cache_total_votes=(po_cache_total_votes+1) WHERE id=' . strval((int) $poll_id), 1);
}
예제 #26
0
 /**
  * The actualiser to edit a poll.
  *
  * @return tempcode		The UI
  */
 function _edit_poll()
 {
     $poll_id = get_param_integer('id');
     $topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 'id', array('t_poll_id' => $poll_id));
     if (is_null($topic_id)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $question = post_param('question', STRING_MAGIC_NULL);
     $is_private = post_param_integer('is_private', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $is_open = post_param_integer('is_open', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $minimum_selections = post_param_integer('minimum_selections', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $maximum_selections = post_param_integer('maximum_selections', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $reason = post_param('reason', STRING_MAGIC_NULL);
     $requires_reply = post_param_integer('requires_reply', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     if (fractional_edit()) {
         $answers = collapse_1d_complexity('pa_answer', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('pa_answer'), array('pa_poll_id' => $poll_id)));
         foreach ($answers as $i => $answer) {
             $answers[$i] = post_param('answer_' . strval($i), $answer);
         }
     } else {
         $answers = array();
         foreach ($_POST as $key => $val) {
             if (!is_string($val)) {
                 continue;
             }
             if (substr($key, 0, 7) == 'answer_') {
                 if (get_magic_quotes_gpc()) {
                     $val = stripslashes($val);
                 }
                 if ($val != '') {
                     $answers[] = $val;
                 }
             }
         }
     }
     require_code('ocf_polls_action');
     require_code('ocf_polls_action2');
     ocf_edit_poll($poll_id, $question, $is_private, $is_open, $minimum_selections, $maximum_selections, $requires_reply, $answers, $reason);
     return $this->redirect_to('EDIT_TOPIC_POLL', $topic_id);
 }
예제 #27
0
파일: vb3.php 프로젝트: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT *,p.pollid AS pollid FROM ' . $table_prefix . 'poll p LEFT JOIN ' . $table_prefix . 'thread t ON p.pollid=t.pollid');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['pollid']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['threadid']), true);
         if (is_null($topic_id)) {
             continue;
         }
         $is_open = $row['active'];
         $answers = explode('|||', $row['options']);
         $maximum = $row['multiple'] == 1 ? count($answers) : 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'pollvote WHERE pollid=' . $row['pollid']);
         foreach ($rows2 as $i => $row2) {
             $rows2[$i]['userid'] = import_id_remap_get('member', strval($row2['userid']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from VB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['userid'];
             if (!is_null($member_id) && $member_id != 0) {
                 $answer = array_key_exists($row2['voteoption'] - 1, $answers) ? $answers[$row2['voteoption'] - 1] : -1;
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['pollid']), $id_new);
     }
 }
예제 #28
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_polls_and_votes($db, $table_prefix, $file_base)
 {
     if ($this->on_same_msn($file_base)) {
         return;
     }
     $rows = $db->query('SELECT p.*,t.id AS tid FROM ' . $table_prefix . 'f_polls p LEFT JOIN ' . $table_prefix . 'f_topics t ON p.id=t.t_poll_id');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['tid']), true);
         if (is_null($topic_id)) {
             continue;
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'f_poll_votes WHERE pv_poll_id=' . strval($row['id']));
         foreach ($rows2 as $i => $row2) {
             $rows2[$i]['pv_member_id'] = import_id_remap_get('member', strval($row2['pv_member_id']), true);
         }
         $rows3 = $db->query('SELECT * FROM ' . $table_prefix . 'f_poll_answers WHERE pa_poll_id=' . strval($row['id']) . ' ORDER BY id');
         $answers = array();
         $id_ordinal_map = array();
         foreach ($rows3 as $i => $row3) {
             $answers[] = array($row3['pa_answer'], 0);
             $id_ordinal_map[$row3['id']] = $i;
         }
         $id_new = ocf_make_poll($topic_id, $row['po_question'], $row['po_is_private'], $row['po_is_open'], $row['po_minimum_selections'], $row['po_maximum_selections'], $row['po_requires_reply'], $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from vote number ordinal to new vote number
         foreach ($rows2 as $row2) {
             $vote = $row2['pv_answer_id'];
             if (!array_key_exists($vote, $id_ordinal_map)) {
                 continue;
             }
             if (!array_key_exists($id_ordinal_map[$vote], $answers)) {
                 continue;
             }
             $answer = $answers[$id_ordinal_map[$vote]];
             if (is_null($row2['pv_member_id'])) {
                 continue;
             }
             $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $row2['pv_member_id'], 'pv_answer_id' => $answer));
         }
         import_id_remap_put('f_poll', strval($row['id']), $id_new);
     }
 }
예제 #29
0
/**
 * Move some topics.
 *
 * @param  AUTO_LINK		The forum the topics are currently in.
 * @param  AUTO_LINK		The forum the topics are being moved to.
 * @param  ?array 		A list of the topic IDs to move (NULL: move all topics from source forum).
 */
function ocf_move_topics($from, $to, $topics = NULL)
{
    if ($from == $to) {
        return;
    }
    // That would be nuts, and interfere with our logic
    require_code('notifications');
    require_code('ocf_topics');
    require_code('ocf_forums_action2');
    $forum_name = ocf_ensure_forum_exists($to);
    if (!ocf_may_moderate_forum($from)) {
        access_denied('I_ERROR');
    }
    $topic_count = 0;
    if (is_null($topics)) {
        if (is_null($from)) {
            access_denied('I_ERROR');
        }
        $all_topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_cache_num_posts', 't_validated'), array('t_forum_id' => $from));
        $or_list = '';
        $post_count = 0;
        $topics = array();
        foreach ($all_topics as $topic_info) {
            $topics[] = $topic_info['id'];
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $topic_info['id']);
            $post_count += $topic_info['t_cache_num_posts'];
            if ($topic_info['t_validated'] == 1) {
                $topic_count++;
            }
        }
        $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_forum_id' => $to), array('t_forum_id' => $from));
        // Update forum IDs' for posts
        $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_cache_forum_id' => $from));
        $or_list_2 = str_replace('id', 'p_topic_id', $or_list);
        if ($or_list_2 == '') {
            return;
        }
    } elseif (count($topics) == 1) {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to', 't_cache_first_title', 't_cache_num_posts', 't_validated'), array('id' => $topics[0]));
        if (!array_key_exists(0, $topic_info)) {
            warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topics[0]) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($topic_info[0]['t_forum_id'])) {
            access_denied('I_ERROR');
        }
        if ($topic_info[0]['t_validated'] == 1) {
            $topic_count++;
        }
        $topic_title = $topic_info[0]['t_cache_first_title'];
        $post_count = $topic_info[0]['t_cache_num_posts'];
        $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_pt_from' => NULL, 't_pt_to' => NULL, 't_forum_id' => $to), array('t_forum_id' => $from, 'id' => $topics[0]), '', 1);
        // Extra where constraint for added security
        log_it('MOVE_TOPICS', $topic_title, strval($topics[0]));
        $or_list = 'id=' . strval($topics[0]);
        $or_list_2 = 'p_topic_id=' . strval($topics[0]);
        // Update forum IDs' for posts
        $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_topic_id' => $topics[0]));
    } else {
        if (count($topics) == 0) {
            return;
        }
        // Nuts, lol
        $or_list = '';
        foreach ($topics as $topic_id) {
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $topic_id);
            if (is_null($from)) {
                $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to'), array('id' => $topic_id));
                if (array_key_exists(0, $topic_info)) {
                    if ($topic_info[0]['t_validated'] == 1) {
                        $topic_count++;
                    }
                    if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt')) {
                        access_denied('I_ERROR');
                    }
                }
            } else {
                $topic_count++;
                // Might not be validated, which means technically we shouldn't do this, but it's low chance, low impact, and the indicator is only a cache thing anyway
            }
        }
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics SET t_forum_id=' . strval((int) $to) . ',t_pt_from=NULL,t_pt_to=NULL WHERE t_forum_id' . (is_null($from) ? ' IS NULL' : '=' . strval((int) $from)) . ' AND (' . $or_list . ')');
        log_it('MOVE_TOPICS', do_lang('MULTIPLE'));
        $post_count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(t_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list);
        // Update forum IDs' for posts
        $or_list_2 = str_replace('id', 'p_topic_id', $or_list);
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . strval((int) $to) . ' WHERE ' . $or_list_2);
    }
    require_code('ocf_posts_action2');
    // Update source forum cache view
    if (!is_null($from)) {
        ocf_force_update_forum_cacheing($from, -$topic_count, -$post_count);
    }
    // Update dest forum cache view
    ocf_force_update_forum_cacheing($to, $topic_count, $post_count);
    if (!is_null($from)) {
        // Update member post counts if we've switched between post-count countable forums
        $post_count_info = $GLOBALS['FORUM_DB']->query('SELECT id,f_post_count_increment FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval((int) $from) . ' OR id=' . strval((int) $to), 2);
        if ($post_count_info[0]['id'] == $from) {
            $from_cnt = $post_count_info[0]['f_post_count_increment'];
            $to_cnt = $post_count_info[1]['f_post_count_increment'];
        } else {
            $from_cnt = $post_count_info[1]['f_post_count_increment'];
            $to_cnt = $post_count_info[0]['f_post_count_increment'];
        }
        require_code('ocf_posts_action');
        if ($from_cnt != $to_cnt) {
            $sql = 'SELECT p_poster FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list_2 . ')';
            if (addon_installed('unvalidated')) {
                $sql .= ' AND p_validated=1';
            }
            $_member_post_counts = collapse_1d_complexity('p_poster', $GLOBALS['FORUM_DB']->query($sql));
            $member_post_counts = array_count_values($_member_post_counts);
            foreach ($member_post_counts as $member_id => $member_post_count) {
                if ($to == 0) {
                    $member_post_count = -$member_post_count;
                }
                ocf_force_update_member_post_count($member_id, $member_post_count);
            }
        }
    }
    require_code('ocf_posts_action');
    if (!is_null($from)) {
        ocf_decache_ocp_blocks($from);
    } else {
        decache('side_ocf_personal_topics');
        decache('_new_pp');
    }
    ocf_decache_ocp_blocks($to, $forum_name);
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $start = 0;
    do {
        $topics2 = $GLOBALS['FORUM_DB']->query('SELECT id,t_cache_first_title,t_cache_last_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list, 100, $start);
        require_code('urls2');
        foreach ($topics2 as $_topic) {
            if ($_topic['t_cache_last_time'] < time() - 60 * 60 * 24 * 14) {
                continue;
            }
            $topic_id = $_topic['id'];
            $topic_title = $_topic['t_cache_first_title'];
            suggest_new_idmoniker_for('topicview', 'misc', strval($topic_id), $topic_title);
            // Now lets inform people tracking the topic that it has moved
            $subject = do_lang('TOPIC_MOVE_MAIL_SUBJECT', get_site_name(), $topic_title);
            $mail = do_lang('TOPIC_MOVE_MAIL', comcode_escape(get_site_name()), comcode_escape($topic_title), array(comcode_escape($forum_name)));
            dispatch_notification('ocf_topic', strval($topic_id), $subject, $mail);
        }
    } while (count($topics2) == 100);
}
예제 #30
0
파일: smf2.php 프로젝트: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'polls');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['id_poll']))) {
             continue;
         }
         $poll_topic_id = $db->query('SELECT id_topic FROM ' . $table_prefix . 'topics WHERE id_poll=' . strval($row['id_poll']));
         if (!isset($poll_topic_id[0]['id_topic'])) {
             continue;
         }
         $poll_topic_id = $poll_topic_id[0]['id_topic'];
         $topic_id = import_id_remap_get('topic', strval($poll_topic_id), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['id_poll']), -1);
             continue;
         }
         $is_open = $row['expire_time'] == 0 || $row['expire_time'] > time() ? 1 : 0;
         $answers = array();
         $poll_choices = $db->query('SELECT * FROM ' . $table_prefix . 'poll_choices WHERE id_poll=' . strval($row['id_poll']));
         $answers_array = array();
         foreach ($poll_choices as $key => $value) {
             $answers_array[] = $value['label'];
         }
         $answer_map = array();
         $maximum = 0;
         foreach ($answers_array as $key => $answer) {
             $answer_map[$key] = $poll_choices[$key]['votes'];
             $answers[$key] = $answer;
             $maximum += $poll_choices[$key]['votes'];
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'log_polls WHERE id_poll=' . strval($row['id_poll']));
         foreach ($rows2 as $row2) {
             $row2['id_member'] = import_id_remap_get('member', strval($row2['id_member']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         foreach ($rows2 as $row2) {
             $member_id = $row2['id_member'];
             if (!is_null($member_id) && $member_id != 0) {
                 if (!isset($answers[strval($row2['id_choice'])])) {
                     continue;
                 }
                 // Safety
                 $answer = $answers[strval($row2['id_choice'])];
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['id_poll']), $id_new);
     }
 }