/**
  * Common handler for add/edit action.
  *
  * @param \titania_category	Category object.
  * @param bool|array			Old settings
  * @return bool Returns true if category was submitted.
  */
 protected function common_post($category, $old_settings = false)
 {
     $this->message->set_parent($category)->set_auth(array('bbcode' => $this->auth->acl_get('u_titania_bbcode'), 'smilies' => $this->auth->acl_get('u_titania_smilies')))->set_settings(array('display_error' => false, 'display_subject' => false));
     $category->post_data($this->message);
     $error = array();
     if ($this->request->is_set_post('submit')) {
         $category = $this->set_submitted_settings($category);
         if (!empty($old_settings) && $category->category_name == $old_settings['name_lang']) {
             $category->category_name = $old_settings['name'];
         }
         $error = $category->validate();
         if (($form_error = $this->message->validate_form_key()) !== false) {
             $error[] = $form_error;
         }
         if (empty($error)) {
             $error = $this->submit($category, $old_settings);
             if (empty($error)) {
                 return true;
             }
         }
     }
     // Generate data for category type dropdown box
     $this->display->generate_type_select($category->category_type);
     $this->message->display();
     $this->template->assign_vars(array('ERROR_MSG' => !empty($error) ? implode('<br />', $error) : '', 'CATEGORY' => $category->category_id, 'CATEGORY_NAME' => $category->get_name(), 'CATEGORY_NAME_CLEAN' => $category->category_name_clean, 'CATEGORY_VISIBLE' => $category->category_visible, 'S_MOVE_CATEGORY_OPTIONS' => $this->display->generate_category_select($category->parent_id, true, false)));
     foreach ($category->available_options as $option => $flag) {
         if ($category->is_option_set($option)) {
             $this->template->assign_var(strtoupper("s_{$option}"), 'checked="checked"');
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * Common handler for edit/create action.
  *
  * @return bool|JsonResponse Returns true if item was submitted.
  */
 protected function common_post()
 {
     // Load the message object
     $this->message->set_parent($this->faq)->set_auth(array('bbcode' => $this->auth->acl_get('u_titania_bbcode'), 'smilies' => $this->auth->acl_get('u_titania_smilies'), 'attachments' => true));
     // Submit check...handles running $this->faq->post_data() if required
     $submit = $this->message->submit_check();
     $error = $this->message->error;
     if ($this->message->is_plupload_request()) {
         return new JsonResponse($this->message->get_plupload_response_data());
     }
     if ($submit) {
         $error = array_merge($error, $this->faq->validate());
         if (($validate_form_key = $this->message->validate_form_key()) !== false) {
             $error[] = $validate_form_key;
         }
         if (empty($error)) {
             $this->faq->submit();
             $this->message->submit($this->id);
             return true;
         }
     }
     $this->template->assign_vars(array('S_EDIT' => true, 'ERROR_MSG' => !empty($error) ? implode('<br />', $error) : false));
     $this->message->display();
     return false;
 }
Exemple #3
0
 /**
  * Display author management page.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function manage()
 {
     if (!$this->is_owner && !$this->auth->acl_get('u_titania_mod_author_mod')) {
         return $this->helper->needs_auth();
     }
     $error = array();
     $this->message->set_parent($this->author)->set_auth(array('bbcode' => $this->auth->acl_get('u_titania_bbcode'), 'smilies' => $this->auth->acl_get('u_titania_smilies')))->set_settings(array('display_error' => false, 'display_subject' => false));
     if ($this->request->is_set_post('submit')) {
         $this->author->post_data($this->message);
         $this->author->__set_array(array('author_realname' => $this->request->variable('realname', '', true), 'author_website' => $this->request->variable('website', '')));
         $error = $this->author->validate();
         if (($validate_form_key = $this->message->validate_form_key()) !== false) {
             $error[] = $validate_form_key;
         }
         if (empty($error)) {
             $this->author->submit();
             redirect($this->author->get_url());
         }
     }
     $this->message->display();
     $this->template->assign_vars(array('S_POST_ACTION' => $this->author->get_url('manage'), 'AUTHOR_WEBSITE' => $this->author->get_website_url() || !$this->is_owner ? $this->author->get_website_url() : '', 'ERROR_MSG' => !empty($error) ? implode('<br />', $error) : false));
     return $this->helper->render('authors/author_manage.html', $this->get_title('MANAGE_AUTHOR'));
 }
Exemple #4
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);
    }
Exemple #5
0
 /**
  * Manage contribution.
  *
  * @param string $contrib_type		Contrib type URL identifier.
  * @param string $contrib			Contrib name clean.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function manage($contrib_type, $contrib)
 {
     $this->setup($contrib_type, $contrib);
     if (!$this->check_auth()) {
         return $this->helper->needs_auth();
     }
     $this->load_screenshot();
     if ($this->screenshots->plupload_active()) {
         return new JsonResponse($this->screenshots->get_plupload_response_data());
     }
     if (confirm_box(true) && $this->check_auth('change_author')) {
         $this->change_author();
     }
     $old_settings = $this->contrib->__get_array();
     $old_settings['categories'] = array_keys($this->contrib->category_data);
     $this->settings = array('permalink' => $this->request->variable('permalink', $this->contrib->contrib_name_clean, true), 'status' => $this->request->variable('contrib_status', (int) $this->contrib->contrib_status), 'categories' => $old_settings['categories'], 'demo' => array(), 'coauthors' => array('active' => $this->request->variable('active_coauthors', '', true), 'nonactive' => $this->request->variable('nonactive_coauthors', '', true)), 'new_author' => $this->request->variable('change_owner', '', true), 'limited_support' => $this->contrib->contrib_limited_support);
     $this->settings['custom'] = $this->contrib->get_custom_fields();
     foreach ($this->contrib->type->get_allowed_branches(true) as $branch => $name) {
         $this->settings['demo'][$branch] = $this->contrib->get_demo_url($branch);
     }
     $this->load_message();
     $submit = $this->request->is_set_post('submit');
     $preview = $this->request->is_set_post('preview');
     $error = $this->screenshots->get_errors();
     if ($preview || $submit || $this->screenshots->uploaded) {
         $this->settings = array_merge($this->settings, array('categories' => $this->request->variable('contrib_category', array(0 => 0)), 'custom' => $this->request->variable('custom_fields', array('' => ''), true), 'limited_support' => $this->request->is_set('limited_support')));
         $demos = $this->request->variable('demo', array(0 => ''));
         foreach ($this->contrib->type->get_allowed_branches(true) as $branch => $name) {
             if (isset($demos[$branch])) {
                 $this->settings['demo'][$branch] = $demos[$branch];
             }
         }
         $this->contrib->post_data($this->message);
         $this->contrib->__set_array(array('contrib_demo' => $this->can_edit_demo ? json_encode($this->settings['demo']) : $this->contrib->contrib_demo, 'contrib_limited_support' => $this->settings['limited_support']));
     }
     // ColorizeIt sample
     if ($this->use_colorizeit) {
         $this->load_colorizeit();
         $error = array_merge($error, $this->colorizeit_sample->get_errors());
         if ($this->colorizeit_sample->uploaded) {
             $this->contrib->post_data($this->message);
         }
     }
     $this->handle_screenshot_action();
     if ($preview) {
         $this->preview();
     } else {
         if ($submit) {
             if (($form_key_error = $this->message->validate_form_key()) !== false) {
                 $error[] = $form_key_error;
             } else {
                 if ($this->request->is_set_post('delete') && $this->check_auth('delete')) {
                     // Handle the deletion routine
                     $this->contrib->delete();
                     redirect($this->helper->route('phpbb.titania.index'));
                 }
             }
             $this->contrib->post_data($this->message);
             $authors = $this->contrib->get_authors_from_usernames(array('active_coauthors' => $this->settings['coauthors']['active'], 'nonactive_coauthors' => $this->settings['coauthors']['nonactive'], 'new_author' => $this->settings['new_author']));
             $author_username = \users_overlord::get_user($this->contrib->contrib_user_id, 'username', true);
             $authors['author'] = array($author_username => $this->contrib->contrib_user_id);
             $error = array_merge($error, $this->contrib->validate($this->settings['categories'], $authors, $this->settings['custom'], $this->contrib->contrib_name_clean));
             // Did we succeed or have an error?
             if (empty($error)) {
                 $this->submit($authors, $old_settings);
             }
         }
     }
     $this->assign_vars($error);
     return $this->helper->render('contributions/contribution_manage.html', $this->contrib->contrib_name . ' - ' . $this->user->lang['MANAGE_CONTRIBUTION']);
 }