Przeglądaj źródła

Changed cache system, fix search.php

Visman 8 lat temu
rodzic
commit
a2dd3dcd37

+ 2 - 3
addons/security_for_login.php

@@ -173,9 +173,8 @@ class addon_security_for_login extends flux_addon
 
 	function gen_cache()
 	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
+        global $container;
 
-		generate_config_cache();
+        $container->get('config update');
 	}
 }

+ 2 - 3
addons/security_for_post.php

@@ -172,9 +172,8 @@ class addon_security_for_post extends flux_addon
 
 	function gen_cache()
 	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
+        global $container;
 
-		generate_config_cache();
+        $container->get('config update');
 	}
 }

+ 2 - 3
addons/security_for_register.php

@@ -173,9 +173,8 @@ class addon_security_for_register extends flux_addon
 
 	function gen_cache()
 	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
+        global $container;
 
-		generate_config_cache();
+        $container->get('config update');
 	}
 }

+ 2 - 10
admin_bans.php

@@ -292,11 +292,7 @@ else if ($request->isPost('add_edit_ban'))
 	else
 		$db->query('UPDATE '.$db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($request->postInt('ban_id'))) or error('Unable to update ban', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the bans cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_bans_cache();
+    $container->get('bans update');
 
 	if ($request->postStr('mode') == 'edit')
 		redirect('admin_bans.php', $lang_admin_bans['Ban edited redirect']);
@@ -315,11 +311,7 @@ else if ($request->isGet('del_ban'))
 
 	$db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Unable to delete ban', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the bans cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_bans_cache();
+    $container->get('bans update');
 
 	redirect('admin_bans.php', $lang_admin_bans['Ban removed redirect']);
 }

+ 3 - 15
admin_censoring.php

@@ -39,11 +39,7 @@ if ($request->isPost('add_word'))
 	$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'censoring WHERE search_for IN (\''.$word.'\',\'*'.$word.'\',\''.$word.'*\',\'*'.$word.'*\')') or error('Unable to fetch censor word', __FILE__, __LINE__, $db->error());
 	$nwords = $db->result($result);
 	
-	// Regenerate the censoring cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_censoring_cache();
+    $container->get('censoring update');
 
 	redirect('admin_censoring.php'.(($nwords > 1) ? '?censorflag=1' : ''), $lang_admin_censoring['Word added redirect']);
 }
@@ -70,11 +66,7 @@ else if ($request->isPost('update'))
 	$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'censoring WHERE search_for IN (\''.$word.'\',\'*'.$word.'\',\''.$word.'*\',\'*'.$word.'*\')') or error('Unable to fetch censor word', __FILE__, __LINE__, $db->error());
 	$nwords = $db->result($result);
 
-	// Regenerate the censoring cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_censoring_cache();
+    $container->get('censoring update');
 
 	redirect('admin_censoring.php'.(($nwords > 1) ? '?censorflag=1' : ''), $lang_admin_censoring['Word updated redirect']);
 }
@@ -88,11 +80,7 @@ else if ($request->isPost('remove'))
 
 	$db->query('DELETE FROM '.$db->prefix.'censoring WHERE id='.$id) or error('Unable to delete censor word', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the censoring cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_censoring_cache();
+    $container->get('censoring update');
 
 	redirect('admin_censoring.php', $lang_admin_censoring['Word removed redirect']);
 }

+ 1 - 5
admin_groups.php

@@ -408,11 +408,7 @@ else if ($request->isPost('set_default_group'))
 
 	$db->query('UPDATE '.$db->prefix.'config SET conf_value='.$group_id.' WHERE conf_name=\'o_default_user_group\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the config cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+	$container->get('config update');
 
 	redirect('admin_groups.php', $lang_admin_groups['Default group redirect']);
 }

+ 1 - 1
admin_options.php

@@ -205,7 +205,7 @@ if ($request->isPost('form_sent'))
 	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 		require PUN_ROOT.'include/cache.php';
 
-	generate_config_cache();
+	$container->get('config update');
 	clear_feed_cache();
 
 	redirect('admin_options.php', $lang_admin_options['Options updated redirect']);

+ 1 - 5
admin_permissions.php

@@ -39,11 +39,7 @@ if ($request->isPost('form_sent'))
 			$db->query('UPDATE '.$db->prefix.'config SET conf_value='.$input.' WHERE conf_name=\'p_'.$db->escape($key).'\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 	}
 
-	// Regenerate the config cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+	$container->get('config update');
 
 	redirect('admin_permissions.php', $lang_admin_permissions['Perms updated redirect']);
 }

+ 2 - 10
admin_users.php

@@ -508,11 +508,7 @@ else if ($request->isPost('delete_users') || $request->isPost('delete_users_comp
 		foreach ($user_ids as $user_id)
 			delete_avatar($user_id);
 
-		// Regenerate the users info cache
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_users_info_cache();
+        $container->get('users_info update');
 
 // New PMS - Visman
 		require PUN_ROOT.'include/pms_new/common_pmsn.php';
@@ -642,11 +638,7 @@ else if ($request->isPost('ban_users') || $request->isPost('ban_users_comply'))
 			$db->query('INSERT INTO '.$db->prefix.'bans (username, ip, email, message, expire, ban_creator) VALUES('.$ban_username.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.', '.$pun_user['id'].')') or error('Unable to add ban', __FILE__, __LINE__, $db->error());
 		}
 
-		// Regenerate the bans cache
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_bans_cache();
+        $container->get('bans update');
 
 		redirect('admin_users.php', $lang_admin_users['Users banned redirect']);
 	}

+ 85 - 0
app/Core/Cache.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace ForkBB\Core;
+
+use ForkBB\Core\Cache\ProviderCacheInterface;
+
+class Cache
+{
+    /**
+     * Провайдер доступа к кэшу
+     * @var ProviderInterfaces
+     */
+    protected $provider;
+
+    /**
+     * Конструктор
+     *
+     * @param ProviderInterfaces $provider
+     */
+    public function __construct(ProviderCacheInterface $provider)
+    {
+        $this->provider = $provider;
+    }
+
+    /**
+     * Получение данных из кэша по ключу
+     *
+     * @param string $key
+     * @param mixed $default
+     *
+     * @return mixed
+     */
+    public function get($key, $default = null)
+    {
+        return $this->provider->get($key, $default);
+    }
+
+    /**
+     * Установка данных в кэш по ключу
+     *
+     * @param string $key
+     * @param mixed $value
+     * @param int $ttl
+     *
+     * @return bool
+     */
+    public function set($key, $value, $ttl = null)
+    {
+        return $this->provider->set($key, $value, $ttl);
+    }
+
+    /**
+     * Удаление данных по ключу
+     *
+     * @param string $key
+     *
+     * @return bool
+     */
+    public function delete($key)
+    {
+        return $this->provider->delete($key);
+    }
+
+    /**
+     * Очистка кэша
+     *
+     * @return bool
+     */
+    public function clear()
+    {
+        return $this->provider->clear();
+    }
+
+    /**
+     * Проверка наличия ключа
+     *
+     * @param string $key
+     *
+     * @return bool
+     */
+    public function has($key)
+    {
+        return $this->provider->has($key);
+    }
+}

