public function get_bookmarks($ext_mode = '', $forums = array())
    {
        define('POSTS_BOOKMARKS_TABLE', $this->table_prefix . 'posts_bookmarks');
        $start = $this->request->variable('start', 0);
        $sql = 'SELECT COUNT(post_id) as posts_count
			FROM ' . POSTS_BOOKMARKS_TABLE . '
			WHERE user_id = ' . $this->user->data['user_id'];
        $result = $this->db->sql_query($sql);
        $posts_count = (int) $this->db->sql_fetchfield('posts_count');
        $this->db->sql_freeresult($result);
        $sql_where = $sql_fields = '';
        if ($ext_mode != 'find') {
            $sql_where = 'LEFT JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)';
            $sql_fields = ', p.post_time, u.user_id, u.username, u.user_colour';
        }
        $pagination_url = append_sid("{$this->phpbb_root_path}postbookmark", "mode=find");
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $posts_count, $this->config['topics_per_page'], $start);
        $sql = 'SELECT b.post_id AS b_post_id, b.user_id, b.bookmark_time, b.bookmark_desc, p.post_id, p.forum_id, p.topic_id, p.poster_id, p.post_subject, t.topic_title ' . $sql_fields . '
			FROM ' . POSTS_BOOKMARKS_TABLE . ' b
			LEFT JOIN ' . POSTS_TABLE . ' p ON( b.post_id = p.post_id)
			LEFT JOIN ' . TOPICS_TABLE . ' t ON( t.topic_id = p.topic_id)
			' . $sql_where . '
			WHERE b.user_id = ' . $this->user->data['user_id'] . '
			ORDER BY b.bookmark_time ASC';
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $topic_author = $sql_where ? get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : '';
            $post_time = $sql_where ? $this->user->format_date($row['post_time']) : '';
            // Send vars to template
            $this->template->assign_block_vars('postrow', array('POST_ID' => $row['b_post_id'], 'POST_TIME' => $post_time, 'BOOKMARK_TIME' => $this->user->format_date($row['bookmark_time']), 'BOOKMARK_DESC' => $row['bookmark_desc'], 'TOPIC_AUTHOR' => $topic_author, 'POST_TITLE' => $row['post_subject'] ? $row['post_subject'] : $row['topic_title'], 'U_VIEW_POST' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "p=" . $row['post_id'] . "#p" . $row['post_id'] . ""), 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'S_DELETED_POST' => !$row['post_id'] ? true : false, 'U_POST_BOOKMARK' => '[url=' . generate_board_url() . '/viewtopic.' . $this->php_ext . '?p=' . $row['post_id'] . '#p' . $row['post_id'] . ']' . ($row['post_subject'] ? $row['post_subject'] : $row['topic_title']) . '[/url]'));
        }
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('TOTAL_BOOKMARKS' => $this->user->lang('TOTAL_BOOKMARKS', (int) $posts_count), 'PAGE_NUMBER' => $this->pagination->on_page($posts_count, $this->config['topics_per_page'], $start)));
    }
    public function index_modify_page_title($event)
    {
        // Count the videos ...
        $sql = 'SELECT COUNT(video_id) AS total_videos
			FROM ' . $this->video_table;
        $result = $this->db->sql_query($sql);
        $total_videos = (int) $this->db->sql_fetchfield('total_videos');
        $this->db->sql_freeresult($result);
        // Count the videos categories ...
        $sql = 'SELECT COUNT(video_cat_id) AS total_categories
			FROM ' . $this->video_cat_table . '';
        $result = $this->db->sql_query($sql);
        $total_categories = (int) $this->db->sql_fetchfield('total_categories');
        $this->db->sql_freeresult($result);
        // Count the videos views ...
        $sql = 'SELECT SUM(video_views) AS total_views
			FROM ' . $this->video_table;
        $result = $this->db->sql_query($sql);
        $total_views = (int) $this->db->sql_fetchfield('total_views');
        $this->db->sql_freeresult($result);
        $total_videos;
        // Count the videos comments ...
        $sql = 'SELECT COUNT(cmnt_id) AS total_comments
			FROM ' . $this->video_cmnts_table;
        $result = $this->db->sql_query($sql);
        $total_comments = (int) $this->db->sql_fetchfield('total_comments');
        $this->db->sql_freeresult($result);
        $l_total_video_s = $total_videos == 0 ? 'TOTAL_VIDEO_ZERO' : 'TOTAL_VIDEOS_OTHER';
        $l_total_category_s = $total_categories == 0 ? 'TOTAL_CATEGORY_ZERO' : 'TOTAL_CATEGORIES_OTHER';
        $l_total_view_s = $total_views == 0 ? 'TOTAL_VIEW_ZERO' : 'TOTAL_VIEWS_OTHER';
        $l_total_comment_s = $total_comments == 0 ? 'TOTAL_COMMENT_ZERO' : 'TOTAL_COMMENTS_OTHER';
        $this->template->assign_vars(array('TOTAL_VIDEOS_INDEX' => sprintf($this->user->lang[$l_total_video_s], $total_videos), 'TOTAL_CATEGORIES' => sprintf($this->user->lang[$l_total_category_s], $total_categories), 'TOTAL_VIEWS' => sprintf($this->user->lang[$l_total_view_s], $total_views), 'TOTAL_COMMENTS' => sprintf($this->user->lang[$l_total_comment_s], $total_comments), 'S_ENABLE_VIDEO_STATICS_ON_INDEX' => $this->config['enable_video_statics_on_index']));
    }
