예제 #1
0
    /**
     * Sync contribs
     *
     * @param string $mode			The mode (validated)
     * @param int|bool $contrib_id	Contrib id to limit to
     * @param int|bool $start		For indexing only
     * @param int|bool $limit		For indexing only
     */
    public function contribs($mode, $contrib_id = false, $start = false, $limit = false)
    {
        switch ($mode) {
            case 'validated':
                $sql = 'SELECT contrib_id, contrib_status
					FROM ' . $this->contribs_table . ($contrib_id ? ' AND contrib_id = ' . (int) $contrib_id : '');
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $sql = 'SELECT COUNT(revision_id) AS cnt
						FROM ' . $this->revisions_table . '
						WHERE contrib_id = ' . $row['contrib_id'] . '
							AND revision_status = ' . TITANIA_REVISION_APPROVED;
                    $result1 = $this->db->sql_query($sql);
                    $cnt = $this->db->sql_fetchfield('cnt', $result1);
                    $this->db->sql_freeresult($result1);
                    if ($cnt > 0 && $row['contrib_status'] == TITANIA_CONTRIB_NEW || $cnt == 0 && $row['contrib_status'] == TITANIA_CONTRIB_APPROVED) {
                        $sql = 'UPDATE ' . $this->contribs_table . ' SET contrib_status = ' . ($cnt > 0 ? TITANIA_CONTRIB_APPROVED : TITANIA_CONTRIB_NEW) . '
							WHERE contrib_id = ' . $row['contrib_id'];
                        $this->db->sql_query($sql);
                    }
                }
                $this->db->sql_freeresult($result);
                break;
            case 'faq_count':
                $contribs = array();
                $sql = 'SELECT faq_access, contrib_id
					FROM ' . $this->contrib_faq_table;
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $flags = count::update_flags($row['faq_access']);
                    $contribs[$row['contrib_id']] = count::increment(isset($contribs[$row['contrib_id']]) ? $contribs[$row['contrib_id']] : '', $flags);
                }
                $this->db->sql_freeresult($result);
                foreach ($contribs as $contrib_id => $count) {
                    $sql = 'UPDATE ' . $this->contribs_table . '
						SET contrib_faq_count = \'' . $this->db->sql_escape($count) . '\'
						WHERE contrib_id = ' . $contrib_id;
                    $this->db->sql_query($sql);
                }
                break;
            case 'index':
                $data = $contribs = array();
                $sql = 'SELECT * FROM ' . $this->contribs_table . '
						ORDER BY contrib_id ASC';
                if ($start === false || $limit === false) {
                    $result = $this->db->sql_query($sql);
                } else {
                    $result = $this->db->sql_query_limit($sql, (int) $limit, (int) $start);
                }
                while ($row = $this->db->sql_fetchrow($result)) {
                    $data[$row['contrib_id']] = array('object_type' => TITANIA_CONTRIB, 'object_id' => $row['contrib_id'], 'title' => $row['contrib_name'], 'text' => $row['contrib_desc'], 'text_uid' => $row['contrib_desc_uid'], 'text_bitfield' => $row['contrib_desc_bitfield'], 'text_options' => $row['contrib_desc_options'], 'author' => $row['contrib_user_id'], 'date' => $row['contrib_last_update'], 'url' => serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'])), 'approved' => in_array($row['contrib_status'], array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) ? true : false, 'categories' => explode(',', $row['contrib_categories']));
                    $contribs[] = $row['contrib_id'];
                }
                $this->db->sql_freeresult($result);
                $sql = 'SELECT DISTINCT contrib_id, phpbb_version_branch, phpbb_version_revision
					FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . '
					WHERE ' . $this->db->sql_in_set('contrib_id', $contribs) . '
						AND revision_validated = 1';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $phpbb_versions[$row['contrib_id']][] = $row;
                }
                $this->db->sql_freeresult($result);
                foreach ($data as $contrib_id => $contrib_data) {
                    if (isset($phpbb_versions[$contrib_id])) {
                        $data[$contrib_id]['phpbb_versions'] = versions::order_phpbb_version_list_from_db($this->cache, $phpbb_versions[$contrib_id]);
                    }
                }
                $this->search_manager->mass_index($data);
                break;
        }
    }
예제 #2
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, '…');
            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');
    }
예제 #3
0
 /**
  * Index the contribution
  */
 public function index()
 {
     if (!sizeof($this->revisions)) {
         $this->get_revisions();
     }
     $phpbb_versions = array();
     foreach ($this->revisions as $revision) {
         if ($revision['revision_status'] == TITANIA_REVISION_APPROVED) {
             $phpbb_versions = array_merge($phpbb_versions, $revision['phpbb_versions']);
         }
     }
     $phpbb_versions = array_unique(versions::order_phpbb_version_list_from_db($this->cache, $phpbb_versions));
     $data = array('title' => $this->contrib_name, 'text' => $this->contrib_desc, 'text_uid' => $this->contrib_desc_uid, 'text_bitfield' => $this->contrib_desc_bitfield, 'text_options' => $this->contrib_desc_options, 'author' => $this->contrib_user_id, 'date' => $this->contrib_last_update, 'url' => serialize(array('contrib_type' => $this->type->url, 'contrib' => $this->contrib_name_clean)), 'approved' => in_array($this->contrib_status, array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) ? true : false, 'categories' => explode(',', $this->contrib_categories), 'phpbb_versions' => $phpbb_versions);
     $this->search_manager->index(TITANIA_CONTRIB, $this->contrib_id, $data);
 }
