Example #1
0
 /**
  * Run requested tool.
  *
  * @param string $tool		Tool.
  * @param int $id			Revision id.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function run_tool($tool, $id)
 {
     if (!in_array($tool, array('automod', 'mpv', 'epv'))) {
         return $this->helper->error('INVALID_TOOL', 404);
     }
     // Check the hash first to avoid unnecessary queries.
     if (!check_link_hash($this->request->variable('hash', ''), 'queue_tool')) {
         return $this->helper->error('PAGE_REQUEST_INVALID');
     }
     $this->load_objects($id);
     if (!$this->contrib->type->acl_get('view')) {
         return $this->helper->needs_auth();
     }
     return $this->{$tool}();
 }
Example #2
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');
 }
Example #3
0
 protected function common_delete($post_id, $undelete = false)
 {
     $this->user->add_lang('posting');
     // Load the stuff we need
     $post = $this->load_post($post_id);
     // Check permissions
     if (!$undelete && !$post->acl_get('delete') || $undelete && !$post->acl_get('undelete')) {
         return $this->controller_helper->needs_auth();
     }
     if (confirm_box(true)) {
         if (!$undelete) {
             // Delete the post
             if ($this->request->is_set_post('hard_delete') || $post->post_deleted) {
                 if (!$this->auth->acl_get('u_titania_post_hard_delete')) {
                     return $this->controller_helper->needs_auth();
                 }
                 $post->hard_delete();
                 // Try to redirect to the next or previous post
                 $redirect_post_id = \posts_overlord::next_prev_post_id($post->topic_id, $post->post_id);
                 if ($redirect_post_id) {
                     return new RedirectResponse($post->topic->get_url(false, array('p' => $redirect_post_id, '#' => "p{$redirect_post_id}")));
                 }
                 return new RedirectResponse($post->topic->get_parent_url());
             } else {
                 $post->soft_delete();
                 if ($this->auth->acl_get('u_titania_mod_post_mod')) {
                     // They can see the post, redirect back to it
                     return new RedirectResponse($post->get_url());
                 } else {
                     // They cannot see the post, try to redirect to the next or previous post
                     $redirect_post_id = \posts_overlord::next_prev_post_id($post->topic_id, $post->post_id);
                     if ($redirect_post_id) {
                         return new RedirectResponse($post->topic->get_url(false, array('p' => $redirect_post_id, '#' => "p{$redirect_post_id}")));
                     }
                 }
             }
             return new RedirectResponse($post->topic->get_url());
         } else {
             $post->undelete();
             return new RedirectResponse($post->get_url());
         }
     } else {
         $s_hard_delete = !$undelete && !$post->post_deleted && $this->auth->acl_get('u_titania_post_hard_delete');
         $this->template->assign_var('S_HARD_DELETE', $s_hard_delete);
         confirm_box(false, !$undelete ? 'DELETE_POST' : 'UNDELETE_POST', '', 'posting/delete_confirm.html');
     }
     return new RedirectResponse($post->get_url());
 }