first commit
This commit is contained in:
4
plugins/system/jchoptimize/fields/index.html
Normal file
4
plugins/system/jchoptimize/fields/index.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
90
plugins/system/jchoptimize/fields/jchdescription.php
Normal file
90
plugins/system/jchoptimize/fields/jchdescription.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JCH Optimize - Performs several front-end optimizations for fast downloads
|
||||
*
|
||||
* @package jchoptimize/joomla-platform
|
||||
* @author Samuel Marshall <samuel@jch-optimize.net>
|
||||
* @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize
|
||||
* @license GNU/GPLv3, or later. See LICENSE file
|
||||
*
|
||||
* If LICENSE file missing, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('No direct access');
|
||||
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_jchoptimize/version.php';
|
||||
|
||||
class JFormFieldJchdescription extends JFormField
|
||||
{
|
||||
|
||||
public $type = 'jchdescription';
|
||||
|
||||
protected function getLabel()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$attributes = $this->element->attributes();
|
||||
|
||||
$html = '';
|
||||
|
||||
switch ($attributes['section'])
|
||||
{
|
||||
case 'features':
|
||||
$header = JText::_('JCH_HEADER_MAJOR_FEATURES');
|
||||
$pro_only = ' <small class="label label-important small" style="padding: 1px 3px;"><em>' . JText::_('JCH_FEATURES_PRO_ONLY') . '</em></small>';
|
||||
$description = '<ul>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_COMBINE_FILES') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_AUTO_SETTINGS') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_SPRITE_GENERATOR') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_IMAGE_ATTRIBUTES') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_CRITICAL_CSS') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_LAZY_LOAD') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_CDN') . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_PRO_CDN') . $pro_only . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_PRO_HTTP2') . $pro_only . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_PRO_REMOVE_UNUSED_CSS') . $pro_only . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_PRO_LAZY_LOAD') . $pro_only . '</li>'
|
||||
. '<li>' . JText::_('JCH_FEATURES_PRO_OPTIMIZE_IMAGES') . $pro_only . '</li>'
|
||||
. '</ul>';
|
||||
|
||||
break;
|
||||
case 'support':
|
||||
$header = JText::_('JCH_HEADER_SUPPORT');
|
||||
$description = '<p>' . JText::sprintf('JCH_SUPPORT_DOCUMENTATION', 'https://www.jch-optimize.net/documentation.html') . '</p>'
|
||||
. '<p>' . JText::sprintf('JCH_SUPPORT_REQUESTS', 'https://www.jch-optimize.net/subscribe/levels.html') . '</p>';
|
||||
|
||||
break;
|
||||
|
||||
case 'feedback':
|
||||
$header = JText::_('JCH_HEADER_FEEDBACK');
|
||||
$description = '<p>' . JText::sprintf('JCH_FEEDBACK_DESCRIPTION', 'https://extensions.joomla.org/extension/core-enhancements/performance/jch-optimize/') . '</p>';
|
||||
break;
|
||||
|
||||
case 'version':
|
||||
$header = '';
|
||||
$description = '<h4>(Version ' . JCH_VERSION . ')</h4>'/* ##<freecode>##
|
||||
. '<br />'
|
||||
. '<p class="alert alert-info alert-block">Upgrade to the pro version now using coupon code JCHGOPRO20 for a 20% discount!!</p>' ##<freecode>## */;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$html .= '</div></div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= $header == '' ? '' : '<h3>' . $header . '</h3>';
|
||||
$html .= $description;
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div><div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
4
plugins/system/jchoptimize/index.html
Normal file
4
plugins/system/jchoptimize/index.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
264
plugins/system/jchoptimize/jchoptimize.php
Normal file
264
plugins/system/jchoptimize/jchoptimize.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JCH Optimize - Performs several front-end optimizations for fast downloads
|
||||
*
|
||||
* @package jchoptimize/joomla-platform
|
||||
* @author Samuel Marshall <samuel@jch-optimize.net>
|
||||
* @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize
|
||||
* @license GNU/GPLv3, or later. See LICENSE file
|
||||
*
|
||||
* If LICENSE file missing, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use JchOptimize\ContainerFactory;
|
||||
use JchOptimize\Core\Container\Container;
|
||||
use JchOptimize\Core\Helper;
|
||||
use JchOptimize\Core\Optimize;
|
||||
use JchOptimize\Core\SystemUri;
|
||||
use JchOptimize\Model\Cache;
|
||||
use Joomla\CMS\Application\CMSApplicationInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
if (!defined('JCH_PLUGIN_DIR')) {
|
||||
define('JCH_PLUGIN_DIR', dirname(__FILE__));
|
||||
}
|
||||
|
||||
include_once JPATH_ADMINISTRATOR . '/components/com_jchoptimize/autoload.php';
|
||||
|
||||
class plgSystemJchoptimize extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* If plugin is enabled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public bool $enabled = true;
|
||||
|
||||
/**
|
||||
* Component parameters
|
||||
*
|
||||
* @var Registry
|
||||
*/
|
||||
protected Registry $comParams;
|
||||
|
||||
/**
|
||||
* Application object
|
||||
*
|
||||
* @var ?CMSApplicationInterface
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Container object
|
||||
*
|
||||
* @var Container
|
||||
*/
|
||||
private Container $container;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $subject
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct(&$subject, $config)
|
||||
{
|
||||
parent::__construct($subject, $config);
|
||||
|
||||
// Disable if the component is not installed or disabled
|
||||
if (!ComponentHelper::isEnabled('com_jchoptimize')) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if we cannot initialize application
|
||||
try {
|
||||
$this->app = Factory::getApplication();
|
||||
} catch (Exception $e) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if we can't get component's container
|
||||
try {
|
||||
$this->container = ContainerFactory::getContainer();
|
||||
} catch (Exception $e) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if not on front end
|
||||
if (!$this->app->isClient('site')) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if jchnooptimize set
|
||||
if ($this->app->input->get('jchnooptimize', '', 'int') == 1) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if site offline and user is guest
|
||||
$user = Factory::getUser();
|
||||
|
||||
if ($this->app->get('offline', '0') && $user->get('guest')) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Get and set component's parameters
|
||||
$this->comParams = $this->container->get('params');
|
||||
|
||||
if (!defined('JCH_DEBUG')) {
|
||||
define('JCH_DEBUG', ($this->comParams->get('debug', 0) && JDEBUG));
|
||||
}
|
||||
|
||||
if ($this->comParams->get('disable_logged_in_users', '1') && !$user->get('guest')) {
|
||||
$this->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function onAfterRoute()
|
||||
{
|
||||
//If already disabled return
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
//Disable if in iframe
|
||||
if ($this->app->input->server->getString('HTTP_SEC_FETCH_DEST') == 'iframe') {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if menu or page excluded
|
||||
$menuexcluded = $this->comParams->get('menuexcluded', array());
|
||||
$menuexcludedurl = $this->comParams->get('menuexcludedurl', array());
|
||||
|
||||
if (in_array($this->app->input->get('Itemid', '', 'int'), $menuexcluded) ||
|
||||
Helper::findExcludes($menuexcludedurl, SystemUri::toString())) {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Disable if page being edited
|
||||
if ($this->app->input->get('layout') == 'edit') {
|
||||
$this->enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onAfterRender()
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->comParams->get('debug', 0)) {
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
}
|
||||
|
||||
$html = $this->app->getBody();
|
||||
|
||||
//Html invalid
|
||||
if (!Helper::validateHtml($html)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->app->input->get('jchbackend') == '1'
|
||||
|| $this->app->input->get('jchnooptimize' == '1')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->app->input->get('jchbackend') == '2') {
|
||||
echo $html;
|
||||
while (@ob_end_flush()) {
|
||||
;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var Optimize $optimize */
|
||||
$optimize = $this->container->get(Optimize::class);
|
||||
$optimize->setHtml($html);
|
||||
|
||||
$sOptimizedHtml = $optimize->process();
|
||||
} catch (Exception $e) {
|
||||
$logger = $this->container->get(LoggerInterface::class);
|
||||
$logger->error($e->getMessage());
|
||||
|
||||
$sOptimizedHtml = $html;
|
||||
}
|
||||
|
||||
$this->app->setBody($sOptimizedHtml);
|
||||
}
|
||||
|
||||
public function onJchCacheExpired()
|
||||
{
|
||||
/** @var Cache $cacheModel
|
||||
*/
|
||||
$cacheModel = $this->container->get(Cache::class);
|
||||
|
||||
return $cacheModel->cleanCache();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function onAfterDispatch()
|
||||
{
|
||||
//If already disabled return false
|
||||
if (!$this->enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Disable if editor loaded
|
||||
if ($this->isEditorLoaded()) {
|
||||
$this->enabled = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the current Editor
|
||||
*
|
||||
* @staticvar string $sEditor
|
||||
* @return bool
|
||||
*/
|
||||
protected function isEditorLoaded(): bool
|
||||
{
|
||||
$aEditors = PluginHelper::getPlugin('editors');
|
||||
|
||||
foreach ($aEditors as $sEditor) {
|
||||
if (class_exists('plgEditor' . $sEditor->name, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
plugins/system/jchoptimize/jchoptimize.xml
Normal file
21
plugins/system/jchoptimize/jchoptimize.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="plugin" group="system" method="upgrade">
|
||||
<name>plg_system_jchoptimize</name>
|
||||
<author>Samuel Marshall</author>
|
||||
<creationDate>2023-08-09</creationDate>
|
||||
<copyright>Copyright (C) 2023 Samuel Marshall. All rights reserved.</copyright>
|
||||
<license>GNU/GPLv3 http://www.gnu.org/copyleft/gpl.html</license>
|
||||
<authorEmail>samuel@jch-optimize.net</authorEmail>
|
||||
<authorUrl>http://www.jch-optimize.net</authorUrl>
|
||||
<version>8.0.6</version>
|
||||
<description>PLG_SYSTEM_JCHOPTIMIZE_DESCRIPTION</description>
|
||||
<files>
|
||||
<filename plugin="jchoptimize">jchoptimize.php</filename>
|
||||
<filename>index.html</filename>
|
||||
<folder>fields</folder>
|
||||
</files>
|
||||
<languages folder="language">
|
||||
<language tag="en-GB">en-GB/en-GB.plg_system_jchoptimize.ini</language>
|
||||
<language tag="en-GB">en-GB/en-GB.plg_system_jchoptimize.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
Reference in New Issue
Block a user