예제 #1
0
    /**
     * 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');
    }
예제 #2
0
 /**
  * Display the list of attention items
  *
  * @param array $options
  * 	attention_type
  *	exclude_attention_types
  * 	attention_object_id
  * 	only_closed bool only display closed items
  * 	display_closed bool display closed and open items
  * 	template_block string the name of the template block to output to (attention if not sent)
  * @param \phpbb\titania\sort $sort
  */
 public static function display_attention_list($options = array(), $sort = false)
 {
     if ($sort === false) {
         // Setup the sort tool
         $sort = self::build_sort();
     }
     $sort->request();
     $path_helper = phpbb::$container->get('path_helper');
     $controller_helper = phpbb::$container->get('phpbb.titania.controller.helper');
     $sql_ary = array('SELECT' => 'a.*', 'FROM' => array(TITANIA_ATTENTION_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'), 'ON' => 'a.attention_object_type = ' . TITANIA_CONTRIB . ' AND a.attention_object_id = c.contrib_id')), 'WHERE' => array(), 'ORDER_BY' => $sort->get_order_by());
     // Limit to certain types if requested
     if (isset($options['attention_type']) && $options['attention_type']) {
         $sql_ary['WHERE'][] = 'a.attention_type = ' . (int) $options['attention_type'];
     }
     // Exclude certain types
     if (!empty($options['exclude_attention_types'])) {
         $sql_ary['WHERE'][] = phpbb::$db->sql_in_set('a.attention_type', $options['exclude_attention_types'], true);
     }
     // Limit to certain item if requested
     if (isset($options['attention_object_id'])) {
         $sql_ary['WHERE'][] = 'a.attention_object_id = ' . (int) $options['attention_object_id'];
     }
     // Do we want the closed ones?
     if (isset($options['only_closed']) && $options['only_closed']) {
         $sql_ary['WHERE'][] = 'a.attention_close_time <> 0';
     } else {
         if (!isset($options['display_closed']) || $options['display_closed'] == false) {
             $sql_ary['WHERE'][] = 'a.attention_close_time = 0';
         }
     }
     $sql_ary['WHERE'][] = self::get_permission_sql();
     $sql_ary['WHERE'] = implode(' AND ', $sql_ary['WHERE']);
     // Main SQL Query
     $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
     // Handle pagination
     if (!$sort->sql_count($sql_ary, 'a.attention_id')) {
         // No results...no need to query more...
         return;
     }
     $url_parts = $path_helper->get_url_parts($controller_helper->get_current_url());
     $sort->build_pagination($url_parts['base'], $url_parts['params']);
     // Get the data
     $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start);
     $attention_ids = $user_ids = array();
     while ($row = phpbb::$db->sql_fetchrow($result)) {
         $attention_ids[] = $row['attention_id'];
         $user_ids[] = $row['attention_poster_id'];
         $user_ids[] = $row['attention_requester'];
         $user_ids[] = $row['attention_close_user'];
         if ($row['attention_close_user']) {
             $user_ids[] = $row['attention_close_user'];
         }
         self::$attention_items[$row['attention_id']] = $row;
     }
     phpbb::$db->sql_freeresult($result);
     // Grab some users
     users_overlord::load_users($user_ids);
     // Output time
     foreach ($attention_ids as $attention_id) {
         $attention = self::get_attention_object($attention_id);
         $output = array_merge($attention->assign_details(true), users_overlord::assign_details($attention->attention_poster_id), users_overlord::assign_details($attention->attention_requester, 'REPORTER_'), users_overlord::assign_details($attention->attention_close_user, 'CLOSER_'));
         // Do we have to?
         if ($row['attention_close_user']) {
             $output = array_merge($output, users_overlord::assign_details($attention->attention_close_user, 'CLOSE_'));
         }
         $template_block = isset($options['template_block']) ? $options['template_block'] : 'attention';
         phpbb::$template->assign_block_vars($template_block, $output);
     }
     unset($attention);
 }
예제 #3
0
    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');
    }
