2016-01-30 20:28:43 +00:00
|
|
|
<?php
|
2021-03-05 03:08:47 +00:00
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 30th April, 2015
|
2022-07-09 15:45:08 +00:00
|
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
2021-03-05 03:08:47 +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');
|
|
|
|
|
2024-03-02 20:10:30 +00:00
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
use Joomla\CMS\Language\Text;
|
|
|
|
use Joomla\CMS\Component\ComponentHelper;
|
2022-05-25 08:30:55 +00:00
|
|
|
use Joomla\CMS\MVC\Model\ListModel;
|
2024-03-02 20:10:30 +00:00
|
|
|
use Joomla\CMS\Plugin\PluginHelper;
|
2021-03-05 03:08:47 +00:00
|
|
|
use Joomla\Utilities\ArrayHelper;
|
2023-10-18 07:26:30 +00:00
|
|
|
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
2024-03-02 20:10:30 +00:00
|
|
|
use VDM\Joomla\Utilities\JsonHelper;
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
/**
|
2022-05-25 08:30:55 +00:00
|
|
|
* Componentbuilder List Model for Compiler
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
2022-05-25 08:30:55 +00:00
|
|
|
class ComponentbuilderModelCompiler extends ListModel
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Model user data.
|
|
|
|
*
|
|
|
|
* @var strings
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
protected $userId;
|
|
|
|
protected $guest;
|
|
|
|
protected $groups;
|
|
|
|
protected $levels;
|
|
|
|
protected $app;
|
|
|
|
protected $input;
|
|
|
|
protected $uikitComp;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to build an SQL query to load the list data.
|
|
|
|
*
|
|
|
|
* @return string An SQL query
|
|
|
|
*/
|
|
|
|
protected function getListQuery()
|
|
|
|
{
|
|
|
|
// Get the current user for authorisation checks
|
2024-03-02 20:10:30 +00:00
|
|
|
$this->user = Factory::getUser();
|
2021-03-05 03:08:47 +00:00
|
|
|
$this->userId = $this->user->get('id');
|
|
|
|
$this->guest = $this->user->get('guest');
|
|
|
|
$this->groups = $this->user->get('groups');
|
2024-03-02 20:10:30 +00:00
|
|
|
$this->authorisedGroups = $this->user->getAuthorisedGroups();
|
2021-03-05 03:08:47 +00:00
|
|
|
$this->levels = $this->user->getAuthorisedViewLevels();
|
2024-03-02 20:10:30 +00:00
|
|
|
$this->app = Factory::getApplication();
|
2021-03-05 03:08:47 +00:00
|
|
|
$this->input = $this->app->input;
|
2024-03-02 20:10:30 +00:00
|
|
|
$this->initSet = true;
|
2017-02-02 11:54:07 +00:00
|
|
|
// Make sure all records load, since no pagination allowed.
|
|
|
|
$this->setState('list.limit', 0);
|
|
|
|
// Get a db connection.
|
2024-03-02 20:10:30 +00:00
|
|
|
$db = Factory::getDbo();
|
2017-02-02 11:54:07 +00:00
|
|
|
|
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
2017-02-16 14:02:23 +00:00
|
|
|
// Get from #__componentbuilder_joomla_component as a
|
2017-02-02 11:54:07 +00:00
|
|
|
$query->select($db->quoteName(
|
|
|
|
array('a.id','a.system_name','a.name','a.name_code','a.component_version','a.debug_linenr','a.short_description','a.image','a.companyname','a.author','a.email','a.website','a.copyright','a.modified','a.created','a.version'),
|
|
|
|
array('id','system_name','name','name_code','component_version','debug_linenr','short_description','image','companyname','author','email','website','copyright','modified','created','version')));
|
2017-02-16 14:02:23 +00:00
|
|
|
$query->from($db->quoteName('#__componentbuilder_joomla_component', 'a'));
|
2017-04-26 08:55:02 +00:00
|
|
|
// Get where a.published is 1
|
2017-02-02 11:54:07 +00:00
|
|
|
$query->where('a.published = 1');
|
|
|
|
$query->order('a.modified DESC');
|
|
|
|
$query->order('a.created DESC');
|
|
|
|
|
|
|
|
// return the query object
|
2021-03-05 03:08:47 +00:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get an array of data items.
|
|
|
|
*
|
|
|
|
* @return mixed An array of data items on success, false on failure.
|
|
|
|
*/
|
|
|
|
public function getItems()
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
$user = Factory::getUser();
|
2021-03-05 03:08:47 +00:00
|
|
|
// check if this user has permission to access items
|
|
|
|
if (!$user->authorise('compiler.access', 'com_componentbuilder'))
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();
|
|
|
|
$app->enqueueMessage(Text::_('Not authorised!'), 'error');
|
2021-03-05 03:08:47 +00:00
|
|
|
// redirect away if not a correct (TODO for now we go to default view)
|
|
|
|
$app->redirect('index.php?option=com_componentbuilder');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// load parent items
|
|
|
|
$items = parent::getItems();
|
|
|
|
|
|
|
|
// Get the global params
|
2024-03-02 20:10:30 +00:00
|
|
|
$globalParams = ComponentHelper::getParams('com_componentbuilder', true);
|
2017-02-02 11:54:07 +00:00
|
|
|
|
2017-12-10 19:17:26 +00:00
|
|
|
// Insure all item fields are adapted where needed.
|
2024-03-02 20:10:30 +00:00
|
|
|
if (UtilitiesArrayHelper::check($items))
|
2017-02-02 11:54:07 +00:00
|
|
|
{
|
2017-12-10 19:17:26 +00:00
|
|
|
// Load the JEvent Dispatcher
|
2024-03-02 20:10:30 +00:00
|
|
|
PluginHelper::importPlugin('content');
|
|
|
|
$this->_dispatcher = Factory::getApplication();
|
2017-02-02 11:54:07 +00:00
|
|
|
foreach ($items as $nr => &$item)
|
|
|
|
{
|
|
|
|
// Always create a slug for sef URL's
|
2024-03-02 20:10:30 +00:00
|
|
|
$item->slug = ($item->id ?? '0') . (isset($item->alias) ? ':' . $item->alias : '');
|
2018-08-23 21:51:09 +00:00
|
|
|
// Check if item has params, or pass whole item.
|
2024-03-02 20:10:30 +00:00
|
|
|
$params = (isset($item->params) && JsonHelper::check($item->params)) ? json_decode($item->params) : $item;
|
2017-12-10 19:17:26 +00:00
|
|
|
// Make sure the content prepare plugins fire on copyright
|
2024-03-02 20:10:30 +00:00
|
|
|
$_copyright = new \stdClass();
|
2017-12-10 19:17:26 +00:00
|
|
|
$_copyright->text =& $item->copyright; // value must be in text
|
|
|
|
// Since all values are now in text (Joomla Limitation), we also add the field name (copyright) to context
|
2021-10-19 01:30:46 +00:00
|
|
|
$this->_dispatcher->triggerEvent("onContentPrepare", array('com_componentbuilder.compiler.copyright', &$_copyright, &$params, 0));
|
2017-02-02 11:54:07 +00:00
|
|
|
// Checking if copyright has uikit components that must be loaded.
|
|
|
|
$this->uikitComp = ComponentbuilderHelper::getUikitComp($item->copyright,$this->uikitComp);
|
|
|
|
}
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return items
|
|
|
|
return $items;
|
2017-02-02 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-26 10:03:08 +00:00
|
|
|
* Get the uikit needed components
|
|
|
|
*
|
|
|
|
* @return mixed An array of objects on success.
|
|
|
|
*
|
|
|
|
*/
|
2017-02-02 11:54:07 +00:00
|
|
|
public function getUikitComp()
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
if (isset($this->uikitComp) && UtilitiesArrayHelper::check($this->uikitComp))
|
2017-02-02 11:54:07 +00:00
|
|
|
{
|
|
|
|
return $this->uikitComp;
|
|
|
|
}
|
|
|
|
return false;
|
2018-09-11 20:28:17 +00:00
|
|
|
}
|
2017-02-02 11:54:07 +00:00
|
|
|
|
2017-03-03 21:53:18 +00:00
|
|
|
public $compiler;
|
2018-04-24 22:36:05 +00:00
|
|
|
|
2022-08-30 15:28:41 +00:00
|
|
|
public function builder()
|
2018-04-24 22:36:05 +00:00
|
|
|
{
|
2019-08-12 21:30:31 +00:00
|
|
|
// run compiler
|
2022-08-30 15:28:41 +00:00
|
|
|
$this->compiler = new Compiler();
|
2017-06-05 20:18:32 +00:00
|
|
|
if($this->compiler)
|
|
|
|
{
|
2016-01-30 20:28:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-12 21:30:31 +00:00
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
public function emptyFolder($dir, $removeDir = false)
|
|
|
|
{
|
|
|
|
jimport('joomla.filesystem.folder');
|
|
|
|
jimport('joomla.filesystem.file');
|
|
|
|
|
|
|
|
if (JFolder::exists($dir))
|
|
|
|
{
|
|
|
|
$it = new RecursiveDirectoryIterator($dir);
|
|
|
|
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
|
|
foreach ($it as $file)
|
|
|
|
{
|
|
|
|
if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue;
|
|
|
|
if ($file->isDir())
|
|
|
|
{
|
|
|
|
JFolder::delete($file->getPathname());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($file->getBasename() !== 'index.html')
|
|
|
|
{
|
|
|
|
JFile::delete($file->getPathname());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($removeDir)
|
|
|
|
{
|
|
|
|
if (JFolder::delete($dir))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-12 21:30:31 +00:00
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
public function install($p_file)
|
|
|
|
{
|
2018-03-09 03:26:44 +00:00
|
|
|
$this->setState('action', 'install');
|
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
// Set FTP credentials, if given.
|
|
|
|
JClientHelper::setCredentialsFromRequest('ftp');
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();
|
2016-01-30 20:28:43 +00:00
|
|
|
|
|
|
|
// Load installer plugins for assistance if required:
|
|
|
|
JPluginHelper::importPlugin('installer');
|
|
|
|
$dispatcher = JEventDispatcher::getInstance();
|
2018-03-09 03:26:44 +00:00
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
$package = null;
|
|
|
|
|
|
|
|
// This event allows an input pre-treatment, a custom pre-packing or custom installation.
|
|
|
|
// (e.g. from a JSON description).
|
|
|
|
$results = $dispatcher->trigger('onInstallerBeforeInstallation', array($this, &$package));
|
|
|
|
|
|
|
|
if (in_array(true, $results, true))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-09 03:26:44 +00:00
|
|
|
|
|
|
|
if (in_array(false, $results, true))
|
2016-01-30 20:28:43 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-12 21:30:31 +00:00
|
|
|
|
2024-03-02 20:10:30 +00:00
|
|
|
$config = Factory::getConfig();
|
2016-01-30 20:28:43 +00:00
|
|
|
$tmp_dest = $config->get('tmp_path');
|
|
|
|
|
|
|
|
// Unpack the downloaded package file.
|
|
|
|
$package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true);
|
2018-03-09 03:26:44 +00:00
|
|
|
|
|
|
|
// insure the install type is folder (JCB zip file is in the folder)
|
2016-01-30 20:28:43 +00:00
|
|
|
$installType = 'folder';
|
2018-03-09 03:26:44 +00:00
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
// This event allows a custom installation of the package or a customization of the package:
|
|
|
|
$results = $dispatcher->trigger('onInstallerBeforeInstaller', array($this, &$package));
|
|
|
|
|
|
|
|
if (in_array(true, $results, true))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elseif (in_array(false, $results, true))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-12 21:30:31 +00:00
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
// Was the package unpacked?
|
|
|
|
if (!$package || !$package['type'])
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
$app->enqueueMessage(Text::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE'), 'error');
|
2016-01-30 20:28:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get an installer instance.
|
|
|
|
$installer = JInstaller::getInstance();
|
|
|
|
|
|
|
|
// Install the package.
|
|
|
|
if (!$installer->install($package['dir']))
|
|
|
|
{
|
|
|
|
// There was an error installing the package.
|
2024-03-02 20:10:30 +00:00
|
|
|
$msg = Text::sprintf('COM_INSTALLER_INSTALL_ERROR', Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
|
2016-01-30 20:28:43 +00:00
|
|
|
$result = false;
|
|
|
|
$msgType = 'error';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-12 21:30:31 +00:00
|
|
|
// Package installed successfully.
|
2024-03-02 20:10:30 +00:00
|
|
|
$msg = Text::sprintf('COM_INSTALLER_INSTALL_SUCCESS', Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
|
2016-01-30 20:28:43 +00:00
|
|
|
$result = true;
|
|
|
|
$msgType = 'message';
|
|
|
|
}
|
|
|
|
|
|
|
|
// This event allows a custom a post-flight:
|
|
|
|
$dispatcher->trigger('onInstallerAfterInstaller', array($this, &$package, $installer, &$result, &$msg));
|
|
|
|
|
|
|
|
// Set some model state values.
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();
|
2016-01-30 20:28:43 +00:00
|
|
|
$app->enqueueMessage($msg, $msgType);
|
|
|
|
$this->setState('name', $installer->get('name'));
|
|
|
|
$this->setState('result', $result);
|
|
|
|
$app->setUserState('com_componentbuilder.message', $installer->message);
|
|
|
|
$app->setUserState('com_componentbuilder.extension_message', $installer->get('extension_message'));
|
|
|
|
$app->setUserState('com_componentbuilder.redirect_url', $installer->get('redirect_url'));
|
|
|
|
|
|
|
|
// Cleanup the install files.
|
|
|
|
if (!is_file($package['packagefile']))
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
$config = Factory::getConfig();
|
2016-01-30 20:28:43 +00:00
|
|
|
$package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
|
|
|
|
}
|
|
|
|
|
|
|
|
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
|
|
|
|
|
2018-03-09 03:26:44 +00:00
|
|
|
// Clear the cached extension data and menu cache
|
|
|
|
$this->cleanCache('_system', 0);
|
|
|
|
$this->cleanCache('_system', 1);
|
|
|
|
$this->cleanCache('com_modules', 0);
|
|
|
|
$this->cleanCache('com_modules', 1);
|
|
|
|
$this->cleanCache('com_plugins', 0);
|
|
|
|
$this->cleanCache('com_plugins', 1);
|
|
|
|
$this->cleanCache('mod_menu', 0);
|
|
|
|
$this->cleanCache('mod_menu', 1);
|
|
|
|
|
2016-01-30 20:28:43 +00:00
|
|
|
return $result;
|
2022-10-20 14:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all components in the system
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @since 3.2.0
|
|
|
|
**/
|
|
|
|
public function getComponents(): array
|
|
|
|
{
|
|
|
|
// Get a db connection.
|
|
|
|
$db = $this->getDbo();
|
|
|
|
|
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
// Select only id and system name
|
|
|
|
$query->select($db->quoteName(array('id', 'system_name'),array('id', 'name')));
|
|
|
|
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
|
|
|
|
|
|
|
|
// only the active components
|
|
|
|
$query->where($db->quoteName('published') . ' = 1');
|
|
|
|
|
|
|
|
// Order it by the ordering field.
|
|
|
|
$query->order('modified DESC');
|
|
|
|
$query->order('created DESC');
|
|
|
|
|
|
|
|
// Reset the query using our newly populated query object.
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
// return the result
|
|
|
|
return $db->loadObjectList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all dynamic content
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @since 3.2.0
|
|
|
|
**/
|
|
|
|
public function getDynamicContent(&$errorMessage): bool
|
|
|
|
{
|
|
|
|
// convert error message to array
|
|
|
|
$errorMessage = [];
|
|
|
|
$searchArray = [
|
|
|
|
// add banners (width - height)
|
|
|
|
'banner' => [
|
|
|
|
'728-90',
|
|
|
|
'160-600'
|
|
|
|
],
|
|
|
|
// The build-gif by size (width - height)
|
|
|
|
'builder-gif' => [
|
|
|
|
'480-540'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
// start search, and get
|
|
|
|
foreach ($searchArray as $type => $sizes)
|
|
|
|
{
|
|
|
|
// per size
|
|
|
|
foreach ($sizes as $size)
|
|
|
|
{
|
|
|
|
// get size
|
|
|
|
if (($set_size = ComponentbuilderHelper::getDynamicContentSize($type, $size)) !== 0)
|
|
|
|
{
|
|
|
|
// we loop over all type size artwork
|
|
|
|
for ($target = 1; $target <= $set_size; $target++)
|
|
|
|
{
|
|
|
|
if (!ComponentbuilderHelper::getDynamicContent($type, $size, false, 0, $target))
|
|
|
|
{
|
2024-03-02 20:10:30 +00:00
|
|
|
$errorMessage[] = Text::sprintf('COM_COMPONENTBUILDER_S_S_NUMBER_BSB_COULD_NOT_BE_DOWNLOADED_SUCCESSFULLY_TO_THIS_JOOMLA_INSTALL', $type, $size, $target);
|
2022-10-20 14:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check if we had any errors
|
2023-10-18 07:26:30 +00:00
|
|
|
if (UtilitiesArrayHelper::check($errorMessage))
|
2022-10-20 14:40:18 +00:00
|
|
|
{
|
|
|
|
// flatten the error message array
|
|
|
|
$errorMessage = implode('<br />', $errorMessage);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|