예제 #1
0
 /**
  * Check whether the author is subscribed to the queue discussion topic.
  *
  * @return bool
  */
 protected function is_author_subscribed()
 {
     if ($this->use_queue) {
         $this->queue->contrib_id = $this->contrib->contrib_id;
         // Get queue discussion topic id if it exists
         $this->queue->get_queue_discussion_topic(true);
         if (!empty($this->queue->queue_discussion_topic_id)) {
             // Is the author subscribed already?
             return $this->subscriptions->is_subscribed(TITANIA_TOPIC, $this->queue->queue_discussion_topic_id);
         }
     }
     return false;
 }
예제 #2
0
    /**
     * 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);
    }