예제 #4
0
        }
        phpbb::$db->sql_freeresult($result);
        // Search in the set
        titania_search::in_set($query, 'id', $contribs);
    }
    $query->where($query->eq('type', TITANIA_CONTRIB));
} else {
    // Search type
    if ($search_type) {
        $query->where($query->eq('type', $search_type));
    }
}
// Do the search
$results = titania_search::custom_search($query, $sort);
// Grab the users
users_overlord::load_users($results['user_ids']);
/*switch ($display)
{
	case 'topics' :
		foreach ($results['documents'] as $document)
		{
			$url_base = $document->url;
			$url_params = '';
			if (substr($url_base, -1) != '/')
			{
				$url_params = substr($url_base, (strrpos($url_base, '/') + 1));
				$url_base = substr($url_base, 0, (strrpos($url_base, '/') + 1));
			}

			phpbb::$template->assign_block_vars('searchresults', array(
				'TOPIC_TITLE'		=> censor_text($document->title),
예제 #5
0
 /**
  * Perform search and output results.
  *
  * @param string $sort_url		Base sort url.
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function show_results($sort_url)
 {
     // Setup the sort tool
     $this->sort->set_defaults($this->config['posts_per_page'])->request();
     // Do the search
     $results = $this->query_index();
     // Grab the users
     \users_overlord::load_users($results['user_ids']);
     $this->display->assign_global_vars();
     $this->assign_doc_vars($results['documents']);
     $this->assign_result_vars($this->sort->total);
     $parameters = array();
     $expected_parameters = array('versions' => array(array(''), false), 'c' => array(array(0), false), 'sc' => array(false, false), 'keywords' => array('', true), 'sf' => array('', false), 'author' => array('', true), 'u' => array(0, false), 'type' => array(0, false), 'contrib' => array(0, false));
     foreach ($expected_parameters as $name => $properties) {
         if ($this->request->is_set($name)) {
             list($default_value, $multibyte) = $properties;
             $value = $this->request->variable($name, $default_value, $multibyte);
             // Clean up URL by not including default values.
             if ($value !== $default_value) {
                 $parameters[$name] = $value;
             }
         }
     }
     $this->sort->build_pagination($sort_url, $parameters);
     return $this->helper->render('search_results.html', $this->user->lang['SEARCH']);
 }
예제 #6
0
    /**
     * Display subscription items.
     *
     * @return null
     */
    protected function display_items()
    {
        $object_types = array(TITANIA_CONTRIB, TITANIA_TOPIC);
        $subscription_count = $this->get_subscription_count($object_types);
        $this->build_sort($subscription_count);
        $cases = array(TITANIA_CONTRIB => 'c.contrib_last_update', TITANIA_TOPIC => 't.topic_last_post_time');
        $sql_ary = $this->get_subscription_sql_ary($cases, $object_types, TITANIA_CONTRIB);
        $sql_ary['LEFT_JOIN'][] = array('FROM' => array($this->topics_table => 't'), 'ON' => 'w.watch_object_type = ' . TITANIA_TOPIC . '
							AND t.topic_id = w.watch_object_id');
        // Additional tracking for support topics
        $this->tracking->get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id');
        $this->tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tsa');
        $this->tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tsc');
        $this->tracking->get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt');
        // Tracking for contributions
        $this->tracking->get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id', 'tc');
        $sql = $this->db->sql_build_query('SELECT', $sql_ary);
        $result = $this->db->sql_query_limit($sql, $this->sort->limit, $this->sort->start);
        $user_ids = $contributions = $topics = $rows = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->tracking->store_from_db($row);
            $rows[] = $row;
            if ($row['watch_object_type'] == TITANIA_TOPIC) {
                $user_ids[] = (int) $row['topic_first_post_user_id'];
                $user_ids[] = (int) $row['topic_last_post_user_id'];
            } else {
                $user_ids[] = (int) $row['contrib_user_id'];
            }
        }
        $this->db->sql_freeresult($result);
        // Get user data
        \users_overlord::load_users($user_ids);
        foreach ($rows as $row) {
            if ($row['watch_object_type'] == TITANIA_TOPIC) {
                // Topic was deleted, remove all subscriptions for it.
                if (!$row['topic_id']) {
                    $this->delete_subscription($row['watch_object_type'], $row['watch_object_id'], false);
                    continue;
                }
                $vars = $this->get_topic_tpl_row($row);
            } else {
                // Contribution no longer exists.
                if (!$row['contrib_id']) {
                    $this->delete_subscription($row['watch_object_type'], $row['watch_object_id'], false);
                    continue;
                }
                $vars = $this->get_contribution_tpl_row($row);
            }
            $this->template->assign_block_vars('subscriptions', $vars);
        }
        $this->template->assign_vars(array('S_WATCHED_ITEMS' => true));
    }
