/** * Display topic section for support/tracker/etc * * @param object $topic The topic object * @param titania_sort $sort The sort object (includes/tools/sort.php) */ public static function display_topic($topic, $sort = false) { if ($sort === false) { // Setup the sort tool $sort = self::build_sort(); } $sort->request(); $sql_ary = array('SELECT' => 'p.*', 'FROM' => array(TITANIA_POSTS_TABLE => 'p'), 'WHERE' => 'p.topic_id = ' . (int) $topic->topic_id . self::sql_permissions('p.'), 'ORDER_BY' => $sort->get_order_by()); // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 'p.post_id')) { // No results...no need to query more... return; } $sort->build_pagination($topic->get_url()); // Get the data $post_ids = $user_ids = array(); $last_post_time = 0; // tracking $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); while ($row = phpbb::$db->sql_fetchrow($result)) { self::$posts[$row['post_id']] = $row; self::$posts[$row['post_id']]['attachments'] = array(); $post_ids[] = $row['post_id']; $user_ids[] = $row['post_user_id']; $user_ids[] = $row['post_edit_user']; $user_ids[] = $row['post_delete_user']; $last_post_time = $row['post_time']; // to set tracking } phpbb::$db->sql_freeresult($result); // Grab the tracking data $last_mark_time = titania_tracking::get_track(TITANIA_TOPIC, $topic->topic_id); // Store tracking data titania_tracking::track(TITANIA_TOPIC, $topic->topic_id, $last_post_time); // load the user data users_overlord::load($user_ids); phpbb::_include('functions_profile_fields', false, 'custom_profile'); $cp = new custom_profile(); $post = new titania_post($topic->topic_type, $topic); $attachments = new titania_attachment($topic->topic_type, false); // Grab all attachments $attachments_set = $attachments->load_attachments_set($post_ids); // Loop de loop $prev_post_time = 0; foreach ($post_ids as $post_id) { $post->__set_array(self::$posts[$post_id]); $attachments->clear_attachments(); if (isset($attachments_set[$post_id])) { $attachments->store_attachments($attachments_set[$post_id]); } // Parse attachments before outputting the message $message = $post->generate_text_for_display(); $parsed_attachments = $attachments->parse_attachments($message); // Prepare message text for use in javascript $message_decoded = censor_text($post->post_text); titania_decode_message($message_decoded, $post->post_text_uid); $message_decoded = bbcode_nl2br($message_decoded); // Build CP Fields $cp_row = array(); if (isset(users_overlord::$cp_fields[$post->post_user_id])) { $cp_row = $cp->generate_profile_fields_template('show', false, users_overlord::$cp_fields[$post->post_user_id]); } $cp_row['row'] = isset($cp_row['row']) && sizeof($cp_row['row']) ? $cp_row['row'] : array(); // Display edit info $display_username = get_username_string('full', $post->post_user_id, users_overlord::get_user($post->post_user_id, 'username'), users_overlord::get_user($post->post_user_id, 'user_colour'), false, phpbb::append_sid('memberlist', 'mode=viewprofile')); $l_edited_by = $post->post_edit_time ? sprintf(phpbb::$user->lang['EDITED_MESSAGE'], $display_username, phpbb::$user->format_date($post->post_edit_time)) : ''; phpbb::$template->assign_block_vars('posts', array_merge($post->assign_details(false), users_overlord::assign_details($post->post_user_id), $cp_row['row'], array('POST_TEXT' => $message, 'POST_TEXT_DECODED' => $message_decoded, 'EDITED_MESSAGE' => $l_edited_by, 'U_MINI_POST' => titania_url::append_url($topic->get_url(), array('p' => $post_id, '#p' => $post_id)), 'MINI_POST_IMG' => $post->post_time > $last_mark_time ? phpbb::$user->img('icon_post_target_unread', 'NEW_POST') : phpbb::$user->img('icon_post_target', 'POST'), 'S_FIRST_UNREAD' => $post->post_time > $last_mark_time && $prev_post_time <= $last_mark_time ? true : false))); // Output CP Fields if (!empty($cp_row['blockrow'])) { foreach ($cp_row['blockrow'] as $field_data) { phpbb::$template->assign_block_vars('posts.custom_fields', $field_data); } } //S_IGNORE_POST //POST_ICON_IMG //MINI_POST_IMG foreach ($parsed_attachments as $attachment) { phpbb::$template->assign_block_vars('posts.attachment', array('DISPLAY_ATTACHMENT' => $attachment)); } $prev_post_time = $post->post_time; } unset($post, $attachments); // Increment the topic view count $sql = 'UPDATE ' . TITANIA_TOPICS_TABLE . ' SET topic_views = topic_views + 1 WHERE topic_id = ' . (int) $topic->topic_id; phpbb::$db->sql_query($sql); }