Exemple #3
0
    public function handle_downloadlog()
    {
        if (!$this->auth->acl_get('a_')) {
            trigger_error('Access Denied');
        } else {
            $this->user->add_lang_ext('dmzx/downloadlog', 'common');
            $fileid = $this->request->variable('file', 0);
            $start = $this->request->variable('start', 0);
            // Pagination number from ACP
            $dll = $this->config['downloadlog_value'];
            // Generate pagination
            $sql = 'SELECT COUNT(downloadslog_id) AS total_downloadlogs
				FROM ' . $this->userdownloadslog_table . '
				WHERE user_id = user_id
				AND file_id = ' . $fileid;
            $result = $this->db->sql_query($sql);
            $total_downloadlogs = (int) $this->db->sql_fetchfield('total_downloadlogs');
            $sql = 'SELECT d.user_id, d.down_date, u.user_id, u.username, u.user_colour
				FROM ' . $this->userdownloadslog_table . ' d, ' . USERS_TABLE . ' u
				WHERE u.user_id = d.user_id
				AND file_id = ' . $fileid . '
				ORDER BY d.down_date DESC';
            $top_result = $this->db->sql_query_limit($sql, $dll, $start);
            while ($row = $this->db->sql_fetchrow($top_result)) {
                $this->template->assign_block_vars('downloaders', array('D_USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'D_TIME' => $this->user->format_date($row['down_date'])));
            }
        }
        $pagination_url = $this->helper->route('dmzx_downloadlog_controller', array('file' => $fileid));
        //Start pagination
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_downloadlogs, $dll, $start);
        $this->template->assign_vars(array('DOWNLOADERS_USERS' => $total_downloadlogs == 1 ? $this->user->lang['DOWNLOADERS_COUNT'] : sprintf($this->user->lang['DOWNLOADERS_COUNTS'], $total_downloadlogs), 'DOWNLOADERS_VERSION' => $this->config['downloadlog_version']));
        page_header('Downloaders Log', false);
        $this->template->set_filenames(array('body' => 'DownloadLog.html'));
        page_footer();
    }
    public function add_page_header_links($event)
    {
        if (!empty($this->config['allow_visits_counter'])) {
            $this->language->add_lang('common', 'dmzx/counter');
            $sql = 'SELECT COUNT(*) AS visits_counter
				FROM ' . $this->visits_counter_table . '
				WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip);
            $result = $this->db->sql_query($sql);
            $visits_counter = (int) $this->db->sql_fetchfield('visits_counter');
            $this->db->sql_freeresult($result);
            $visits = $this->config['visits_counter'];
            if ($visits_counter == 0) {
                $sql_ary = array('uvc_ip' => $this->user->ip, 'uvc_timestamp' => time());
                $sql = 'INSERT INTO ' . $this->visits_counter_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
                $this->db->sql_query($sql);
                $this->config->increment('visits_counter', 1, true);
            } else {
                $sql_ary = array('uvc_timestamp' => time());
                $sql = 'UPDATE ' . $this->visits_counter_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip);
                $this->db->sql_query($sql);
            }
            $timestamp = time() - 3600 * 24;
            $sql_ary = array($timestamp);
            $sql = 'DELETE FROM ' . $this->visits_counter_table . '
				WHERE uvc_timestamp < ' . $timestamp;
            $this->db->sql_query($sql);
            $sql = 'SELECT COUNT(*) AS num_del
				FROM ' . $this->visits_counter_table . ' ';
            $result = $this->db->sql_query($sql);
            $visitsok = (int) $this->db->sql_fetchfield('num_del');
            $this->template->assign_vars(array('UNIQUE_VISITS_COUNTER' => $this->language->lang('UNIQUE_VISITS_COUNTER', $visitsok)));
        }
    }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function get_max_id()
 {
     $sql = 'SELECT MAX(topic_id) AS max_id FROM ' . POLL_OPTIONS_TABLE;
     $result = $this->db->sql_query($sql);
     $max_id = (int) $this->db->sql_fetchfield('max_id');
     $this->db->sql_freeresult($result);
     return $max_id;
 }
 /**
  * {@inheritdoc}
  */
 public function get_max_id()
 {
     $columns = $this->get_columns();
     $sql = 'SELECT MAX(' . $columns['id'] . ') AS max_id FROM ' . $this->get_table_name();
     $result = $this->db->sql_query($sql);
     $max_id = (int) $this->db->sql_fetchfield('max_id');
     $this->db->sql_freeresult($result);
     return $max_id;
 }
    public function page_header($event)
    {
        $this->user->add_lang_ext('dmzx/totalavtiveext', 'common');
        $sql = 'SELECT SUM(ext_active) AS count
			FROM ' . EXT_TABLE;
        $result = $this->db->sql_query($sql);
        $ext_count = (int) $this->db->sql_fetchfield('count');
        $this->template->assign_vars(array('TOTAL_EXT' => $this->user->lang['TOTAL_EXT'] . ' <strong>' . number_format($ext_count) . '</strong>'));
    }
