Exemplo n.º 1
0
/**
 * Turn a post row, into a detailed map of information that is suitable for use as display parameters for that post.
 *
 * @param  array		The post row.
 * @param  boolean	Whether the post is the only post in the topic.
 * @return array		The detailed map.
 */
function ocf_get_details_to_show_post($_postdetails, $only_post = false)
{
    $forum_id = $_postdetails['p_cache_forum_id'];
    $primary_group = ocf_get_member_primary_group($_postdetails['p_poster']);
    if (is_null($primary_group)) {
        $_postdetails['p_poster'] = db_get_first_id();
        $primary_group = db_get_first_id();
    }
    $post = array('id' => $_postdetails['id'], 'topic_id' => $_postdetails['p_topic_id'], 'title' => $_postdetails['p_title'], 'post' => $_postdetails['message'], 'time' => $_postdetails['p_time'], 'time_string' => get_timezoned_date($_postdetails['p_time']), 'validated' => $_postdetails['p_validated'], 'is_emphasised' => $_postdetails['p_is_emphasised'], 'poster_username' => $_postdetails['p_poster_name_if_guest'], 'poster' => $_postdetails['p_poster'], 'has_history' => !is_null($_postdetails['h_post_id']));
    if (array_key_exists('message_comcode', $_postdetails)) {
        $post['message_comcode'] = $_postdetails['message_comcode'];
    }
    // Edited?
    if (!is_null($_postdetails['p_last_edit_by'])) {
        $post['last_edit_by'] = $_postdetails['p_last_edit_by'];
        $post['last_edit_time'] = $_postdetails['p_last_edit_time'];
        $post['last_edit_time_string'] = get_timezoned_date($_postdetails['p_last_edit_time']);
        $post['last_edit_by_username'] = $GLOBALS['OCF_DRIVER']->get_username($_postdetails['p_last_edit_by']);
        if ($post['last_edit_by_username'] == '') {
            $post['last_edit_by_username'] = do_lang('UNKNOWN');
        }
        // Shouldn't happen, but imported data can be weird
    }
    // Find title
    $title = addon_installed('ocf_member_titles') ? $GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_title') : '';
    if ($title == '') {
        $title = get_translated_text(ocf_get_group_property($primary_group, 'title'), $GLOBALS['FORUM_DB']);
    }
    $post['poster_title'] = $title;
    // If this isn't guest posted, we can put some member details in
    if (!is_null($_postdetails['p_poster']) && $_postdetails['p_poster'] != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        if (addon_installed('points')) {
            require_code('points');
            $post['poster_points'] = total_points($_postdetails['p_poster']);
        }
        $post['poster_posts'] = $GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_cache_num_posts');
        $post['poster_highlighted_name'] = $GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_highlighted_name');
        // Signature
        if (($GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_views_signatures') == 1 || get_value('disable_views_sigs_option') === '1') && $_postdetails['p_skip_sig'] == 0 && addon_installed('ocf_signatures')) {
            global $SIGNATURES_CACHE;
            if (array_key_exists($_postdetails['p_poster'], $SIGNATURES_CACHE)) {
                $sig = $SIGNATURES_CACHE[$_postdetails['p_poster']];
            } else {
                $sig = get_translated_tempcode($GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_signature'), $GLOBALS['FORUM_DB']);
                $SIGNATURES_CACHE[$_postdetails['p_poster']] = $sig;
            }
            $post['signature'] = $sig;
        }
        // Any custom fields to show?
        $post['custom_fields'] = ocf_get_all_custom_fields_match_member($_postdetails['p_poster'], get_member() != $_postdetails['p_poster'] && !has_specific_permission(get_member(), 'view_any_profile_field') ? 1 : NULL, get_member() == $_postdetails['p_poster'] && !has_specific_permission(get_member(), 'view_any_profile_field') ? 1 : NULL, NULL, NULL, NULL, 1);
        // Usergroup
        $post['primary_group'] = $primary_group;
        $post['primary_group_name'] = ocf_get_group_name($primary_group);
        // Find avatar
        $avatar = $GLOBALS['OCF_DRIVER']->get_member_avatar_url($_postdetails['p_poster']);
        if ($avatar != '') {
            $post['poster_avatar'] = $avatar;
        }
        // Any warnings?
        if (has_specific_permission(get_member(), 'see_warnings') && addon_installed('ocf_warnings')) {
            $num_warnings = $GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_cache_warnings');
            /*if ($num_warnings!=0)*/
            $post['poster_num_warnings'] = $num_warnings;
        }
        // Join date
        $post['poster_join_date'] = $GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'], 'm_join_time');
        $post['poster_join_date_string'] = get_timezoned_date($post['poster_join_date']);
    } elseif ($_postdetails['p_poster'] == $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        if ($_postdetails['p_poster_name_if_guest'] == do_lang('SYSTEM')) {
            $post['poster_avatar'] = find_theme_image('ocf_default_avatars/default_set/ocp_fanatic', true);
        }
    }
    // Do we have any special controls over this post?
    require_code('ocf_posts');
    if (ocf_may_edit_post_by($_postdetails['p_poster'], $forum_id)) {
        $post['may_edit'] = true;
    }
    if (ocf_may_delete_post_by($_postdetails['p_poster'], $forum_id) && !$only_post) {
        $post['may_delete'] = true;
    }
    // More
    if (has_specific_permission(get_member(), 'see_ip')) {
        $post['ip_address'] = $_postdetails['p_ip_address'];
    }
    if (!is_null($_postdetails['p_intended_solely_for'])) {
        $post['intended_solely_for'] = $_postdetails['p_intended_solely_for'];
    }
    return $post;
}
Exemplo n.º 2
0
 /**
  * The UI to edit a post.
  *
  * @return tempcode		The UI
  */
 function edit_post()
 {
     $post_id = get_param_integer('id');
     $post_details = $GLOBALS['FORUM_DB']->query_select('f_posts', array('*'), array('id' => $post_id), '', 1);
     if (!array_key_exists(0, $post_details)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $forum_id = $post_details[0]['p_cache_forum_id'];
     if (!is_null($forum_id)) {
         $_comments_forum = get_option('comments_forum_name');
         if (is_numeric($_comments_forum)) {
             $comments_forum = $_comments_forum;
         } else {
             $comments_forum = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($_comments_forum);
         }
         if (!has_category_access(get_member(), 'forums', strval($forum_id)) && $forum_id != $comments_forum) {
             access_denied('CATEGORY_ACCESS');
         }
         // Can happen if trying to reply to a stated whisper made to you in a forum you don't have access to
     }
     if (!ocf_may_edit_post_by($post_details[0]['p_poster'], $forum_id)) {
         access_denied('I_ERROR');
     }
     $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('*'), array('id' => $post_details[0]['p_topic_id']), '', 1);
     if (!array_key_exists(0, $topic_info)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $this->handle_topic_breadcrumbs($forum_id, $post_details[0]['p_topic_id'], $topic_info[0]['t_cache_first_title'], do_lang_tempcode('EDIT_POST'));
     $hidden_fields = new ocp_tempcode();
     $intended_solely_for = $post_details[0]['p_intended_solely_for'];
     if (!is_null($intended_solely_for)) {
         $hidden_fields->attach(form_input_hidden('intended_solely_for', strval($intended_solely_for)));
     }
     $hidden_fields->attach(form_input_hidden('from_url', get_self_url(true)));
     $hidden_fields->attach(form_input_hidden('post_id', strval($post_id)));
     $map = array('page' => '_SELF', 'type' => '_edit_post');
     $redirect = get_param('redirect', '');
     if ($redirect != '') {
         $map['redirect'] = $redirect;
     }
     $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;
     }
     $post_url = build_url($map, '_SELF');
     $post = post_param('post', get_translated_text($post_details[0]['p_post'], $GLOBALS['FORUM_DB']));
     // Certain aspects relating to the posting system
     $specialisation = new ocp_tempcode();
     if (get_option('is_on_post_titles') == '1' || $post_details[0]['p_title'] != '' || $post_id == $topic_info[0]['t_cache_first_post_id']) {
         $specialisation->attach(form_input_line(do_lang_tempcode('TITLE'), '', 'title', post_param('title', $post_details[0]['p_title']), false, 1));
     }
     $specialisation->attach(form_input_line(do_lang_tempcode('REASON'), '', 'reason', '', false, 2));
     if (ocf_may_moderate_forum($forum_id, get_member())) {
         $moderation_options = array(array(do_lang_tempcode('EMPHASISED'), 'is_emphasised', $post_details[0]['p_is_emphasised'] == 1, do_lang_tempcode('DESCRIPTION_EMPHASISED')));
         if (addon_installed('unvalidated')) {
             if ($post_details[0]['p_validated'] == 0) {
                 $post_details[0]['p_validated'] = get_param_integer('validated', 0);
                 if ($post_details[0]['p_validated'] == 1) {
                     attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING'));
                 }
             }
             $moderation_options[] = array(do_lang_tempcode('VALIDATED'), 'validated', $post_details[0]['p_validated'] == 1, do_lang_tempcode('DESCRIPTION_VALIDATED'));
         }
     } else {
         $moderation_options = array();
         $hidden_fields->attach(form_input_hidden('validated', '1'));
     }
     $specialisation2 = new ocp_tempcode();
     require_code('fields');
     if (has_tied_catalogue('post')) {
         append_form_custom_fields('post', strval($post_id), $specialisation2, $hidden_fields);
     }
     if (count($moderation_options) != 0) {
         $specialisation2->attach(form_input_various_ticks($moderation_options, '', NULL, do_lang_tempcode('MODERATION_OPTIONS')));
     }
     $specialisation2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS'))));
     $options = array();
     $options[] = array(do_lang_tempcode('MARK_UNREAD'), 'mark_as_unread', false, do_lang_tempcode('DESCRIPTION_MARK_UNREAD'));
     $options[] = array(do_lang_tempcode('SHOW_AS_EDITED'), 'show_as_edited', time() - $post_details[0]['p_time'] > 60 * 3, do_lang_tempcode('DESCRIPTION_POST_SHOW_AS_EDITED'));
     $specialisation2->attach(form_input_various_ticks($options, ''));
     if (ocf_may_delete_post_by($post_details[0]['p_poster'], $forum_id)) {
         $specialisation2->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false));
     }
     // Awards?
     if (addon_installed('awards')) {
         require_code('awards');
         $specialisation->attach(get_award_fields('post', strval($post_id)));
     }
     if (is_null(get_param('post', NULL))) {
         $parsed = get_translated_tempcode($post_details[0]['p_post'], $GLOBALS['FORUM_DB']);
     } else {
         $parsed = NULL;
     }
     $posting_form = get_posting_form(do_lang('SAVE'), $post, $post_url, $hidden_fields, $specialisation, NULL, '', $specialisation2, $parsed, $this->_post_javascript());
     list($warning_details, $ping_url) = handle_conflict_resolution();
     $title = get_page_title('EDIT_POST');
     return do_template('POSTING_SCREEN', array('_GUID' => '347e469de58882bf77722bba6ed4aba4', 'STAFF_HELP_URL' => brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/tut_mod', 'TITLE' => $title, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'POSTING_FORM' => $posting_form));
 }
Exemplo n.º 3
0
/**
 * Delete posts from a topic.
 *
 * @param  AUTO_LINK		The ID of the topic we're deleting posts from.
 * @param  array			A list of posts to delete.
 * @param  LONG_TEXT		The reason for this action.
 * @return boolean		Whether the topic was deleted, due to all posts in said topic being deleted.
 */
function ocf_delete_posts_topic($topic_id, $posts, $reason)
{
    // Info about source
    $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id'), array('id' => $topic_id), '', 1);
    if (!array_key_exists(0, $info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $forum_id = $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
    $_postdetails = $GLOBALS['FORUM_DB']->query('SELECT id,p_post,p_poster,p_time,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++;
        }
        $post_owner = $post['p_poster'];
        if (!ocf_may_delete_post_by($post_owner, $forum_id)) {
            access_denied('I_ERROR');
        }
    }
    // Save in history
    foreach ($_postdetails as $post) {
        $GLOBALS['FORUM_DB']->query_insert('f_post_history', array('h_create_date_and_time' => $post['p_time'], 'h_action_date_and_time' => time(), 'h_owner_member_id' => $post['p_poster'], 'h_alterer_member_id' => get_member(), 'h_post_id' => $post['id'], 'h_topic_id' => $topic_id, 'h_before' => get_translated_text($post['p_post'], $GLOBALS['FORUM_DB']), 'h_action' => 'DELETE_POST'));
    }
    // Update member post counts
    $post_counts = is_null($forum_id) ? 1 : $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_post_count_increment', array('id' => $forum_id));
    if ($post_counts == 1) {
        $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 = $GLOBALS['FORUM_DB']->query($sql);
        $member_post_counts = array();
        foreach ($_member_post_counts as $_member_post_count) {
            $_member = $_member_post_count['p_poster'];
            if (!array_key_exists($_member, $member_post_counts)) {
                $member_post_counts[$_member] = 0;
            }
            $member_post_counts[$_member]++;
        }
        foreach ($member_post_counts as $member_id => $member_post_count) {
            if (!is_null($forum_id)) {
                ocf_force_update_member_post_count($member_id, -$member_post_count);
            }
        }
    }
    // Clean up lang
    require_code('attachments2');
    require_code('attachments3');
    foreach ($_postdetails as $post) {
        delete_lang_comcode_attachments($post['p_post'], 'ocf_post', $post['id'], $GLOBALS['FORUM_DB']);
    }
    $GLOBALS['FORUM_DB']->query('DELETE FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE ' . $or_list);
    $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'review_supplement WHERE ' . str_replace('id=', 'r_post_id=', $or_list));
    $test = $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)', array('p_topic_id' => $topic_id));
    if ($test == 0) {
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        ocf_delete_topic($topic_id, do_lang('DELETE_POSTS'));
        $ret = true;
    } else {
        $ret = false;
        // Update cacheing
        ocf_force_update_topic_cacheing($topic_id, -$num_posts_counted, true, true);
    }
    if (!is_null($forum_id)) {
        ocf_force_update_forum_cacheing($forum_id, 0, -$num_posts_counted);
    }
    require_code('ocf_general_action2');
    if (count($posts) == 1) {
        ocf_mod_log_it('DELETE_POST', strval($topic_id), strval($posts[0]), $reason);
    } else {
        ocf_mod_log_it('DELETE_POSTS', strval($topic_id), strval(count($posts)), $reason);
    }
    if (!is_null($forum_id)) {
        ocf_decache_ocp_blocks($forum_id);
    } else {
        decache('side_ocf_personal_topics');
        decache('_new_pp');
    }
    return $ret;
}