Esempio n. 1
0
    /**
     * Load the contrib
     *
     * @param int|string $contrib The contrib item (contrib_name_clean, contrib_id)
     * @param int $type Contrib type
     * @return bool True if the contrib exists, false if not
     */
    public function load($contrib = false, $type = false)
    {
        if ($contrib === false) {
            $contrib = $this->contrib_id;
        }
        $sql_ary = array('SELECT' => 'c.*, a.*', 'FROM' => array($this->sql_table => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_AUTHORS_TABLE => 'a'), 'ON' => 'a.user_id = c.contrib_user_id')));
        if (is_int($contrib)) {
            $sql_ary['WHERE'] = 'contrib_id = ' . (int) $contrib;
        } else {
            if (!$type) {
                return false;
            }
            // Temp fix until issue is fixed in phpBB (http://tracker.phpbb.com/browse/PHPBB3-10921)
            $contrib = strtr(utf8_clean_string($contrib), array('!' => 'ǃ'));
            $sql_ary['WHERE'] = 'contrib_name_clean = \'' . phpbb::$db->sql_escape($contrib) . '\'
				AND contrib_type = ' . (int) $type;
        }
        $result = phpbb::$db->sql_query(phpbb::$db->sql_build_query('SELECT', $sql_ary));
        $sql_data = phpbb::$db->sql_fetchrow($result);
        phpbb::$db->sql_freeresult($result);
        // Make sure we have data.
        if (empty($sql_data)) {
            return false;
        }
        // Set object data.
        $this->__set_array($sql_data);
        $this->set_type($this->contrib_type);
        // Fill categories
        $this->fill_categories();
        // Set author object and set the data for the author object.
        $this->author = new titania_author($this->contrib_user_id);
        $this->author->__set_array($sql_data);
        // Load co-authors list
        $this->coauthors = array();
        $sql_ary = array('SELECT' => 'cc.*, a.*', 'FROM' => array(TITANIA_CONTRIB_COAUTHORS_TABLE => 'cc'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_AUTHORS_TABLE => 'a'), 'ON' => 'a.user_id = cc.user_id')), 'WHERE' => 'cc.contrib_id = ' . $this->contrib_id);
        $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
        $result = phpbb::$db->sql_query($sql);
        while ($row = phpbb::$db->sql_fetchrow($result)) {
            $this->coauthors[$row['user_id']] = $row;
        }
        phpbb::$db->sql_freeresult($result);
        // Load the users table information
        users_overlord::load_users(array_merge(array($this->contrib_user_id), array_keys($this->coauthors)));
        // Check author/co-author status
        if ($this->contrib_user_id == phpbb::$user->data['user_id']) {
            $this->is_author = true;
        } else {
            if (isset($this->coauthors[phpbb::$user->data['user_id']])) {
                $this->is_coauthor = true;
                if ($this->coauthors[phpbb::$user->data['user_id']]['active']) {
                    $this->is_active_coauthor = true;
                }
            }
        }
        return true;
    }
Esempio n. 2
0
 /**
  * Load the contrib
  *
  * @param int|string $contrib The contrib item (contrib_name_clean, contrib_id)
  *
  * @return bool True if the contrib exists, false if not
  */
 public function load($contrib)
 {
     $sql_ary = array('SELECT' => 'c.*, a.*', 'FROM' => array($this->sql_table => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_AUTHORS_TABLE => 'a'), 'ON' => 'a.user_id = c.contrib_user_id')));
     if (is_int($contrib)) {
         $sql_ary['WHERE'] = 'contrib_id = ' . (int) $contrib;
     } else {
         $sql_ary['WHERE'] = 'contrib_name_clean = \'' . phpbb::$db->sql_escape(utf8_clean_string($contrib)) . '\'';
     }
     $result = phpbb::$db->sql_query(phpbb::$db->sql_build_query('SELECT', $sql_ary));
     $sql_data = phpbb::$db->sql_fetchrow($result);
     phpbb::$db->sql_freeresult($result);
     // Make sure we have data.
     if (empty($sql_data)) {
         return false;
     }
     // Set object data.
     $this->__set_array($sql_data);
     // Set author object and set the data for the author object.
     $this->author = new titania_author($this->contrib_user_id);
     $this->author->__set_array($sql_data);
     // Load co-authors list
     $this->coauthors = array();
     $sql_ary = array('SELECT' => 'cc.*, a.*', 'FROM' => array(TITANIA_CONTRIB_COAUTHORS_TABLE => 'cc'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_AUTHORS_TABLE => 'a'), 'ON' => 'a.user_id = cc.user_id')), 'WHERE' => 'cc.contrib_id = ' . $this->contrib_id);
     $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
     $result = phpbb::$db->sql_query($sql);
     while ($row = phpbb::$db->sql_fetchrow($result)) {
         $this->coauthors[$row['user_id']] = $row;
     }
     phpbb::$db->sql_freeresult($result);
     // Load the users table information
     users_overlord::load_users(array_merge(array($this->contrib_user_id), array_keys($this->coauthors)));
     // Check author/co-author status
     if ($this->contrib_user_id == phpbb::$user->data['user_id']) {
         $this->is_author = true;
     } else {
         if (isset($this->coauthors[phpbb::$user->data['user_id']])) {
             $this->is_coauthor = true;
             if ($this->coauthors[phpbb::$user->data['user_id']]['active']) {
                 $this->is_active_coauthor = true;
             }
         }
     }
     if (in_array($this->contrib_status, array(TITANIA_CONTRIB_HIDDEN, TITANIA_CONTRIB_DISABLED)) && !($this->is_author || $this->is_active_coauthor || phpbb::$auth->acl_get('u_titania_mod_contrib_mod') || titania_types::$types[$this->contrib_type]->acl_get('moderate'))) {
         // Hide hidden and disabled contribs for non-(authors/moderators)
         return false;
     }
     return true;
 }
