コード例 #1
0
ファイル: topics.php プロジェクト: erico-deh/ocPortal
    /**
     * The actualiser to add a reply.
     *
     * @return tempcode		The UI
     */
    function _add_reply()
    {
        if (addon_installed('captcha')) {
            require_code('captcha');
            enforce_captcha();
        }
        require_code('attachments2');
        require_code('ocf_posts_action');
        require_code('ocf_posts_action2');
        $invited_members = array();
        $topic_id = either_param_integer('topic_id', -1);
        // Posting into an existing topic?
        $forum_id = post_param_integer('forum_id', -1);
        // New topic in existing forum? (NB: -2 represents reported posts forum)
        $member_id = post_param_integer('member_id', -1);
        // Send TOPIC to specific member? Could be Private Topic (topic_id==-1, forum_id==-1), or personal post (topic_id!=-1, forum_id==-1)
        $parent_id = either_param_integer('parent_id', NULL);
        if ($member_id == -1) {
            $member_username = post_param('to_member_id_0', '');
            if ($member_username != '') {
                $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($member_username);
                if (is_null($member_id)) {
                    warn_exit(do_lang_tempcode('_USER_NO_EXIST', $member_username));
                }
            }
            foreach ($_POST as $key => $_invited_member) {
                if (substr($key, 0, 13) != 'to_member_id_') {
                    continue;
                }
                if ($key == 'to_member_id_0') {
                    continue;
                }
                if ($_invited_member == '') {
                    continue;
                }
                if (get_magic_quotes_gpc()) {
                    $_invited_member = stripslashes($_invited_member);
                }
                $invited_member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_invited_member);
                if (is_null($invited_member)) {
                    attach_message(do_lang_tempcode('_USER_NO_EXIST', $_invited_member), 'warn');
                } else {
                    $invited_members[] = intval($invited_member);
                }
            }
        }
        $validated = post_param_integer('validated', post_param_integer('_validated', 0));
        $is_emphasised = post_param_integer('is_emphasised', 0);
        $skip_sig = post_param_integer('skip_sig', 0);
        $post = post_param('post');
        $title = post_param('title', NULL);
        if (is_null($title)) {
            $title = '';
        }
        $check_permissions = true;
        $add_poll = post_param_integer('add_poll', 0);
        $topic_validated = $validated;
        if ($validated == 1) {
            $topic_validated = 1 - $add_poll;
        }
        // If a topic is gonna have a poll added, it starts unvalidated. Adding the poll will validate it.
        $anonymous = post_param_integer('anonymous', 0);
        $poster_name_if_guest = post_param('poster_name_if_guest', NULL);
        if ($poster_name_if_guest == '') {
            $poster_name_if_guest = NULL;
        }
        if (!is_null($poster_name_if_guest)) {
            $poster_name_if_guest = trim($poster_name_if_guest);
            $restricted_usernames = explode(',', get_option('restricted_usernames'));
            $restricted_usernames[] = do_lang('UNKNOWN');
            $restricted_usernames[] = do_lang('SYSTEM');
            if (!is_null($GLOBALS['FORUM_DRIVER']->get_member_from_username($poster_name_if_guest))) {
                $restricted_usernames[] = $poster_name_if_guest;
            }
            foreach ($restricted_usernames as $_restricted_username) {
                $restricted_username = trim($_restricted_username);
                if ($restricted_username == '') {
                    continue;
                }
                if ($poster_name_if_guest == $restricted_username) {
                    $poster_name_if_guest = $poster_name_if_guest . ' (' . do_lang('GUEST') . ')';
                    break;
                }
            }
        }
        $new_topic = $topic_id == -1;
        if (!$new_topic) {
            $_intended_solely_for = post_param('intended_solely_for', '');
            if ($_intended_solely_for == '') {
                $intended_solely_for = NULL;
            } else {
                $intended_solely_for = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_intended_solely_for);
                if (is_null($intended_solely_for)) {
                    warn_exit(do_lang_tempcode('_USER_NO_EXIST', $_intended_solely_for));
                }
            }
        } else {
            $intended_solely_for = NULL;
        }
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        if ($new_topic) {
            ocf_check_post($post);
            if ($title == '') {
                warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'title'));
            }
            $sunk = post_param_integer('sunk', 0);
            $topic_title = $title;
            if ($forum_id == -1) {
                require_code('ocf_members2');
                if (!ocf_may_whisper($member_id)) {
                    warn_exit(do_lang_tempcode('NO_PT_FROM_ALLOW'));
                }
                check_specific_permission('use_pt');
                $topic_id = ocf_make_topic(NULL, post_param('description', ''), post_param('emoticon', ''), $topic_validated, post_param_integer('open', 0), post_param_integer('pinned', 0), $sunk, post_param_integer('cascading', 0), get_member(), $member_id);
                $_title = get_page_title('ADD_PERSONAL_TOPIC');
            } elseif ($forum_id == -2) {
                $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name(get_option('reported_posts_forum'));
                if (is_null($forum_id)) {
                    warn_exit(do_lang_tempcode('NO_REPORTED_POST_FORUM'));
                }
                // See if post already reported...
                $topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON p.id=t.t_cache_first_post_id', 't.id', array('p.p_title' => $title, 't.t_forum_id' => $forum_id));
                if (!is_null($topic_id)) {
                    // Already a topic
                } else {
                    $topic_id = ocf_make_topic($forum_id, '', '', 1, 1, 0, 0, 0, NULL, NULL, false);
                }
                $_title = get_page_title('REPORT_POST');
                $check_permissions = false;
                decache('main_staff_checklist');
            } else {
                $topic_id = ocf_make_topic($forum_id, post_param('description', ''), post_param('emoticon', ''), $topic_validated, post_param_integer('open', 0), post_param_integer('pinned', 0), $sunk, post_param_integer('cascading', 0));
                $_title = get_page_title('ADD_TOPIC');
                if (addon_installed('awards')) {
                    require_code('awards');
                    handle_award_setting('topic', strval($topic_id));
                }
            }
            $first_post = true;
            require_code('fields');
            if (has_tied_catalogue('topic')) {
                save_form_custom_fields('topic', strval($topic_id));
            }
        } else {
            $_title = get_page_title('ADD_POST');
            $first_post = false;
            $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_cache_first_title', 't_sunk', 't_forum_id', 't_is_open', 't_description'), array('id' => $topic_id), '', 1);
            if (!array_key_exists(0, $topic_info)) {
                warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
            }
            $forum_id = $topic_info[0]['t_forum_id'];
            $topic_title = $topic_info[0]['t_cache_first_title'];
            $sunk = $topic_info[0]['t_sunk'];
            if ($topic_info[0]['t_is_open'] == 0) {
                $may_moderate_forum = ocf_may_moderate_forum($forum_id);
                if (!$may_moderate_forum) {
                    warn_exit(do_lang_tempcode('TOPIC_IS_CLOSED'));
                }
            }
            // Moderator reply
            $new_title = post_param('new_title', NULL);
            if (!is_null($new_title) && !is_null($forum_id) && ocf_may_moderate_forum($forum_id, get_member())) {
                $cascading = post_param_integer('cascading', 0);
                $pinned = post_param_integer('pinned', 0);
                $sunk = post_param_integer('sunk', 0);
                $open = post_param_integer('open', 0);
                $topic_validated = post_param_integer('topic_validated', 0);
                $to = post_param_integer('to', NULL);
                $schedule = get_input_date('schedule');
                if (!is_null($schedule) && addon_installed('calendar')) {
                    $_intended_solely_for = is_null($intended_solely_for) ? 'NULL' : strval($intended_solely_for);
                    $_postdetailser_name_if_guest = is_null($poster_name_if_guest) ? 'NULL' : '\'' . addslashes($poster_name_if_guest) . '\'';
                    $_first_post = $first_post ? 'true' : 'false';
                    $__title = is_null($title) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($title)) . '\'';
                    $_postdetails = is_null($post) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($post)) . '\'';
                    $_new_title = is_null($new_title) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($new_title)) . '\'';
                    $schedule_code = <<<END
