f6d49d07 by root

Merge branch 'deployment/production'

Conflicts:
	.gitignore
2 parents a5611969 e5290566
Showing 34 changed files with 2804 additions and 7 deletions
1 .DS_Store 1 app/administrator/cache/*
2 administrator/cache/* 2 app/administrator/logs/*
3 administrator/logs/* 3 /administrator/cache/*
4 cache 4 /administrator/logs/*
5 /cache
5 files 6 files
6 images 7 images
7 php5.6-back 8 php5.6-back
......
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 <?xml version="1.0" encoding="utf-8"?>
2 <metadata>
3 <layout title="COM_CACHE_CACHE_VIEW_DEFAULT_TITLE">
4 <message>
5 <![CDATA[COM_CACHE_CACHE_VIEW_DEFAULT_DESC]]>
6 </message>
7 </layout>
8 </metadata>
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>
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
1 <?php
2 /**
3 * N2MinifierJS.php - modified PHP implementation of Douglas Crockford's N2MinifierJS.
4 *
5 * <code>
6 * $minifiedJs = N2MinifierJS::minify($js);
7 * </code>
8 *
9 * This is a modified port of jsmin.c. Improvements:
10 *
11 * Does not choke on some regexp literals containing quote characters. E.g. /'/
12 *
13 * Spaces are preserved after some add/sub operators, so they are not mistakenly
14 * converted to post-inc/dec. E.g. a + ++b -> a+ ++b
15 *
16 * Preserves multi-line comments that begin with /*!
17 *
18 * PHP 5 or higher is required.
19 *
20 * Permission is hereby granted to use this version of the library under the
21 * same terms as jsmin.c, which has the following license:
22 *
23 * --
24 * Copyright (c) 2002 Douglas Crockford (www.crockford.com)
25 *
26 * Permission is hereby granted, free of charge, to any person obtaining a copy of
27 * this software and associated documentation files (the "Software"), to deal in
28 * the Software without restriction, including without limitation the rights to
29 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
30 * of the Software, and to permit persons to whom the Software is furnished to do
31 * so, subject to the following conditions:
32 *
33 * The above copyright notice and this permission notice shall be included in all
34 * copies or substantial portions of the Software.
35 *
36 * The Software shall be used for Good, not Evil.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 * SOFTWARE.
45 * --
46 *
47 * @package N2MinifierJS
48 * @author Ryan Grove <ryan@wonko.com> (PHP port)
49 * @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
50 * @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
51 * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
52 * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
53 * @license http://opensource.org/licenses/mit-license.php MIT License
54 * @link http://code.google.com/p/jsmin-php/
55 */
56
57 class N2MinifierJS {
58 const ORD_LF = 10;
59 const ORD_SPACE = 32;
60 const ACTION_KEEP_A = 1;
61 const ACTION_DELETE_A = 2;
62 const ACTION_DELETE_A_B = 3;
63
64 protected $a = "\n";
65 protected $b = '';
66 protected $input = '';
67 protected $inputIndex = 0;
68 protected $inputLength = 0;
69 protected $lookAhead = null;
70 protected $output = '';
71 protected $lastByteOut = '';
72 protected $keptComment = '';
73
74 /**
75 * Minify Javascript.
76 *
77 * @param string $js Javascript to be minified
78 *
79 * @return string
80 */
81 public static function minify($js)
82 {
83 $jsmin = new N2MinifierJS($js);
84 return $jsmin->min();
85 }
86
87 /**
88 * @param string $input
89 */
90 public function __construct($input)
91 {
92 $this->input = $input;
93 }
94
95 /**
96 * Perform minification, return result
97 *
98 * @return string
99 */
100 public function min()
101 {
102 if ($this->output !== '') { // min already run
103 return $this->output;
104 }
105
106 $mbIntEnc = null;
107 if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
108 $mbIntEnc = mb_internal_encoding();
109 mb_internal_encoding('8bit');
110 }
111 $this->input = str_replace("\r\n", "\n", $this->input);
112 $this->inputLength = strlen($this->input);
113
114 $this->action(self::ACTION_DELETE_A_B);
115
116 while ($this->a !== null) {
117 // determine next command
118 $command = self::ACTION_KEEP_A; // default
119 if ($this->a === ' ') {
120 if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
121 && ($this->b === $this->lastByteOut)) {
122 // Don't delete this space. If we do, the addition/subtraction
123 // could be parsed as a post-increment
124 } elseif (! $this->isAlphaNum($this->b)) {
125 $command = self::ACTION_DELETE_A;
126 }
127 } elseif ($this->a === "\n") {
128 if ($this->b === ' ') {
129 $command = self::ACTION_DELETE_A_B;
130
131 // in case of mbstring.func_overload & 2, must check for null b,
132 // otherwise mb_strpos will give WARNING
133 } elseif ($this->b === null
134 || (false === strpos('{[(+-!~', $this->b)
135 && ! $this->isAlphaNum($this->b))) {
136 $command = self::ACTION_DELETE_A;
137 }
138 } elseif (! $this->isAlphaNum($this->a)) {
139 if ($this->b === ' '
140 || ($this->b === "\n"
141 && (false === strpos('}])+-"\'', $this->a)))) {
142 $command = self::ACTION_DELETE_A_B;
143 }
144 }
145 $this->action($command);
146 }
147 $this->output = trim($this->output);
148
149 if ($mbIntEnc !== null) {
150 mb_internal_encoding($mbIntEnc);
151 }
152 return $this->output;
153 }
154
155 /**
156 * ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
157 * ACTION_DELETE_A = Copy B to A. Get the next B.
158 * ACTION_DELETE_A_B = Get the next B.
159 *
160 * @param int $command
161 *
162 *@throws N2JSMin_UnterminatedRegExpException|N2JSMin_UnterminatedStringException
163 */
164 protected function action($command)
165 {
166 // make sure we don't compress "a + ++b" to "a+++b", etc.
167 if ($command === self::ACTION_DELETE_A_B
168 && $this->b === ' '
169 && ($this->a === '+' || $this->a === '-')) {
170 // Note: we're at an addition/substraction operator; the inputIndex
171 // will certainly be a valid index
172 if ($this->input[$this->inputIndex] === $this->a) {
173 // This is "+ +" or "- -". Don't delete the space.
174 $command = self::ACTION_KEEP_A;
175 }
176 }
177
178 switch ($command) {
179 case self::ACTION_KEEP_A: // 1
180 $this->output .= $this->a;
181
182 if ($this->keptComment) {
183 $this->output = rtrim($this->output, "\n");
184 $this->output .= $this->keptComment;
185 $this->keptComment = '';
186 }
187
188 $this->lastByteOut = $this->a;
189
190 // fallthrough intentional
191 case self::ACTION_DELETE_A: // 2
192 $this->a = $this->b;
193 if ($this->a === "'" || $this->a === '"') { // string literal
194 $str = $this->a; // in case needed for exception
195 for(;;) {
196 $this->output .= $this->a;
197 $this->lastByteOut = $this->a;
198
199 $this->a = $this->get();
200 if ($this->a === $this->b) { // end quote
201 break;
202 }
203 if ($this->isEOF($this->a)) {
204 throw new N2JSMin_UnterminatedStringException(
205 "N2MinifierJS: Unterminated String at byte {$this->inputIndex}: {$str}");
206 }
207 $str .= $this->a;
208 if ($this->a === '\\') {
209 $this->output .= $this->a;
210 $this->lastByteOut = $this->a;
211
212 $this->a = $this->get();
213 $str .= $this->a;
214 }
215 }
216 }
217
218 // fallthrough intentional
219 case self::ACTION_DELETE_A_B: // 3
220 $this->b = $this->next();
221 if ($this->b === '/' && $this->isRegexpLiteral()) {
222 $this->output .= $this->a . $this->b;
223 $pattern = '/'; // keep entire pattern in case we need to report it in the exception
224 for(;;) {
225 $this->a = $this->get();
226 $pattern .= $this->a;
227 if ($this->a === '[') {
228 for(;;) {
229 $this->output .= $this->a;
230 $this->a = $this->get();
231 $pattern .= $this->a;
232 if ($this->a === ']') {
233 break;
234 }
235 if ($this->a === '\\') {
236 $this->output .= $this->a;
237 $this->a = $this->get();
238 $pattern .= $this->a;
239 }
240 if ($this->isEOF($this->a)) {
241 throw new N2JSMin_UnterminatedRegExpException(
242 "N2MinifierJS: Unterminated set in RegExp at byte "
243 . $this->inputIndex .": {$pattern}");
244 }
245 }
246 }
247
248 if ($this->a === '/') { // end pattern
249 break; // while (true)
250 } elseif ($this->a === '\\') {
251 $this->output .= $this->a;
252 $this->a = $this->get();
253 $pattern .= $this->a;
254 } elseif ($this->isEOF($this->a)) {
255 throw new N2JSMin_UnterminatedRegExpException(
256 "N2MinifierJS: Unterminated RegExp at byte {$this->inputIndex}: {$pattern}");
257 }
258 $this->output .= $this->a;
259 $this->lastByteOut = $this->a;
260 }
261 $this->b = $this->next();
262 }
263 // end case ACTION_DELETE_A_B
264 }
265 }
266
267 /**
268 * @return bool
269 */
270 protected function isRegexpLiteral()
271 {
272 if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
273 // we obviously aren't dividing
274 return true;
275 }
276 if ($this->a === ' ' || $this->a === "\n") {
277 $length = strlen($this->output);
278 if ($length < 2) { // weird edge case
279 return true;
280 }
281 // you can't divide a keyword
282 if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
283 if ($this->output === $m[0]) { // odd but could happen
284 return true;
285 }
286 // make sure it's a keyword, not end of an identifier
287 $charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
288 if (! $this->isAlphaNum($charBeforeKeyword)) {
289 return true;
290 }
291 }
292 }
293 return false;
294 }
295
296 /**
297 * Return the next character from stdin. Watch out for lookahead. If the character is a control character,
298 * translate it to a space or linefeed.
299 *
300 * @return string
301 */
302 protected function get()
303 {
304 $c = $this->lookAhead;
305 $this->lookAhead = null;
306 if ($c === null) {
307 // getc(stdin)
308 if ($this->inputIndex < $this->inputLength) {
309 $c = $this->input[$this->inputIndex];
310 $this->inputIndex += 1;
311 } else {
312 $c = null;
313 }
314 }
315 if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
316 return $c;
317 }
318 if ($c === "\r") {
319 return "\n";
320 }
321 return ' ';
322 }
323
324 /**
325 * Does $a indicate end of input?
326 *
327 * @param string $a
328 * @return bool
329 */
330 protected function isEOF($a)
331 {
332 return ord($a) <= self::ORD_LF;
333 }
334
335 /**
336 * Get next char (without getting it). If is ctrl character, translate to a space or newline.
337 *
338 * @return string
339 */
340 protected function peek()
341 {
342 $this->lookAhead = $this->get();
343 return $this->lookAhead;
344 }
345
346 /**
347 * Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
348 *
349 * @param string $c
350 *
351 * @return bool
352 */
353 protected function isAlphaNum($c)
354 {
355 return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
356 }
357
358 /**
359 * Consume a single line comment from input (possibly retaining it)
360 */
361 protected function consumeSingleLineComment()
362 {
363 $comment = '';
364 while (true) {
365 $get = $this->get();
366 $comment .= $get;
367 if (ord($get) <= self::ORD_LF) { // end of line reached
368 // if IE conditional comment
369 if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
370 $this->keptComment .= "/{$comment}";
371 }
372 return;
373 }
374 }
375 }
376
377 /**
378 * Consume a multiple line comment from input (possibly retaining it)
379 *
380 * @throws N2JSMin_UnterminatedCommentException
381 */
382 protected function consumeMultipleLineComment()
383 {
384 $this->get();
385 $comment = '';
386 for(;;) {
387 $get = $this->get();
388 if ($get === '*') {
389 if ($this->peek() === '/') { // end of comment reached
390 $this->get();
391 if (0 === strpos($comment, '!')) {
392 // preserved by YUI Compressor
393 if (!$this->keptComment) {
394 // don't prepend a newline if two comments right after one another
395 $this->keptComment = "\n";
396 }
397 $this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
398 } else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
399 // IE conditional
400 $this->keptComment .= "/*{$comment}*/";
401 }
402 return;
403 }
404 } elseif ($get === null) {
405 throw new N2JSMin_UnterminatedCommentException(
406 "N2MinifierJS: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
407 }
408 $comment .= $get;
409 }
410 }
411
412 /**
413 * Get the next character, skipping over comments. Some comments may be preserved.
414 *
415 * @return string
416 */
417 protected function next()
418 {
419 $get = $this->get();
420 if ($get === '/') {
421 switch ($this->peek()) {
422 case '/':
423 $this->consumeSingleLineComment();
424 $get = "\n";
425 break;
426 case '*':
427 $this->consumeMultipleLineComment();
428 $get = ' ';
429 break;
430 }
431 }
432 return $get;
433 }
434 }
435
436 class N2JSMin_UnterminatedStringException extends Exception {}
437 class N2JSMin_UnterminatedCommentException extends Exception {}
438 class N2JSMin_UnterminatedRegExpException extends Exception {}
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
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 }
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>
...@@ -414,10 +414,12 @@ main, ...@@ -414,10 +414,12 @@ main,
414 .btn_infoall a:active, 414 .btn_infoall a:active,
415 .btn_infoall a:hover, 415 .btn_infoall a:hover,
416 .btn_infoall a:visited { 416 .btn_infoall a:visited {
417 display: inline-block;
417 color: #fff !important; 418 color: #fff !important;
418 background-color: #009fa8; 419 background-color: #009fa8;
419 color: #fff; 420 color: #fff;
420 padding: 5px 15px 5px; 421 margin: 0 0 8px 8px;
422 padding: 1.5px 15px 1.5px;
421 font-size: 85%; 423 font-size: 85%;
422 border-radius: 5px; 424 border-radius: 5px;
423 } 425 }
...@@ -456,6 +458,9 @@ main, ...@@ -456,6 +458,9 @@ main,
456 #media .btn_infoall a:visited { 458 #media .btn_infoall a:visited {
457 background-color: #fba09b; 459 background-color: #fba09b;
458 } 460 }
461 #all > div.btn_infoall > a.newsarea-feed {
462 background-color: #ee802f;
463 }
459 464
460 @media (max-width: 1150px) { 465 @media (max-width: 1150px) {
461 #panels ul li .day { 466 #panels ul li .day {
......
...@@ -45,7 +45,7 @@ JHtml::_('script', 'template.js', array('version' => 'auto', 'relative' => true) ...@@ -45,7 +45,7 @@ JHtml::_('script', 'template.js', array('version' => 'auto', 'relative' => true)
45 JHtml::_('script', 'jui/html5.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9')); 45 JHtml::_('script', 'jui/html5.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9'));
46 46
47 // Add Stylesheets 47 // Add Stylesheets
48 JHtml::_('stylesheet', 'template.css', array('version' => '20200625001', 'relative' => true)); 48 JHtml::_('stylesheet', 'template.css', array('version' => '20200702001', 'relative' => true));
49 49
50 50
51 // Use of Google Font 51 // Use of Google Font
...@@ -648,6 +648,7 @@ if ($this->params->get('logoFile')) { ...@@ -648,6 +648,7 @@ if ($this->params->get('logoFile')) {
648 <li><a href="/entrance/open-campus/sessions.html">体験授業</a></li> 648 <li><a href="/entrance/open-campus/sessions.html">体験授業</a></li>
649 <li><a href="/entrance/open-campus/process.html">学外進学説明会のご案内</a></li> 649 <li><a href="/entrance/open-campus/process.html">学外進学説明会のご案内</a></li>
650 <li><a href="/entrance/open-campus/visitor.html">施設見学のご案内</a></li> 650 <li><a href="/entrance/open-campus/visitor.html">施設見学のご案内</a></li>
651 <li><a href="/entrance/open-campus/web.html">Webオープンキャンパス</a></li>
651 </ul> 652 </ul>
652 <div class="title"><a href="/campus-life/statatrra.html">学内業務補助</a></div> 653 <div class="title"><a href="/campus-life/statatrra.html">学内業務補助</a></div>
653 <ul> 654 <ul>
...@@ -768,6 +769,7 @@ if ($this->params->get('logoFile')) { ...@@ -768,6 +769,7 @@ if ($this->params->get('logoFile')) {
768 <li><a href="/faculties/masters/classes.html" title="授業科目">授業科目</a></li> 769 <li><a href="/faculties/masters/classes.html" title="授業科目">授業科目</a></li>
769 <li><a href="/faculties/masters/licenses.html" title="取得可能な免許・資格">取得可能な免許・資格</a></li> 770 <li><a href="/faculties/masters/licenses.html" title="取得可能な免許・資格">取得可能な免許・資格</a></li>
770 <li><a href="/faculties/masters/documents.html" title="各種提出様式">各種提出様式</a></li> 771 <li><a href="/faculties/masters/documents.html" title="各種提出様式">各種提出様式</a></li>
772 <li><a href="/faculties/masters/thesis.html" title="修士課程の学位論文について">修士課程の学位論文について</a></li>
771 </ul> 773 </ul>
772 <div class="title"><a href="/faculties/3.html">筑波大学との共同専攻:大学院体育学研究科大学体育スポーツ高度化共同専攻 (後期3年の課程のみの博士課程)</a></div> 774 <div class="title"><a href="/faculties/3.html">筑波大学との共同専攻:大学院体育学研究科大学体育スポーツ高度化共同専攻 (後期3年の課程のみの博士課程)</a></div>
773 <ul> 775 <ul>
...@@ -792,13 +794,14 @@ if ($this->params->get('logoFile')) { ...@@ -792,13 +794,14 @@ if ($this->params->get('logoFile')) {
792 <li><a href="/faculties/doctors/horizons.html" title="担当教員研究領域">担当教員研究領域</a></li> 794 <li><a href="/faculties/doctors/horizons.html" title="担当教員研究領域">担当教員研究領域</a></li>
793 <li><a href="/faculties/doctors/classes.html" title="授業科目">授業科目</a></li> 795 <li><a href="/faculties/doctors/classes.html" title="授業科目">授業科目</a></li>
794 <li><a href="/faculties/doctors/documents.html" title="各種提出様式">各種提出様式</a></li> 796 <li><a href="/faculties/doctors/documents.html" title="各種提出様式">各種提出様式</a></li>
797 <li><a href="/faculties/doctors/thesis.html" title="課程博士の学位論文について">課程博士の学位論文について</a></li>
795 </ul> 798 </ul>
796 <div class="title"><a href="/faculties/thesis.html">論文博士</a></div> 799 <div class="title"><a href="/faculties/thesis.html">論文博士</a></div>
797 <ul> 800 <ul>
798 <li><a href="/faculties/thesis/thesis.html" title="論文博士の概要">論文博士の概要</a></li> 801 <li><a href="/faculties/thesis/thesis.html" title="論文博士の概要">論文博士の概要</a></li>
799 <li><a href="/entrance/schooler/programkenkyusei.html" title="論文博士取得支援プログラムについて(研究生対象)">論文博士取得支援プログラムについて(研究生対象)</a></li> 802 <li><a href="/entrance/schooler/programkenkyusei.html" title="論文博士取得支援プログラムについて(研究生対象)">論文博士取得支援プログラムについて(研究生対象)</a></li>
800 <li><a href="/faculties/thesis/exam.html" title="論文博士の論文提出に係る外国語試験の実施について">論文博士の論文提出に係る外国語試験の実施について</a></li> 803 <li><a href="/faculties/thesis/exam.html" title="論文博士の論文提出に係る外国語試験の実施について">論文博士の論文提出に係る外国語試験の実施について</a></li>
801 <li><a href="/faculties/thesis/degrees.html" title="博士の学位授与について">博士の学位授与について</a></li> 804 <li><a href="/faculties/thesis/degrees.html" title="論文博士の学位論文について">論文博士の学位論文について</a></li>
802 </ul> 805 </ul>
803 </div> 806 </div>
804 <!-- ▲4列目 --> 807 <!-- ▲4列目 -->
......
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
1 <?php
2 /**
3 * N2MinifierJS.php - modified PHP implementation of Douglas Crockford's N2MinifierJS.
4 *
5 * <code>
6 * $minifiedJs = N2MinifierJS::minify($js);
7 * </code>
8 *
9 * This is a modified port of jsmin.c. Improvements:
10 *
11 * Does not choke on some regexp literals containing quote characters. E.g. /'/
12 *
13 * Spaces are preserved after some add/sub operators, so they are not mistakenly
14 * converted to post-inc/dec. E.g. a + ++b -> a+ ++b
15 *
16 * Preserves multi-line comments that begin with /*!
17 *
18 * PHP 5 or higher is required.
19 *
20 * Permission is hereby granted to use this version of the library under the
21 * same terms as jsmin.c, which has the following license:
22 *
23 * --
24 * Copyright (c) 2002 Douglas Crockford (www.crockford.com)
25 *
26 * Permission is hereby granted, free of charge, to any person obtaining a copy of
27 * this software and associated documentation files (the "Software"), to deal in
28 * the Software without restriction, including without limitation the rights to
29 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
30 * of the Software, and to permit persons to whom the Software is furnished to do
31 * so, subject to the following conditions:
32 *
33 * The above copyright notice and this permission notice shall be included in all
34 * copies or substantial portions of the Software.
35 *
36 * The Software shall be used for Good, not Evil.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 * SOFTWARE.
45 * --
46 *
47 * @package N2MinifierJS
48 * @author Ryan Grove <ryan@wonko.com> (PHP port)
49 * @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
50 * @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
51 * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
52 * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
53 * @license http://opensource.org/licenses/mit-license.php MIT License
54 * @link http://code.google.com/p/jsmin-php/
55 */
56
57 class N2MinifierJS {
58 const ORD_LF = 10;
59 const ORD_SPACE = 32;
60 const ACTION_KEEP_A = 1;
61 const ACTION_DELETE_A = 2;
62 const ACTION_DELETE_A_B = 3;
63
64 protected $a = "\n";
65 protected $b = '';
66 protected $input = '';
67 protected $inputIndex = 0;
68 protected $inputLength = 0;
69 protected $lookAhead = null;
70 protected $output = '';
71 protected $lastByteOut = '';
72 protected $keptComment = '';
73
74 /**
75 * Minify Javascript.
76 *
77 * @param string $js Javascript to be minified
78 *
79 * @return string
80 */
81 public static function minify($js)
82 {
83 $jsmin = new N2MinifierJS($js);
84 return $jsmin->min();
85 }
86
87 /**
88 * @param string $input
89 */
90 public function __construct($input)
91 {
92 $this->input = $input;
93 }
94
95 /**
96 * Perform minification, return result
97 *
98 * @return string
99 */
100 public function min()
101 {
102 if ($this->output !== '') { // min already run
103 return $this->output;
104 }
105
106 $mbIntEnc = null;
107 if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
108 $mbIntEnc = mb_internal_encoding();
109 mb_internal_encoding('8bit');
110 }
111 $this->input = str_replace("\r\n", "\n", $this->input);
112 $this->inputLength = strlen($this->input);
113
114 $this->action(self::ACTION_DELETE_A_B);
115
116 while ($this->a !== null) {
117 // determine next command
118 $command = self::ACTION_KEEP_A; // default
119 if ($this->a === ' ') {
120 if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
121 && ($this->b === $this->lastByteOut)) {
122 // Don't delete this space. If we do, the addition/subtraction
123 // could be parsed as a post-increment
124 } elseif (! $this->isAlphaNum($this->b)) {
125 $command = self::ACTION_DELETE_A;
126 }
127 } elseif ($this->a === "\n") {
128 if ($this->b === ' ') {
129 $command = self::ACTION_DELETE_A_B;
130
131 // in case of mbstring.func_overload & 2, must check for null b,
132 // otherwise mb_strpos will give WARNING
133 } elseif ($this->b === null
134 || (false === strpos('{[(+-!~', $this->b)
135 && ! $this->isAlphaNum($this->b))) {
136 $command = self::ACTION_DELETE_A;
137 }
138 } elseif (! $this->isAlphaNum($this->a)) {
139 if ($this->b === ' '
140 || ($this->b === "\n"
141 && (false === strpos('}])+-"\'', $this->a)))) {
142 $command = self::ACTION_DELETE_A_B;
143 }
144 }
145 $this->action($command);
146 }
147 $this->output = trim($this->output);
148
149 if ($mbIntEnc !== null) {
150 mb_internal_encoding($mbIntEnc);
151 }
152 return $this->output;
153 }
154
155 /**
156 * ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
157 * ACTION_DELETE_A = Copy B to A. Get the next B.
158 * ACTION_DELETE_A_B = Get the next B.
159 *
160 * @param int $command
161 *
162 *@throws N2JSMin_UnterminatedRegExpException|N2JSMin_UnterminatedStringException
163 */
164 protected function action($command)
165 {
166 // make sure we don't compress "a + ++b" to "a+++b", etc.
167 if ($command === self::ACTION_DELETE_A_B
168 && $this->b === ' '
169 && ($this->a === '+' || $this->a === '-')) {
170 // Note: we're at an addition/substraction operator; the inputIndex
171 // will certainly be a valid index
172 if ($this->input[$this->inputIndex] === $this->a) {
173 // This is "+ +" or "- -". Don't delete the space.
174 $command = self::ACTION_KEEP_A;
175 }
176 }
177
178 switch ($command) {
179 case self::ACTION_KEEP_A: // 1
180 $this->output .= $this->a;
181
182 if ($this->keptComment) {
183 $this->output = rtrim($this->output, "\n");
184 $this->output .= $this->keptComment;
185 $this->keptComment = '';
186 }
187
188 $this->lastByteOut = $this->a;
189
190 // fallthrough intentional
191 case self::ACTION_DELETE_A: // 2
192 $this->a = $this->b;
193 if ($this->a === "'" || $this->a === '"') { // string literal
194 $str = $this->a; // in case needed for exception
195 for(;;) {
196 $this->output .= $this->a;
197 $this->lastByteOut = $this->a;
198
199 $this->a = $this->get();
200 if ($this->a === $this->b) { // end quote
201 break;
202 }
203 if ($this->isEOF($this->a)) {
204 throw new N2JSMin_UnterminatedStringException(
205 "N2MinifierJS: Unterminated String at byte {$this->inputIndex}: {$str}");
206 }
207 $str .= $this->a;
208 if ($this->a === '\\') {
209 $this->output .= $this->a;
210 $this->lastByteOut = $this->a;
211
212 $this->a = $this->get();
213 $str .= $this->a;
214 }
215 }
216 }
217
218 // fallthrough intentional
219 case self::ACTION_DELETE_A_B: // 3
220 $this->b = $this->next();
221 if ($this->b === '/' && $this->isRegexpLiteral()) {
222 $this->output .= $this->a . $this->b;
223 $pattern = '/'; // keep entire pattern in case we need to report it in the exception
224 for(;;) {
225 $this->a = $this->get();
226 $pattern .= $this->a;
227 if ($this->a === '[') {
228 for(;;) {
229 $this->output .= $this->a;
230 $this->a = $this->get();
231 $pattern .= $this->a;
232 if ($this->a === ']') {
233 break;
234 }
235 if ($this->a === '\\') {
236 $this->output .= $this->a;
237 $this->a = $this->get();
238 $pattern .= $this->a;
239 }
240 if ($this->isEOF($this->a)) {
241 throw new N2JSMin_UnterminatedRegExpException(
242 "N2MinifierJS: Unterminated set in RegExp at byte "
243 . $this->inputIndex .": {$pattern}");
244 }
245 }
246 }
247
248 if ($this->a === '/') { // end pattern
249 break; // while (true)
250 } elseif ($this->a === '\\') {
251 $this->output .= $this->a;
252 $this->a = $this->get();
253 $pattern .= $this->a;
254 } elseif ($this->isEOF($this->a)) {
255 throw new N2JSMin_UnterminatedRegExpException(
256 "N2MinifierJS: Unterminated RegExp at byte {$this->inputIndex}: {$pattern}");
257 }
258 $this->output .= $this->a;
259 $this->lastByteOut = $this->a;
260 }
261 $this->b = $this->next();
262 }
263 // end case ACTION_DELETE_A_B
264 }
265 }
266
267 /**
268 * @return bool
269 */
270 protected function isRegexpLiteral()
271 {
272 if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
273 // we obviously aren't dividing
274 return true;
275 }
276 if ($this->a === ' ' || $this->a === "\n") {
277 $length = strlen($this->output);
278 if ($length < 2) { // weird edge case
279 return true;
280 }
281 // you can't divide a keyword
282 if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
283 if ($this->output === $m[0]) { // odd but could happen
284 return true;
285 }
286 // make sure it's a keyword, not end of an identifier
287 $charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
288 if (! $this->isAlphaNum($charBeforeKeyword)) {
289 return true;
290 }
291 }
292 }
293 return false;
294 }
295
296 /**
297 * Return the next character from stdin. Watch out for lookahead. If the character is a control character,
298 * translate it to a space or linefeed.
299 *
300 * @return string
301 */
302 protected function get()
303 {
304 $c = $this->lookAhead;
305 $this->lookAhead = null;
306 if ($c === null) {
307 // getc(stdin)
308 if ($this->inputIndex < $this->inputLength) {
309 $c = $this->input[$this->inputIndex];
310 $this->inputIndex += 1;
311 } else {
312 $c = null;
313 }
314 }
315 if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
316 return $c;
317 }
318 if ($c === "\r") {
319 return "\n";
320 }
321 return ' ';
322 }
323
324 /**
325 * Does $a indicate end of input?
326 *
327 * @param string $a
328 * @return bool
329 */
330 protected function isEOF($a)
331 {
332 return ord($a) <= self::ORD_LF;
333 }
334
335 /**
336 * Get next char (without getting it). If is ctrl character, translate to a space or newline.
337 *
338 * @return string
339 */
340 protected function peek()
341 {
342 $this->lookAhead = $this->get();
343 return $this->lookAhead;
344 }
345
346 /**
347 * Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
348 *
349 * @param string $c
350 *
351 * @return bool
352 */
353 protected function isAlphaNum($c)
354 {
355 return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
356 }
357
358 /**
359 * Consume a single line comment from input (possibly retaining it)
360 */
361 protected function consumeSingleLineComment()
362 {
363 $comment = '';
364 while (true) {
365 $get = $this->get();
366 $comment .= $get;
367 if (ord($get) <= self::ORD_LF) { // end of line reached
368 // if IE conditional comment
369 if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
370 $this->keptComment .= "/{$comment}";
371 }
372 return;
373 }
374 }
375 }
376
377 /**
378 * Consume a multiple line comment from input (possibly retaining it)
379 *
380 * @throws N2JSMin_UnterminatedCommentException
381 */
382 protected function consumeMultipleLineComment()
383 {
384 $this->get();
385 $comment = '';
386 for(;;) {
387 $get = $this->get();
388 if ($get === '*') {
389 if ($this->peek() === '/') { // end of comment reached
390 $this->get();
391 if (0 === strpos($comment, '!')) {
392 // preserved by YUI Compressor
393 if (!$this->keptComment) {
394 // don't prepend a newline if two comments right after one another
395 $this->keptComment = "\n";
396 }
397 $this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
398 } else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
399 // IE conditional
400 $this->keptComment .= "/*{$comment}*/";
401 }
402 return;
403 }
404 } elseif ($get === null) {
405 throw new N2JSMin_UnterminatedCommentException(
406 "N2MinifierJS: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
407 }
408 $comment .= $get;
409 }
410 }
411
412 /**
413 * Get the next character, skipping over comments. Some comments may be preserved.
414 *
415 * @return string
416 */
417 protected function next()
418 {
419 $get = $this->get();
420 if ($get === '/') {
421 switch ($this->peek()) {
422 case '/':
423 $this->consumeSingleLineComment();
424 $get = "\n";
425 break;
426 case '*':
427 $this->consumeMultipleLineComment();
428 $get = ' ';
429 break;
430 }
431 }
432 return $get;
433 }
434 }
435
436 class N2JSMin_UnterminatedStringException extends Exception {}
437 class N2JSMin_UnterminatedCommentException extends Exception {}
438 class N2JSMin_UnterminatedRegExpException extends Exception {}
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
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!