コンポーネント / ライブラリのキャッシュをgit管理に追加
Showing
32 changed files
with
1916 additions
and
2 deletions
1 | <?php | ||
2 | /** | ||
3 | * @package Joomla.Administrator | ||
4 | * @subpackage com_cache | ||
5 | * | ||
6 | * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
7 | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
8 | */ | ||
9 | |||
10 | defined('_JEXEC') or die; | ||
11 | |||
12 | JHtml::_('formbehavior.chosen', 'select'); | ||
13 | JHtml::_('bootstrap.tooltip'); | ||
14 | |||
15 | $listOrder = $this->escape($this->state->get('list.ordering')); | ||
16 | $listDirn = $this->escape($this->state->get('list.direction')); | ||
17 | ?> | ||
18 | <form action="<?php echo JRoute::_('index.php?option=com_cache'); ?>" method="post" name="adminForm" id="adminForm"> | ||
19 | <?php if (!empty($this->sidebar)) : ?> | ||
20 | <div id="j-sidebar-container" class="span2"> | ||
21 | <?php echo $this->sidebar; ?> | ||
22 | </div> | ||
23 | <div id="j-main-container" class="span10"> | ||
24 | <?php else : ?> | ||
25 | <div id="j-main-container"> | ||
26 | <?php endif; ?> | ||
27 | <?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> | ||
28 | <?php if ($this->total > 0) : ?> | ||
29 | <table class="table table-striped"> | ||
30 | <thead> | ||
31 | <tr> | ||
32 | <th width="1%" class="nowrap center"> | ||
33 | <?php echo JHtml::_('grid.checkall'); ?> | ||
34 | </th> | ||
35 | <th class="title nowrap"> | ||
36 | <?php echo JHtml::_('searchtools.sort', 'COM_CACHE_GROUP', 'group', $listDirn, $listOrder); ?> | ||
37 | </th> | ||
38 | <th width="5%" class="nowrap"> | ||
39 | <?php echo JHtml::_('searchtools.sort', 'COM_CACHE_NUMBER_OF_FILES', 'count', $listDirn, $listOrder); ?> | ||
40 | </th> | ||
41 | <th width="10%" class="nowrap"> | ||
42 | <?php echo JHtml::_('searchtools.sort', 'COM_CACHE_SIZE', 'size', $listDirn, $listOrder); ?> | ||
43 | </th> | ||
44 | </tr> | ||
45 | </thead> | ||
46 | <tfoot> | ||
47 | <tr> | ||
48 | <td colspan="4"> | ||
49 | <?php echo $this->pagination->getListFooter(); ?> | ||
50 | </td> | ||
51 | </tr> | ||
52 | </tfoot> | ||
53 | <tbody> | ||
54 | <?php | ||
55 | $i = 0; | ||
56 | foreach ($this->data as $folder => $item) : ?> | ||
57 | <tr class="row<?php echo $i % 2; ?>"> | ||
58 | <td> | ||
59 | <input type="checkbox" id="cb<?php echo $i; ?>" name="cid[]" value="<?php echo $this->escape($item->group); ?>" onclick="Joomla.isChecked(this.checked);" /> | ||
60 | </td> | ||
61 | <td> | ||
62 | <label for="cb<?php echo $i; ?>"> | ||
63 | <strong><?php echo $this->escape($item->group); ?></strong> | ||
64 | </label> | ||
65 | </td> | ||
66 | <td> | ||
67 | <?php echo $item->count; ?> | ||
68 | </td> | ||
69 | <td> | ||
70 | <?php echo JHtml::_('number.bytes', $item->size); ?> | ||
71 | </td> | ||
72 | </tr> | ||
73 | <?php $i++; endforeach; ?> | ||
74 | </tbody> | ||
75 | </table> | ||
76 | <?php endif; ?> | ||
77 | <input type="hidden" name="task" value="" /> | ||
78 | <input type="hidden" name="boxchecked" value="0" /> | ||
79 | <?php echo JHtml::_('form.token'); ?> | ||
80 | </div> | ||
81 | </form> |
1 | <?php | ||
2 | /** | ||
3 | * @package Joomla.Administrator | ||
4 | * @subpackage com_cache | ||
5 | * | ||
6 | * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
7 | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
8 | */ | ||
9 | |||
10 | defined('_JEXEC') or die; | ||
11 | |||
12 | /** | ||
13 | * HTML View class for the Cache component | ||
14 | * | ||
15 | * @since 1.6 | ||
16 | */ | ||
17 | class CacheViewCache extends JViewLegacy | ||
18 | { | ||
19 | /** | ||
20 | * @var object client object. | ||
21 | * @deprecated 4.0 | ||
22 | */ | ||
23 | protected $client; | ||
24 | |||
25 | protected $data; | ||
26 | |||
27 | protected $pagination; | ||
28 | |||
29 | protected $state; | ||
30 | |||
31 | /** | ||
32 | * Display a view. | ||
33 | * | ||
34 | * @param string $tpl The name of the template file to parse; automatically searches through the template paths. | ||
35 | * | ||
36 | * @return mixed A string if successful, otherwise an Error object. | ||
37 | */ | ||
38 | public function display($tpl = null) | ||
39 | { | ||
40 | $this->data = $this->get('Data'); | ||
41 | $this->pagination = $this->get('Pagination'); | ||
42 | $this->total = $this->get('Total'); | ||
43 | $this->state = $this->get('State'); | ||
44 | $this->filterForm = $this->get('FilterForm'); | ||
45 | $this->activeFilters = $this->get('ActiveFilters'); | ||
46 | |||
47 | // Check for errors. | ||
48 | if (count($errors = $this->get('Errors'))) | ||
49 | { | ||
50 | throw new Exception(implode("\n", $errors), 500); | ||
51 | } | ||
52 | |||
53 | $this->addToolbar(); | ||
54 | $this->sidebar = JHtmlSidebar::render(); | ||
55 | parent::display($tpl); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Add the page title and toolbar. | ||
60 | * | ||
61 | * @return void | ||
62 | * | ||
63 | * @since 1.6 | ||
64 | */ | ||
65 | protected function addToolbar() | ||
66 | { | ||
67 | $state = $this->get('State'); | ||
68 | |||
69 | if ($state->get('client_id') == 1) | ||
70 | { | ||
71 | JToolbarHelper::title(JText::_('COM_CACHE_CLEAR_CACHE_ADMIN_TITLE'), 'lightning clear'); | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | JToolbarHelper::title(JText::_('COM_CACHE_CLEAR_CACHE_SITE_TITLE'), 'lightning clear'); | ||
76 | } | ||
77 | |||
78 | JToolbarHelper::custom('delete', 'delete.png', 'delete_f2.png', 'JTOOLBAR_DELETE', true); | ||
79 | JToolbarHelper::custom('deleteAll', 'remove.png', 'delete_f2.png', 'JTOOLBAR_DELETE_ALL', false); | ||
80 | JToolbarHelper::divider(); | ||
81 | |||
82 | if (JFactory::getUser()->authorise('core.admin', 'com_cache')) | ||
83 | { | ||
84 | JToolbarHelper::preferences('com_cache'); | ||
85 | } | ||
86 | |||
87 | JToolbarHelper::divider(); | ||
88 | JToolbarHelper::help('JHELP_SITE_MAINTENANCE_CLEAR_CACHE'); | ||
89 | |||
90 | JHtmlSidebar::setAction('index.php?option=com_cache'); | ||
91 | } | ||
92 | } |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
5 | <title>Insert title here</title> | ||
6 | </head> | ||
7 | <body> | ||
8 | |||
9 | </body> | ||
10 | </html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
5 | <title>Insert title here</title> | ||
6 | </head> | ||
7 | <body> | ||
8 | |||
9 | </body> | ||
10 | </html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
5 | <title>Insert title here</title> | ||
6 | </head> | ||
7 | <body> | ||
8 | |||
9 | </body> | ||
10 | </html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
5 | <title>Insert title here</title> | ||
6 | </head> | ||
7 | <body> | ||
8 | |||
9 | </body> | ||
10 | </html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | /** | ||
3 | * @package Joomla.Administrator | ||
4 | * @subpackage Template.hathor | ||
5 | * | ||
6 | * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
7 | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
8 | */ | ||
9 | |||
10 | defined('_JEXEC') or die; | ||
11 | |||
12 | $listOrder = $this->escape($this->state->get('list.ordering')); | ||
13 | $listDirn = $this->escape($this->state->get('list.direction')); | ||
14 | ?> | ||
15 | |||
16 | <form action="<?php echo JRoute::_('index.php?option=com_cache'); ?>" method="post" name="adminForm" id="adminForm"> | ||
17 | <?php if (!empty( $this->sidebar)) : ?> | ||
18 | <div id="j-sidebar-container" class="span2"> | ||
19 | <?php echo $this->sidebar; ?> | ||
20 | </div> | ||
21 | <div id="j-main-container" class="span10"> | ||
22 | <?php else : ?> | ||
23 | <div id="j-main-container"> | ||
24 | <?php endif;?> | ||
25 | <fieldset id="filter-bar"> | ||
26 | <legend class="element-invisible"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></legend> | ||
27 | <div class="filter-select fltrt"> | ||
28 | <label class="selectlabel" for="client_id"> | ||
29 | <?php echo JText::_('COM_CACHE_SELECT_CLIENT'); ?> | ||
30 | </label> | ||
31 | <select name="client_id" id="client_id"> | ||
32 | <?php echo JHtml::_('select.options', CacheHelper::getClientOptions(), 'value', 'text', $this->state->get('client_id'));?> | ||
33 | </select> | ||
34 | |||
35 | <button type="submit" id="filter-go"> | ||
36 | <?php echo JText::_('JSUBMIT'); ?></button> | ||
37 | </div> | ||
38 | </fieldset> | ||
39 | <div class="clr"> </div> | ||
40 | <table class="adminlist"> | ||
41 | <thead> | ||
42 | <tr> | ||
43 | <th class="checkmark-col"> | ||
44 | <input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" /> | ||
45 | </th> | ||
46 | <th class="title nowrap"> | ||
47 | <?php echo JHtml::_('grid.sort', 'COM_CACHE_GROUP', 'group', $listDirn, $listOrder); ?> | ||
48 | </th> | ||
49 | <th class="width-5 center nowrap"> | ||
50 | <?php echo JHtml::_('grid.sort', 'COM_CACHE_NUMBER_OF_FILES', 'count', $listDirn, $listOrder); ?> | ||
51 | </th> | ||
52 | <th class="width-10 center"> | ||
53 | <?php echo JHtml::_('grid.sort', 'COM_CACHE_SIZE', 'size', $listDirn, $listOrder); ?> | ||
54 | </th> | ||
55 | </tr> | ||
56 | </thead> | ||
57 | |||
58 | <tbody> | ||
59 | <?php | ||
60 | $i = 0; | ||
61 | foreach ($this->data as $folder => $item) : ?> | ||
62 | <tr class="row<?php echo $i % 2; ?>"> | ||
63 | <td> | ||
64 | <input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $item->group; ?>" onclick="Joomla.isChecked(this.checked);" /> | ||
65 | </td> | ||
66 | <td> | ||
67 | <span class="bold"> | ||
68 | <?php echo $item->group; ?> | ||
69 | </span> | ||
70 | </td> | ||
71 | <td class="center"> | ||
72 | <?php echo $item->count; ?> | ||
73 | </td> | ||
74 | <td class="center"> | ||
75 | <?php echo JHtml::_('number.bytes', $item->size*1024); ?> | ||
76 | </td> | ||
77 | </tr> | ||
78 | <?php $i++; endforeach; ?> | ||
79 | </tbody> | ||
80 | </table> | ||
81 | |||
82 | <?php echo $this->pagination->getListFooter(); ?> | ||
83 | |||
84 | <input type="hidden" name="task" value="" /> | ||
85 | <input type="hidden" name="boxchecked" value="0" /> | ||
86 | <input type="hidden" name="client" value="<?php echo $this->client->id;?>" /> | ||
87 | <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" /> | ||
88 | <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" /> | ||
89 | <?php echo JHtml::_('form.token'); ?> | ||
90 | </div> | ||
91 | </form> |
libraries/fof/utils/cache/cleaner.php
0 → 100644
1 | <?php | ||
2 | /** | ||
3 | * @package FrameworkOnFramework | ||
4 | * @subpackage utils | ||
5 | * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved. | ||
6 | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
7 | */ | ||
8 | |||
9 | defined('FOF_INCLUDED') or die; | ||
10 | |||
11 | /** | ||
12 | * A utility class to help you quickly clean the Joomla! cache | ||
13 | */ | ||
14 | class FOFUtilsCacheCleaner | ||
15 | { | ||
16 | /** | ||
17 | * Clears the com_modules and com_plugins cache. You need to call this whenever you alter the publish state or | ||
18 | * parameters of a module or plugin from your code. | ||
19 | * | ||
20 | * @return void | ||
21 | */ | ||
22 | public static function clearPluginsAndModulesCache() | ||
23 | { | ||
24 | self::clearPluginsCache(); | ||
25 | self::clearModulesCache(); | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Clears the com_plugins cache. You need to call this whenever you alter the publish state or parameters of a | ||
30 | * plugin from your code. | ||
31 | * | ||
32 | * @return void | ||
33 | */ | ||
34 | public static function clearPluginsCache() | ||
35 | { | ||
36 | self::clearCacheGroups(array('com_plugins'), array(0,1)); | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Clears the com_modules cache. You need to call this whenever you alter the publish state or parameters of a | ||
41 | * module from your code. | ||
42 | * | ||
43 | * @return void | ||
44 | */ | ||
45 | public static function clearModulesCache() | ||
46 | { | ||
47 | self::clearCacheGroups(array('com_modules'), array(0,1)); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * Clears the specified cache groups. | ||
52 | * | ||
53 | * @param array $clearGroups Which cache groups to clear. Usually this is com_yourcomponent to clear your | ||
54 | * component's cache. | ||
55 | * @param array $cacheClients Which cache clients to clear. 0 is the back-end, 1 is the front-end. If you do not | ||
56 | * specify anything, both cache clients will be cleared. | ||
57 | * | ||
58 | * @return void | ||
59 | */ | ||
60 | public static function clearCacheGroups(array $clearGroups, array $cacheClients = array(0, 1)) | ||
61 | { | ||
62 | $conf = JFactory::getConfig(); | ||
63 | |||
64 | foreach ($clearGroups as $group) | ||
65 | { | ||
66 | foreach ($cacheClients as $client_id) | ||
67 | { | ||
68 | try | ||
69 | { | ||
70 | $options = array( | ||
71 | 'defaultgroup' => $group, | ||
72 | 'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache') | ||
73 | ); | ||
74 | |||
75 | $cache = JCache::getInstance('callback', $options); | ||
76 | $cache->clean(); | ||
77 | } | ||
78 | catch (Exception $e) | ||
79 | { | ||
80 | // suck it up | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::importAll('libraries.cache.storage'); | ||
3 | |||
4 | class N2Cache { | ||
5 | |||
6 | protected $group = ''; | ||
7 | protected $isAccessible = false; | ||
8 | |||
9 | /** @var N2CacheStorage */ | ||
10 | public $storage; | ||
11 | |||
12 | protected $_storageEngine = 'default'; | ||
13 | |||
14 | /** | ||
15 | * @param string $engine | ||
16 | * | ||
17 | * @return N2CacheStorage | ||
18 | */ | ||
19 | public static function getStorage($engine = "default") { | ||
20 | static $storage = null; | ||
21 | if ($storage === null) { | ||
22 | $storage = array( | ||
23 | 'filesystem' => new N2CacheStorageFilesystem(), | ||
24 | 'database' => new N2CacheStorageDatabase() | ||
25 | ); | ||
26 | } | ||
27 | if ($engine == 'default') { | ||
28 | if (defined('NEXTEND_CACHE_STORAGE')) { | ||
29 | return $storage[NEXTEND_CACHE_STORAGE]; | ||
30 | } | ||
31 | |||
32 | return $storage['filesystem']; | ||
33 | } | ||
34 | |||
35 | return $storage[$engine]; | ||
36 | } | ||
37 | |||
38 | public static function clearGroup($group) { | ||
39 | $storage = self::getStorage(); | ||
40 | $storage->clear($group); | ||
41 | $storage->clear($group, 'web'); | ||
42 | } | ||
43 | |||
44 | public function __construct($group, $isAccessible = false) { | ||
45 | $this->group = $group; | ||
46 | $this->isAccessible = $isAccessible; | ||
47 | $this->storage = self::getStorage($this->_storageEngine); | ||
48 | } | ||
49 | |||
50 | protected function clearCurrentGroup() { | ||
51 | $this->storage->clear($this->group, $this->getScope()); | ||
52 | } | ||
53 | |||
54 | protected function getScope() { | ||
55 | if ($this->isAccessible) { | ||
56 | return 'web'; | ||
57 | } | ||
58 | |||
59 | return 'notweb'; | ||
60 | } | ||
61 | |||
62 | protected function exists($key) { | ||
63 | return $this->storage->exists($this->group, $key, $this->getScope()); | ||
64 | } | ||
65 | |||
66 | protected function get($key) { | ||
67 | return $this->storage->get($this->group, $key, $this->getScope()); | ||
68 | } | ||
69 | |||
70 | protected function set($key, $value) { | ||
71 | $this->storage->set($this->group, $key, $value, $this->getScope()); | ||
72 | } | ||
73 | |||
74 | protected function getPath($key) { | ||
75 | return $this->storage->getPath($this->group, $key, $this->getScope()); | ||
76 | } | ||
77 | |||
78 | protected function remove($key) { | ||
79 | return $this->storage->remove($this->group, $key, $this->getScope()); | ||
80 | } | ||
81 | } |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheCombine extends N2Cache { | ||
5 | |||
6 | protected $files = array(); | ||
7 | protected $inline = ''; | ||
8 | protected $fileType = ''; | ||
9 | protected $minify = false; | ||
10 | protected $options = array(); | ||
11 | |||
12 | public function __construct($fileType, $minify = false, $options = array()) { | ||
13 | $this->fileType = $fileType; | ||
14 | $this->minify = $minify; | ||
15 | $this->options = $options; | ||
16 | $this->options['minify'] = $this->minify; | ||
17 | parent::__construct('combined', true); | ||
18 | } | ||
19 | |||
20 | public function add($file) { | ||
21 | if (!in_array($file, $this->files)) { | ||
22 | $this->files[] = $file; | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function addInline($text) { | ||
27 | $this->inline .= $text; | ||
28 | } | ||
29 | |||
30 | protected function getHash() { | ||
31 | $hash = ''; | ||
32 | for ($i = 0; $i < count($this->files); $i++) { | ||
33 | $hash .= $this->files[$i] . filemtime($this->files[$i]); | ||
34 | } | ||
35 | if (!empty($this->inline)) { | ||
36 | $hash .= $this->inline; | ||
37 | } | ||
38 | |||
39 | return md5($hash . json_encode($this->options)); | ||
40 | } | ||
41 | |||
42 | public function make() { | ||
43 | $hash = $this->getHash(); | ||
44 | $fileName = $hash . '.' . $this->fileType; | ||
45 | if (!$this->exists($fileName)) { | ||
46 | $buffer = ''; | ||
47 | for ($i = 0; $i < count($this->files); $i++) { | ||
48 | $buffer .= file_get_contents($this->files[$i]); | ||
49 | } | ||
50 | if ($this->minify !== false) { | ||
51 | $buffer = call_user_func($this->minify, $buffer); | ||
52 | } | ||
53 | $buffer .= $this->inline; | ||
54 | |||
55 | $this->set($fileName, $buffer); | ||
56 | } | ||
57 | |||
58 | return $this->getPath($fileName); | ||
59 | } | ||
60 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheImage extends N2Cache { | ||
5 | |||
6 | protected $_storageEngine = 'filesystem'; | ||
7 | |||
8 | protected function getScope() { | ||
9 | return 'image'; | ||
10 | } | ||
11 | |||
12 | public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) { | ||
13 | |||
14 | if (!$hash) { | ||
15 | $hash = $this->generateHash($fileExtension, $callable, $parameters); | ||
16 | } | ||
17 | $keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME); | ||
18 | $fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '') . '.' . $fileExtension; | ||
19 | |||
20 | if (!$this->exists($fileName)) { | ||
21 | $this->set($fileName, call_user_func_array($callable, $parameters)); | ||
22 | } | ||
23 | |||
24 | return $this->getPath($fileName); | ||
25 | } | ||
26 | |||
27 | private function generateHash($fileExtension, $callable, $parameters) { | ||
28 | return md5(json_encode(array( | ||
29 | $fileExtension, | ||
30 | $callable, | ||
31 | $parameters | ||
32 | ))); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | class N2StoreImage extends N2Cache { | ||
37 | |||
38 | protected $_storageEngine = 'filesystem'; | ||
39 | |||
40 | protected function getScope() { | ||
41 | return 'image'; | ||
42 | } | ||
43 | |||
44 | public function makeCache($fileName, $content) { | ||
45 | if (!$this->isImage($fileName)) { | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | if (!$this->exists($fileName)) { | ||
50 | $this->set($fileName, $content); | ||
51 | } | ||
52 | |||
53 | return $this->getPath($fileName); | ||
54 | } | ||
55 | |||
56 | private function isImage($fileName) { | ||
57 | $supported_image = array( | ||
58 | 'gif', | ||
59 | 'jpg', | ||
60 | 'jpeg', | ||
61 | 'png', | ||
62 | 'mp4', | ||
63 | 'mp3' | ||
64 | ); | ||
65 | |||
66 | $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); | ||
67 | if (in_array($ext, $supported_image)) { | ||
68 | return true; | ||
69 | } | ||
70 | |||
71 | return false; | ||
72 | } | ||
73 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheManifest extends N2Cache { | ||
5 | |||
6 | private $isRaw = false; | ||
7 | |||
8 | private $manifestData; | ||
9 | |||
10 | public function __construct($group, $isAccessible = false, $isRaw = false) { | ||
11 | parent::__construct($group, $isAccessible); | ||
12 | $this->isRaw = $isRaw; | ||
13 | } | ||
14 | |||
15 | public function makeCache($fileName, $hash, $callable) { | ||
16 | if (!$this->isCached($fileName, $hash)) { | ||
17 | |||
18 | $return = call_user_func($callable, $this); | ||
19 | if ($return === false) { | ||
20 | return false; | ||
21 | } | ||
22 | |||
23 | return $this->createCacheFile($fileName, $hash, $return); | ||
24 | } | ||
25 | if ($this->isAccessible) { | ||
26 | return $this->getPath($fileName); | ||
27 | } | ||
28 | |||
29 | return json_decode($this->get($fileName), true); | ||
30 | } | ||
31 | |||
32 | private function isCached($fileName, $hash) { | ||
33 | |||
34 | |||
35 | $manifestKey = $this->getManifestKey($fileName); | ||
36 | if ($this->exists($manifestKey)) { | ||
37 | |||
38 | $this->manifestData = json_decode($this->get($manifestKey), true); | ||
39 | |||
40 | if (!$this->isCacheValid($this->manifestData) || $this->manifestData['hash'] != $hash) { | ||
41 | $this->clean($fileName); | ||
42 | |||
43 | return false; | ||
44 | } | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | return false; | ||
50 | } | ||
51 | |||
52 | protected function createCacheFile($fileName, $hash, $content) { | ||
53 | |||
54 | $this->manifestData = array(); | ||
55 | |||
56 | $this->manifestData['hash'] = $hash; | ||
57 | $this->addManifestData($this->manifestData); | ||
58 | |||
59 | $this->set($this->getManifestKey($fileName), json_encode($this->manifestData)); | ||
60 | |||
61 | $this->set($fileName, $this->isRaw ? $content : json_encode($content)); | ||
62 | |||
63 | if ($this->isAccessible) { | ||
64 | return $this->getPath($fileName); | ||
65 | } | ||
66 | |||
67 | return $content; | ||
68 | } | ||
69 | |||
70 | protected function isCacheValid(&$manifestData) { | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | protected function addManifestData(&$manifestData) { | ||
75 | |||
76 | } | ||
77 | |||
78 | public function clean($fileName) { | ||
79 | |||
80 | $this->remove($this->getManifestKey($fileName)); | ||
81 | $this->remove($fileName); | ||
82 | } | ||
83 | |||
84 | protected function getManifestKey($fileName) { | ||
85 | return $fileName . '.manifest'; | ||
86 | } | ||
87 | |||
88 | public function getData($key, $default = 0) { | ||
89 | return isset($this->manifestData[$key]) ? $this->manifestData[$key] : $default; | ||
90 | } | ||
91 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed.
Click to expand it.
1 | <?php | ||
2 | |||
3 | abstract class N2CacheStorage { | ||
4 | |||
5 | protected $paths = array(); | ||
6 | |||
7 | public function __construct() { | ||
8 | $this->paths['web'] = 'web'; | ||
9 | $this->paths['notweb'] = 'notweb'; | ||
10 | $this->paths['image'] = 'image'; | ||
11 | } | ||
12 | |||
13 | public function isFilesystem() { | ||
14 | return false; | ||
15 | } | ||
16 | |||
17 | public abstract function clear($group, $scope = 'notweb'); | ||
18 | |||
19 | public abstract function exists($group, $key, $scope = 'notweb'); | ||
20 | |||
21 | public abstract function set($group, $key, $value, $scope = 'notweb'); | ||
22 | |||
23 | public abstract function get($group, $key, $scope = 'notweb'); | ||
24 | |||
25 | public abstract function remove($group, $key, $scope = 'notweb'); | ||
26 | |||
27 | public abstract function getPath($group, $key, $scope = 'notweb'); | ||
28 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.storage.cachestorage'); | ||
3 | |||
4 | class N2CacheStorageDatabase extends N2CacheStorage { | ||
5 | |||
6 | protected $db; | ||
7 | |||
8 | public function __construct() { | ||
9 | |||
10 | parent::__construct(); | ||
11 | |||
12 | $this->db = new N2StorageSection('cache'); | ||
13 | } | ||
14 | |||
15 | public function clear($group, $scope = 'notweb') { | ||
16 | |||
17 | $this->db->delete($scope . '/' . $group); | ||
18 | } | ||
19 | |||
20 | public function exists($group, $key, $scope = 'notweb') { | ||
21 | |||
22 | if ($this->db->get($scope . '/' . $group, $key)) { | ||
23 | return true; | ||
24 | } | ||
25 | |||
26 | return false; | ||
27 | } | ||
28 | |||
29 | public function set($group, $key, $value, $scope = 'notweb') { | ||
30 | |||
31 | $this->db->set($scope . '/' . $group, $key, $value); | ||
32 | } | ||
33 | |||
34 | public function get($group, $key, $scope = 'notweb') { | ||
35 | return $this->db->get($scope . '/' . $group, $key); | ||
36 | } | ||
37 | |||
38 | public function remove($group, $key, $scope = 'notweb') { | ||
39 | $this->db->delete($scope . '/' . $group, $key); | ||
40 | } | ||
41 | |||
42 | public function getPath($group, $key, $scope = 'notweb') { | ||
43 | |||
44 | return N2Platform::getSiteUrl() . '?nextendcache=1&g=' . urlencode($group) . '&k=' . urlencode($key); | ||
45 | } | ||
46 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.storage.cachestorage'); | ||
3 | |||
4 | class N2CacheStorageFilesystem extends N2CacheStorage { | ||
5 | |||
6 | public function __construct() { | ||
7 | $this->paths['web'] = N2Filesystem::getWebCachePath(); | ||
8 | $this->paths['notweb'] = N2Filesystem::getNotWebCachePath(); | ||
9 | $this->paths['image'] = N2Filesystem::getImagesFolder(); | ||
10 | } | ||
11 | |||
12 | public function isFilesystem() { | ||
13 | return true; | ||
14 | } | ||
15 | |||
16 | public function clear($group, $scope = 'notweb') { | ||
17 | |||
18 | if (N2Filesystem::existsFolder($this->paths[$scope] . NDS . $group)) { | ||
19 | N2Filesystem::deleteFolder($this->paths[$scope] . NDS . $group); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | public function exists($group, $key, $scope = 'notweb') { | ||
24 | if (N2Filesystem::existsFile($this->paths[$scope] . NDS . $group . NDS . $key)) { | ||
25 | return true; | ||
26 | } | ||
27 | |||
28 | return false; | ||
29 | } | ||
30 | |||
31 | public function set($group, $key, $value, $scope = 'notweb') { | ||
32 | $path = $this->paths[$scope] . NDS . $group . NDS . $key; | ||
33 | $dir = dirname($path); | ||
34 | if (!N2Filesystem::existsFolder($dir)) { | ||
35 | N2Filesystem::createFolder($dir); | ||
36 | } | ||
37 | N2Filesystem::createFile($path, $value); | ||
38 | } | ||
39 | |||
40 | public function get($group, $key, $scope = 'notweb') { | ||
41 | return N2Filesystem::readFile($this->paths[$scope] . NDS . $group . NDS . $key); | ||
42 | } | ||
43 | |||
44 | public function remove($group, $key, $scope = 'notweb') { | ||
45 | if ($this->exists($group, $key, $scope)) { | ||
46 | @unlink($this->paths[$scope] . NDS . $group . NDS . $key); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | public function getPath($group, $key, $scope = 'notweb') { | ||
51 | return $this->paths[$scope] . NDS . $group . NDS . $key; | ||
52 | } | ||
53 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | |||
3 | class N2CacheManifestGenerator extends N2CacheManifest | ||
4 | { | ||
5 | |||
6 | /** | ||
7 | * @var N2SmartSliderAbstract | ||
8 | */ | ||
9 | private $slider; | ||
10 | |||
11 | private $generator; | ||
12 | |||
13 | /** | ||
14 | * @param N2SmartSliderAbstract $slider | ||
15 | * @param N2SmartSliderSlidesGenerator $generator | ||
16 | */ | ||
17 | public function __construct($slider, $generator) { | ||
18 | parent::__construct($slider->cacheId, false); | ||
19 | $this->slider = $slider; | ||
20 | $this->generator = $generator; | ||
21 | } | ||
22 | |||
23 | protected function isCacheValid(&$manifestData) { | ||
24 | $nextRefresh = $manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60; | ||
25 | if ($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60 < N2Platform::getTime()) { | ||
26 | return false; | ||
27 | } | ||
28 | $this->generator->setNextCacheRefresh($nextRefresh); | ||
29 | return true; | ||
30 | } | ||
31 | |||
32 | protected function addManifestData(&$manifestData) { | ||
33 | $manifestData['cacheTime'] = N2Platform::getTime(); | ||
34 | $this->generator->setNextCacheRefresh($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60); | ||
35 | } | ||
36 | } |
1 | <?php | ||
2 | |||
3 | class N2CacheManifestSlider extends N2CacheManifest { | ||
4 | |||
5 | private $parameters = array(); | ||
6 | |||
7 | private $isExtended = false; | ||
8 | |||
9 | public function __construct($cacheId, $parameters = array()) { | ||
10 | parent::__construct($cacheId, false); | ||
11 | $this->parameters = $parameters; | ||
12 | |||
13 | } | ||
14 | |||
15 | public function makeCache($fileName, $hash, $callable) { | ||
16 | |||
17 | $variations = 1; | ||
18 | if ($this->exists($this->getManifestKey('variations'))) { | ||
19 | $variations = intval($this->get($this->getManifestKey('variations'))); | ||
20 | } | ||
21 | $fileName = $fileName . mt_rand(1, $variations); | ||
22 | |||
23 | if (N2SmartSliderSettings::get('serversidemobiledetect', '0') == '1') { | ||
24 | N2Loader::import('libraries.mobiledetect'); | ||
25 | |||
26 | if (N2MobileDetect::$current['isMobile']) { | ||
27 | $fileName .= '-mobile'; | ||
28 | } else if (N2MobileDetect::$current['isTablet']) { | ||
29 | $fileName .= '-tablet'; | ||
30 | } else { | ||
31 | $fileName .= '-desktop'; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if ($this->exists($this->getManifestKey('data'))) { | ||
36 | $data = json_decode($this->get($this->getManifestKey('data')), true); | ||
37 | $fileName = $this->extendFileName($fileName, $data); | ||
38 | } else { | ||
39 | $this->clearCurrentGroup(); | ||
40 | } | ||
41 | |||
42 | $output = parent::makeCache($fileName, $hash, $callable); | ||
43 | |||
44 | return $output; | ||
45 | } | ||
46 | |||
47 | protected function createCacheFile($fileName, $hash, $content) { | ||
48 | |||
49 | $this->set($this->getManifestKey('data'), json_encode($this->parameters['slider']->manifestData)); | ||
50 | |||
51 | $fileName = $this->extendFileName($fileName, $this->parameters['slider']->manifestData); | ||
52 | |||
53 | return parent::createCacheFile($fileName, $hash, $content); | ||
54 | } | ||
55 | |||
56 | private function extendFileName($fileName, $manifestData) { | ||
57 | |||
58 | if ($this->isExtended) { | ||
59 | return $fileName; | ||
60 | } | ||
61 | |||
62 | $this->isExtended = true; | ||
63 | |||
64 | $generators = $manifestData['generator']; | ||
65 | |||
66 | if (count($generators)) { | ||
67 | N2Loader::import("models.generator", "smartslider"); | ||
68 | $generatorModel = new N2SmartsliderGeneratorModel(); | ||
69 | |||
70 | foreach ($generators AS $generator) { | ||
71 | list($group, $type, $params) = $generator; | ||
72 | $info = $generatorModel->getGeneratorInfo($group, $type); | ||
73 | |||
74 | require_once($info->path . '/generator.php'); | ||
75 | $class = 'N2Generator' . $group . $type; | ||
76 | |||
77 | $fileName .= call_user_func_array(array( | ||
78 | $class, | ||
79 | 'cacheKey' | ||
80 | ), $params); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return $fileName; | ||
85 | } | ||
86 | |||
87 | protected function isCacheValid(&$manifestData) { | ||
88 | |||
89 | if (!isset($manifestData['version']) || $manifestData['version'] != N2SS3::$version) { | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | if (N2SmartSliderHelper::getInstance() | ||
94 | ->isSliderChanged($this->parameters['slider']->sliderId, 1) | ||
95 | ) { | ||
96 | $this->clearCurrentGroup(); | ||
97 | N2SmartSliderHelper::getInstance() | ||
98 | ->setSliderChanged($this->parameters['slider']->sliderId, 0); | ||
99 | |||
100 | return false; | ||
101 | } | ||
102 | |||
103 | $time = N2Platform::getTime(); | ||
104 | |||
105 | if ($manifestData['nextCacheRefresh'] < $time) { | ||
106 | return false; | ||
107 | } | ||
108 | |||
109 | if (!isset($manifestData['currentPath']) || $manifestData['currentPath'] != md5(__FILE__)) { | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | return true; | ||
114 | } | ||
115 | |||
116 | protected function addManifestData(&$manifestData) { | ||
117 | |||
118 | $manifestData['nextCacheRefresh'] = N2Pluggable::applyFilters('SSNextCacheRefresh', $this->parameters['slider']->getNextCacheRefresh(), array($this->parameters['slider'])); | ||
119 | $manifestData['currentPath'] = md5(__FILE__); | ||
120 | $manifestData['version'] = N2SS3::$version; | ||
121 | |||
122 | $variations = 1; | ||
123 | |||
124 | $params = $this->parameters['slider']->params; | ||
125 | if (!$params->get('randomize-cache', 0) && ($params->get('randomize', 0) || $params->get('randomizeFirst', 0))) { | ||
126 | $variations = intval($params->get('variations', 5)); | ||
127 | if ($variations < 1) { | ||
128 | $variations = 1; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | $this->set($this->getManifestKey('variations'), $variations); | ||
133 | } | ||
134 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
plugins/system/cache/cache.php
0 → 100644
1 | <?php | ||
2 | /** | ||
3 | * @package Joomla.Plugin | ||
4 | * @subpackage System.cache | ||
5 | * | ||
6 | * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
7 | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
8 | */ | ||
9 | |||
10 | defined('_JEXEC') or die; | ||
11 | |||
12 | /** | ||
13 | * Joomla! Page Cache Plugin. | ||
14 | * | ||
15 | * @since 1.5 | ||
16 | */ | ||
17 | class PlgSystemCache extends JPlugin | ||
18 | { | ||
19 | /** | ||
20 | * Cache instance. | ||
21 | * | ||
22 | * @var JCache | ||
23 | * @since 1.5 | ||
24 | */ | ||
25 | public $_cache; | ||
26 | |||
27 | /** | ||
28 | * Cache key | ||
29 | * | ||
30 | * @var string | ||
31 | * @since 3.0 | ||
32 | */ | ||
33 | public $_cache_key; | ||
34 | |||
35 | /** | ||
36 | * Application object. | ||
37 | * | ||
38 | * @var JApplicationCms | ||
39 | * @since 3.8.0 | ||
40 | */ | ||
41 | protected $app; | ||
42 | |||
43 | /** | ||
44 | * Constructor. | ||
45 | * | ||
46 | * @param object &$subject The object to observe. | ||
47 | * @param array $config An optional associative array of configuration settings. | ||
48 | * | ||
49 | * @since 1.5 | ||
50 | */ | ||
51 | public function __construct(& $subject, $config) | ||
52 | { | ||
53 | parent::__construct($subject, $config); | ||
54 | |||
55 | // Get the application if not done by JPlugin. | ||
56 | if (!isset($this->app)) | ||
57 | { | ||
58 | $this->app = JFactory::getApplication(); | ||
59 | } | ||
60 | |||
61 | // Set the cache options. | ||
62 | $options = array( | ||
63 | 'defaultgroup' => 'page', | ||
64 | 'browsercache' => $this->params->get('browsercache', 0), | ||
65 | 'caching' => false, | ||
66 | ); | ||
67 | |||
68 | // Instantiate cache with previous options and create the cache key identifier. | ||
69 | $this->_cache = JCache::getInstance('page', $options); | ||
70 | $this->_cache_key = JUri::getInstance()->toString(); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * Get a cache key for the current page based on the url and possible other factors. | ||
75 | * | ||
76 | * @return string | ||
77 | * | ||
78 | * @since 3.7 | ||
79 | */ | ||
80 | protected function getCacheKey() | ||
81 | { | ||
82 | static $key; | ||
83 | |||
84 | if (!$key) | ||
85 | { | ||
86 | JPluginHelper::importPlugin('pagecache'); | ||
87 | |||
88 | $parts = JEventDispatcher::getInstance()->trigger('onPageCacheGetKey'); | ||
89 | $parts[] = JUri::getInstance()->toString(); | ||
90 | |||
91 | $key = md5(serialize($parts)); | ||
92 | } | ||
93 | |||
94 | return $key; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * After Initialise Event. | ||
99 | * Checks if URL exists in cache, if so dumps it directly and closes. | ||
100 | * | ||
101 | * @return void | ||
102 | * | ||
103 | * @since 1.5 | ||
104 | */ | ||
105 | public function onAfterInitialise() | ||
106 | { | ||
107 | if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || $this->app->getMessageQueue()) | ||
108 | { | ||
109 | return; | ||
110 | } | ||
111 | |||
112 | // If any pagecache plugins return false for onPageCacheSetCaching, do not use the cache. | ||
113 | JPluginHelper::importPlugin('pagecache'); | ||
114 | |||
115 | $results = JEventDispatcher::getInstance()->trigger('onPageCacheSetCaching'); | ||
116 | $caching = !in_array(false, $results, true); | ||
117 | |||
118 | if ($caching && JFactory::getUser()->guest && $this->app->input->getMethod() === 'GET') | ||
119 | { | ||
120 | $this->_cache->setCaching(true); | ||
121 | } | ||
122 | |||
123 | $data = $this->_cache->get($this->getCacheKey()); | ||
124 | |||
125 | // If page exist in cache, show cached page. | ||
126 | if ($data !== false) | ||
127 | { | ||
128 | // Set HTML page from cache. | ||
129 | $this->app->setBody($data); | ||
130 | |||
131 | // Dumps HTML page. | ||
132 | echo $this->app->toString((bool) $this->app->get('gzip')); | ||
133 | |||
134 | // Mark afterCache in debug and run debug onAfterRespond events. | ||
135 | // e.g., show Joomla Debug Console if debug is active. | ||
136 | if (JDEBUG) | ||
137 | { | ||
138 | JProfiler::getInstance('Application')->mark('afterCache'); | ||
139 | JEventDispatcher::getInstance()->trigger('onAfterRespond'); | ||
140 | } | ||
141 | |||
142 | // Closes the application. | ||
143 | $this->app->close(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * After Render Event. | ||
149 | * Verify if current page is not excluded from cache. | ||
150 | * | ||
151 | * @return void | ||
152 | * | ||
153 | * @since 3.9.12 | ||
154 | */ | ||
155 | public function onAfterRender() | ||
156 | { | ||
157 | if ($this->_cache->getCaching() === false) | ||
158 | { | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | // We need to check if user is guest again here, because auto-login plugins have not been fired before the first aid check. | ||
163 | // Page is excluded if excluded in plugin settings. | ||
164 | if (!JFactory::getUser()->guest || $this->app->getMessageQueue() || $this->isExcluded() === true) | ||
165 | { | ||
166 | $this->_cache->setCaching(false); | ||
167 | |||
168 | return; | ||
169 | } | ||
170 | |||
171 | // Disable compression before caching the page. | ||
172 | $this->app->set('gzip', false); | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * After Respond Event. | ||
177 | * Stores page in cache. | ||
178 | * | ||
179 | * @return void | ||
180 | * | ||
181 | * @since 1.5 | ||
182 | */ | ||
183 | public function onAfterRespond() | ||
184 | { | ||
185 | if ($this->_cache->getCaching() === false) | ||
186 | { | ||
187 | return; | ||
188 | } | ||
189 | |||
190 | // Saves current page in cache. | ||
191 | $this->_cache->store($this->app->getBody(), $this->getCacheKey()); | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * Check if the page is excluded from the cache or not. | ||
196 | * | ||
197 | * @return boolean True if the page is excluded else false | ||
198 | * | ||
199 | * @since 3.5 | ||
200 | */ | ||
201 | protected function isExcluded() | ||
202 | { | ||
203 | // Check if menu items have been excluded. | ||
204 | if ($exclusions = $this->params->get('exclude_menu_items', array())) | ||
205 | { | ||
206 | // Get the current menu item. | ||
207 | $active = $this->app->getMenu()->getActive(); | ||
208 | |||
209 | if ($active && $active->id && in_array((int) $active->id, (array) $exclusions)) | ||
210 | { | ||
211 | return true; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | // Check if regular expressions are being used. | ||
216 | if ($exclusions = $this->params->get('exclude', '')) | ||
217 | { | ||
218 | // Normalize line endings. | ||
219 | $exclusions = str_replace(array("\r\n", "\r"), "\n", $exclusions); | ||
220 | |||
221 | // Split them. | ||
222 | $exclusions = explode("\n", $exclusions); | ||
223 | |||
224 | // Gets internal URI. | ||
225 | $internal_uri = '/index.php?' . JUri::getInstance()->buildQuery($this->app->getRouter()->getVars()); | ||
226 | |||
227 | // Loop through each pattern. | ||
228 | if ($exclusions) | ||
229 | { | ||
230 | foreach ($exclusions as $exclusion) | ||
231 | { | ||
232 | // Make sure the exclusion has some content | ||
233 | if ($exclusion !== '') | ||
234 | { | ||
235 | // Test both external and internal URI | ||
236 | if (preg_match('#' . $exclusion . '#i', $this->_cache_key . ' ' . $internal_uri, $match)) | ||
237 | { | ||
238 | return true; | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | |||
245 | // If any pagecache plugins return true for onPageCacheIsExcluded, exclude. | ||
246 | JPluginHelper::importPlugin('pagecache'); | ||
247 | |||
248 | $results = JEventDispatcher::getInstance()->trigger('onPageCacheIsExcluded'); | ||
249 | |||
250 | return in_array(true, $results, true); | ||
251 | } | ||
252 | } |
plugins/system/cache/cache.xml
0 → 100644
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <extension version="3.1" type="plugin" group="system" method="upgrade"> | ||
3 | <name>plg_system_cache</name> | ||
4 | <author>Joomla! Project</author> | ||
5 | <creationDate>February 2007</creationDate> | ||
6 | <copyright>Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.</copyright> | ||
7 | <license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
8 | <authorEmail>admin@joomla.org</authorEmail> | ||
9 | <authorUrl>www.joomla.org</authorUrl> | ||
10 | <version>3.0.0</version> | ||
11 | <description>PLG_CACHE_XML_DESCRIPTION</description> | ||
12 | <files> | ||
13 | <filename plugin="cache">cache.php</filename> | ||
14 | </files> | ||
15 | <languages> | ||
16 | <language tag="en-GB">en-GB.plg_system_cache.ini</language> | ||
17 | <language tag="en-GB">en-GB.plg_system_cache.sys.ini</language> | ||
18 | </languages> | ||
19 | <config> | ||
20 | <fields name="params"> | ||
21 | <fieldset name="basic"> | ||
22 | <field | ||
23 | name="browsercache" | ||
24 | type="radio" | ||
25 | label="PLG_CACHE_FIELD_BROWSERCACHE_LABEL" | ||
26 | description="PLG_CACHE_FIELD_BROWSERCACHE_DESC" | ||
27 | class="btn-group btn-group-yesno" | ||
28 | default="0" | ||
29 | filter="integer" | ||
30 | > | ||
31 | <option value="1">JYES</option> | ||
32 | <option value="0">JNO</option> | ||
33 | </field> | ||
34 | |||
35 | <field | ||
36 | name="exclude_menu_items" | ||
37 | type="menuitem" | ||
38 | label="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_LABEL" | ||
39 | description="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_DESC" | ||
40 | multiple="multiple" | ||
41 | filter="int_array" | ||
42 | /> | ||
43 | |||
44 | </fieldset> | ||
45 | <fieldset name="advanced"> | ||
46 | <field | ||
47 | name="exclude" | ||
48 | type="textarea" | ||
49 | label="PLG_CACHE_FIELD_EXCLUDE_LABEL" | ||
50 | description="PLG_CACHE_FIELD_EXCLUDE_DESC" | ||
51 | class="input-xxlarge" | ||
52 | rows="15" | ||
53 | filter="raw" | ||
54 | /> | ||
55 | |||
56 | </fieldset> | ||
57 | </fields> | ||
58 | </config> | ||
59 | </extension> |
1 | <?php | ||
2 | N2Loader::importAll('libraries.cache.storage'); | ||
3 | |||
4 | class N2Cache { | ||
5 | |||
6 | protected $group = ''; | ||
7 | protected $isAccessible = false; | ||
8 | |||
9 | /** @var N2CacheStorage */ | ||
10 | public $storage; | ||
11 | |||
12 | protected $_storageEngine = 'default'; | ||
13 | |||
14 | /** | ||
15 | * @param string $engine | ||
16 | * | ||
17 | * @return N2CacheStorage | ||
18 | */ | ||
19 | public static function getStorage($engine = "default") { | ||
20 | static $storage = null; | ||
21 | if ($storage === null) { | ||
22 | $storage = array( | ||
23 | 'filesystem' => new N2CacheStorageFilesystem(), | ||
24 | 'database' => new N2CacheStorageDatabase() | ||
25 | ); | ||
26 | } | ||
27 | if ($engine == 'default') { | ||
28 | if (defined('NEXTEND_CACHE_STORAGE')) { | ||
29 | return $storage[NEXTEND_CACHE_STORAGE]; | ||
30 | } | ||
31 | |||
32 | return $storage['filesystem']; | ||
33 | } | ||
34 | |||
35 | return $storage[$engine]; | ||
36 | } | ||
37 | |||
38 | public static function clearGroup($group) { | ||
39 | $storage = self::getStorage(); | ||
40 | $storage->clear($group); | ||
41 | $storage->clear($group, 'web'); | ||
42 | } | ||
43 | |||
44 | public function __construct($group, $isAccessible = false) { | ||
45 | $this->group = $group; | ||
46 | $this->isAccessible = $isAccessible; | ||
47 | $this->storage = self::getStorage($this->_storageEngine); | ||
48 | } | ||
49 | |||
50 | protected function clearCurrentGroup() { | ||
51 | $this->storage->clear($this->group, $this->getScope()); | ||
52 | } | ||
53 | |||
54 | protected function getScope() { | ||
55 | if ($this->isAccessible) { | ||
56 | return 'web'; | ||
57 | } | ||
58 | |||
59 | return 'notweb'; | ||
60 | } | ||
61 | |||
62 | protected function exists($key) { | ||
63 | return $this->storage->exists($this->group, $key, $this->getScope()); | ||
64 | } | ||
65 | |||
66 | protected function get($key) { | ||
67 | return $this->storage->get($this->group, $key, $this->getScope()); | ||
68 | } | ||
69 | |||
70 | protected function set($key, $value) { | ||
71 | $this->storage->set($this->group, $key, $value, $this->getScope()); | ||
72 | } | ||
73 | |||
74 | protected function getPath($key) { | ||
75 | return $this->storage->getPath($this->group, $key, $this->getScope()); | ||
76 | } | ||
77 | |||
78 | protected function remove($key) { | ||
79 | return $this->storage->remove($this->group, $key, $this->getScope()); | ||
80 | } | ||
81 | } |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheCombine extends N2Cache { | ||
5 | |||
6 | protected $files = array(); | ||
7 | protected $inline = ''; | ||
8 | protected $fileType = ''; | ||
9 | protected $minify = false; | ||
10 | protected $options = array(); | ||
11 | |||
12 | public function __construct($fileType, $minify = false, $options = array()) { | ||
13 | $this->fileType = $fileType; | ||
14 | $this->minify = $minify; | ||
15 | $this->options = $options; | ||
16 | $this->options['minify'] = $this->minify; | ||
17 | parent::__construct('combined', true); | ||
18 | } | ||
19 | |||
20 | public function add($file) { | ||
21 | if (!in_array($file, $this->files)) { | ||
22 | $this->files[] = $file; | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function addInline($text) { | ||
27 | $this->inline .= $text; | ||
28 | } | ||
29 | |||
30 | protected function getHash() { | ||
31 | $hash = ''; | ||
32 | for ($i = 0; $i < count($this->files); $i++) { | ||
33 | $hash .= $this->files[$i] . filemtime($this->files[$i]); | ||
34 | } | ||
35 | if (!empty($this->inline)) { | ||
36 | $hash .= $this->inline; | ||
37 | } | ||
38 | |||
39 | return md5($hash . json_encode($this->options)); | ||
40 | } | ||
41 | |||
42 | public function make() { | ||
43 | $hash = $this->getHash(); | ||
44 | $fileName = $hash . '.' . $this->fileType; | ||
45 | if (!$this->exists($fileName)) { | ||
46 | $buffer = ''; | ||
47 | for ($i = 0; $i < count($this->files); $i++) { | ||
48 | $buffer .= file_get_contents($this->files[$i]); | ||
49 | } | ||
50 | if ($this->minify !== false) { | ||
51 | $buffer = call_user_func($this->minify, $buffer); | ||
52 | } | ||
53 | $buffer .= $this->inline; | ||
54 | |||
55 | $this->set($fileName, $buffer); | ||
56 | } | ||
57 | |||
58 | return $this->getPath($fileName); | ||
59 | } | ||
60 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheImage extends N2Cache { | ||
5 | |||
6 | protected $_storageEngine = 'filesystem'; | ||
7 | |||
8 | protected function getScope() { | ||
9 | return 'image'; | ||
10 | } | ||
11 | |||
12 | public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) { | ||
13 | |||
14 | if (!$hash) { | ||
15 | $hash = $this->generateHash($fileExtension, $callable, $parameters); | ||
16 | } | ||
17 | $keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME); | ||
18 | $fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '') . '.' . $fileExtension; | ||
19 | |||
20 | if (!$this->exists($fileName)) { | ||
21 | $this->set($fileName, call_user_func_array($callable, $parameters)); | ||
22 | } | ||
23 | |||
24 | return $this->getPath($fileName); | ||
25 | } | ||
26 | |||
27 | private function generateHash($fileExtension, $callable, $parameters) { | ||
28 | return md5(json_encode(array( | ||
29 | $fileExtension, | ||
30 | $callable, | ||
31 | $parameters | ||
32 | ))); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | class N2StoreImage extends N2Cache { | ||
37 | |||
38 | protected $_storageEngine = 'filesystem'; | ||
39 | |||
40 | protected function getScope() { | ||
41 | return 'image'; | ||
42 | } | ||
43 | |||
44 | public function makeCache($fileName, $content) { | ||
45 | if (!$this->isImage($fileName)) { | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | if (!$this->exists($fileName)) { | ||
50 | $this->set($fileName, $content); | ||
51 | } | ||
52 | |||
53 | return $this->getPath($fileName); | ||
54 | } | ||
55 | |||
56 | private function isImage($fileName) { | ||
57 | $supported_image = array( | ||
58 | 'gif', | ||
59 | 'jpg', | ||
60 | 'jpeg', | ||
61 | 'png', | ||
62 | 'mp4', | ||
63 | 'mp3' | ||
64 | ); | ||
65 | |||
66 | $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); | ||
67 | if (in_array($ext, $supported_image)) { | ||
68 | return true; | ||
69 | } | ||
70 | |||
71 | return false; | ||
72 | } | ||
73 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.cache'); | ||
3 | |||
4 | class N2CacheManifest extends N2Cache { | ||
5 | |||
6 | private $isRaw = false; | ||
7 | |||
8 | private $manifestData; | ||
9 | |||
10 | public function __construct($group, $isAccessible = false, $isRaw = false) { | ||
11 | parent::__construct($group, $isAccessible); | ||
12 | $this->isRaw = $isRaw; | ||
13 | } | ||
14 | |||
15 | public function makeCache($fileName, $hash, $callable) { | ||
16 | if (!$this->isCached($fileName, $hash)) { | ||
17 | |||
18 | $return = call_user_func($callable, $this); | ||
19 | if ($return === false) { | ||
20 | return false; | ||
21 | } | ||
22 | |||
23 | return $this->createCacheFile($fileName, $hash, $return); | ||
24 | } | ||
25 | if ($this->isAccessible) { | ||
26 | return $this->getPath($fileName); | ||
27 | } | ||
28 | |||
29 | return json_decode($this->get($fileName), true); | ||
30 | } | ||
31 | |||
32 | private function isCached($fileName, $hash) { | ||
33 | |||
34 | |||
35 | $manifestKey = $this->getManifestKey($fileName); | ||
36 | if ($this->exists($manifestKey)) { | ||
37 | |||
38 | $this->manifestData = json_decode($this->get($manifestKey), true); | ||
39 | |||
40 | if (!$this->isCacheValid($this->manifestData) || $this->manifestData['hash'] != $hash) { | ||
41 | $this->clean($fileName); | ||
42 | |||
43 | return false; | ||
44 | } | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | return false; | ||
50 | } | ||
51 | |||
52 | protected function createCacheFile($fileName, $hash, $content) { | ||
53 | |||
54 | $this->manifestData = array(); | ||
55 | |||
56 | $this->manifestData['hash'] = $hash; | ||
57 | $this->addManifestData($this->manifestData); | ||
58 | |||
59 | $this->set($this->getManifestKey($fileName), json_encode($this->manifestData)); | ||
60 | |||
61 | $this->set($fileName, $this->isRaw ? $content : json_encode($content)); | ||
62 | |||
63 | if ($this->isAccessible) { | ||
64 | return $this->getPath($fileName); | ||
65 | } | ||
66 | |||
67 | return $content; | ||
68 | } | ||
69 | |||
70 | protected function isCacheValid(&$manifestData) { | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | protected function addManifestData(&$manifestData) { | ||
75 | |||
76 | } | ||
77 | |||
78 | public function clean($fileName) { | ||
79 | |||
80 | $this->remove($this->getManifestKey($fileName)); | ||
81 | $this->remove($fileName); | ||
82 | } | ||
83 | |||
84 | protected function getManifestKey($fileName) { | ||
85 | return $fileName . '.manifest'; | ||
86 | } | ||
87 | |||
88 | public function getData($key, $default = 0) { | ||
89 | return isset($this->manifestData[$key]) ? $this->manifestData[$key] : $default; | ||
90 | } | ||
91 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed.
Click to expand it.
1 | <?php | ||
2 | |||
3 | abstract class N2CacheStorage { | ||
4 | |||
5 | protected $paths = array(); | ||
6 | |||
7 | public function __construct() { | ||
8 | $this->paths['web'] = 'web'; | ||
9 | $this->paths['notweb'] = 'notweb'; | ||
10 | $this->paths['image'] = 'image'; | ||
11 | } | ||
12 | |||
13 | public function isFilesystem() { | ||
14 | return false; | ||
15 | } | ||
16 | |||
17 | public abstract function clear($group, $scope = 'notweb'); | ||
18 | |||
19 | public abstract function exists($group, $key, $scope = 'notweb'); | ||
20 | |||
21 | public abstract function set($group, $key, $value, $scope = 'notweb'); | ||
22 | |||
23 | public abstract function get($group, $key, $scope = 'notweb'); | ||
24 | |||
25 | public abstract function remove($group, $key, $scope = 'notweb'); | ||
26 | |||
27 | public abstract function getPath($group, $key, $scope = 'notweb'); | ||
28 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.storage.cachestorage'); | ||
3 | |||
4 | class N2CacheStorageDatabase extends N2CacheStorage { | ||
5 | |||
6 | protected $db; | ||
7 | |||
8 | public function __construct() { | ||
9 | |||
10 | parent::__construct(); | ||
11 | |||
12 | $this->db = new N2StorageSection('cache'); | ||
13 | } | ||
14 | |||
15 | public function clear($group, $scope = 'notweb') { | ||
16 | |||
17 | $this->db->delete($scope . '/' . $group); | ||
18 | } | ||
19 | |||
20 | public function exists($group, $key, $scope = 'notweb') { | ||
21 | |||
22 | if ($this->db->get($scope . '/' . $group, $key)) { | ||
23 | return true; | ||
24 | } | ||
25 | |||
26 | return false; | ||
27 | } | ||
28 | |||
29 | public function set($group, $key, $value, $scope = 'notweb') { | ||
30 | |||
31 | $this->db->set($scope . '/' . $group, $key, $value); | ||
32 | } | ||
33 | |||
34 | public function get($group, $key, $scope = 'notweb') { | ||
35 | return $this->db->get($scope . '/' . $group, $key); | ||
36 | } | ||
37 | |||
38 | public function remove($group, $key, $scope = 'notweb') { | ||
39 | $this->db->delete($scope . '/' . $group, $key); | ||
40 | } | ||
41 | |||
42 | public function getPath($group, $key, $scope = 'notweb') { | ||
43 | |||
44 | return N2Platform::getSiteUrl() . '?nextendcache=1&g=' . urlencode($group) . '&k=' . urlencode($key); | ||
45 | } | ||
46 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | N2Loader::import('libraries.cache.storage.cachestorage'); | ||
3 | |||
4 | class N2CacheStorageFilesystem extends N2CacheStorage { | ||
5 | |||
6 | public function __construct() { | ||
7 | $this->paths['web'] = N2Filesystem::getWebCachePath(); | ||
8 | $this->paths['notweb'] = N2Filesystem::getNotWebCachePath(); | ||
9 | $this->paths['image'] = N2Filesystem::getImagesFolder(); | ||
10 | } | ||
11 | |||
12 | public function isFilesystem() { | ||
13 | return true; | ||
14 | } | ||
15 | |||
16 | public function clear($group, $scope = 'notweb') { | ||
17 | |||
18 | if (N2Filesystem::existsFolder($this->paths[$scope] . NDS . $group)) { | ||
19 | N2Filesystem::deleteFolder($this->paths[$scope] . NDS . $group); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | public function exists($group, $key, $scope = 'notweb') { | ||
24 | if (N2Filesystem::existsFile($this->paths[$scope] . NDS . $group . NDS . $key)) { | ||
25 | return true; | ||
26 | } | ||
27 | |||
28 | return false; | ||
29 | } | ||
30 | |||
31 | public function set($group, $key, $value, $scope = 'notweb') { | ||
32 | $path = $this->paths[$scope] . NDS . $group . NDS . $key; | ||
33 | $dir = dirname($path); | ||
34 | if (!N2Filesystem::existsFolder($dir)) { | ||
35 | N2Filesystem::createFolder($dir); | ||
36 | } | ||
37 | N2Filesystem::createFile($path, $value); | ||
38 | } | ||
39 | |||
40 | public function get($group, $key, $scope = 'notweb') { | ||
41 | return N2Filesystem::readFile($this->paths[$scope] . NDS . $group . NDS . $key); | ||
42 | } | ||
43 | |||
44 | public function remove($group, $key, $scope = 'notweb') { | ||
45 | if ($this->exists($group, $key, $scope)) { | ||
46 | @unlink($this->paths[$scope] . NDS . $group . NDS . $key); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | public function getPath($group, $key, $scope = 'notweb') { | ||
51 | return $this->paths[$scope] . NDS . $group . NDS . $key; | ||
52 | } | ||
53 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <?php | ||
2 | |||
3 | class N2CacheManifestGenerator extends N2CacheManifest | ||
4 | { | ||
5 | |||
6 | /** | ||
7 | * @var N2SmartSliderAbstract | ||
8 | */ | ||
9 | private $slider; | ||
10 | |||
11 | private $generator; | ||
12 | |||
13 | /** | ||
14 | * @param N2SmartSliderAbstract $slider | ||
15 | * @param N2SmartSliderSlidesGenerator $generator | ||
16 | */ | ||
17 | public function __construct($slider, $generator) { | ||
18 | parent::__construct($slider->cacheId, false); | ||
19 | $this->slider = $slider; | ||
20 | $this->generator = $generator; | ||
21 | } | ||
22 | |||
23 | protected function isCacheValid(&$manifestData) { | ||
24 | $nextRefresh = $manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60; | ||
25 | if ($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60 < N2Platform::getTime()) { | ||
26 | return false; | ||
27 | } | ||
28 | $this->generator->setNextCacheRefresh($nextRefresh); | ||
29 | return true; | ||
30 | } | ||
31 | |||
32 | protected function addManifestData(&$manifestData) { | ||
33 | $manifestData['cacheTime'] = N2Platform::getTime(); | ||
34 | $this->generator->setNextCacheRefresh($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60); | ||
35 | } | ||
36 | } |
1 | <?php | ||
2 | |||
3 | class N2CacheManifestSlider extends N2CacheManifest { | ||
4 | |||
5 | private $parameters = array(); | ||
6 | |||
7 | private $isExtended = false; | ||
8 | |||
9 | public function __construct($cacheId, $parameters = array()) { | ||
10 | parent::__construct($cacheId, false); | ||
11 | $this->parameters = $parameters; | ||
12 | |||
13 | } | ||
14 | |||
15 | public function makeCache($fileName, $hash, $callable) { | ||
16 | |||
17 | $variations = 1; | ||
18 | if ($this->exists($this->getManifestKey('variations'))) { | ||
19 | $variations = intval($this->get($this->getManifestKey('variations'))); | ||
20 | } | ||
21 | $fileName = $fileName . mt_rand(1, $variations); | ||
22 | |||
23 | if (N2SmartSliderSettings::get('serversidemobiledetect', '0') == '1') { | ||
24 | N2Loader::import('libraries.mobiledetect'); | ||
25 | |||
26 | if (N2MobileDetect::$current['isMobile']) { | ||
27 | $fileName .= '-mobile'; | ||
28 | } else if (N2MobileDetect::$current['isTablet']) { | ||
29 | $fileName .= '-tablet'; | ||
30 | } else { | ||
31 | $fileName .= '-desktop'; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if ($this->exists($this->getManifestKey('data'))) { | ||
36 | $data = json_decode($this->get($this->getManifestKey('data')), true); | ||
37 | $fileName = $this->extendFileName($fileName, $data); | ||
38 | } else { | ||
39 | $this->clearCurrentGroup(); | ||
40 | } | ||
41 | |||
42 | $output = parent::makeCache($fileName, $hash, $callable); | ||
43 | |||
44 | return $output; | ||
45 | } | ||
46 | |||
47 | protected function createCacheFile($fileName, $hash, $content) { | ||
48 | |||
49 | $this->set($this->getManifestKey('data'), json_encode($this->parameters['slider']->manifestData)); | ||
50 | |||
51 | $fileName = $this->extendFileName($fileName, $this->parameters['slider']->manifestData); | ||
52 | |||
53 | return parent::createCacheFile($fileName, $hash, $content); | ||
54 | } | ||
55 | |||
56 | private function extendFileName($fileName, $manifestData) { | ||
57 | |||
58 | if ($this->isExtended) { | ||
59 | return $fileName; | ||
60 | } | ||
61 | |||
62 | $this->isExtended = true; | ||
63 | |||
64 | $generators = $manifestData['generator']; | ||
65 | |||
66 | if (count($generators)) { | ||
67 | N2Loader::import("models.generator", "smartslider"); | ||
68 | $generatorModel = new N2SmartsliderGeneratorModel(); | ||
69 | |||
70 | foreach ($generators AS $generator) { | ||
71 | list($group, $type, $params) = $generator; | ||
72 | $info = $generatorModel->getGeneratorInfo($group, $type); | ||
73 | |||
74 | require_once($info->path . '/generator.php'); | ||
75 | $class = 'N2Generator' . $group . $type; | ||
76 | |||
77 | $fileName .= call_user_func_array(array( | ||
78 | $class, | ||
79 | 'cacheKey' | ||
80 | ), $params); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return $fileName; | ||
85 | } | ||
86 | |||
87 | protected function isCacheValid(&$manifestData) { | ||
88 | |||
89 | if (!isset($manifestData['version']) || $manifestData['version'] != N2SS3::$version) { | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | if (N2SmartSliderHelper::getInstance() | ||
94 | ->isSliderChanged($this->parameters['slider']->sliderId, 1) | ||
95 | ) { | ||
96 | $this->clearCurrentGroup(); | ||
97 | N2SmartSliderHelper::getInstance() | ||
98 | ->setSliderChanged($this->parameters['slider']->sliderId, 0); | ||
99 | |||
100 | return false; | ||
101 | } | ||
102 | |||
103 | $time = N2Platform::getTime(); | ||
104 | |||
105 | if ($manifestData['nextCacheRefresh'] < $time) { | ||
106 | return false; | ||
107 | } | ||
108 | |||
109 | if (!isset($manifestData['currentPath']) || $manifestData['currentPath'] != md5(__FILE__)) { | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | return true; | ||
114 | } | ||
115 | |||
116 | protected function addManifestData(&$manifestData) { | ||
117 | |||
118 | $manifestData['nextCacheRefresh'] = N2Pluggable::applyFilters('SSNextCacheRefresh', $this->parameters['slider']->getNextCacheRefresh(), array($this->parameters['slider'])); | ||
119 | $manifestData['currentPath'] = md5(__FILE__); | ||
120 | $manifestData['version'] = N2SS3::$version; | ||
121 | |||
122 | $variations = 1; | ||
123 | |||
124 | $params = $this->parameters['slider']->params; | ||
125 | if (!$params->get('randomize-cache', 0) && ($params->get('randomize', 0) || $params->get('randomizeFirst', 0))) { | ||
126 | $variations = intval($params->get('variations', 5)); | ||
127 | if ($variations < 1) { | ||
128 | $variations = 1; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | $this->set($this->getManifestKey('variations'), $variations); | ||
133 | } | ||
134 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment