34
0
plg_extension_componentbuil.../componentbuilderpowersautoloadercompiler.php

115 lines
3.2 KiB
PHP
Raw Normal View History

2021-12-03 02:46:29 +00:00
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
2022-08-20 16:38:51 +00:00
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
2021-12-03 02:46:29 +00:00
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Plugin\CMSPlugin;
2023-10-18 07:28:04 +00:00
use Joomla\Registry\Registry;
use VDM\Joomla\Utilities\ArrayHelper;
2021-12-03 02:46:29 +00:00
JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php');
2023-02-05 21:57:58 +00:00
use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory;
2021-12-03 02:46:29 +00:00
/**
* Extension - Componentbuilder Powers Autoloader Compiler plugin.
*
* @package ComponentbuilderPowersAutoloaderCompiler
2023-10-18 07:28:04 +00:00
* @since 1.1.1
2021-12-03 02:46:29 +00:00
*/
class PlgExtensionComponentbuilderPowersAutoloaderCompiler extends CMSPlugin
{
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
* @since 1.0.0
*/
protected $autoloadLanguage = true;
/**
* Event Triggered in the compiler [on After Get]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onAfterGet(&$context, $compiler)
{
// check if this component needs a power autoloader plugin loaded
2022-10-23 21:15:15 +00:00
if ($compiler->addPower && $this->componentActive($context) && ComponentbuilderHelper::checkArray($compiler->linkedPowers))
2021-12-03 02:46:29 +00:00
{
// now get the plugin ID if set
if (($id = (int) $this->params->get('plugin', 0)) !== 0)
{
// load the power autoloader plugin
2023-02-05 21:57:58 +00:00
CFactory::_('Joomlaplugin.Data')->set($id);
2021-12-03 02:46:29 +00:00
// now set the plugin powers placeholder
2023-10-18 07:28:04 +00:00
CFactory::_('Compiler.Builder.Content.One')->set('PLUGIN_POWER_AUTOLOADER', '');
2021-12-03 02:46:29 +00:00
}
else
{
2022-05-09 12:26:07 +00:00
JFactory::getApplication()->enqueueMessage(JText::_('PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_YOU_DO_NOT_HAVE_A_GLOBAL_POWER_PLUGIN_SETUP_SO_THE_POWERS_PLUGIN_AUTOLOADER_COULD_NOT_BE_ADDED'), 'Error');
2021-12-03 02:46:29 +00:00
}
}
}
/**
* The array of active components
*
* @var array
*/
protected $componentsActive;
/**
* The activate option
*
* @var int
*/
protected $activateOption = 0;
/**
* Set the line number in comments
*
* @param string $context The context of the current executing component
*
* @return bool
*
*/
protected function componentActive(&$context)
{
// check the active option
if (!$this->activateOption)
{
$this->activateOption = $this->params->get('activate_option', 1);
}
// active for all components
if ($this->activateOption == 1)
{
return true;
}
// first check is we have the active components set
2023-10-18 07:28:04 +00:00
if ($this->activateOption == 2 && !ArrayHelper::check($this->componentsActive))
2021-12-03 02:46:29 +00:00
{
$this->componentsActive = $this->params->get('components');
}
// only check if there are active
2023-10-18 07:28:04 +00:00
if (ArrayHelper::check($this->componentsActive))
2021-12-03 02:46:29 +00:00
{
return in_array((int) filter_var($context, FILTER_SANITIZE_NUMBER_INT), $this->componentsActive);
}
return false;
}
}