/** * Display contributions * * @param string $mode The mode (category, author) * @param int $id The parent id (only show contributions under this category, author, etc) * @param string $blockname The name of the template block to use (contribs by default) */ function display_contribs($mode, $id, $sort = false, $blockname = 'contribs') { titania::add_lang('contributions'); titania::_include('functions_display', 'titania_topic_folder_img'); // Setup the sort tool if not sent, then request if ($sort === false) { $sort = self::build_sort(); } $sort->request(); $select = 'DISTINCT(c.contrib_id), c.contrib_name, c.contrib_name_clean, c.contrib_status, c.contrib_downloads, c.contrib_views, c.contrib_rating, c.contrib_rating_count, c.contrib_type, c.contrib_last_update, c.contrib_user_id'; switch ($mode) { case 'author': // Get the contrib_ids this user is an author in (includes as a co-author) $contrib_ids = titania::$cache->get_author_contribs($id); if (!sizeof($contrib_ids)) { return compact('sort'); } $sql_ary = array('SELECT' => $select, 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'WHERE' => phpbb::$db->sql_in_set('c.contrib_id', $contrib_ids) . ' AND c.contrib_visible = 1', 'ORDER_BY' => $sort->get_order_by()); break; case 'category': $sql_ary = array('SELECT' => $select, 'FROM' => array(TITANIA_CONTRIB_IN_CATEGORIES_TABLE => 'cic'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => 'cic.contrib_id = c.contrib_id')), 'WHERE' => (is_array($id) && sizeof($id) ? phpbb::$db->sql_in_set('cic.category_id', array_map('intval', $id)) : 'cic.category_id = ' . (int) $id) . ' AND c.contrib_visible = 1', 'ORDER_BY' => $sort->get_order_by()); break; case 'all': $sql_ary = array('SELECT' => $select, 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'WHERE' => 'c.contrib_visible = 1', 'ORDER_BY' => $sort->get_order_by()); break; } titania_tracking::get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id'); // Permissions if (titania::$config->require_validation && !phpbb::$auth->acl_get('u_titania_mod_contrib_mod')) { $sql_ary['LEFT_JOIN'][] = array('FROM' => array(TITANIA_CONTRIB_COAUTHORS_TABLE => 'cc'), 'ON' => 'cc.contrib_id = c.contrib_id AND cc.user_id = ' . phpbb::$user->data['user_id']); $view_unapproved = array(); if (sizeof(titania_types::find_authed('moderate'))) { $view_unapproved = array_merge($view_unapproved, titania_types::find_authed('moderate')); } if (sizeof(titania_types::find_authed('view'))) { $view_unapproved = array_merge($view_unapproved, titania_types::find_authed('view')); } // Find the ones that do not require validation $view_unapproved = array_merge($view_unapproved, titania_types::find_validation_free()); $view_unapproved = array_unique($view_unapproved); $sql_ary['WHERE'] .= ' AND (' . phpbb::$db->sql_in_set('c.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . (sizeof($view_unapproved) ? ' OR ' . phpbb::$db->sql_in_set('c.contrib_type', array_map('intval', $view_unapproved)) : '') . ' OR c.contrib_user_id = ' . phpbb::$user->data['user_id'] . ' OR cc.active = 1)'; } // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 'DISTINCT(c.contrib_id)')) { // No results...no need to query more... return compact('sort'); } $sort->build_pagination(titania_url::$current_page, titania_url::$params); $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $contrib_ids = $user_ids = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { $user_ids[] = $row['contrib_user_id']; $contrib_ids[] = $row['contrib_id']; self::$contribs[$row['contrib_id']] = $row; } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); // Get phpBB versions if (sizeof($contrib_ids)) { $validation_free = titania_types::find_validation_free(); if (sizeof($validation_free) && titania::$config->require_validation) { $sql = 'SELECT rp.contrib_id, rp.phpbb_version_branch, rp.phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' rp, ' . TITANIA_CONTRIBS_TABLE . ' c WHERE ' . phpbb::$db->sql_in_set('rp.contrib_id', array_map('intval', $contrib_ids)) . ' AND c.contrib_id = rp.contrib_id AND (rp.revision_validated = 1 OR ' . phpbb::$db->sql_in_set('c.contrib_type', $validation_free) . ') ORDER BY rp.row_id DESC'; } else { $sql = 'SELECT contrib_id, phpbb_version_branch, phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('contrib_id', array_map('intval', $contrib_ids)) . (titania::$config->require_validation ? ' AND revision_validated = 1' : '') . ' ORDER BY row_id DESC'; } $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { self::$contribs[$row['contrib_id']]['phpbb_versions'][] = $row; } phpbb::$db->sql_freeresult($result); } // Setup some objects we'll use for temps $contrib = new titania_contribution(); $contrib->author = new titania_author(); $versions = titania::$cache->get_phpbb_versions(); $author_contribs = titania::$cache->get_author_contribs(phpbb::$user->data['user_id'], true); // Get the mark all tracking titania_tracking::get_track(TITANIA_CONTRIB, 0); foreach ($contrib_ids as $contrib_id) { $row = self::$contribs[$contrib_id]; $contrib->__set_array($row); $contrib->author->user_id = $contrib->contrib_user_id; $contrib->author->__set_array($row); // Author contrib variables $contrib->is_author = $contrib->contrib_user_id == phpbb::$user->data['user_id'] ? true : false; $contrib->is_active_coauthor = in_array($contrib->contrib_id, $author_contribs) ? true : false; // Store the tracking info we grabbed from the DB titania_tracking::store_from_db($row); // Get the folder image $folder_img = $folder_alt = ''; $last_read_mark = titania_tracking::get_track(TITANIA_CONTRIB, $contrib->contrib_id, true); $last_complete_mark = titania_tracking::get_track(TITANIA_CONTRIB, 0, true); $is_unread = $contrib->contrib_last_update > $last_read_mark && $contrib->contrib_last_update > $last_complete_mark ? true : false; titania_topic_folder_img($folder_img, $folder_alt, 0, $is_unread); // Only get unique phpBB versions supported if (isset($row['phpbb_versions'])) { titania::_include('functions_display', 'order_phpbb_version_list_from_db'); $ordered_phpbb_versions = order_phpbb_version_list_from_db($row['phpbb_versions']); } phpbb::$template->assign_block_vars($blockname, array_merge($contrib->assign_details(true, true), array('FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'), 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'), 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height'), 'PHPBB_VERSION' => isset($row['phpbb_versions']) && sizeof($ordered_phpbb_versions) == 1 ? $ordered_phpbb_versions[0] : ''))); if (isset($row['phpbb_versions'])) { foreach ($ordered_phpbb_versions as $version_row) { phpbb::$template->assign_block_vars($blockname . '.phpbb_versions', array('NAME' => $version_row)); } } $contrib_type = $row['contrib_type']; } unset($contrib); return compact('sort'); }
public function queue($mode, $queue_id = false) { switch ($mode) { case 'update_first_queue_post': $queue = new titania_queue(); $contrib = new titania_contribution(); $sql = 'SELECT * FROM ' . TITANIA_QUEUE_TABLE . ' q, ' . TITANIA_CONTRIBS_TABLE . ' c WHERE c.contrib_id = q.contrib_id' . ($queue_id ? ' AND queue_id = ' . (int) $queue_id : ''); $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $contrib->__set_array($row); $queue->__set_array($row); $queue->update_first_queue_post(false, $contrib); } phpbb::$db->sql_freeresult($result); unset($queue); break; case 'revision_queue_id': $sql = 'SELECT queue_id, revision_id FROM ' . TITANIA_QUEUE_TABLE; $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $sql = 'UPDATE ' . TITANIA_REVISIONS_TABLE . ' SET revision_queue_id = ' . (int) $row['queue_id'] . ' WHERE revision_id = ' . (int) $row['revision_id']; phpbb::$db->sql_query($sql); } phpbb::$db->sql_freeresult($result); break; } }
function main($id, $mode) { global $phpbb_root_path; define('PHPBB_INCLUDED', true); define('USE_PHPBB_TEMPLATE', true); define('IN_TITANIA', true); if (!defined('PHP_EXT')) { define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); } require TITANIA_ROOT . 'common.' . PHP_EXT; // Need a few hacks to be used from within phpBB titania_url::decode_url(titania::$config->phpbb_script_path); titania::$hook->register(array('titania_url', 'build_url'), 'titania_outside_build_url', 'standalone'); titania::$hook->register(array('titania_url', 'append_url'), 'titania_outside_build_url', 'standalone'); titania::$hook->register(array('titania', 'page_header'), 'titania_outside_page_header', 'standalone'); titania::$hook->register(array('titania', 'page_footer'), 'titania_outside_page_footer', 'standalone'); $this->p_master->assign_tpl_vars(phpbb::append_sid('ucp')); // Include some files titania::_include('functions_display', 'titania_topic_folder_img'); // Setup the sort tool $sort = new titania_sort(); $sort->default_limit = phpbb::$config['topics_per_page']; $sort->request(); // Start initial var setup $url = $this->u_action; add_form_key('ucp_front_subscription'); // User wants to unsubscribe? if (isset($_POST['unsubscribe'])) { if (check_form_key('ucp_front_subscription')) { $sections = request_var('sections', array(0 => array(0 => 0))); $items = request_var('items', array(0 => array(0 => 0))); $subscriptions = $sections + $items; if (sizeof($subscriptions)) { foreach ($subscriptions as $type => $type_id) { $object_ids = array_keys($type_id); foreach ($object_ids as $object_id) { $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . ' WHERE watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND watch_object_type = ' . $type . ' AND watch_object_id = ' . $object_id; phpbb::$db->sql_query($sql); } } } else { $msg = phpbb::$user->lang['NO_SUBSCRIPTIONS_SELECTED']; } } else { $msg = phpbb::$user->lang['FORM_INVALID']; } if (isset($msg)) { meta_refresh(3, $url); $message = $msg . '<br /><br />' . sprintf(phpbb::$user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>'); trigger_error($message); } } switch ($mode) { case 'subscription_items': $array_items = array(TITANIA_CONTRIB, TITANIA_TOPIC); // We prepare pagination stuff $sql = 'SELECT COUNT(*) AS subscription_count FROM ' . TITANIA_WATCH_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . ' AND watch_user_id = ' . phpbb::$user->data['user_id']; phpbb::$db->sql_query($sql); $subscription_count = phpbb::$db->sql_fetchfield('subscription_count'); phpbb::$db->sql_freeresult(); $sort->total = $subscription_count; $sort->build_pagination($url); $sql_ary = array('SELECT' => '*, CASE w.watch_object_type WHEN ' . TITANIA_CONTRIB . ' THEN c.contrib_last_update WHEN ' . TITANIA_TOPIC . ' THEN t.topic_last_post_time END AS time', 'FROM' => array(TITANIA_WATCH_TABLE => 'w'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => '(w.watch_object_type = ' . TITANIA_CONTRIB . ') AND c.contrib_id = w.watch_object_id'), array('FROM' => array(TITANIA_TOPICS_TABLE => 't'), 'ON' => 'w.watch_object_type = ' . TITANIA_TOPIC . ' AND t.topic_id = w.watch_object_id')), 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items), 'ORDER_BY' => 'time DESC'); // Additional tracking for support topics titania_tracking::get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id'); titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tsa'); titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tsc'); titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); // Tracking for contributions titania_tracking::get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id', 'tc'); $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $user_ids = $rows = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { $rows[] = $row; titania_tracking::store_from_db($row); if ($row['watch_object_type'] == TITANIA_TOPIC) { $user_ids[] = $row['topic_first_post_user_id']; $user_ids[] = $row['topic_last_post_user_id']; } else { if ($row['watch_object_type'] == TITANIA_CONTRIB) { $user_ids[] = $row['contrib_user_id']; } } } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); foreach ($rows as $row) { $folder_img = $folder_alt = ''; if ($row['watch_object_type'] == TITANIA_TOPIC) { if (!$row['topic_id']) { // Topic was deleted $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . ' WHERE watch_object_type = ' . (int) $row['watch_object_type'] . ' AND watch_object_id = ' . (int) $row['watch_object_id']; phpbb::$db->sql_query($sql); continue; } $topic = new titania_topic(); $topic->__set_array($row); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); $tpl_block = 'items'; $subscription_target = ''; if ($row['topic_type'] == TITANIA_QUEUE_DISCUSSION) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE_VALIDATION']; } if ($row['topic_type'] == TITANIA_QUEUE) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE']; } if ($row['topic_type'] == TITANIA_SUPPORT) { $subscription_target = phpbb::$user->lang['SUBSCRIPTION_SUPPORT_TOPIC']; } // Tracking check $last_read_mark = titania_tracking::get_track(TITANIA_TOPIC, $topic->topic_id, true); $last_read_mark = max($last_read_mark, titania_tracking::find_last_read_mark($topic->additional_unread_fields, $topic->topic_type, $topic->parent_id)); $topic->unread = $topic->topic_last_post_time > $last_read_mark ? true : false; // Get the folder image $topic->topic_folder_img($folder_img, $folder_alt); $vars = array('LAST_POST_IMG' => phpbb::$user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['topic_first_post_user_id'], '_full'), 'SUBSCRIPTION_ID' => $row['topic_id'], 'SUBSCRIPTION_LAST_AUTHOR_FULL' => users_overlord::get_user($row['topic_last_post_user_id'], '_full'), 'SUBSCRIPTION_LAST_TIME' => phpbb::$user->format_date($row['topic_last_post_time']), 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['topic_time']), 'SUBSCRIPTION_TARGET' => $subscription_target, 'SUBSCRIPTION_TITLE' => censor_text($row['topic_subject']), 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'U_VIEW_SUBSCRIPTION' => $topic->get_url(), 'U_VIEW_LAST_POST' => titania_url::append_url($topic->get_url(), array('p' => $topic->topic_last_post_id, '#p' => $topic->topic_last_post_id)), 'S_ACCESS_TEAMS' => $row['topic_access'] == TITANIA_ACCESS_TEAMS || $row['topic_type'] == TITANIA_QUEUE ? true : false, 'S_ACCESS_AUTHORS' => $row['topic_access'] == TITANIA_ACCESS_AUTHORS ? true : false, 'S_TOPIC' => true); } else { if ($row['watch_object_type'] == TITANIA_CONTRIB) { $tpl_block = 'items'; $contrib = new titania_contribution(); $contrib->__set_array($row); titania_topic_folder_img($folder_img, $folder_alt, 0, titania_tracking::is_unread(TITANIA_CONTRIB, $contrib->contrib_id, $contrib->contrib_last_update)); $vars = array('SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'), 'SUBSCRIPTION_CONTRIB_TYPE' => titania_types::$types[$contrib->contrib_type]->lang, 'SUBSCRIPTION_DOWNLOADS' => $row['contrib_downloads'], 'SUBSCRIPTION_ID' => $row['contrib_id'], 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_CONTRIB'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']), 'SUBSCRIPTION_TITLE' => $row['contrib_name'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'SUBSCRIPTION_VIEWS' => $row['contrib_views'], 'U_VIEW_SUBSCRIPTION' => $contrib->get_url(), 'S_CONTRIB' => true); } } phpbb::$template->assign_block_vars($tpl_block, array_merge($vars, array('FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'), 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'), 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height')))); } break; case 'subscription_sections': $array_items = array(TITANIA_SUPPORT, TITANIA_QUEUE, TITANIA_ATTENTION); // We prepare pagination stuff $sql = 'SELECT COUNT(*) AS subscription_count FROM ' . TITANIA_WATCH_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . ' AND watch_user_id = ' . phpbb::$user->data['user_id']; phpbb::$db->sql_query($sql); $subscription_count = phpbb::$db->sql_fetchfield('subscription_count'); phpbb::$db->sql_freeresult(); $sort->total = $subscription_count; $sort->build_pagination($url); $sql_ary = array('SELECT' => '*, CASE w.watch_object_type WHEN ' . TITANIA_SUPPORT . ' THEN c.contrib_last_update END AS time', 'FROM' => array(TITANIA_WATCH_TABLE => 'w'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => '(w.watch_object_type = ' . TITANIA_SUPPORT . ') AND c.contrib_id = w.watch_object_id')), 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . ' AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items), 'ORDER_BY' => 'time DESC'); $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $user_ids = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { $rows[] = $row; $user_ids[] = $row['contrib_user_id']; } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); if (isset($rows)) { foreach ($rows as $row) { if ($row['watch_object_type'] == TITANIA_SUPPORT) { $tpl_block = 'sections'; $contrib = new titania_contribution(); $contrib->__set_array($row); $vars = array('SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'), 'SUBSCRIPTION_ID' => $row['watch_object_id'], 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_SUPPORT'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']), 'SUBSCRIPTION_TITLE' => $row['contrib_name'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'U_VIEW_SUBSCRIPTION' => $contrib->get_url('support')); } else { if ($row['watch_object_type'] == TITANIA_ATTENTION) { $tpl_block = 'sections'; $vars = array('SUBSCRIPTION_ID' => $row['watch_object_id'], 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_ATTENTION'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_ATTENTION' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => titania_url::build_url('manage/attention')); } else { if ($row['watch_object_type'] == TITANIA_QUEUE) { $tpl_block = 'sections'; $queue_id = $row['watch_object_id']; // Setup the base url we will use $base_url = titania_url::build_url('manage/queue'); $vars = array('SUBSCRIPTION_ID' => $queue_id, 'SUBSCRIPTION_TARGET' => titania_types::$types[$queue_id]->lang, 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_QUEUE'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_QUEUE' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => titania_url::append_url($base_url, array('queue' => titania_types::$types[$queue_id]->url))); } } } phpbb::$template->assign_block_vars($tpl_block, $vars); } } break; } phpbb::$template->assign_vars(array('S_ACTION' => $url, 'TITANIA_THEME_PATH' => titania::$absolute_path . 'styles/' . titania::$config->style . '/theme/')); titania::page_header(phpbb::$user->lang['SUBSCRIPTION_TITANIA']); titania::page_footer(true, 'manage/' . $mode . '.html'); }
/** * Generate report message for a change in description. * * @return string */ protected function get_description_change($old_settings) { $contrib = new \titania_contribution(); $contrib->__set_array($old_settings); $old_description = $contrib->generate_text_for_edit(); $old_description = $old_description['text']; $description = $this->contrib->generate_text_for_edit(); $description = $description['text']; return $old_description !== $description ? "{$old_description}>>>>>>>>>>{$description}" : ''; }
/** * Run the tool */ function run_tool() { // Define some vars that we'll need $start = request_var('start', 0); $limit = 100; // Create topic if it does not exist? $create_topic = true; titania::_include('functions_posting', 'phpbb_posting'); titania::add_lang('contributions'); $types = array(); foreach (titania_types::$types as $id => $class) { if ($class->forum_robot && $class->forum_database) { $types[] = $id; } } if (!sizeof($types)) { trigger_back('UPDATE_RELEASE_TOPICS_COMPLETE'); } $sql = 'SELECT COUNT(contrib_id) AS cnt FROM ' . TITANIA_CONTRIBS_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . ' AND ' . phpbb::$db->sql_in_set('contrib_type', $types); phpbb::$db->sql_query($sql); $total = phpbb::$db->sql_fetchfield('cnt'); phpbb::$db->sql_freeresult(); // Grab our batch $sql_ary = array('SELECT' => 'c.contrib_id, c.contrib_user_id, c.contrib_type, c.contrib_name, c.contrib_name_clean, c.contrib_desc, c.contrib_desc_uid, c.contrib_release_topic_id, t.topic_first_post_id, u.user_id, u.username, u.username_clean, u.user_colour', 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c', USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 't.topic_id = c.contrib_release_topic_id')), 'GROUP_BY' => 'c.contrib_id', 'WHERE' => phpbb::$db->sql_in_set('c.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . ' AND u.user_id = c.contrib_user_id AND ' . phpbb::$db->sql_in_set('contrib_type', $types), 'ORDER_BY' => 'c.contrib_id DESC'); $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); $result = phpbb::$db->sql_query_limit($sql, $limit, $start); while ($row = phpbb::$db->sql_fetchrow($result)) { // Grab the revisions $revisions = array(); $sql = 'SELECT r.revision_id, r.attachment_id, r.revision_version, a.real_filename, a.filesize FROM ' . TITANIA_REVISIONS_TABLE . ' r, ' . TITANIA_ATTACHMENTS_TABLE . ' a WHERE r.contrib_id = ' . $row['contrib_id'] . ' AND r.revision_status = ' . TITANIA_REVISION_APPROVED . ' AND a.attachment_id = r.attachment_id'; $rev_result = phpbb::$db->sql_query($sql); while ($rev_row = phpbb::$db->sql_fetchrow($rev_result)) { $revisions[$rev_row['revision_version']] = $rev_row; } phpbb::$db->sql_freeresult($rev_result); // Sort the revisions by their version, put the newest one in $revision uksort($revisions, 'reverse_version_compare'); if (!sizeof($revisions)) { continue; } $revision = array_shift($revisions); users_overlord::$users[$row['user_id']] = $row; $contrib = new titania_contribution(); $contrib->__set_array($row); $contrib->download = $row; // Update the release topic $contrib->update_release_topic(); } phpbb::$db->sql_freeresult($result); if ($start + $limit >= $total) { trigger_back('UPDATE_RELEASE_TOPICS_COMPLETE'); } else { meta_refresh(0, titania_url::build_url('manage/administration', array('t' => 'update_release_topics', 'start' => $start + $limit, 'submit' => 1, 'hash' => generate_link_hash('manage')))); trigger_error(phpbb::$user->lang('UPDATE_RELEASE_TOPICS_PROGRESS', $start + $limit, $total)); } }
/** * Sync queue * * @param string $mode * @param int|bool $queue_id (Optional) Queue id to limit to. Defaults to false. */ public function queue($mode, $queue_id = false) { switch ($mode) { case 'update_first_queue_post': $queue = new \titania_queue(); $contrib = new \titania_contribution(); $sql = 'SELECT * FROM ' . $this->queue_table . ' q, ' . $this->contribs_table . ' c WHERE c.contrib_id = q.contrib_id' . ($queue_id ? ' AND queue_id = ' . (int) $queue_id : ''); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $contrib->__set_array($row); $contrib->set_type($row['contrib_type']); $queue->__set_array($row); $queue->update_first_queue_post(false, $contrib); } $this->db->sql_freeresult($result); unset($queue); break; case 'revision_queue_id': $sql = 'SELECT queue_id, revision_id FROM ' . $this->queue_table; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $sql = 'UPDATE ' . $this->revisions_table . ' SET revision_queue_id = ' . (int) $row['queue_id'] . ' WHERE revision_id = ' . (int) $row['revision_id']; $this->db->sql_query($sql); } $this->db->sql_freeresult($result); break; } }
/** * Display "forum" like section for support/tracker/etc * * @param string $type The type (support, review, queue, tracker, author_support, author_tracker) author_ for displaying posts from the areas the given author is involved in (either an author/co-author) * @param object|boolean $object The object (for contrib related (support, review, queue, tracker) and author_ modes) * @param object|boolean $sort The sort object (includes/tools/sort.php) * @param array $options Some special options * @param string $contrib_type The type of the support topic list */ public static function display_forums($type, $object = false, $sort = false, $options = array()) { if ($sort === false) { // Setup the sort tool $sort = self::build_sort(); } $sort->request(); $topic_ids = array(); $switch_on_sticky = true; // Display the extra block after stickies end? Not used when not sorting with stickies first $sql_ary = array('SELECT' => 't.*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour', 'FROM' => array(TITANIA_TOPICS_TABLE => 't'), 'WHERE' => self::sql_permissions('t.', false, true), 'ORDER_BY' => 't.topic_sticky DESC, ' . $sort->get_order_by()); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 't.topic_first_post_user_id = u.user_id'); $sql_ary['LEFT_JOIN'][] = array('FROM' => array(USERS_TABLE => 'ul'), 'ON' => 't.topic_last_post_user_id = ul.user_id'); titania_tracking::get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id'); // Setup the contribution/topic we will use for parsing the output (before the switch so we are able to do type specific things for it) $topic = new titania_topic(); $contrib = new titania_contribution(); // type specific things switch ($type) { case 'tracker': $page_url = $object->get_url('tracker'); $sql_ary['WHERE'] .= ' AND t.parent_id = ' . (int) $object->contrib_id; $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_TRACKER; if (isset($options['category'])) { $sql_ary['WHERE'] .= ' AND t.topic_category = ' . (int) $options['category']; } break; case 'queue': $page_url = titania_url::build_url('manage/queue'); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_QUEUE; break; case 'queue_discussion': $page_url = titania_url::build_url('manage/queue_discussion', array('queue' => titania_types::$types[$options['topic_category']]->url)); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_QUEUE_DISCUSSION; // Only display those in which the users are authed $authed = titania_types::find_authed('queue_discussion'); if (!sizeof($authed)) { return compact('sort'); } if (isset($options['topic_category'])) { if (!in_array((int) $options['topic_category'], $authed)) { return compact('sort'); } $sql_ary['WHERE'] .= ' AND t.topic_category = ' . (int) $options['topic_category']; } else { $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.topic_category', $authed); } // Additional tracking for all queue discussion topics titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); // Additional tracking for marking items as read in each contribution titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tst'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); break; case 'author_support': $page_url = $object->get_url('support'); $contrib_ids = titania::$cache->get_author_contribs($object->user_id, true); $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.parent_id', array_map('intval', $contrib_ids)); // We also display the queue discussion topic between validators and authors in the support area $sql_ary['WHERE'] .= ' AND (t.topic_type = ' . TITANIA_SUPPORT . ' OR t.topic_type = ' . TITANIA_QUEUE_DISCUSSION . ')'; // Additional tracking for marking items as read in each contribution titania_tracking::get_tracks(TITANIA_SUPPORT, $contrib_ids); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); // Additional tracking for all support topics titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0, 'type_match' => true); // Track the queue discussion too if applicable if (titania_types::find_authed('queue_discussion')) { titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); } // Try to grab the category/contrib name $sql_ary['SELECT'] .= ', contrib.contrib_name, contrib.contrib_name_clean, contrib.contrib_id, contrib.contrib_type'; $sql_ary['LEFT_JOIN'] = array_merge(isset($sql_ary['LEFT_JOIN']) ? $sql_ary['LEFT_JOIN'] : array(), array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'contrib'), 'ON' => 'contrib.contrib_id = t.parent_id'))); // Do not order stickies first $sql_ary['ORDER_BY'] = $sort->get_order_by(); $switch_on_sticky = false; break; case 'author_tracker': $page_url = $object->get_url('tracker'); $contrib_ids = titania::$cache->get_author_contribs($object->user_id); $sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('t.parent_id', array_map('intval', $contrib_ids)); $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_TRACKER; break; case 'all_support': // Try to grab the category/contrib name $sql_ary['SELECT'] .= ', contrib.contrib_name, contrib.contrib_name_clean, contrib.contrib_id, contrib.contrib_type'; $sql_ary['LEFT_JOIN'] = array_merge(isset($sql_ary['LEFT_JOIN']) ? $sql_ary['LEFT_JOIN'] : array(), array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'contrib'), 'ON' => 'contrib.contrib_id = t.parent_id'))); if (isset(titania_types::$types[$options['contrib_type']])) { $page_url = titania_url::build_url('support/' . titania_types::$types[$options['contrib_type']]->url); $sql_ary['WHERE'] .= ' AND contrib.contrib_type = ' . $options['contrib_type']; } else { $page_url = titania_url::build_url('support/all'); } // Additional tracking field (to allow marking all support/discussion as read) $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_SUPPORT; // Additional tracking for all support topics titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0); // Do not order stickies first $sql_ary['ORDER_BY'] = $sort->get_order_by(); $switch_on_sticky = false; break; case 'support': default: $page_url = $object->get_url('support'); $sql_ary['WHERE'] .= ' AND t.parent_id = ' . (int) $object->contrib_id; // We also display the queue discussion topic between validators and authors in the support area if ($object->is_author || $object->is_active_coauthor || titania_types::$types[$object->contrib_type]->acl_get('queue_discussion')) { $sql_ary['WHERE'] .= ' AND (t.topic_type = ' . TITANIA_SUPPORT . ' OR t.topic_type = ' . TITANIA_QUEUE_DISCUSSION . ')'; } else { $sql_ary['WHERE'] .= ' AND t.topic_type = ' . TITANIA_SUPPORT; } // Additional tracking for marking items as read in each contribution titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, $object->contrib_id, 'tst'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true); // Additional tracking for all support topics titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tstg'); $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0); // Track the queue discussion too if applicable if (titania_types::$types[$object->contrib_type]->acl_get('queue_discussion')) { titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt'); $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true); } break; } // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 't.topic_id')) { // No results...no need to query more... return compact('sort'); } $sort->build_pagination($page_url); $last_was_sticky = false; // Get the data $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); while ($row = phpbb::$db->sql_fetchrow($result)) { // Store the tracking info we grabbed from the DB titania_tracking::store_from_db($row); self::$topics[$row['topic_id']] = $row; $topic->__set_array($row); $contrib->__set_array($row); phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array('S_TOPIC_TYPE_SWITCH' => $switch_on_sticky && $last_was_sticky && !$topic->topic_sticky ? true : false, 'CONTRIB_TYPE' => isset($row['contrib_type']) && $row['contrib_type'] ? titania_types::$types[$row['contrib_type']]->lang : '', 'TOPIC_CONTRIB_NAME' => isset($row['contrib_name']) && $row['contrib_name'] ? censor_text($row['contrib_name']) : '', 'U_VIEW_TOPIC_CONTRIB' => isset($row['contrib_type']) && $row['contrib_type'] ? $contrib->get_url() : '', 'U_VIEW_TOPIC_CONTRIB_SUPPORT' => isset($row['contrib_type']) && $row['contrib_type'] ? $contrib->get_url('support') : ''))); $last_was_sticky = $topic->topic_sticky; } phpbb::$db->sql_freeresult($result); unset($topic); return compact('sort'); }
/** * Update contrib release topics. * * @param array $row Contrib data array */ protected function update_contrib(array $row) { \users_overlord::$users[$row['user_id']] = $row; $contrib = new \titania_contribution(); $contrib->__set_array($row); $contrib->set_type($row['contrib_type']); $contrib->author = new \titania_author(); $contrib->author->__set_array($row); // Update the release topic $contrib->update_release_topic(); }
/** * Get contrib object. * * @param array $data Contribution data * @return \titania_contribution */ protected function get_contrib($data) { $contrib = new \titania_contribution(); $contrib->__set_array($data); $contrib->set_type($data['contrib_type']); return $contrib; }
titania::add_lang('manage'); if (!class_exists('titania_type_translation')) { require TITANIA_ROOT . 'includes/types/translation.php'; } // Give founders access to run this if (phpbb::$user->data['user_type'] != USER_FOUNDER) { titania::needs_auth(); } // Hopefully this helps @set_time_limit(0); // Delete all translations $contrib = new titania_contribution(); $sql = 'SELECT * FROM ' . TITANIA_CONTRIBS_TABLE . ' WHERE contrib_type = ' . TITANIA_TYPE_TRANSLATION; $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $contrib->__set_array($row); $contrib->delete(); } phpbb::$db->sql_freeresult($result); // All the language packs we'll need, we wont transfer inactive ones, they need to be cleaned up anyways $sql = 'SELECT * FROM lang_packs WHERE display > 0 AND version = 3'; $result = $db->sql_query($sql); // All the authors we'll need $sql2 = 'SELECT * FROM lang_packs_authors WHERE lang_id IN ( SELECT lang_id FROM lang_packs WHERE display > 0 ) '; $authors = $db->sql_fetchrowset($db->sql_query($sql2)); $i = 0; while ($row = $db->sql_fetchrow($result)) { $permalink = titania_url::url_slug($row['english_name']); $conflict = $cnt = false; do { $permalink_test = $cnt !== false ? $permalink . '_' . $cnt : $permalink;
/** * Assign variables to the template */ public function assign_details() { if (!sizeof($this->styles)) { return false; } // Get siblings $prev = $this->sibling($this->default_style, 'prev'); $next = $this->sibling($this->default_style, 'next'); $this->template->assign_vars(array('U_PREV' => $prev['url'], 'PREV_ID' => $prev['id'], 'U_NEXT' => $next['url'], 'NEXT_ID' => $next['id'])); $category = ''; $style = new \titania_contribution(); $style->set_type(TITANIA_TYPE_STYLE); $style->options = array('demo' => true); foreach ($this->styles as $id => $data) { $style->__set_array(array('contrib_id' => $id, 'contrib_name_clean' => $data['contrib_name_clean'], 'contrib_demo' => $data['contrib_demo'])); $preview_img = false; if (isset($data['thumb_id'])) { $parameters = array('id' => $data['thumb_id']); if ($data['thumbnail']) { $parameters += array('mode' => 'view', 'thumb' => 1); } $preview_img = $this->controller_helper->route('phpbb.titania.download', $parameters); } $authors = $this->get_author_profile(array('username_clean' => $data['username_clean'], 'username' => $data['username'], 'user_id' => $data['contrib_user_id'], 'user_colour' => $data['user_colour'])); $authors .= $data['coauthors']; $data['category_name'] = $this->user->lang($data['category_name']); $phpbb_version = $data['phpbb_versions']['branch'][0] . '.' . $data['phpbb_versions']['branch'][1] . '.' . $data['phpbb_versions']['revision']; $current_phpbb_version = $data['phpbb_versions']['branch'][0] . '.' . $data['phpbb_versions']['branch'][1] . '.' . $this->ext_config->phpbb_versions[$data['phpbb_versions']['branch']]['latest_revision']; $vars = array('AUTHORS' => $authors, 'CATEGORY' => $category != $data['category_name'] ? $data['category_name'] : false, 'ID' => $id, 'IFRAME' => $style->get_demo_url($this->phpbb_branch), 'LICENSE' => $data['revision_license'] ? $data['revision_license'] : $this->user->lang['UNKNOWN'], 'NAME' => $data['contrib_name'], 'PHPBB_VERSION' => $phpbb_version, 'PREVIEW' => $preview_img, 'S_OUTDATED' => phpbb_version_compare($phpbb_version, $current_phpbb_version, '<'), 'U_DEMO' => $style->get_demo_url($this->phpbb_branch, true), 'U_DOWNLOAD' => $this->controller_helper->route('phpbb.titania.download', array('id' => $data['attachment_id'])), 'U_VIEW' => $style->get_url()); if ($this->default_style == $id) { $this->template->assign_vars($vars); } $category = $data['category_name']; $this->template->assign_block_vars('stylerow', $vars); unset($this->styles[$id], $vars, $this->coauthors[$id]); } }
/** * Display contributions * * @param string $mode The mode (category, author) * @param int $id The parent id (only show contributions under this category, author, etc) * @param int|bool $branch Branch to limit results to: 20|30|31. Defaults to false. * @param \phpbb\titania\sort|bool $sort * @param string $blockname The name of the template block to use (contribs by default) * * @return array */ public static function display_contribs($mode, $id, $branch = false, $sort = false, $blockname = 'contribs') { phpbb::$user->add_lang_ext('phpbb/titania', 'contributions'); $tracking = phpbb::$container->get('phpbb.titania.tracking'); $types = phpbb::$container->get('phpbb.titania.contribution.type.collection'); // Setup the sort tool if not sent, then request if ($sort === false) { $sort = self::build_sort(); } $sort->request(); $branch = $branch ? (int) $branch : null; $select = 'DISTINCT(c.contrib_id), c.contrib_name, c.contrib_name_clean, c.contrib_status, c.contrib_downloads, c.contrib_views, c.contrib_rating, c.contrib_rating_count, c.contrib_type, c.contrib_last_update, c.contrib_user_id, c.contrib_limited_support, c.contrib_categories, c.contrib_desc, c.contrib_desc_uid'; switch ($mode) { case 'author': // Get the contrib_ids this user is an author in (includes as a co-author) $contrib_ids = titania::$cache->get_author_contribs($id, $types, phpbb::$user); if (!sizeof($contrib_ids)) { return compact('sort'); } $sql_ary = array('SELECT' => $select . ', a.attachment_id, a.thumbnail', 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_ATTACHMENTS_TABLE => 'a'), 'ON' => 'c.contrib_id = a.object_id AND a.object_type = ' . TITANIA_SCREENSHOT . ' AND a.is_orphan = 0 AND a.is_preview = 1')), 'WHERE' => phpbb::$db->sql_in_set('c.contrib_id', $contrib_ids) . ' AND c.contrib_visible = 1', 'ORDER_BY' => $sort->get_order_by()); break; case 'category': $sql_ary = array('SELECT' => $select . ', a.attachment_id, a.thumbnail', 'FROM' => array(TITANIA_CONTRIB_IN_CATEGORIES_TABLE => 'cic'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => 'cic.contrib_id = c.contrib_id'), array('FROM' => array(TITANIA_REVISIONS_PHPBB_TABLE => 'rp'), 'ON' => 'cic.contrib_id = rp.contrib_id'), array('FROM' => array(TITANIA_ATTACHMENTS_TABLE => 'a'), 'ON' => 'c.contrib_id = a.object_id AND a.object_type = ' . TITANIA_SCREENSHOT . ' AND a.is_orphan = 0 AND a.is_preview = 1')), 'WHERE' => (is_array($id) && sizeof($id) ? phpbb::$db->sql_in_set('cic.category_id', array_map('intval', $id)) : 'cic.category_id = ' . (int) $id) . ' AND c.contrib_visible = 1' . ($branch ? " AND rp.phpbb_version_branch = {$branch}" : ''), 'ORDER_BY' => $sort->get_order_by()); break; case 'all': $sql_ary = array('SELECT' => $select . ', a.attachment_id, a.thumbnail', 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_REVISIONS_PHPBB_TABLE => 'rp'), 'ON' => 'c.contrib_id = rp.contrib_id'), array('FROM' => array(TITANIA_ATTACHMENTS_TABLE => 'a'), 'ON' => 'c.contrib_id = a.object_id AND a.object_type = ' . TITANIA_SCREENSHOT . ' AND a.is_orphan = 0 AND a.is_preview = 1')), 'WHERE' => 'c.contrib_visible = 1' . ($branch ? " AND rp.phpbb_version_branch = {$branch}" : ''), 'ORDER_BY' => $sort->get_order_by()); break; } $tracking->get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id'); $mod_contrib_mod = (bool) phpbb::$auth->acl_get('u_titania_mod_contrib_mod'); // Permissions if (!$mod_contrib_mod) { $sql_ary['SELECT'] .= ', cc.user_id AS coauthor'; $sql_ary['LEFT_JOIN'][] = array('FROM' => array(TITANIA_CONTRIB_COAUTHORS_TABLE => 'cc'), 'ON' => 'cc.contrib_id = c.contrib_id AND cc.user_id = ' . phpbb::$user->data['user_id']); $view_unapproved = array(); if ($types->find_authed('moderate')) { $view_unapproved = array_merge($view_unapproved, $types->find_authed('moderate')); } if ($types->find_authed('view')) { $view_unapproved = array_merge($view_unapproved, $types->find_authed('view')); } $view_unapproved = array_unique($view_unapproved); $sql_ary['WHERE'] .= ' AND (' . phpbb::$db->sql_in_set('c.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . (sizeof($view_unapproved) ? ' OR ' . phpbb::$db->sql_in_set('c.contrib_type', array_map('intval', $view_unapproved)) : '') . ' OR c.contrib_user_id = ' . phpbb::$user->data['user_id'] . ' OR cc.active = 1)'; } // Main SQL Query $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary); // Handle pagination if (!$sort->sql_count($sql_ary, 'DISTINCT(c.contrib_id)')) { // No results...no need to query more... return compact('sort'); } $controller_helper = phpbb::$container->get('controller.helper'); $path_helper = phpbb::$container->get('path_helper'); $access = phpbb::$container->get('phpbb.titania.access'); $url = $path_helper->get_url_parts($controller_helper->get_current_url()); $sort->build_pagination($url['base']); $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start); $contrib_ids = $user_ids = array(); while ($row = phpbb::$db->sql_fetchrow($result)) { //Check to see if user has permission if (!$mod_contrib_mod && $row['contrib_user_id'] != phpbb::$user->data['user_id'] && $row['coauthor'] != phpbb::$user->data['user_id'] && !$access->is_team()) { //If the contribution has a status that is not accessible by the current user let's not add it if (in_array($row['contrib_status'], array(TITANIA_CONTRIB_NEW, TITANIA_CONTRIB_CLEANED, TITANIA_CONTRIB_HIDDEN, TITANIA_CONTRIB_DISABLED))) { continue; } } $user_ids[] = $row['contrib_user_id']; $contrib_ids[] = $row['contrib_id']; self::$contribs[$row['contrib_id']] = $row; } phpbb::$db->sql_freeresult($result); // Get user data users_overlord::load_users($user_ids); // Get phpBB versions if (sizeof($contrib_ids)) { $validation_free = $types->find_validation_free(); if (sizeof($validation_free) && titania::$config->require_validation) { $sql = 'SELECT rp.contrib_id, rp.phpbb_version_branch, rp.phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' rp, ' . TITANIA_CONTRIBS_TABLE . ' c WHERE ' . phpbb::$db->sql_in_set('rp.contrib_id', array_map('intval', $contrib_ids)) . ' AND c.contrib_id = rp.contrib_id AND (rp.revision_validated = 1 OR ' . phpbb::$db->sql_in_set('c.contrib_type', $validation_free) . ') ORDER BY rp.row_id DESC'; } else { $sql = 'SELECT contrib_id, phpbb_version_branch, phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' WHERE ' . phpbb::$db->sql_in_set('contrib_id', array_map('intval', $contrib_ids)) . (titania::$config->require_validation ? ' AND revision_validated = 1' : '') . ' ORDER BY row_id DESC'; } $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { self::$contribs[$row['contrib_id']]['phpbb_versions'][] = $row; } phpbb::$db->sql_freeresult($result); } // Setup some objects we'll use for temps $contrib = new titania_contribution(); $contrib->author = new titania_author(); $versions = titania::$cache->get_phpbb_versions(); $author_contribs = titania::$cache->get_author_contribs(phpbb::$user->data['user_id'], $types, phpbb::$user, true); // Get the mark all tracking $tracking->get_track(TITANIA_CONTRIB, 0); foreach ($contrib_ids as $contrib_id) { $row = self::$contribs[$contrib_id]; $contrib->__set_array($row); $contrib->set_type($row['contrib_type']); $contrib->author->user_id = $contrib->contrib_user_id; $contrib->author->__set_array($row); $contrib->fill_categories(); // Author contrib variables $contrib->is_author = $contrib->contrib_user_id == phpbb::$user->data['user_id'] ? true : false; $contrib->is_active_coauthor = in_array($contrib->contrib_id, $author_contribs) ? true : false; $rating = new \titania_rating('contrib', $contrib); $rating->cannot_rate = true; $contrib->rating = $rating; // Store the tracking info we grabbed from the DB $tracking->store_from_db($row); // Get the folder image $folder_img = $folder_alt = ''; $last_read_mark = $tracking->get_track(TITANIA_CONTRIB, $contrib->contrib_id, true); $last_complete_mark = $tracking->get_track(TITANIA_CONTRIB, 0, true); $is_unread = $contrib->contrib_last_update > $last_read_mark && $contrib->contrib_last_update > $last_complete_mark ? true : false; phpbb::$container->get('phpbb.titania.display')->topic_folder_img($folder_img, $folder_alt, 0, $is_unread); // Only get unique phpBB versions supported if (isset($row['phpbb_versions'])) { $ordered_phpbb_versions = versions::order_phpbb_version_list_from_db(titania::$cache, $row['phpbb_versions'], $contrib->options['all_versions']); } $preview_params = array(); $stripped_desc = message::generate_clean_excerpt($contrib->contrib_desc, $contrib->contrib_desc_uid, 255, '…'); if (!empty($row['attachment_id'])) { $preview_params['id'] = $row['attachment_id']; if ($row['thumbnail']) { $preview_params['thumb'] = 1; } } phpbb::$template->assign_block_vars($blockname, array_merge($contrib->assign_details(true, true), array('FOLDER_STYLE' => $folder_img, 'FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'), 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'), 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height'), 'PHPBB_VERSION' => isset($row['phpbb_versions']) && sizeof($ordered_phpbb_versions) == 1 ? $ordered_phpbb_versions[0] : '', 'DESC_SNIPPET' => $stripped_desc, 'PREVIEW' => $preview_params ? $controller_helper->route('phpbb.titania.download', $preview_params) : ''))); if (isset($row['phpbb_versions'])) { $prev_branch = ''; foreach ($ordered_phpbb_versions as $version_row) { phpbb::$template->assign_block_vars($blockname . '.phpbb_versions', array('NAME' => $version_row)); $branch = versions::get_branch_from_string($version_row); if ($prev_branch != $branch) { phpbb::$template->assign_block_vars($blockname . '.branches', array('NAME' => $version_row)); } $prev_branch = $branch; } } $contrib_type = $row['contrib_type']; } unset($contrib); return compact('sort'); }