예제 #7
0
            users_overlord::load_users(array($post->post_user_id, $post->post_edit_user, $post->post_delete_user));
            users_overlord::assign_details($post->post_user_id, 'POSTER_', true);
            phpbb::$template->assign_vars(array('POST_SUBJECT' => censor_text($post->post_subject), 'POST_DATE' => phpbb::$user->format_date($post->post_time), 'POST_TEXT' => $post->generate_text_for_display(), 'EDITED_MESSAGE' => $post->post_edited ? sprintf(phpbb::$user->lang['EDITED_MESSAGE'], users_overlord::get_user($post->post_edit_user, '_full'), phpbb::$user->format_date($post->post_edited)) : '', 'DELETED_MESSAGE' => $post->post_deleted != 0 ? sprintf(phpbb::$user->lang['DELETED_MESSAGE'], users_overlord::get_user($post->post_delete_user, '_full'), phpbb::$user->format_date($post->post_deleted), $post->get_url('undelete')) : '', 'POST_EDIT_REASON' => censor_text($post->post_edit_reason), 'U_VIEW' => $post->get_url(), 'U_EDIT' => $post->get_url('edit'), 'SECTION_NAME' => '<a href="' . $post->get_url() . '">' . censor_text($post->post_subject) . '</a> - ' . phpbb::$user->lang['ATTENTION']));
            $title = censor_text($post->post_subject);
            break;
        case TITANIA_CONTRIB:
            $contrib = new titania_contribution();
            if (!$contrib->load((int) $object_id)) {
                $attention_object->delete();
                trigger_error('NO_CONTRIB');
            }
            // Close the report
            if ($close) {
                redirect(titania_url::build_url(titania_url::$current_page));
            }
            users_overlord::load_users(array($contrib->contrib_user_id));
            users_overlord::assign_details($contrib->contrib_user_id, 'POSTER_', true);
            phpbb::$template->assign_vars(array('POST_SUBJECT' => censor_text($contrib->contrib_name), 'POST_DATE' => phpbb::$user->format_date($contrib->contrib_last_update), 'POST_TEXT' => $contrib->generate_text_for_display(), 'U_VIEW' => $contrib->get_url(), 'U_EDIT' => $contrib->get_url('manage'), 'SECTION_NAME' => '<a href="' . $contrib->get_url() . '">' . censor_text($contrib->contrib_name) . '</a>  - ' . phpbb::$user->lang['ATTENTION']));
            $title = censor_text($contrib->contrib_name);
            break;
        default:
            trigger_error('NO_ATTENTION_TYPE');
            break;
    }
    titania::page_header($title . ' - ' . phpbb::$user->lang['ATTENTION']);
    titania::page_footer(true, 'manage/attention_details.html');
} else {
    $type = request_var('type', '');
    if (isset($_POST['sort'])) {
        $closed = isset($_POST['closed']) ? true : false;
        $open = isset($_POST['open']) || !$closed ? true : false;
예제 #8
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;
    }
예제 #9
0
    /**
     * Generate the stats page
     */
    public function display_stats()
    {
        $stats = false;
        //titania::$cache->get('queue_stats');
        if ($stats === false) {
            $stats = array();
            foreach (titania_types::$types as $type_id => $class) {
                foreach (titania::$config->queue_stats_periods as $name => $data) {
                    // Shorten
                    $temp_stats = array();
                    // Select the stats for this type
                    $sql = 'SELECT revision_id, contrib_id, queue_type, submitter_user_id, queue_submit_time, queue_close_time, queue_close_user
						FROM ' . TITANIA_QUEUE_TABLE . '
							WHERE queue_type = ' . (int) $type_id . '
								AND queue_close_time > 0 ' . (isset($data['where']) ? 'AND ' . $data['where'] : '');
                    $result = phpbb::$db->sql_query($sql);
                    while ($row = phpbb::$db->sql_fetchrow($result)) {
                        // List of submitters with totals
                        $temp_stats['submitters'][$row['submitter_user_id']] = isset($temp_stats['submitters'][$row['submitter_user_id']]) ? $temp_stats['submitters'][$row['submitter_user_id']] + 1 : 1;
                        // List of users who closed the queue items with totals
                        $temp_stats['closers'][$row['queue_close_user']] = isset($temp_stats['closers'][$row['queue_close_user']]) ? $temp_stats['closers'][$row['queue_close_user']] + 1 : 1;
                        // Count
                        $temp_stats['total'] = isset($temp_stats['total']) ? $temp_stats['total'] + 1 : 1;
                        // Total time in validation
                        $temp_stats['total_validation_time'] = isset($temp_stats['total_validation_time']) ? $temp_stats['total_validation_time'] + ($row['queue_close_time'] - $row['queue_submit_time']) : $row['queue_close_time'] - $row['queue_submit_time'];
                    }
                    phpbb::$db->sql_freeresult($result);
                    // Shorten
                    $stats[$type_id][$name] = $temp_stats;
                }
                // Handle the data
                foreach (titania::$config->queue_stats_periods as $name => $data) {
                    // Shorten
                    $temp_stats = $stats[$type_id][$name];
                    // List of submitters with totals
                    if (isset($temp_stats['submitters']) && sizeof($temp_stats['submitters'])) {
                        arsort($temp_stats['submitters']);
                    }
                    // List of users who closed the queue items with totals
                    if (isset($temp_stats['closers']) && sizeof($temp_stats['closers'])) {
                        arsort($temp_stats['closers']);
                    }
                    // Average time in validation
                    $temp_stats['average_validation_time'] = floor(isset($temp_stats['total_validation_time']) && $temp_stats['total_validation_time'] > 0 ? $temp_stats['total_validation_time'] / $temp_stats['total'] : 0);
                    // Shorten
                    $stats[$type_id][$name] = $temp_stats;
                }
            }
            titania::$cache->put('queue_stats', $stats, 60 * 60);
        }
        // Need to grab some user data
        $user_ids = array();
        foreach (titania_types::$types as $type_id => $class) {
            foreach (titania::$config->queue_stats_periods as $name => $data) {
                // Shorten
                $temp_stats = $stats[$type_id][$name];
                foreach (array('submitters', 'closers') as $type) {
                    if (isset($temp_stats[$type]) && sizeof($temp_stats[$type])) {
                        $i = 1;
                        foreach ($temp_stats[$type] as $user_id => $cnt) {
                            // Only grab the first 5
                            if ($i > 5) {
                                break;
                            }
                            $i++;
                            $user_ids[] = $user_id;
                        }
                    }
                }
            }
        }
        // Load the users
        users_overlord::load_users($user_ids);
        // Output
        foreach (titania_types::$types as $type_id => $class) {
            phpbb::$template->assign_block_vars('stats', array('TITLE' => $class->lang));
            foreach (titania::$config->queue_stats_periods as $name => $data) {
                // Shorten
                $temp_stats = $stats[$type_id][$name];
                $avg_num_weeks = $avg_num_days = 0;
                if ($temp_stats['average_validation_time'] > 0) {
                    $avg_num_weeks = floor($temp_stats['average_validation_time'] / (60 * 60 * 24 * 7));
                    $avg_num_days = floor($temp_stats['average_validation_time'] / (60 * 60 * 24)) % 7;
                }
                phpbb::$template->assign_block_vars('stats.periods', array('TITLE' => isset(phpbb::$user->lang[$data['lang']]) ? phpbb::$user->lang[$data['lang']] : $data['lang'], 'AVERAGE_VALIDATION_TIME' => phpbb::$user->lang('NUM_WEEKS', $avg_num_weeks) . ' ' . phpbb::$user->lang('NUM_DAYS', $avg_num_days)));
                // Submitter/closer data
                foreach (array('submitters', 'closers') as $type) {
                    if (isset($temp_stats[$type]) && sizeof($temp_stats[$type])) {
                        $i = 1;
                        foreach ($temp_stats[$type] as $user_id => $cnt) {
                            // Only output the first 5
                            if ($i > 5) {
                                break;
                            }
                            $i++;
                            // Assign user details and total
                            phpbb::$template->assign_block_vars('stats.periods.' . $type, array_merge(users_overlord::assign_details($user_id), array('TOTAL' => $cnt)));
                        }
                    }
                }
            }
        }
    }
예제 #10
0
 /**
  * Display the list of attention items
  *
  * @param array $options
  * 	attention_type
  * 	attention_object_id
  * 	only_closed bool only display closed items
  * 	display_closed bool display closed and open items
  * 	template_block string the name of the template block to output to (attention if not sent)
  * @param titania_sort $sort
  */
 public static function display_attention_list($options = array(), $sort = false)
 {
     if ($sort === false) {
         // Setup the sort tool
         $sort = self::build_sort();
     }
     $sort->request();
     $sql_ary = array('SELECT' => '*', 'FROM' => array(TITANIA_ATTENTION_TABLE => 'a'), 'WHERE' => array(), 'ORDER_BY' => $sort->get_order_by());
     // Limit to certain types if requested
     if (isset($options['attention_type']) && $options['attention_type']) {
         $sql_ary['WHERE'][] = 'a.attention_type = ' . (int) $options['attention_type'];
     }
     // Limit to certain item if requested
     if (isset($options['attention_object_id'])) {
         $sql_ary['WHERE'][] = 'a.attention_object_id = ' . (int) $options['attention_object_id'];
     }
     // Do we want the closed ones?
     if (isset($options['only_closed']) && $options['only_closed']) {
         $sql_ary['WHERE'][] = 'a.attention_close_time <> 0';
     } else {
         if (!isset($options['display_closed']) || $options['display_closed'] == false) {
             $sql_ary['WHERE'][] = 'a.attention_close_time = 0';
         }
     }
     $sql_ary['WHERE'] = implode(' AND ', $sql_ary['WHERE']);
     // Main SQL Query
     $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
     // Handle pagination
     if (!$sort->sql_count($sql_ary, 'a.attention_id')) {
         // No results...no need to query more...
         return;
     }
     $sort->build_pagination(titania_url::$current_page, titania_url::$params);
     // Get the data
     $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start);
     $attention_ids = $user_ids = array();
     while ($row = phpbb::$db->sql_fetchrow($result)) {
         $attention_ids[] = $row['attention_id'];
         $user_ids[] = $row['attention_poster_id'];
         $user_ids[] = $row['attention_requester'];
         $user_ids[] = $row['attention_close_user'];
         if ($row['attention_close_user']) {
             $user_ids[] = $row['attention_close_user'];
         }
         self::$attention_items[$row['attention_id']] = $row;
     }
     phpbb::$db->sql_freeresult($result);
     // Grab some users
     users_overlord::load_users($user_ids);
     // Output time
     $attention = new titania_attention();
     foreach ($attention_ids as $attention_id) {
         $row = self::$attention_items[$attention_id];
         $attention->__set_array($row);
         $output = array_merge($attention->assign_details(true), users_overlord::assign_details($row['attention_poster_id']), users_overlord::assign_details($row['attention_requester'], 'REPORTER_'), users_overlord::assign_details($row['attention_close_user'], 'CLOSER_'));
         // Do we have to?
         if ($row['attention_close_user']) {
             $output = array_merge($output, users_overlord::assign_details($row['attention_close_user'], 'CLOSE_'));
         }
         $template_block = isset($options['template_block']) ? $options['template_block'] : 'attention';
         phpbb::$template->assign_block_vars($template_block, $output);
     }
     unset($attention);
 }