+ 168 - 0
app/Core/Cache/FileCache.php

@@ -0,0 +1,168 @@
+<?php
+
+namespace ForkBB\Core\Cache;
+
+use RuntimeException;
+use InvalidArgumentException;
+
+class FileCache implements ProviderCacheInterface
+{
+    /**
+     * Директория кэша
+     * @var string
+     */
+    protected $cacheDir;
+
+    /**
+     * Конструктор
+     *
+     * @param string $dir
+     *
+     * @throws \InvalidArgumentException
+     * @throws \RuntimeException
+     */
+    public function __construct($dir)
+    {
+        if (empty($dir) || ! is_string($dir)) {
+            throw new InvalidArgumentException('Cache directory must be set to a string');
+        } elseif (! is_dir($dir)) {
+            throw new RuntimeException("`$dir`: Not a directory");
+        } elseif (! is_writable($dir)) {
+            throw new RuntimeException("No write access to `$dir` directory");
+        }
+        $this->cacheDir = $dir;
+    }
+
+    /**
+     * Получение данных из кэша по ключу
+     *
+     * @param string $key
+     * @param mixed $default
+     *
+     * @return mixed
+     */
+    public function get($key, $default = null)
+    {
+        $file = $this->file($key);
+        if (file_exists($file)) {
+            require $file;
+
+            if (isset($expire) && isset($data)
+                && ($expire < 1 || $expire > time())
+            ) {
+                return $data;
+            }
+        }
+        return $default;
+    }
+
+    /**
+     * Установка данных в кэш по ключу
+     *
+     * @param string $key
+     * @param mixed $value
+     * @param int $ttl
+     *
+     * @throws \RuntimeException
+     * @return bool
+     */
+    public function set($key, $value, $ttl = null)
+    {
+        $file = $this->file($key);
+        $expire = null === $ttl || $ttl < 1 ? 0 : time() + $ttl;
+        $content = "<?php\n\n" . '$expire = ' . $expire . ";\n\n" . '$data = ' . var_export($value, true) . ";\n";
+        if (false === file_put_contents($file, $content, LOCK_EX)) {
+            throw new RuntimeException("The key '$key' can not be saved");
+        } else {
+            $this->invalidate($file);
+            return true;
+        }
+    }
+
+    /**
+     * Удаление данных по ключу
+     *
+     * @param string $key
+     *
+     * @throws \RuntimeException
+     * @return bool
+     */
+    public function delete($key)
+    {
+        $file = $this->file($key);
+        if (file_exists($file)) {
+            if (unlink($file)) {
+                $this->invalidate($file);
+                return true;
+            } else {
+                throw new RuntimeException("The key `$key` could not be removed");
+            }
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * Очистка кэша
+     *
+     * @return bool
+     */
+    public function clear()
+    {
+        $d = dir($this->cacheDir);
+        if (! $d) {
+            return false;
+        }
+        $result = true;
+        while (($entry = $d->read()) !== false) {
+            if (substr($entry, -4) == '.php') {
+                $f = unlink($this->cacheDir . '/' . $entry);
+                $result = $result && $f;
+            }
+        }
+        $d->close();
+        return $result;
+    }
+
+    /**
+     * Проверка наличия ключа
+     *
+     * @param string $key
+     *
+     * @return bool
+     */
+    public function has($key)
+    {
+        return null !== $this->get($key);
+    }
+
+    /**
+     * Генерация имени файла по ключу
+     *
+     * @param string $key
+     *
+     * @throws \InvalidArgumentException
+     * @return string
+     */
+    protected function file($key)
+    {
+        if (is_string($key) && preg_match('%^[\w-]+$%D', $key)) {
+            return $this->cacheDir . '/cache_' . $key . '.php';
+        }
+        throw new InvalidArgumentException("`$key`: Key contains invalid characters");
+    }
+
+    /**
+     * Очистка opcache и apc от закэшированного файла
+     *
+     * @param string $file
+     */
+    protected function invalidate($file)
+    {
+        if (function_exists('opcache_invalidate')) {
+            opcache_invalidate($file, true);
+        } elseif (function_exists('apc_delete_file')) {
+            apc_delete_file($file);
+        }
+    }
+}

+ 52 - 0
app/Core/Cache/ProviderCacheInterface.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace ForkBB\Core\Cache;
+
+interface ProviderCacheInterface
+{
+    /**
+     * Получение данных из кэша по ключу
+     *
+     * @param string $key
+     * @param mixed $default
+     *
+     * @return mixed
+     */
+    public function get($key, $default = null);
+
+    /**
+     * Установка данных в кэш по ключу
+     *
+     * @param string $key
+     * @param mixed $value
+     * @param int $ttl
+     *
+     * @return bool
+     */
+    public function set($key, $value, $ttl = null);
+
+    /**
+     * Удаление данных по ключу
+     *
+     * @param string $key
+     *
+     * @return bool
+     */
+    public function delete($key);
+
+    /**
+     * Очистка кэша
+     *
+     * @return bool
+     */
+    public function clear();
+
+    /**
+     * Проверка наличия ключа
+     *
+     * @param string $key
+     *
+     * @return bool
+     */
+    public function has($key);
+}

+ 5 - 0
app/Core/Secury.php

@@ -18,6 +18,9 @@ class Secury
      * Конструктор
      *
      * @param array $hmac
+     *
+     * @throws \InvalidArgumentException
+     * @throws \UnexpectedValueException
      */
     public function __construct(array $hmac)
     {
@@ -36,6 +39,7 @@ class Secury
      * @param string $data
      * @param string $key
      *
+     * @throws \InvalidArgumentException
      * @return string
      */
     public function hmac($data, $key)
@@ -51,6 +55,7 @@ class Secury
      *
      * @param int $len
      *
+     * @throws \RuntimeException
      * @return string
      */
     public function randomKey($len)

+ 134 - 0
app/Models/Actions/CacheGenerator.php

@@ -0,0 +1,134 @@
+<?php
+
+namespace ForkBB\Models\Actions;
+
+//use ForkBB\Core\DB;
+
+class CacheGenerator
+{
+    /**
+     * @var ForkBB\Core\DB
+     */
+    protected $db;
+
+    /**
+     * Конструктор
+     *
+     * @param ForkBB\Core\DB $db
+     */
+    public function __construct($db)
+    {
+        $this->db = $db;
+    }
+
+    /**
+     * Возвращает массив конфигурации форума
+     *
+     * @return array
+     */
+    public function config()
+    {
+        // Get the forum config from the DB
+        $result = $this->db->query('SELECT * FROM '.$this->db->prefix.'config', true) or error('Unable to fetch forum config', __FILE__, __LINE__, $this->db->error());
+        $arr = [];
+        while ($cur = $this->db->fetch_row($result)) {
+            $arr[$cur[0]] = $cur[1];
+        }
+        $this->db->free_result($result);
+        return $arr;
+    }
+
+    /**
+     * Возвращает массив банов
+     *
+     * @return array
+     */
+    public function bans()
+    {
+        // Get the ban list from the DB
+        $result = $this->db->query('SELECT * FROM '.$this->db->prefix.'bans', true) or error('Unable to fetch ban list', __FILE__, __LINE__, $this->db->error());
+        $arr = [];
+        while ($cur = $this->db->fetch_assoc($result)) {
+            $arr[] = $cur;
+        }
+        $this->db->free_result($result);
+        return $arr;
+    }
+
+    /**
+     * Возвращает массив слов попадающий под цензуру
+     *
+     * @return array
+     */
+    public function censoring()
+    {
+        $result = $this->db->query('SELECT search_for, replace_with FROM '.$this->db->prefix.'censoring') or error('Unable to fetch censoring list', __FILE__, __LINE__, $this->db->error());
+        $num_words = $this->db->num_rows($result);
+
+        $search_for = $replace_with = [];
+        for ($i = 0; $i < $num_words; $i++) {
+            list($search_for[$i], $replace_with[$i]) = $this->db->fetch_row($result);
+            $search_for[$i] = '%(?<=[^\p{L}\p{N}])('.str_replace('\*', '[\p{L}\p{N}]*?', preg_quote($search_for[$i], '%')).')(?=[^\p{L}\p{N}])%iu';
+        }
+        $this->db->free_result($result);
+
+        return [
+            'search_for' => $search_for,
+            'replace_with' => $replace_with
+        ];
+    }
+
+    /**
+     * Возвращает информацию о последнем зарегистрированном пользователе и
+     * общем числе пользователей
+     *
+     * @return array
+     */
+    public function usersInfo()
+    {
+        $stats = [];
+
+        $result = $this->db->query('SELECT COUNT(id)-1 FROM '.$this->db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $this->db->error());
+        $stats['total_users'] = $this->db->result($result);
+
+        $result = $this->db->query('SELECT id, username FROM '.$this->db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $this->db->error());
+        $stats['last_user'] = $this->db->fetch_assoc($result);
+
+        return $stats;
+    }
+
+    /**
+     * Возвращает спимок id админов
+     *
+     * @return array
+     */
+    public function admins()
+    {
+        // Get admins from the DB
+        $result = $this->db->query('SELECT id FROM '.$this->db->prefix.'users WHERE group_id='.PUN_ADMIN) or error('Unable to fetch users info', __FILE__, __LINE__, $this->db->error());
+        $arr = [];
+        while ($row = $this->db->fetch_row($result)) {
+            $arr[] = $row[0];
+        }
+        $this->db->free_result($result);
+
+        return $arr;
+    }
+
+    /**
+     * Возвращает массив с описанием смайлов
+     *
+     * @return array
+     */
+    public function smilies()
+    {
+        $arr = [];
+        $result = $this->db->query('SELECT text, image FROM '.$this->db->prefix.'smilies ORDER BY disp_position') or error('Unable to retrieve smilies', __FILE__, __LINE__, $this->db->error());
+        while ($cur = $this->db->fetch_assoc($result)) {
+            $arr[$cur['text']] = $cur['image'];
+        }
+        $this->db->free_result($result);
+
+        return $arr;
+    }
+}

+ 68 - 0
app/Models/Actions/CacheLoader.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace ForkBB\Models\Actions;
+
+use ForkBB\Core\Cache;
+use R2\DependencyInjection\ContainerInterface;
+use R2\DependencyInjection\ContainerAwareInterface;
+use InvalidArgumentException;
+
+class CacheLoader implements ContainerAwareInterface
+{
+    /**
+     * Контейнер
+     * @var ContainerInterface
+     */
+    protected $c;
+
+    /**
+     * Инициализация контейнера
+     *
+     * @param ContainerInterface $container
+     */
+    public function setContainer(ContainerInterface $container)
+    {
+        $this->c = $container;
+    }
+
+    /**
+     * @var ForkBB\Core\Cache
+     */
+    protected $cache;
+
+    /**
+     * Конструктор
+     *
+     * @param ForkBB\Core\Cache $cache
+     */
+    public function __construct(Cache $cache)
+    {
+        $this->cache = $cache;
+    }
+
+    /**
+     * Загрузка данных из кэша (генерация кэша при отсутствии или по требованию)
+     *
+     * @param string $key
+     * @param bool $update
+     *
+     * @throws \InvalidArgumentException
+     * @return mixed
+     */
+    public function load($key, $update = false)
+    {
+        if (preg_match('%\p{Lu}%u', $key)) {
+            throw new InvalidArgumentException('The key must not contain uppercase letters');
+        }
+        if (! $update && $this->cache->has($key)) {
+            return $this->cache->get($key);
+        } else {
+            $value = $this->c->get('get ' . $key);
+            $this->cache->set($key, $value);
+            if ($update) {
+                $this->c->set($key, $value);
+            }
+            return $value;
+        }
+    }
+}

+ 104 - 0
app/Models/Actions/CacheStopwords.php

@@ -0,0 +1,104 @@
+<?php
+
+namespace ForkBB\Models\Actions;
+
+use ForkBB\Core\Cache;
+
+class CacheStopwords
+{
+    /**
+     * @var ForkBB\Core\Cache
+     */
+    protected $cache;
+
+    /**
+     * @var array
+     */
+    protected $files;
+
+    /**
+     * @var string
+     */
+    protected $id;
+
+    /**
+     * Конструктор
+     *
+     * @param ForkBB\Core\Cache $cache
+     */
+    public function __construct(Cache $cache)
+    {
+        $this->cache = $cache;
+    }
+
+    /**
+     * Возвращает массив слов, которые не участвуют в поиске
+     *
+     * @return array
+     */
+    public function load()
+    {
+        $arr = $this->cache->get('stopwords');
+        if (isset($arr['id'])
+            && isset($arr['stopwords'])
+            && $arr['id'] === $this->generateId()
+        ) {
+            return $arr['stopwords'];
+        } else {
+            return $this->regeneration();
+        }
+    }
+
+    /**
+     * Генерация id кэша на основе найденных файлов stopwords.txt
+     *
+     * @return string
+     */
+    protected function generateId()
+    {
+        if (! empty($this->id)) {
+            return $this->id;
+        }
+
+        $files = glob(PUN_ROOT . 'lang/*/stopwords.txt');
+        if ($files === false) {
+            return 'cache_id_error';
+        }
+
+        $this->files = $files;
+        $hash = [];
+
+        foreach ($files as $file) {
+            $hash[] = $file;
+            $hash[] = filemtime($file);
+        }
+
+        return $this->id = sha1(implode('|', $hash));
+    }
+
+    /**
+     * Регенерация кэша массива слов с возвращением результата
+     *
+     * @return array
+     */
+    protected function regeneration()
+    {
+        $id = $this->generateId();
+
+        if (! is_array($this->files)) {
+            return [];
+        }
+
+        $stopwords = [];
+        foreach ($this->files as $file) {
+            $stopwords = array_merge($stopwords, file($file));
+        }
+
+        // Tidy up and filter the stopwords
+        $stopwords = array_map('trim', $stopwords);
+        $stopwords = array_filter($stopwords);
+
+        $this->cache->set('stopwords', ['id' => $id, 'stopwords' => $stopwords]);
+        return $stopwords;
+    }
+}

+ 4 - 3
db_update.php

@@ -623,12 +623,14 @@ if (isset($_POST['req_db_pass']))
 		}
 
 		$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$db->escape($maintenance_message).'\' WHERE conf_name=\'o_maintenance_message\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
-
+/*
 		// Regenerate the config cache
 		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 			require PUN_ROOT.'include/cache.php';
 
 		generate_config_cache();
+*/
+        $container->get('config update');
 	}
 }
 else if (isset($_GET['uid']))