Esempio n. 3
0
    /**
     * Sync authors
     *
     * @param string $mode The mode (count)
     * @param int $user_id User id to limit to
     */
    public function authors($mode, $user_id = false)
    {
        switch ($mode) {
            case 'count':
                // Reset the count for all authors first
                $sql_ary = array('author_contribs' => 0);
                foreach (titania_types::$types as $type_id => $class) {
                    if (!isset($class->author_count)) {
                        continue;
                    }
                    $sql_ary[$class->author_count] = 0;
                }
                $sql = 'UPDATE ' . TITANIA_AUTHORS_TABLE . '
					SET ' . phpbb::$db->sql_build_array('UPDATE', $sql_ary);
                phpbb::$db->sql_query($sql);
                $sql = 'SELECT DISTINCT(contrib_user_id) AS user_id FROM ' . TITANIA_CONTRIBS_TABLE . ($user_id ? ' WHERE contrib_user_id = ' . (int) $user_id : '');
                $result = phpbb::$db->sql_query($sql);
                while ($row = phpbb::$db->sql_fetchrow($result)) {
                    $sql_ary = $this->_get_author_count($row['user_id']);
                    // sql_affectedrows does not work if the count is 0 across the board
                    $sql = 'SELECT author_id FROM ' . TITANIA_AUTHORS_TABLE . '
						WHERE user_id = ' . (int) $row['user_id'];
                    phpbb::$db->sql_query($sql);
                    $author_id = phpbb::$db->sql_fetchfield('author_id');
                    phpbb::$db->sql_freeresult();
                    if ($author_id) {
                        // Increment/Decrement the contrib counter for the new owner
                        $sql = 'UPDATE ' . TITANIA_AUTHORS_TABLE . '
							SET ' . phpbb::$db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $row['user_id'];
                        phpbb::$db->sql_query($sql);
                    } else {
                        $author = new titania_author($row['user_id']);
                        $author->__set_array($sql_ary);
                        $author->submit();
                    }
                }
                phpbb::$db->sql_freeresult($result);
                break;
        }
    }
Esempio n. 4
0
 /**
  * Display author management page.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function manage()
 {
     if (!$this->is_owner && !$this->auth->acl_get('u_titania_mod_author_mod')) {
         return $this->helper->needs_auth();
     }
     $error = array();
     $this->message->set_parent($this->author)->set_auth(array('bbcode' => $this->auth->acl_get('u_titania_bbcode'), 'smilies' => $this->auth->acl_get('u_titania_smilies')))->set_settings(array('display_error' => false, 'display_subject' => false));
     if ($this->request->is_set_post('submit')) {
         $this->author->post_data($this->message);
         $this->author->__set_array(array('author_realname' => $this->request->variable('realname', '', true), 'author_website' => $this->request->variable('website', '')));
         $error = $this->author->validate();
         if (($validate_form_key = $this->message->validate_form_key()) !== false) {
             $error[] = $validate_form_key;
         }
         if (empty($error)) {
             $this->author->submit();
             redirect($this->author->get_url());
         }
     }
     $this->message->display();
     $this->template->assign_vars(array('S_POST_ACTION' => $this->author->get_url('manage'), 'AUTHOR_WEBSITE' => $this->author->get_website_url() || !$this->is_owner ? $this->author->get_website_url() : '', 'ERROR_MSG' => !empty($error) ? implode('<br />', $error) : false));
     return $this->helper->render('authors/author_manage.html', $this->get_title('MANAGE_AUTHOR'));
 }