/**
     * Synchronize queue topic url values.
     *
     * @return bool|int
     */
    protected function sync_contrib_topics($progress)
    {
        $i = 0;
        $topic_type_where = $this->db->sql_in_set('topic_type', array(TITANIA_SUPPORT, TITANIA_QUEUE_DISCUSSION));
        $sql = 'SELECT contrib_id, contrib_type, contrib_name_clean
			FROM ' . $this->contribs_table;
        $result = $this->db->sql_query_limit($sql, $this->limit, $this->start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $url = serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean']));
            $where = 'parent_id = ' . (int) $row['contrib_id'] . '
				AND ' . $topic_type_where;
            $this->update_field($this->topics_table, 'topic', $url, $where);
            $i++;
        }
        $this->db->sql_freeresult($result);
        $sql = "SELECT topic_id, topic_url\n\t\t\tFROM {$this->topics_table}\n\t\t\tWHERE {$topic_type_where}";
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $where = 'topic_id = ' . (int) $row['topic_id'];
            $this->update_field($this->posts_table, 'post', $row['topic_url'], $where);
            if ($progress) {
                $progress->advance();
            }
        }
        $this->db->sql_freeresult($result);
        if ($i === $this->limit) {
            return $this->start + $this->limit;
        }
        return false;
    }
Exemple #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');
 }
