Esempio n. 1
0
 public function __construct(\phpbb\cache\service $cache, \phpbb\request\request_interface $request, \phpbb\user $user)
 {
     $this->cache = $cache;
     $this->request = $request;
     $this->user = $user;
     $this->ranks = $this->cache->obtain_ranks();
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function display(array $bdata, $edit_mode = false)
 {
     $this->settings = $bdata['settings'];
     $extensions = $this->cache->obtain_attach_extensions(0);
     $ext_groups = $this->_get_extension_groups($extensions);
     $posts_data = $this->_get_posts_data();
     $attachments = $this->forum_data->get_attachments(0, $ext_groups[$this->settings['ext_type']], false, 'download_count DESC');
     $content = '';
     if (sizeof($attachments)) {
         $this->_get_block_content($attachments, $posts_data, $extensions);
         $content = $this->ptemplate->render_view('blitze/sitemaker', 'blocks/attachments.html', 'attachments');
     }
     return array('title' => 'ATTACHMENTS', 'content' => $content);
 }
Esempio n. 3
0
    /**
     * Delete module
     *
     * @param int|string $id Module ID of the acp_portal module
     * @param string $mode Mode of the acp_portal module
     * @param string $action Current action of the acp_portal module
     * @param int $module_id ID of the module that should be deleted
     */
    public function module_delete($id, $mode, $action, $module_id)
    {
        $module_data = $this->get_move_module_data($module_id);
        if ($module_data !== false) {
            $module_classname = $this->request->variable('module_classname', '');
            $this->get_module($module_data['module_classname']);
            if (confirm_box(true)) {
                $this->module->uninstall($module_data['module_id'], $this->db);
                $sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE . '
					WHERE module_id = ' . (int) $module_id;
                $this->db->sql_query($sql);
                $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
					SET module_order = module_order - 1
					WHERE module_column = ' . (int) $module_data['module_column'] . '
						AND module_order > ' . (int) $module_data['module_order'];
                $this->db->sql_query($sql);
                $this->cache->purge();
                // make sure we don't get errors after re-adding a module
                // Handle ajax request
                $this->handle_ajax_request(array('success' => true, 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE']));
                trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action));
            } else {
                if ($this->module->get_language()) {
                    $this->controller_helper->load_module_language($this->module);
                }
                $confirm_text = isset($this->user->lang[$module_data['module_name']]) ? sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name']));
                confirm_box(false, $confirm_text, build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'module_id' => $module_id, 'module_classname' => $module_classname)));
            }
        }
        $this->cache->destroy('sql', PORTAL_MODULES_TABLE);
    }
    private function obtain_guest_count_24()
    {
        $total_guests_online_24 = 0;
        // Get number of online guests for the past 24 hours
        // caching and main sql if none yet
        if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) {
            // teh time
            $interval = time() - 86400;
            if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') {
                $sql = 'SELECT COUNT(session_ip) as num_guests_24
					FROM (
						SELECT DISTINCT session_ip
						FROM ' . SESSIONS_TABLE . '
						WHERE session_user_id = ' . ANONYMOUS . '
							AND session_time >= ' . ($interval - (int) ($interval % 60)) . ')';
            } else {
                $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24
					FROM ' . SESSIONS_TABLE . '
					WHERE session_user_id = ' . ANONYMOUS . '
						AND session_time >= ' . ($interval - (int) ($interval % 60));
            }
            $result = $this->db->sql_query($sql);
            $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24');
            $this->db->sql_freeresult($result);
            // cache this stuff for, ohhhh, how about 5 minutes
            // change 300 to whatever number to reduce or increase the cache time
            $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300);
        }
        return $total_guests_online_24;
    }
    private function obtain_guest_count_24()
    {
        $total_guests_online_24 = 0;
        if ($this->config['load_online_guests']) {
            // Get number of online guests for the past 24 hours
            // caching and main sql if none yet
            if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) {
                if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') {
                    $sql = 'SELECT COUNT(session_ip) as num_guests_24
						FROM (
							SELECT DISTINCT session_ip
							FROM ' . SESSIONS_TABLE . '
							WHERE session_user_id = ' . ANONYMOUS . '
								AND session_time >= ' . ($this->interval - (int) ($this->interval % 60)) . ')';
                } else {
                    $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24
						FROM ' . SESSIONS_TABLE . '
						WHERE session_user_id = ' . ANONYMOUS . '
							AND session_time >= ' . ($this->interval - (int) ($this->interval % 60));
                }
                $result = $this->db->sql_query($sql);
                $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24');
                $this->db->sql_freeresult($result);
                // cache this data for 5 minutes, this improves performance
                $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300);
            }
        }
        return $total_guests_online_24;
    }
Esempio n. 6
0
    /**
     * Get the notification type id from the name
     *
     * @param string $notification_type_name The name
     * @return int the notification_type_id
     * @throws \phpbb\notification\exception
     */
    public function get_notification_type_id($notification_type_name)
    {
        $notification_type_ids = $this->cache->get('notification_type_ids');
        $this->db->sql_transaction('begin');
        if ($notification_type_ids === false) {
            $notification_type_ids = array();
            $sql = 'SELECT notification_type_id, notification_type_name
				FROM ' . $this->notification_types_table;
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id'];
            }
            $this->db->sql_freeresult($result);
            $this->cache->put('notification_type_ids', $notification_type_ids);
        }
        if (!isset($notification_type_ids[$notification_type_name])) {
            if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name])) {
                throw new \phpbb\notification\exception('NOTIFICATION_TYPE_NOT_EXIST', array($notification_type_name));
            }
            $sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array('notification_type_name' => $notification_type_name, 'notification_type_enabled' => 1));
            $this->db->sql_query($sql);
            $notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid();
            $this->cache->put('notification_type_ids', $notification_type_ids);
        }
        $this->db->sql_transaction('commit');
        return $notification_type_ids[$notification_type_name];
    }
Esempio n. 7
0
    /**
     * Permission Remove
     *
     * Remove a permission (auth) option
     *
     * @param string $auth_option The name of the permission (auth) option
     * @param bool $global True for checking a global permission setting,
     * 	False for a local permission setting
     * @return null
     */
    public function remove($auth_option, $global = true)
    {
        if (!$this->exists($auth_option, $global)) {
            return;
        }
        if ($global) {
            $type_sql = ' AND is_global = 1';
        } else {
            $type_sql = ' AND is_local = 1';
        }
        $sql = 'SELECT auth_option_id, is_global, is_local
			FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\tWHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . $type_sql;
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        $id = (int) $row['auth_option_id'];
        // If it is a local and global permission, do not remove the row! :P
        if ($row['is_global'] && $row['is_local']) {
            $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
				SET ' . ($global ? 'is_global = 0' : 'is_local = 0') . '
				WHERE auth_option_id = ' . $id;
            $this->db->sql_query($sql);
        } else {
            // Delete time
            $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE);
            foreach ($tables as $table) {
                $this->db->sql_query('DELETE FROM ' . $table . '
					WHERE auth_option_id = ' . $id);
            }
        }
        // Purge the auth cache
        $this->cache->destroy('_acl_options');
        $this->auth->acl_clear_prefetch();
    }
Esempio n. 8
0
    /**
     * Get topics count by type
     *
     * @return array	Topics count array with type in array keys and count
     *		in array values
     */
    public function get_topics_count()
    {
        if (($return_ary = $this->cache->get('_b3p_topics_type_count')) === false) {
            $return_ary = array(POST_ANNOUNCE => 0, POST_STICKY => 0);
            $sql_in = array(POST_ANNOUNCE, POST_STICKY);
            $sql = 'SELECT DISTINCT(topic_id) AS topic_id, topic_type AS type
						FROM ' . TOPICS_TABLE . '
						WHERE ' . $this->db->sql_in_set('topic_type', $sql_in, false);
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                switch ($row['type']) {
                    case POST_ANNOUNCE:
                        ++$return_ary[POST_ANNOUNCE];
                        break;
                    case POST_STICKY:
                        ++$return_ary[POST_STICKY];
                        break;
                }
            }
            $this->db->sql_freeresult($result);
            // cache topics type count for 1 hour
            $this->cache->put('_b3p_topics_type_count', $return_ary, 3600);
        }
        return $return_ary;
    }
Esempio n. 9
0
    public function display_tpotm($event)
    {
        $now = time();
        $date_today = gmdate("Y-m-d", $now);
        list($year_cur, $month_cur, $day1) = split('-', $date_today);
        /* Start time for current month */
        $month_start_cur = gmmktime(0, 0, 0, $month_cur, 1, $year_cur);
        $month_start = $month_start_cur;
        $month_end = $now;
        /*
         * group_id 5 = administrators
         * group_id 4 = global moderators
         * per default into a Vanilla 3.1.x board
         */
        $group_ids = array(5, 4);
        /*
         * config time for cache, still to be fully implemented thus hardcoded
         * 900 = 15 minutes
         */
        $config_time_cache = 900;
        /* Check cached data */
        if (($row = $this->cache->get('_tpotm')) === false) {
            $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_type, u.group_id, p.poster_id, p.post_time, COUNT(p.post_id) AS total_posts
				FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p
				WHERE u.user_id > ' . ANONYMOUS . '
					AND u.user_id = p.poster_id
						AND (u.user_type <> ' . USER_FOUNDER . ')
							AND ' . $this->db->sql_in_set('u.group_id', $group_ids, true) . '
								AND p.post_time BETWEEN ' . $month_start . ' AND ' . $month_end . '
				GROUP BY u.user_id
				ORDER BY total_posts DESC';
            $result = $this->db->sql_query_limit($sql, 1);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            /* caching this data improves performance */
            $this->cache->put('_tpotm', $row, (int) $config_time_cache);
        }
        /* Let's show the Top Poster then */
        $tpotm_tot_posts = (int) $row['total_posts'];
        $tpotm_un_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
        /* Fresh installs or new Month starts give zero posts */
        $tpotm_un_nobody = $this->user->lang['TPOTM_NOBODY'];
        $tpotm_post = $this->user->lang('TPOTM_POST', (int) $tpotm_tot_posts);
        $tpotm_name = $tpotm_tot_posts < 1 ? $tpotm_un_nobody : $tpotm_un_string;
        /* you know.. template stuffs */
        $this->template->assign_vars(array('TPOTM_NAME' => $tpotm_name, 'L_TPOTM_CAT' => $this->user->lang['TPOTM_CAT'], 'L_TPOTM_NOW' => $this->user->lang['TPOTM_NOW'], 'L_TPOTM_POST' => $tpotm_post));
    }