Exemple #8
0
    public function attachments_data($event)
    {
        $topic_id = $event['topic_id'];
        $sql = 'SELECT COUNT(attach_id) as num_attachments
			FROM ' . ATTACHMENTS_TABLE . " a\n\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tAND a.is_orphan = 0";
        $result = $this->db->sql_query($sql);
        $num_attachments = $this->db->sql_fetchfield('num_attachments');
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('U_ATTACHMENTS_TOPIC' => $this->helper->route("bb3mobi_attach_cat", array('t' => $topic_id)), 'TOTAL_ATTACH_TOPIC' => (int) $num_attachments));
    }
Exemple #9
0
    /**
     * Get number of groups, displayed on the legend
     *
     * @return	int		value of the last item displayed
     */
    public function get_group_count()
    {
        $sql = 'SELECT group_legend
			FROM ' . GROUPS_TABLE . '
			ORDER BY group_legend DESC';
        $result = $this->db->sql_query_limit($sql, 1);
        $group_count = (int) $this->db->sql_fetchfield('group_legend');
        $this->db->sql_freeresult($result);
        return $group_count;
    }
Exemple #10
0
    /**
     * Executes the command thumbnail:generate.
     *
     * Generate a thumbnail for all attachments which need one and don't have it yet.
     *
     * @param InputInterface $input The input stream used to get the argument and verboe option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
            return 0;
        }
        $extensions = $this->cache->obtain_attach_extensions(true);
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        if (!function_exists('create_thumbnail')) {
            require $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        }
        $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
        $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $progress->start();
        $thumbnail_created = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) {
                $source = $this->phpbb_root_path . 'files/' . $row['physical_filename'];
                $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
                if (create_thumbnail($source, $destination, $row['mimetype'])) {
                    $thumbnail_created[] = (int) $row['attach_id'];
                    if (count($thumbnail_created) === 250) {
                        $this->commit_changes($thumbnail_created);
                        $thumbnail_created = array();
                    }
                    $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
                } else {
                    $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
                }
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_created)) {
            $this->commit_changes($thumbnail_created);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
        return 0;
    }
    /**
     * Get total.
     *
     * @return int
     */
    public function get_total()
    {
        if ($this->total === null) {
            $sql = 'SELECT COUNT(DISTINCT topic_id, post_user_id) AS cnt
				FROM ' . $this->posts_table . '
				WHERE post_approved = 1
					AND post_deleted = 0';
            $result = $this->db->sql_query($sql);
            $this->total = (int) $this->db->sql_fetchfield('cnt', $result);
            $this->db->sql_freeresult($result);
        }
        return $this->total;
    }