Exemple #3
0
 /**
  * Assign details
  *
  * A little different from those in other classes, this one only returns the info ready for output
  */
 public function assign_details($output_text = true)
 {
     $details = array('POST_ID' => $this->post_id, 'TOPIC_ID' => $this->topic_id, 'POST_TYPE' => $this->post_type, 'POST_ACCESS' => $this->post_access, 'POST_LOCKED' => $this->post_locked, 'POST_ATTACHMENT' => $this->post_attachment, 'POST_USER_ID' => $this->post_user_id, 'POST_IP' => phpbb::$auth->acl_get('u_titania_mod_post_mod') ? $this->post_ip : false, 'POST_TIME' => phpbb::$user->format_date($this->post_time), 'POST_EDIT_REASON' => censor_text($this->post_edit_reason), 'POST_SUBJECT' => censor_text($this->post_subject), 'POST_TEXT' => $output_text ? $this->generate_text_for_display() : '', 'EDITED_MESSAGE' => $this->post_edited ? sprintf(phpbb::$user->lang['EDITED_MESSAGE'], users_overlord::get_user($this->post_edit_user, '_full'), phpbb::$user->format_date($this->post_edited)) : '', 'DELETED_MESSAGE' => $this->post_deleted != 0 ? sprintf(phpbb::$user->lang['DELETED_MESSAGE'], users_overlord::get_user($this->post_delete_user, '_full'), phpbb::$user->format_date($this->post_deleted), $this->get_url('undelete')) : '', 'U_VIEW' => $this->get_url(), 'U_EDIT' => $this->acl_get('edit') ? $this->get_url('edit') : '', 'U_QUICKEDIT' => $this->acl_get('edit') ? $this->get_url('quick_edit') : '', 'U_DELETE' => $this->acl_get('delete') && (!$this->post_deleted || phpbb::$auth->acl_get('u_titania_post_hard_delete')) ? $this->get_url('delete') : '', 'U_REPORT' => phpbb::$user->data['is_registered'] ? $this->get_url('report') : '', 'U_WARN' => false, 'U_INFO' => phpbb::$auth->acl_gets('u_titania_mod_author_mod', 'u_titania_mod_contrib_mod', 'u_titania_mod_faq_mod', 'u_titania_mod_post_mod') || $this->types->find_authed('moderate') ? $this->controller_helper->route('phpbb.titania.manage.attention.redirect', array('type' => TITANIA_POST, 'id' => $this->post_id)) : '', 'U_QUOTE' => $this->acl_get('post') ? $this->get_url('quote') : '', 'S_UNREAD_POST' => $this->unread ? true : false, 'S_POST_APPROVED' => phpbb::$auth->acl_get('u_titania_mod_post_mod') ? $this->post_approved : true, 'S_POST_REPORTED' => phpbb::$auth->acl_get('u_titania_mod_post_mod') ? $this->post_reported : false, 'S_POST_DELETED' => $this->post_deleted != 0 ? true : false, 'S_ACCESS_TEAMS' => $this->access->is_team($this->post_access), 'S_ACCESS_AUTHORS' => $this->access->is_author($this->post_access));
     // Hooks
     titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $details, $this);
     return $details;
 }
 /**
  * Get the contribution type of the category.
  *
  * @return \phpbb\titania\contribution\type\type_interface|bool False if the type couldn't be determined
  */
 protected function get_category_type()
 {
     $children = $this->get_children_ids();
     $type_id = $this->category->category_type;
     // If the category is the top most parent, we'll try to get the type from the first child
     if (!$type_id && !empty($children)) {
         $type_id = $this->categories[$children[0]]['category_type'];
     }
     return $type_id ? $this->types->get($type_id) : false;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #7
0
 /**
  * Load contribution.
  *
  * @param string $contrib_type		Contrib type URL identifier.
  * @param string $contrib			Contrib name clean.
  * @throws \Exception				Throws exception if contrib is not found.
  * @return null
  */
 protected function load_contrib($contrib_type, $contrib)
 {
     $type = $contrib_type ? $this->types->type_from_url($contrib_type) : false;
     $this->contrib = new \titania_contribution();
     if (!$this->contrib->load($contrib, $type) || !$this->contrib->is_visible()) {
         throw new \Exception($this->user->lang['CONTRIB_NOT_FOUND']);
     }
     $this->is_author = $this->contrib->is_active_coauthor || $this->contrib->is_author;
     $this->set_access_level();
 }
Exemple #8
0
 /**
  * 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));
     }
 }
Exemple #9
0
 /**
  * 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);
 }
Exemple #10
0
 /**
  * Get navigation tab options.
  *
  * @return array
  */
 protected function get_navigation_options()
 {
     /**
      * Menu Array
      *
      * 'filename' => array(
      *	'title'		=> 'nav menu title',
      * 	'url'		=> $page_url,
      *	'auth'		=> ($can_see_page) ? true : false, // Not required, always true if missing
      * ),
      */
     return array('attention' => array('title' => 'ATTENTION', 'url' => $this->helper->route('phpbb.titania.manage.attention'), 'auth' => $this->auth->acl_gets('u_titania_mod_author_mod', 'u_titania_mod_contrib_mod', 'u_titania_mod_faq_mod', 'u_titania_mod_post_mod') || $this->types->find_authed('moderate'), 'count' => $this->get_open_attention_count()), 'queue' => array('title' => 'VALIDATION_QUEUE', 'url' => $this->helper->route('phpbb.titania.queue'), 'auth' => $this->types->find_authed('view') && $this->ext_config->use_queue), 'queue_discussion' => array('title' => 'QUEUE_DISCUSSION', 'url' => $this->helper->route('phpbb.titania.queue_discussion'), 'auth' => $this->types->find_authed('queue_discussion') && $this->ext_config->use_queue), 'administration' => array('title' => 'ADMINISTRATION', 'url' => $this->helper->route('phpbb.titania.administration'), 'auth' => $this->auth->acl_get('u_titania_admin'), 'match' => array('categories')), 'categories' => array('title' => 'MANAGE_CATEGORIES', 'url' => $this->helper->route('phpbb.titania.manage.categories'), 'auth' => $this->auth->acl_get('u_titania_admin'), 'display' => false));
 }
Exemple #11
0
    /**
     * Get additional FAQ data.
     *
     * @param array $ids
     * @param array $documents
     * @return array
     */
    protected function get_faqs(array $ids, array $documents)
    {
        if (!$ids) {
            return $documents;
        }
        $sql = 'SELECT f.faq_id AS id, f.faq_subject AS title, c.contrib_name_clean, c.contrib_type, f.faq_text AS text,
				f.faq_text_uid AS text_uid, f.faq_text_bitfield AS text_bitfield,
				f.faq_text_options AS text_options
			FROM ' . $this->contribs_table . ' c, ' . $this->faq_table . ' f
			WHERE ' . $this->db->sql_in_set('f.faq_id', $ids) . '
				AND f.contrib_id = c.contrib_id';
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $id = TITANIA_FAQ . '_' . $row['id'];
            $row['url'] = serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'], 'id' => $row['id']));
            $documents[$id] = array_merge($documents[$id], $row);
        }
        $this->db->sql_freeresult($result);
        return $documents;
    }