Esempio n. 10
0
    /**
     * Module Remove
     *
     * Remove a module
     *
     * @param string $class The module class(acp|mcp|ucp)
     * @param int|string|bool $parent The parent module_id|module_langname(0 for no parent).
     * 	Use false to ignore the parent check and check class wide.
     * @param int|string $module The module id|module_langname
     * 	specify that here
     * @return null
     * @throws \phpbb\db\migration\exception
     */
    public function remove($class, $parent = 0, $module = '')
    {
        // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto
        if (is_array($module)) {
            if (isset($module['module_langname'])) {
                // Manual Method
                return $this->remove($class, $parent, $module['module_langname']);
            }
            // Failed.
            if (!isset($module['module_basename'])) {
                throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST');
            }
            // Automatic method
            $basename = $module['module_basename'];
            $module_info = $this->get_module_info($class, $basename);
            foreach ($module_info['modes'] as $mode => $info) {
                if (!isset($module['modes']) || in_array($mode, $module['modes'])) {
                    $this->remove($class, $parent, $info['title']);
                }
            }
        } else {
            if (!$this->exists($class, $parent, $module)) {
                return;
            }
            $parent_sql = '';
            if ($parent !== false) {
                // Allows '' to be sent as 0
                $parent = $parent ?: 0;
                if (!is_numeric($parent)) {
                    $sql = 'SELECT module_id
						FROM ' . $this->modules_table . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'";
                    $result = $this->db->sql_query($sql);
                    $module_id = $this->db->sql_fetchfield('module_id');
                    $this->db->sql_freeresult($result);
                    // we know it exists from the module_exists check
                    $parent_sql = 'AND parent_id = ' . (int) $module_id;
                } else {
                    $parent_sql = 'AND parent_id = ' . (int) $parent;
                }
            }
            $module_ids = array();
            if (!is_numeric($module)) {
                $sql = 'SELECT module_id
					FROM ' . $this->modules_table . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($module) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'\n\t\t\t\t\t\t{$parent_sql}";
                $result = $this->db->sql_query($sql);
                while ($module_id = $this->db->sql_fetchfield('module_id')) {
                    $module_ids[] = (int) $module_id;
                }
                $this->db->sql_freeresult($result);
            } else {
                $module_ids[] = (int) $module;
            }
            foreach ($module_ids as $module_id) {
                $this->module_manager->delete_module($module_id, $class);
            }
            $this->cache->destroy("_modules_{$class}");
        }
    }
Esempio n. 11
0
	/**
	* Obtains the latest version information
	*
	* @param bool $force_update Ignores cached data. Defaults to false.
	* @param bool $force_cache Force the use of the cache. Override $force_update.
	* @return string Version info, includes stable and unstable data
	* @throws \RuntimeException
	*/
	public function get_versions($force_update = false, $force_cache = false)
	{
		$cache_file = '_versioncheck_' . $this->host . $this->path . $this->file;

		$info = $this->cache->get($cache_file);

		if ($info === false && $force_cache)
		{
			throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL'));
		}
		else if ($info === false || $force_update)
		{
			try {
				$info = $this->file_downloader->get($this->host, $this->path, $this->file);
			}
			catch (\RuntimeException $exception)
			{
				throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage()));
			}
			$error_string = $this->file_downloader->get_error_string();

			if (!empty($error_string))
			{
				throw new \RuntimeException($error_string);
			}

			$info = json_decode($info, true);

			// Sanitize any data we retrieve from a server
			if (!empty($info))
			{
				$json_sanitizer = function (&$value, $key) {
					$type_cast_helper = new \phpbb\request\type_cast_helper();
					$type_cast_helper->set_var($value, $value, gettype($value), true);
				};
				array_walk_recursive($info, $json_sanitizer);
			}

			if (empty($info['stable']) && empty($info['unstable']))
			{
				$this->user->add_lang('acp/common');

				throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL'));
			}

			$info['stable'] = (empty($info['stable'])) ? array() : $info['stable'];
			$info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable'];

			$this->cache->put($cache_file, $info, 86400); // 24 hours
		}

		return $info;
	}
Esempio n. 12
0
 /**
  * Init files upload class
  *
  * @param int $forum_id Forum ID
  * @param bool $is_message Whether attachment is inside PM or not
  */
 protected function init_files_upload($forum_id, $is_message)
 {
     if ($this->config['check_attachment_content'] && isset($this->config['mime_triggers'])) {
         $this->files_upload->set_disallowed_content(explode('|', $this->config['mime_triggers']));
     } else {
         if (!$this->config['check_attachment_content']) {
             $this->files_upload->set_disallowed_content(array());
         }
     }
     $this->extensions = $this->cache->obtain_attach_extensions($is_message ? false : (int) $forum_id);
     $this->files_upload->set_allowed_extensions(array_keys($this->extensions['_allowed_']));
 }
Esempio n. 13
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;
    }
 /**
  * Set points config value. Creates missing config entry.
  */
 function set_points_config($config_name, $config_value, $is_dynamic = false)
 {
     $sql = 'UPDATE ' . $this->points_config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($config_value) . "'\n\t\t\t\tWHERE config_name = '" . $this->db->sql_escape($config_name) . "'";
     $this->db->sql_query($sql);
     if (!$this->db->sql_affectedrows() && !isset($points_config[$config_name])) {
         $sql = 'INSERT INTO ' . $this->points_config_table . ' ' . $this->db->sql_build_array('INSERT', array('config_name' => $config_name, 'config_value' => $config_value, 'is_dynamic' => $is_dynamic ? 1 : 0));
         $this->db->sql_query($sql);
     }
     $points_config[$config_name] = $config_value;
     if (!$is_dynamic) {
         $this->cache->destroy('config');
     }
 }
Esempio n. 15
0
 /**
  * Gets the PBWoW config data from the DB, or the cache if it is present
  */
 protected function get_pbwow_config()
 {
     if (($this->pbwow_config = $this->cache->get('pbwow_config')) != true) {
         $this->pbwow_config = array();
         if ($this->db_tools->sql_table_exists($this->pbwow_config_table)) {
             $sql = 'SELECT config_name, config_value FROM ' . $this->pbwow_config_table;
             $result = $this->db->sql_query($sql);
             while ($row = $this->db->sql_fetchrow($result)) {
                 $this->pbwow_config[$row['config_name']] = $row['config_value'];
             }
             $this->db->sql_freeresult($result);
         }
         $this->cache->put('pbwow_config', $this->pbwow_config);
     }
 }
Esempio n. 16
0
    function obtain_k_resources()
    {
        include_once $this->phpbb_root_path . 'ext/phpbbireland/portal/config/constants.' . $this->phpEx;
        if (($this->k_resources = $this->cache->get('k_resources')) === false) {
            $sql = 'SELECT *
				FROM ' . K_RESOURCES_TABLE . '
				ORDER BY word ASC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $this->k_resources[] = $row['word'];
            }
            $db->sql_freeresult($result);
            $this->cache->put('k_resources', $this->k_resources);
        }
        return $this->k_resources;
    }
    /**
     * Get the reputation types
     *
     * @return array Reputation types
     * @access public
     */
    public function get_reputation_types()
    {
        $reputation_type_ids = $this->cache->get('reputation_type_ids');
        if ($reputation_type_ids === false) {
            $reputation_type_ids = array();
            $sql = 'SELECT *
				FROM ' . $this->reputation_types_table;
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $reputation_type_ids[(int) $row['reputation_type_id']] = (string) $row['reputation_type_name'];
            }
            $this->db->sql_freeresult($result);
            $this->cache->put('reputation_type_ids', $reputation_type_ids);
        }
        return $reputation_type_ids;
    }
Esempio n. 18
0
 /**
  * Update cat table
  *
  * @return null
  */
 public function update()
 {
     if (!check_form_key($this->form_key)) {
         $this->update = false;
         $this->errors[] = $this->user->lang['FORM_INVALID'];
     }
     switch ($this->action) {
         case 'delete':
             $action_subcats = $this->request->variable('action_subcats', '');
             $subcats_to_id = $this->request->variable('subcats_to_id', 0);
             $action_links = $this->request->variable('action_links', '');
             $links_to_id = $this->request->variable('links_to_id', 0);
             try {
                 $this->errors = $this->_delete_cat($action_links, $action_subcats, $links_to_id, $subcats_to_id);
             } catch (\Exception $e) {
                 trigger_error($e->getMessage(), E_USER_WARNING);
             }
             if (sizeof($this->errors)) {
                 break;
             }
             $this->cache->destroy('sql', DIR_CAT_TABLE);
             trigger_error($this->user->lang['DIR_CAT_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
             break;
         case 'edit':
             $this->cat_data = array('cat_id' => $this->cat_id);
             // No break here
         // No break here
         case 'add':
             $this->cat_data += array('parent_id' => $this->request->variable('cat_parent_id', (int) $this->parent_id), 'cat_parents' => '', 'cat_name' => $this->request->variable('cat_name', '', true), 'cat_desc' => $this->request->variable('cat_desc', '', true), 'cat_desc_uid' => '', 'cat_desc_options' => 7, 'cat_desc_bitfield' => '', 'cat_icon' => $this->request->variable('cat_icon', ''), 'display_subcat_list' => $this->request->variable('display_on_index', false), 'cat_allow_comments' => $this->request->variable('allow_comments', 1), 'cat_allow_votes' => $this->request->variable('allow_votes', 1), 'cat_must_describe' => $this->request->variable('must_describe', 1), 'cat_count_all' => $this->request->variable('count_all', 0), 'cat_validate' => $this->request->variable('validate', 0), 'cat_link_back' => $this->request->variable('link_back', 0), 'cat_cron_enable' => $this->request->variable('cron_enable', 0), 'cat_cron_freq' => $this->request->variable('cron_every', 7), 'cat_cron_nb_check' => $this->request->variable('nb_check', 1));
             // Get data for cat description if specified
             if ($this->cat_data['cat_desc']) {
                 generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_parse_bbcode', false), $this->request->variable('desc_parse_urls', false), $this->request->variable('desc_parse_smilies', false));
             }
             try {
                 $this->errors = $this->_update_cat_data();
             } catch (\Exception $e) {
                 trigger_error($e->getMessage(), E_USER_WARNING);
             }
             if (!sizeof($this->errors)) {
                 $this->cache->destroy('sql', DIR_CAT_TABLE);
                 $message = $this->action == 'add' ? $this->user->lang['DIR_CAT_CREATED'] : $this->user->lang['DIR_CAT_UPDATED'];
                 trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
             }
             break;
     }
 }
 /**
  * Display flag on change in ucp
  * Ajax function
  * @param $flag_id
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getFlag($flag_id)
 {
     if (empty($flag_id)) {
         if ($this->config['flags_required']) {
             return new Response($this->user->lang['MUST_CHOOSE_FLAG']);
         } else {
             return new Response($this->user->lang['NO_SUCH_FLAG']);
         }
     }
     $flags = $this->cache->get('_user_flags');
     $flag_img = $this->ext_path . 'flags/' . strtolower($flags[$flag_id]['flag_image']);
     $flag_img = str_replace('./', generate_board_url() . '/', $flag_img);
     //fix paths
     $flag_name = $flags[$flag_id]['flag_name'];
     $return = '<img class="flag_image" src="' . $flag_img . '" alt="' . $flag_name . '" title="' . $flag_name . '" />';
     return new Response($return);
 }
 /**
  * Get top_flags
  * displayed on the index page
  */
 public function top_flags()
 {
     // grab all the flags
     $sql_array = array('SELECT' => 'user_flag, COUNT(user_flag) AS fnum', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => $this->db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . ' AND user_flag > 0', 'GROUP_BY' => 'user_flag', 'ORDER_BY' => 'fnum DESC');
     // we limit the number of flags to display to the number set in the ACP settings
     $result = $this->db->sql_query_limit($this->db->sql_build_query('SELECT', $sql_array), $this->config['flags_num_display']);
     $count = 0;
     $flags = $this->cache->get('_user_flags');
     while ($row = $this->db->sql_fetchrow($result)) {
         ++$count;
         $this->template->assign_block_vars('flag', array('FLAG' => $this->get_user_flag($row['user_flag']), 'FLAG_USERS' => $this->user->lang('FLAG_USERS', (int) $row['fnum']), 'U_FLAG' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $flags[$row['user_flag']]['flag_id']))));
     }
     $this->db->sql_freeresult($result);
     if ($count) {
         $this->template->assign_vars(array('U_FLAGS' => $this->helper->route('rmcgirr83_nationalflags_display'), 'S_FLAGS' => true));
     }
 }
