/** * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX. * * @return tempcode The snippet */ function run() { if (get_option('is_on_comments') == '0') { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } $serialized_options = get_param('serialized_options', false, true); $hash = get_param('hash'); if (best_hash($serialized_options, get_site_salt()) != $hash) { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } secure_serialized_data($serialized_options); list($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, $reverse, $may_reply, $highlight_by_user, $allow_reviews) = unserialize($serialized_options); $posts = array_map('intval', explode(',', get_param('ids', false, true))); $_parent_id = get_param('id', ''); $parent_id = $_parent_id == '' ? mixed() : intval($_parent_id); require_code('topics'); $renderer = new OCP_Topic(); return $renderer->render_posts_from_topic($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, NULL, $reverse, $may_reply, $highlight_by_user, $allow_reviews, $posts, $parent_id); }
/** * Render a topic. * * @param ?integer Number of posts to show initially (NULL: no limit) * @param integer Maximum thread depth * @param boolean Whether the current user may reply to the topic (influences what buttons show) * @param ?MEMBER User to highlight the posts of (NULL: none) * @param array Review ratings rows * @param AUTO_LINK ID of forum this topic in in * @param ?AUTO_LINK Only show posts under here (NULL: show posts from root) * @param boolean Whether to just render everything as flat (used when doing AJAX post loading). NOT actually used since we wrote better post-orphaning-fixing code. * @return array Tuple: Rendered topic, serialized options to render more posts, secure hash of serialized options to prevent tampering */ function render_posts($num_to_show_limit, $max_thread_depth, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id, $parent_post_id = NULL, $maybe_missing_links = false) { require_code('feedback'); if (get_forum_type() == 'ocf' && !addon_installed('ocf_forum')) { return array(); } $posts = array(); $queue = $this->all_posts_ordered; if (!is_null($parent_post_id) && !$maybe_missing_links) { $queue = $this->_grab_at_and_underneath($parent_post_id, $queue); } if (is_null($this->is_threaded)) { $this->is_threaded = false; } if (is_null($num_to_show_limit) || !$this->is_threaded) { $posts = $queue; $queue = array(); } else { $posts = $this->_decide_what_to_render($num_to_show_limit, $queue); } require_javascript('javascript_ajax'); require_javascript('javascript_more'); require_javascript('javascript_thumbnails'); // Precache member/group details in one fell swoop if (get_forum_type() == 'ocf') { require_code('ocf_topicview'); $members = array(); foreach ($posts as $_postdetails) { $members[$_postdetails['p_poster']] = 1; } ocf_cache_member_details(array_keys($members)); } if (!is_null($this->topic_id)) { // If FALSE then Posts will have been passed in manually as full already anyway $posts = $this->_grab_full_post_details($posts); } if ($this->is_threaded) { $tree = $this->_arrange_posts_in_tree($parent_post_id, $posts, $queue, $max_thread_depth); if (count($posts) != 0) { global $M_SORT_KEY; $M_SORT_KEY = 'date'; usort($posts, 'multi_sort'); while (count($posts) != 0) { $orphaned_post = array_shift($posts); $tree2 = $this->_arrange_posts_in_tree($orphaned_post['id'], $posts, $queue, $max_thread_depth); $orphaned_post['parent_id'] = NULL; $orphaned_post['children'] = $tree2; $tree[0][] = $orphaned_post; } } } else { $tree = array($posts); } $ret = $this->_render_post_tree($num_to_show_limit, $tree, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id); $other_ids = mixed(); if ($this->is_threaded) { $other_ids = array(); foreach ($tree[1] as $u) { $other_ids[] = strval($u['id']); } } $ret->attach(do_template('POST_CHILD_LOAD_LINK', array('NUM_TO_SHOW_LIMIT' => strval($num_to_show_limit), 'OTHER_IDS' => $other_ids, 'ID' => '', 'CHILDREN' => count($other_ids) == 0 ? '' : '1'))); if (!is_null($this->topic_id)) { $serialized_options = serialize(array($this->topic_id, $num_to_show_limit, true, false, strval($forum_id), $this->reverse, $may_reply, $highlight_by_user, count($all_individual_review_ratings) != 0)); $hash = best_hash($serialized_options, get_site_salt()); } else { $serialized_options = mixed(); $hash = mixed(); } return array($ret, $serialized_options, $hash); }
/** * Do an AJAX comment post */ function post_comment_script() { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past // Read in context of what we're doing $options = post_param('options'); secure_serialized_data($options); list($page_name, $content_id, $allow_comments, $submitter, $content_url, $content_title, $forum) = unserialize($options); // Check security $hash = post_param('hash'); if (best_hash($options, get_site_salt()) != $hash) { header('Content-Type: text/plain; charset=' . get_charset()); exit; } // Post comment actualise_post_comment($allow_comments >= 1, $page_name, $content_id, $content_url, $content_title, $forum); // Get new comments state $comment_details = get_comments($page_name, $allow_comments == 1, $content_id, false, $forum, NULL, NULL, false, false, $submitter, $allow_comments == 2); // And output as text header('Content-Type: text/plain; charset=' . get_charset()); $comment_details->evaluate_echo(); }