Files
conservatorio-tomadini/plugins/system/conditionalcontent/conditionalcontent.php
2024-12-17 17:34:10 +01:00

126 lines
3.6 KiB
PHP

<?php
/**
* @package Conditional Content
* @version 5.2.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Language\Text as JText;
use RegularLabs\Library\Document as RL_Document;
use RegularLabs\Library\Extension as RL_Extension;
use RegularLabs\Library\Html as RL_Html;
use RegularLabs\Library\SystemPlugin as RL_SystemPlugin;
use RegularLabs\Plugin\System\ConditionalContent\Params;
use RegularLabs\Plugin\System\ConditionalContent\Protect;
use RegularLabs\Plugin\System\ConditionalContent\Replace;
// Do not instantiate plugin on install pages
// to prevent installation/update breaking because of potential breaking changes
if (
in_array(JFactory::getApplication()->input->getCmd('option'), ['com_installer', 'com_regularlabsmanager'])
&& JFactory::getApplication()->input->getCmd('action') != ''
)
{
return;
}
if ( ! is_file(JPATH_LIBRARIES . '/regularlabs/regularlabs.xml')
|| ! class_exists('RegularLabs\Library\Parameters')
|| ! class_exists('RegularLabs\Library\DownloadKey')
|| ! class_exists('RegularLabs\Library\SystemPlugin')
)
{
JFactory::getApplication()->getLanguage()->load('plg_system_conditionalcontent', __DIR__);
JFactory::getApplication()->enqueueMessage(
JText::sprintf('AA_EXTENSION_CAN_NOT_FUNCTION', JText::_('CONDITIONALCONTENT'))
. ' ' . JText::_('AA_REGULAR_LABS_LIBRARY_NOT_INSTALLED'),
'error'
);
return;
}
if ( ! RL_Document::isJoomlaVersion(4, 'CONDITIONALCONTENT'))
{
RL_Extension::disable('conditionalcontent', 'plugin');
RL_Document::adminError(
JText::sprintf('RL_PLUGIN_HAS_BEEN_DISABLED', JText::_('CONDITIONALCONTENT'))
);
return;
}
if (true)
{
class PlgSystemConditionalContent extends RL_SystemPlugin
{
public $_lang_prefix = 'COC';
public $_can_disable_by_url = false;
public $_jversion = 4;
public $_enable_in_admin = true;
public function __construct(&$subject, $config = [])
{
parent::__construct($subject, $config);
$params = Params::get();
$this->_enable_in_admin = $params->enable_admin;
}
public function processArticle(
&$string,
$area = 'article',
$context = '',
$article = null,
$page = 0
)
{
Replace::replaceTags($string, $area, $context, $article);
}
/**
* @param object $module
* @param array $params
*/
protected function handleOnAfterRenderModule(&$module, &$params): void
{
if ( ! isset($module->content))
{
return;
}
Replace::replaceTags($module->content, 'module');
}
protected function changeDocumentBuffer(&$buffer)
{
return Replace::replaceTags($buffer, 'component');
}
protected function changeFinalHtmlOutput(&$html)
{
// only do stuff in body
[$pre, $body, $post] = RL_Html::getBody($html);
Replace::replaceTags($body, 'body');
$html = $pre . $body . $post;
return true;
}
protected function cleanFinalHtmlOutput(&$html)
{
Protect::unprotectTags($html);
//RL_Protect::removeInlineComments($html, 'ConditionalContent');
}
}
}