Esempio n. 21
0
 /**
  * Modify the viewtopic post row
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function viewtopic_modify_post_row($event)
 {
     $users_groups = $this->cache->get('_user_groups');
     $user_id = $event['user_poster_data']['user_id'];
     if (!empty($users_groups[$user_id])) {
         $user_in_groups = '<ul>';
         foreach ($users_groups[$user_id] as $key => $value) {
             if ($value['group_type'] == GROUP_HIDDEN && (!$this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') || $user_id != (int) $this->user->data['user_id'])) {
                 continue;
             }
             $group_name = isset($this->user->lang['G_' . $value['group_name']]) ? $this->user->lang['G_' . $value['group_name']] : $value['group_name'];
             $group_link = append_sid("{$this->root_path}memberlist.{$this->php_ext}", 'mode=group&amp;g=' . $value['group_id']);
             $group_colour = !empty($value['group_colour']) ? 'style="color:#' . $value['group_colour'] . ';"' : '';
             $user_in_groups .= '<li><a href=' . $group_link . ' ' . $group_colour . '>' . $group_name . '</a></li>';
         }
         $user_in_groups .= '</ul>';
         $event['post_row'] = array_merge($event['post_row'], array('POSTER_GROUP' => $user_in_groups));
     }
 }
    /**
     * Delete a flag
     *
     * @param int $flag_id The flag identifier to delete
     * @return null
     * @access public
     */
    public function delete_flag($flag_id)
    {
        if (confirm_box(true)) {
            // Grab the flag name for the log...
            $sql = 'SELECT flag_name, flag_image
				FROM ' . $this->flags_table . '
				WHERE flag_id = ' . (int) $flag_id;
            $result = $this->db->sql_query($sql);
            $flag_row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            // Delete the flag...
            $sql = 'DELETE FROM ' . $this->flags_table . '
				WHERE flag_id = ' . (int) $flag_id;
            $this->db->sql_query($sql);
            // Reset the flag for users
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET user_flag = 0
				WHERE user_flag = ' . (int) $flag_id;
            $this->db->sql_query($sql);
            $log = $this->container->get('log');
            $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_FLAGS_DELETED', time(), array($flag_row['flag_name']));
            $this->cache->destroy('_user_flags');
            $this->functions->cache_flags();
            trigger_error($this->user->lang['MSG_FLAGS_DELETED'] . adm_back_link($this->u_action . "&amp;mode=manage"));
        } else {
            // display a count of users who have this flag
            $sql = 'SELECT COUNT(user_flag) AS flag_count
				FROM ' . USERS_TABLE . '
				WHERE user_flag = ' . (int) $flag_id;
            $result = $this->db->sql_query($sql);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            $message = $this->user->lang['MSG_CONFIRM'];
            if (!empty($row['flag_count'])) {
                $message .= $row['flag_count'] != 1 ? $this->user->lang('MSG_FLAGS_CONFIRM_DELETE', $row['flag_count']) : $this->user->lang('MSG_FLAG_CONFIRM_DELETE', $row['flag_count']);
            }
            confirm_box(false, $message, build_hidden_fields(array('id' => (int) $flag_id, 'mode' => 'manage', 'action' => 'delete')));
            // Use a redirect to take the user back to the previous page
            // if the user chose not delete the flag from the confirmation page.
            redirect("{$this->u_action}");
        }
    }