예제 #4
0
 public function display($tpl_block = 'revisions', $show_queue = false, $all_versions = false)
 {
     $ordered_phpbb_versions = versions::order_phpbb_version_list_from_db($this->cache, $this->phpbb_versions, $all_versions);
     // Get rid of the day of the week if it exists in the dateformat
     $old_date_format = phpbb::$user->date_format;
     phpbb::$user->date_format = str_replace('D ', '', phpbb::$user->date_format);
     $install_time = false;
     if ($this->install_time > 0) {
         if ($this->install_time < 60) {
             $install_time = phpbb::$user->lang['INSTALL_LESS_THAN_1_MINUTE'];
         } else {
             $install_time = phpbb::$user->lang('INSTALL_MINUTES', (int) ($this->install_time / 60));
         }
     }
     // ColorizeIt stuff
     $url_colorizeit = '';
     if ($this->revision_status == TITANIA_REVISION_APPROVED && strlen(titania::$config->colorizeit) && $this->contrib && $this->contrib->has_colorizeit()) {
         $url_colorizeit = 'http://' . titania::$config->colorizeit_url . '/custom/' . titania::$config->colorizeit . '.html?id=' . $this->attachment_id . '&amp;sample=' . $this->contrib->clr_sample->get_id();
     }
     phpbb::$template->assign_block_vars($tpl_block, array('REVISION_ID' => $this->revision_id, 'CREATED' => phpbb::$user->format_date($this->revision_time), 'NAME' => $this->revision_name ? censor_text($this->revision_name) : ($this->contrib ? $this->contrib->contrib_name . ' ' . $this->revision_version : ''), 'VERSION' => $this->revision_version, 'VALIDATED_DATE' => $this->validation_date ? phpbb::$user->format_date($this->validation_date) : phpbb::$user->lang['NOT_VALIDATED'], 'REVISION_QUEUE' => $show_queue && $this->revision_queue_id ? $this->controller_helper->route('phpbb.titania.queue.item', array('id' => $this->revision_queue_id)) : '', 'PHPBB_VERSION' => sizeof($ordered_phpbb_versions) == 1 ? $ordered_phpbb_versions[0] : '', 'REVISION_LICENSE' => $this->revision_license ? censor_text($this->revision_license) : ($this->contrib && sizeof($this->contrib->type->license_options) ? phpbb::$user->lang['UNKNOWN'] : ''), 'INSTALL_TIME' => $install_time, 'BBC_HTML_REPLACEMENT' => $this->revision_bbc_html_replace, 'BBC_BBCODE_USAGE' => $this->revision_bbc_bbcode_usage, 'BBC_HELPLINE' => $this->revision_bbc_help_line, 'BBC_DEMO' => $this->revision_bbc_demo, 'INSTALL_LEVEL' => $this->install_level > 0 ? phpbb::$user->lang['INSTALL_LEVEL_' . $this->install_level] : '', 'DOWNLOADS' => isset($this->download_count) ? $this->download_count : 0, 'U_DOWNLOAD' => $this->get_url(), 'U_COLORIZEIT' => $url_colorizeit, 'U_EDIT' => $this->contrib && ($this->contrib->is_author || $this->contrib->is_active_coauthor || $this->contrib->type->acl_get('moderate')) ? $this->contrib->get_url('revision', array('page' => 'edit', 'id' => $this->revision_id)) : '', 'S_USE_QUEUE' => titania::$config->use_queue && $this->contrib->type->use_queue ? true : false, 'S_NEW' => $this->revision_status == TITANIA_REVISION_NEW ? true : false, 'S_APPROVED' => $this->revision_status == TITANIA_REVISION_APPROVED ? true : false, 'S_DENIED' => $this->revision_status == TITANIA_REVISION_DENIED ? true : false, 'S_PULLED_SECURITY' => $this->revision_status == TITANIA_REVISION_PULLED_SECURITY ? true : false, 'S_PULLED_OTHER' => $this->revision_status == TITANIA_REVISION_PULLED_OTHER ? true : false, 'S_REPACKED' => $this->revision_status == TITANIA_REVISION_REPACKED ? true : false, 'S_RESUBMITTED' => $this->revision_status == TITANIA_REVISION_RESUBMITTED ? true : false));
     phpbb::$user->date_format = $old_date_format;
     // Output phpBB versions
     foreach ($ordered_phpbb_versions as $version) {
         phpbb::$template->assign_block_vars($tpl_block . '.phpbb_versions', array('VERSION' => $version));
     }
     // Output translations
     if ($this->translations->get_count()) {
         $message = false;
         $this->translations->parse_attachments($message, false, false, $tpl_block . '.translations', '');
     }
     // Hooks
     titania::$hook->call_hook(array(__CLASS__, __FUNCTION__), $this, $tpl_block);
 }