Esempio n. 1
0
 /**
  * builds the cache if it doesn't exist
  */
 function mchat_cache()
 {
     // Grab the config entries in the ACP...and cache em :P
     if (($config_mchat = $this->cache->get('_mchat_config')) === false) {
         $sql = 'SELECT * FROM ' . $this->mchat_config_table;
         $result = $this->db->sql_query($sql);
         $config_mchat = array();
         while ($row = $this->db->sql_fetchrow($result)) {
             $config_mchat[$row['config_name']] = $row['config_value'];
         }
         $this->db->sql_freeresult($result);
         $this->cache->put('_mchat_config', $config_mchat);
     }
 }
Esempio n. 2
0
 /**
  * Build a cache of group names
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function build_group_name_cache($event)
 {
     if ($this->cache->get('_user_groups') === false) {
         $sql_ary = array('SELECT' => 'ug.user_id, g.group_name, g.group_colour, g.group_type, g.group_id', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array(USER_GROUP_TABLE => 'ug'), 'ON' => 'ug.user_id = u.user_id'), array('FROM' => array(GROUPS_TABLE => 'g'), 'ON' => 'ug.group_id = g.group_id')), 'WHERE' => $this->db->sql_in_set('u.user_type', array(USER_FOUNDER, USER_NORMAL)) . ' AND ug.user_pending = 0', 'ORDER_BY' => 'u.user_id ASC, g.group_name');
         $result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary));
         $user_groups = array();
         while ($row = $this->db->sql_fetchrow($result)) {
             $user_groups[$row['user_id']][] = array('group_name' => (string) $row['group_name'], 'group_colour' => $row['group_colour'], 'group_id' => $row['group_id'], 'group_type' => $row['group_type']);
         }
         $this->db->sql_freeresult($result);
         // cache this data for 5 minutes
         $this->cache->put('_user_groups', $user_groups, 300);
     }
 }
Esempio n. 3
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];
    }
    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;
    }
Esempio n. 5
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;
    }
    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. 7
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. 8
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. 9
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;
    }
    /**
     * cache_flags
     *
     * Build the cache of the flags
     *
     * @return null
     */
    public function cache_flags()
    {
        if ($this->cache->get('_user_flags') === false) {
            $sql = 'SELECT flag_id, flag_name, flag_image
				FROM ' . $this->flags_table . '
			ORDER BY flag_id';
            $result = $this->db->sql_query($sql);
            $user_flags = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $user_flags[$row['flag_id']] = array('flag_id' => $row['flag_id'], 'flag_name' => $row['flag_name'], 'flag_image' => $row['flag_image']);
            }
            $this->db->sql_freeresult($result);
            // cache this data for ever, can only change in ACP
            $this->cache->put('_user_flags', $user_flags);
        }
    }
    /**
     * 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. 12
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));
    }
 public function common_config($event)
 {
     $sql_array = array('SELECT' => 'config_name, config_value', 'FROM' => array($this->points_config_table => 'c'));
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql);
     while ($row = $this->db->sql_fetchrow($result)) {
         $points_config[$row['config_name']] = $row['config_value'];
     }
     $this->db->sql_freeresult($result);
     $this->cache->put('points_config', $points_config);
     $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v'));
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql);
     $points_values = $this->db->sql_fetchrow($result);
     $this->db->sql_freeresult($result);
     $this->cache->put('points_values', $points_values);
     return $points_values;
 }
    /**
     * 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;
    }
    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'])));
    }