Exemplo n.º 1
0
 /**
  * Display new contribution page.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function create()
 {
     if (!$this->is_owner && !$this->auth->acl_get('u_titania_contrib_submit')) {
         return $this->helper->needs_auth();
     }
     $this->user->add_lang_ext('phpbb/titania', 'contributions');
     $contrib = new \titania_contribution();
     $contrib->contrib_user_id = $this->user->data['user_id'];
     $contrib->author = $this->author;
     $contrib->get_options();
     // Set some main vars up
     $message = $this->setup_message($contrib);
     $submit = $this->request->is_set_post('submit');
     $preview = $this->request->is_set_post('preview');
     $error = array();
     $settings = array('type' => $this->request->variable('contrib_type', 0), 'permalink' => $this->request->variable('permalink', '', true), 'categories' => $this->request->variable('contrib_category', array(0)), 'coauthors' => array('active' => $this->request->variable('active_coauthors', '', true), 'nonactive' => $this->request->variable('nonactive_coauthors', '', true)), 'custom' => $this->request->variable('custom_fields', array('' => ''), true));
     if ($preview || $submit) {
         $contrib->post_data($message);
         $contrib->__set_array(array('contrib_type' => $settings['type'], 'contrib_name_clean' => $settings['permalink'], 'contrib_visible' => 1));
     }
     if ($preview) {
         $message->preview();
     } else {
         if ($submit) {
             $authors = $contrib->get_authors_from_usernames(array('active_coauthors' => $settings['coauthors']['active'], 'nonactive_coauthors' => $settings['coauthors']['nonactive']));
             $authors['author'] = array($this->user->data['username'] => $this->user->data['user_id']);
             $error = $contrib->validate($settings['categories'], $authors, $settings['custom']);
             if (($form_key_error = $message->validate_form_key()) !== false) {
                 $error[] = $form_key_error;
             }
             if (empty($error)) {
                 $contrib->set_type($contrib->contrib_type);
                 $contrib->set_custom_fields($settings['custom']);
                 $contrib->contrib_categories = implode(',', $settings['categories']);
                 $contrib->contrib_creation_time = time();
                 $contrib->submit();
                 $contrib->set_coauthors($authors['active_coauthors'], $authors['nonactive_coauthors'], true);
                 // Create relations
                 $contrib->put_contrib_in_categories($settings['categories']);
                 if ($this->ext_config->support_in_titania) {
                     $active_authors = array_merge($authors['author'], $authors['active_coauthors']);
                     foreach ($active_authors as $author) {
                         $this->subscriptions->subscribe(TITANIA_SUPPORT, $contrib->contrib_id, $author);
                     }
                 }
                 redirect($contrib->get_url('revision'));
             }
         }
     }
     // Generate some stuff
     $this->display->generate_type_select($contrib->contrib_type);
     $this->display->generate_category_select($settings['categories']);
     $contrib->assign_details();
     $message->display();
     foreach ($this->types->get_all() as $type) {
         $this->display->generate_custom_fields($type->contribution_fields, $settings['custom'], $type->id);
     }
     $this->template->assign_vars(array('S_POST_ACTION' => $this->author->get_url('create'), 'S_CREATE' => true, 'S_CAN_EDIT_CONTRIB' => $this->auth->acl_get('u_titania_contrib_submit'), 'CONTRIB_PERMALINK' => $settings['permalink'], 'ERROR_MSG' => !empty($error) ? implode('<br />', $error) : false, 'ACTIVE_COAUTHORS' => $settings['coauthors']['active'], 'NONACTIVE_COAUTHORS' => $settings['coauthors']['nonactive']));
     return $this->helper->render('contributions/contribution_manage.html', 'NEW_CONTRIBUTION');
 }
Exemplo n.º 2
0
 /**
  * Subscribe new coauthors to contrib support section.
  *
  * @param array $old_coauthors		Value of contrib's "coauthors" property
  * @param array $new_coauthors		Array of new active coauthors
  */
 protected function subscribe_new_coauthors(array $old_coauthors, array $new_coauthors)
 {
     $old_active = array();
     foreach ($old_coauthors as $id => $data) {
         if ($data['active']) {
             $old_active[] = (int) $id;
         }
     }
     $subscribe = array_diff($new_coauthors, $old_active);
     foreach ($subscribe as $user_id) {
         $this->subscriptions->subscribe(TITANIA_SUPPORT, $this->contrib->contrib_id, $user_id);
     }
 }
Exemplo n.º 3
0
 /**
  * Handle initial revision, queue, and attachment creation.
  *
  * @return array Returns array in form for array('error' => array())
  *	where error contains any errors found.
  */
 protected function create()
 {
     if ($this->request->variable('disagree', false)) {
         // Did not agree to the agreement.
         redirect($this->contrib->get_url());
     }
     // Handle upload
     $this->uploader->handle_form_action();
     if ($this->uploader->uploaded) {
         $uploaded = $this->uploader->get_operator()->get_all_ids();
         // If multiple files are uploaded, then one is being replaced.
         if (sizeof($uploaded) > 1) {
             $this->uploader->get_operator()->delete(array_diff($uploaded, array($this->uploader->uploaded)));
         }
         $this->attachment = $this->uploader->get_uploaded_attachment();
     }
     if ($this->uploader->plupload_active()) {
         return array('response' => new JsonResponse($this->uploader->get_plupload_response_data()));
     } else {
         if ($this->request->is_set('attachment_data')) {
             $data = $this->uploader->get_filtered_request_data();
             if (!empty($data)) {
                 $attachment = array_shift($data);
                 $this->load_attachment($attachment['attach_id']);
             }
         }
     }
     $settings = array('version' => $this->request->variable('revision_version', '', true), 'name' => $this->request->variable('revision_name', '', true), 'allow_repack' => $this->request->variable('queue_allow_repack', 0), 'license' => $this->request->variable('revision_license', '', true), 'custom' => $this->request->variable('custom_fields', array('' => ''), true), 'vendor_versions' => $this->get_selected_branches(), 'test_account' => $this->request->variable('revision_test_account', '', true));
     if ($this->has_custom_license($settings['license'])) {
         $settings['license'] = $this->request->variable('revision_custom_license', '', true);
     }
     // Check for errors
     $error = array_merge($this->uploader->get_errors(), $this->validate_settings($settings));
     if (empty($error)) {
         $this->create_revision($settings);
         // Add queue values to the queue table
         if ($this->use_queue) {
             $this->create_queue_item($settings['allow_repack'], $settings['test_account']);
             // Subscribe author to queue discussion topic
             if ($this->request->variable('subscribe_author', false)) {
                 $this->subscriptions->subscribe(TITANIA_TOPIC, $this->queue->queue_discussion_topic_id);
             }
         }
         if ($this->attachment) {
             $this->set_package_paths();
         }
         $error = $this->clean_package();
     }
     return array('error' => $error);
 }
Exemplo n.º 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);
    }