コード例 #1
0
ファイル: support.php プロジェクト: Sajaki/customisation-db
 /**
  * Display support topics from all contributions or of a specific type.
  *
  * @param string $type	Contribution type's string identifier
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function display_topics($type)
 {
     $type_id = $this->get_type_id($type);
     if ($type_id === false) {
         return $this->helper->error('NO_PAGE', 404);
     }
     if ($type == 'all') {
         // Mark all topics read
         if ($this->request->variable('mark', '') == 'topics') {
             $this->tracking->track(TITANIA_ALL_SUPPORT, self::ALL_SUPPORT);
         }
         // Mark all topics read
         $this->template->assign_var('U_MARK_TOPICS', $this->helper->route('phpbb.titania.support', array('type' => 'all', 'mark' => 'topics')));
     }
     $this->display->assign_global_vars();
     $u_all_support = $this->helper->route('phpbb.titania.support', array('type' => 'all'));
     $this->template->assign_var('U_ALL_SUPPORT', $u_all_support);
     // Generate the main breadcrumbs
     $this->display->generate_breadcrumbs(array('ALL_SUPPORT' => $u_all_support));
     // Links to the support topic lists
     foreach ($this->types->get_all() as $id => $class) {
         $this->template->assign_block_vars('support_types', array('U_SUPPORT' => $this->helper->route('phpbb.titania.support', array('type' => $class->url)), 'TYPE_SUPPORT' => $class->langs));
     }
     $data = \topics_overlord::display_forums_complete('all_support', false, array('contrib_type' => $type_id));
     // Canonical URL
     $data['sort']->set_url($this->helper->route('phpbb.titania.support', array('type' => $type)));
     $this->template->assign_var('U_CANONICAL', $data['sort']->build_canonical());
     return $this->helper->render('all_support.html', 'CUSTOMISATION_DATABASE');
 }
コード例 #2
0
ファイル: author.php プロジェクト: Sajaki/customisation-db
 /**
  * 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');
 }
コード例 #3
0
ファイル: display.php プロジェクト: Sajaki/customisation-db
 /**
  * Create a select with the contrib types
  *
  * @param int|bool $selected	Selected contrib type id. Defaults to false.
  * @return void
  */
 public function generate_type_select($selected = false)
 {
     $this->template->assign_block_vars('type_select', array('S_IS_SELECTED' => $selected === false, 'VALUE' => 0, 'NAME' => isset($this->user->lang['SELECT_CONTRIB_TYPE']) ? $this->user->lang['SELECT_CONTRIB_TYPE'] : '--'));
     foreach ($this->types->get_all() as $key => $type) {
         if (!$type->acl_get('submit')) {
             continue;
         }
         $this->template->assign_block_vars('type_select', array('S_IS_SELECTED' => $key == $selected, 'VALUE' => $key, 'NAME' => isset($this->user->lang['SELECT_CONTRIB_TYPE']) ? $type->lang : $type->langs));
     }
 }
コード例 #4
0
 /**
  * Get types that use release topics.
  *
  * @return array
  */
 protected function get_applicable_types()
 {
     $types = array();
     foreach ($this->types->get_all() as $id => $class) {
         if ($class->forum_robot && $class->forum_database) {
             $types[] = $id;
         }
     }
     return $types;
 }
コード例 #5
0
 /**
  * Get default contrib type field count values.
  *
  * @return array
  */
 protected function get_defaults()
 {
     $defaults = array('author_contribs' => 0);
     foreach ($this->types->get_all() as $id => $class) {
         if (isset($class->author_count)) {
             $defaults[$class->author_count] = 0;
         }
     }
     return $defaults;
 }