Exemple #12
0
    /**
     * Return correct object for specified mode
     *
     * @param string	$mode		The feeds mode.
     * @param int	$forum_id	Forum id specified by the script if forum feed provided.
     * @param int	$topic_id	Topic id specified by the script if topic feed provided.
     *
     * @return object	Returns correct feeds object for specified mode.
     */
    function get_feed($mode, $forum_id, $topic_id)
    {
        switch ($mode) {
            case 'forums':
                if (!$this->config['feed_overall_forums']) {
                    return false;
                }
                return $this->container->get('feed.forums');
                break;
            case 'topics':
            case 'topics_new':
                if (!$this->config['feed_topics_new']) {
                    return false;
                }
                return $this->container->get('feed.topics');
                break;
            case 'topics_active':
                if (!$this->config['feed_topics_active']) {
                    return false;
                }
                return $this->container->get('feed.topics_active');
                break;
            case 'news':
                // Get at least one news forum
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
                $result = $this->db->sql_query_limit($sql, 1, 0, 600);
                $s_feed_news = (int) $this->db->sql_fetchfield('forum_id');
                $this->db->sql_freeresult($result);
                if (!$s_feed_news) {
                    return false;
                }
                return $this->container->get('feed.news');
                break;
            default:
                if ($topic_id && $this->config['feed_topic']) {
                    return $this->container->get('feed.topic')->set_topic_id($topic_id);
                } else {
                    if ($forum_id && $this->config['feed_forum']) {
                        return $this->container->get('feed.forum')->set_forum_id($forum_id);
                    } else {
                        if ($this->config['feed_overall']) {
                            return $this->container->get('feed.overall');
                        }
                    }
                }
                return false;
                break;
        }
    }
    public function cache_user_data($event)
    {
        $cache_user_data = $event['user_cache_data'];
        $sql_where = $this->auth->acl_get('u_viewonline') ? '' : 'AND session_viewonline = 1';
        $sql = 'SELECT session_browser
			FROM ' . SESSIONS_TABLE . '
			WHERE session_user_id = ' . $event['poster_id'] . '
			' . $sql_where . '
			AND session_time >= ' . (time() - $this->config['load_online_time'] * 60) . '';
        $result = $this->db->sql_query($sql);
        if ($cache_user_data['session_browser'] = $this->db->sql_fetchfield('session_browser')) {
            $event['user_cache_data'] = $cache_user_data;
        }
    }
    /**
     * Checks to see if we can use this username for a merge, based on a few factors.
     *
     * @param string $username - The username to check
     * @param array &$errors - Errors array to work with
     * @return mixed - Return the user's ID (integer) if valid, return void if there was an error
     */
    private function check_user($username, &$errors, $old_user)
    {
        // Grabbeth the old user's ID
        if (!empty($username)) {
            $sql = 'SELECT user_id, user_type
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
            $result = $this->db->sql_query($sql);
            $user_id = (int) $this->db->sql_fetchfield('user_id');
            $user_type = (int) $this->db->sql_fetchfield('user_type');
            $this->db->sql_freeresult($result);
            // No such user.  o_0
            if (!$user_id) {
                $errors[] = $this->user->lang['NO_USER'];
                return;
            }
        } else {
            $errors[] = $this->user->lang['NO_USER_SPECIFIED'];
            return;
        }
        // Check to see if it is ourselves here
        if ($user_id === (int) $this->user->data['user_id'] && $old_user) {
            $errors[] = $this->user->lang['CANNOT_MERGE_SELF'];
            return;
        }
        // Make sure we aren't messing with a founder
        if ($user_type === USER_FOUNDER && $old_user && $this->user->data['user_type'] !== USER_FOUNDER) {
            $errors[] = $this->user->lang['CANNOT_MERGE_FOUNDER'];
            return;
        }
        return $user_id;
    }
    public function test_rename()
    {
        global $table_prefix;
        // uses auth, so we set up the mock/stub
        // to allow reading first forum
        $this->auth->expects($this->once())->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true)));
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $tag_id = 1;
        $new_name_clean = "newtagname";
        $assigned_count = $this->tags_manager->rename($tag_id, $new_name_clean);
        $this->assertEquals(1, $assigned_count);
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
    }
    /**
     * Returns an array of message IDs that have been deleted from the message table
     */
    public function mchat_missing_ids($start_id, $end_id)
    {
        if ($this->config['mchat_edit_delete_limit']) {
            $sql_where = 'message_time < ' . (time() - $this->config['mchat_edit_delete_limit']);
            $cache_ttl = 0;
        } else {
            $sql_where = 'message_id < ' . (int) $start_id;
            $cache_ttl = 3600;
        }
        $sql = 'SELECT message_id
			FROM ' . $this->mchat_table . '
			WHERE ' . $sql_where . '
			ORDER BY message_id DESC';
        $result = $this->db->sql_query_limit($sql, 1, 0, $cache_ttl);
        $earliest_id = (int) $this->db->sql_fetchfield('message_id');
        $this->db->sql_freeresult($result);
        if (!$earliest_id) {
            $sql = 'SELECT MIN(message_id) as earliest_id
				FROM ' . $this->mchat_table;
            $result = $this->db->sql_query($sql, 3600);
            $earliest_id = $this->db->sql_fetchfield('earliest_id');
            $this->db->sql_freeresult($result);
        }
        if (!$earliest_id) {
            return range($start_id, $end_id);
        }
        $sql = 'SELECT (t1.message_id + 1) AS start, (
			SELECT MIN(t3.message_id) - 1
			FROM ' . $this->mchat_table . ' t3
			WHERE t3.message_id > t1.message_id
		) AS end
		FROM ' . $this->mchat_table . ' t1
		WHERE t1.message_id > ' . (int) $earliest_id . ' AND NOT EXISTS (
			SELECT t2.message_id
			FROM ' . $this->mchat_table . ' t2
			WHERE t2.message_id = t1.message_id + 1
		)';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        $missing_ids = array();
        if ($start_id < $earliest_id && !$this->config['mchat_edit_delete_limit']) {
            $missing_ids[] = range($start_id, $earliest_id - 1);
        }
        foreach ($rows as $row) {
            if ($row['end']) {
                $missing_ids[] = range($row['start'], $row['end']);
            } else {
                $latest_message = $row['start'] - 1;
                if ($end_id > $latest_message) {
                    $missing_ids[] = range($latest_message + 1, $end_id);
                }
            }
        }
        // Flatten
        if (!empty($missing_ids)) {
            $missing_ids = call_user_func_array('array_merge', $missing_ids);
        }
        return $missing_ids;
    }