@@ -1346,8 +1348,7 @@ foreach ($errors[$id] as $cur_error)
 		while ($row = $db->fetch_row($result))
 			update_forum($row[0]);
 
-		// Empty the PHP cache
-		forum_clear_cache();
+        $container->get('Cache')->clear();
 
 		// Delete the update lock file
 		@unlink(FORUM_CACHE_DIR.'db_update.lock');

+ 1 - 1
delete.php

@@ -47,7 +47,7 @@ if (($pun_user['g_delete_posts'] == '0' ||
 	!$is_admmod)
 	message($lang_common['No permission'], false, '403 Forbidden');
 
-if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], get_admin_ids()))
+if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], $container->get('admins')))
 	message($lang_common['No permission'], false, '403 Forbidden');
 
 // мод ограничения времени редактирвания - Visman

+ 1 - 1
edit.php

@@ -50,7 +50,7 @@ if (($pun_user['g_edit_posts'] == '0' ||
 	!$is_admmod)
 	message($lang_common['No permission'], false, '403 Forbidden');
 
-if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], get_admin_ids()))
+if ($is_admmod && $pun_user['g_id'] != PUN_ADMIN && in_array($cur_post['poster_id'], $container->get('admins')))
 	message($lang_common['No permission'], false, '403 Forbidden');
 
 // мод ограничения времени редактирвания - Visman

