コード例 #1
0
ファイル: posts.php プロジェクト: erico-deh/ocPortal
 function tearDown()
 {
     if (!ocf_delete_posts_topic($topic_id = $this->topic_id, $posts = array($this->post_id), $reason = 'Nothing')) {
         ocf_delete_topic($this->topic_id);
     }
     parent::tearDown();
 }
コード例 #2
0
/**
 * Delete a forum.
 *
 * @param  AUTO_LINK		The ID of the forum we are deleting.
 * @param  AUTO_LINK		The ID of the forum that topics will be moved to.
 * @param  BINARY			Whether to delete topics instead of moving them to the target forum.
 */
function ocf_delete_forum($forum_id, $target_forum_id, $delete_topics = 0)
{
    if ($forum_id == db_get_first_id()) {
        warn_exit(do_lang_tempcode('CANNOT_DELETE_ROOT_FORUM'));
    }
    require_code('ocf_topics_action');
    require_code('ocf_topics_action2');
    if ($delete_topics == 0) {
        ocf_move_topics($forum_id, $target_forum_id);
    } else {
        $rows = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id'), array('t_forum_id' => $forum_id));
        foreach ($rows as $row) {
            ocf_delete_topic($row['id'], '');
        }
    }
    $forum_info = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => $forum_id), '', 1);
    if (!array_key_exists(0, $forum_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    delete_lang($forum_info[0]['f_description'], $GLOBALS['FORUM_DB']);
    delete_lang($forum_info[0]['f_intro_question'], $GLOBALS['FORUM_DB']);
    $name = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_name', array('id' => $forum_id));
    $GLOBALS['FORUM_DB']->query_update('f_multi_moderations', array('mm_move_to' => NULL), array('mm_move_to' => $forum_id));
    $GLOBALS['FORUM_DB']->query_update('f_forums', array('f_parent_forum' => db_get_first_id()), array('f_parent_forum' => $forum_id));
    $GLOBALS['FORUM_DB']->query_delete('f_forums', array('id' => $forum_id), '', 1);
    $GLOBALS['FORUM_DB']->query_delete('group_category_access', array('module_the_name' => 'forums', 'category_name' => strval($forum_id)));
    $GLOBALS['FORUM_DB']->query_delete('gsp', array('module_the_name' => 'forums', 'category_name' => strval($forum_id)));
    require_code('notifications');
    delete_all_notifications_on('ocf_topic', 'forum:' . strval($forum_id));
    $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_member', array('i_forum_id' => $forum_id));
    $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_ip', array('i_forum_id' => $forum_id));
    log_it('DELETE_FORUM', strval($forum_id), $name);
}
コード例 #3
0
ファイル: poll.php プロジェクト: erico-deh/ocPortal
 function tearDown()
 {
     ocf_delete_poll($poll_id = $this->poll_id, $reason = 'Simple');
     ocf_delete_topic($this->topic_id);
     parent::tearDown();
 }
コード例 #4
0
ファイル: topics.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to delete a topic.
  *
  * @return tempcode		The UI
  */
 function _delete_topic()
 {
     $topic_id = get_param_integer('id');
     $post_target_topic_id = post_param_integer('select_topic_id', -1);
     if ($post_target_topic_id == -1) {
         $post_target_topic_id = post_param_integer('manual_topic_id', -1);
     }
     if ($post_target_topic_id == -1) {
         $post_target_topic_id = NULL;
     }
     require_code('ocf_topics_action');
     require_code('ocf_topics_action2');
     $forum_id = ocf_delete_topic($topic_id, post_param('reason'), $post_target_topic_id);
     require_code('fields');
     if (has_tied_catalogue('topic')) {
         delete_form_custom_fields('topic', strval($topic_id));
     }
     return $this->redirect_to_forum('DELETE_TOPIC', $forum_id);
 }
コード例 #5
0
/**
 * Move posts from one topic to another.
 *
 * @param  AUTO_LINK		The ID of the source topic.
 * @param  AUTO_LINK		The ID of the destination topic.
 * @param  array			A list of post IDs to move.
 * @param  LONG_TEXT		The reason for this action.
 * @param  ?AUTO_LINK	The forum the destination topic is in (NULL: find from DB).
 * @param  boolean		Whether to delete the topic if all posts in it have been moved.
 * @param  ?SHORT_TEXT	The title for the new topic (NULL: work out / irrelevant).
 * @return boolean		Whether the topic was deleted.
 */
function ocf_move_posts($from_topic_id, $to_topic_id, $posts, $reason, $to_forum_id = NULL, $delete_if_empty = false, $title = NULL)
{
    if (is_null($to_topic_id)) {
        if (is_null($to_forum_id)) {
            fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
        }
        require_code('ocf_topics_action');
        $to_topic_id = ocf_make_topic($to_forum_id);
        if (!is_null($title) && count($posts) != 0) {
            $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_title' => $title), array('id' => $posts[0]), '', 1);
        }
    }
    // Info about source
    $from_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id'), array('id' => $from_topic_id));
    if (!array_key_exists(0, $from_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $from_forum_id = $from_info[0]['t_forum_id'];
    $to_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id'), array('id' => $to_topic_id));
    if (!array_key_exists(0, $to_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $to_forum_id = $to_info[0]['t_forum_id'];
    $or_list = '';
    foreach ($posts as $post) {
        if ($or_list != '') {
            $or_list .= ' OR ';
        }
        $or_list .= 'id=' . strval((int) $post);
    }
    // Check access
    if (!ocf_may_moderate_forum($from_forum_id)) {
        access_denied('I_ERROR');
    }
    $_postdetails = $GLOBALS['FORUM_DB']->query('SELECT p_cache_forum_id,p_intended_solely_for,p_validated FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE ' . $or_list);
    $num_posts_counted = 0;
    foreach ($_postdetails as $post) {
        if (is_null($post['p_intended_solely_for']) && $post['p_validated'] == 1) {
            $num_posts_counted++;
        }
        if ($post['p_cache_forum_id'] != $from_forum_id) {
            fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
        }
    }
    $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . strval((int) $to_forum_id) . ', p_topic_id=' . strval((int) $to_topic_id) . ' WHERE ' . $or_list);
    // Update cacheing
    require_code('ocf_posts_action2');
    ocf_force_update_topic_cacheing($from_topic_id, -$num_posts_counted, true, true);
    ocf_force_update_topic_cacheing($to_topic_id, $num_posts_counted, true, true);
    if (!is_null($from_forum_id) && !is_null($to_topic_id) && $from_forum_id != $to_topic_id) {
        if ($from_forum_id != $to_forum_id) {
            require_code('ocf_forums_action2');
            ocf_force_update_forum_cacheing($from_forum_id, 0, -$num_posts_counted);
            ocf_force_update_forum_cacheing($to_forum_id, 0, $num_posts_counted);
            // 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_forum_id) . ' OR id=' . strval((int) $to_forum_id), 2);
            if ($post_count_info[0]['id'] == $from_forum_id) {
                $from = $post_count_info[0]['f_post_count_increment'];
                $to = $post_count_info[1]['f_post_count_increment'];
            } else {
                $from = $post_count_info[1]['f_post_count_increment'];
                $to = $post_count_info[0]['f_post_count_increment'];
            }
            if ($from != $to) {
                $sql = 'SELECT p_poster FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list . ')';
                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);
                }
            }
        }
    }
    $test = $delete_if_empty ? $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)', array('p_topic_id' => $from_topic_id)) : 1;
    if ($test == 0) {
        $num_view_count = 0;
        $num_view_count += $GLOBALS['FORUM_DB']->query_value('f_topics', 't_num_views', array('id' => $from_topic_id));
        $num_view_count += $GLOBALS['FORUM_DB']->query_value('f_topics', 't_num_views', array('id' => $to_topic_id));
        $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_num_views' => $num_view_count), array('id' => $to_topic_id), '', 1);
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        ocf_delete_topic($from_topic_id, do_lang('MOVE_POSTS'));
        return true;
    } else {
        // Make informative post
        $me_link = '[page="' . get_module_zone('members') . '" type="view" id="' . strval(get_member()) . '" caption="' . $GLOBALS['OCF_DRIVER']->get_username(get_member()) . '"]members[/page]';
        $topic_title = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $to_topic_id));
        $lang = do_lang('INLINE_POSTS_MOVED_MESSAGE', $me_link, integer_format(count($posts)), array('[page="' . get_module_zone('topicview') . '" id="' . strval($to_topic_id) . '" caption="' . str_replace('"', '\\"', str_replace('[', '\\[', $topic_title)) . '"]topicview[/page]'));
        ocf_make_post($from_topic_id, '', $lang, 0, false, 1, 1, NULL, NULL, $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_time', array('id' => $posts[0])) + 1, NULL, NULL, NULL, NULL, false);
        require_code('ocf_general_action2');
        ocf_mod_log_it('MOVE_POSTS', strval($to_topic_id), strval(count($posts)), $reason);
        if (!is_null($from_forum_id)) {
            ocf_decache_ocp_blocks($from_forum_id);
        }
        if (!is_null($to_forum_id)) {
            ocf_decache_ocp_blocks($to_forum_id);
        }
        return false;
    }
    return false;
    // should never get here
}