Exemple #17
0
    /**
     * Render the final page of the convertor
     */
    public function finish()
    {
        $this->setup_navigation('finish');
        $this->template->assign_vars(array('TITLE' => $this->language->lang('CONVERT_COMPLETE'), 'BODY' => $this->language->lang('CONVERT_COMPLETE_EXPLAIN')));
        // If we reached this step (conversion completed) we want to purge the cache and log the user out.
        // This is for making sure the session get not screwed due to the 3.0.x users table being completely new.
        $this->cache->purge();
        $this->installer_cache->purge();
        require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
        require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
        $sql = 'SELECT config_value
			FROM ' . $this->config_table . '
			WHERE config_name = \'search_type\'';
        $result = $this->db->sql_query($sql);
        if ($this->db->sql_fetchfield('config_value') != 'fulltext_mysql') {
            $this->template->assign_vars(array('S_ERROR_BOX' => true, 'ERROR_TITLE' => $this->language->lang('SEARCH_INDEX_UNCONVERTED'), 'ERROR_MSG' => $this->language->lang('SEARCH_INDEX_UNCONVERTED_EXPLAIN')));
        }
        $this->db->sql_freeresult($result);
        switch ($this->db->get_sql_layer()) {
            case 'sqlite':
            case 'sqlite3':
                $this->db->sql_query('DELETE FROM ' . $this->session_keys_table);
                $this->db->sql_query('DELETE FROM ' . $this->session_table);
                break;
            default:
                $this->db->sql_query('TRUNCATE TABLE ' . $this->session_keys_table);
                $this->db->sql_query('TRUNCATE TABLE ' . $this->session_table);
                break;
        }
        return $this->controller_helper->render('installer_convert.html', 'CONVERT_COMPLETE');
    }
    /**
     * Obtained cached 24 hour activity data
     *
     * @return array
     */
    protected function obtain_activity_data()
    {
        if (($activity = $this->cache->get('_activity_mod')) === false) {
            // Set interval to 24 hours ago
            $interval = time() - 86400;
            $activity = array();
            // Total new posts in the last 24 hours
            $sql = 'SELECT COUNT(post_id) AS new_posts
				FROM ' . POSTS_TABLE . '
				WHERE post_time > ' . (int) $interval;
            $result = $this->db->sql_query($sql);
            $activity['posts'] = $this->db->sql_fetchfield('new_posts');
            $this->db->sql_freeresult($result);
            // Total new topics in the last 24 hours
            $sql = 'SELECT COUNT(topic_id) AS new_topics
				FROM ' . TOPICS_TABLE . '
				WHERE topic_time > ' . (int) $interval;
            $result = $this->db->sql_query($sql);
            $activity['topics'] = $this->db->sql_fetchfield('new_topics');
            $this->db->sql_freeresult($result);
            // Total new users in the last 24 hours, counts inactive users as well
            $sql = 'SELECT COUNT(user_id) AS new_users
				FROM ' . USERS_TABLE . '
				WHERE user_regdate > ' . (int) $interval;
            $result = $this->db->sql_query($sql);
            $activity['users'] = $this->db->sql_fetchfield('new_users');
            $this->db->sql_freeresult($result);
            // Cache this data for the same as online timespan, this improves performance
            $this->cache->put('_activity_mod', $activity, $this->config['load_online_time']);
        }
        return $activity;
    }