コード例 #6
0
ファイル: author.php プロジェクト: Sajaki/customisation-db
 /**
  * Passes details to the template
  *
  * @param bool $return True if you want the data prepared for output and returned as an array, false to output to the template
  */
 public function assign_details($return = false, $row = false, $revert = true)
 {
     // Set special data to display
     if ($row !== false) {
         if ($revert) {
             $backup = $this->object_data;
         }
         $this->__set_array($row);
     }
     $vars = array('AUTHOR_NAME' => $this->get_username_string('username'), 'AUTHOR_NAME_FULL' => $this->get_username_string(), 'AUTHOR_REALNAME' => $this->author_realname, 'AUTHOR_WEBSITE' => $this->get_website_url(), 'AUTHOR_WEBSITE_LINK' => '<a href="' . $this->get_website_url() . '">' . $this->get_website_url() . '</a>', 'AUTHOR_RATING' => $this->author_id ? $this->author_rating : '', 'AUTHOR_RATING_STRING' => $this->author_id && isset($this->rating) ? $this->rating->get_rating_string() : '', 'AUTHOR_RATING_COUNT' => $this->author_id ? $this->author_rating_count : '', 'AUTHOR_CONTRIBS' => $this->author_contribs, 'AUTHOR_DESC' => $this->generate_text_for_display(), 'U_AUTHOR_PROFILE' => $this->get_url(), 'U_AUTHOR_PROFILE_PHPBB' => $this->get_phpbb_profile_url(), 'U_AUTHOR_PROFILE_PHPBB_COM' => $this->get_phpbb_com_profile_url(), 'U_AUTHOR_CONTRIBUTIONS' => $this->get_url('contributions'));
     // Add to it the common user details
     if (isset(users_overlord::$users[$this->user_id])) {
         $vars = array_merge(users_overlord::assign_details($this->user_id), $vars);
     }
     // Output the count for different types
     $type_list = array();
     foreach ($this->types->get_all() as $type) {
         if (!isset($type->author_count)) {
             // Figure out the counts some other way
             $valid_statuses = array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED);
             $sql_ary = array('SELECT' => 'COUNT(*) AS contrib_cnt', 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIB_COAUTHORS_TABLE => 'ca'), 'ON' => 'ca.contrib_id = c.contrib_id AND ca.user_id = ' . $this->user_id)), 'WHERE' => phpbb::$db->sql_in_set('c.contrib_status', $valid_statuses) . " AND c.contrib_visible = 1 AND c.contrib_type = {$type->id} AND (c.contrib_user_id = {$this->user_id}\n\t\t\t\t\t\t\t\t\tOR ca.user_id = {$this->user_id})");
             $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
             $result = phpbb::$db->sql_query($sql);
             $contrib_cnt = phpbb::$db->sql_fetchfield('contrib_cnt');
             phpbb::$db->sql_freeresult($result);
         } else {
             $contrib_cnt = $this->{$type->author_count};
         }
         if ($contrib_cnt > 0) {
             $lang_key = 'AUTHOR_' . strtoupper($type->name) . 'S';
             if ($contrib_cnt == 1) {
                 $type_list[] = isset(phpbb::$user->lang[$lang_key . '_ONE']) ? phpbb::$user->lang[$lang_key . '_ONE'] : '{' . $lang_key . '_ONE}';
             } else {
                 $type_list[] = isset(phpbb::$user->lang[$lang_key]) ? sprintf(phpbb::$user->lang[$lang_key], $contrib_cnt) : '{' . $lang_key . '}';
             }
         }
     }
     $vars['AUTHOR_CONTRIB_LIST'] = implode($type_list, ', ');
     /* @todo: automatically display the common author data too...
     		if (isset($this->sql_data))
     		{
     			$vars = array_merge($vars, assign_user_details($this->sql_data));
     		}*/
     // Revert data
     if ($revert && $row !== false) {
         $this->__set_array($backup);
         unset($backup);
     }
     if ($return) {
         return $vars;
     }
     phpbb::$template->assign_vars($vars);
 }
コード例 #7
0
ファイル: sync.php プロジェクト: Sajaki/customisation-db
    /**
     * Get the contrib count for a user.
     *
     * @param int $user_id
     * @return array
     */
    public function _get_author_count($user_id)
    {
        $sql_ary = array('author_contribs' => 0);
        foreach ($this->types->get_all() as $type_id => $class) {
            if (!isset($class->author_count)) {
                continue;
            }
            $sql_ary[$class->author_count] = 0;
        }
        // Count the contribution totals for each user
        foreach ($this->types->get_all() as $type_id => $class) {
            // Main authors
            $sql = 'SELECT COUNT(contrib_id) AS cnt
				FROM ' . $this->contribs_table . '
				WHERE contrib_type = ' . (int) $type_id . '
					AND contrib_user_id = ' . (int) $user_id . '
					AND ' . $this->db->sql_in_set('contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED));
            $this->db->sql_query($sql);
            $cnt = $this->db->sql_fetchfield('cnt');
            $sql_ary['author_contribs'] += $cnt;
            if (isset($class->author_count)) {
                $sql_ary[$class->author_count] += $cnt;
            }
            // Co-authors
            $sql = 'SELECT COUNT(c.contrib_id) AS cnt
				FROM ' . $this->contrib_coauthors_table . ' cc, ' . $this->contribs_table . ' c
				WHERE c.contrib_type = ' . (int) $type_id . '
					AND cc.user_id = ' . (int) $user_id . '
					AND c.contrib_id = cc.contrib_id
					AND ' . $this->db->sql_in_set('c.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED));
            $this->db->sql_query($sql);
            $cnt = $this->db->sql_fetchfield('cnt');
            $sql_ary['author_contribs'] += $cnt;
            if (isset($class->author_count)) {
                $sql_ary[$class->author_count] += $cnt;
            }
        }
        return $sql_ary;
    }
