/** * 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'); }
/** * 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; } }
/** * 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(); } }
} redirect(titania_url::build_url('')); break; /** * 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'); }