示例#1
0
 /**
  * Executes the command cache:purge.
  *
  * Purge the cache (including permissions) and increment the asset_version number
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->config->increment('assets_version', 1);
     $this->cache->purge();
     // Clear permissions
     $this->auth->acl_clear_prefetch();
     src_cache_moderators($this->db, $this->cache, $this->auth);
     $this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array());
     $output->writeln($this->user->lang('PURGE_CACHE_SUCCESS'));
 }
示例#2
0
 /**
  * Provide the class loader with a cache to store paths. If set to null, the
  * the class loader will resolve paths by checking for the existance of every
  * directory in the class name every time.
  *
  * @param \src\cache\driver\driver_interface $cache An implementation of the src cache interface.
  */
 public function set_cache(\src\cache\driver\driver_interface $cache = null)
 {
     if ($cache) {
         $this->cached_paths = $cache->get('class_loader_' . str_replace('\\', '__', $this->namespace));
         if ($this->cached_paths === false) {
             $this->cached_paths = array();
         }
     }
     $this->cache = $cache;
 }
示例#3
0
    /**
     * Increments an integer config value directly in the database.
     *
     * Using this method instead of setting the new value directly avoids race
     * conditions and unlike set_atomic it cannot fail.
     *
     * @param string $key       The configuration option's name
     * @param int    $increment Amount to increment by
     * @param bool   $use_cache Whether this variable should be cached or if it
     *                          changes too frequently to be efficiently cached.
     */
    function increment($key, $increment, $use_cache = true)
    {
        if (!isset($this->config[$key])) {
            $this->set($key, '0', $use_cache);
        }
        $sql_update = $this->db->cast_expr_to_string($this->db->cast_expr_to_bigint('config_value') . ' + ' . (int) $increment);
        $this->db->sql_query('UPDATE ' . $this->table . '
			SET config_value = ' . $sql_update . "\n\t\t\tWHERE config_name = '" . $this->db->sql_escape($key) . "'");
        if ($use_cache) {
            $this->cache->destroy('config');
        }
        $this->config[$key] += $increment;
    }
示例#4
0
    /**
     * Obtain disallowed usernames
     */
    function obtain_disallowed_usernames()
    {
        if (($usernames = $this->driver->get('_disallowed_usernames')) === false) {
            $sql = 'SELECT disallow_username
				FROM ' . DISALLOW_TABLE;
            $result = $this->db->sql_query($sql);
            $usernames = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
            }
            $this->db->sql_freeresult($result);
            $this->driver->put('_disallowed_usernames', $usernames);
        }
        return $usernames;
    }
示例#5
0
    function get_excluded_forums()
    {
        static $forum_ids;
        // Matches acp/acp_srcrd.php
        $cache_name = 'feed_excluded_forum_ids';
        if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false) {
            $sql = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
            $result = $this->db->sql_query($sql);
            $forum_ids = array();
            while ($forum_id = (int) $this->db->sql_fetchfield('forum_id')) {
                $forum_ids[$forum_id] = $forum_id;
            }
            $this->db->sql_freeresult($result);
            $this->cache->put('_' . $cache_name, $forum_ids);
        }
        return $forum_ids;
    }
示例#6
0
    /**
     * Moves an item up/down
     *
     * @param	int		$teampage_id	teampage_id of the item to be moved
     * @param	int		$delta		number of steps:
     *								- positive = move up
     *								- negative = move down
     * @return	bool		True if the group was moved successfully
     */
    public function move_teampage($teampage_id, $delta)
    {
        $delta = (int) $delta;
        if (!$delta) {
            return false;
        }
        $move_up = $delta > 0 ? true : false;
        $data = $this->get_teampage_values($teampage_id);
        $current_value = (int) $data['teampage_position'];
        if ($current_value != self::GROUP_DISABLED) {
            $this->db->sql_transaction('begin');
            if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) {
                // If we move items down, we need to grab the one sibling more,
                // so we do not ignore the children of the previous sibling.
                // We will remove the additional sibling later on.
                $delta = abs($delta) + 1;
            }
            $sql = 'SELECT teampage_id, teampage_position
				FROM ' . TEAMPAGE_TABLE . '
				WHERE teampage_parent = ' . (int) $data['teampage_parent'] . '
					AND teampage_position' . ($move_up ? ' < ' : ' > ') . $current_value . '
				ORDER BY teampage_position' . ($move_up ? ' DESC' : ' ASC');
            $result = $this->db->sql_query_limit($sql, $delta);
            $sibling_count = 0;
            $sibling_limit = $delta;
            // Reset the delta, as we recalculate the new real delta
            $delta = 0;
            while ($row = $this->db->sql_fetchrow($result)) {
                $sibling_count++;
                $delta = $current_value - $row['teampage_position'];
                // Remove the additional sibling we added previously
                // But only, if we included it, this is not be the case
                // when we reached the end of our list
                if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit) {
                    $delta++;
                }
            }
            $this->db->sql_freeresult($result);
            if ($delta) {
                $sql = 'SELECT COUNT(teampage_id) as num_items
					FROM ' . TEAMPAGE_TABLE . '
					WHERE teampage_id = ' . (int) $teampage_id . '
						OR teampage_parent = ' . (int) $teampage_id;
                $result = $this->db->sql_query($sql);
                $num_items = (int) $this->db->sql_fetchfield('num_items');
                $this->db->sql_freeresult($result);
                // First we move all items between our current value and the target value up/down 1,
                // so we have a gap for our item to move.
                $sql = 'UPDATE ' . TEAMPAGE_TABLE . '
					SET teampage_position = teampage_position' . ($move_up ? ' + ' : ' - ') . $num_items . '
					WHERE teampage_position' . ($move_up ? ' >= ' : ' <= ') . ($current_value - $delta) . '
						AND teampage_position' . ($move_up ? ' < ' : ' > ') . $current_value . '
						AND NOT (teampage_id = ' . (int) $teampage_id . '
							OR teampage_parent = ' . (int) $teampage_id . ')';
                $this->db->sql_query($sql);
                $delta = !$move_up && $data['teampage_parent'] == self::NO_PARENT ? abs($delta) - ($num_items - 1) : abs($delta);
                // And now finally, when we moved some other items and built a gap,
                // we can move the desired item to it.
                $sql = 'UPDATE ' . TEAMPAGE_TABLE . '
					SET teampage_position = teampage_position ' . ($move_up ? ' - ' : ' + ') . $delta . '
					WHERE teampage_id = ' . (int) $teampage_id . '
						OR teampage_parent = ' . (int) $teampage_id;
                $this->db->sql_query($sql);
                $this->db->sql_transaction('commit');
                $this->cache->destroy('sql', TEAMPAGE_TABLE);
                return true;
            }
            $this->db->sql_transaction('commit');
        }
        $this->cache->destroy('sql', TEAMPAGE_TABLE);
        return false;
    }