Exemple #12
0
    /**
     * 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;
    }
 /**
  * Get queue item template row.
  *
  * @param array $row
  * @return array
  */
 protected function get_queue_tpl_row($row)
 {
     $queue_id = $row['watch_object_id'];
     $type = $this->types->get($queue_id);
     return array('SUBSCRIPTION_ID' => $queue_id, 'SUBSCRIPTION_TARGET' => $type->lang, 'SUBSCRIPTION_TIME' => $this->user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => $this->user->lang['SUBSCRIPTION_QUEUE'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_QUEUE' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => $this->get_real_url($this->helper->route('phpbb.titania.queue.type', array('queue_type' => $type->url))));
 }
 /**
  * Dump include file.
  *
  * @param string $type		Contrib type name
  * @param int $group		Group id
  * @param array $packages	Packages
  */
 protected function dump_include($type, $group, array $packages)
 {
     $type_name = $this->types->get($type)->name;
     $this->repo->dump_include("packages-{$type_name}-{$group}.json", $packages);
 }
 /**
 * 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;
 }
 /**
  * Set the contribution type to generate stats for.
  *
  * @param string $type	Contribution type URL value.
  * @return null
  */
 protected function set_type($type)
 {
     $type = $this->types->type_from_url($type);
     $this->type = $type ? $this->types->get($type) : false;
 }
Exemple #17
0
 /**
  * Get type id from url string identifier
  *
  * @param string $type Contribution type's string identifier
  * @return int|bool Returns the type's id or false if no type matches.
  */
 protected function get_type_id($type)
 {
     return $type == 'all' ? self::ALL_SUPPORT : $this->types->type_from_url($type);
 }
Exemple #18
0
    /**
     * Get the author contribs for the specified user id
     *
     * @param int $user_id The user ID
     * @param type_collection $types
     * @param \phpbb\user $user User object
     * @param bool $active True to request only active contributions, false for all
     *
     * @return array Array of contrib_id's
     */
    public function get_author_contribs($user_id, type_collection $types, $user, $active = false)
    {
        $user_id = (int) $user_id;
        // We shall group authors by id in groups of 2500
        $author_block_name = '_titania_authors_' . floor($user_id / 2500);
        if ($author_block = $this->driver->get($author_block_name) === false) {
            $author_block = array();
        }
        if (!isset($author_block[$user_id])) {
            $author_block[$user_id] = array();
            // Need to get the contribs for the selected author
            $sql = 'SELECT contrib_id, contrib_type, contrib_status FROM ' . TITANIA_CONTRIBS_TABLE . '
				WHERE contrib_user_id = ' . $user_id;
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $author_block[$user_id][$row['contrib_id']] = array('status' => $row['contrib_status'], 'active' => true, 'type' => $row['contrib_type']);
            }
            $this->db->sql_freeresult($result);
            // Now get the lists where the user is a co-author
            $sql = 'SELECT cc.contrib_id, c.contrib_status, c.contrib_type, cc.active FROM ' . TITANIA_CONTRIB_COAUTHORS_TABLE . ' cc, ' . TITANIA_CONTRIBS_TABLE . ' c
				WHERE cc.user_id = ' . $user_id . '
					AND c.contrib_id = cc.contrib_id';
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $author_block[$user_id][$row['contrib_id']] = array('status' => $row['contrib_status'], 'active' => $row['active'], 'type' => $row['contrib_type']);
            }
            $this->db->sql_freeresult($result);
            // Store the updated cache data
            $this->driver->put($author_block_name, $author_block);
        }
        $contribs = array();
        foreach ($author_block[$user_id] as $contrib_id => $data) {
            // If approved, or new and doesn't require approval, or the user is viewing their own, or permission to view non-validated, add them to the list
            if ($user->data['user_id'] == $user_id || in_array($data['status'], array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) || $types->get($data['type'])->acl_get('view') || $types->get($data['type'])->acl_get('moderate')) {
                if (!$active || $data['active']) {
                    $contribs[] = $contrib_id;
                }
            }
        }
        return $contribs;
    }