:require_code('ocf_topics_action2'); require_code('ocf_topics_action'); ocf_edit_topic({$topic_id},NULL,NULL,{$validated},{$open},{$pinned},{$sunk},{$cascading},'',{$_new_title}); if (({$to}!={$forum_id}) && (!is_null({$to}))) ocf_move_topics({$forum_id},{$to},array({$topic_id})); \$post_id=ocf_make_post({$topic_id},{$__title},{$_postdetails},{$skip_sig},{$_first_post},{$validated},{$is_emphasised},{$_postdetailser_name_if_guest},NULL,NULL,NULL,{$_intended_solely_for},NULL,NULL,false,true,NULL,true,{$topic_title},{$sunk},NULL,{$anonymous}==1); if (addon_installed('awards')) { require_code('awards'); handle_award_setting('post',strval(\$post_id)); }
END;
                    require_code('calendar');
                    $start_year = post_param_integer('schedule_year');
                    $start_month = post_param_integer('schedule_month');
                    $start_day = post_param_integer('schedule_day');
                    $start_hour = post_param_integer('schedule_hour');
                    $start_minute = post_param_integer('schedule_minute');
                    require_code('calendar2');
                    $event_id = add_calendar_event(db_get_first_id(), '', NULL, 0, do_lang('ADD_POST'), $schedule_code, 3, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute);
                    regenerate_event_reminder_jobs($event_id);
                    $text = do_lang_tempcode('SUCCESS');
                    $map = array('page' => 'topicview', 'id' => $topic_id, 'type' => 'first_unread');
                    $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
                    if ($test != -1 && $test != 0) {
                        $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
                    }
                    $test = get_param_integer('threaded', -1);
                    if ($test != -1) {
                        $map['threaded'] = $test;
                    }
                    $_url = build_url($map, get_module_zone('topicview'));
                    $url = $_url->evaluate();
                    $url .= '#first_unread';
                    $url = get_param('redirect', $url);
                    return redirect_screen($_title, $url, $text);
                }
                ocf_edit_topic($topic_id, NULL, NULL, $topic_validated, $open, $pinned, $sunk, $cascading, '', $new_title == '' ? NULL : $new_title);
                if ($to != $forum_id && !is_null($to)) {
                    ocf_move_topics($forum_id, $to, array($topic_id));
                }
            }
        }
        $post_id = ocf_make_post($topic_id, $title, $post, $skip_sig, $first_post, $validated, $is_emphasised, $poster_name_if_guest, NULL, NULL, NULL, $intended_solely_for, NULL, NULL, $check_permissions, true, NULL, true, $topic_title, $sunk, NULL, $anonymous == 1, $forum_id == -1 || is_null($forum_id), $forum_id == -1 || is_null($forum_id), false, $parent_id);
        if (addon_installed('awards')) {
            require_code('awards');
            handle_award_setting('post', strval($post_id));
        }
        if (!is_null($forum_id) && $anonymous == 0 && $intended_solely_for === NULL) {
            if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forumview') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forums', strval($forum_id))) {
                syndicate_described_activity($first_post ? 'ocf:ACTIVITY_ADD_TOPIC' : 'ocf:ACTIVITY_ADD_POST_IN', $first_post ? $title : $topic_title, '', '', '_SEARCH:topicview:misc:' . strval($topic_id) . '#post_' . strval($post_id), '', '', 'ocf_forum');
            }
        }
        require_code('fields');
        if (has_tied_catalogue('post')) {
            save_form_custom_fields('post', strval($post_id));
        }
        $validated = $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_validated', array('id' => $post_id));
        $rep_post_id = post_param_integer('o_post_id', -1);
        if ($rep_post_id != -1) {
            $map = array('page' => 'topicview', 'id' => $rep_post_id, 'type' => 'findpost');
            $_url = build_url($map, get_module_zone('topicview'));
            $url = $_url->evaluate();
            $url .= '#post_' . strval($rep_post_id);
        } else {
            $map = array('page' => 'topicview', 'id' => $post_id, 'type' => 'findpost');
            $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
            if ($test != -1 && $test != 0) {
                $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
            }
            $test = get_param_integer('threaded', -1);
            if ($test != -1) {
                $map['threaded'] = $test;
            }
            $_url = build_url($map, get_module_zone('topicview'));
            $url = $_url->evaluate();
            if ($validated != 0) {
                $url .= '#post_' . strval($post_id);
            }
        }
        if ($forum_id >= 0) {
            $topic_validated = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_validated', array('id' => $topic_id));
            if ($topic_validated == 0 && !has_specific_permission(get_member(), 'jump_to_unvalidated')) {
                $map = array('page' => 'forumview', 'id' => $forum_id);
                $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
                if ($test != -1 && $test != 0) {
                    $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
                }
                $test = get_param_integer('threaded', -1);
                if ($test != -1) {
                    $map['threaded'] = $test;
                }
                $_url = build_url($map, get_module_zone('forumview'));
                $url = $_url->evaluate();
            }
        }
        if ($new_topic && $forum_id == -1) {
            require_code('notifications');
            enable_notifications('ocf_topic', strval($topic_id), get_member());
            // from
            enable_notifications('ocf_topic', strval($topic_id), $member_id);
            // to
            foreach ($invited_members as $invited_member) {
                enable_notifications('ocf_topic', strval($topic_id), $invited_member);
                ocf_invite_to_pt($invited_member, $topic_id);
            }
        }
        if ($anonymous == 1) {
            log_it('MAKE_ANONYMOUS_POST', strval($post_id), $title);
        }
        if (addon_installed('awards')) {
            require_code('awards');
            handle_award_setting('post', strval($post_id));
        }
        if ($forum_id == -1 && $member_id != -1) {
            send_pt_notification($post_id, $title, $topic_id, $member_id, NULL, $post);
        }
        if ($add_poll == 1) {
            if (post_param_integer('add_poll', 0) == 1) {
                // Show it worked / Refresh
                $_url = build_url(array('page' => '_SELF', 'type' => 'add_poll', 'id' => $topic_id, 'try_validate' => 1), '_SELF');
                return redirect_screen($_title, $_url, do_lang_tempcode('SUCCESS'));
            }
        }
        if (!$new_topic && $forum_id != -1 && $member_id == -1) {
            handle_topic_ticket_reply($forum_id, $topic_id, $topic_title, $post);
        }
        $text = $validated == 1 ? do_lang_tempcode('SUCCESS') : do_lang_tempcode('SUBMIT_UNVALIDATED');
        require_code('autosave');
        clear_ocp_autosave();
        // Show it worked / Refresh
        $url = get_param('redirect', $url);
        return redirect_screen($_title, $url, $text);
    }