Exemple #19
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'";
        $result = $this->db->sql_query($sql);
        $group_id = (int) $this->db->sql_fetchfield('group_id');
        $this->db->sql_freeresult($result);
        if (!$group_id) {
            // If we reach this point then something has gone very wrong
            $this->io_handler->add_error_message('NO_GROUP');
        }
        foreach ($this->bot_list as $bot_name => $bot_ary) {
            $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => '9E8DA7', 'user_email' => '', 'user_lang' => $this->install_config->get('default_lang'), 'user_style' => 1, 'user_timezone' => 'UTC', 'user_dateformat' => $this->language->lang('default_dateformat'), 'user_allow_massemail' => 0, 'user_allow_pm' => 0);
            if (!function_exists('user_add')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $user_id = user_add($user_row);
            if (!$user_id) {
                // If we can't insert this user then continue to the next one to avoid inconsistent data
                $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
                continue;
            }
            $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1]));
            $this->db->sql_query($sql);
        }
    }
    /**
     * @param mixed $mchat_prune_amount set from mchat config entry
     */
    function mchat_prune($mchat_prune_amount)
    {
        // Run query to get the total message rows...
        $sql = 'SELECT COUNT(message_id) AS total_messages FROM ' . $this->mchat_table;
        $result = $this->db->sql_query($sql);
        $mchat_total_messages = (int) $this->db->sql_fetchfield('total_messages');
        $this->db->sql_freeresult($result);
        // count is below prune amount?
        // do nothing
        $prune = true;
        if ($mchat_total_messages <= $mchat_prune_amount) {
            $prune = false;
        }
        if ($prune) {
            $result = $this->db->sql_query_limit('SELECT * FROM ' . $this->mchat_table . ' ORDER BY message_id ASC', 1);
            $row = $this->db->sql_fetchrow($result);
            $first_id = (int) $row['message_id'];
            $this->db->sql_freeresult($result);
            // compute the delete id
            $delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
            // let's go delete them...if the message id is less than the delete id
            $sql = 'DELETE FROM ' . $this->mchat_table . '
			WHERE message_id < ' . (int) $delete_id;
            $this->db->sql_query($sql);
            $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
        }
        // free up some memory...variable(s) are no longer needed.
        unset($mchat_total_messages);
        // return to what we were doing
        return;
    }
    /**
     *  The actual validation
     */
    public function check_answer()
    {
        // Well how did the user sorted it
        $options_left = $this->request->variable('sortables_options_left', array(0));
        $options_right = $this->request->variable('sortables_options_right', array(0));
        // Make sure the didn't submitted more options then it should (like trying everything... left/right: options ^ 2 )
        if ($this->total_options === sizeof($options_left) + sizeof($options_right)) {
            // Let's count how many options the user sorted correctly
            $sql = 'SELECT COUNT(*) AS total
							FROM ' . $this->table_sortables_answers . '
							WHERE question_id = ' . (int) $this->question . '
									AND ((answer_sort = 0 AND ' . $this->db->sql_in_set('answer_id', $options_left, false, true) . ')
									OR (answer_sort = 1 AND ' . $this->db->sql_in_set('answer_id', $options_right, false, true) . '))';
            $result = $this->db->sql_query($sql);
            $total_options_good = (int) $this->db->sql_fetchfield('total');
            // Now compare that amount with the total amount of options for this question
            if ($this->total_options === $total_options_good) {
                $this->solved = $this::SOLVED;
                // Remember this for the hidden fields
                $this->options_left = $options_left;
                $this->options_right = $options_right;
            }
            $this->db->sql_freeresult($result);
        }
        return $this->solved === $this::SOLVED;
    }
 public function activedate_set($event)
 {
     $topic_data = $event['topic_data'];
     $first_post = intval($topic_data['topic_first_post_id']);
     if (0 == $event['active_date']) {
         // Reset
         $sql = 'SELECT event_id FROM ' . $this->cal_table . ' WHERE post_id = ' . $first_post;
         $result = $this->db->sql_query_limit($sql, 1);
         $event_id = $this->db->sql_fetchfield('event_id');
         $this->db->sql_freeresult($result);
         if (!$event_id) {
             // No event entered, simply skip
             return;
         }
         $sql = 'DELETE FROM ' . $this->cal_table . ' WHERE event_id = ' . $event_id;
         $this->db->sql_query($sql);
         $sql = 'DELETE FROM ' . $this->cal_event_table . ' WHERE id = ' . $event_id;
         $this->db->sql_query($sql);
         $sql = 'DELETE FROM ' . $this->cal_participants_table . ' WHERE post_id = ' . $first_post;
         $this->db->sql_query($sql);
     } else {
         // Copy Date & entries
         if ($this->hookup->topic_id != $event['topic_id']) {
             if ($this->hookup->topic_id != 0) {
                 $this->hookup = new hookup();
             }
             $this->hookup->load_hookup($event['topic_id']);
         }
         //TODO Fortsetzen
     }
 }