예제 #11
0
    /**
     * Display forum-like list for queue
     *
     * @param string $type The type of queue (the contrib type)
     * @param object|boolean $sort The sort object (includes/tools/sort.php)
     */
    public static function display_queue($type, $queue_status = TITANIA_QUEUE_NEW, $sort = false)
    {
        if ($sort === false) {
            // Setup the sort tool
            $sort = self::build_sort();
        }
        $sort->request();
        $controller_helper = phpbb::$container->get('phpbb.titania.controller.helper');
        $path_helper = phpbb::$container->get('path_helper');
        $tracking = phpbb::$container->get('phpbb.titania.tracking');
        $queue_ids = array();
        $sql_ary = array('SELECT' => 'q.*, c.*, r.*, 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, tp.topic_posted', 'FROM' => array(TITANIA_QUEUE_TABLE => 'q', TITANIA_CONTRIBS_TABLE => 'c', TITANIA_REVISIONS_TABLE => 'r', TITANIA_TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TITANIA_TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . (int) phpbb::$user->data['user_id'])), 'WHERE' => 'q.queue_type = ' . (int) $type . ($queue_status ? ' AND q.queue_status = ' . (int) $queue_status : ' AND q.queue_status > 0 ') . '
				AND c.contrib_id = q.contrib_id
				AND r.revision_id = q.revision_id
				AND t.topic_id = q.queue_topic_id', 'ORDER_BY' => $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');
        $tracking->get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id');
        // Main SQL Query
        $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
        // Handle pagination
        if (!$sort->sql_count($sql_ary, 'q.queue_id')) {
            // No results...no need to query more...
            return;
        }
        $url_parts = $path_helper->get_url_parts($controller_helper->get_current_url());
        $sort->build_pagination($url_parts['base'], $url_parts['params']);
        $queue_ids = $user_ids = array();
        // 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
            $tracking->store_from_db($row);
            $queue_ids[] = $row['queue_id'];
            $user_ids[] = $row['topic_first_post_user_id'];
            $user_ids[] = $row['topic_last_post_user_id'];
            $user_ids[] = $row['submitter_user_id'];
            self::$queue[$row['queue_id']] = $row;
        }
        phpbb::$db->sql_freeresult($result);
        users_overlord::load_users($user_ids);
        $topic = new titania_topic();
        foreach ($queue_ids as $queue_id) {
            $row = self::$queue[$queue_id];
            $topic->__set_array($row);
            $topic->topic_posted = $row['topic_posted'];
            phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array('TOPIC_SUBJECT' => $row['contrib_name'] . ' - ' . $row['revision_version'], 'S_TOPIC_PROGRESS' => $row['queue_progress'] ? true : false, 'U_VIEW_TOPIC' => $topic->get_url(false, array('tag' => $queue_status)), 'S_TESTED' => $row['queue_tested'] ? true : false)));
        }
        unset($topic);
        phpbb::$template->assign_vars(array('S_TOPIC_LIST' => true));
        // Assign common stuff for topics list
        topics_overlord::assign_common();
    }