コード例 #2
0
/**
 * Perform a multi moderation.
 *
 * @param  AUTO_LINK		The ID of the multi moderation we are performing.
 * @param  AUTO_LINK		The ID of the topic we are performing the multi moderation on.
 * @param  LONG_TEXT		The reason for performing the multi moderation (may be blank).
 * @param  LONG_TEXT		The post text for a post to be added to the topic (blank: do not add a post).
 * @param  BINARY			Whether the post is marked emphasised.
 * @param  BINARY			Whether to skip showing the posters signature in the post.
 */
function ocf_perform_multi_moderation($id, $topic_id, $reason, $post_text = '', $is_emphasised = 1, $skip_sig = 0)
{
    $topic_details = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_cache_first_title', 't_cache_first_post_id'), array('id' => $topic_id), '', 1);
    if (!array_key_exists(0, $topic_details)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $from = $topic_details[0]['t_forum_id'];
    if (!ocf_may_perform_multi_moderation($from)) {
        access_denied('I_ERROR');
    }
    $mm = $GLOBALS['FORUM_DB']->query_select('f_multi_moderations', array('*'), array('id' => $id));
    if (!array_key_exists(0, $mm)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    require_code('ocfiltering');
    $idlist = ocfilter_to_idlist_using_db($mm[0]['mm_forum_multi_code'], 'id', 'f_forums', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
    if (!in_array($from, $idlist)) {
        warn_exit(do_lang_tempcode('MM_APPLY_TWICE'));
    }
    $pin_state = $mm[0]['mm_pin_state'];
    $open_state = $mm[0]['mm_open_state'];
    $sink_state = $mm[0]['mm_sink_state'];
    $move_to = $mm[0]['mm_move_to'];
    $title_suffix = $mm[0]['mm_title_suffix'];
    //$post_text=$mm[0]['mm_post_text']; We'll allow user to specify the post_text, with this as a default
    $update_array = array();
    if (!is_null($pin_state)) {
        $update_array['t_pinned'] = $pin_state;
    }
    if (!is_null($sink_state)) {
        $update_array['t_sunk'] = $sink_state;
    }
    if (!is_null($open_state)) {
        $update_array['t_is_open'] = $open_state;
    }
    if ($title_suffix != '') {
        $new_title = $topic_details[0]['t_cache_first_title'] . ' [' . $title_suffix . ']';
        $update_array['t_cache_first_title'] = $new_title;
        $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_title' => $new_title), array('id' => $topic_details[0]['t_cache_first_post_id']), '', 1);
    }
    if (count($update_array) != 0) {
        $GLOBALS['FORUM_DB']->query_update('f_topics', $update_array, array('id' => $topic_id), '', 1);
    }
    if (!is_null($move_to)) {
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        ocf_move_topics($from, $move_to, array($topic_id));
    }
    if ($post_text != '') {
        require_code('ocf_posts_action');
        require_code('ocf_posts_action2');
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        ocf_make_post($topic_id, '', $post_text, $skip_sig, false, 1, $is_emphasised);
        $forum_id = is_null($move_to) ? $from : $move_to;
        handle_topic_ticket_reply($forum_id, $topic_id, $topic_details[0]['t_cache_first_title'], $post_text);
    }
    require_code('ocf_general_action2');
    ocf_mod_log_it('PERFORM_MULTI_MODERATION', strval($id), strval($topic_id), $reason);
}