Exemple #23
0
    /**
     * Get attachment id from legacy Ariel URL.
     *
     * @return int
     */
    protected function get_legacy_download_id()
    {
        // Mostly to make moving from Ariel easier
        $revision_id = $this->request->variable('revision', 0);
        $contrib_id = $this->request->variable('contrib', 0);
        $download_id = 0;
        if ($revision_id) {
            $sql = 'SELECT attachment_id
				FROM ' . TITANIA_REVISIONS_TABLE . "\n\t\t\t\tWHERE revision_id = {$revision_id}";
            $this->db->sql_query($sql);
            $download_id = (int) $this->db->sql_fetchfield('attachment_id');
            $this->db->sql_freeresult();
        } else {
            if ($contrib_id) {
                $sql = 'SELECT attachment_id
				FROM ' . TITANIA_REVISIONS_TABLE . '
				WHERE contrib_id = ' . $contrib_id . '
					AND revision_status = ' . TITANIA_REVISION_APPROVED . '
				ORDER BY revision_id DESC';
                $this->db->sql_query_limit($sql, 1);
                $download_id = (int) $this->db->sql_fetchfield('attachment_id');
                $this->db->sql_freeresult();
            }
        }
        return $download_id;
    }
    public function modify_posting_auth($event)
    {
        if ($this->config['points_enable']) {
            $mode = $event['mode'];
            // Grab the costs of making a topic or post in this forum
            $sql = 'SELECT forum_cost_topic, forum_cost_post
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . (int) $event['forum_id'];
            $result = $this->db->sql_query($sql);
            $forum = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            // Grab the user's points
            $sql = 'SELECT user_points
					FROM ' . USERS_TABLE . '
					WHERE user_id = ' . (int) $this->user->data['user_id'];
            $result = $this->db->sql_query($sql);
            $user_points = $this->db->sql_fetchfield('user_points');
            $this->db->sql_freeresult($result);
            if ($mode == 'post' && $forum['forum_cost_topic'] > 0 && $user_points < $forum['forum_cost_topic'] && $this->auth->acl_get('f_pay_topic', (int) $event['forum_id'])) {
                $message = sprintf($this->user->lang['POINTS_INSUFFICIENT_TOPIC'], $forum['forum_cost_topic'], $this->config['points_name']);
                $message .= '<br /><br />' . $this->user->lang('RETURN_FORUM', '<a href="' . append_sid("{$this->phpbb_root_path}viewforum.{$this->phpEx}", 'f=' . (int) $event['forum_id']) . '">', '</a>');
                trigger_error($message);
            } else {
                if (($mode == 'reply' || $mode == 'quote') && $forum['forum_cost_post'] > 0 && $user_points < $forum['forum_cost_post'] && $this->auth->acl_get('f_pay_post', (int) $event['forum_id'])) {
                    $message = sprintf($this->user->lang['POINTS_INSUFFICIENT_POST'], $forum['forum_cost_post'], $this->config['points_name']);
                    $message .= '<br /><br />' . $this->user->lang('RETURN_FORUM', '<a href="' . append_sid("{$this->phpbb_root_path}viewforum.{$this->phpEx}", 'f=' . (int) $event['forum_id']) . '">', '</a>');
                    trigger_error($message);
                } else {
                    $event['is_authed'] = true;
                }
            }
        }
    }
 /**
  * Executes the given $sql and fetches the field $field_name
  *
  * @param string $sql
  *        	the sql query
  * @param string $field_name
  *        	the name of the field to fetch
  * @param int $limit
  *        	optional limit
  * @param int $start
  *        	otional start
  * @return the value of the field
  */
 public function get_field($sql, $field_name, $limit = 0, $start = 0)
 {
     $result = $limit > 0 ? $this->db->sql_query_limit($sql, $limit, $start) : $this->db->sql_query($sql);
     $re = $this->db->sql_fetchfield($field_name);
     $this->db->sql_freeresult($result);
     return $re;
 }
    /**
     * Move module horizontally
     *
     * @param int $module_id Module ID
     * @param array $module_data Module data array
     * @param int $move_action The move action
     */
    public function move_module_horizontal($module_id, $module_data, $move_action)
    {
        $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
				SET module_order = module_order + 1
				WHERE module_order >= ' . (int) $module_data['module_order'] . '
					AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
        $this->db->sql_query($sql);
        $updated = $this->db->sql_affectedrows();
        $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
				SET module_column = ' . (int) ($module_data['module_column'] + $move_action) . '
				WHERE module_id = ' . (int) $module_id;
        $this->db->sql_query($sql);
        $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
				SET module_order = module_order - 1
				WHERE module_order >= ' . (int) $module_data['module_order'] . '
				AND module_column = ' . (int) $module_data['module_column'];
        $this->db->sql_query($sql);
        // the module that needs to moved is in the last row
        if (!$updated) {
            $sql = 'SELECT MAX(module_order) as new_order
						FROM ' . PORTAL_MODULES_TABLE . '
						WHERE module_order < ' . (int) $module_data['module_order'] . '
						AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
            $this->db->sql_query($sql);
            $new_order = $this->db->sql_fetchfield('new_order') + 1;
            $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
					SET module_order = ' . (int) $new_order . '
					WHERE module_id = ' . (int) $module_id;
            $this->db->sql_query($sql);
        }
    }