예제 #12
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;
 }
예제 #13
0
 /**
  * Assign details for the source post.
  */
 public function assign_source_object_details()
 {
     users_overlord::load_users(array($this->post->post_user_id, $this->post->post_edit_user, $this->post->post_delete_user));
     users_overlord::assign_details($this->post->post_user_id, 'POSTER_', true);
     $this->load_contrib_object();
     $action_param = array('hash' => generate_link_hash('attention_action'));
     phpbb::$template->assign_vars(array('OBJECT_TYPE' => $this->get_lang_string('object'), 'PARENT' => $this->contrib->contrib_name, 'U_PARENT' => $this->contrib->get_url(), 'POST_SUBJECT' => censor_text($this->post->post_subject), 'POST_DATE' => phpbb::$user->format_date($this->post->post_time), 'POST_TEXT' => $this->post->generate_text_for_display(), 'EDITED_MESSAGE' => $this->post->post_edited ? sprintf(phpbb::$user->lang['EDITED_MESSAGE'], users_overlord::get_user($this->post->post_edit_user, '_full'), phpbb::$user->format_date($this->post->post_edited)) : '', 'DELETED_MESSAGE' => $this->post->post_deleted != 0 ? sprintf(phpbb::$user->lang['DELETED_MESSAGE'], users_overlord::get_user($this->post->post_delete_user, '_full'), phpbb::$user->format_date($this->post->post_deleted), $this->post->get_url('undelete')) : '', 'POST_EDIT_REASON' => censor_text($this->post->post_edit_reason), 'U_APPROVE' => !$this->post->post_approved ? $this->get_report_url('approve', $action_param) : false, 'U_DISAPPROVE' => !$this->post->post_approved ? $this->get_report_url('disapprove', $action_param) : false, 'U_VIEW' => $this->post->get_url(), 'U_EDIT' => $this->post->get_url('edit'), 'SECTION_NAME' => '<a href="' . $this->post->get_url() . '">' . censor_text($this->post->post_subject) . '</a> - ' . phpbb::$user->lang['ATTENTION'], 'S_UNAPPROVED' => !$this->post->post_approved));
 }
