primo commit
This commit is contained in:
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Alledia\Framework\Factory;
|
||||
use Alledia\Framework\Joomla\Table\Base as BaseTable;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Table\Table;
|
||||
|
||||
abstract class AbstractComponent extends Licensed
|
||||
{
|
||||
/**
|
||||
* @var self
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $controller = null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($namespace)
|
||||
{
|
||||
parent::__construct($namespace, 'component');
|
||||
|
||||
BaseDatabaseModel::addIncludePath(JPATH_COMPONENT . '/models');
|
||||
Table::addIncludePath(JPATH_COMPONENT . '/tables');
|
||||
|
||||
$this->loadLibrary();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance($namespace = null)
|
||||
{
|
||||
if (empty(static::$instance)) {
|
||||
static::$instance = new static($namespace);
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->loadController();
|
||||
$this->executeRedirectTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function loadController()
|
||||
{
|
||||
if (!is_object($this->controller)) {
|
||||
$app = Factory::getApplication();
|
||||
$client = $app->isClient('administrator') ? 'Admin' : 'Site';
|
||||
|
||||
$controllerClass = 'Alledia\\' . $this->namespace . '\\' . ucfirst($this->license)
|
||||
. '\\Joomla\\Controller\\' . $client;
|
||||
require JPATH_COMPONENT . '/controller.php';
|
||||
|
||||
$this->controller = $controllerClass::getInstance($this->namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function executeRedirectTask()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$task = $app->input->getCmd('task');
|
||||
|
||||
$this->controller->execute($task);
|
||||
$this->controller->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return ?BaseDatabaseModel
|
||||
*/
|
||||
public function getModel(string $type): ?BaseDatabaseModel
|
||||
{
|
||||
$class = sprintf(
|
||||
'Alledia\\%s\\%s\\Joomla\\Model\\%s',
|
||||
$this->namespace,
|
||||
$this->isPro() ? 'Pro' : 'Free',
|
||||
$type
|
||||
);
|
||||
if (class_exists($class)) {
|
||||
return new $class();
|
||||
}
|
||||
|
||||
return BaseDatabaseModel::getInstance($type, $this->namespace . 'Model');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return ?Table
|
||||
*/
|
||||
public function getTable(string $type): ?Table
|
||||
{
|
||||
$class = sprintf(
|
||||
'Alledia\\%s\\%s\\Joomla\\Table\\%s',
|
||||
$this->namespace,
|
||||
$this->isPro() ? 'Pro' : 'Free',
|
||||
$type
|
||||
);
|
||||
if (class_exists($class)) {
|
||||
$db = Factory::getDbo();
|
||||
|
||||
return new $class($db);
|
||||
}
|
||||
|
||||
return BaseTable::getInstance($type, $this->namespace . 'Table');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
abstract class AbstractFlexibleModule extends Licensed
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $title = null;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
public $module = null;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
public $position = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $showtitle = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $menuid = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $style = null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($namespace, $module = null)
|
||||
{
|
||||
parent::__construct($namespace, 'module');
|
||||
|
||||
$this->loadLibrary();
|
||||
|
||||
if (is_object($module)) {
|
||||
$properties = [
|
||||
'id',
|
||||
'title',
|
||||
'module',
|
||||
'position',
|
||||
'content',
|
||||
'showtitle',
|
||||
'menuid',
|
||||
'name',
|
||||
'style',
|
||||
'params'
|
||||
];
|
||||
foreach ($properties as $property) {
|
||||
if (isset($module->{$property})) {
|
||||
$this->{$property} = $module->{$property};
|
||||
}
|
||||
}
|
||||
if (!$this->params instanceof Registry) {
|
||||
$this->params = new Registry($this->params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to initialize the module
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
require ModuleHelper::getLayoutPath('mod_' . $this->element, $this->params->get('layout', 'default'));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Alledia\Framework\Factory;
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
/**
|
||||
* @deprecated 1.4.1 Use AbstractFlexibleModule instead. This module doesn't
|
||||
* work with multiple modules in the same page because of the Singleton pattern.
|
||||
*
|
||||
*/
|
||||
abstract class AbstractModule extends Licensed
|
||||
{
|
||||
/**
|
||||
* @var AbstractModule
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $title = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $module = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $position = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $showtitle = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $menuid = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $style = null;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($namespace)
|
||||
{
|
||||
parent::__construct($namespace, 'module');
|
||||
|
||||
$this->loadLibrary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of child classes
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param object $module
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public static function getInstance($namespace = null, $module = null)
|
||||
{
|
||||
if (empty(static::$instance)) {
|
||||
$instance = new static($namespace);
|
||||
|
||||
if (is_object($module)) {
|
||||
$instance->id = $module->id;
|
||||
$instance->title = $module->title;
|
||||
$instance->module = $module->module;
|
||||
$instance->position = $module->position;
|
||||
$instance->content = $module->content;
|
||||
$instance->showtitle = $module->showtitle;
|
||||
$instance->menuid = $module->menuid;
|
||||
$instance->name = $module->name;
|
||||
$instance->style = $module->style;
|
||||
$instance->params = new Registry($module->params);
|
||||
} else {
|
||||
// @TODO: Raise warning/Error
|
||||
}
|
||||
|
||||
$instance->loadLanguage();
|
||||
|
||||
static::$instance = $instance;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
require ModuleHelper::getLayoutPath('mod_' . $this->element, $this->params->get('layout', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function loadLanguage()
|
||||
{
|
||||
$language = Factory::getLanguage();
|
||||
$language->load($this->module, JPATH_SITE);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
use Alledia\Framework\Factory;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Version;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
defined('_JEXEC') or die();
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
abstract class AbstractPlugin extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Alledia Extension instance
|
||||
*
|
||||
* @var Licensed
|
||||
*/
|
||||
protected $extension;
|
||||
|
||||
/**
|
||||
* Library namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace;
|
||||
|
||||
/**
|
||||
* Method used to load the extension data. It is not on the constructor
|
||||
* because this way we can avoid loading the data if the plugin
|
||||
* will not be used.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->loadExtension();
|
||||
|
||||
// Load the libraries, if existent
|
||||
$this->extension->loadLibrary();
|
||||
|
||||
$this->loadLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load the language files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadLanguage($extension = '', $basePath = JPATH_ADMINISTRATOR)
|
||||
{
|
||||
parent::loadLanguage($extension, $basePath);
|
||||
|
||||
$systemStrings = 'plg_' . $this->_type . '_' . $this->_name . '.sys';
|
||||
parent::loadLanguage($systemStrings, $basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load the extension data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loadExtension()
|
||||
{
|
||||
if (!isset($this->extension)) {
|
||||
$this->extension = Factory::getExtension($this->namespace, 'plugin', $this->_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this extension is licensed as pro
|
||||
*
|
||||
* @return bool True for pro version
|
||||
*/
|
||||
protected function isPro()
|
||||
{
|
||||
return $this->extension->isPro();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
class Component extends Licensed
|
||||
{
|
||||
/**
|
||||
* @var BaseController
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($namespace)
|
||||
{
|
||||
parent::__construct($namespace, 'component');
|
||||
|
||||
$this->loadLibrary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the main controller
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function loadController()
|
||||
{
|
||||
if (!isset($this->controller)) {
|
||||
jimport('legacy.controller.legacy');
|
||||
|
||||
$this->controller = BaseController::getInstance($this->namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function executeTask()
|
||||
{
|
||||
$task = Factory::getApplication()->input->getCmd('task');
|
||||
|
||||
$this->controller->execute($task);
|
||||
$this->controller->redirect();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,515 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use JFormFieldCustomFooter;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\Registry\Registry;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Generic extension class
|
||||
*
|
||||
* @todo : Make this class compatible with non-Alledia extensions
|
||||
*/
|
||||
class Generic
|
||||
{
|
||||
/**
|
||||
* The extension namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = null;
|
||||
|
||||
/**
|
||||
* The extension type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = null;
|
||||
|
||||
/**
|
||||
* The extension id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $id = null;
|
||||
|
||||
/**
|
||||
* The extension name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* The extension params
|
||||
*
|
||||
* @var Registry
|
||||
*/
|
||||
public $params = null;
|
||||
|
||||
/**
|
||||
* The extension enable state
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $enabled;
|
||||
|
||||
/**
|
||||
* The element of the extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $element;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $folder = null;
|
||||
|
||||
/**
|
||||
* Base path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* The manifest information
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $manifest = null;
|
||||
|
||||
/**
|
||||
* The manifest information as SimpleXMLElement
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
public $manifestXml = null;
|
||||
|
||||
/**
|
||||
* The config information
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
public $config = null;
|
||||
|
||||
/**
|
||||
* Class constructor, set the extension type.
|
||||
*
|
||||
* @param string $namespace The element of the extension
|
||||
* @param string $type The type of extension
|
||||
* @param string $folder The folder for plugins (only)
|
||||
*/
|
||||
public function __construct($namespace, $type, $folder = '', $basePath = JPATH_SITE)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->element = strtolower($namespace);
|
||||
$this->folder = $folder;
|
||||
$this->basePath = rtrim($basePath, '/\\');
|
||||
$this->namespace = $namespace;
|
||||
|
||||
$this->getManifest();
|
||||
|
||||
$this->getDataFromDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about this extension from the database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getDataFromDatabase()
|
||||
{
|
||||
$element = $this->getElementToDb();
|
||||
|
||||
// Load the extension info from database
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('extension_id'),
|
||||
$db->quoteName('name'),
|
||||
$db->quoteName('enabled'),
|
||||
$db->quoteName('params')
|
||||
])
|
||||
->from('#__extensions')
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote($this->type))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote($element));
|
||||
|
||||
if ($this->type === 'plugin') {
|
||||
$query->where($db->quoteName('folder') . ' = ' . $db->quote($this->folder));
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$row = $db->loadObject();
|
||||
|
||||
if (is_object($row)) {
|
||||
$this->id = $row->extension_id;
|
||||
$this->name = $row->name;
|
||||
$this->enabled = (bool)$row->enabled;
|
||||
$this->params = new Registry($row->params);
|
||||
|
||||
} else {
|
||||
$this->id = null;
|
||||
$this->name = null;
|
||||
$this->enabled = false;
|
||||
$this->params = new Registry();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the extension is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path for the extension
|
||||
*
|
||||
* @return string The path
|
||||
*/
|
||||
public function getExtensionPath()
|
||||
{
|
||||
$folders = [
|
||||
'component' => 'administrator/components/',
|
||||
'plugin' => 'plugins/',
|
||||
'template' => 'templates/',
|
||||
'library' => 'libraries/',
|
||||
'cli' => 'cli/',
|
||||
'module' => 'modules/'
|
||||
];
|
||||
|
||||
$basePath = $this->basePath . '/' . $folders[$this->type];
|
||||
|
||||
switch ($this->type) {
|
||||
case 'plugin':
|
||||
$basePath .= $this->folder . '/';
|
||||
break;
|
||||
|
||||
case 'module':
|
||||
if (!preg_match('/^mod_/', $this->element)) {
|
||||
$basePath .= 'mod_';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'component':
|
||||
if (!preg_match('/^com_/', $this->element)) {
|
||||
$basePath .= 'com_';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$basePath .= $this->element;
|
||||
|
||||
return $basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full element
|
||||
*
|
||||
* @return string The full element
|
||||
*/
|
||||
public function getFullElement()
|
||||
{
|
||||
return Helper::getFullElementFromInfo($this->type, $this->element, $this->folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element to match the database records.
|
||||
* Only components and modules have the prefix.
|
||||
*
|
||||
* @return string The element
|
||||
*/
|
||||
public function getElementToDb()
|
||||
{
|
||||
$prefixes = [
|
||||
'component' => 'com_',
|
||||
'module' => 'mod_'
|
||||
];
|
||||
|
||||
$fullElement = '';
|
||||
if (array_key_exists($this->type, $prefixes)) {
|
||||
if (!preg_match('/^' . $prefixes[$this->type] . '/', $this->element)) {
|
||||
$fullElement = $prefixes[$this->type];
|
||||
}
|
||||
}
|
||||
|
||||
$fullElement .= $this->element;
|
||||
|
||||
return $fullElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get manifest path for this extension
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getManifestPath()
|
||||
{
|
||||
$extensionPath = $this->getExtensionPath();
|
||||
|
||||
// Templates or extension?
|
||||
if ($this->type === 'template') {
|
||||
$fileName = 'templateDetails.xml';
|
||||
} else {
|
||||
$fileName = $this->element . '.xml';
|
||||
}
|
||||
|
||||
$path = $extensionPath . "/{$fileName}";
|
||||
|
||||
if (!is_file($path)) {
|
||||
$path = $extensionPath . "/{$this->getElementToDb()}.xml";
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension manifest as SimpleXMLElement
|
||||
*
|
||||
* @param bool $force If true, force to load the manifest, ignoring the cached one
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function getManifestAsSimpleXML($force = false)
|
||||
{
|
||||
if (!isset($this->manifestXml) || $force) {
|
||||
$path = $this->getManifestPath();
|
||||
|
||||
if (File::exists($path)) {
|
||||
$this->manifestXml = simplexml_load_file($path);
|
||||
} else {
|
||||
$this->manifestXml = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->manifestXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension information
|
||||
*
|
||||
* @param bool $force If true, force to load the manifest, ignoring the cached one
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getManifest($force = false)
|
||||
{
|
||||
if (!isset($this->manifest) || $force) {
|
||||
$xml = $this->getManifestAsSimpleXML($force);
|
||||
if (!empty($xml)) {
|
||||
$this->manifest = (object)json_decode(json_encode($xml));
|
||||
} else {
|
||||
$this->manifest = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->manifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension config file
|
||||
*
|
||||
* @param bool $force Force to reload the config file
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function getConfig($force = false)
|
||||
{
|
||||
if (!isset($this->config) || $force) {
|
||||
$this->config = null;
|
||||
|
||||
$path = $this->getExtensionPath() . '/config.xml';
|
||||
|
||||
if (file_exists($path)) {
|
||||
$this->config = simplexml_load_file($path);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the update URL from database
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdateURL()
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('sites.location')
|
||||
->from('#__update_sites AS sites')
|
||||
->leftJoin('#__update_sites_extensions AS extensions ON (sites.update_site_id = extensions.update_site_id)')
|
||||
->where('extensions.extension_id = ' . $this->id);
|
||||
|
||||
return $db->setQuery($query)->loadResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the update URL
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
public function setUpdateURL($url)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Get the update site id
|
||||
$join = $db->quoteName('#__update_sites_extensions') . ' AS extensions '
|
||||
. 'ON (sites.update_site_id = extensions.update_site_id)';
|
||||
$query = $db->getQuery(true)
|
||||
->select('sites.update_site_id')
|
||||
->from($db->quoteName('#__update_sites') . ' AS sites')
|
||||
->leftJoin($join)
|
||||
->where('extensions.extension_id = ' . $this->id);
|
||||
|
||||
$siteId = (int)$db->setQuery($query)->loadResult();
|
||||
|
||||
if (!empty($siteId)) {
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__update_sites'))
|
||||
->set($db->quoteName('location') . ' = ' . $db->quote($url))
|
||||
->where($db->quoteName('update_site_id') . ' = ' . $siteId);
|
||||
|
||||
$db->setQuery($query)->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the params on the database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function storeParams()
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
$updateObject = (object)[
|
||||
'params' => $this->params->toString(),
|
||||
'extension_id' => $this->id
|
||||
];
|
||||
|
||||
$db->updateObject('#__extensions', $updateObject, ['extension_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return (int)$this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO: Move to the licensed class?
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFooterMarkup()
|
||||
{
|
||||
$manifest = $this->getManifestAsSimpleXML();
|
||||
|
||||
if ($manifest->alledia) {
|
||||
$configPath = $this->getExtensionPath() . '/config.xml';
|
||||
if (File::exists($configPath)) {
|
||||
$config = $this->getConfig();
|
||||
|
||||
if (is_object($config)) {
|
||||
$footerElement = $config->xpath('//field[@type="customfooter"]');
|
||||
$footerElement = reset($footerElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($footerElement)) {
|
||||
if (is_object($manifest)) {
|
||||
if ($footerElement = $manifest->xpath('//field[@type="customfooter"]')) {
|
||||
$footerElement = reset($footerElement);
|
||||
|
||||
} elseif ($media = (string)$manifest->media['destination']) {
|
||||
$customField = sprintf(
|
||||
'<field type="customfooter" name="customfooter" media="%s"/>',
|
||||
$media
|
||||
);
|
||||
|
||||
$footerElement = new SimpleXMLElement($customField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($footerElement) == false) {
|
||||
if (class_exists('JFormFieldCustomFooter') === false) {
|
||||
$classPath = $this->getExtensionPath() . '/form/fields/customfooter.php';
|
||||
if (is_file($classPath)) {
|
||||
require_once $classPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('JFormFieldCustomFooter')) {
|
||||
$field = new JFormFieldCustomFooter();
|
||||
$field->fromInstaller = true;
|
||||
|
||||
return $field->getInputUsingCustomElement($footerElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension's version collected from the manifest file
|
||||
*
|
||||
* @return string The extension's version
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
if (!empty($this->manifest->version)) {
|
||||
return $this->manifest->version;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
176
libraries/allediaframework/Framework/Joomla/Extension/Helper.php
Normal file
176
libraries/allediaframework/Framework/Joomla/Extension/Helper.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
use Alledia\Framework\Factory;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
/**
|
||||
* Generic extension helper class
|
||||
*/
|
||||
abstract class Helper
|
||||
{
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
protected static $extensionInfo = [];
|
||||
|
||||
protected static $extensionTypes = [
|
||||
'com' => 'component',
|
||||
'plg' => 'plugin',
|
||||
'mod' => 'module',
|
||||
'lib' => 'library',
|
||||
'tpl' => 'template',
|
||||
'cli' => 'cli'
|
||||
];
|
||||
|
||||
/**
|
||||
* Build a string representing the element
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $element
|
||||
* @param string $folder
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFullElementFromInfo($type, $element, $folder = null)
|
||||
{
|
||||
$prefix = array_search($type, static::$extensionTypes);
|
||||
if ($prefix) {
|
||||
if (strpos($element, $prefix) === 0) {
|
||||
$shortElement = substr($element, strlen($prefix) + 1);
|
||||
}
|
||||
$parts = [
|
||||
$prefix,
|
||||
$type == 'plugin' ? $folder : null,
|
||||
$shortElement ?? $element
|
||||
];
|
||||
|
||||
return join('_', array_filter($parts));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string $element
|
||||
*
|
||||
* @return ?array
|
||||
*/
|
||||
public static function getExtensionInfoFromElement(?string $element): ?array
|
||||
{
|
||||
if (isset(static::$extensionInfo[$element]) == false) {
|
||||
static::$extensionInfo[$element] = false;
|
||||
|
||||
$parts = explode('_', $element, 3);
|
||||
if (count($parts) > 1) {
|
||||
$prefix = $parts[0];
|
||||
$name = $parts[2] ?? $parts[1];
|
||||
$group = empty($parts[2]) ? null : $parts[1];
|
||||
|
||||
$types = [
|
||||
'com' => 'component',
|
||||
'plg' => 'plugin',
|
||||
'mod' => 'module',
|
||||
'lib' => 'library',
|
||||
'tpl' => 'template',
|
||||
'cli' => 'cli'
|
||||
];
|
||||
|
||||
if (array_key_exists($prefix, $types)) {
|
||||
$result = [
|
||||
'prefix' => $prefix,
|
||||
'type' => $types[$prefix],
|
||||
'name' => $name,
|
||||
'group' => $group,
|
||||
'namespace' => preg_replace_callback(
|
||||
'/^(os[a-z])(.*)/i',
|
||||
function ($matches) {
|
||||
return strtoupper($matches[1]) . $matches[2];
|
||||
},
|
||||
$name
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
static::$extensionInfo[$element] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
return static::$extensionInfo[$element] ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $element
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function loadLibrary($element)
|
||||
{
|
||||
$extension = static::getExtensionForElement($element);
|
||||
|
||||
if (is_object($extension)) {
|
||||
return $extension->loadLibrary();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFooterMarkup($element)
|
||||
{
|
||||
if (is_string($element)) {
|
||||
$extension = static::getExtensionForElement($element);
|
||||
} elseif (is_object($element)) {
|
||||
$extension = $element;
|
||||
}
|
||||
|
||||
if (!empty($extension)) {
|
||||
return $extension->getFooterMarkup();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $element
|
||||
*
|
||||
* @return Licensed
|
||||
*/
|
||||
public static function getExtensionForElement($element)
|
||||
{
|
||||
$info = static::getExtensionInfoFromElement($element);
|
||||
|
||||
if (!empty($info['type']) && !empty($info['namespace'])) {
|
||||
return Factory::getExtension($info['namespace'], $info['type'], $info['group']);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AllediaFramework
|
||||
* @contact www.joomlashack.com, help@joomlashack.com
|
||||
* @copyright 2016-2023 Joomlashack.com. All rights reserved
|
||||
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
|
||||
*
|
||||
* This file is part of AllediaFramework.
|
||||
*
|
||||
* AllediaFramework is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AllediaFramework is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Alledia\Framework\Joomla\Extension;
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Alledia\Framework\AutoLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Licensed class, for extensions with Free and Pro versions
|
||||
*/
|
||||
class Licensed extends Generic
|
||||
{
|
||||
/**
|
||||
* License type: free or pro
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $license = null;
|
||||
|
||||
/**
|
||||
* The path for the pro library
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $proLibraryPath = null;
|
||||
|
||||
/**
|
||||
* The path for the free library
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $libraryPath = null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($namespace, $type, $folder = '', $basePath = JPATH_SITE)
|
||||
{
|
||||
parent::__construct($namespace, $type, $folder, $basePath);
|
||||
|
||||
$this->license = strtolower($this->manifest->alledia->license ?? '');
|
||||
$this->namespace = $this->manifest->alledia->namespace ?? '';
|
||||
|
||||
$this->getLibraryPath();
|
||||
$this->getProLibraryPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the license is pro
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPro(): bool
|
||||
{
|
||||
return $this->license === 'pro';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the license is free
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFree(): bool
|
||||
{
|
||||
return !$this->isPro();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the include path for the free library, based on the extension type
|
||||
*
|
||||
* @return string The path for pro
|
||||
*/
|
||||
public function getLibraryPath()
|
||||
{
|
||||
if ($this->libraryPath === null) {
|
||||
$basePath = $this->getExtensionPath();
|
||||
|
||||
$this->libraryPath = $basePath . '/library';
|
||||
}
|
||||
|
||||
return $this->libraryPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the include path the pro library, based on the extension type
|
||||
*
|
||||
* @return string The path for pro
|
||||
*/
|
||||
public function getProLibraryPath()
|
||||
{
|
||||
if (empty($this->proLibraryPath)) {
|
||||
$basePath = $this->getLibraryPath();
|
||||
|
||||
$this->proLibraryPath = $basePath . '/Pro';
|
||||
}
|
||||
|
||||
return $this->proLibraryPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the library, if existent (including the Pro Library)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadLibrary()
|
||||
{
|
||||
if ($this->namespace) {
|
||||
$libraryPath = $this->getLibraryPath();
|
||||
|
||||
if (is_dir($libraryPath)) {
|
||||
AutoLoader::register('Alledia\\' . $this->namespace, $libraryPath);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user