/** * Split/merge * * @param int $topic_id * @param string $mode Either split_topic or move_posts * @return Response|RedirectResponse */ public function split_topic($topic_id, $mode) { // Auth check if (!$this->auth->acl_get('u_titania_mod_post_mod')) { return $this->controller_helper->needs_auth(); } $this->user->add_lang('mcp'); $subject = $this->request->variable('subject', '', true); $new_topic_id = $this->request->variable('new_topic_id', 0); $post_ids = $this->request->variable('post_ids', array(0)); $submit = $this->request->is_set_post('split'); $range = $this->request->variable('from', ''); $topic = $this->load_topic($topic_id); $errors = array(); if ($topic->topic_type != TITANIA_SUPPORT) { return $this->controller_helper->message('SPLIT_NOT_ALLOWED'); } $page_title = $mode == 'split_topic' ? 'SPLIT_TOPIC' : 'MERGE_POSTS'; $page_title = $this->user->lang($page_title) . ' - ' . $topic->topic_subject; if ($submit) { // Check for errors if (!check_form_key('split_topic')) { $errors[] = $this->user->lang['FORM_INVALID']; } if ($mode == 'split_topic' && utf8_clean_string($subject) == '') { $errors[] = $this->user->lang['NO_SUBJECT']; } else { if ($mode == 'move_posts' && !$new_topic_id) { $errors[] = $this->user->lang['NO_FINAL_TOPIC_SELECTED']; } } if (empty($post_ids)) { $errors[] = $this->user->lang['NO_POST_SELECTED']; } if ($new_topic_id == $topic->topic_id) { $errors[] = $this->user->lang['ERROR_MERGE_SAME_TOPIC']; } if (empty($errors)) { if ($mode == 'move_posts') { // Load the topic $new_topic = $this->load_topic($new_topic_id); if (!$new_topic) { $errors[] = $this->user->lang['NO_TOPIC']; } // Only allow support posts to be moved to the same contrib if ($new_topic->parent_id != $topic->parent_id || $new_topic->topic_type != TITANIA_SUPPORT) { $errors[] = $this->user->lang['ERROR_NOT_SAME_PARENT']; } // Ensure that we don't have a range $range = false; } else { $sql_extra = 'post_id = ' . (int) $post_ids[0]; // Get info from first post $sql = 'SELECT post_id, post_access, post_approved, post_time FROM ' . TITANIA_POSTS_TABLE . ' WHERE post_type = ' . TITANIA_SUPPORT . ' AND topic_id = ' . (int) $topic->topic_id . ' AND '; $result = $this->db->sql_query_limit($sql . $sql_extra, 1); $first_post = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (!$first_post) { $errors[] = $this->user->lang['NO_POST_SELECTED']; } else { if ($range == 'from') { // Get info from last post $sql_extra = 'post_time >= ' . (int) $first_post['post_time'] . ' ORDER BY post_time DESC'; $result = $this->db->sql_query_limit($sql . $sql_extra, 1); $last_post = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $range = array('min' => $first_post['post_time'], 'max' => $last_post['post_time']); } else { $range = false; } // Create the new \topic with some basic info. $data = array('parent_id' => $topic->parent_id, 'topic_type' => $topic->topic_type, 'topic_access' => $first_post['post_access'], 'topic_approved' => 1, 'topic_status' => ITEM_UNLOCKED, 'topic_time' => $first_post['post_time'], 'topic_subject' => $subject, 'topic_url' => $topic->topic_url); $new_topic = new \titania_topic(); $new_topic->__set_array($data); $new_topic->submit(); // Use new subject as the first post's subject to avoid issues when it gets approved if (!$first_post['post_approved']) { $sql = 'UPDATE ' . TITANIA_POSTS_TABLE . ' SET post_subject = "' . $this->db->sql_escape($subject) . '" WHERE post_id = ' . (int) $first_post['post_id']; $this->db->sql_query($sql); } } } // If there aren't any errors, go ahead and transfer the posts. if (empty($errors)) { $new_topic->acquire_posts($topic, $post_ids, $range); return new RedirectResponse($new_topic->get_url()); } } } if (!$submit || !empty($errors)) { $errors = implode('<br />', $errors); $this->template->assign_vars(array('ERRORS' => $errors, 'TOPIC_SUBJECT' => $topic->topic_subject, 'S_SPLIT' => $mode == 'split_topic', 'SUBJECT' => $subject, 'TO_ID' => $new_topic_id)); // Setup the sort tool $topic_sort = \posts_overlord::build_sort(); $topic_sort->request(); $topic_sort->url_parameters = array('action' => $mode); // Display topic \posts_overlord::display_topic($topic, $topic_sort); \posts_overlord::assign_common(); add_form_key('split_topic'); } return $this->controller_helper->render('posting/split_merge_topic_body.html', $page_title); }
function main($id, $mode) { global $phpbb_root_path; define('PHPBB_INCLUDED', true); define('USE_PHPBB_TEMPLATE', true); define('IN_TITANIA', true); if (!defined('PHP_EXT')) { define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); } require TITANIA_ROOT . 'common.' . PHP_EXT; // Need a few hacks to be used from within phpBB titania_url::decode_url(titania::$config->phpbb_script_path); titania::$hook->register(array('titania_url', 'build_url'), 'titania_outside_build_url', 'standalone'); titania::$hook->register(array('titania_url', 'append_url'), 'titania_outside_build_url', 'standalone'); titania::$hook->register(array('titania', 'page_header'), 'titania_outside_page_header', 'standalone'); titania::$hook->register(array('titania', 'page_footer'), 'titania_outside_page_footer', 'standalone'); $this->p_master->assign_tpl_vars(phpbb::append_sid('ucp')); // Include some files titania::_include('functions_display', 'titania_topic_folder_img'); // Setup the sort tool $sort = new titania_sort(); $sort->default_limit = phpbb::$config['topics_per_page']; $sort->request(); // Start initial var setup $url = $this->u_action; add_form_key('ucp_front_subscription'); // User wants to unsubscribe? if (isset($_POST['unsubscribe'])) { if (check_form_key('ucp_front_subscription')) { $sections = request_var('sections', array(0 => array(0 => 0))); $items = request_var('items', array(0 => array(0 => 0))); $subscriptions = $sections + $items; if (sizeof($subscriptions)) { foreach ($subscriptions as $type => $type_id) { $object_ids = array_keys($type_id); foreach ($object_ids as $object_id) { $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . ' WHERE watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND watch_object_type = ' . $type . ' AND watch_object_id = ' . $object_id; phpbb::$db->sql_query($sql); } } } else { $msg = phpbb::$user->lang['NO_SUBSCRIPTIONS_SELECTED']; } } else { $msg = phpbb::$user->lang['FORM_INVALID']; } if (isset($msg)) { meta_refresh(3, $url); $message = $msg . '<br /><br />' . sprintf(phpbb::$user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>'); trigger_error($message); } } switch ($mode) { case 'subscription_items': $array_items = array(TITANIA_CONTRIB, TITANIA_TOPIC); // We prepare pagination stuff $sql = 'SELECT COUNT(*) AS subscription_count FROM ' . TITANIA_WATCH_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . ' AND watch_user_id = ' . phpbb::$user->data['user_id']; phpbb::$db->sql_query($sql); $subscription_count = phpbb::$db->sql_fetchfield('subscription_count'); phpbb::$db->sql_freeresult(); $sort->total = $subscription_count; $sort->build_pagination($url); $sql_ary = array('SELECT' => '*, CASE w.watch_object_type WHEN ' . TITANIA_CONTRIB . ' THEN c.contrib_last_update WHEN ' . TITANIA_TOPIC . ' THEN t.topic_last_post_time END AS time', 'FROM' => array(TITANIA_WATCH_TABLE => 'w'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => '(w.watch_object_type = ' . TITANIA_CONTRIB . ') AND c.contrib_id = w.watch_object_id'), array('FROM' => array(TITANIA_TOPICS_TABLE => 't'), 'ON' => 'w.watch_object_type = ' . TITANIA_TOPIC . ' AND t.topic_id = w.watch_object_id')), 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items), 'ORDER_BY' => 'time DESC'); // Additional tracking for support topics titania_tracking::get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id'); titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tsa'); titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tsc'); titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); // Tracking for contributions titania_tracking::get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id', 'tc'); $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $user_ids = $rows = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { $rows[] = $row; titania_tracking::store_from_db($row); if ($row['watch_object_type'] == TITANIA_TOPIC) { $user_ids[] = $row['topic_first_post_user_id']; $user_ids[] = $row['topic_last_post_user_id']; } else { if ($row['watch_object_type'] == TITANIA_CONTRIB) { $user_ids[] = $row['contrib_user_id']; } } } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); foreach ($rows as $row) { $folder_img = $folder_alt = ''; if ($row['watch_object_type'] == TITANIA_TOPIC) { if (!$row['topic_id']) { // Topic was deleted $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . ' WHERE watch_object_type = ' . (int) $row['watch_object_type'] . ' AND watch_object_id = ' . (int) $row['watch_object_id']; phpbb::$db->sql_query($sql); continue; } $topic = new titania_topic(); $topic->__set_array($row); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); $tpl_block = 'items'; $subscription_target = ''; if ($row['topic_type'] == TITANIA_QUEUE_DISCUSSION) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE_VALIDATION']; } if ($row['topic_type'] == TITANIA_QUEUE) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE']; } if ($row['topic_type'] == TITANIA_SUPPORT) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_SUPPORT_TOPIC']; } // Tracking check $last_read_mark = titania_tracking::get_track(TITANIA_TOPIC, $topic->topic_id, true); $last_read_mark = max($last_read_mark, titania_tracking::find_last_read_mark($topic->additional_unread_fields, $topic->topic_type, $topic->parent_id)); $topic->unread = $topic->topic_last_post_time > $last_read_mark ? true : false; // Get the folder image $topic->topic_folder_img($folder_img, $folder_alt); $vars = array('LAST_POST_IMG' => phpbb::$user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['topic_first_post_user_id'], '_full'), 'SUBSCRIPTION_ID' => $row['topic_id'], 'SUBSCRIPTION_LAST_AUTHOR_FULL' => users_overlord::get_user($row['topic_last_post_user_id'], '_full'), 'SUBSCRIPTION_LAST_TIME' => phpbb::$user->format_date($row['topic_last_post_time']), 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['topic_time']), 'SUBSCRIPTION_TARGET' => $subscription_target, 'SUBSCRIPTION_TITLE' => censor_text($row['topic_subject']), 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'U_VIEW_SUBSCRIPTION' => $topic->get_url(), 'U_VIEW_LAST_POST' => titania_url::append_url($topic->get_url(), array('p' => $topic->topic_last_post_id, '#p' => $topic->topic_last_post_id)), 'S_ACCESS_TEAMS' => $row['topic_access'] == TITANIA_ACCESS_TEAMS || $row['topic_type'] == TITANIA_QUEUE ? true : false, 'S_ACCESS_AUTHORS' => $row['topic_access'] == TITANIA_ACCESS_AUTHORS ? true : false, 'S_TOPIC' => true); } else { if ($row['watch_object_type'] == TITANIA_CONTRIB) { $tpl_block = 'items'; $contrib = new titania_contribution(); $contrib->__set_array($row); titania_topic_folder_img($folder_img, $folder_alt, 0, titania_tracking::is_unread(TITANIA_CONTRIB, $contrib->contrib_id, $contrib->contrib_last_update)); $vars = array('SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'), 'SUBSCRIPTION_CONTRIB_TYPE' => titania_types::$types[$contrib->contrib_type]->lang, 'SUBSCRIPTION_DOWNLOADS' => $row['contrib_downloads'], 'SUBSCRIPTION_ID' => $row['contrib_id'], 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_CONTRIB'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']), 'SUBSCRIPTION_TITLE' => $row['contrib_name'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'SUBSCRIPTION_VIEWS' => $row['contrib_views'], 'U_VIEW_SUBSCRIPTION' => $contrib->get_url(), 'S_CONTRIB' => true); } } phpbb::$template->assign_block_vars($tpl_block, array_merge($vars, array('FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'), 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'), 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height')))); } break; case 'subscription_sections': $array_items = array(TITANIA_SUPPORT, TITANIA_QUEUE, TITANIA_ATTENTION); // We prepare pagination stuff $sql = 'SELECT COUNT(*) AS subscription_count FROM ' . TITANIA_WATCH_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . ' AND watch_user_id = ' . phpbb::$user->data['user_id']; phpbb::$db->sql_query($sql); $subscription_count = phpbb::$db->sql_fetchfield('subscription_count'); phpbb::$db->sql_freeresult(); $sort->total = $subscription_count; $sort->build_pagination($url); $sql_ary = array('SELECT' => '*, CASE w.watch_object_type WHEN ' . TITANIA_SUPPORT . ' THEN c.contrib_last_update END AS time', 'FROM' => array(TITANIA_WATCH_TABLE => 'w'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => '(w.watch_object_type = ' . TITANIA_SUPPORT . ') AND c.contrib_id = w.watch_object_id')), 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items), 'ORDER_BY' => 'time DESC'); $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $user_ids = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { $rows[] = $row; $user_ids[] = $row['contrib_user_id']; } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); if (isset($rows)) { foreach ($rows as $row) { if ($row['watch_object_type'] == TITANIA_SUPPORT) { $tpl_block = 'sections'; $contrib = new titania_contribution(); $contrib->__set_array($row); $vars = array('SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'), 'SUBSCRIPTION_ID' => $row['watch_object_id'], 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_SUPPORT'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']), 'SUBSCRIPTION_TITLE' => $row['contrib_name'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'U_VIEW_SUBSCRIPTION' => $contrib->get_url('support')); } else { if ($row['watch_object_type'] == TITANIA_ATTENTION) { $tpl_block = 'sections'; $vars = array('SUBSCRIPTION_ID' => $row['watch_object_id'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_ATTENTION'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_ATTENTION' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => titania_url::build_url('manage/attention')); } else { if ($row['watch_object_type'] == TITANIA_QUEUE) { $tpl_block = 'sections'; $queue_id = $row['watch_object_id']; // Setup the base url we will use $base_url = titania_url::build_url('manage/queue'); $vars = array('SUBSCRIPTION_ID' => $queue_id, 'SUBSCRIPTION_TARGET' => titania_types::$types[$queue_id]->lang, 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_QUEUE'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_QUEUE' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => titania_url::append_url($base_url, array('queue' => titania_types::$types[$queue_id]->url))); } } } phpbb::$template->assign_block_vars($tpl_block, $vars); } } break; } phpbb::$template->assign_vars(array('S_ACTION' => $url, 'TITANIA_THEME_PATH' => titania::$absolute_path . 'styles/' . titania::$config->style . '/theme/')); titania::page_header(phpbb::$user->lang['SUBSCRIPTION_TITANIA']); titania::page_footer(true, 'manage/' . $mode . '.html'); }
/** * Get topic template row. * * @param array $row * @return array */ protected function get_topic_tpl_row($row) { $topic = new \titania_topic(); $topic->__set_array($row); $additional_unread_fields = array(array('type' => TITANIA_SUPPORT, 'id' => 0), array('type' => TITANIA_SUPPORT, 'parent_match' => true), array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true)); $topic->additional_unread_fields = array_merge($topic->additional_unread_fields, $additional_unread_fields); $subscription_target = ''; $type_lang = array(TITANIA_QUEUE_DISCUSSION => 'SUBSCRIPTION_QUEUE_VALIDATION', TITANIA_QUEUE => 'SUBSCRIPTION_QUEUE', TITANIA_SUPPORT => 'SUBSCRIPTION_SUPPORT_TOPIC'); if (isset($type_lang[$row['topic_type']])) { $subscription_target = $this->user->lang($type_lang[$row['topic_type']]); } // Tracking check $last_read_mark = $this->tracking->get_track(TITANIA_TOPIC, $topic->topic_id, true); $last_read_mark = max($last_read_mark, $this->tracking->find_last_read_mark($topic->additional_unread_fields, $topic->topic_type, $topic->parent_id)); $topic->unread = $topic->topic_last_post_time > $last_read_mark; // Get the folder image $topic->topic_folder_img($folder_img, $folder_alt); return array('FOLDER_STYLE' => $folder_img, 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'SUBSCRIPTION_AUTHOR_FULL' => \users_overlord::get_user($row['topic_first_post_user_id'], '_full'), 'SUBSCRIPTION_ID' => $row['topic_id'], 'SUBSCRIPTION_LAST_AUTHOR_FULL' => \users_overlord::get_user($row['topic_last_post_user_id'], '_full'), 'SUBSCRIPTION_LAST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'SUBSCRIPTION_TIME' => $this->user->format_date($row['topic_time']), 'SUBSCRIPTION_TARGET' => $subscription_target, 'SUBSCRIPTION_TITLE' => censor_text($row['topic_subject']), 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'U_VIEW_SUBSCRIPTION' => $this->get_real_url($topic->get_url()), 'U_VIEW_LAST_POST' => $this->get_real_url($topic->get_url(false, array('p' => $topic->topic_last_post_id, '#' => 'p' . $topic->topic_last_post_id))), 'S_ACCESS_TEAMS' => $row['topic_access'] == access::TEAM_LEVEL || $row['topic_type'] == TITANIA_QUEUE, 'S_ACCESS_AUTHORS' => $row['topic_access'] == access::AUTHOR_LEVEL, 'S_TOPIC' => true); }
public function move($new_status, \phpbb\titania\tags $tags) { $this->user->add_lang_ext('phpbb/titania', 'manage'); $from = $tags->get_tag_name($this->queue_status); $to = $tags->get_tag_name($new_status); $this->topic_reply(sprintf(phpbb::$user->lang['QUEUE_REPLY_MOVE'], $from, $to)); $this->queue_status = (int) $new_status; $this->queue_progress = 0; $this->queue_progress_time = 0; $this->submit(false); // Send notifications $contrib = contribs_overlord::get_contrib_object($this->contrib_id, true); $topic = new titania_topic(); $topic->load($this->queue_topic_id); $path_helper = phpbb::$container->get('path_helper'); $u_view_queue = $topic->get_url(false, array('tag' => $new_status)); $vars = array('CONTRIB_NAME' => $contrib->contrib_name, 'CATEGORY_NAME' => $to, 'U_VIEW_QUEUE' => $path_helper->strip_url_params($u_view_queue, 'sid')); $this->subscriptions->send_notifications(TITANIA_QUEUE_TAG, $new_status, 'new_contrib_queue_cat', $vars, phpbb::$user->data['user_id']); // Hooks titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $this); }
/** * Queue discussion topic redirect. * * @return Returns \Symfony\Component\HttpFoundation\Response if no * topic was found, otherwise redirects to topic. */ protected function queue_discussion() { $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . ' WHERE topic_type = ' . TITANIA_QUEUE_DISCUSSION . ' AND parent_id = ' . $this->contrib->contrib_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if ($row) { $topic = new \titania_topic(); $topic->__set_array($row); redirect($topic->get_url()); } return $this->helper->error('NO_QUEUE_DISCUSSION_TOPIC', 404); }
$page = basename(request_var('page', '')); // Add common lang titania::add_lang('contributions'); // Go to the queue discussion for this contribution item (saves us from having to figure out the URL to the topic every time we generate it) if ($page == 'queue_discussion') { load_contrib(); $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . ' WHERE topic_type = ' . TITANIA_QUEUE_DISCUSSION . ' AND parent_id = ' . titania::$contrib->contrib_id; $result = phpbb::$db->sql_query($sql); $row = phpbb::$db->sql_fetchrow($result); phpbb::$db->sql_freeresult($result); if ($row) { $topic = new titania_topic(); $topic->__set_array($row); redirect($topic->get_url()); } trigger_error('NO_QUEUE_DISCUSSION_TOPIC'); } // And now to load the appropriate page... switch ($page) { case 'faq': case 'support': case 'manage': case 'revision': case 'revision_edit': include TITANIA_ROOT . 'contributions/' . $page . '.' . PHP_EXT; break; case 'report': include TITANIA_ROOT . 'contributions/details.' . PHP_EXT; break;
/** * Display forum-like list for queue * * @param string $type The type of queue (the contrib type) * @param object|boolean $sort The sort object (includes/tools/sort.php) */ public static function display_queue($type, $queue_status = TITANIA_QUEUE_NEW, $sort = false) { if ($sort === false) { // Setup the sort tool $sort = self::build_sort(); } $sort->request(); $controller_helper = phpbb::$container->get('phpbb.titania.controller.helper'); $path_helper = phpbb::$container->get('path_helper'); $tracking = phpbb::$container->get('phpbb.titania.tracking'); $queue_ids = array(); $sql_ary = array('SELECT' => 'q.*, c.*, r.*, t.*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour, tp.topic_posted', 'FROM' => array(TITANIA_QUEUE_TABLE => 'q', TITANIA_CONTRIBS_TABLE => 'c', TITANIA_REVISIONS_TABLE => 'r', TITANIA_TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . (int) phpbb::$user->data['user_id'])), 'WHERE' => 'q.queue_type = ' . (int) $type . ($queue_status ? ' AND q.queue_status = ' . (int) $queue_status : ' AND q.queue_status > 0 ') . ' AND c.contrib_id = q.contrib_id AND r.revision_id = q.revision_id AND t.topic_id = q.queue_topic_id', 'ORDER_BY' => $sort->get_order_by()); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 't.topic_first_post_user_id = u.user_id'); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'ul'), 'ON' => 't.topic_last_post_user_id = ul.user_id'); $tracking->get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id'); // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 'q.queue_id')) { // No results...no need to query more... return; } $url_parts = $path_helper->get_url_parts($controller_helper->get_current_url()); $sort->build_pagination($url_parts['base'], $url_parts['params']); $queue_ids = $user_ids = array(); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); while ($row = phpbb::$db->sql_fetchrow($result)) { // Store the tracking info we grabbed from the DB $tracking->store_from_db($row); $queue_ids[] = $row['queue_id']; $user_ids[] = $row['topic_first_post_user_id']; $user_ids[] = $row['topic_last_post_user_id']; $user_ids[] = $row['submitter_user_id']; self::$queue[$row['queue_id']] = $row; } phpbb::$db->sql_freeresult($result); users_overlord::load_users($user_ids); $topic = new titania_topic(); foreach ($queue_ids as $queue_id) { $row = self::$queue[$queue_id]; $topic->__set_array($row); $topic->topic_posted = $row['topic_posted']; phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array('TOPIC_SUBJECT' => $row['contrib_name'] . ' - ' . $row['revision_version'], 'S_TOPIC_PROGRESS' => $row['queue_progress'] ? true : false, 'U_VIEW_TOPIC' => $topic->get_url(false, array('tag' => $queue_status)), 'S_TESTED' => $row['queue_tested'] ? true : false))); } unset($topic); phpbb::$template->assign_vars(array('S_TOPIC_LIST' => true)); // Assign common stuff for topics list topics_overlord::assign_common(); }
/** * Change the permalink to the contribution * Do not change it yourself, always use this function to do so * * @param string $new_permalink */ public function change_permalink($new_permalink) { $old_permalink = $this->contrib_name_clean; $new_permalink = titania_url::url_slug($new_permalink); if (!$this->validate_permalink($new_permalink)) { return false; } $this->contrib_name_clean = $new_permalink; // Attention items $sql = 'UPDATE ' . TITANIA_ATTENTION_TABLE . ' SET attention_url = \'' . phpbb::$db->sql_escape($this->get_url()) . '\' WHERE attention_object_type = ' . TITANIA_CONTRIB . ' AND attention_object_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); // Update the topics/posts under this $topic_ids = $post_ids = array(); $topic = new titania_topic(); $topic->topic_url = $this->get_url('support'); $sql = 'SELECT topic_id, topic_subject_clean FROM ' . TITANIA_TOPICS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('topic_type', array(TITANIA_SUPPORT, TITANIA_QUEUE_DISCUSSION)) . ' AND parent_id = ' . $this->contrib_id; $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $topic_ids[$row['topic_id']] = $row; } phpbb::$db->sql_freeresult($result); if (sizeof($topic_ids)) { $post = new titania_post(); $post->topic = $topic; $sql = 'SELECT * FROM ' . TITANIA_POSTS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('topic_id', array_map('intval', array_keys($topic_ids))); $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $topic->__set_array($topic_ids[$row['topic_id']]); $post->__set_array($row); $post->post_url = $topic->get_url(); $post_ids[$row['post_id']] = $post->post_url; // Need to reindex as well... $post->index(); // Update the posts table $sql = 'UPDATE ' . TITANIA_POSTS_TABLE . ' SET post_url = \'' . phpbb::$db->sql_escape($post->post_url) . '\' WHERE post_id = ' . $row['post_id']; phpbb::$db->sql_query($sql); } phpbb::$db->sql_freeresult($result); unset($topic, $post); // Update the topics table $sql = 'UPDATE ' . TITANIA_TOPICS_TABLE . ' SET topic_url = \'' . phpbb::$db->sql_escape($this->get_url('support')) . '\' WHERE ' . phpbb::$db->sql_in_set('topic_type', array(TITANIA_SUPPORT, TITANIA_QUEUE_DISCUSSION)) . ' AND parent_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); if (sizeof($post_ids)) { // On to attention items for posts $sql = 'SELECT attention_id, attention_object_id FROM ' . TITANIA_ATTENTION_TABLE . ' WHERE attention_object_type = ' . TITANIA_POST . ' AND ' . phpbb::$db->sql_in_set('attention_object_id', array_map('intval', array_keys($post_ids))); $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $sql = 'UPDATE ' . TITANIA_ATTENTION_TABLE . ' SET attention_url = \'' . phpbb::$db->sql_escape($post_ids[$row['attention_object_id']]) . '\' WHERE attention_id = ' . $row['attention_id']; phpbb::$db->sql_query($sql); } phpbb::$db->sql_freeresult($result); } } // Finally update the contrib_name_clean $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_name_clean = \'' . phpbb::$db->sql_escape($this->contrib_name_clean) . '\' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); }
/** * Display "forum" like section for support/tracker/etc * * @param string $type The type (support, review, queue, tracker, author_support, author_tracker) author_ for displaying posts from the areas the given author is involved in (either an author/co-author) * @param object|boolean $object The object (for contrib related (support, review, queue, tracker) and author_ modes) * @param object|boolean $sort The sort object (includes/tools/sort.php) * @param array $options Some special options * @param string $contrib_type The type of the support topic list */ public static function display_forums($type, $object = false, $sort = false, $options = array()) { if ($sort === false) { // Setup the sort tool $sort = self::build_sort(); } $sort->request(); $controller_helper = phpbb::$container->get('phpbb.titania.controller.helper'); $tracking = phpbb::$container->get('phpbb.titania.tracking'); $types = phpbb::$container->get('phpbb.titania.contribution.type.collection'); $topic_ids = array(); $switch_on_sticky = true; // Display the extra block after stickies end? Not used when not sorting with stickies first $sql_ary = array('SELECT' => 't.*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour, tp.topic_posted', 'FROM' => array(TITANIA_TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . (int) phpbb::$user->data['user_id'])), 'WHERE' => self::sql_permissions('t.', false, true), 'ORDER_BY' => 't.topic_sticky DESC, ' . $sort->get_order_by()); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 't.topic_first_post_user_id = u.user_id'); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'ul'), 'ON' => 't.topic_last_post_user_id = ul.user_id'); $tracking->get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id'); // Setup the contribution/topic we will use for parsing the output (before the switch so we are able to do type specific things for it) $topic = new titania_topic(); $contrib = new titania_contribution(); // type specific things switch ($type) { case 'tracker': $page_url = $object->get_url('tracker'); $sql_ary['WHERE'] .= ' AND t.parent_id = ' . (int) $object->contrib_id; $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_TRACKER; if (isset($options['category'])) { $sql_ary['WHERE'] .= ' AND t.topic_category = ' . (int) $options['category']; } break; case 'queue': $page_url = $controller_helper->route('phpbb.titania.queue'); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_QUEUE; break; case 'queue_discussion': $page_url = $controller_helper->route('phpbb.titania.queue_discussion.type', array('queue_type' => $types->get($options['topic_category'])->url)); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_QUEUE_DISCUSSION; // Only display those in which the users are authed $authed = $types->find_authed('queue_discussion'); if (!sizeof($authed)) { return compact('sort'); } if (isset($options['topic_category'])) { if (!in_array((int) $options['topic_category'], $authed)) { return compact('sort'); } $sql_ary['WHERE'] .= ' AND t.topic_category = ' . (int) $options['topic_category']; } else { $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.topic_category', $authed); } // Additional tracking for all queue discussion topics $tracking->get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); // Additional tracking for marking items as read in each contribution $tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tst'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); break; case 'author_support': $page_url = $object->get_url('support'); $contrib_ids = titania::$cache->get_author_contribs($object->user_id, $types, phpbb::$user, true); $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.parent_id', array_map('intval', $contrib_ids)); // We also display the queue discussion topic between validators and authors in the support area $sql_ary['WHERE'] .= ' AND (t.topic_type = ' . TITANIA_SUPPORT . ' OR t.topic_type = ' . TITANIA_QUEUE_DISCUSSION . ')'; // Do not display abandoned contribs in the author's support section $sql_ary['WHERE'] .= 'AND contrib.contrib_limited_support = 0'; // Additional tracking for marking items as read in each contribution $tracking->get_tracks(TITANIA_SUPPORT, $contrib_ids); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); // Additional tracking for all support topics $tracking->get_track_sql($sql_ary, TITANIA_ALL_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_ALL_SUPPORT, 'id' => 0); // Track the queue discussion too if applicable if ($types->find_authed('queue_discussion')) { $tracking->get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); } // Try to grab the category/contrib name $sql_ary['SELECT'] .= ', contrib.contrib_name, contrib.contrib_name_clean, contrib.contrib_id, contrib.contrib_type'; $sql_ary['LEFT_JOIN'] = array_merge(isset($sql_ary['LEFT_JOIN']) ? $sql_ary['LEFT_JOIN'] : array(), array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'contrib'), 'ON' => 'contrib.contrib_id = t.parent_id'))); // Do not order stickies first $sql_ary['ORDER_BY'] = $sort->get_order_by(); $switch_on_sticky = false; break; case 'author_tracker': $page_url = $object->get_url('tracker'); $contrib_ids = titania::$cache->get_author_contribs($object->user_id, $types, phpbb::$user); $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.parent_id', array_map('intval', $contrib_ids)); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_TRACKER; break; case 'all_support': // Try to grab the category/contrib name $sql_ary['SELECT'] .= ', contrib.contrib_name, contrib.contrib_name_clean, contrib.contrib_id, contrib.contrib_type'; $sql_ary['LEFT_JOIN'] = array_merge(isset($sql_ary['LEFT_JOIN']) ? $sql_ary['LEFT_JOIN'] : array(), array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'contrib'), 'ON' => 'contrib.contrib_id = t.parent_id'))); if (!phpbb::$auth->acl_get('u_titania_mod_post_mod')) { $mod_in_types = $types->find_authed('moderate'); $sql_ary['WHERE'] .= ' AND (' . phpbb::$db->sql_in_set('contrib.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . (sizeof($mod_in_types) ? ' OR ' . phpbb::$db->sql_in_set('contrib.contrib_type', $mod_in_types) : '') . ')'; } if ($types->exists($options['contrib_type'])) { $page_url = $controller_helper->route('phpbb.titania.support', array('type' => $types->get($options['contrib_type'])->url)); $sql_ary['WHERE'] .= ' AND contrib.contrib_type = ' . $options['contrib_type']; } else { $page_url = $controller_helper->route('phpbb.titania.support'); } // Additional tracking field (to allow marking all support/discussion as read) $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_SUPPORT; $tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 'contrib.contrib_id', 'tst'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); // Additional tracking for all support topics $tracking->get_track_sql($sql_ary, TITANIA_ALL_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_ALL_SUPPORT, 'id' => 0); // Do not order stickies first $sql_ary['ORDER_BY'] = $sort->get_order_by(); $switch_on_sticky = false; break; case 'support': default: $page_url = $object->get_url('support'); $sql_ary['WHERE'] .= ' AND t.parent_id = ' . (int) $object->contrib_id; // We also display the queue discussion topic between validators and authors in the support area if ($object->is_author || $object->is_active_coauthor || $object->type->acl_get('queue_discussion')) { $sql_ary['WHERE'] .= ' AND (t.topic_type = ' . TITANIA_SUPPORT . ' OR t.topic_type = ' . TITANIA_QUEUE_DISCUSSION . ')'; } else { $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_SUPPORT; } // Additional tracking for marking items as read in each contribution $tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, $object->contrib_id, 'tst'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); // Additional tracking for all support topics $tracking->get_track_sql($sql_ary, TITANIA_ALL_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_ALL_SUPPORT, 'id' => 0); // Track the queue discussion too if applicable if ($object->type->acl_get('queue_discussion')) { $tracking->get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); } break; } // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 't.topic_id')) { // No results...no need to query more... return compact('sort'); } $sort->build_pagination($page_url); $last_was_sticky = false; phpbb::$template->assign_var('S_SPLIT_BY_TOPIC_TYPE', $switch_on_sticky); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); while ($row = phpbb::$db->sql_fetchrow($result)) { // Store the tracking info we grabbed from the DB $tracking->store_from_db($row); self::$topics[$row['topic_id']] = $row; $topic->__set_array($row); $contrib->__set_array($row); if (!empty($row['contrib_type'])) { $contrib->set_type($row['contrib_type']); } $topic->topic_posted = $row['topic_posted']; phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array('S_TOPIC_TYPE_SWITCH' => $switch_on_sticky && $last_was_sticky && !$topic->topic_sticky ? true : false, 'CONTRIB_TYPE' => isset($row['contrib_type']) && $row['contrib_type'] ? $types->get($row['contrib_type'])->lang : '', 'TOPIC_CONTRIB_NAME' => isset($row['contrib_name']) && $row['contrib_name'] ? censor_text($row['contrib_name']) : '', 'U_VIEW_TOPIC_CONTRIB' => isset($row['contrib_type']) && $row['contrib_type'] ? $contrib->get_url() : '', 'U_VIEW_TOPIC_CONTRIB_SUPPORT' => isset($row['contrib_type']) && $row['contrib_type'] ? $contrib->get_url('support') : ''))); $sort = phpbb::$container->get('phpbb.titania.sort'); $sort->__set_array(array('template_block' => 'topics.pagination', 'total' => $topic->get_postcount(), 'limit' => phpbb::$config['posts_per_page'])); $sort->set_defaults(phpbb::$config['posts_per_page']); $sort->build_pagination($topic->get_url()); $last_was_sticky = $topic->topic_sticky; } phpbb::$db->sql_freeresult($result); unset($topic); return compact('sort'); }