Esempio n. 23
0
    /**
     * @param mixed $mchat_prune_amount set from mchat config entry
     */
    function display_mchat_bbcodes()
    {
        // grab the bbcodes that aren't allowed
        $config_mchat = $this->cache->get('_mchat_config');
        $disallowed_bbcode_array = explode('|', strtoupper($config_mchat['bbcode_disallowed']));
        preg_replace('#^(.*?)=#si', '$1', $disallowed_bbcode_array);
        $default_bbcodes = array('b', 'i', 'u', 'quote', 'code', 'list', 'img', 'url', 'size', 'color', 'email', 'flash');
        // let's remove the default bbcodes
        if (sizeof($disallowed_bbcode_array)) {
            foreach ($default_bbcodes as $default_bbcode) {
                $default_bbcode = strtoupper($default_bbcode);
                if (!in_array($default_bbcode, $disallowed_bbcode_array)) {
                    $this->template->assign_vars(array('S_MCHAT_BBCODE_' . $default_bbcode => true));
                }
            }
        }
        // now for the custom bbcodes
        // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
        $num_predefined_bbcodes = 22;
        $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
		FROM ' . BBCODES_TABLE . '
		WHERE display_on_posting = 1
		ORDER BY bbcode_tag';
        $result = $this->db->sql_query($sql);
        $i = 0;
        while ($row = $this->db->sql_fetchrow($result)) {
            $bbcode_tag_name = strtoupper($row['bbcode_tag']);
            if (sizeof($disallowed_bbcode_array)) {
                if (in_array($bbcode_tag_name, $disallowed_bbcode_array)) {
                    continue;
                }
            }
            // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
            if (isset($this->user->lang[strtoupper($row['bbcode_helpline'])])) {
                $row['bbcode_helpline'] = $this->user->lang[strtoupper($row['bbcode_helpline'])];
            }
            $this->template->assign_block_vars('custom_tags', array('BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'", 'BBCODE_ID' => $num_predefined_bbcodes + $i * 2, 'BBCODE_TAG' => $row['bbcode_tag'], 'BBCODE_HELPLINE' => $row['bbcode_helpline'], 'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\\'", '<', '>'), $row['bbcode_helpline'])));
            $i++;
        }
        $this->db->sql_freeresult($result);
    }
    /**
     * Obtain an array of users in a rank.
     *
     * @return array
     */
    protected function get_user_rank_data($rank_id)
    {
        $rank_data = $rank_users = array();
        if (($rank_data = $this->cache->get('_rank_data')) === false) {
            $ranks = $this->cache->obtain_ranks();
            $where = $this->config['userranks_ignore_bots'] ? 'WHERE user_type <> ' . USER_IGNORE . '' : '';
            $sql = 'SELECT user_id, user_colour, username, user_rank, user_posts
				FROM ' . USERS_TABLE . "\n\t\t\t\t\t{$where}\n\t\t\t\tORDER BY username_clean ASC";
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                if (!empty($row['user_rank'])) {
                    $rank_data[$row['user_id']] = $row;
                } else {
                    if ($row['user_posts'] !== false) {
                        if (!empty($ranks['normal'])) {
                            foreach ($ranks['normal'] as $rank) {
                                if ($row['user_posts'] >= $rank['rank_min']) {
                                    $row['user_rank'] = $rank['rank_id'];
                                    $rank_data[$row['user_id']] = $row;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            $this->db->sql_freeresult($result);
            // Cache this data to save processing
            $this->cache->put('_rank_data', $rank_data, $this->config['load_online_time']);
        }
        foreach ($rank_data as $user_rank) {
            if ($user_rank['user_rank'] == $rank_id) {
                $rank_users[$user_rank['user_id']] = $user_rank;
            }
        }
        return $rank_users;
    }
Esempio n. 25
0
    /**
     * Method to render the page data
     *
     * @var bool		Bool if the rendering is only for index
     * @return array	Data for page rendering
     */
    public function render_data_for_page($only_for_index = false)
    {
        $include_on_index = $only_for_index === true;
        // Add lang file
        $this->user->add_lang('posting');
        //chat enabled
        if (!$this->config['mchat_enable']) {
            trigger_error($this->user->lang['MCHAT_ENABLE'], E_USER_NOTICE);
        }
        //	avatars
        if (!function_exists('get_user_avatar')) {
            include $this->phpbb_root_path . 'includes/functions_display.' . $this->phpEx;
        }
        if (($this->config_mchat = $this->cache->get('_mchat_config')) === false) {
            $this->functions_mchat->mchat_cache();
        }
        $this->config_mchat = $this->cache->get('_mchat_config');
        // Access rights
        $mchat_allow_bbcode = $this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode') ? true : false;
        $mchat_smilies = $this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies') ? true : false;
        $mchat_urls = $this->config['allow_post_links'] && $this->auth->acl_get('u_mchat_urls') ? true : false;
        $mchat_ip = $this->auth->acl_get('u_mchat_ip') ? true : false;
        $mchat_pm = $this->auth->acl_get('u_mchat_pm') ? true : false;
        $mchat_like = $this->auth->acl_get('u_mchat_like') ? true : false;
        $mchat_quote = $this->auth->acl_get('u_mchat_quote') ? true : false;
        $mchat_add_mess = $this->auth->acl_get('u_mchat_use') ? true : false;
        $mchat_view = $this->auth->acl_get('u_mchat_view') ? true : false;
        $mchat_no_flood = $this->auth->acl_get('u_mchat_flood_ignore') ? true : false;
        $mchat_read_archive = $this->auth->acl_get('u_mchat_archive') ? true : false;
        $mchat_founder = $this->user->data['user_type'] == USER_FOUNDER ? true : false;
        $mchat_session_time = !empty($this->config_mchat['timeout']) ? $this->config_mchat['timeout'] : (!empty($this->config['load_online_time']) ? $this->config['load_online_time'] * 60 : $this->config['session_length']);
        $mchat_rules = !empty($this->config_mchat['rules']) || isset($this->user->lang[strtoupper('mchat_rules')]) ? true : false;
        $mchat_avatars = !empty($this->config_mchat['avatars']) && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars'] ? true : false;
        // needed variables
        // Request options.
        $mchat_mode = $this->request->variable('mode', '');
        $mchat_read_mode = $mchat_archive_mode = $mchat_custom_page = $mchat_no_message = false;
        // set redirect if on index or custom page
        $on_page = $include_on_index ? 'index' : 'mchat';
        // grab fools..uhmmm, foes the user has
        $foes_array = array();
        $sql = 'SELECT * FROM ' . ZEBRA_TABLE . '
			WHERE user_id = ' . $this->user->data['user_id'] . '	AND foe = 1';
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $foes_array[] = $row['zebra_id'];
        }
        $this->db->sql_freeresult($result);
        // Request mode...
        switch ($mchat_mode) {
            // rules popup..
            case 'rules':
                // If the rules are defined in the language file use them, else just use the entry in the database
                if ($mchat_rules || isset($this->user->lang[strtoupper('mchat_rules')])) {
                    if (isset($this->user->lang[strtoupper('mchat_rules')])) {
                        $this->template->assign_var('MCHAT_RULES', $this->user->lang[strtoupper('mchat_rules')]);
                    } else {
                        $mchat_rules = $this->config_mchat['rules'];
                        $mchat_rules = explode("\n", $mchat_rules);
                        foreach ($mchat_rules as $mchat_rule) {
                            $mchat_rule = utf8_htmlspecialchars($mchat_rule);
                            $this->template->assign_block_vars('rule', array('MCHAT_RULE' => $mchat_rule));
                        }
                    }
                    // Output the page
                    // Return for: \$this->helper->render(filename, lang_title);
                    return array('filename' => 'mchat_rules.html', 'lang_title' => $this->user->lang['MCHAT_HELP']);
                } else {
                    // Show no rules
                    trigger_error('MCHAT_NO_RULES', E_USER_NOTICE);
                }
                break;
                // whois function..
            // whois function..
            case 'whois':
                // Must have auths
                if ($mchat_mode == 'whois' && $mchat_ip) {
                    // function already exists..
                    if (!function_exists('user_ipwhois')) {
                        include $this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx;
                    }
                    $this->user_ip = $this->request->variable('ip', '');
                    $this->template->assign_var('WHOIS', user_ipwhois($this->user_ip));
                    // Output the page
                    // Return for: \$this->helper->render(filename, lang_title);
                    return array('filename' => 'viewonline_whois.html', 'lang_title' => $this->user->lang['WHO_IS_ONLINE']);
                } else {
                    // Show not authorized
                    trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE);
                }
                break;
                // Clean function...
            // Clean function...
            case 'clean':
                // User logged in?
                if (!$this->user->data['is_registered'] || !$mchat_founder) {
                    if (!$this->user->data['is_registered']) {
                        // Login box...
                        login_box('', $this->user->lang['LOGIN']);
                    } else {
                        if (!$mchat_founder) {
                            // Show not authorized
                            trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE);
                        }
                    }
                }
                $mchat_redirect = $this->request->variable('redirect', '');
                $mchat_redirect = $mchat_redirect == 'index' ? append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") : $this->helper->route('dmzx_mchat_controller', array('#mChat'));
                if (confirm_box(true)) {
                    // Run cleaner
                    $sql = 'TRUNCATE TABLE ' . $this->mchat_table;
                    $this->db->sql_query($sql);
                    meta_refresh(3, $mchat_redirect);
                    trigger_error($this->user->lang['MCHAT_CLEANED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>'));
                } else {
                    // Display confirm box
                    confirm_box(false, $this->user->lang['MCHAT_DELALLMESS']);
                }
                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
                redirect($mchat_redirect);
                break;
                // Archive function...
            // Archive function...
            case 'archive':
                if (!$mchat_read_archive || !$mchat_view) {
                    // redirect to correct page
                    $mchat_redirect = append_sid("{$this->phpbb_root_path}index.{$this->phpEx}");
                    // Redirect to previous page
                    meta_refresh(3, $mchat_redirect);
                    trigger_error($this->user->lang['MCHAT_NOACCESS_ARCHIVE'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>'));
                }
                if ($this->config['mchat_enable'] && $mchat_read_archive && $mchat_view) {
                    // how many chats do we have?
                    $sql = 'SELECT COUNT(message_id) AS messages FROM ' . $this->mchat_table;
                    $result = $this->db->sql_query($sql);
                    $mchat_total_messages = $this->db->sql_fetchfield('messages');
                    $this->db->sql_freeresult($result);
                    // prune the chats if necessary and amount in ACP not empty
                    if ($this->config_mchat['prune_enable'] && ($mchat_total_messages > $this->config_mchat['prune_num'] && $this->config_mchat['prune_num'] > 0)) {
                        $this->functions_mchat->mchat_prune((int) $this->config_mchat['prune_num']);
                    }
                    // Reguest...
                    $mchat_archive_start = $this->request->variable('start', 0);
                    $sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0';
                    // Message row
                    $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm
						FROM ' . $this->mchat_table . ' m
							LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
						' . $sql_where . '
						ORDER BY m.message_id DESC';
                    $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['archive_limit'], $mchat_archive_start);
                    $rows = $this->db->sql_fetchrowset($result);
                    $this->db->sql_freeresult($result);
                    foreach ($rows as $row) {
                        // auth check
                        if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) {
                            continue;
                        }
                        // edit, delete and permission auths
                        $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false;
                        $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                        $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                        $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : '';
                        $message_edit = $row['message'];
                        decode_message($message_edit, $row['bbcode_uid']);
                        $message_edit = str_replace('"', '&quot;', $message_edit);
                        // Edit Fix ;)
                        if (sizeof($foes_array)) {
                            if (in_array($row['user_id'], $foes_array)) {
                                $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
                            }
                        }
                        $row['username'] = mb_ereg_replace("'", "&#146;", $row['username']);
                        $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2));
                    }
                    // Write no message
                    if (empty($rows)) {
                        $mchat_no_message = true;
                    }
                }
                // Run query again to get the total message rows...
                $sql = 'SELECT COUNT(message_id) AS mess_id FROM ' . $this->mchat_table;
                $result = $this->db->sql_query($sql);
                $mchat_total_message = $this->db->sql_fetchfield('mess_id');
                $this->db->sql_freeresult($result);
                // Page list function...
                $pagination_url = $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive'));
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $mchat_total_message, (int) $this->config_mchat['archive_limit'], $mchat_archive_start);
                $this->template->assign_vars(array('MCHAT_TOTAL_MESSAGES' => sprintf($this->user->lang['MCHAT_TOTALMESSAGES'], $mchat_total_message)));
                //add to navlinks
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['MCHAT_ARCHIVE_PAGE'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive'))));
                // If archive mode request set true
                $mchat_archive_mode = true;
                $old_mode = 'archive';
                break;
                // Read function...
            // Read function...
            case 'read':
                // If mChat disabled or user can't view the chat
                if (!$this->config['mchat_enable'] || !$mchat_view) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                // if we're reading on the custom page, then we are chatting
                if ($mchat_custom_page) {
                    // insert user into the mChat sessions table
                    $this->functions_mchat->mchat_sessions($mchat_session_time, true);
                }
                // Request
                $mchat_message_last_id = $this->request->variable('message_last_id', 0);
                $sql_and = $this->user->data['user_mchat_topics'] ? '' : 'AND m.forum_id = 0';
                $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm
					FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u
					WHERE m.user_id = u.user_id
					AND m.message_id > ' . (int) $mchat_message_last_id . '
					' . $sql_and . '
					ORDER BY m.message_id DESC';
                $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['message_limit']);
                $rows = $this->db->sql_fetchrowset($result);
                $this->db->sql_freeresult($result);
                // Reverse the array wanting messages appear in reverse
                if ($this->config['mchat_message_top']) {
                    $rows = array_reverse($rows);
                }
                foreach ($rows as $row) {
                    // auth check
                    if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) {
                        continue;
                    }
                    // edit auths
                    if ($this->user->data['user_id'] == ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) {
                        $chat_auths = $this->user->data['session_ip'] == $row['user_ip'] ? true : false;
                    } else {
                        $chat_auths = $this->user->data['user_id'] == $row['user_id'] ? true : false;
                    }
                    // edit, delete and permission auths
                    $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false;
                    $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false;
                    $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false;
                    $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : '';
                    $message_edit = $row['message'];
                    decode_message($message_edit, $row['bbcode_uid']);
                    $message_edit = str_replace('"', '&quot;', $message_edit);
                    $message_edit = mb_ereg_replace("'", "&#146;", $message_edit);
                    // Edit Fix ;)
                    if (sizeof($foes_array)) {
                        if (in_array($row['user_id'], $foes_array)) {
                            $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
                        }
                    }
                    $row['username'] = mb_ereg_replace("'", "&#146;", $row['username']);
                    $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2));
                }
                // Write no message
                if (empty($rows)) {
                    $mchat_no_message = true;
                }
                // If read mode request set true
                $mchat_read_mode = true;
                break;
                // Stats function...
            // Stats function...
            case 'stats':
                // If mChat disabled or user can't view the chat
                if (!$this->config['mchat_enable'] || !$mchat_view || !$this->config_mchat['whois']) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time);
                if (!empty($mchat_stats['online_userlist'])) {
                    $message = '<div class="mChatStats" id="mChatStats"><a href="#" onclick="mChat.toggle(\'UserList\'); return false;">' . $mchat_stats['mchat_users_count'] . '</a>&nbsp;' . $mchat_stats['refresh_message'] . '<br /><span id="mChatUserList" style="display: none; float: left;">' . $mchat_stats['online_userlist'] . '</span></div>';
                } else {
                    $message = '<div class="mChatStats" id="Div1">' . $this->user->lang['MCHAT_NO_CHATTERS'] . '&nbsp;(' . $mchat_stats['refresh_message'] . ')</div>';
                }
                if ($this->request->is_ajax()) {
                    // Return for: \Symfony\Component\HttpFoundation\JsonResponse
                    return array('json' => true, 'message' => $message);
                } else {
                    throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED');
                }
                break;
                // Add function...
            // Add function...
            case 'add':
                // If mChat disabled
                if (!$this->config['mchat_enable'] || !$mchat_add_mess || !check_form_key('mchat_posting', -1)) {
                    // Forbidden (for jQ AJAX request)
                    if ($this->request->is_ajax()) {
                        // FOR DEBUG
                        throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                    }
                }
                // Reguest...
                $message = utf8_ucfirst(utf8_normalize_nfc($this->request->variable('message', '', true)));
                // must have something other than bbcode in the message
                if (empty($mchatregex)) {
                    //let's strip all the bbcode
                    $mchatregex = '#\\[/?[^\\[\\]]+\\]#mi';
                }
                $message_chars = preg_replace($mchatregex, '', $message);
                $message_chars = utf8_strlen(trim($message_chars)) > 0 ? true : false;
                if (!$message || !$message_chars) {
                    // Not Implemented (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED');
                }
                // Flood control
                if (!$mchat_no_flood && $this->config_mchat['flood_time']) {
                    $mchat_flood_current_time = time();
                    $sql = 'SELECT message_time FROM ' . $this->mchat_table . '
						WHERE user_id = ' . (int) $this->user->data['user_id'] . '
						ORDER BY message_time DESC';
                    $result = $this->db->sql_query_limit($sql, 1);
                    $row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if ($row['message_time'] > 0 && $mchat_flood_current_time - $row['message_time'] < (int) $this->config_mchat['flood_time']) {
                        // Locked (for jQ AJAX request)
                        throw new \phpbb\exception\http_exception(400, 'MCHAT_BAD_REQUEST');
                    }
                }
                // insert user into the mChat sessions table
                $this->functions_mchat->mchat_sessions($mchat_session_time, true);
                // we override the $this->config['min_post_chars'] entry?
                if ($this->config_mchat['override_min_post_chars']) {
                    $old_cfg['min_post_chars'] = $this->config['min_post_chars'];
                    $this->config['min_post_chars'] = 0;
                }
                //we do the same for the max number of smilies?
                if ($this->config_mchat['override_smilie_limit']) {
                    $old_cfg['max_post_smilies'] = $this->config['max_post_smilies'];
                    $this->config['max_post_smilies'] = 0;
                }
                // Add function part code from http://wiki.phpbb.com/Parsing_text
                $uid = $bitfield = $options = '';
                // will be modified by generate_text_for_storage
                generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies);
                // Not allowed bbcodes
                if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) {
                    if (!$mchat_allow_bbcode) {
                        $bbcode_remove = '#\\[/?[^\\[\\]]+\\]#Usi';
                        $message = preg_replace($bbcode_remove, '', $message);
                    } else {
                        if ($this->config_mchat['bbcode_disallowed']) {
                            if (empty($bbcode_replace)) {
                                $bbcode_replace = array('#\\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi', '#\\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi');
                            }
                            $message = preg_replace($bbcode_replace, '', $message);
                        }
                    }
                }
                $sql_ary = array('forum_id' => 0, 'post_id' => 0, 'user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->data['session_ip'], 'message' => str_replace('\'', '&rsquo;', $message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, 'message_time' => time());
                $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
                $this->db->sql_query($sql);
                // reset the config settings
                if (isset($old_cfg['min_post_chars'])) {
                    $this->config['min_post_chars'] = $old_cfg['min_post_chars'];
                    unset($old_cfg['min_post_chars']);
                }
                if (isset($old_cfg['max_post_smilies'])) {
                    $this->config['max_post_smilies'] = $old_cfg['max_post_smilies'];
                    unset($old_cfg['max_post_smilies']);
                }
                // Stop run code!
                if ($this->request->is_ajax()) {
                    // Return for: \Symfony\Component\HttpFoundation\JsonResponse
                    return array('json' => true, 'success' => true);
                } else {
                    exit_handler();
                }
                break;
                // Edit function...
            // Edit function...
            case 'edit':
                $message_id = $this->request->variable('message_id', 0);
                // If mChat disabled and not edit
                if (!$this->config['mchat_enable'] || !$message_id) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                // check for the correct user
                $sql = 'SELECT *
					FROM ' . $this->mchat_table . '
					WHERE message_id = ' . (int) $message_id;
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                // edit and delete auths
                $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                // If mChat disabled and not edit
                if (!$mchat_edit) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                // Reguest...
                $message = $this->request->variable('message', '', true);
                // must have something other than bbcode in the message
                if (empty($mchatregex)) {
                    //let's strip all the bbcode
                    $mchatregex = '#\\[/?[^\\[\\]]+\\]#mi';
                }
                $message_chars = preg_replace($mchatregex, '', $message);
                $message_chars = utf8_strlen(trim($message_chars)) > 0 ? true : false;
                if (!$message || !$message_chars) {
                    // Not Implemented (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED');
                }
                // Message limit
                $message = $this->config_mchat['max_message_lngth'] != 0 && utf8_strlen($message) >= $this->config_mchat['max_message_lngth'] + 3 ? utf8_substr($message, 0, $this->config_mchat['max_message_lngth']) . '...' : $message;
                // we override the $this->config['min_post_chars'] entry?
                if ($this->config_mchat['override_min_post_chars']) {
                    $old_cfg['min_post_chars'] = $this->config['min_post_chars'];
                    $this->config['min_post_chars'] = 0;
                }
                //we do the same for the max number of smilies?
                if ($this->config_mchat['override_smilie_limit']) {
                    $old_cfg['max_post_smilies'] = $this->config['max_post_smilies'];
                    $this->config['max_post_smilies'] = 0;
                }
                // Edit function part code from http://wiki.phpbb.com/Parsing_text
                $uid = $bitfield = $options = '';
                // will be modified by generate_text_for_storage
                generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies);
                // Not allowed bbcodes
                if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) {
                    if (!$mchat_allow_bbcode) {
                        $bbcode_remove = '#\\[/?[^\\[\\]]+\\]#Usi';
                        $message = preg_replace($bbcode_remove, '', $message);
                    } else {
                        if ($this->config_mchat['bbcode_disallowed']) {
                            if (empty($bbcode_replace)) {
                                $bbcode_replace = array('#\\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi', '#\\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi');
                            }
                            $message = preg_replace($bbcode_replace, '', $message);
                        }
                    }
                }
                $sql_ary = array('message' => str_replace('\'', '&rsquo;', $message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options);
                $sql = 'UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE message_id = ' . (int) $message_id;
                $this->db->sql_query($sql);
                // Message edited...now read it
                $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm
					FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u
					WHERE m.user_id = u.user_id
						AND m.message_id = ' . (int) $message_id . '
					ORDER BY m.message_id DESC';
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $message_edit = $row['message'];
                decode_message($message_edit, $row['bbcode_uid']);
                $message_edit = str_replace('"', '&quot;', $message_edit);
                // Edit Fix ;)
                $message_edit = mb_ereg_replace("'", "&#146;", $message_edit);
                // Edit Fix ;)
                $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false;
                $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : '';
                $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => censor_text(generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'])), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2));
                // reset the config settings
                if (isset($old_cfg['min_post_chars'])) {
                    $this->config['min_post_chars'] = $old_cfg['min_post_chars'];
                    unset($old_cfg['min_post_chars']);
                }
                if (isset($old_cfg['max_post_smilies'])) {
                    $this->config['max_post_smilies'] = $old_cfg['max_post_smilies'];
                    unset($old_cfg['max_post_smilies']);
                }
                //adds a log
                //	$message_author = get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']);
                //	add_log('admin', 'LOG_EDITED_MCHAT', $message_author);
                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($row['username']));
                // insert user into the mChat sessions table
                $this->functions_mchat->mchat_sessions($mchat_session_time, true);
                // If read mode request set true
                $mchat_read_mode = true;
                break;
                // Delete function...
            // Delete function...
            case 'delete':
                $message_id = $this->request->variable('message_id', 0);
                // If mChat disabled
                if (!$this->config['mchat_enable'] || !$message_id) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                // check for the correct user
                $sql = 'SELECT m.*, u.username, u.user_colour
					FROM ' . $this->mchat_table . ' m
					LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
					WHERE m.message_id = ' . (int) $message_id;
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                // edit and delete auths
                $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false;
                // If mChat disabled
                if (!$mchat_del) {
                    // Forbidden (for jQ AJAX request)
                    throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
                }
                // Run delete!
                $sql = 'DELETE FROM ' . $this->mchat_table . '
					WHERE message_id = ' . (int) $message_id;
                $this->db->sql_query($sql);
                //adds a log
                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($row['username']));
                // insert user into the mChat sessions table
                $this->functions_mchat->mchat_sessions($mchat_session_time, true);
                // Stop running code
                if ($this->request->is_ajax()) {
                    // Return for: \Symfony\Component\HttpFoundation\JsonResponse
                    return array('json' => true, 'success' => true);
                } else {
                    exit_handler();
                }
                break;
                // Default function...
            // Default function...
            default:
                // If not include in index.php set mchat.php page true
                if (!$include_on_index) {
                    // Yes its custom page...
                    $mchat_custom_page = true;
                    // If custom page false mchat.php page redirect to index...
                    if (!$this->config_mchat['custom_page'] && $mchat_custom_page) {
                        $mchat_redirect = append_sid("{$this->phpbb_root_path}index.{$this->phpEx}");
                        // Redirect to previous page
                        meta_refresh(3, $mchat_redirect);
                        trigger_error($this->user->lang['MCHAT_NO_CUSTOM_PAGE'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>'));
                    }
                    // user has permissions to view the custom chat?
                    if (!$mchat_view && $mchat_custom_page) {
                        trigger_error('NOT_AUTHORISED', E_USER_NOTICE);
                    }
                    // if whois true
                    if ($this->config_mchat['whois']) {
                        // Grab group details for legend display for who is online on the custom page.
                        $order_legend = $this->config['legend_sort_groupname'] ? 'group_name' : 'group_legend';
                        if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) {
                            $sql = 'SELECT group_id, group_name, group_colour, group_type FROM ' . GROUPS_TABLE . '
						WHERE group_legend <> 0
							ORDER BY ' . $order_legend . ' ASC';
                        } else {
                            $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type FROM ' . GROUPS_TABLE . ' g
						LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id AND ug.user_id = ' . $this->user->data['user_id'] . ' AND ug.user_pending = 0)
							WHERE g.group_legend <> 0
								AND (g.group_type <> ' . GROUP_HIDDEN . '
									OR ug.user_id = ' . (int) $this->user->data['user_id'] . ')
							ORDER BY g.' . $order_legend . ' ASC';
                        }
                        $result = $this->db->sql_query($sql);
                        $legend = array();
                        while ($row = $this->db->sql_fetchrow($result)) {
                            $colour_text = $row['group_colour'] ? ' style="color:#' . $row['group_colour'] . '"' : '';
                            $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'];
                            if ($row['group_name'] == 'BOTS' || $this->user->data['user_id'] != ANONYMOUS && !$this->auth->acl_get('u_viewprofile')) {
                                $legend[] = '<span' . $colour_text . '>' . $group_name . '</span>';
                            } else {
                                $legend[] = '<a' . $colour_text . ' href="' . append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
                            }
                        }
                        $this->db->sql_freeresult($result);
                        $legend = implode(', ', $legend);
                        // Assign index specific vars
                        $this->template->assign_vars(array('LEGEND' => $legend));
                    }
                    $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['MCHAT_TITLE'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller')));
                }
                // Run code...
                if ($mchat_view) {
                    $message_number = $mchat_custom_page ? $this->config_mchat['message_limit'] : $this->config_mchat['message_num'];
                    $sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0';
                    // Message row
                    $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm
						FROM ' . $this->mchat_table . ' m
							LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
						' . $sql_where . '
						ORDER BY message_id DESC';
                    $result = $this->db->sql_query_limit($sql, $message_number);
                    $rows = $this->db->sql_fetchrowset($result);
                    $this->db->sql_freeresult($result);
                    if ($this->config['mchat_message_top']) {
                        $rows = array_reverse($rows, true);
                    }
                    foreach ($rows as $row) {
                        // auth check
                        if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) {
                            continue;
                        }
                        // edit, delete and permission auths
                        $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false;
                        // edit auths
                        if ($this->user->data['user_id'] == ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) {
                            $chat_auths = $this->user->data['session_ip'] == $row['user_ip'] ? true : false;
                        } else {
                            $chat_auths = $this->user->data['user_id'] == $row['user_id'] ? true : false;
                        }
                        $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false;
                        $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false;
                        $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : '';
                        $message_edit = $row['message'];
                        decode_message($message_edit, $row['bbcode_uid']);
                        $message_edit = str_replace('"', '&quot;', $message_edit);
                        // Edit Fix ;)
                        $message_edit = mb_ereg_replace("'", "&#146;", $message_edit);
                        if (sizeof($foes_array)) {
                            if (in_array($row['user_id'], $foes_array)) {
                                $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
                            }
                        }
                        $row['username'] = mb_ereg_replace("'", "&#146;", $row['username']);
                        $message = str_replace('\'', '&rsquo;', $row['message']);
                        $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&amp;mode=compose&amp;u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2));
                    }
                    // Write no message
                    if (empty($rows)) {
                        $mchat_no_message = true;
                    }
                    // display custom bbcodes
                    if ($mchat_allow_bbcode && $this->config['allow_bbcode']) {
                        $this->functions_mchat->display_mchat_bbcodes();
                    }
                    // Smile row
                    if ($mchat_smilies) {
                        if (!function_exists('generate_smilies')) {
                            include $this->phpbb_root_path . 'includes/functions_posting.' . $this->phpEx;
                        }
                        generate_smilies('inline', 0);
                    }
                    // If the static message is defined in the language file use it, else just use the entry in the database
                    if (isset($this->user->lang[strtoupper('static_message')]) || !empty($this->config_mchat['static_message'])) {
                        $this->config_mchat['static_message'] = $this->config_mchat['static_message'];
                        if (isset($this->user->lang[strtoupper('static_message')])) {
                            $this->config_mchat['static_message'] = $this->user->lang[strtoupper('static_message')];
                        }
                    }
                    // If the static message is defined in the language file use it, else just use the entry in the database
                    if (isset($this->user->lang[strtoupper('mchat_rules')]) || !empty($this->config_mchat['rules'])) {
                        if (isset($this->user->lang[strtoupper('mchat_rules')])) {
                            $this->config_mchat['rules'] = $this->user->lang[strtoupper('mchat_rules')];
                        }
                    }
                    // a list of users using the chat
                    if ($mchat_custom_page) {
                        $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time, true);
                    } else {
                        $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time);
                    }
                    $this->template->assign_vars(array('MCHAT_USERS_COUNT' => $mchat_users['mchat_users_count'], 'MCHAT_USERS_LIST' => $mchat_users['online_userlist']));
                }
                break;
        }
        // show index stats
        if (!empty($this->config['mchat_stats_index']) && !empty($this->user->data['user_mchat_stats_index'])) {
            // stats display
            $mchat_session_time = !empty($this->config_mchat['timeout']) ? $this->config_mchat['timeout'] : $this->config['session_length'];
            $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time);
            $this->template->assign_vars(array('MCHAT_INDEX_STATS' => true, 'MCHAT_INDEX_USERS_COUNT' => $mchat_stats['mchat_users_count'], 'MCHAT_INDEX_USERS_LIST' => !empty($mchat_stats['online_userlist']) ? $mchat_stats['online_userlist'] : '', 'L_MCHAT_ONLINE_EXPLAIN' => $mchat_stats['refresh_message']));
        }
        $copyright = base64_decode('PGEgaHJlZj0iaHR0cDovL3JtY2dpcnI4My5vcmciPlJNY0dpcnI4MzwvYT4gJmNvcHk7IDxhIGhyZWY9Imh0dHA6Ly93d3cuZG16eC13ZWIubmV0IiB0aXRsZT0id3d3LmRtengtd2ViLm5ldCI+ZG16eDwvYT4=');
        add_form_key('mchat_posting');
        // Template function...
        $this->template->assign_vars(array('MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'), 'MCHAT_REFRESH_JS' => 1000 * $this->config_mchat['refresh'], 'MCHAT_ADD_MESSAGE' => $mchat_add_mess, 'MCHAT_READ_MODE' => $mchat_read_mode, 'MCHAT_ARCHIVE_MODE' => $mchat_archive_mode, 'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'], 'MCHAT_RULES' => $mchat_rules, 'MCHAT_ALLOW_SMILES' => $mchat_smilies, 'MCHAT_ALLOW_IP' => $mchat_ip, 'MCHAT_ALLOW_PM' => $mchat_pm, 'MCHAT_ALLOW_LIKE' => $mchat_like, 'MCHAT_ALLOW_QUOTE' => $mchat_quote, 'MCHAT_NOMESSAGE_MODE' => $mchat_no_message, 'MCHAT_ALLOW_BBCODES' => $mchat_allow_bbcode && $this->config['allow_bbcode'] ? true : false, 'MCHAT_MESSAGE_TOP' => $this->config['mchat_message_top'] ? true : false, 'MCHAT_ENABLE' => $this->config['mchat_enable'], 'MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')), 'MCHAT_CUSTOM_PAGE' => $mchat_custom_page, 'MCHAT_INDEX_HEIGHT' => $this->config_mchat['index_height'], 'MCHAT_CUSTOM_HEIGHT' => $this->config_mchat['custom_height'], 'MCHAT_READ_ARCHIVE_BUTTON' => $mchat_read_archive, 'MCHAT_FOUNDER' => $mchat_founder, 'MCHAT_CLEAN_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'clean', 'redirect' => $on_page)), 'MCHAT_STATIC_MESS' => !empty($this->config_mchat['static_message']) ? htmlspecialchars_decode($this->config_mchat['static_message']) : '', 'L_MCHAT_COPYRIGHT' => $copyright, 'MCHAT_WHOIS' => $this->config_mchat['whois'], 'MCHAT_MESSAGE_LNGTH' => $this->config_mchat['max_message_lngth'], 'L_MCHAT_MESSAGE_LNGTH_EXPLAIN' => intval($this->config_mchat['max_message_lngth']) ? sprintf($this->user->lang['MCHAT_MESSAGE_LNGTH_EXPLAIN'], intval($this->config_mchat['max_message_lngth'])) : '', 'MCHAT_MESS_LONG' => sprintf($this->user->lang['MCHAT_MESS_LONG'], $this->config_mchat['max_message_lngth']), 'MCHAT_USER_TIMEOUT' => $this->config_mchat['timeout'] ? 1000 * $this->config_mchat['timeout'] : false, 'MCHAT_WHOIS_REFRESH' => 1000 * $this->config_mchat['whois_refresh'], 'MCHAT_PAUSE_ON_INPUT' => $this->config_mchat['pause_on_input'] ? true : false, 'L_MCHAT_ONLINE_EXPLAIN' => $this->functions_mchat->mchat_session_time($mchat_session_time), 'MCHAT_REFRESH_YES' => sprintf($this->user->lang['MCHAT_REFRESH_YES'], $this->config_mchat['refresh']), 'L_MCHAT_WHOIS_REFRESH_EXPLAIN' => sprintf($this->user->lang['WHO_IS_REFRESH_EXPLAIN'], $this->config_mchat['whois_refresh']), 'S_MCHAT_AVATARS' => $mchat_avatars, 'S_MCHAT_LOCATION' => $this->config_mchat['location'], 'S_MCHAT_SOUND_YES' => $this->user->data['user_mchat_sound'], 'S_MCHAT_INDEX_STATS' => $this->user->data['user_mchat_stats_index'], 'U_MORE_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'rules')), 'S_MCHAT_ON_INDEX' => $this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index']) ? true : false));
        // Return for: \$this->helper->render(filename, lang_title);
        return array('filename' => 'mchat_body.html', 'lang_title' => $this->user->lang['MCHAT_TITLE']);
    }
