2021-10-14 14:31:41 +00:00
|
|
|
<?php
|
2021-12-03 02:46:17 +00:00
|
|
|
/**
|
|
|
|
* @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:17 +00:00
|
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2021-10-14 14:31:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
use Joomla\CMS\Application\CMSApplication;
|
|
|
|
use Joomla\CMS\Plugin\CMSPlugin;
|
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
|
|
|
|
JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extension - Componentbuilder Headers Compiler plugin.
|
|
|
|
*
|
|
|
|
* @package ComponentbuilderHeadersCompiler
|
2022-09-20 11:36:38 +00:00
|
|
|
* @since 2.1.1
|
2021-10-14 14:31:41 +00:00
|
|
|
*/
|
|
|
|
class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
|
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
/**
|
2021-10-14 14:31:59 +00:00
|
|
|
* Global switch to see if a file has custom headers.
|
2021-10-14 14:31:41 +00:00
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
protected $loadHeaders = false;
|
2021-10-14 14:31:41 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-08 20:42:13 +00:00
|
|
|
* The active headers
|
2021-10-14 14:31:41 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2021-12-08 20:42:13 +00:00
|
|
|
* @since 1.0.8
|
2021-10-14 14:31:41 +00:00
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
protected $activeHeaders = array();
|
2021-10-14 14:31:41 +00:00
|
|
|
|
2021-12-03 02:46:17 +00:00
|
|
|
/**
|
|
|
|
* The compiler placeholders values
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 1.0.6
|
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
protected $placeholders = array();
|
2021-12-03 02:46:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The powers to include in project
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 1.0.6
|
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
protected $linkedPowers = array();
|
2021-12-03 02:46:17 +00:00
|
|
|
|
2021-10-14 14:31:41 +00:00
|
|
|
/**
|
|
|
|
* The Targets
|
|
|
|
*
|
|
|
|
* @var array
|
2021-12-08 20:42:13 +00:00
|
|
|
* @since 1.0.8
|
2021-10-14 14:31:41 +00:00
|
|
|
*/
|
2021-10-14 14:31:46 +00:00
|
|
|
protected $targets = array(
|
2021-12-08 20:42:13 +00:00
|
|
|
'admin_view_headers' =>
|
2021-10-14 14:31:46 +00:00
|
|
|
array(
|
|
|
|
'add_admin_view_model' => array(
|
|
|
|
'field' => 'admin_view_model',
|
|
|
|
'context' => 'admin.view.model',
|
|
|
|
'view' => 'name_single'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_admin_view' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'admin_view',
|
|
|
|
'context' => 'admin.view',
|
|
|
|
'view' => 'name_single'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_admin_view_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'admin_view_html',
|
|
|
|
'context' => 'admin.view.html',
|
|
|
|
'view' => 'name_single'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_admin_view_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'site_admin_view_html',
|
|
|
|
'context' => 'site.admin.view.html',
|
|
|
|
'view' => 'name_single'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_admin_view_controller' => array(
|
|
|
|
'field' => 'admin_view_controller',
|
|
|
|
'context' => 'admin.view.controller',
|
|
|
|
'view' => 'name_single'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_ajax_model' => array(
|
|
|
|
'field' => 'ajax_model',
|
|
|
|
'context' => 'ajax.admin.model',
|
|
|
|
'view' => 'ajax'
|
|
|
|
),
|
2021-10-14 14:31:46 +00:00
|
|
|
'add_admin_views_model' => array(
|
|
|
|
'field' => 'admin_views_model',
|
|
|
|
'context' => 'admin.views.model',
|
|
|
|
'view' => 'name_list'
|
2021-10-14 14:32:05 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_admin_views' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'admin_views',
|
|
|
|
'context' => 'admin.views',
|
|
|
|
'view' => 'name_list'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_admin_views_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'admin_views_html',
|
|
|
|
'context' => 'admin.views.html',
|
|
|
|
'view' => 'name_list'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_admin_views_controller' => array(
|
|
|
|
'field' => 'admin_views_controller',
|
|
|
|
'context' => 'admin.views.controller',
|
|
|
|
'view' => 'name_list'
|
2021-10-14 14:31:46 +00:00
|
|
|
)
|
2021-10-14 14:31:41 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'site_view_headers' =>
|
2021-10-14 14:31:46 +00:00
|
|
|
array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_site_view_model' => array(
|
|
|
|
'field' => 'site_view_model',
|
|
|
|
'context' => 'site.view.model',
|
2021-10-14 14:31:46 +00:00
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_view' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'site_view',
|
|
|
|
'context' => 'site.view',
|
2021-10-14 14:31:46 +00:00
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_view_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'site_view_html',
|
|
|
|
'context' => 'site.view.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_site_view_controller' => array(
|
|
|
|
'field' => 'site_view_controller',
|
|
|
|
'context' => 'site.view.controller',
|
2021-10-14 14:31:46 +00:00
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_views_model' => array(
|
|
|
|
'field' => 'site_views_model',
|
|
|
|
'context' => 'site.views.model',
|
|
|
|
'view' => 'code'
|
2021-10-14 14:32:05 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_views' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'site_views',
|
|
|
|
'context' => 'site.views',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_views_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'site_views_html',
|
|
|
|
'context' => 'site.views.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_site_views_controller' => array(
|
|
|
|
'field' => 'site_views_controller',
|
|
|
|
'context' => 'site.views.controller',
|
|
|
|
'view' => 'code'
|
2021-12-08 20:42:13 +00:00
|
|
|
),
|
|
|
|
'add_ajax_model' => array(
|
|
|
|
'field' => 'ajax_model',
|
|
|
|
'context' => 'ajax.site.model',
|
|
|
|
'view' => 'ajax'
|
2021-10-14 14:31:46 +00:00
|
|
|
)
|
2021-10-14 14:31:53 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'custom_admin_view_headers' =>
|
2021-10-14 14:31:53 +00:00
|
|
|
array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_custom_admin_view_model' => array(
|
|
|
|
'field' => 'custom_admin_view_model',
|
|
|
|
'context' => 'custom.admin.view.model',
|
2021-10-14 14:31:53 +00:00
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_custom_admin_view' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'custom_admin_view',
|
|
|
|
'context' => 'custom.admin.view',
|
2021-10-14 14:31:53 +00:00
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_custom_admin_view_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'custom_admin_view_html',
|
|
|
|
'context' => 'custom.admin.view.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_custom_admin_view_controller' => array(
|
|
|
|
'field' => 'custom_admin_view_controller',
|
|
|
|
'context' => 'custom.admin.view.controller',
|
2021-10-14 14:31:53 +00:00
|
|
|
'view' => 'code'
|
2022-01-10 14:13:13 +00:00
|
|
|
),
|
|
|
|
'add_custom_admin_views_model' => array(
|
|
|
|
'field' => 'custom_admin_views_model',
|
|
|
|
'context' => 'custom.admin.views.model',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_views' => array(
|
|
|
|
'field' => 'custom_admin_views',
|
|
|
|
'context' => 'custom.admin.views',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_views_html' => array(
|
|
|
|
'field' => 'custom_admin_views_html',
|
|
|
|
'context' => 'custom.admin.views.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_views_controller' => array(
|
|
|
|
'field' => 'custom_admin_views_controller',
|
|
|
|
'context' => 'custom.admin.views.controller',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_ajax_model' => array(
|
|
|
|
'field' => 'ajax_model',
|
|
|
|
'context' => 'ajax.admin.model',
|
|
|
|
'view' => 'ajax'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'dynamic_get_headers' =>
|
|
|
|
array(
|
|
|
|
'add_site_view_model' => array(
|
|
|
|
'field' => 'site_view_model',
|
|
|
|
'context' => 'site.view.model',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_view' => array(
|
|
|
|
'field' => 'site_view',
|
|
|
|
'context' => 'site.view',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_view_html' => array(
|
|
|
|
'field' => 'site_view_html',
|
|
|
|
'context' => 'site.view.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_view_controller' => array(
|
|
|
|
'field' => 'site_view_controller',
|
|
|
|
'context' => 'site.view.controller',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_views_model' => array(
|
|
|
|
'field' => 'site_views_model',
|
|
|
|
'context' => 'site.views.model',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_views' => array(
|
|
|
|
'field' => 'site_views',
|
|
|
|
'context' => 'site.views',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_views_html' => array(
|
|
|
|
'field' => 'site_views_html',
|
|
|
|
'context' => 'site.views.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_site_views_controller' => array(
|
|
|
|
'field' => 'site_views_controller',
|
|
|
|
'context' => 'site.views.controller',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_view_model' => array(
|
|
|
|
'field' => 'custom_admin_view_model',
|
|
|
|
'context' => 'custom.admin.view.model',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_view' => array(
|
|
|
|
'field' => 'custom_admin_view',
|
|
|
|
'context' => 'custom.admin.view',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_view_html' => array(
|
|
|
|
'field' => 'custom_admin_view_html',
|
|
|
|
'context' => 'custom.admin.view.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
|
|
|
'add_custom_admin_view_controller' => array(
|
|
|
|
'field' => 'custom_admin_view_controller',
|
|
|
|
'context' => 'custom.admin.view.controller',
|
|
|
|
'view' => 'code'
|
2021-10-14 14:31:53 +00:00
|
|
|
),
|
|
|
|
'add_custom_admin_views_model' => array(
|
|
|
|
'field' => 'custom_admin_views_model',
|
|
|
|
'context' => 'custom.admin.views.model',
|
|
|
|
'view' => 'code'
|
2021-10-14 14:32:05 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_custom_admin_views' => array(
|
2021-10-14 14:32:05 +00:00
|
|
|
'field' => 'custom_admin_views',
|
|
|
|
'context' => 'custom.admin.views',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_custom_admin_views_html' => array(
|
2021-12-03 02:46:17 +00:00
|
|
|
'field' => 'custom_admin_views_html',
|
|
|
|
'context' => 'custom.admin.views.html',
|
|
|
|
'view' => 'code'
|
|
|
|
),
|
2021-10-14 14:32:05 +00:00
|
|
|
'add_custom_admin_views_controller' => array(
|
|
|
|
'field' => 'custom_admin_views_controller',
|
|
|
|
'context' => 'custom.admin.views.controller',
|
|
|
|
'view' => 'code'
|
2021-12-08 20:42:13 +00:00
|
|
|
),
|
|
|
|
'add_ajax_model' => array(
|
|
|
|
'field' => 'ajax_model',
|
|
|
|
'context' => 'ajax.admin.model',
|
|
|
|
'view' => 'ajax'
|
2021-10-14 14:31:53 +00:00
|
|
|
)
|
2021-10-14 14:31:59 +00:00
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'component_dashboard_headers' =>
|
2021-10-14 14:31:59 +00:00
|
|
|
array(
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_dashboard_model' => array(
|
|
|
|
'field' => 'dashboard_model',
|
|
|
|
'context' => 'dashboard.model',
|
|
|
|
'view' => 'dashboard'
|
|
|
|
),
|
|
|
|
'add_dashboard_view' => array(
|
|
|
|
'field' => 'dashboard_view',
|
|
|
|
'context' => 'dashboard.view',
|
|
|
|
'view' => 'dashboard'
|
|
|
|
),
|
|
|
|
'add_dashboard_view_html' => array(
|
|
|
|
'field' => 'dashboard_view_html',
|
|
|
|
'context' => 'dashboard.view.html',
|
|
|
|
'view' => 'dashboard'
|
|
|
|
),
|
|
|
|
'add_dashboard_controller' => array(
|
|
|
|
'field' => 'dashboard_controller',
|
|
|
|
'context' => 'dashboard.controller',
|
|
|
|
'view' => 'dashboard'
|
|
|
|
),
|
|
|
|
'add_ajax_model' => array(
|
|
|
|
'field' => 'ajax_model',
|
|
|
|
'context' => 'ajax.admin.model',
|
|
|
|
'view' => 'ajax'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'joomla_component_headers' =>
|
|
|
|
array(
|
|
|
|
'add_admin_component' => array(
|
2021-10-14 14:31:59 +00:00
|
|
|
'field' => 'admin_component',
|
|
|
|
'context' => 'admin.component',
|
|
|
|
'view' => 'admin'
|
|
|
|
),
|
|
|
|
'add_site_component' => array(
|
|
|
|
'field' => 'site_component',
|
|
|
|
'context' => 'site.component',
|
|
|
|
'view' => 'site'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_admin_helper' => array(
|
2021-10-14 14:31:59 +00:00
|
|
|
'field' => 'admin_helper',
|
|
|
|
'context' => 'admin.helper',
|
|
|
|
'view' => 'admin'
|
|
|
|
),
|
2021-12-08 20:42:13 +00:00
|
|
|
'add_site_helper' => array(
|
2021-10-14 14:31:59 +00:00
|
|
|
'field' => 'site_helper',
|
|
|
|
'context' => 'site.helper',
|
|
|
|
'view' => 'site'
|
|
|
|
)
|
2021-10-14 14:31:41 +00:00
|
|
|
)
|
2021-12-08 20:42:13 +00:00
|
|
|
);
|
2021-10-14 14:31:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on Before Model View Data]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
public function jcb_ce_onBeforeModelViewData(&$context, &$view, &$placeholders)
|
|
|
|
{
|
|
|
|
// check that the params are set
|
|
|
|
if (isset($view->params))
|
2021-10-14 14:31:46 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// add the headers for the Admin Views
|
|
|
|
$this->setHeaders($view->params, $view, 'admin_view_headers');
|
2021-10-14 14:31:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on Before Model Custom View Data]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2021-12-08 20:42:13 +00:00
|
|
|
* @since 1.0.2
|
2021-10-14 14:31:46 +00:00
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
public function jcb_ce_onBeforeModelCustomViewData(&$context, &$view, &$id, &$table)
|
|
|
|
{
|
|
|
|
// check that the params are set
|
|
|
|
if (isset($view->params))
|
2021-10-14 14:31:41 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// add the headers for the Site Views
|
|
|
|
$this->setHeaders($view->params, $view, 'site_view_headers');
|
|
|
|
// add the headers for the Custom Admin Views
|
|
|
|
$this->setHeaders($view->params, $view, 'custom_admin_view_headers');
|
2021-10-14 14:31:41 +00:00
|
|
|
}
|
2021-12-08 20:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 14:47:57 +00:00
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on Before Model Dynamic Get Data]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0.10
|
|
|
|
*/
|
|
|
|
public function jcb_ce_onBeforeModelDynamicGetData(&$context, &$dynamicGet, &$id, &$code, &$area)
|
|
|
|
{
|
|
|
|
// check that the params are set
|
|
|
|
if (isset($dynamicGet->params))
|
|
|
|
{
|
|
|
|
// add the headers for the Site Views
|
|
|
|
$this->setDynamicHeaders($dynamicGet->params, $code, 'dynamic_get_headers');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 20:42:13 +00:00
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on Before Model Component Data]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0.4
|
|
|
|
*/
|
|
|
|
public function jcb_ce_onBeforeModelComponentData(&$context, &$component)
|
|
|
|
{
|
|
|
|
// check that the params are set
|
|
|
|
if (isset($component->params))
|
|
|
|
{
|
|
|
|
// add the headers for the Joomla Component
|
|
|
|
$this->setHeaders($component->params, $component, 'joomla_component_headers');
|
|
|
|
}
|
|
|
|
// check that the dashboard params are set
|
|
|
|
if (isset($component->dashboard_params))
|
|
|
|
{
|
|
|
|
// add the headers for the Component Dashboard
|
|
|
|
$this->setHeaders($component->dashboard_params, $component, 'component_dashboard_headers');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on set Class Header]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
|
|
|
public function jcb_ce_setClassHeader(&$context, &$event_context, &$view_name, &$headers)
|
|
|
|
{
|
|
|
|
if ($this->loadHeaders && isset($this->activeHeaders[$view_name])
|
|
|
|
&& isset($this->activeHeaders[$view_name][$event_context]))
|
2021-10-14 14:31:53 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// we have default headers we actually need
|
|
|
|
foreach ($headers as $n => $header)
|
2021-10-14 14:31:53 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// if an empty line is found just skip it
|
|
|
|
if (empty($header))
|
2021-10-14 14:31:53 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// we check if this header is also set from the user
|
|
|
|
if (isset($this->activeHeaders[$view_name][$event_context]) && strpos(
|
|
|
|
$this->activeHeaders[$view_name][$event_context], $header
|
|
|
|
) !== false)
|
|
|
|
{
|
|
|
|
// since it is set, remove it here
|
|
|
|
unset($headers[$n]);
|
2021-10-14 14:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 20:42:13 +00:00
|
|
|
// now add the custom headers
|
|
|
|
// yes they are below the defaults, unless overridden and removed above
|
|
|
|
$headers[] = $this->activeHeaders[$view_name][$event_context];
|
2021-10-14 14:31:53 +00:00
|
|
|
}
|
2021-10-14 14:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-08 20:42:13 +00:00
|
|
|
* Event Triggered in the compiler [on Before Get Component Data]
|
2021-10-14 14:31:59 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2021-12-08 20:42:13 +00:00
|
|
|
* @since 1.0.6
|
2021-10-14 14:31:59 +00:00
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
public function jcb_ce_onBeforeGetComponentData(&$context, $compiler)
|
|
|
|
{
|
|
|
|
// get placeholders from the compiler
|
|
|
|
$this->placeholders = $compiler->globalPlaceholders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Triggered in the compiler [on After Get Component Data]
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0.6
|
|
|
|
*/
|
|
|
|
public function jcb_ce_onAfterGetComponentData(&$context, $compiler)
|
|
|
|
{
|
|
|
|
// add the powers to the component
|
|
|
|
if (ComponentbuilderHelper::checkArray($this->linkedPowers, true))
|
|
|
|
{
|
|
|
|
$compiler->linkedPowers = $this->linkedPowers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the headers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0.8
|
|
|
|
*/
|
|
|
|
protected function setHeaders(&$params, &$obj, $key)
|
2021-10-14 14:31:59 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// add the headers
|
|
|
|
$params = (ComponentbuilderHelper::checkJson($params)) ? json_decode($params, true) : $params;
|
|
|
|
// make sure we have the keys values in the params area
|
|
|
|
if (ComponentbuilderHelper::checkArray($params) && isset($params[$key])
|
|
|
|
&& ComponentbuilderHelper::checkArray($params[$key]))
|
2021-10-14 14:31:59 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
foreach ($this->targets[$key] as $target => $event)
|
2021-10-14 14:31:59 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
if (isset($params[$key][$target])
|
|
|
|
&& $params[$key][$target] == 1)
|
2021-10-14 14:31:59 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// get the header string if set
|
|
|
|
$this->getHeaders(
|
|
|
|
$params[$key],
|
|
|
|
$event,
|
|
|
|
$this->getViewName(
|
|
|
|
$obj,
|
|
|
|
$event['view']
|
|
|
|
)
|
|
|
|
);
|
2021-10-14 14:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 14:47:57 +00:00
|
|
|
/**
|
|
|
|
* set the dynamic get headers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0.10
|
|
|
|
*/
|
|
|
|
protected function setDynamicHeaders($params, $code, $key)
|
|
|
|
{
|
|
|
|
// add the headers
|
|
|
|
$params = (ComponentbuilderHelper::checkJson($params)) ? json_decode($params, true) : $params;
|
|
|
|
// make sure we have the keys values in the params area
|
|
|
|
if (ComponentbuilderHelper::checkArray($params) && isset($params[$key])
|
|
|
|
&& ComponentbuilderHelper::checkArray($params[$key]))
|
|
|
|
{
|
|
|
|
foreach ($this->targets[$key] as $target => $event)
|
|
|
|
{
|
|
|
|
if (isset($params[$key][$target])
|
|
|
|
&& $params[$key][$target] == 1)
|
|
|
|
{
|
|
|
|
// get the header string if set
|
|
|
|
$this->getHeaders(
|
|
|
|
$params[$key],
|
|
|
|
$event,
|
|
|
|
$code
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 02:46:17 +00:00
|
|
|
/**
|
2021-12-08 20:42:13 +00:00
|
|
|
* get the headers
|
2021-12-03 02:46:17 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
2021-12-08 20:42:13 +00:00
|
|
|
protected function getHeaders(&$params, &$get, $view_name)
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
|
|
|
// we first check if the value is set
|
2021-12-08 20:42:13 +00:00
|
|
|
if (isset($params[$get['field']]) || isset($params['power_' . $get['field']]))
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// start little headers bucket
|
|
|
|
$headers = array();
|
2021-12-03 02:46:17 +00:00
|
|
|
// load the headers if text
|
2021-12-08 20:42:13 +00:00
|
|
|
if (isset($params[$get['field']]) && ComponentbuilderHelper::checkString($params[$get['field']]))
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
$headers[] = $params[$get['field']];
|
2021-12-03 02:46:17 +00:00
|
|
|
}
|
|
|
|
// load the headers if power
|
2021-12-08 20:42:13 +00:00
|
|
|
if (isset($params['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($params['power_' . $get['field']], true)
|
2022-05-18 11:08:14 +00:00
|
|
|
&& ($powers = $this->getPowers($params['power_' . $get['field']])) !== false)
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
2022-05-18 11:08:14 +00:00
|
|
|
$headers[] = $powers;
|
2021-12-03 02:46:17 +00:00
|
|
|
}
|
2021-12-08 20:42:13 +00:00
|
|
|
// check if we found some header values
|
|
|
|
if (ComponentbuilderHelper::checkArray($headers, true))
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
2021-12-08 20:42:13 +00:00
|
|
|
// activate the load of the headers
|
|
|
|
$this->loadHeaders = true;
|
|
|
|
// check if this active header is already set
|
|
|
|
if (!isset($this->activeHeaders[$view_name][$get['context']]))
|
|
|
|
{
|
|
|
|
// start the active header
|
|
|
|
$this->activeHeaders[$view_name][$get['context']] = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// each addition we add a new line
|
2022-09-20 11:36:38 +00:00
|
|
|
$this->activeHeaders[$view_name][$get['context']] .= PHP_EOL;
|
2021-12-08 20:42:13 +00:00
|
|
|
}
|
|
|
|
// load the found headers
|
|
|
|
$this->activeHeaders[$view_name][$get['context']] .= implode(PHP_EOL, $headers);
|
2021-12-03 02:46:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-08 20:42:13 +00:00
|
|
|
* get the view name
|
2021-12-03 02:46:17 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*
|
2021-12-08 20:42:13 +00:00
|
|
|
* @since 1.0.8
|
|
|
|
*/
|
|
|
|
protected function getViewName(&$view, &$get)
|
|
|
|
{
|
|
|
|
if ($get === 'site' || $get === 'admin' || $get === 'ajax' || $get === 'dashboard')
|
|
|
|
{
|
|
|
|
// static key name
|
|
|
|
return $get;
|
|
|
|
}
|
|
|
|
elseif (isset($view->{$get}))
|
|
|
|
{
|
|
|
|
return ComponentbuilderHelper::safeString(
|
|
|
|
$view->{$get}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return '_error';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the powers header use strings
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*
|
2021-12-03 02:46:17 +00:00
|
|
|
* @since 1.0.6
|
|
|
|
*/
|
2022-05-18 11:08:14 +00:00
|
|
|
protected function getPowers($rows)
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
2022-05-18 11:08:14 +00:00
|
|
|
// load the active powers
|
|
|
|
$powers = array_filter(
|
|
|
|
// get the power namespace
|
|
|
|
array_map(function ($row) {
|
|
|
|
if (($power = ComponentbuilderHelper::getGUID($row['power'], 'power', ['a.guid', 'a.namespace'])) !== false)
|
|
|
|
{
|
|
|
|
$power->build = (int) $row['build'];
|
|
|
|
$power->as = (string) $row['as'];
|
|
|
|
return $power;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}, $rows),
|
|
|
|
// check that we have valid powers
|
|
|
|
function ($row) {
|
|
|
|
return is_object($row) && isset($row->guid);
|
|
|
|
}
|
|
|
|
);
|
2021-12-03 02:46:17 +00:00
|
|
|
// add to active powers
|
2022-05-18 11:08:14 +00:00
|
|
|
if (ComponentbuilderHelper::checkArray($powers))
|
2021-12-03 02:46:17 +00:00
|
|
|
{
|
|
|
|
// convert the dots to namespace
|
2022-05-18 11:08:14 +00:00
|
|
|
$powers = array_map(function ($power) {
|
|
|
|
// add to compiler (to build)
|
|
|
|
if ($power->build != 6)
|
|
|
|
{
|
|
|
|
// secure that always will remain always even if only set that way once
|
|
|
|
if (empty($this->linkedPowers[$power->guid]) || $power->build == 1)
|
|
|
|
{
|
|
|
|
$this->linkedPowers[$power->guid] = $power->build;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// build the namespace
|
|
|
|
$namespace = ComponentbuilderHelper::safeNamespace(
|
2021-12-03 02:46:17 +00:00
|
|
|
str_replace(
|
|
|
|
array_keys($this->placeholders),
|
|
|
|
array_values($this->placeholders),
|
2022-05-18 11:08:14 +00:00
|
|
|
str_replace('.', '\\', $power->namespace)
|
2021-12-03 02:46:17 +00:00
|
|
|
)
|
|
|
|
);
|
2022-05-18 11:08:14 +00:00
|
|
|
// check if it has an AS option
|
|
|
|
if (ComponentbuilderHelper::checkString($power->as) && $power->as !== 'default')
|
|
|
|
{
|
|
|
|
return 'use ' . $namespace . ' as ' . $power->as . ';';
|
|
|
|
}
|
|
|
|
return 'use ' . $namespace . ';';
|
|
|
|
}, $powers);
|
|
|
|
|
|
|
|
// return the found powers
|
|
|
|
return implode(PHP_EOL, $powers);
|
2021-10-14 14:31:41 +00:00
|
|
|
}
|
2021-12-03 02:46:17 +00:00
|
|
|
|
2022-05-18 11:08:14 +00:00
|
|
|
return false;
|
2021-12-03 02:46:17 +00:00
|
|
|
}
|
2021-12-08 20:42:13 +00:00
|
|
|
|
2021-10-14 14:31:41 +00:00
|
|
|
}
|