+ 1 - 12
extern.php

@@ -518,18 +518,7 @@ else if ($action == 'stats')
 	// Load the index.php language file
 	require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
 
-	// Collect some statistics from the database
-	if (file_exists($container->getParameter('DIR_CACHE') . 'cache_users_info.php'))
-		include $container->getParameter('DIR_CACHE') . 'cache_users_info.php';
-
-	if (!defined('PUN_USERS_INFO_LOADED'))
-	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_users_info_cache();
-		require $container->getParameter('DIR_CACHE') . 'cache_users_info.php';
-	}
+    $stats = $container->get('users_info');
 
 	$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
 	list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);

+ 5 - 15
include/bbcode.inc.php

@@ -14,26 +14,16 @@ if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/img/bbcode/b.png'))
 else
 	$btndir = 'style/Air/img/bbcode/';
 
-if (!isset($smilies))
-{
-	if (file_exists($container->getParameter('DIR_CACHE') . 'cache_smilies.php'))
-		include $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-	else
-	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_smiley_cache();
-		require $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-	}
-}
+$smilies = $container->get('smilies');
 
 $smil_g = $smil_i = $smil_t = array();
 foreach ($smilies as $smileyt => $smileyi)
 {
-	if (isset($smil_g[$smileyi])) continue;
+	if (isset($smil_g[$smileyi])) {
+        continue;
+    }
 	$smil_g[$smileyi] = true;
-	$smil_i[] = "'".$smileyi."'";
+	$smil_i[] = "'".$smileyi."'"; //????
 	$smil_t[] = "'".addslashes($smileyt)."'";
 }
 

+ 0 - 165
include/cache.php

@@ -11,50 +11,6 @@ if (!defined('PUN'))
 	exit;
 
 
-//
-// Generate the config cache PHP script
-//
-function generate_config_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	// Get the forum config from the DB
-	$result = $db->query('SELECT * FROM '.$db->prefix.'config', true) or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());
-
-	$output = array();
-	while ($cur_config_item = $db->fetch_row($result))
-		$output[$cur_config_item[0]] = $cur_config_item[1];
-
-	// Output config as PHP code
-	$content = '<?php'."\n\n".'define(\'PUN_CONFIG_LOADED\', 1);'."\n\n".'$pun_config = '.var_export($output, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_config.php', $content);
-}
-
-
-//
-// Generate the bans cache PHP script
-//
-function generate_bans_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	// Get the ban list from the DB
-	$result = $db->query('SELECT * FROM '.$db->prefix.'bans', true) or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
-
-	$output = array();
-	while ($cur_ban = $db->fetch_assoc($result))
-		$output[] = $cur_ban;
-
-	// Output ban list as PHP code
-	$content = '<?php'."\n\n".'define(\'PUN_BANS_LOADED\', 1);'."\n\n".'$pun_bans = '.var_export($output, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_bans.php', $content);
-}
-
-
 //
 // Generate quick jump cache PHP scripts
 //
@@ -143,104 +99,6 @@ function generate_quickjump_cache($group_id = false)
 }
 
 
-//
-// Generate the censoring cache PHP script
-//
-function generate_censoring_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	$result = $db->query('SELECT search_for, replace_with FROM '.$db->prefix.'censoring') or error('Unable to fetch censoring list', __FILE__, __LINE__, $db->error());
-	$num_words = $db->num_rows($result);
-
-	$search_for = $replace_with = array();
-	for ($i = 0; $i < $num_words; $i++)
-	{
-		list($search_for[$i], $replace_with[$i]) = $db->fetch_row($result);
-		$search_for[$i] = '%(?<=[^\p{L}\p{N}])('.str_replace('\*', '[\p{L}\p{N}]*?', preg_quote($search_for[$i], '%')).')(?=[^\p{L}\p{N}])%iu';
-	}
-
-	// Output censored words as PHP code
-	$content = '<?php'."\n\n".'define(\'PUN_CENSOR_LOADED\', 1);'."\n\n".'$search_for = '.var_export($search_for, true).';'."\n\n".'$replace_with = '.var_export($replace_with, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_censoring.php', $content);
-}
-
-
-//
-// Generate the stopwords cache PHP script
-//
-function generate_stopwords_cache()
-{
-	$stopwords = array();
-
-	$d = dir(PUN_ROOT.'lang');
-	while (($entry = $d->read()) !== false)
-	{
-		if ($entry{0} == '.')
-			continue;
-
-		if (is_dir(PUN_ROOT.'lang/'.$entry) && file_exists(PUN_ROOT.'lang/'.$entry.'/stopwords.txt'))
-			$stopwords = array_merge($stopwords, file(PUN_ROOT.'lang/'.$entry.'/stopwords.txt'));
-	}
-	$d->close();
-
-	// Tidy up and filter the stopwords
-	$stopwords = array_map('trim', $stopwords);
-	$stopwords = array_filter($stopwords);
-
-	// Output stopwords as PHP code
-	$content = '<?php'."\n\n".'$cache_id = \''.generate_stopwords_cache_id().'\';'."\n".'if ($cache_id != generate_stopwords_cache_id()) return;'."\n\n".'define(\'PUN_STOPWORDS_LOADED\', 1);'."\n\n".'$stopwords = '.var_export($stopwords, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_stopwords.php', $content);
-}
-
-
-//
-// Load some information about the latest registered users
-//
-function generate_users_info_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	$stats = array();
-
-	$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
-	$stats['total_users'] = $db->result($result);
-
-	$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
-	$stats['last_user'] = $db->fetch_assoc($result);
-
-	// Output users info as PHP code
-	$content = '<?php'."\n\n".'define(\'PUN_USERS_INFO_LOADED\', 1);'."\n\n".'$stats = '.var_export($stats, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_users_info.php', $content);
-}
-
-
-//
-// Generate the admins cache PHP script
-//
-function generate_admins_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	// Get admins from the DB
-	$result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE group_id='.PUN_ADMIN) or error('Unable to fetch users info', __FILE__, __LINE__, $db->error());
-
-	$output = array();
-	while ($row = $db->fetch_row($result))
-		$output[] = $row[0];
-
-	// Output admin list as PHP code
-	$content = '<?php'."\n\n".'define(\'PUN_ADMINS_LOADED\', 1);'."\n\n".'$pun_admins = '.var_export($output, true).';'."\n\n".'?>';
-	fluxbb_write_cache_file('cache_admins.php', $content);
-}
-
-
 //
 // Safely write out a cache file.
 //
