/** * Common posting stuff for post/reply/edit * * @param string $mode * @param \titania_post $post * @return JsonResponse|RedirectResponse|Response|null */ protected function common_post($mode, $post) { $this->user->add_lang('posting'); // Submit check...handles running $post->post_data() if required $submit = $this->message->submit_check(); $is_reply = $mode == 'edit' || $mode == 'reply'; $post_attachments = $this->message->has_attachments(); // Ensure that post_attachment remains valid when the user doesn't submit the post after deleting all attachments if ($mode == 'edit' && $post->post_attachment && empty($post_attachments)) { $sql = 'UPDATE ' . TITANIA_POSTS_TABLE . ' SET post_attachment = 0 WHERE post_id = ' . (int) $post->post_id; $this->db->sql_query($sql); } if ($this->message->is_plupload_request()) { return new JsonResponse($this->message->get_plupload_response_data()); } if ($submit) { $error = $post->validate(); if (($validate_form_key = $this->message->validate_form_key()) !== false) { $error[] = $validate_form_key; } // @todo use permissions for captcha if (!$this->user->data['is_registered'] && ($validate_captcha = $this->message->validate_captcha()) !== false) { $error[] = $validate_captcha; } $error = array_merge($error, $this->message->error); if (sizeof($error)) { $this->template->assign_var('ERROR', implode('<br />', $error)); } else { // Force Queue Discussion topics to always be stickies if ($post->post_type == TITANIA_QUEUE_DISCUSSION) { $post->topic->topic_sticky = true; } // Does the post need approval? Never for the Queue Discussion or Queue. Do not set again in edit mode, otherwise this causes problems when the post has been approved. if (!$this->auth->acl_get('u_titania_post_approved') && $post->post_type != TITANIA_QUEUE_DISCUSSION && $post->post_type != TITANIA_QUEUE && $mode != 'edit') { $post->post_approved = false; } $post->post_attachment = !empty($post_attachments); $post->parent_contrib_type = $this->parent_type; $post->submit(); $this->message->submit($post->post_access); // Did they want to subscribe? if ($this->request->is_set_post('notify') && $this->user->data['is_registered']) { $this->subscriptions->subscribe(TITANIA_TOPIC, $post->topic->topic_id); } // Unapproved posts will get a notice if (!$post->topic->get_postcount()) { return $this->controller_helper->message($this->user->lang['POST_STORED_MOD'] . '<br /><br />' . $this->user->lang('RETURN_INDEX', '<a href="' . $post->topic->get_parent_url() . '">', '</a>')); } else { if (!$post->post_approved) { return $this->controller_helper->message($this->user->lang['POST_STORED_MOD'] . '<br /><br />' . $this->user->lang('RETURN_TOPIC', '<a href="' . $post->topic->get_url() . '">', '</a>')); } else { // Send out subscription notifications if ($mode == 'post' || $mode == 'reply') { $this->send_notifications($post, $mode); } } } return new RedirectResponse($post->get_url()); } } else { if (!empty($this->message->error)) { $this->template->assign_var('ERROR', implode('<br />', $this->message->error)); } } // Do we subscribe to actual topic? $is_subscribed = $is_reply && $this->subscriptions->is_subscribed(TITANIA_TOPIC, $post->topic->topic_id); $can_subscribe = $this->user->data['is_registered'] && !$is_subscribed; $this->template->assign_vars(array('S_NOTIFY_ALLOWED' => $can_subscribe, 'S_NOTIFY_CHECKED' => $can_subscribe && $this->user->data['user_notify'] && $post->post_type == TITANIA_SUPPORT ? ' checked=checked' : '')); $topic_access_level = access::PUBLIC_LEVEL; if ($is_reply) { // If this is the first post, we'll allow lowering the access level, otherwise the topic access level is the minimum that can be set $topic_access_level = $post->post_id == $post->topic->topic_first_post_id ? access::PUBLIC_LEVEL : $post->topic->topic_access; } $this->message->display($topic_access_level); }
/** * Get the queue discussion topic or create one if needed * * @param bool $check_only Return false if topic does not exist instead of creating it * * @return titania_topic object */ public function get_queue_discussion_topic($check_only = false) { $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . ' WHERE parent_id = ' . $this->contrib_id . ' AND topic_type = ' . TITANIA_QUEUE_DISCUSSION; $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); $this->queue_discussion_topic_id = $topic->topic_id; return $topic; } else { if ($check_only) { return false; } } // No queue discussion topic...so we must create one $this->user->add_lang_ext('phpbb/titania', 'posting'); $contrib = contribs_overlord::get_contrib_object($this->contrib_id, true); $post = new titania_post(TITANIA_QUEUE_DISCUSSION); $post->topic->__set_array(array('parent_id' => $this->contrib_id, 'topic_category' => $contrib->contrib_type, 'topic_url' => serialize(array('contrib_type' => $contrib->type->url, 'contrib' => $contrib->contrib_name_clean)), 'topic_sticky' => true)); $post->__set_array(array('post_access' => access::AUTHOR_LEVEL, 'post_subject' => sprintf(phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_TITLE'], $contrib->contrib_name), 'post_text' => phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_MESSAGE'])); $post->generate_text_for_storage(true, true, true); $post->submit(); $this->queue_discussion_topic_id = $post->topic->topic_id; return $post->topic; }
function titania_move_topic($topic_id, $topic, $topic_type, $contrib_name = '', $revision_version = '') { $post = false; // Convert the topics over from the phpBB forums if ($topic_id) { $sql = 'SELECT * FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int) $topic_id . ' ORDER BY post_id ASC'; $post_result = phpbb::$db->sql_query($sql); while ($post_row = phpbb::$db->sql_fetchrow($post_result)) { $post = new titania_post($topic_type, $topic); // Rewrite some URLs $contrib_view = 'http://www.phpbb.com/customise/db/contribution/$1/'; $contrib_view_full = '<a class="postlink" href="' . $contrib_view . '">' . $contrib_view . '</a>'; // Rewrite the full URLs $replace = array('#<a class="postlink" href="http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=queue&mode=overview&contrib_id=([0-9]+)">.+</a>#', '#<a class="postlink" href="http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=misc&mode=display&contrib_id=([0-9]+)">.+</a>#'); $post_row['post_text'] = preg_replace($replace, $contrib_view_full, $post_row['post_text']); // Rewrite the unparsed URLs $replace = array('#http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=queue&mode=overview&contrib_id=([0-9]+)#', '#http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=misc&mode=display&contrib_id=([0-9]+)#'); $post_row['post_text'] = preg_replace($replace, $contrib_view, $post_row['post_text']); // Rewrite the download URLs $replace = array('#<a class="postlink" href="http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/download/([0-9]+)/?">(.+)</a>#', '#<a class="postlink" href="http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=misc&mode=display&download=1&contrib_id=([0-9]+)">(.+)</a>#'); $post_row['post_text'] = preg_replace($replace, '<a class="postlink" href="http://www.phpbb.com/customise/db/download/contrib_$1">$2</a>', $post_row['post_text']); $replace = array('#http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/download/([0-9]+)/?"#', '#http(?:\\:|&\\#58;)//www(?:\\.|&\\#46;)phpbb(?:\\.|&\\#46;)com/(?:styles|mods)/db/index(?:\\.|&\\#46;)php\\?i=misc&mode=display&download=1&contrib_id=([0-9]+)#'); $post_row['post_text'] = preg_replace($replace, 'http://www.phpbb.com/customise/db/download/contrib_$1', $post_row['post_text']); // Remove selected tags stuff (they are completely useless with Titania) $replace = "#\n\\[b:[a-z0-9]+\\]Selected tags:\\[/b:[a-z0-9]+\\]\n\\[list.+\\]\\[/list:o:[a-z0-9]+\\]\n#"; $post_row['post_text'] = preg_replace($replace, '', $post_row['post_text']); $post_row['post_text'] = str_replace("===INT===", '', $post_row['post_text']); $post->__set_array(array('post_access' => $topic_type == TITANIA_QUEUE ? TITANIA_ACCESS_TEAMS : TITANIA_ACCESS_AUTHORS, 'post_user_id' => $post_row['poster_id'], 'post_ip' => $post_row['poster_ip'], 'post_time' => $post_row['post_time'], 'post_subject' => $post_row['post_subject'], 'post_text' => $post_row['post_text'], 'post_text_bitfield' => $post_row['bbcode_bitfield'], 'post_text_uid' => $post_row['bbcode_uid'], 'post_text_options' => ($post_row['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($post_row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($post_row['enable_magic_url'] ? OPTION_FLAG_LINKS : 0))); if ($topic_type == TITANIA_QUEUE_DISCUSSION) { $post->topic->topic_sticky = true; } $post->submit(); } phpbb::$db->sql_freeresult($post_result); } // We didn't convert any posts? (Local install perhaps?) if ($post === false && $contrib_name) { $post = new titania_post($topic_type, $topic); $post->__set_array(array('post_access' => TITANIA_ACCESS_TEAMS, 'post_subject' => phpbb::$user->lang['VALIDATION'] . ' - ' . $contrib_name . ' - ' . $revision_version, 'post_text' => 'Converted from Ariel')); switch ($post->topic->topic_category) { case TITANIA_TYPE_MOD: $post->post_user_id = titania::$config->forum_mod_robot; break; case TITANIA_TYPE_STYLE: $post->post_user_id = titania::$config->forum_style_robot; break; } $post->submit(); } }
$topic = $queue->get_queue_discussion_topic(); $post = new titania_post(TITANIA_QUEUE_DISCUSSION, $topic); $post->__set_array(array('post_subject' => 'Re: ' . $post->topic->topic_subject)); // Load the message object $message_object = new titania_message($post); $message_object->set_auth(array('bbcode' => true, 'smilies' => true)); $message_object->set_settings(array('display_subject' => false)); // Submit check...handles running $post->post_data() if required $submit = $message_object->submit_check(); if ($submit) { $queue->allow_author_repack = true; $contrib = contribs_overlord::get_contrib_object($queue->contrib_id, true); $for_edit = $post->generate_text_for_edit(); $post->post_text = $for_edit['message'] . "\n\n[url=" . titania_url::append_url($contrib->get_url('revision'), array('repack' => $queue->revision_id)) . ']' . phpbb::$user->lang['AUTHOR_REPACK_LINK'] . '[/url]'; $post->generate_text_for_storage($for_edit['allow_bbcode'], $for_edit['allow_smilies'], $for_edit['allow_urls']); $post->submit(); $queue->submit(); $queue->topic_reply('QUEUE_REPLY_ALLOW_REPACK'); $queue->submit(); redirect(titania_url::append_url($base_url, array('q' => $queue->queue_id))); } $message_object->display(); // Common stuff phpbb::$template->assign_vars(array('S_POST_ACTION' => titania_url::$current_page_url, 'L_POST_A' => phpbb::$user->lang['DISCUSSION_REPLY_MESSAGE'])); titania::page_header('DISCUSSION_REPLY_MESSAGE'); titania::page_footer(true, 'manage/queue_post.html'); break; case 'move': $queue = queue_overlord::get_queue_object($queue_id, true); $tags = titania::$cache->get_tags(TITANIA_QUEUE); if (check_link_hash(request_var('hash', ''), 'quick_actions') || titania::confirm_box(true)) {
/** * Get the queue discussion topic or create one if needed * * @return titania_topic object */ public function get_queue_discussion_topic() { $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . ' WHERE parent_id = ' . $this->contrib_id . ' AND topic_type = ' . TITANIA_QUEUE_DISCUSSION; $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); return $topic; } // No queue discussion topic...so we must create one titania::add_lang('posting'); $contrib = contribs_overlord::get_contrib_object($this->contrib_id, true); $post = new titania_post(TITANIA_QUEUE_DISCUSSION); $post->topic->__set_array(array('parent_id' => $this->contrib_id, 'topic_category' => $contrib->contrib_type, 'topic_url' => titania_types::$types[$contrib->contrib_type]->url . '/' . $contrib->contrib_name_clean . '/support/', 'topic_sticky' => true)); $post->__set_array(array('post_access' => TITANIA_ACCESS_AUTHORS, 'post_subject' => sprintf(phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_TITLE'], $contrib->contrib_name), 'post_text' => phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_MESSAGE'])); $post->generate_text_for_storage(true, true, true); $post->submit(); return $post->topic; }