Esempio n. 26
0
 /**
  * Looks at the list of allowed extensions and generates a string
  * appropriate for use in configuring plupload with
  *
  * @param \phpbb\cache\service $cache
  * @param string $forum_id The ID of the forum
  *
  * @return string
  */
 public function generate_filter_string(\phpbb\cache\service $cache, $forum_id)
 {
     $attach_extensions = $cache->obtain_attach_extensions($forum_id);
     unset($attach_extensions['_allowed_']);
     $groups = array();
     // Re-arrange the extension array to $groups[$group_name][]
     foreach ($attach_extensions as $extension => $extension_info) {
         if (!isset($groups[$extension_info['group_name']])) {
             $groups[$extension_info['group_name']] = array();
         }
         $groups[$extension_info['group_name']][] = $extension;
     }
     $filters = array();
     foreach ($groups as $group => $extensions) {
         $filters[] = sprintf("{title: '%s', extensions: '%s'}", addslashes(ucfirst(strtolower($group))), addslashes(implode(',', $extensions)));
     }
     return implode(',', $filters);
 }
Esempio n. 27
0
 protected function finalise_update()
 {
     $this->cache->purge();
     $this->config->increment('assets_version', 1);
 }
Esempio n. 28
0
    /**
     * {@inheritdoc}
     */
    public function get_template_center($module_id)
    {
        $news = $this->request->variable('news_' . $module_id, -1);
        $news = $news > $this->config['board3_number_of_news_' . $module_id] - 1 ? -1 : $news;
        $this->user->add_lang('viewforum');
        $start = $this->request->variable('np_' . $module_id, 0);
        $start = $start < 0 ? 0 : $start;
        $total_news = 1;
        // Fetch news from portal functions.php with check if "read full" is requested.
        $portal_news_length = $news < 0 && !$this->config['board3_news_style_' . $module_id] ? $this->config['board3_news_length_' . $module_id] : 0;
        $this->fetch_posts->set_module_id($module_id);
        $fetch_news = $this->fetch_posts->get_posts($this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $start, (bool) $this->config['board3_news_exclude_' . $module_id]);
        $topic_icons = false;
        if (!empty($fetch_news['topic_icons'])) {
            $topic_icons = true;
        }
        // Standard news row
        $news_row = array('S_NEWEST_OR_FIRST' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['JUMP_NEWEST'] : $this->user->lang['JUMP_FIRST'], 'POSTED_BY_TEXT' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['LAST_POST'] : $this->user->lang['POSTED'], 'S_DISPLAY_NEWS_RVS' => $this->config['board3_show_news_replies_views_' . $module_id] ? true : false, 'S_TOPIC_ICONS' => $topic_icons, 'MODULE_ID' => $module_id);
        // Any news present? If not terminate it here.
        if (sizeof($fetch_news) == 0) {
            // Create standard news row
            $this->template->assign_block_vars('news', $news_row);
            $this->template->assign_block_vars('news.news_row', array('S_NO_TOPICS' => true, 'S_NOT_LAST' => false));
        } else {
            // Count number of posts for news archive, considering if permission check is dis- or enabled.
            if ($this->config['board3_news_archive_' . $module_id]) {
                $permissions = $this->config['board3_news_permissions_' . $module_id];
                $forum_from = $this->config['board3_news_forum_' . $module_id];
                $forum_from = strpos($forum_from, ',') !== false ? explode(',', $forum_from) : ($forum_from != '' ? array($forum_from) : array());
                $str_where = '';
                // Get disallowed forums
                $disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
                if ($this->config['board3_news_exclude_' . $module_id] == true) {
                    $disallow_access = array_merge($disallow_access, $forum_from);
                    $forum_from = array();
                }
                if (sizeof($forum_from)) {
                    $disallow_access = array_diff($forum_from, $disallow_access);
                    if (!sizeof($disallow_access)) {
                        return array();
                    }
                    foreach ($disallow_access as $acc_id) {
                        $acc_id = (int) $acc_id;
                        $str_where .= "forum_id = {$acc_id} OR ";
                    }
                } else {
                    foreach ($disallow_access as $acc_id) {
                        $acc_id = (int) $acc_id;
                        $str_where .= "forum_id <> {$acc_id} AND ";
                    }
                }
                $str_where = strlen($str_where) > 0 ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
                $topic_type = $this->config['board3_show_all_news_' . $module_id] ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL;
                $sql = 'SELECT COUNT(topic_id) AS num_topics
					FROM ' . TOPICS_TABLE . '
					WHERE ' . $topic_type . '
						AND topic_visibility = ' . ITEM_APPROVED . '
						AND topic_moved_id = 0
						' . $str_where;
                $result = $this->db->sql_query($sql, 300);
                $total_news = (int) $this->db->sql_fetchfield('num_topics');
                $this->db->sql_freeresult($result);
            }
            $topic_tracking_info = get_portal_tracking_info($fetch_news);
            // Create pagination if necessary
            if ($this->config['board3_news_archive_' . $module_id]) {
                $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $module_id);
            }
            if ($this->config['board3_number_of_news_' . $module_id] != 0 && $this->config['board3_news_archive_' . $module_id]) {
                $news_row = array_merge($news_row, array('NP_PAGINATION' => !empty($pagination) ? $pagination : '', 'TOTAL_NEWS' => $total_news == 1 ? sprintf($this->user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($this->user->lang['VIEW_FORUM_TOPICS'][2], $total_news), 'NP_PAGE_NUMBER' => $this->pagination->on_page($total_news, $this->config['board3_number_of_news_' . $module_id], $start)));
            }
            // Create standard news row
            $this->template->assign_block_vars('news', $news_row);
            // Show the news overview
            if ($news < 0) {
                $count = $fetch_news['topic_count'];
                for ($i = 0; $i < $count; $i++) {
                    if (isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) {
                        $open_bracket = '[ ';
                        $close_bracket = ' ]';
                        $read_full = $this->user->lang['READ_FULL'];
                    } else {
                        $open_bracket = '';
                        $close_bracket = '';
                        $read_full = '';
                    }
                    // unread?
                    $forum_id = $fetch_news[$i]['forum_id'];
                    $topic_id = $fetch_news[$i]['topic_id'];
                    $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                    $read_full_url = $this->request->is_set('np_' . $module_id) ? "np_{$module_id}={$start}&amp;news_{$module_id}={$i}#n_{$module_id}_{$i}" : "news_{$module_id}={$i}#n_{$module_id}_{$i}";
                    $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
                    $replies = $this->auth->acl_get('m_approve', $forum_id) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies'];
                    switch ($fetch_news[$i]['topic_type']) {
                        case POST_STICKY:
                            $folder = 'sticky_read';
                            $folder_new = 'sticky_unread';
                            break;
                        case POST_ANNOUNCE:
                            $folder = 'announce_read';
                            $folder_new = 'announce_unread';
                            break;
                        default:
                            $folder = 'topic_read';
                            $folder_new = 'topic_unread';
                            if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) {
                                $folder .= '_hot';
                                $folder_new .= '_hot';
                            }
                            break;
                    }
                    if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) {
                        $folder .= '_locked';
                        $folder_new .= '_locked';
                    }
                    if ($fetch_news[$i]['topic_posted']) {
                        $folder .= '_mine';
                        $folder_new .= '_mine';
                    }
                    $folder_img = $unread_topic ? $folder_new : $folder;
                    $folder_alt = $unread_topic ? 'NEW_POSTS' : ($fetch_news[$i]['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
                    // Grab icons
                    $icons = $this->cache->obtain_icons();
                    $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'USERNAME_FULL_LAST' => $fetch_news[$i]['username_full_last'], 'U_USER_PROFILE' => ($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&amp;u=' . $fetch_news[$i]['user_id']) : '', 'TIME' => $fetch_news[$i]['topic_time'], 'LAST_POST_TIME' => $this->user->format_date($fetch_news[$i]['topic_last_post_time']), 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['height'] : '', 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id'] . '&amp;p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id'] . '&amp;view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&amp;f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_NOT_LAST' => $i < sizeof($fetch_news) - 1 ? true : false, 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false));
                    // Assign pagination
                    $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1);
                    if (!empty($fetch_news[$i]['attachments'])) {
                        foreach ($fetch_news[$i]['attachments'] as $attachment) {
                            $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                        }
                    }
                }
            } else {
                $i = $news;
                $forum_id = $fetch_news[$i]['forum_id'];
                $topic_id = $fetch_news[$i]['topic_id'];
                $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                $open_bracket = '[ ';
                $close_bracket = ' ]';
                $read_full = $this->user->lang['BACK'];
                $read_full_url = $this->request->is_set('np_' . $module_id) ? $this->modules_helper->route('board3_portal_controller') . "?np_{$module_id}={$start}#n_{$module_id}_{$i}" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_{$i}";
                $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
                $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'TIME' => $fetch_news[$i]['topic_time'], 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&amp;f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'U_READ_FULL' => $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false));
                $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1);
                if (!empty($fetch_news[$i]['attachments'])) {
                    foreach ($fetch_news[$i]['attachments'] as $attachment) {
                        $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                    }
                }
            }
        }
        $this->template->assign_vars(array('NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE')));
        if ($this->config['board3_news_style_' . $module_id]) {
            return 'news_compact_center.html';
        } else {
            return 'news_center.html';
        }
    }
    public function upcoming_birthdays()
    {
        $time = $this->user->create_datetime();
        $now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset());
        $today = mktime(0, 0, 0, $now['mon'], $now['mday'], $now['year']);
        // Number of seconds per day
        $secs_per_day = 24 * 60 * 60;
        // We will use the timezone offset for our cache name
        $cache_name = $time->getOffset();
        $cache_name = str_replace('-', 'minus_', $cache_name);
        $cache_name = $cache_name . '_ubl';
        if (($upcomingbirthdays = $this->cache->get('_' . $cache_name)) === false) {
            // Only care about dates ahead of today.  Start date is always tomorrow
            $date_start = $now[0] + $secs_per_day;
            $date_end = $date_start + (int) $this->config['allow_birthdays_ahead'] * $secs_per_day;
            $dates = array();
            while ($date_start <= $date_end) {
                $day = date('j', $date_start);
                $month = date('n', $date_start);
                $dates[] = $this->db->sql_escape(sprintf('%2d-%2d-', $day, $month));
                $date_start = $date_start + $secs_per_day;
            }
            $sql_array = array();
            foreach ($dates as $date) {
                $sql_array[] = "u.user_birthday LIKE '" . $date . "%'";
            }
            $sql = 'SELECT u.user_id, u.username, u.user_colour, u.user_birthday, b.ban_id
				FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . BANLIST_TABLE . " b ON (u.user_id = b.ban_userid)\n\t\t\t\tWHERE (b.ban_id IS NULL\n\t\t\t\t\tOR b.ban_exclude = 1)\n\t\t\t\t\tAND (" . implode(' OR ', $sql_array) . ")\n\t\t\t\t\tAND " . $this->db->sql_in_set('u.user_type', array(USER_NORMAL, USER_FOUNDER));
            $result = $this->db->sql_query($sql);
            $upcomingbirthdays = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $bdday = $bdmonth = 0;
                list($bdday, $bdmonth) = array_map('intval', explode('-', $row['user_birthday']));
                $bdcheck = strtotime(gmdate('Y') . '-' . (int) trim($bdmonth) . '-' . (int) trim($bdday) . ' UTC');
                $bdyear = $bdcheck < $today ? (int) gmdate('Y') + 1 : (int) gmdate('Y');
                $bddate = $bdyear . '-' . (int) $bdmonth . '-' . (int) $bdday;
                // re-write those who have feb 29th as a birthday but only on non leap years
                if ((int) trim($bdday) == 29 && (int) trim($bdmonth) == 2) {
                    if (!$this->is_leap_year($bdyear) && !$time->format('L')) {
                        $bdday = 28;
                        $bddate = $bdyear . '-' . (int) trim($bdmonth) . '-' . (int) trim($bdday);
                    }
                }
                $upcomingbirthdays[] = array('user_birthday_tstamp' => strtotime($bddate . ' UTC'), 'username' => $row['username'], 'user_birthdayyear' => $bdyear, 'user_birthday' => $row['user_birthday'], 'user_id' => $row['user_id'], 'user_colour' => $row['user_colour']);
            }
            $this->db->sql_freeresult($result);
            // cache this data for one hour, this improves performance
            $this->cache->put('_' . $cache_name, $upcomingbirthdays, 3600);
        }
        sort($upcomingbirthdays);
        $birthday_ahead_list = '';
        $tomorrow = mktime(0, 0, 0, $now['mon'], $now['mday'] + 1, $now['year']);
        for ($i = 0, $end = sizeof($upcomingbirthdays); $i < $end; $i++) {
            if ($upcomingbirthdays[$i]['user_birthday_tstamp'] >= $tomorrow && $upcomingbirthdays[$i]['user_birthday_tstamp'] <= $today + $this->config['allow_birthdays_ahead'] * $secs_per_day) {
                $user_link = get_username_string('full', $upcomingbirthdays[$i]['user_id'], $upcomingbirthdays[$i]['username'], $upcomingbirthdays[$i]['user_colour']);
                $birthdate = getdate($upcomingbirthdays[$i]['user_birthday_tstamp']);
                //lets add to the birthday_ahead list.
                $birthday_ahead_list .= ($birthday_ahead_list != '' ? $this->user->lang['COMMA_SEPARATOR'] : '') . '<span title="' . $birthdate['mday'] . '-' . $birthdate['mon'] . '-' . $birthdate['year'] . '">' . $user_link . '</span>';
                if ($age = (int) substr($upcomingbirthdays[$i]['user_birthday'], -4)) {
                    $birthday_ahead_list .= ' (' . ($upcomingbirthdays[$i]['user_birthdayyear'] - $age) . ')';
                }
            }
        }
        // Assign index specific vars
        $this->template->assign_vars(array('BIRTHDAYS_AHEAD_LIST' => $birthday_ahead_list, 'L_BIRTHDAYS_AHEAD' => $this->user->lang('BIRTHDAYS_AHEAD', $this->config['allow_birthdays_ahead'])));
    }