@@ -284,29 +142,6 @@ function clear_feed_cache()
 }
 
 
-//
-// Generate smiley cache PHP array
-//
-function generate_smiley_cache()
-{
-	global $container;
-
-    $db = $container->get('DB');
-
-	$str = '<?php'."\n".'$smilies = array('."\n";
-
-	$result = $db->query('SELECT image, text FROM '.$db->prefix.'smilies ORDER BY disp_position') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error());
-	while ($s = $db->fetch_assoc($result))
-	{
-		$str .= "'".addslashes(pun_htmlspecialchars($s['text']))."' => '".$s['image']."',"."\n";
-	}
-
-	$str .= ');'."\n".'?>';
-
-	fluxbb_write_cache_file('cache_smilies.php', $str);
-}
-
-
 //
 // Generate the subforums cache - Visman
 //

+ 1 - 27
include/common.php

@@ -66,20 +66,7 @@ $db = $container->get('DB');
 // Start a transaction
 $db->start_transaction();
 
-// Load cached config
-if (file_exists($container->getParameter('DIR_CACHE') . 'cache_config.php'))
-	include $container->getParameter('DIR_CACHE') . 'cache_config.php';
-
-if (!defined('PUN_CONFIG_LOADED'))
-{
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
-	require $container->getParameter('DIR_CACHE') . 'cache_config.php';
-}
-
-$container->set('config', $pun_config);
+$pun_config = $container->get('config');
 
 // Verify that we are running the proper database schema revision
 if (empty($pun_config['i_fork_revision']) || $pun_config['i_fork_revision'] < FORK_REVISION) {
@@ -115,19 +102,6 @@ else
 if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
 	maintenance_message();
 
-// Load cached bans
-if (file_exists($container->getParameter('DIR_CACHE') . 'cache_bans.php'))
-	include $container->getParameter('DIR_CACHE') . 'cache_bans.php';
-
-if (!defined('PUN_BANS_LOADED'))
-{
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_bans_cache();
-	require $container->getParameter('DIR_CACHE') . 'cache_bans.php';
-}
-
 // Check if current user is banned
 check_bans();
 

+ 4 - 2
include/email.php

@@ -31,9 +31,11 @@ function is_valid_email($email)
 //
 function is_banned_email($email)
 {
-	global $pun_bans;
+	global $container;
 
-	foreach ($pun_bans as $cur_ban)
+    $bans = $container->get('bans');
+
+	foreach ($bans as $cur_ban)
 	{
 		if ($cur_ban['email'] != '' &&
 			($email == $cur_ban['email'] ||

+ 19 - 127
include/functions.php

@@ -214,29 +214,6 @@ function get_base_url($support_https = false)
 }
 
 
-//
-// Fetch admin IDs
-//
-function get_admin_ids()
-{
-    global $container;
-
-	if (file_exists($container->getParameter('DIR_CACHE') . 'cache_admins.php'))
-		include $container->getParameter('DIR_CACHE') . 'cache_admins.php';
-
-	if (!defined('PUN_ADMINS_LOADED'))
-	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_admins_cache();
-		require $container->getParameter('DIR_CACHE') . 'cache_admins.php';
-	}
-
-	return $pun_admins;
-}
-
-
 //
 // Fill $pun_user with default values (for guests)
 //
@@ -310,52 +287,18 @@ function set_default_user()
 }
 
 
-//
-// SHA1 HMAC with PHP 4 fallback
-//
-function forum_hmac($data, $key, $raw_output = false)
-{
-	if (function_exists('hash_hmac'))
-		return hash_hmac('sha1', $data, $key, $raw_output);
-
-	// If key size more than blocksize then we hash it once
-	if (strlen($key) > 64)
-		$key = pack('H*', sha1($key)); // we have to use raw output here to match the standard
-
-	// Ensure we're padded to exactly one block boundary
-	$key = str_pad($key, 64, chr(0x00));
-
-	$hmac_opad = str_repeat(chr(0x5C), 64);
-	$hmac_ipad = str_repeat(chr(0x36), 64);
-
-	// Do inner and outer padding
-	for ($i = 0;$i < 64;$i++) {
-		$hmac_opad[$i] = $hmac_opad[$i] ^ $key[$i];
-		$hmac_ipad[$i] = $hmac_ipad[$i] ^ $key[$i];
-	}
-
-	// Finally, calculate the HMAC
-	$hash = sha1($hmac_opad.pack('H*', sha1($hmac_ipad.$data)));
-
-	// If we want raw output then we need to pack the final result
-	if ($raw_output)
-		$hash = pack('H*', $hash);
-
-	return $hash;
-}
-
-
 //
 // Check whether the connecting user is banned (and delete any expired bans while we're at it)
 //
 function check_bans()
 {
-	global $container, $pun_config, $lang_common, $pun_user, $pun_bans;
+	global $container, $pun_config, $lang_common, $pun_user;
 
     $db = $container->get('DB');
+    $bans = $container->get('bans');
 
 	// Admins and moderators aren't affected
-	if ($pun_user['is_admmod'] || !$pun_bans)
+	if ($pun_user['is_admmod'] || !$bans)
 		return;
 
 	// Add a dot or a colon (depending on IPv4/IPv6) at the end of the IP address to prevent banned address
@@ -366,7 +309,7 @@ function check_bans()
 	$bans_altered = false;
 	$is_banned = false;
 
-	foreach ($pun_bans as $cur_ban)
+	foreach ($bans as $cur_ban)
 	{
 		// Has this ban expired?
 		if ($cur_ban['expire'] != '' && $cur_ban['expire'] <= time())
@@ -410,10 +353,7 @@ function check_bans()
 	// If we removed any expired bans during our run-through, we need to regenerate the bans cache
 	if ($bans_altered)
 	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_bans_cache();
+        $container->get('bans update');
 	}
 }
 
@@ -423,9 +363,10 @@ function check_bans()
 //
 function check_username($username, $exclude_id = null)
 {
-	global $container, $pun_config, $errors, $lang_prof_reg, $lang_register, $lang_common, $pun_bans;
+	global $container, $pun_config, $errors, $lang_prof_reg, $lang_register, $lang_common;
 
     $db = $container->get('DB');
+    $bans = $container->get('bans');
 
 	// Convert multiple whitespace characters into one (to prevent people from registering with indistinguishable usernames)
 	$username = preg_replace('%\s+%s', ' ', $username);
@@ -462,7 +403,7 @@ function check_username($username, $exclude_id = null)
 	}
 
 	// Check username for any banned usernames
-	foreach ($pun_bans as $cur_ban)
+	foreach ($bans as $cur_ban)
 	{
 		if ($cur_ban['username'] != '' && mb_strtolower($username) == mb_strtolower($cur_ban['username']))
 		{
@@ -542,11 +483,7 @@ function update_users_online($tid = 0, &$witt_us = array())
 		$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$kol.'\' WHERE conf_name=\'st_max_users\'') or error('Unable to update config value \'st_max_users\'', __FILE__, __LINE__, $db->error());
 		$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$now.'\' WHERE conf_name=\'st_max_users_time\'') or error('Unable to update config value \'st_max_users_time\'', __FILE__, __LINE__, $db->error());
 
-		// Regenerate the config cache
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_config_cache();
+        $container->get('config update');
 	}
 }
 
