示例#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');
 }
示例#2
0
    /**
     * Update the release topic for this contribution
     */
    public function update_release_topic()
    {
        if (titania_types::$types[$this->contrib_type]->forum_robot && titania_types::$types[$this->contrib_type]->forum_database && titania_types::$types[$this->contrib_type]->create_public) {
            titania::_include('functions_posting', 'phpbb_posting');
            // Get the latest download
            $this->get_download();
            // If there is not a download do not update.
            if (!$this->download) {
                return;
            }
            $contrib_description = $this->contrib_desc;
            titania_decode_message($contrib_description, $this->contrib_desc_uid);
            // Global body and options
            $body = sprintf(phpbb::$user->lang[titania_types::$types[$this->contrib_type]->create_public], $this->contrib_name, titania_url::remove_sid($this->author->get_url()), users_overlord::get_user($this->author->user_id, '_username'), $contrib_description, $this->download['revision_version'], titania_url::build_clean_url('download', array('id' => $this->download['attachment_id'])), $this->download['real_filename'], $this->download['filesize'], titania_url::remove_sid($this->get_url()), titania_url::remove_sid($this->get_url('support')));
            $options = array('poster_id' => titania_types::$types[$this->contrib_type]->forum_robot, 'forum_id' => titania_types::$types[$this->contrib_type]->forum_database);
            if ($this->contrib_release_topic_id) {
                // We edit the first post of contrib release topic
                $options_edit = array('topic_id' => $this->contrib_release_topic_id, 'topic_title' => $this->contrib_name, 'post_text' => $body);
                $options_edit = array_merge($options_edit, $options);
                phpbb_posting('edit_first_post', $options_edit);
            } else {
                // We create a new topic in database
                $options_post = array('topic_title' => $this->contrib_name, 'post_text' => $body);
                $options_post = array_merge($options_post, $options);
                $this->contrib_release_topic_id = phpbb_posting('post', $options_post);
                $sql = 'UPDATE ' . $this->sql_table . '
					SET contrib_release_topic_id = ' . $this->contrib_release_topic_id . '
					WHERE contrib_id = ' . $this->contrib_id;
                phpbb::$db->sql_query($sql);
            }
        }
    }
示例#3
0
 /**
  * Update the release topic for this contribution
  */
 public function update_release_topic()
 {
     if ($this->type->forum_robot && $this->type->forum_database && $this->type->create_public) {
         titania::_include('functions_posting', 'phpbb_posting');
         // Get the latest download
         $this->get_download();
         // If there is not a download do not update.
         if (!$this->download) {
             return;
         }
         // Get the latest revision
         $this->get_revisions();
         // If there is not a revision do not update.
         if (!$this->revisions) {
             return;
         }
         $contrib_description = $this->contrib_desc;
         message::decode($contrib_description, $this->contrib_desc_uid);
         foreach ($this->download as $download) {
             $phpbb_version = $this->revisions[$download['revision_id']]['phpbb_versions'][0];
             $branch = (int) $phpbb_version['phpbb_version_branch'];
             if (empty($this->type->forum_database[$branch])) {
                 continue;
             }
             $u_download = $this->controller_helper->route('phpbb.titania.download', array('id' => $download['attachment_id']));
             // Global body and options
             $body = phpbb::$user->lang($this->type->create_public, $this->contrib_name, $this->path_helper->strip_url_params($this->author->get_url(), 'sid'), users_overlord::get_user($this->author->user_id, '_username'), $contrib_description, $download['revision_version'], $this->path_helper->strip_url_params($u_download, 'sid'), $download['real_filename'], get_formatted_filesize($download['filesize']), $this->path_helper->strip_url_params($this->get_url(), 'sid'), $this->path_helper->strip_url_params($this->get_url('support'), 'sid'), $phpbb_version['phpbb_version_branch'][0] . '.' . $phpbb_version['phpbb_version_branch'][1] . '.' . $phpbb_version['phpbb_version_revision']);
             $options = array('poster_id' => $this->type->forum_robot, 'forum_id' => $this->type->forum_database[$branch]);
             $release_topic_id = (int) $this->get_release_topic_id($branch);
             if ($release_topic_id) {
                 // We edit the first post of contrib release topic
                 $options_edit = array('topic_id' => $release_topic_id, 'topic_title' => $this->contrib_name, 'post_text' => $body);
                 $options_edit = array_merge($options_edit, $options);
                 phpbb_posting('edit_first_post', $options_edit);
             } else {
                 // We create a new topic in database
                 $options_post = array('topic_title' => $this->contrib_name, 'post_text' => $body);
                 $options_post = array_merge($options_post, $options);
                 $release_topic_id = phpbb_posting('post', $options_post);
                 $this->set_release_topic_id($branch, $release_topic_id);
             }
         }
     }
 }
示例#4
0
     /**
      * Rate something & remove a rating from something
      */
 /**
  * Rate something & remove a rating from something
  */
 case 'rate':
     $type = request_var('type', '');
     $id = request_var('id', 0);
     $value = request_var('value', -1.0);
     switch ($type) {
         case 'author':
             $object = new titania_author();
             $object->load($id);
             $object->get_rating();
             $redirect = $object->get_url();
             if (!$object || !$object->author_id) {
                 trigger_error('AUTHOR_NOT_FOUND');
             }
             break;
         case 'contrib':
             $object = new titania_contribution();
             $object->load($id);
             $object->get_rating();
             $redirect = $object->get_url();
             if (!$object) {
                 trigger_error('CONTRIB_NOT_FOUND');
             }
             break;
         default:
             trigger_error('BAD_RATING');