e5290566 by Yokihito Oki

コンポーネント / ライブラリのキャッシュをgit管理に追加

1 parent c9c39c53
Showing 32 changed files with 1916 additions and 2 deletions
app/administrator/cache/*
administrator/logs/*
cache
app/administrator/logs/*
/administrator/cache/*
/administrator/logs/*
/cache
files
images
php5.6-back
......
<?php
/**
* @package Joomla.Administrator
* @subpackage com_cache
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('bootstrap.tooltip');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<form action="<?php echo JRoute::_('index.php?option=com_cache'); ?>" method="post" name="adminForm" id="adminForm">
<?php if (!empty($this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<?php else : ?>
<div id="j-main-container">
<?php endif; ?>
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<?php if ($this->total > 0) : ?>
<table class="table table-striped">
<thead>
<tr>
<th width="1%" class="nowrap center">
<?php echo JHtml::_('grid.checkall'); ?>
</th>
<th class="title nowrap">
<?php echo JHtml::_('searchtools.sort', 'COM_CACHE_GROUP', 'group', $listDirn, $listOrder); ?>
</th>
<th width="5%" class="nowrap">
<?php echo JHtml::_('searchtools.sort', 'COM_CACHE_NUMBER_OF_FILES', 'count', $listDirn, $listOrder); ?>
</th>
<th width="10%" class="nowrap">
<?php echo JHtml::_('searchtools.sort', 'COM_CACHE_SIZE', 'size', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php
$i = 0;
foreach ($this->data as $folder => $item) : ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<input type="checkbox" id="cb<?php echo $i; ?>" name="cid[]" value="<?php echo $this->escape($item->group); ?>" onclick="Joomla.isChecked(this.checked);" />
</td>
<td>
<label for="cb<?php echo $i; ?>">
<strong><?php echo $this->escape($item->group); ?></strong>
</label>
</td>
<td>
<?php echo $item->count; ?>
</td>
<td>
<?php echo JHtml::_('number.bytes', $item->size); ?>
</td>
</tr>
<?php $i++; endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_CACHE_CACHE_VIEW_DEFAULT_TITLE">
<message>
<![CDATA[COM_CACHE_CACHE_VIEW_DEFAULT_DESC]]>
</message>
</layout>
</metadata>
<?php
/**
* @package Joomla.Administrator
* @subpackage com_cache
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* HTML View class for the Cache component
*
* @since 1.6
*/
class CacheViewCache extends JViewLegacy
{
/**
* @var object client object.
* @deprecated 4.0
*/
protected $client;
protected $data;
protected $pagination;
protected $state;
/**
* Display a view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->data = $this->get('Data');
$this->pagination = $this->get('Pagination');
$this->total = $this->get('Total');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new Exception(implode("\n", $errors), 500);
}
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$state = $this->get('State');
if ($state->get('client_id') == 1)
{
JToolbarHelper::title(JText::_('COM_CACHE_CLEAR_CACHE_ADMIN_TITLE'), 'lightning clear');
}
else
{
JToolbarHelper::title(JText::_('COM_CACHE_CLEAR_CACHE_SITE_TITLE'), 'lightning clear');
}
JToolbarHelper::custom('delete', 'delete.png', 'delete_f2.png', 'JTOOLBAR_DELETE', true);
JToolbarHelper::custom('deleteAll', 'remove.png', 'delete_f2.png', 'JTOOLBAR_DELETE_ALL', false);
JToolbarHelper::divider();
if (JFactory::getUser()->authorise('core.admin', 'com_cache'))
{
JToolbarHelper::preferences('com_cache');
}
JToolbarHelper::divider();
JToolbarHelper::help('JHELP_SITE_MAINTENANCE_CLEAR_CACHE');
JHtmlSidebar::setAction('index.php?option=com_cache');
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<?php
/**
* @package Joomla.Administrator
* @subpackage Template.hathor
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<form action="<?php echo JRoute::_('index.php?option=com_cache'); ?>" method="post" name="adminForm" id="adminForm">
<?php if (!empty( $this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<fieldset id="filter-bar">
<legend class="element-invisible"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></legend>
<div class="filter-select fltrt">
<label class="selectlabel" for="client_id">
<?php echo JText::_('COM_CACHE_SELECT_CLIENT'); ?>
</label>
<select name="client_id" id="client_id">
<?php echo JHtml::_('select.options', CacheHelper::getClientOptions(), 'value', 'text', $this->state->get('client_id'));?>
</select>
<button type="submit" id="filter-go">
<?php echo JText::_('JSUBMIT'); ?></button>
</div>
</fieldset>
<div class="clr"> </div>
<table class="adminlist">
<thead>
<tr>
<th class="checkmark-col">
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
</th>
<th class="title nowrap">
<?php echo JHtml::_('grid.sort', 'COM_CACHE_GROUP', 'group', $listDirn, $listOrder); ?>
</th>
<th class="width-5 center nowrap">
<?php echo JHtml::_('grid.sort', 'COM_CACHE_NUMBER_OF_FILES', 'count', $listDirn, $listOrder); ?>
</th>
<th class="width-10 center">
<?php echo JHtml::_('grid.sort', 'COM_CACHE_SIZE', 'size', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($this->data as $folder => $item) : ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $item->group; ?>" onclick="Joomla.isChecked(this.checked);" />
</td>
<td>
<span class="bold">
<?php echo $item->group; ?>
</span>
</td>
<td class="center">
<?php echo $item->count; ?>
</td>
<td class="center">
<?php echo JHtml::_('number.bytes', $item->size*1024); ?>
</td>
</tr>
<?php $i++; endforeach; ?>
</tbody>
</table>
<?php echo $this->pagination->getListFooter(); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="client" value="<?php echo $this->client->id;?>" />
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
<?php
/**
* @package FrameworkOnFramework
* @subpackage utils
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('FOF_INCLUDED') or die;
/**
* A utility class to help you quickly clean the Joomla! cache
*/
class FOFUtilsCacheCleaner
{
/**
* Clears the com_modules and com_plugins cache. You need to call this whenever you alter the publish state or
* parameters of a module or plugin from your code.
*
* @return void
*/
public static function clearPluginsAndModulesCache()
{
self::clearPluginsCache();
self::clearModulesCache();
}
/**
* Clears the com_plugins cache. You need to call this whenever you alter the publish state or parameters of a
* plugin from your code.
*
* @return void
*/
public static function clearPluginsCache()
{
self::clearCacheGroups(array('com_plugins'), array(0,1));
}
/**
* Clears the com_modules cache. You need to call this whenever you alter the publish state or parameters of a
* module from your code.
*
* @return void
*/
public static function clearModulesCache()
{
self::clearCacheGroups(array('com_modules'), array(0,1));
}
/**
* Clears the specified cache groups.
*
* @param array $clearGroups Which cache groups to clear. Usually this is com_yourcomponent to clear your
* component's cache.
* @param array $cacheClients Which cache clients to clear. 0 is the back-end, 1 is the front-end. If you do not
* specify anything, both cache clients will be cleared.
*
* @return void
*/
public static function clearCacheGroups(array $clearGroups, array $cacheClients = array(0, 1))
{
$conf = JFactory::getConfig();
foreach ($clearGroups as $group)
{
foreach ($cacheClients as $client_id)
{
try
{
$options = array(
'defaultgroup' => $group,
'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache')
);
$cache = JCache::getInstance('callback', $options);
$cache->clean();
}
catch (Exception $e)
{
// suck it up
}
}
}
}
}
\ No newline at end of file
<?php
N2Loader::importAll('libraries.cache.storage');
class N2Cache {
protected $group = '';
protected $isAccessible = false;
/** @var N2CacheStorage */
public $storage;
protected $_storageEngine = 'default';
/**
* @param string $engine
*
* @return N2CacheStorage
*/
public static function getStorage($engine = "default") {
static $storage = null;
if ($storage === null) {
$storage = array(
'filesystem' => new N2CacheStorageFilesystem(),
'database' => new N2CacheStorageDatabase()
);
}
if ($engine == 'default') {
if (defined('NEXTEND_CACHE_STORAGE')) {
return $storage[NEXTEND_CACHE_STORAGE];
}
return $storage['filesystem'];
}
return $storage[$engine];
}
public static function clearGroup($group) {
$storage = self::getStorage();
$storage->clear($group);
$storage->clear($group, 'web');
}
public function __construct($group, $isAccessible = false) {
$this->group = $group;
$this->isAccessible = $isAccessible;
$this->storage = self::getStorage($this->_storageEngine);
}
protected function clearCurrentGroup() {
$this->storage->clear($this->group, $this->getScope());
}
protected function getScope() {
if ($this->isAccessible) {
return 'web';
}
return 'notweb';
}
protected function exists($key) {
return $this->storage->exists($this->group, $key, $this->getScope());
}
protected function get($key) {
return $this->storage->get($this->group, $key, $this->getScope());
}
protected function set($key, $value) {
$this->storage->set($this->group, $key, $value, $this->getScope());
}
protected function getPath($key) {
return $this->storage->getPath($this->group, $key, $this->getScope());
}
protected function remove($key) {
return $this->storage->remove($this->group, $key, $this->getScope());
}
}
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheCombine extends N2Cache {
protected $files = array();
protected $inline = '';
protected $fileType = '';
protected $minify = false;
protected $options = array();
public function __construct($fileType, $minify = false, $options = array()) {
$this->fileType = $fileType;
$this->minify = $minify;
$this->options = $options;
$this->options['minify'] = $this->minify;
parent::__construct('combined', true);
}
public function add($file) {
if (!in_array($file, $this->files)) {
$this->files[] = $file;
}
}
public function addInline($text) {
$this->inline .= $text;
}
protected function getHash() {
$hash = '';
for ($i = 0; $i < count($this->files); $i++) {
$hash .= $this->files[$i] . filemtime($this->files[$i]);
}
if (!empty($this->inline)) {
$hash .= $this->inline;
}
return md5($hash . json_encode($this->options));
}
public function make() {
$hash = $this->getHash();
$fileName = $hash . '.' . $this->fileType;
if (!$this->exists($fileName)) {
$buffer = '';
for ($i = 0; $i < count($this->files); $i++) {
$buffer .= file_get_contents($this->files[$i]);
}
if ($this->minify !== false) {
$buffer = call_user_func($this->minify, $buffer);
}
$buffer .= $this->inline;
$this->set($fileName, $buffer);
}
return $this->getPath($fileName);
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheImage extends N2Cache {
protected $_storageEngine = 'filesystem';
protected function getScope() {
return 'image';
}
public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) {
if (!$hash) {
$hash = $this->generateHash($fileExtension, $callable, $parameters);
}
$keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME);
$fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '') . '.' . $fileExtension;
if (!$this->exists($fileName)) {
$this->set($fileName, call_user_func_array($callable, $parameters));
}
return $this->getPath($fileName);
}
private function generateHash($fileExtension, $callable, $parameters) {
return md5(json_encode(array(
$fileExtension,
$callable,
$parameters
)));
}
}
class N2StoreImage extends N2Cache {
protected $_storageEngine = 'filesystem';
protected function getScope() {
return 'image';
}
public function makeCache($fileName, $content) {
if (!$this->isImage($fileName)) {
return false;
}
if (!$this->exists($fileName)) {
$this->set($fileName, $content);
}
return $this->getPath($fileName);
}
private function isImage($fileName) {
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'mp4',
'mp3'
);
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (in_array($ext, $supported_image)) {
return true;
}
return false;
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheManifest extends N2Cache {
private $isRaw = false;
private $manifestData;
public function __construct($group, $isAccessible = false, $isRaw = false) {
parent::__construct($group, $isAccessible);
$this->isRaw = $isRaw;
}
public function makeCache($fileName, $hash, $callable) {
if (!$this->isCached($fileName, $hash)) {
$return = call_user_func($callable, $this);
if ($return === false) {
return false;
}
return $this->createCacheFile($fileName, $hash, $return);
}
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return json_decode($this->get($fileName), true);
}
private function isCached($fileName, $hash) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$this->manifestData = json_decode($this->get($manifestKey), true);
if (!$this->isCacheValid($this->manifestData) || $this->manifestData['hash'] != $hash) {
$this->clean($fileName);
return false;
}
return true;
}
return false;
}
protected function createCacheFile($fileName, $hash, $content) {
$this->manifestData = array();
$this->manifestData['hash'] = $hash;
$this->addManifestData($this->manifestData);
$this->set($this->getManifestKey($fileName), json_encode($this->manifestData));
$this->set($fileName, $this->isRaw ? $content : json_encode($content));
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return $content;
}
protected function isCacheValid(&$manifestData) {
return true;
}
protected function addManifestData(&$manifestData) {
}
public function clean($fileName) {
$this->remove($this->getManifestKey($fileName));
$this->remove($fileName);
}
protected function getManifestKey($fileName) {
return $fileName . '.manifest';
}
public function getData($key, $default = 0) {
return isset($this->manifestData[$key]) ? $this->manifestData[$key] : $default;
}
}
\ No newline at end of file
<?php
abstract class N2CacheStorage {
protected $paths = array();
public function __construct() {
$this->paths['web'] = 'web';
$this->paths['notweb'] = 'notweb';
$this->paths['image'] = 'image';
}
public function isFilesystem() {
return false;
}
public abstract function clear($group, $scope = 'notweb');
public abstract function exists($group, $key, $scope = 'notweb');
public abstract function set($group, $key, $value, $scope = 'notweb');
public abstract function get($group, $key, $scope = 'notweb');
public abstract function remove($group, $key, $scope = 'notweb');
public abstract function getPath($group, $key, $scope = 'notweb');
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.storage.cachestorage');
class N2CacheStorageDatabase extends N2CacheStorage {
protected $db;
public function __construct() {
parent::__construct();
$this->db = new N2StorageSection('cache');
}
public function clear($group, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group);
}
public function exists($group, $key, $scope = 'notweb') {
if ($this->db->get($scope . '/' . $group, $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$this->db->set($scope . '/' . $group, $key, $value);
}
public function get($group, $key, $scope = 'notweb') {
return $this->db->get($scope . '/' . $group, $key);
}
public function remove($group, $key, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group, $key);
}
public function getPath($group, $key, $scope = 'notweb') {
return N2Platform::getSiteUrl() . '?nextendcache=1&g=' . urlencode($group) . '&k=' . urlencode($key);
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.storage.cachestorage');
class N2CacheStorageFilesystem extends N2CacheStorage {
public function __construct() {
$this->paths['web'] = N2Filesystem::getWebCachePath();
$this->paths['notweb'] = N2Filesystem::getNotWebCachePath();
$this->paths['image'] = N2Filesystem::getImagesFolder();
}
public function isFilesystem() {
return true;
}
public function clear($group, $scope = 'notweb') {
if (N2Filesystem::existsFolder($this->paths[$scope] . NDS . $group)) {
N2Filesystem::deleteFolder($this->paths[$scope] . NDS . $group);
}
}
public function exists($group, $key, $scope = 'notweb') {
if (N2Filesystem::existsFile($this->paths[$scope] . NDS . $group . NDS . $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$path = $this->paths[$scope] . NDS . $group . NDS . $key;
$dir = dirname($path);
if (!N2Filesystem::existsFolder($dir)) {
N2Filesystem::createFolder($dir);
}
N2Filesystem::createFile($path, $value);
}
public function get($group, $key, $scope = 'notweb') {
return N2Filesystem::readFile($this->paths[$scope] . NDS . $group . NDS . $key);
}
public function remove($group, $key, $scope = 'notweb') {
if ($this->exists($group, $key, $scope)) {
@unlink($this->paths[$scope] . NDS . $group . NDS . $key);
}
}
public function getPath($group, $key, $scope = 'notweb') {
return $this->paths[$scope] . NDS . $group . NDS . $key;
}
}
\ No newline at end of file
<?php
class N2CacheManifestGenerator extends N2CacheManifest
{
/**
* @var N2SmartSliderAbstract
*/
private $slider;
private $generator;
/**
* @param N2SmartSliderAbstract $slider
* @param N2SmartSliderSlidesGenerator $generator
*/
public function __construct($slider, $generator) {
parent::__construct($slider->cacheId, false);
$this->slider = $slider;
$this->generator = $generator;
}
protected function isCacheValid(&$manifestData) {
$nextRefresh = $manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60;
if ($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60 < N2Platform::getTime()) {
return false;
}
$this->generator->setNextCacheRefresh($nextRefresh);
return true;
}
protected function addManifestData(&$manifestData) {
$manifestData['cacheTime'] = N2Platform::getTime();
$this->generator->setNextCacheRefresh($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60);
}
}
<?php
class N2CacheManifestSlider extends N2CacheManifest {
private $parameters = array();
private $isExtended = false;
public function __construct($cacheId, $parameters = array()) {
parent::__construct($cacheId, false);
$this->parameters = $parameters;
}
public function makeCache($fileName, $hash, $callable) {
$variations = 1;
if ($this->exists($this->getManifestKey('variations'))) {
$variations = intval($this->get($this->getManifestKey('variations')));
}
$fileName = $fileName . mt_rand(1, $variations);
if (N2SmartSliderSettings::get('serversidemobiledetect', '0') == '1') {
N2Loader::import('libraries.mobiledetect');
if (N2MobileDetect::$current['isMobile']) {
$fileName .= '-mobile';
} else if (N2MobileDetect::$current['isTablet']) {
$fileName .= '-tablet';
} else {
$fileName .= '-desktop';
}
}
if ($this->exists($this->getManifestKey('data'))) {
$data = json_decode($this->get($this->getManifestKey('data')), true);
$fileName = $this->extendFileName($fileName, $data);
} else {
$this->clearCurrentGroup();
}
$output = parent::makeCache($fileName, $hash, $callable);
return $output;
}
protected function createCacheFile($fileName, $hash, $content) {
$this->set($this->getManifestKey('data'), json_encode($this->parameters['slider']->manifestData));
$fileName = $this->extendFileName($fileName, $this->parameters['slider']->manifestData);
return parent::createCacheFile($fileName, $hash, $content);
}
private function extendFileName($fileName, $manifestData) {
if ($this->isExtended) {
return $fileName;
}
$this->isExtended = true;
$generators = $manifestData['generator'];
if (count($generators)) {
N2Loader::import("models.generator", "smartslider");
$generatorModel = new N2SmartsliderGeneratorModel();
foreach ($generators AS $generator) {
list($group, $type, $params) = $generator;
$info = $generatorModel->getGeneratorInfo($group, $type);
require_once($info->path . '/generator.php');
$class = 'N2Generator' . $group . $type;
$fileName .= call_user_func_array(array(
$class,
'cacheKey'
), $params);
}
}
return $fileName;
}
protected function isCacheValid(&$manifestData) {
if (!isset($manifestData['version']) || $manifestData['version'] != N2SS3::$version) {
return false;
}
if (N2SmartSliderHelper::getInstance()
->isSliderChanged($this->parameters['slider']->sliderId, 1)
) {
$this->clearCurrentGroup();
N2SmartSliderHelper::getInstance()
->setSliderChanged($this->parameters['slider']->sliderId, 0);
return false;
}
$time = N2Platform::getTime();
if ($manifestData['nextCacheRefresh'] < $time) {
return false;
}
if (!isset($manifestData['currentPath']) || $manifestData['currentPath'] != md5(__FILE__)) {
return false;
}
return true;
}
protected function addManifestData(&$manifestData) {
$manifestData['nextCacheRefresh'] = N2Pluggable::applyFilters('SSNextCacheRefresh', $this->parameters['slider']->getNextCacheRefresh(), array($this->parameters['slider']));
$manifestData['currentPath'] = md5(__FILE__);
$manifestData['version'] = N2SS3::$version;
$variations = 1;
$params = $this->parameters['slider']->params;
if (!$params->get('randomize-cache', 0) && ($params->get('randomize', 0) || $params->get('randomizeFirst', 0))) {
$variations = intval($params->get('variations', 5));
if ($variations < 1) {
$variations = 1;
}
}
$this->set($this->getManifestKey('variations'), $variations);
}
}
\ No newline at end of file
<?php
/**
* @package Joomla.Plugin
* @subpackage System.cache
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Joomla! Page Cache Plugin.
*
* @since 1.5
*/
class PlgSystemCache extends JPlugin
{
/**
* Cache instance.
*
* @var JCache
* @since 1.5
*/
public $_cache;
/**
* Cache key
*
* @var string
* @since 3.0
*/
public $_cache_key;
/**
* Application object.
*
* @var JApplicationCms
* @since 3.8.0
*/
protected $app;
/**
* Constructor.
*
* @param object &$subject The object to observe.
* @param array $config An optional associative array of configuration settings.
*
* @since 1.5
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
// Get the application if not done by JPlugin.
if (!isset($this->app))
{
$this->app = JFactory::getApplication();
}
// Set the cache options.
$options = array(
'defaultgroup' => 'page',
'browsercache' => $this->params->get('browsercache', 0),
'caching' => false,
);
// Instantiate cache with previous options and create the cache key identifier.
$this->_cache = JCache::getInstance('page', $options);
$this->_cache_key = JUri::getInstance()->toString();
}
/**
* Get a cache key for the current page based on the url and possible other factors.
*
* @return string
*
* @since 3.7
*/
protected function getCacheKey()
{
static $key;
if (!$key)
{
JPluginHelper::importPlugin('pagecache');
$parts = JEventDispatcher::getInstance()->trigger('onPageCacheGetKey');
$parts[] = JUri::getInstance()->toString();
$key = md5(serialize($parts));
}
return $key;
}
/**
* After Initialise Event.
* Checks if URL exists in cache, if so dumps it directly and closes.
*
* @return void
*
* @since 1.5
*/
public function onAfterInitialise()
{
if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || $this->app->getMessageQueue())
{
return;
}
// If any pagecache plugins return false for onPageCacheSetCaching, do not use the cache.
JPluginHelper::importPlugin('pagecache');
$results = JEventDispatcher::getInstance()->trigger('onPageCacheSetCaching');
$caching = !in_array(false, $results, true);
if ($caching && JFactory::getUser()->guest && $this->app->input->getMethod() === 'GET')
{
$this->_cache->setCaching(true);
}
$data = $this->_cache->get($this->getCacheKey());
// If page exist in cache, show cached page.
if ($data !== false)
{
// Set HTML page from cache.
$this->app->setBody($data);
// Dumps HTML page.
echo $this->app->toString((bool) $this->app->get('gzip'));
// Mark afterCache in debug and run debug onAfterRespond events.
// e.g., show Joomla Debug Console if debug is active.
if (JDEBUG)
{
JProfiler::getInstance('Application')->mark('afterCache');
JEventDispatcher::getInstance()->trigger('onAfterRespond');
}
// Closes the application.
$this->app->close();
}
}
/**
* After Render Event.
* Verify if current page is not excluded from cache.
*
* @return void
*
* @since 3.9.12
*/
public function onAfterRender()
{
if ($this->_cache->getCaching() === false)
{
return;
}
// We need to check if user is guest again here, because auto-login plugins have not been fired before the first aid check.
// Page is excluded if excluded in plugin settings.
if (!JFactory::getUser()->guest || $this->app->getMessageQueue() || $this->isExcluded() === true)
{
$this->_cache->setCaching(false);
return;
}
// Disable compression before caching the page.
$this->app->set('gzip', false);
}
/**
* After Respond Event.
* Stores page in cache.
*
* @return void
*
* @since 1.5
*/
public function onAfterRespond()
{
if ($this->_cache->getCaching() === false)
{
return;
}
// Saves current page in cache.
$this->_cache->store($this->app->getBody(), $this->getCacheKey());
}
/**
* Check if the page is excluded from the cache or not.
*
* @return boolean True if the page is excluded else false
*
* @since 3.5
*/
protected function isExcluded()
{
// Check if menu items have been excluded.
if ($exclusions = $this->params->get('exclude_menu_items', array()))
{
// Get the current menu item.
$active = $this->app->getMenu()->getActive();
if ($active && $active->id && in_array((int) $active->id, (array) $exclusions))
{
return true;
}
}
// Check if regular expressions are being used.
if ($exclusions = $this->params->get('exclude', ''))
{
// Normalize line endings.
$exclusions = str_replace(array("\r\n", "\r"), "\n", $exclusions);
// Split them.
$exclusions = explode("\n", $exclusions);
// Gets internal URI.
$internal_uri = '/index.php?' . JUri::getInstance()->buildQuery($this->app->getRouter()->getVars());
// Loop through each pattern.
if ($exclusions)
{
foreach ($exclusions as $exclusion)
{
// Make sure the exclusion has some content
if ($exclusion !== '')
{
// Test both external and internal URI
if (preg_match('#' . $exclusion . '#i', $this->_cache_key . ' ' . $internal_uri, $match))
{
return true;
}
}
}
}
}
// If any pagecache plugins return true for onPageCacheIsExcluded, exclude.
JPluginHelper::importPlugin('pagecache');
$results = JEventDispatcher::getInstance()->trigger('onPageCacheIsExcluded');
return in_array(true, $results, true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="system" method="upgrade">
<name>plg_system_cache</name>
<author>Joomla! Project</author>
<creationDate>February 2007</creationDate>
<copyright>Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CACHE_XML_DESCRIPTION</description>
<files>
<filename plugin="cache">cache.php</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_system_cache.ini</language>
<language tag="en-GB">en-GB.plg_system_cache.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="browsercache"
type="radio"
label="PLG_CACHE_FIELD_BROWSERCACHE_LABEL"
description="PLG_CACHE_FIELD_BROWSERCACHE_DESC"
class="btn-group btn-group-yesno"
default="0"
filter="integer"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="exclude_menu_items"
type="menuitem"
label="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_LABEL"
description="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_DESC"
multiple="multiple"
filter="int_array"
/>
</fieldset>
<fieldset name="advanced">
<field
name="exclude"
type="textarea"
label="PLG_CACHE_FIELD_EXCLUDE_LABEL"
description="PLG_CACHE_FIELD_EXCLUDE_DESC"
class="input-xxlarge"
rows="15"
filter="raw"
/>
</fieldset>
</fields>
</config>
</extension>
<?php
N2Loader::importAll('libraries.cache.storage');
class N2Cache {
protected $group = '';
protected $isAccessible = false;
/** @var N2CacheStorage */
public $storage;
protected $_storageEngine = 'default';
/**
* @param string $engine
*
* @return N2CacheStorage
*/
public static function getStorage($engine = "default") {
static $storage = null;
if ($storage === null) {
$storage = array(
'filesystem' => new N2CacheStorageFilesystem(),
'database' => new N2CacheStorageDatabase()
);
}
if ($engine == 'default') {
if (defined('NEXTEND_CACHE_STORAGE')) {
return $storage[NEXTEND_CACHE_STORAGE];
}
return $storage['filesystem'];
}
return $storage[$engine];
}
public static function clearGroup($group) {
$storage = self::getStorage();
$storage->clear($group);
$storage->clear($group, 'web');
}
public function __construct($group, $isAccessible = false) {
$this->group = $group;
$this->isAccessible = $isAccessible;
$this->storage = self::getStorage($this->_storageEngine);
}
protected function clearCurrentGroup() {
$this->storage->clear($this->group, $this->getScope());
}
protected function getScope() {
if ($this->isAccessible) {
return 'web';
}
return 'notweb';
}
protected function exists($key) {
return $this->storage->exists($this->group, $key, $this->getScope());
}
protected function get($key) {
return $this->storage->get($this->group, $key, $this->getScope());
}
protected function set($key, $value) {
$this->storage->set($this->group, $key, $value, $this->getScope());
}
protected function getPath($key) {
return $this->storage->getPath($this->group, $key, $this->getScope());
}
protected function remove($key) {
return $this->storage->remove($this->group, $key, $this->getScope());
}
}
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheCombine extends N2Cache {
protected $files = array();
protected $inline = '';
protected $fileType = '';
protected $minify = false;
protected $options = array();
public function __construct($fileType, $minify = false, $options = array()) {
$this->fileType = $fileType;
$this->minify = $minify;
$this->options = $options;
$this->options['minify'] = $this->minify;
parent::__construct('combined', true);
}
public function add($file) {
if (!in_array($file, $this->files)) {
$this->files[] = $file;
}
}
public function addInline($text) {
$this->inline .= $text;
}
protected function getHash() {
$hash = '';
for ($i = 0; $i < count($this->files); $i++) {
$hash .= $this->files[$i] . filemtime($this->files[$i]);
}
if (!empty($this->inline)) {
$hash .= $this->inline;
}
return md5($hash . json_encode($this->options));
}
public function make() {
$hash = $this->getHash();
$fileName = $hash . '.' . $this->fileType;
if (!$this->exists($fileName)) {
$buffer = '';
for ($i = 0; $i < count($this->files); $i++) {
$buffer .= file_get_contents($this->files[$i]);
}
if ($this->minify !== false) {
$buffer = call_user_func($this->minify, $buffer);
}
$buffer .= $this->inline;
$this->set($fileName, $buffer);
}
return $this->getPath($fileName);
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheImage extends N2Cache {
protected $_storageEngine = 'filesystem';
protected function getScope() {
return 'image';
}
public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) {
if (!$hash) {
$hash = $this->generateHash($fileExtension, $callable, $parameters);
}
$keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME);
$fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '') . '.' . $fileExtension;
if (!$this->exists($fileName)) {
$this->set($fileName, call_user_func_array($callable, $parameters));
}
return $this->getPath($fileName);
}
private function generateHash($fileExtension, $callable, $parameters) {
return md5(json_encode(array(
$fileExtension,
$callable,
$parameters
)));
}
}
class N2StoreImage extends N2Cache {
protected $_storageEngine = 'filesystem';
protected function getScope() {
return 'image';
}
public function makeCache($fileName, $content) {
if (!$this->isImage($fileName)) {
return false;
}
if (!$this->exists($fileName)) {
$this->set($fileName, $content);
}
return $this->getPath($fileName);
}
private function isImage($fileName) {
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'mp4',
'mp3'
);
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (in_array($ext, $supported_image)) {
return true;
}
return false;
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.cache');
class N2CacheManifest extends N2Cache {
private $isRaw = false;
private $manifestData;
public function __construct($group, $isAccessible = false, $isRaw = false) {
parent::__construct($group, $isAccessible);
$this->isRaw = $isRaw;
}
public function makeCache($fileName, $hash, $callable) {
if (!$this->isCached($fileName, $hash)) {
$return = call_user_func($callable, $this);
if ($return === false) {
return false;
}
return $this->createCacheFile($fileName, $hash, $return);
}
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return json_decode($this->get($fileName), true);
}
private function isCached($fileName, $hash) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$this->manifestData = json_decode($this->get($manifestKey), true);
if (!$this->isCacheValid($this->manifestData) || $this->manifestData['hash'] != $hash) {
$this->clean($fileName);
return false;
}
return true;
}
return false;
}
protected function createCacheFile($fileName, $hash, $content) {
$this->manifestData = array();
$this->manifestData['hash'] = $hash;
$this->addManifestData($this->manifestData);
$this->set($this->getManifestKey($fileName), json_encode($this->manifestData));
$this->set($fileName, $this->isRaw ? $content : json_encode($content));
if ($this->isAccessible) {
return $this->getPath($fileName);
}
return $content;
}
protected function isCacheValid(&$manifestData) {
return true;
}
protected function addManifestData(&$manifestData) {
}
public function clean($fileName) {
$this->remove($this->getManifestKey($fileName));
$this->remove($fileName);
}
protected function getManifestKey($fileName) {
return $fileName . '.manifest';
}
public function getData($key, $default = 0) {
return isset($this->manifestData[$key]) ? $this->manifestData[$key] : $default;
}
}
\ No newline at end of file
<?php
abstract class N2CacheStorage {
protected $paths = array();
public function __construct() {
$this->paths['web'] = 'web';
$this->paths['notweb'] = 'notweb';
$this->paths['image'] = 'image';
}
public function isFilesystem() {
return false;
}
public abstract function clear($group, $scope = 'notweb');
public abstract function exists($group, $key, $scope = 'notweb');
public abstract function set($group, $key, $value, $scope = 'notweb');
public abstract function get($group, $key, $scope = 'notweb');
public abstract function remove($group, $key, $scope = 'notweb');
public abstract function getPath($group, $key, $scope = 'notweb');
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.storage.cachestorage');
class N2CacheStorageDatabase extends N2CacheStorage {
protected $db;
public function __construct() {
parent::__construct();
$this->db = new N2StorageSection('cache');
}
public function clear($group, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group);
}
public function exists($group, $key, $scope = 'notweb') {
if ($this->db->get($scope . '/' . $group, $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$this->db->set($scope . '/' . $group, $key, $value);
}
public function get($group, $key, $scope = 'notweb') {
return $this->db->get($scope . '/' . $group, $key);
}
public function remove($group, $key, $scope = 'notweb') {
$this->db->delete($scope . '/' . $group, $key);
}
public function getPath($group, $key, $scope = 'notweb') {
return N2Platform::getSiteUrl() . '?nextendcache=1&g=' . urlencode($group) . '&k=' . urlencode($key);
}
}
\ No newline at end of file
<?php
N2Loader::import('libraries.cache.storage.cachestorage');
class N2CacheStorageFilesystem extends N2CacheStorage {
public function __construct() {
$this->paths['web'] = N2Filesystem::getWebCachePath();
$this->paths['notweb'] = N2Filesystem::getNotWebCachePath();
$this->paths['image'] = N2Filesystem::getImagesFolder();
}
public function isFilesystem() {
return true;
}
public function clear($group, $scope = 'notweb') {
if (N2Filesystem::existsFolder($this->paths[$scope] . NDS . $group)) {
N2Filesystem::deleteFolder($this->paths[$scope] . NDS . $group);
}
}
public function exists($group, $key, $scope = 'notweb') {
if (N2Filesystem::existsFile($this->paths[$scope] . NDS . $group . NDS . $key)) {
return true;
}
return false;
}
public function set($group, $key, $value, $scope = 'notweb') {
$path = $this->paths[$scope] . NDS . $group . NDS . $key;
$dir = dirname($path);
if (!N2Filesystem::existsFolder($dir)) {
N2Filesystem::createFolder($dir);
}
N2Filesystem::createFile($path, $value);
}
public function get($group, $key, $scope = 'notweb') {
return N2Filesystem::readFile($this->paths[$scope] . NDS . $group . NDS . $key);
}
public function remove($group, $key, $scope = 'notweb') {
if ($this->exists($group, $key, $scope)) {
@unlink($this->paths[$scope] . NDS . $group . NDS . $key);
}
}
public function getPath($group, $key, $scope = 'notweb') {
return $this->paths[$scope] . NDS . $group . NDS . $key;
}
}
\ No newline at end of file
<?php
class N2CacheManifestGenerator extends N2CacheManifest
{
/**
* @var N2SmartSliderAbstract
*/
private $slider;
private $generator;
/**
* @param N2SmartSliderAbstract $slider
* @param N2SmartSliderSlidesGenerator $generator
*/
public function __construct($slider, $generator) {
parent::__construct($slider->cacheId, false);
$this->slider = $slider;
$this->generator = $generator;
}
protected function isCacheValid(&$manifestData) {
$nextRefresh = $manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60;
if ($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60 < N2Platform::getTime()) {
return false;
}
$this->generator->setNextCacheRefresh($nextRefresh);
return true;
}
protected function addManifestData(&$manifestData) {
$manifestData['cacheTime'] = N2Platform::getTime();
$this->generator->setNextCacheRefresh($manifestData['cacheTime'] + max(0, $this->generator->currentGenerator['params']->get('cache-expiration', 1)) * 60 * 60);
}
}
<?php
class N2CacheManifestSlider extends N2CacheManifest {
private $parameters = array();
private $isExtended = false;
public function __construct($cacheId, $parameters = array()) {
parent::__construct($cacheId, false);
$this->parameters = $parameters;
}
public function makeCache($fileName, $hash, $callable) {
$variations = 1;
if ($this->exists($this->getManifestKey('variations'))) {
$variations = intval($this->get($this->getManifestKey('variations')));
}
$fileName = $fileName . mt_rand(1, $variations);
if (N2SmartSliderSettings::get('serversidemobiledetect', '0') == '1') {
N2Loader::import('libraries.mobiledetect');
if (N2MobileDetect::$current['isMobile']) {
$fileName .= '-mobile';
} else if (N2MobileDetect::$current['isTablet']) {
$fileName .= '-tablet';
} else {
$fileName .= '-desktop';
}
}
if ($this->exists($this->getManifestKey('data'))) {
$data = json_decode($this->get($this->getManifestKey('data')), true);
$fileName = $this->extendFileName($fileName, $data);
} else {
$this->clearCurrentGroup();
}
$output = parent::makeCache($fileName, $hash, $callable);
return $output;
}
protected function createCacheFile($fileName, $hash, $content) {
$this->set($this->getManifestKey('data'), json_encode($this->parameters['slider']->manifestData));
$fileName = $this->extendFileName($fileName, $this->parameters['slider']->manifestData);
return parent::createCacheFile($fileName, $hash, $content);
}
private function extendFileName($fileName, $manifestData) {
if ($this->isExtended) {
return $fileName;
}
$this->isExtended = true;
$generators = $manifestData['generator'];
if (count($generators)) {
N2Loader::import("models.generator", "smartslider");
$generatorModel = new N2SmartsliderGeneratorModel();
foreach ($generators AS $generator) {
list($group, $type, $params) = $generator;
$info = $generatorModel->getGeneratorInfo($group, $type);
require_once($info->path . '/generator.php');
$class = 'N2Generator' . $group . $type;
$fileName .= call_user_func_array(array(
$class,
'cacheKey'
), $params);
}
}
return $fileName;
}
protected function isCacheValid(&$manifestData) {
if (!isset($manifestData['version']) || $manifestData['version'] != N2SS3::$version) {
return false;
}
if (N2SmartSliderHelper::getInstance()
->isSliderChanged($this->parameters['slider']->sliderId, 1)
) {
$this->clearCurrentGroup();
N2SmartSliderHelper::getInstance()
->setSliderChanged($this->parameters['slider']->sliderId, 0);
return false;
}
$time = N2Platform::getTime();
if ($manifestData['nextCacheRefresh'] < $time) {
return false;
}
if (!isset($manifestData['currentPath']) || $manifestData['currentPath'] != md5(__FILE__)) {
return false;
}
return true;
}
protected function addManifestData(&$manifestData) {
$manifestData['nextCacheRefresh'] = N2Pluggable::applyFilters('SSNextCacheRefresh', $this->parameters['slider']->getNextCacheRefresh(), array($this->parameters['slider']));
$manifestData['currentPath'] = md5(__FILE__);
$manifestData['version'] = N2SS3::$version;
$variations = 1;
$params = $this->parameters['slider']->params;
if (!$params->get('randomize-cache', 0) && ($params->get('randomize', 0) || $params->get('randomizeFirst', 0))) {
$variations = intval($params->get('variations', 5));
if ($variations < 1) {
$variations = 1;
}
}
$this->set($this->getManifestKey('variations'), $variations);
}
}
\ 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!