@@ -834,48 +771,22 @@ function delete_post($post_id, $topic_id)
 }
 
 
-//
-// Delete every .php file in the forum's cache directory
-//
-function forum_clear_cache()
-{
-    global $container;
-
-	$d = dir($container->getParameter('DIR_CACHE'));
-	while (($entry = $d->read()) !== false)
-	{
-		if (substr($entry, -4) == '.php')
-			@unlink($container->getParameter('DIR_CACHE') . $entry);
-	}
-	$d->close();
-}
-
-
 //
 // Replace censored words in $text
 //
 function censor_words($text)
 {
-	static $container, $search_for, $replace_with;
+    global $container;
+	static $search_for, $replace_with;
 
 	// If not already built in a previous call, build an array of censor words and their replacement text
-	if (!isset($search_for))
-	{
-		if (file_exists($container->getParameter('DIR_CACHE') . 'cache_censoring.php'))
-			include $container->getParameter('DIR_CACHE') . 'cache_censoring.php';
-
-		if (!defined('PUN_CENSOR_LOADED'))
-		{
-			if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-				require PUN_ROOT.'include/cache.php';
-
-			generate_censoring_cache();
-			require $container->getParameter('DIR_CACHE') . 'cache_censoring.php';
-		}
+	if (!isset($search_for)) {
+        list($search_for, $replace_with) = $container->get('censoring');
 	}
 
-	if (!empty($search_for))
+	if (!empty($search_for)) {
 		$text = substr(ucp_preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);
+    }
 
 	return $text;
 }
@@ -887,15 +798,17 @@ function censor_words($text)
 //
 function get_title($user)
 {
-	global $pun_bans, $lang_common;
+	global $container, $lang_common;
 	static $ban_list;
 
+    $bans = $container->get('bans');
+
 	// If not already built in a previous call, build an array of lowercase banned usernames
 	if (empty($ban_list))
 	{
 		$ban_list = array();
 
-		foreach ($pun_bans as $cur_ban)
+		foreach ($bans as $cur_ban)
 			$ban_list[] = mb_strtolower($cur_ban['username']);
 	}
 
@@ -1750,27 +1663,6 @@ function forum_list_langs()
 }
 
 
-//
-// Generate a cache ID based on the last modification time for all stopwords files
-//
-function generate_stopwords_cache_id()
-{
-	$files = glob(PUN_ROOT.'lang/*/stopwords.txt');
-	if ($files === false)
-		return 'cache_id_error';
-
-	$hash = array();
-
-	foreach ($files as $file)
-	{
-		$hash[] = $file;
-		$hash[] = filemtime($file);
-	}
-
-	return sha1(implode('|', $hash));
-}
-
-
 //
 // Split text into chunks ($inside contains all text inside $start and $end, and $outside contains all text outside)
 //

+ 6 - 18
include/parser.php

@@ -38,22 +38,6 @@ if (!defined('PUN'))
 %iex' */
 $re_list = '%\[list(?:=([1a*]))?+\]((?:[^\[]*+(?:(?!\[list(?:=[1a*])?+\]|\[/list\])\[[^\[]*+)*+|(?R))*)\[/list\]%i';
 
-// Here you can add additional smilies if you like (please note that you must escape single quote and backslash)
-// Load smilies cache - Visman
-if (!isset($smilies))
-{
-	if (file_exists($container->getParameter('DIR_CACHE') . 'cache_smilies.php'))
-		include $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-	else
-	{
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_smiley_cache();
-		require $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-	}
-}
-
 //
 // Make sure all BBCodes are lower case and do a little cleanup
 //
@@ -941,14 +925,18 @@ function forum_array_key($arr, $key)
 //
 function do_smilies($text)
 {
-	global $smilies;
+	global $container;
+
+    // Load smilies cache - Visman
+    $smilies = $container->get('smilies');
 
 	$text = ' '.$text.' ';
 
 	foreach ($smilies as $smiley_text => $smiley_img)
 	{
-		if (strpos($text, $smiley_text) !== false)
+		if (strpos($text, $smiley_text) !== false) { //???? проблема: смайлы без кодирования, а текст уже с кодированием
 			$text = ucp_preg_replace('%(?<=[>\s])'.preg_quote($smiley_text, '%').'(?=[^\p{L}\p{N}])%um', '<img src="'.pun_htmlspecialchars(get_base_url(true).'/img/smilies/'.$smiley_img).'" alt="'.substr($smiley_img, 0, strrpos($smiley_img, '.')).'" />', $text);
+        }
 	}
 
 	return substr($text, 1, -1);

+ 1 - 11
include/search_idx.php

@@ -169,17 +169,7 @@ function validate_search_word($word, $idx)
 
 	if (!isset($stopwords))
 	{
-		if (file_exists($container->getParameter('DIR_CACHE') . 'cache_stopwords.php'))
-			include $container->getParameter('DIR_CACHE') . 'cache_stopwords.php';
-
-		if (!defined('PUN_STOPWORDS_LOADED'))
-		{
-			if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-				require PUN_ROOT.'include/cache.php';
-
-			generate_stopwords_cache();
-			require $container->getParameter('DIR_CACHE') . 'cache_stopwords.php';
-		}
+        $stopwords = $container->get('stopwords');
 	}
 
 	// If it is a stopword it isn't valid

+ 1 - 12
index.php

@@ -47,18 +47,7 @@ require PUN_ROOT.'header.php';
 
 require PUN_ROOT.'include/subforums_view.php'; // MOD subforums - Visman
 
-// Collect some statistics from the database
-if (file_exists($container->getParameter('DIR_CACHE') . 'cache_users_info.php'))
-	include $container->getParameter('DIR_CACHE') . 'cache_users_info.php';
-
-if (!defined('PUN_USERS_INFO_LOADED'))
-{
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_users_info_cache();
-	require $container->getParameter('DIR_CACHE') . 'cache_users_info.php';
-}
+$stats = $container->get('users_info');
 
 $result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
 list($stats['total_topics'], $stats['total_posts']) = array_map('intval', $db->fetch_row($result));

+ 1 - 1
js/post.js

@@ -76,7 +76,7 @@ FluxBB.post = (function (doc, win) {
 	function SmileysMapBB() {
 		var html = '';
 		for (var i = 0; i < FluxBB.vars.bbSmImg.length; i++) {
-			html += '<img src="img/smilies/' + FluxBB.vars.bbSmImg[i] + '" alt="' + FluxBB.vars.bbSmTxt[i] + '" onclick="return FluxBB.post.insText(\'\', \' ' + FluxBB.vars.bbSmTxt[i].replace(/\\/g, '\\\\').replace(/&#039;/g, '\\\'') + ' \');" />';
+			html += '<img src="img/smilies/' + FluxBB.vars.bbSmImg[i] + '" alt="' + FluxBB.vars.bbSmTxt[i] + '" onclick="return FluxBB.post.insText(\'\', \' ' + FluxBB.vars.bbSmTxt[i].replace(/\\/g, '\\\\').replace(/\'/g, '\\\'') + ' \');" />';
 		}
 		return html;
 	}

+ 1 - 5
login.php

@@ -68,11 +68,7 @@ if ($request->isPost('form_sent') && $action === 'in')
 		{
 			$db->query('UPDATE '.$db->prefix.'users SET group_id='.$pun_config['o_default_user_group'].' WHERE id='.$cur_user['id']) or error('Unable to update user status', __FILE__, __LINE__, $db->error());
 
-			// Regenerate the users info cache
-			if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-				require PUN_ROOT.'include/cache.php';
-
-			generate_users_info_cache();
+            $container->get('users_info update');
 		}
 
 		// перезаписываем ip админа и модератора - Visman

+ 2 - 2
moderate.php

@@ -92,7 +92,7 @@ if ($request->isGet('tid'))
 				message($lang_common['Bad request'], false, '404 Not Found');
 
 			// Verify that the post IDs are valid
-			$admins_sql = ($pun_user['g_id'] != PUN_ADMIN) ? ' AND poster_id NOT IN('.implode(',', get_admin_ids()).')' : '';
+			$admins_sql = ($pun_user['g_id'] != PUN_ADMIN) ? ' AND poster_id NOT IN('.implode(',', $container->get('admins')).')' : '';
 			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid.$admins_sql) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
 
 			if ($db->num_rows($result) != substr_count($posts, ',') + 1)
@@ -846,7 +846,7 @@ else if ($request->isPost('delete_topics') || $request->isPost('delete_topics_co
 		// Verify that the posts are not by admins
 		if ($pun_user['g_id'] != PUN_ADMIN)
 		{
-			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.') AND poster_id IN('.implode(',', get_admin_ids()).')') or error('Unable to check posts', __FILE__, __LINE__, $db->error());
+			$result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.') AND poster_id IN('.implode(',', $container->get('admins')).')') or error('Unable to check posts', __FILE__, __LINE__, $db->error());
 			if ($db->num_rows($result))
 				message($lang_common['No permission'], false, '403 Forbidden');
 		}

+ 4 - 16
plugins/AP_Fancybox.php

@@ -121,11 +121,8 @@ if ($request->isPost('installation'))
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_guest\', \'0\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_files\', \''.$db->escape(PLUGIN_FILES).'\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
+    $container->get('config update');
 
-	generate_config_cache();
-	
 	$err = InstallModInFiles();
 	if (empty($err))
 		redirect(PLUGIN_URL, $lang_fb['Red installation']);
@@ -151,10 +148,7 @@ else if ($request->isPost('update'))
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_guest\', \''.$gst.'\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_files\', \''.$db->escape(implode(',', $fls)).'\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_fb['Reg update']);
 }
@@ -164,11 +158,8 @@ else if ($request->isPost('delete'))
 {
 	$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name LIKE \'o\_fbox\_%\'') or error('Unable to remove config entries', __FILE__, __LINE__, $db->error());;
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
+    $container->get('config update');
 
-	generate_config_cache();
-	
 	$err = DeleteModInFiles();
 	if (empty($err))
 		redirect(PLUGIN_URL, $lang_fb['Red delete']);
@@ -187,10 +178,7 @@ if ($f_inst && !isset($pun_config['o_fbox_files'])) // непредвиденн
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_guest\', \'0\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_fbox_files\', \''.$db->escape(PLUGIN_FILES).'\')') or error('Unable to insert into table config.', __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, 'Synchronization of settings this plugin.');
 }

+ 2 - 9
plugins/AP_MergePosts.php

@@ -31,11 +31,7 @@ if ($request->isPost('show_text'))
 	$merge_timeout = $request->postInt('text_to_show', 0); //????
 	$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$merge_timeout.'\' WHERE conf_name=\'o_merge_timeout\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the config cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_admin_plugin_merge_posts['Plugin redirect']);
 }