예제 #14
0
    /**
     * 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, '&hellip;');
            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');
    }
예제 #15
0
 /**
  * Assign details for the source contribution.
  */
 public function assign_source_object_details()
 {
     users_overlord::load_users(array($this->contrib->contrib_user_id));
     users_overlord::assign_details($this->contrib->contrib_user_id, 'POSTER_', true);
     phpbb::$template->assign_vars(array('OBJECT_TYPE' => $this->get_lang_string('object'), 'POST_SUBJECT' => censor_text($this->contrib->contrib_name), 'POST_DATE' => phpbb::$user->format_date($this->contrib->contrib_last_update), 'POST_TEXT' => $this->contrib->generate_text_for_display(), 'U_VIEW' => $this->contrib->get_url(), 'U_EDIT' => $this->contrib->get_url('manage'), 'SECTION_NAME' => '<a href="' . $this->contrib->get_url() . '">' . censor_text($this->contrib->contrib_name) . '</a>  - ' . phpbb::$user->lang['ATTENTION']));
 }
예제 #16
0
 /**
  * Send an individual a notification.
  * @todo This should probably be moved somewhere else so it can be reused.
  *
  * @param int $user_id
  * @param string $email_template
  * @param array $message_vars Additional variables for email message.
  */
 public function notify_user($user_id, $email_template, $message_vars)
 {
     if ($user_id == ANONYMOUS) {
         return;
     }
     phpbb::_include('functions_messenger', false, 'messenger');
     $lang_path = phpbb::$user->lang_path;
     phpbb::$user->set_custom_lang_path(titania::$config->language_path);
     $messenger = new messenger(false);
     users_overlord::load_users(array($user_id));
     $messenger->template($email_template, users_overlord::get_user($user_id, 'user_lang'));
     $messenger->to(users_overlord::get_user($user_id, 'user_email'), users_overlord::get_user($user_id, '_username'));
     $messenger->assign_vars(array_merge($message_vars, array('USERNAME' => htmlspecialchars_decode(users_overlord::get_user($user_id, '_username')))));
     $messenger->send();
     phpbb::$user->set_custom_lang_path($lang_path);
     // This gets reset when $template->_tpl_load() gets called
     phpbb::$user->theme['template_inherits_id'] = 1;
 }