/** * A hook that is used to change the behavior of phpBB just before the templates * are displayed. * @param phpbb_hook $phpbb_hook The phpBB hook object * @return void * @todo Clean up, kinda messy this :/ */ public static function subject_prefix_template_hook(&$hook) { switch (sp_phpbb::$user->page['page_name']) { // Add the prefix dropdown to the posting page case 'posting.' . PHP_EXT: global $forum_id, $post_id, $topic_id; global $mode, $preview; // Must habs perms if (sp_phpbb::$auth->acl_get('!f_subject_prefix', $forum_id)) { return; } $pid = request_var('subjectprefix', 0); // When editing we only pass this point when the *first* post is edited $selected = false; $sql = 'SELECT subject_prefix_id FROM ' . TOPICS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\tAND topic_first_post_id = {$post_id}"; $result = sp_phpbb::$db->sql_query($sql); $selected = sp_phpbb::$db->sql_fetchfield('subject_prefix_id', false, $result); sp_phpbb::$db->sql_freeresult($result); // If submitted, change the selected prefix here if (isset($_POST['post'])) { global $data; switch ($mode) { case 'edit': if ($selected === false) { return; } // No Break; // No Break; case 'post': // Validate that this prefix can be used here $tree = $forums = array(); sp_phpbb::$cache->obtain_prefix_forum_tree($tree, $forums); if (!isset($tree[$forum_id][$pid]) && $pid > 0) { trigger_error('PREFIX_NOT_ALLOWED'); } // Only have to add the prefix $sql = 'UPDATE ' . TOPICS_TABLE . ' SET subject_prefix_id = ' . $pid . ' WHERE topic_id = ' . $data['topic_id']; sp_phpbb::$db->sql_query($sql); // Done :) return; break; } } else { // Set the correct prefix when previewing if (!empty($preview)) { $selected = $pid; } switch ($mode) { case 'edit': if ($selected === false) { // Nope return; } // No Break; // No Break; case 'post': sp_phpbb::$template->assign_vars(array('S_SUBJECT_PREFIX_OPTIONS' => sp_core::generate_prefix_options($forum_id, $selected))); break; } } break; } }
/** * Reorder the prefixes * @return void */ private function qa_move() { $direction = $_GET['direction'] == 'down' ? 'down' : 'up'; $fid = request_var('f', 0); $order = request_var('prefix_order', 0); sp_core::prefix_reorder($fid, $order, $direction); }