@@ -55,10 +51,7 @@ else
 		else
 			$merge_timeout = $db->result($result);
 
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_config_cache();
+        $container->get('config update');
 	}
 	else
 		$merge_timeout = $pun_config['o_merge_timeout'];

+ 1 - 4
plugins/AP_PMS_New.php

@@ -50,10 +50,7 @@ if ($request->isPost('show_text'))
 				$db->query('UPDATE '.$db->prefix.'groups SET g_pm='.$g_p.', g_pm_limit='.$g_lim.' WHERE g_id='.$cur_group['g_id']) or error('Unable to update user group list', __FILE__, __LINE__, $db->error());
 			}
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_apmsn['Plugin redirect']);
 }

+ 1 - 4
plugins/AP_Poll.php

@@ -47,10 +47,7 @@ if ($request->isPost('show_text'))
 		$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.intval($poll_guest).'\' WHERE conf_name=\'o_poll_guest\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 	}
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_admin_plugin_poll['Plugin redirect']);
 }

+ 1 - 4
plugins/AP_Security.php

@@ -38,10 +38,7 @@ if ($request->isPost('show_text'))
 	$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$b_crypto.'\' WHERE conf_name=\'o_crypto_enable\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 	$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$b_enable_acaptcha.'\' WHERE conf_name=\'o_enable_acaptcha\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_admin_plugin_security['Plugin redirect']);
 }

+ 6 - 27
plugins/AP_Smilies.php

@@ -9,8 +9,8 @@
 
 // Limits configuration / Configuration des limites
 $smilies_config_image_size = 10240;	// max upload image size in bytes