示例#7
0
    /**
     * Show style details
     */
    protected function action_details()
    {
        $id = $this->request->variable('id', 0);
        if (!$id) {
            trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Get all styles
        $styles = $this->get_styles();
        usort($styles, array($this, 'sort_styles'));
        // Find current style
        $style = false;
        foreach ($styles as $row) {
            if ($row['style_id'] == $id) {
                $style = $row;
                break;
            }
        }
        if ($style === false) {
            trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Find all available parent styles
        $list = $this->find_possible_parents($styles, $id);
        // Add form key
        $form_key = 'acp_styles';
        add_form_key($form_key);
        // Change data
        if ($this->request->variable('update', false)) {
            if (!check_form_key($form_key)) {
                trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            $update = array('style_name' => trim($this->request->variable('style_name', $style['style_name'])), 'style_parent_id' => $this->request->variable('style_parent', (int) $style['style_parent_id']), 'style_active' => $this->request->variable('style_active', (int) $style['style_active']));
            $update_action = $this->u_action . '&amp;action=details&amp;id=' . $id;
            // Check style name
            if ($update['style_name'] != $style['style_name']) {
                if (!strlen($update['style_name'])) {
                    trigger_error($this->user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING);
                }
                foreach ($styles as $row) {
                    if ($row['style_name'] == $update['style_name']) {
                        trigger_error($this->user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING);
                    }
                }
            } else {
                unset($update['style_name']);
            }
            // Check parent style id
            if ($update['style_parent_id'] != $style['style_parent_id']) {
                if ($update['style_parent_id'] != 0) {
                    $found = false;
                    foreach ($list as $row) {
                        if ($row['style_id'] == $update['style_parent_id']) {
                            $found = true;
                            $update['style_parent_tree'] = ($row['style_parent_tree'] != '' ? $row['style_parent_tree'] . '/' : '') . $row['style_path'];
                            break;
                        }
                    }
                    if (!$found) {
                        trigger_error($this->user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING);
                    }
                } else {
                    $update['style_parent_tree'] = '';
                }
            } else {
                unset($update['style_parent_id']);
            }
            // Check style_active
            if ($update['style_active'] != $style['style_active']) {
                if (!$update['style_active'] && $this->default_style == $style['style_id']) {
                    trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING);
                }
            } else {
                unset($update['style_active']);
            }
            // Update data
            if (count($update)) {
                $sql = 'UPDATE ' . STYLES_TABLE . '
					SET ' . $this->db->sql_build_array('UPDATE', $update) . "\n\t\t\t\t\tWHERE style_id = {$id}";
                $this->db->sql_query($sql);
                $style = array_merge($style, $update);
                if (isset($update['style_parent_id'])) {
                    // Update styles tree
                    $styles = $this->get_styles();
                    if ($this->update_styles_tree($styles, $style)) {
                        // Something was changed in styles tree, purge all cache
                        $this->cache->purge();
                    }
                }
                add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']);
            }
            // Update default style
            $default = $this->request->variable('style_default', 0);
            if ($default) {
                if (!$style['style_active']) {
                    trigger_error($this->user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING);
                }
                set_config('default_style', $id);
                $this->cache->purge();
            }
            // Show styles list
            $this->frontend();
            return;
        }
        // Show page title
        $this->welcome_message('ACP_STYLES', null);
        // Show parent styles
        foreach ($list as $row) {
            $this->template->assign_block_vars('parent_styles', array('STYLE_ID' => $row['style_id'], 'STYLE_NAME' => htmlspecialchars($row['style_name']), 'LEVEL' => $row['level'], 'SPACER' => str_repeat('&nbsp; ', $row['level'])));
        }
        // Show style details
        $this->template->assign_vars(array('S_STYLE_DETAILS' => true, 'STYLE_ID' => $style['style_id'], 'STYLE_NAME' => htmlspecialchars($style['style_name']), 'STYLE_PATH' => htmlspecialchars($style['style_path']), 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_PARENT' => $style['style_parent_id'], 'S_STYLE_ACTIVE' => $style['style_active'], 'S_STYLE_DEFAULT' => $style['style_id'] == $this->default_style));
    }