コード例 #8
0
 /**
 * Validate contribution settings.
 *
 * @param array $contrib_categories		Contribution categories.
 * @param array $authors					Array in the form of array('author' => array(username => user_id),
 *	'active_coauthors' => array(...), 'nonactive_coauthors' => array(...), 'missing' =>
 	array('active_coauthors' => array(username => username)).
 * @param array $custom_fields			Custom field values.
 * @param string $old_permalink			Old permalink. Defaults to empty string.
 *
 * @return array Returns array containing any errors found.
 */
 public function validate($contrib_categories = array(), $authors, $custom_fields, $old_permalink = '')
 {
     phpbb::$user->add_lang('ucp');
     $error = array();
     if (utf8_clean_string($this->contrib_name) == '') {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_NAME'];
     }
     if (!$this->contrib_type) {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_TYPE'];
     } else {
         // Check for a valid type
         $valid_type = false;
         foreach ($this->types->get_all() as $type_id => $class) {
             if (!$class->acl_get('submit')) {
                 continue;
             }
             if ($this->contrib_type == $type_id) {
                 $valid_type = true;
                 break;
             }
         }
         if (!$valid_type) {
             $error[] = phpbb::$user->lang['EMPTY_CONTRIB_TYPE'];
         } else {
             $this->set_type($this->contrib_type);
             $error = array_merge($error, $this->type->validate_contrib_fields($custom_fields));
             if (!$this->contrib_name_clean) {
                 // If they leave it blank automatically create it
                 $this->generate_permalink();
             }
             if (($permalink_error = $this->validate_permalink($this->contrib_name_clean, $old_permalink)) !== false) {
                 $error[] = $permalink_error;
             }
         }
         if (!$contrib_categories) {
             $error[] = phpbb::$user->lang['EMPTY_CATEGORY'];
         } else {
             $categories = titania::$cache->get_categories();
             $category = new \titania_category();
             foreach ($contrib_categories as $category_id) {
                 if (!isset($categories[$category_id])) {
                     $error[] = phpbb::$user->lang['NO_CATEGORY'];
                 } else {
                     if ($categories[$category_id]['category_type'] != $this->contrib_type) {
                         $error[] = phpbb::$user->lang['WRONG_CATEGORY'];
                     }
                 }
                 if ($valid_type) {
                     $category->__set_array($categories[$category_id]);
                     if ($category->is_option_set('team_only') && !$this->type->acl_get('moderate')) {
                         $error[] = phpbb::$user->lang['CATEGORY_NOT_ALLOWED'];
                     }
                 }
             }
         }
     }
     if (!$this->contrib_desc) {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_DESC'];
     }
     $author = key($authors['author']);
     $missing_coauthors = array_merge($authors['missing']['active_coauthors'], $authors['missing']['nonactive_coauthors']);
     if (!empty($missing_coauthors)) {
         $error[] = phpbb::$user->lang('COULD_NOT_FIND_USERS', phpbb_generate_string_list($missing_coauthors, phpbb::$user));
     }
     $duplicates = array_intersect($authors['active_coauthors'], $authors['nonactive_coauthors']);
     if (!empty($duplicates)) {
         $error[] = phpbb::$user->lang('DUPLICATE_AUTHORS', phpbb_generate_string_list(array_keys($duplicates), phpbb::$user));
     }
     if (isset($authors['active_coauthors'][$author]) || isset($authors['nonactive_coauthors'][$author])) {
         $error[] = phpbb::$user->lang['CANNOT_ADD_SELF_COAUTHOR'];
     }
     if (!empty($authors['missing']['new_author'])) {
         $error[] = phpbb::$user->lang('CONTRIB_CHANGE_OWNER_NOT_FOUND', key($authors['missing']['new_author']));
     }
     if ($this->contrib_demo !== '') {
         $demos = json_decode($this->contrib_demo, true);
         foreach ($demos as $url) {
             if ($url !== '' && !preg_match('#^http[s]?://(.*?\\.)*?[a-z0-9\\-]{2,4}#i', $url)) {
                 $error[] = phpbb::$user->lang('FIELD_INVALID_URL', phpbb::$user->lang['CONTRIB_DEMO']);
                 break;
             }
         }
     }
     // Hooks
     titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $error, $this);
     return $error;
 }