-$smilies_config_image_width = 20;			// max upload image width in pixels
-$smilies_config_image_height = 20;		// max upload image height in pixels
+$smilies_config_image_width = 40;			// max upload image width in pixels
+$smilies_config_image_height = 40;		// max upload image height in pixels
 
 // Make sure no one attempts to run this script "directly"
 if (!defined('PUN'))
@@ -28,16 +28,7 @@ else
 	require PUN_ROOT.'lang/English/admin_plugin_smilies.php';
 
 // Retrieve the smiley set
-if (file_exists($container->getParameter('DIR_CACHE') . 'cache_smilies.php'))
-	include $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-else
-{
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_smiley_cache();
-	require $container->getParameter('DIR_CACHE') . 'cache_smilies.php';
-}
+$smilies = $container->get('smilies');
 
 // Retrieve the smiley images
 $img_smilies = array();
@@ -78,11 +69,7 @@ if ($request->isPost('reord'))
 	while ($db_smilies = $db->fetch_assoc($result))
 		$db->query('UPDATE '.$db->prefix.'smilies SET disp_position='.$smilies_order[$db_smilies['id']].', text=\''.$db->escape($smilies_code[$db_smilies['id']]).'\', image=\''.$db->escape($smilies_img[$db_smilies['id']]).'\' WHERE id='.$db_smilies['id']) or error('Unable to edit smilies', __FILE__, __LINE__, $db->error());
 
-	// Regenerate cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_smiley_cache();
+    $container->get('smilies update');
 
 	redirect(PLUGIN_URL, $lang_smiley['Smilies edited']);
 }
@@ -98,11 +85,7 @@ elseif ($request->isPost('remove'))
 	// Delete smilies
 	$db->query('DELETE FROM '.$db->prefix.'smilies WHERE id IN ('.implode(', ', $rem_smilies).')') or error('Unable to delete smiley', __FILE__, __LINE__, $db->error());
 
-	// Regenerate cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_smiley_cache();
+    $container->get('smilies update');
 
 	redirect(PLUGIN_URL, $lang_smiley['Delete Smiley Redirect']);
 }
@@ -124,11 +107,7 @@ elseif ($request->isPost('add_smiley'))
 	// Add the smiley
 	$db->query('INSERT INTO '.$db->prefix.'smilies (image, text) VALUES (\''.$db->escape($smiley_image).'\', \''.$db->escape($smiley_code).'\')') or error('Unable to add smiley', __FILE__, __LINE__, $db->error());
 
-	// Regenerate cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_smiley_cache();
+    $container->get('smilies update');
 
 	redirect(PLUGIN_URL, $lang_smiley['Successful Creation']);
 }

+ 3 - 12
plugins/AP_Upload.php

@@ -44,10 +44,7 @@ if ($request->isPost('installation'))
 	$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name LIKE \'o\_uploadile\_%\'') or error('Unable to remove config entries', __FILE__, __LINE__, $db->error());;
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_uploadile_other\', \''.$db->escape(serialize($sconf)).'\')') or error($lang_up['Error DB ins-up'], __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_up['Redirect']);
 }
@@ -116,10 +113,7 @@ else if ($request->isPost('update'))
 	$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name LIKE \'o\_uploadile\_%\'') or error('Unable to remove config entries', __FILE__, __LINE__, $db->error());;
 	$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_uploadile_other\', \''.$db->escape(serialize($sconf)).'\')') or error($lang_up['Error DB ins-up'], __FILE__, __LINE__, $db->error());
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
-
-	generate_config_cache();
+    $container->get('config update');
 
 	redirect(PLUGIN_URL, $lang_up['Redirect']);
 }
@@ -134,11 +128,8 @@ else if ($request->isPost('restore'))
 
 	$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name LIKE \'o\_uploadile\_%\'') or error('Unable to remove config entries', __FILE__, __LINE__, $db->error());;
 
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
+    $container->get('config update');
 
-	generate_config_cache();
-	
 	redirect(PLUGIN_URL, $lang_up['Redirect']);
 }
 

+ 12 - 21
profile.php

@@ -489,14 +489,11 @@ else if ($request->isPost('update_group_membership'))
 
 	$db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
 
-	// Regenerate the users info cache
-	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-		require PUN_ROOT.'include/cache.php';
+    $container->get('users_info update');
 
-	generate_users_info_cache();
-
-	if ($old_group_id == PUN_ADMIN || $new_group_id == PUN_ADMIN)
-		generate_admins_cache();
+	if ($old_group_id == PUN_ADMIN || $new_group_id == PUN_ADMIN) {
+        $container->get('admins update');
+    }
 
 	$result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$new_group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
 	$new_group_mod = $db->result($result);
@@ -694,14 +691,11 @@ else if ($request->isPost('delete_user') || $request->isPost('delete_user_comply
 		// Delete user avatar
 		delete_avatar($id);
 
-		// Regenerate the users info cache
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_users_info_cache();
+        $container->get('users_info update');
 
-		if ($group_id == PUN_ADMIN)
-			generate_admins_cache();
+		if ($group_id == PUN_ADMIN) {
+            $container->get('admins update');
+        }
 
 		redirect('index.php', $lang_profile['User delete redirect']);
 	}
@@ -1059,15 +1053,12 @@ else if ($request->isPost('form_sent'))
 			}
 		}
 
-		// Regenerate the users info cache
-		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-			require PUN_ROOT.'include/cache.php';
-
-		generate_users_info_cache();
+        $container->get('users_info update');
 
 		// Check if the bans table was updated and regenerate the bans cache when needed
-		if (isset($bans_updated))
-			generate_bans_cache();
+		if (isset($bans_updated)) {
+            $container->get('bans update');
+        }
 	}
 
 	redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);

+ 1 - 5
register.php

@@ -168,11 +168,7 @@ if ($request->isPost('form_sent'))
 
 		if ($pun_config['o_regs_verify'] == '0')
 		{
-			// Regenerate the users info cache
-			if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
-				require PUN_ROOT.'include/cache.php';
-
-			generate_users_info_cache();
+            $container->get('users_info update');
 		}
 
 		// If the mailing list isn't empty, we may need to send out some alerts

+ 1 - 1
search.php

@@ -75,7 +75,7 @@ if (! empty($action) || $request->isGet('search_id'))
 
 		$show_as = $request->getStr('show_as') === 'topics' ? 'topics' : 'posts';
 		$sort_by = $request->getInt('sort_by', 0);
-		$search_in = min(max($request->getInt('search_in', 0), 1), -1);
+		$search_in = max(min($request->getInt('search_in', 0), 1), -1);
 	}
 	// If it's a user search (by ID)
 	else if ($action === 'show_user_posts' || $action === 'show_user_topics' || $action === 'show_subscriptions')

+ 1 - 1
viewtopic.php

@@ -190,7 +190,7 @@ if (defined('WITT_ENABLE'))
 $mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
 if ($is_admmod)
-	$admin_ids = get_admin_ids();
+	$admin_ids = $container->get('admins');
 
 if ($pun_user['is_bot']) // запретим ботам постить - Visman
 	$pun_config['o_quickpost'] = $cur_topic['post_replies'] = $pun_user['g_post_replies'] = $pun_config['o_topic_views'] = '';