Esempio n. 30
0
    public function display_recent_topics($tpl_loopname = 'recent_topics', $spec_forum_id = 0, $include_subforums = true)
    {
        $this->user->add_lang_ext('paybas/recenttopics', 'recenttopics');
        /**
         * Set some internal needed variables
         */
        $topics_per_page = $this->config['rt_number'];
        $num_pages = $this->config['rt_page_number'];
        $min_topic_level = $this->config['rt_min_topic_level'];
        $excluded_topics = $this->config['rt_anti_topics'];
        $display_parent_forums = $this->config['rt_parents'];
        $unread_only = $this->config['rt_unreadonly'];
        $sort_topics = $this->config['rt_sort_start_time'] ? 'topic_time' : 'topic_last_post_time';
        $persistent_display = $this->config['rt_persistent_display'];
        if ($persistent_display) {
            $this->template->assign_vars(array(strtoupper($tpl_loopname) . '_DISPLAY' => true));
        }
        $start = $this->request->variable($tpl_loopname . '_start', 0);
        $excluded_topic_ids = explode(', ', $excluded_topics);
        $total_limit = $topics_per_page * $num_pages;
        if (!function_exists('display_forums')) {
            include $this->root_path . 'includes/functions_display.' . $this->phpEx;
        }
        /**
         * Get the forums we take our topics from
         */
        // Get the allowed forums
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ids = array_unique($forum_ary);
        if (!sizeof($forum_ids)) {
            // No forums with f_read
            return;
        }
        $spec_forum_ary = array();
        if ($spec_forum_id) {
            // Only take a special-forum
            if (!$include_subforums) {
                if (!in_array($spec_forum_id, $forum_ids)) {
                    return;
                }
                $forum_ids = array();
                $sql = 'SELECT 1 as display_forum
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . intval($spec_forum_id) . '
						AND forum_recent_topics = 1';
                $result = $this->db->sql_query_limit($sql, 1);
                $display_forum = (bool) $this->db->sql_fetchfield('display_forum');
                $this->db->sql_freeresult($result);
                if ($display_forum) {
                    $forum_ids = array($spec_forum_id);
                }
            } else {
                // ... and it's subforums
                $sql = 'SELECT f2.forum_id
					FROM ' . FORUMS_TABLE . ' f1
					LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\t\tORDER BY f2.left_id DESC";
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $spec_forum_ary[] = $row['forum_id'];
                }
                $this->db->sql_freeresult($result);
                $forum_ids = array_intersect($forum_ids, $spec_forum_ary);
                if (!sizeof($forum_ids)) {
                    return;
                }
            }
        } else {
            $sql = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . '
					AND forum_recent_topics = 1';
            $result = $this->db->sql_query($sql);
            $forum_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $forum_ids[] = $row['forum_id'];
            }
            $this->db->sql_freeresult($result);
        }
        // No forums with f_read or recent topics enabled
        if (!sizeof($forum_ids)) {
            return;
        }
        // Remove duplicated ids
        $forum_ids = array_unique($forum_ids);
        $forums = $topic_list = array();
        $topics_count = 0;
        $obtain_icons = false;
        // Either use the phpBB core function to get unread topics, or the custom function for default behavior
        if ($unread_only && $this->user->data['user_id'] != ANONYMOUS) {
            // Get unread topics
            $sql_extra = ' AND ' . $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true);
            $sql_extra .= ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.');
            $unread_topics = get_unread_topics(false, $sql_extra, '', $total_limit);
            foreach ($unread_topics as $topic_id => $mark_time) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $topic_id;
                }
            }
        } else {
            // Get the allowed topics
            $sql_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . '
					AND t.topic_status <> ' . ITEM_MOVED . '
					AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
            // Check if we want all topics, or only stickies/announcements/globals
            if ($min_topic_level > 0) {
                $sql_array['WHERE'] .= ' AND t.topic_type >= ' . $min_topic_level;
            }
            /**
             * Event to modify the SQL query before the allowed topics list data is retrieved
             *
             * @event paybas.recenttopics.sql_pull_topics_list
             * @var    array    sql_array        The SQL array
             * @since 2.0.4
             */
            $vars = array('sql_array');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_list', compact($vars)));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query_limit($sql, $total_limit);
            while ($row = $this->db->sql_fetchrow($result)) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $row['topic_id'];
                    $rowset[$row['topic_id']] = $row;
                    if (!isset($forums[$row['forum_id']]) && $this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                        $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
                    }
                    $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
                    $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']];
                    if ($row['icon_id'] && $this->auth->acl_get('f_icons', $row['forum_id'])) {
                        $obtain_icons = true;
                    }
                }
            }
            $this->db->sql_freeresult($result);
        }
        // No topics to display
        if (!sizeof($topic_list)) {
            return;
        }
        // Grab icons
        if ($obtain_icons) {
            $icons = $this->cache->obtain_icons();
        } else {
            $icons = array();
        }
        // Borrowed from search.php
        foreach ($forums as $forum_id => $forum) {
            if ($this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']);
            } else {
                if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                    $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                    $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                    $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']);
                    if (!$this->user->data['is_registered']) {
                        $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                    }
                }
            }
        }
        // Now only pull the data of the requested topics
        $sql_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_list), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
        if ($display_parent_forums) {
            $sql_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id';
        }
        /**
         * Event to modify the SQL query before the topics data is retrieved
         *
         * @event paybas.recenttopics.sql_pull_topics_data
         * @var    array    sql_array        The SQL array
         * @since 2.0.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $topics_per_page);
        $rowset = $topic_icons = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $rowset[] = $row;
        }
        $this->db->sql_freeresult($result);
        // No topics returned by the DB
        if (!sizeof($rowset)) {
            return;
        }
        /**
         * Event to modify the topics list data before we start the display loop
         *
         * @event paybas.recenttopics.modify_topics_list
         * @var    array    topic_list        Array of all the topic IDs
         * @var    array    rowset            The full topics list array
         * @since 2.0.1
         */
        $vars = array('topic_list', 'rowset');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_topics_list', compact($vars)));
        foreach ($rowset as $row) {
            $topic_id = $row['topic_id'];
            $forum_id = $row['forum_id'];
            $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            //$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
            $replies = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
            if ($unread_only) {
                topic_status($row, $replies, true, $folder_img, $folder_alt, $topic_type);
                $unread_topic = true;
            } else {
                topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type);
                $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false;
            }
            $view_topic_url = append_sid("{$this->root_path}viewtopic.{$this->phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id);
            $view_forum_url = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $forum_id);
            $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $forum_id);
            $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $forum_id);
            $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $this->user->session_id) : '';
            $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            if (!empty($icons[$row['icon_id']])) {
                $topic_icons[] = $topic_id;
            }
            // Get folder img, topic status/type related information
            $folder_img = $folder_alt = $topic_type = '';
            topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
            $tpl_ary = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? $this->user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
            /**
             * Modify the topic data before it is assigned to the template
             *
             * @event paybas.recenttopics.modify_tpl_ary
             * @var    array    row            Array with topic data
             * @var    array    tpl_ary        Template block array with topic data
             * @since 2.0.0
             */
            $vars = array('row', 'tpl_ary');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_tpl_ary', compact($vars)));
            $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
            $this->pagination->generate_template_pagination($view_topic_url, $tpl_loopname . '.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            if ($display_parent_forums) {
                $forum_parents = get_forum_parents($row);
                foreach ($forum_parents as $parent_id => $data) {
                    $this->template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $parent_id)));
                }
            }
        }
        // Get URL-parameters for pagination
        $url_params = explode('&', $this->user->page['query_string']);
        $append_params = false;
        foreach ($url_params as $param) {
            if (!$param) {
                continue;
            }
            if (strpos($param, '=') === false) {
                // Fix MSSTI Advanced BBCode MOD
                $append_params[$param] = '1';
                continue;
            }
            list($name, $value) = explode('=', $param);
            if ($name != $tpl_loopname . '_start') {
                $append_params[$name] = $value;
            }
        }
        $pagination_url = append_sid($this->root_path . $this->user->page['page_name'], $append_params);
        $this->pagination->generate_template_pagination($pagination_url, 'rt_pagination', $tpl_loopname . '_start', $topics_count, $topics_per_page, $start);
        $this->template->assign_vars(array('RT_SORT_START_TIME' => $sort_topics === 'topic_time' ? true : false, 'S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), strtoupper($tpl_loopname) . '_DISPLAY' => true));
    }