Beispiel #1
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;
        }
    }
Beispiel #2
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'));
 }
 /**
  * Increment the contrib count for an author (also verifies that there is a row in the authors table)
  * Always use this when updating the count for an author!
  *
  * @param int|array $user_id
  * @param string action + or -
  * @param bool $force Ignore the check on require_validation, contrib_status (DO NOT USE UNLESS YOU HAVE A VERY GOOD REASON; should only be required by the update_status function)
  */
 private function change_author_contrib_count($user_id, $action = '+', $force = false)
 {
     if (is_array($user_id)) {
         foreach ($user_id as $uid) {
             $this->change_author_contrib_count($uid, $action, $force);
         }
         return;
     }
     // Don't change if it's not approved
     if ($force == false && !in_array($this->contrib_status, array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED))) {
         return;
     }
     $user_id = (int) $user_id;
     $action = $action == '-' ? '-' : '+';
     // Increment/Decrement the contrib counter for the new owner
     $sql = 'UPDATE ' . TITANIA_AUTHORS_TABLE . "\n\t\t\tSET author_contribs = author_contribs {$action} 1" . (isset($this->type->author_count) ? ', ' . $this->type->author_count . ' = ' . $this->type->author_count . " {$action} 1" : '') . "\n\t\t\tWHERE user_id = {$user_id} " . ($action == '-' ? 'AND author_contribs > 0' : '');
     phpbb::$db->sql_query($sql);
     if (!phpbb::$db->sql_affectedrows() && $action == '+') {
         $author = new titania_author($user_id);
         $author->author_contribs = 1;
         if (isset($this->type->author_count)) {
             $author->{$this->type->author_count} = 1;
         }
         $author->submit();
     }
 }