Exemple #27
0
    public function update_read_tracking($data)
    {
        // Mark the post and the topic read
        markread('post', (int) $data['forum_id'], (int) $data['topic_id'], $data['post_time']);
        markread('topic', (int) $data['forum_id'], (int) $data['topic_id'], time());
        // Handle read tracking
        if ($this->config['load_db_lastread'] && $this->user->data['is_registered']) {
            $sql = 'SELECT mark_time
				FROM ' . FORUMS_TRACK_TABLE . '
				WHERE user_id = ' . (int) $this->user->data['user_id'] . '
					AND forum_id = ' . (int) $data['forum_id'];
            $result = $this->db->sql_query($sql);
            $f_mark_time = (int) $this->db->sql_fetchfield('mark_time');
            $this->db->sql_freeresult($result);
        } else {
            if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                $f_mark_time = false;
            }
        }
        if ($this->config['load_db_lastread'] && $this->user->data['is_registered'] || $this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
            // Update forum info
            $sql = 'SELECT forum_last_post_time
				FROM ' . FORUMS_TABLE . '
				WHERE forum_id = ' . (int) $data['forum_id'];
            $result = $this->db->sql_query($sql);
            $forum_last_post_time = (int) $this->db->sql_fetchfield('forum_last_post_time');
            $this->db->sql_freeresult($result);
            update_forum_tracking_info((int) $data['forum_id'], $forum_last_post_time, $f_mark_time, false);
        }
    }
Exemple #28
0
    /**
     * Add a subscription
     *
     * @param string $item_type Type identifier of the subscription
     * @param int $item_id The id of the item
     * @param string $method The method of the notification e.g. 'board', 'email', or 'jabber'
     *                       (if null a subscription will be added for all the defaults methods)
     * @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
     */
    public function add_subscription($item_type, $item_id = 0, $method = null, $user_id = false)
    {
        if ($method === null) {
            foreach ($this->get_default_methods() as $method_name) {
                $this->add_subscription($item_type, $item_id, $method_name, $user_id);
            }
            return;
        }
        $user_id = $user_id === false ? $this->user->data['user_id'] : $user_id;
        $sql = 'SELECT notify
			FROM ' . $this->user_notifications_table . "\n\t\t\tWHERE item_type = '" . $this->db->sql_escape($item_type) . "'\n\t\t\t\tAND item_id = " . (int) $item_id . '
				AND user_id = ' . (int) $user_id . "\n\t\t\t\tAND method = '" . $this->db->sql_escape($method) . "'";
        $this->db->sql_query($sql);
        $current = $this->db->sql_fetchfield('notify');
        $this->db->sql_freeresult();
        if ($current === false) {
            $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array('item_type' => $item_type, 'item_id' => (int) $item_id, 'user_id' => (int) $user_id, 'method' => $method, 'notify' => 1));
            $this->db->sql_query($sql);
        } else {
            if (!$current) {
                $sql = 'UPDATE ' . $this->user_notifications_table . "\n\t\t\t\tSET notify = 1\n\t\t\t\tWHERE item_type = '" . $this->db->sql_escape($item_type) . "'\n\t\t\t\t\tAND item_id = " . (int) $item_id . '
					AND user_id = ' . (int) $user_id . "\n\t\t\t\t\tAND method = '" . $this->db->sql_escape($method) . "'";
                $this->db->sql_query($sql);
            }
        }
    }
Exemple #29
0
    /**
     * Executes the command thumbnail:delete.
     *
     * Deletes all existing thumbnails and updates the database accordingly.
     *
     * @param InputInterface $input The input stream used to get the argument and verbose option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 1';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
            return 0;
        }
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 1';
        $result = $this->db->sql_query($sql);
        $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
        $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING'));
        $progress->start();
        $thumbnail_deleted = array();
        $return = 0;
        while ($row = $this->db->sql_fetchrow($result)) {
            $thumbnail_path = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
            if (@unlink($thumbnail_path)) {
                $thumbnail_deleted[] = $row['attach_id'];
                if (sizeof($thumbnail_deleted) === 250) {
                    $this->commit_changes($thumbnail_deleted);
                    $thumbnail_deleted = array();
                }
                $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
            } else {
                $return = 1;
                $progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_deleted)) {
            $this->commit_changes($thumbnail_deleted);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
        return $return;
    }
    /**
     * Get Ideas poster bot username
     *
     * @return string Ideas bot username
     * @access protected
     */
    protected function get_ideas_topics_poster_username()
    {
        $sql = 'SELECT username FROM ' . USERS_TABLE . '
			WHERE user_id = ' . (int) $this->config['ideas_poster_id'];
        $this->db->sql_query($sql);
        $username = $this->db->sql_fetchfield('username');
        return $username !== false ? $username : '';
    }