/** * Makes a post in the specified forum, in the specified topic according to the given specifications. If the topic doesn't exist, it is created along with a spacer-post. * Spacer posts exist in order to allow staff to delete the first true post in a topic. Without spacers, this would not be possible with most forum systems. They also serve to provide meta information on the topic that cannot be encoded in the title (such as a link to the content being commented upon). * * @param object Link to the real forum driver * @param SHORT_TEXT The forum name * @param SHORT_TEXT The topic identifier (usually <content-type>_<content-id>) * @param MEMBER The member ID * @param LONG_TEXT The post title * @param LONG_TEXT The post content in Comcode format * @param string The topic title; must be same as content title if this is for a comment topic * @param string This is put together with the topic identifier to make a more-human-readable topic title or topic description (hopefully the latter and a $content_title title, but only if the forum supports descriptions) * @param ?URLPATH URL to the content (NULL: do not make spacer post) * @param ?TIME The post time (NULL: use current time) * @param ?IP The post IP address (NULL: use current members IP address) * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param ?BINARY Whether the topic is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param boolean Whether to skip post checks * @param SHORT_TEXT The name of the poster * @param ?AUTO_LINK ID of post being replied to (NULL: N/A) * @param boolean Whether the reply is only visible to staff * @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) * @return array Topic ID (may be NULL), and whether a hidden post has been made */ function _helper_make_post_forum_topic($this_ref, $forum_name, $topic_identifier, $member_id, $post_title, $post, $content_title, $topic_identifier_encapsulation_prefix, $content_url, $time, $ip, $validated, $topic_validated, $skip_post_checks, $poster_name_if_guest, $parent_id, $staff_only, $no_notify_for__notification_code, $no_notify_for__code_category) { if (is_null($time)) { $time = time(); } if (is_null($ip)) { $ip = get_ip_address(); } require_code('comcode_check'); check_comcode($post, NULL, false, NULL, true); require_code('ocf_topics'); require_code('ocf_posts'); //require_code('ocf_forums'); require_lang('ocf'); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); if (!is_integer($forum_name)) { $forum_id = $this_ref->forum_id_from_name($forum_name); if (is_null($forum_id)) { warn_exit(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name))); } } else { $forum_id = (int) $forum_name; } $topic_id = $this_ref->find_topic_id_for_topic_identifier($forum_name, $topic_identifier); $update_caching = false; $support_attachments = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $update_caching = true; $support_attachments = true; } if (is_null($topic_id)) { $is_starter = true; require_code('ocf_topics_action'); $topic_id = ocf_make_topic($forum_id, $topic_identifier_encapsulation_prefix . ': #' . $topic_identifier, '', $topic_validated, 1, 0, 0, 0, NULL, NULL, false, 0, NULL, $content_url); if (strpos($topic_identifier, ':') !== false) { // Sync comment_posted ones to also monitor the forum ones; no need for opposite way as comment ones already trigger forum ones $start = 0; $max = 300; require_code('notifications'); $ob = _get_notification_ob_for_code('comment_posted'); do { list($members, $possibly_has_more) = $ob->list_members_who_have_enabled('comment_posted', $topic_identifier, NULL, $start, $max); foreach ($members as $to_member_id => $setting) { enable_notifications('ocf_topic', strval($topic_id), $to_member_id); } $start += $max; } while ($possibly_has_more); } // Make spacer post if (!is_null($content_url)) { $spacer_title = $content_title; $home_link = hyperlink($content_url, escape_html($content_title)); $spacer_post = '[semihtml]' . do_lang('SPACER_POST', $home_link->evaluate(), '', '', get_site_default_lang()) . '[/semihtml]'; ocf_make_post($topic_id, $spacer_title, $spacer_post, 0, true, 1, 0, do_lang('SYSTEM'), $ip, $time, db_get_first_id(), NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, false, false, false); $is_starter = false; } $is_new = true; } else { $is_starter = false; $is_new = false; } $GLOBALS['LAST_TOPIC_ID'] = $topic_id; $GLOBALS['LAST_TOPIC_IS_NEW'] = $is_new; if ($post == '') { return array(NULL, false); } ocf_check_post($post, $topic_id, $member_id); $poster_name = $poster_name_if_guest; if ($poster_name == '') { $poster_name = $this_ref->get_username($member_id); } $post_id = ocf_make_post($topic_id, $post_title, $post, 0, $is_starter, $validated, 0, $poster_name, $ip, $time, $member_id, $staff_only ? $GLOBALS['FORUM_DRIVER']->get_guest_id() : NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, $skip_post_checks, false, false, $parent_id); $GLOBALS['LAST_POST_ID'] = $post_id; if ($is_new) { // Broken cache now for the rest of this page view - fix by flushing global $TOPIC_IDENTIFIERS_TO_IDS; $TOPIC_IDENTIFIERS_TO_IDS = array(); } // Send out notifications $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); ocf_send_topic_notification($url, $topic_id, $forum_id, $member_id, $is_new, $post, $content_title, NULL, false, $no_notify_for__notification_code, $no_notify_for__code_category); $is_hidden = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $validated_actual = $this_ref->connection->query_value('f_posts', 'p_validated', array('id' => $post_id)); if ($validated_actual == 0) { require_code('site'); attach_message(do_lang_tempcode('SUBMIT_UNVALIDATED'), 'inform'); $is_hidden = true; } } return array($topic_id, $is_hidden); }
/** * 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); }
/** * Standard modular run function for preview hooks. * * @return array A pair: The preview, the updated post Comcode */ function run() { require_lang('ocf'); require_css('ocf'); $original_comcode = post_param('post'); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); ocf_check_post($original_comcode, post_param_integer('topic_id', NULL), get_member()); $posting_ref_id = post_param_integer('posting_ref_id', mt_rand(0, 100000)); if ($posting_ref_id < 0) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } $post_bits = do_comcode_attachments($original_comcode, 'ocf_post', strval(-$posting_ref_id), true, $GLOBALS['FORUM_DB']); $post_comcode = $post_bits['comcode']; $post_html = $post_bits['tempcode']; // Put quote in $parent_id = post_param_integer('parent_id', NULL); if (!is_null($parent_id) && strpos($post_comcode, '[quote') === false) { $_p = $GLOBALS['FORUM_DB']->query_select('f_posts', array('*'), array('id' => $parent_id), '', 1); if (array_key_exists(0, $_p)) { $p = $_p[0]; $p['message'] = get_translated_tempcode($p['p_post'], $GLOBALS['FORUM_DB']); $temp = $post_html; $post_html = new ocp_tempcode(); $post_html = do_template('COMCODE_QUOTE_BY', array('SAIDLESS' => false, 'BY' => $p['p_poster_name_if_guest'], 'CONTENT' => $p['message'])); $post_html->attach($temp); } } $post_owner = get_member(); $_post_date = time(); $post_id = post_param_integer('post_id', NULL); if (!is_null($post_id)) { $post_owner = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_poster', array('id' => $post_id)); if (is_null($post_owner)) { $post_owner = get_member(); } $_post_date = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_time', array('id' => $post_id)); if (is_null($_post_date)) { $_post_date = time(); } } $post_date = get_timezoned_date($_post_date); $post_title = post_param('title', ''); if (strlen($post_title) > 120) { warn_exit(do_lang_tempcode('TITLE_TOO_LONG')); } $unvalidated = post_param_integer('validated', 0) == 0 && get_param('page', '') == 'topics' ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode(); $emphasis = new ocp_tempcode(); $intended_solely_for = post_param('intended_solely_for', NULL); if ($intended_solely_for == '') { $intended_solely_for = NULL; } $is_emphasised = post_param_integer('is_emphasised', 0) == 1; if ($is_emphasised) { $emphasis = do_lang_tempcode('IMPORTANT'); } elseif (!is_null($intended_solely_for)) { if (is_numeric($intended_solely_for)) { $_intended_solely_for = $GLOBALS['FORUM_DRIVER']->get_username(intval($intended_solely_for)); if (!is_null($_intended_solely_for)) { $intended_solely_for = $_intended_solely_for; } } $emphasis = do_lang_tempcode('PP_TO', escape_html($intended_solely_for)); } $class = $is_emphasised ? 'ocf_post_emphasis' : (!is_null($intended_solely_for) ? 'ocf_post_personal' : ''); // Member details $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_signature'), $GLOBALS['FORUM_DB']); $_postdetails_avatar = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($post_owner); if ($_postdetails_avatar != '') { $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('_GUID' => '2683c09eabd7a9f1fdc57a20117483ef', 'AVATAR' => $_postdetails_avatar)); } else { $post_avatar = new ocp_tempcode(); } require_code('ocf_groups'); require_code('ocf_members'); $poster_title = addon_installed('ocf_member_titles') ? $GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_title') : ''; $primary_group = $GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_primary_group'); if ($poster_title == '') { $poster_title = get_translated_text(ocf_get_group_property($primary_group, 'title'), $GLOBALS['FORUM_DB']); } // Poster box if (!is_guest($post_owner)) { require_code('ocf_members2'); $poster_details = ocf_show_member_box($post_owner, false, NULL, NULL, false); $poster_username = $GLOBALS['FORUM_DRIVER']->get_username($post_owner); if (is_null($poster_username)) { $poster_username = do_lang('UNKNOWN'); } $poster = do_template('OCF_POSTER_MEMBER', array('_GUID' => '976a6ceb631bbdcdd950b723cb5d2487', 'ONLINE' => true, 'ID' => strval($post_owner), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post_owner, false, true), 'POSTER_USERNAME' => $poster_username)); } else { $poster_details = new ocp_tempcode(); $custom_fields = do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => get_ip_address())); $poster_details = do_template('OCF_GUEST_DETAILS', array('_GUID' => '2db48e17db9f060c04386843f2d0f105', 'CUSTOM_FIELDS' => $custom_fields)); $poster_username = post_param('poster_name_if_guest', do_lang('GUEST')); $ip_link = has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => get_ip_address()), get_module_zone('admin_lookup')) : new ocp_tempcode(); $poster = do_template('OCF_POSTER_GUEST', array('_GUID' => '9c0ba6198663de96facc7399a08e8281', 'IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $poster_username)); } // Rank images $rank_images = new ocp_tempcode(); $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($post_owner, true); foreach ($posters_groups as $group) { $rank_image = ocf_get_group_property($group, 'rank_image'); $group_leader = ocf_get_group_property($group, 'group_leader'); $group_name = ocf_get_group_name($group); if ($rank_image != '') { $rank_images->attach(do_template('OCF_RANK_IMAGE', array('_GUID' => 'a6a413fc07e05b28ab995b072718b755', 'GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == get_member()))); } } if (get_param('type') == 'edit_post') { $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => strval(time()), 'LAST_EDIT_DATE' => get_timezoned_date(time(), true), 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url(get_member(), false, true), 'LAST_EDIT_USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()))); } else { $last_edited = new ocp_tempcode(); } $post = do_template('OCF_TOPIC_POST', array('_GUID' => '354473f96b4f7324d2a9c476ff78f0d7', 'POST_ID' => '', 'TOPIC_FIRST_POST_ID' => '', 'TOPIC_FIRST_POSTER' => strval(get_member()), 'POST_TITLE' => $post_title, 'CLASS' => $class, 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => '', 'TOPIC_ID' => '', 'ID' => '', 'POST_DATE_RAW' => strval($_post_date), 'POST_DATE' => $post_date, 'UNVALIDATED' => $unvalidated, 'URL' => '', 'POSTER' => $poster, 'POST_AVATAR' => $post_avatar, 'POSTER_TITLE' => $poster_title, 'RANK_IMAGES' => $rank_images, 'POST' => $post_html, 'LAST_EDITED' => $last_edited, 'SIGNATURE' => $signature, 'BUTTONS' => '', 'POSTER_ID' => strval($post_owner))); $out = do_template('OCF_TOPIC_POST_CLEAN_WRAP', array('_GUID' => '62bbfabfa5c16c2aa6724a0b79839626', 'POST' => $post)); return array($out, $post_comcode); }
/** * Add a post. * * @param AUTO_LINK The ID of the topic to add the post to. * @param SHORT_TEXT The title of the post (may be blank). * @param LONG_TEXT The post. * @param BINARY Whether to skip showing the posters signature in the post. * @param boolean Whether the post is the first in the topic. * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). * @param BINARY Whether the post is marked emphasised. * @param ?string The name of the person making the post (NULL: username of current member). * @param ?IP The IP address the post is to be made under (NULL: IP of current user). * @param ?TIME The time of the post (NULL: now). * @param ?MEMBER The poster (NULL: current member). * @param ?MEMBER The member that this post is intended solely for (NULL: public). * @param ?TIME The last edit time of the post (NULL: never edited). * @param ?MEMBER The member that was last to edit the post (NULL: never edited). * @param boolean Whether to check permissions for whether the post may be made as it is given. * @param boolean Whether to update the caches after making the post. * @param ?AUTO_LINK The forum the post will be in (NULL: find out from the DB). * @param boolean Whether to allow attachments in this post. * @param ?string The title of the topic (NULL: find from the DB). * @param BINARY Whether the topic is a sunk topic. * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param boolean Whether to make the post anonymous * @param boolean Whether to skip post checks * @param boolean Whether this is for a new Private Topic * @param boolean Whether to explicitly insert the Comcode with admin privileges * @param ?AUTO_LINK Parent post ID (NULL: none-threaded/root-of-thread) * @return AUTO_LINK The ID of the new post. */ function ocf_make_post($topic_id, $title, $post, $skip_sig = 0, $is_starter = false, $validated = NULL, $is_emphasised = 0, $poster_name_if_guest = NULL, $ip_address = NULL, $time = NULL, $poster = NULL, $intended_solely_for = NULL, $last_edit_time = NULL, $last_edit_by = NULL, $check_permissions = true, $update_cacheing = true, $forum_id = NULL, $support_attachments = true, $topic_title = '', $sunk = 0, $id = NULL, $anonymous = false, $skip_post_checks = false, $is_pt = false, $insert_comcode_as_admin = false, $parent_id = NULL) { if (is_null($poster)) { $poster = get_member(); } if ($check_permissions) { if (strlen($title) > 120) { warn_exit(do_lang_tempcode('TITLE_TOO_LONG')); } if (get_option('prevent_shouting') == '1') { if (strtoupper($title) == $title) { $title = ucwords($title); } } if (is_null($intended_solely_for) && !$skip_post_checks) { ocf_check_post($post, $topic_id, $poster); } } if (is_null($ip_address)) { $ip_address = get_ip_address(); } if (is_null($time)) { $time = time(); $send_notification = true; } else { $send_notification = false; } if (is_null($poster_name_if_guest)) { if ($poster == $GLOBALS['OCF_DRIVER']->get_guest_id() || $anonymous) { $poster_name_if_guest = do_lang('GUEST'); } else { $poster_name_if_guest = $GLOBALS['OCF_DRIVER']->get_username($poster); if (is_null($poster_name_if_guest)) { $poster_name_if_guest = do_lang('UNKNOWN'); } } } if (is_null($forum_id) || $topic_title == '' && !$is_starter) { $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_is_open', 't_pt_from', 't_pt_to', 't_forum_id', 't_cache_last_member_id', 't_cache_first_title'), 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']; $topic_title = $info[0]['t_cache_first_title']; if ($topic_title == '') { $topic_title = $title; } if ($check_permissions) { if ($info[0]['t_pt_from'] != get_member() && $info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($forum_id)) { access_denied('I_ERROR'); } } } if (is_null($forum_id)) { if ($check_permissions && $poster == $GLOBALS['OCF_DRIVER']->get_guest_id()) { access_denied('I_ERROR'); } $validated = 1; // Personal posts always validated } else { if ($check_permissions) { if ($info[0]['t_is_open'] == 0 && !ocf_may_moderate_forum($forum_id)) { access_denied('I_ERROR'); } $last_member_id = $info[0]['t_cache_last_member_id']; if (!ocf_may_post_in_topic($forum_id, $topic_id, $last_member_id) && !$is_starter) { access_denied('I_ERROR'); } } } // Ensure parent post is from the same topic if (!is_null($parent_id)) { $test_topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_topic_id', array('id' => $parent_id), ' AND ' . ocf_get_topic_where($topic_id, $poster)); if (is_null($test_topic_id)) { $parent_id = NULL; } } if (is_null($validated) || $validated == 1 && $check_permissions) { if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_lowrange_content', 'topics', array('forums', $forum_id))) { $validated = 0; } else { $validated = 1; } } if (!$support_attachments) { $lang_id = insert_lang_comcode($post, 4, $GLOBALS['FORUM_DB'], $insert_comcode_as_admin); } else { $lang_id = 0; } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('p_title' => substr($title, 0, 255), 'p_post' => $lang_id, 'p_ip_address' => $ip_address, 'p_time' => $time, 'p_poster' => $anonymous ? db_get_first_id() : $poster, 'p_poster_name_if_guest' => substr($poster_name_if_guest, 0, 80), 'p_validated' => $validated, 'p_topic_id' => $topic_id, 'p_is_emphasised' => $is_emphasised, 'p_cache_forum_id' => $forum_id, 'p_last_edit_time' => $last_edit_time, 'p_last_edit_by' => $last_edit_by, 'p_intended_solely_for' => $intended_solely_for, 'p_skip_sig' => $skip_sig, 'p_parent_id' => $parent_id); if (!is_null($id)) { $map['id'] = $id; } $post_id = $GLOBALS['FORUM_DB']->query_insert('f_posts', $map, true); if ($support_attachments) { require_code('attachments2'); $lang_id = insert_lang_comcode_attachments(4, $post, 'ocf_post', strval($post_id), $GLOBALS['FORUM_DB']); $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_post' => $lang_id), array('id' => $post_id), '', 1); } $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); if ($validated == 0) { if ($check_permissions) { // send_validation_mail is used for other content - but forum is special $subject = do_lang('POST_REQUIRING_VALIDATION_MAIL_SUBJECT', $topic_title, NULL, NULL, get_site_default_lang()); $post_text = get_translated_text($lang_id, $GLOBALS['FORUM_DB'], get_site_default_lang()); $mail = do_lang('POST_REQUIRING_VALIDATION_MAIL', comcode_escape($url), comcode_escape($poster_name_if_guest), $post_text); require_code('notifications'); dispatch_notification('needs_validation', NULL, $subject, $mail); } } else { if ($check_permissions) { if ($send_notification) { $post_comcode = get_translated_text($lang_id, $GLOBALS['FORUM_DB']); require_code('ocf_posts_action2'); ocf_send_topic_notification($url, $topic_id, $forum_id, $anonymous ? db_get_first_id() : $poster, $is_starter, $post_comcode, $topic_title, $intended_solely_for, $is_pt); // Send a notification for the inline PP if (!is_null($intended_solely_for)) { require_code('notifications'); $msubject = do_lang('NEW_PERSONAL_POST_SUBJECT', $topic_title, NULL, NULL, get_lang($intended_solely_for)); $mmessage = do_lang('NEW_PERSONAL_POST_MESSAGE', comcode_escape($GLOBALS['FORUM_DRIVER']->get_username($anonymous ? db_get_first_id() : $poster)), comcode_escape($topic_title), array(comcode_escape($url), $post_comcode), get_lang($intended_solely_for)); dispatch_notification('ocf_new_pt', NULL, $msubject, $mmessage, array($intended_solely_for), $anonymous ? db_get_first_id() : $poster); } } } } if ($check_permissions) { // Is the user gonna automatically enable notifications for this? $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field($poster, 'm_auto_monitor_contrib_content'); if ($auto_monitor_contrib_content == 1) { require_code('notifications'); enable_notifications('ocf_topic', strval($topic_id), $poster); } } if ($update_cacheing) { if (function_exists('get_member')) { if (function_exists('ocf_ping_topic_read')) { ocf_ping_topic_read($topic_id); } if (is_null($forum_id)) { $with = $info[0]['t_pt_from']; if ($with == get_member()) { $with = $info[0]['t_pt_to']; } decache('side_ocf_personal_topics', array($with)); decache('_new_pp', array($with)); } if (get_option('show_post_validation') == '1') { decache('main_staff_checklist'); } } if (is_null($intended_solely_for)) { if ($validated == 1) { require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($topic_id, 1, true, $is_starter, $post_id, $time, $title, $lang_id, $poster_name_if_guest, $poster); } if ($validated == 1) { if (!is_null($forum_id)) { require_code('ocf_posts_action2'); // Find if the topic is validated. This can be approximate, if we don't get 1 then ocf_force_update_forum_cacheing will do a search, making the code very slightly slower if (!$check_permissions || is_null($forum_id)) { $topic_validated = 1; } else { if ($is_starter) { $topic_validated = has_specific_permission($poster, 'bypass_validation_midrange_content', 'topics', array('forums', $forum_id)) ? 1 : 0; } else { $topic_validated = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_validated', array('id' => $topic_id)); } } ocf_force_update_forum_cacheing($forum_id, $is_starter ? 1 : 0, 1, $topic_validated == 0 ? NULL : $topic_id, $topic_validated == 0 ? NULL : $topic_title, $topic_validated == 0 ? NULL : $time, $topic_validated == 0 ? NULL : $poster_name_if_guest, $topic_validated == 0 ? NULL : $poster, $topic_validated == 0 ? NULL : $forum_id); } } } // Update post count if (!is_null($forum_id)) { $post_counts = is_null($forum_id) ? 1 : $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_post_count_increment', array('id' => $forum_id)); if ($post_counts === 1 && !$anonymous && $validated == 1) { ocf_force_update_member_post_count($poster, 1); } if ($check_permissions) { ocf_decache_ocp_blocks($forum_id, NULL, $intended_solely_for); } // i.e. we don't run this if in installer } if ($poster != $GLOBALS['OCF_DRIVER']->get_guest_id()) { require_code('ocf_posts_action2'); ocf_member_handle_promotion($poster); } } return $post_id; }
/** * Edit a post. * * @param AUTO_LINK The ID of the post that we're editing. * @param BINARY Whether the post is validated. * @param SHORT_TEXT The title of the post (may be blank). * @param LONG_TEXT The post. * @param BINARY Whether to skip showing the posters signature in the post. * @param BINARY Whether the post is marked emphasised. * @param ?MEMBER The member that this post is intended solely for (NULL: none). * @param boolean Whether to show the post as edited. * @param boolean Whether to mark the topic as unread by those previous having read this post. * @param LONG_TEXT The reason for this action. * @param boolean Whether to check permissions. * @return AUTO_LINK The ID of the topic (whilst this could be known without calling this function, as we've gone to effort and grabbed it from the DB, it might turn out useful for something). */ function ocf_edit_post($post_id, $validated, $title, $post, $skip_sig, $is_emphasised, $intended_solely_for, $show_as_edited, $mark_as_unread, $reason, $check_perms = true) { $post_info = $GLOBALS['FORUM_DB']->query_select('f_posts', array('p_topic_id', 'p_time', 'p_post', 'p_poster', 'p_cache_forum_id'), array('id' => $post_id)); if (!array_key_exists(0, $post_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $_postdetails = $post_info[0]['p_post']; $post_owner = $post_info[0]['p_poster']; $forum_id = $post_info[0]['p_cache_forum_id']; $topic_id = $post_info[0]['p_topic_id']; $update = array(); require_code('ocf_posts_action'); require_code('ocf_posts'); ocf_check_post($post); if ($check_perms) { if (!ocf_may_edit_post_by($post_owner, $forum_id)) { access_denied('I_ERROR'); } } if (is_null($validated) || $validated == 1) { if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_lowrange_content', 'topics', array('forums', $forum_id))) { $validated = 0; } else { $validated = 1; } if ($mark_as_unread) { // $topic_info=$GLOBALS['FORUM_DB']->query_select('f_topics',array('t_cache_last_time'),array('id'=>$topic_id),'',1); // $seven_days_ago=time()-60*60*24*intval(get_option('post_history_days')); Can't be conditional, as we need the vforums to update, and they depend on t_cache_last_time. We can't just update t_cache_last_time for consistency // if ($topic_info[0]['t_cache_last_time']<$seven_days_ago) $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_cache_last_time' => time(), 't_cache_last_post_id' => $post_id, 't_cache_last_title' => $title, 't_cache_last_username' => $GLOBALS['FORUM_DRIVER']->get_username($post_owner), 't_cache_last_member_id' => $post_owner), array('id' => $topic_id), '', 1); // $update['p_time']=time(); Not viable- would reorder topic. $GLOBALS['FORUM_DB']->query_delete('f_read_logs', array('l_topic_id' => $topic_id)); } } $edit_time = time(); // Save in history $GLOBALS['FORUM_DB']->query_insert('f_post_history', array('h_create_date_and_time' => $post_info[0]['p_time'], 'h_action_date_and_time' => $edit_time, 'h_owner_member_id' => $post_owner, 'h_alterer_member_id' => get_member(), 'h_post_id' => $post_id, 'h_topic_id' => $topic_id, 'h_before' => get_translated_text($_postdetails, $GLOBALS['FORUM_DB']), 'h_action' => 'EDIT_POST')); require_code('attachments2'); require_code('attachments3'); if (!addon_installed('unvalidated')) { $validated = 1; } $update = array_merge($update, array('p_title' => $title, 'p_post' => update_lang_comcode_attachments($_postdetails, $post, 'ocf_post', strval($post_id), $GLOBALS['FORUM_DB'], false, $post_owner), 'p_is_emphasised' => $is_emphasised, 'p_intended_solely_for' => $intended_solely_for, 'p_validated' => $validated, 'p_skip_sig' => $skip_sig)); if ($show_as_edited) { $update['p_last_edit_time'] = $edit_time; $update['p_last_edit_by'] = get_member(); } else { $update['p_last_edit_time'] = NULL; $update['p_last_edit_by'] = NULL; } $GLOBALS['FORUM_DB']->query_update('f_posts', $update, array('id' => $post_id), '', 1); // Update topic cacheing $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_cache_first_post_id', 't_cache_first_title'), array('id' => $topic_id), '', 1); if (array_key_exists(0, $info) && $info[0]['t_cache_first_post_id'] == $post_id && $info[0]['t_cache_first_title'] != $title) { require_code('urls2'); suggest_new_idmoniker_for('topicview', 'misc', strval($topic_id), $title); $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_cache_first_title' => $title), array('id' => $topic_id), '', 1); } require_code('ocf_general_action2'); ocf_mod_log_it('EDIT_POST', strval($post_id), $title, $reason); if (!is_null($forum_id)) { ocf_decache_ocp_blocks($forum_id); } return $topic_id; // We may want this }