Moves all major structre function to container. Adds new Server replacment class for legacy calls. Refactored multiple classes. Add more advanced compiler options, with donation notice.
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Component Dynamic Dashboard
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Dashboard
|
||||
{
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Component
|
||||
*
|
||||
* @var Component
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Component $component;
|
||||
|
||||
/**
|
||||
* Application object.
|
||||
*
|
||||
* @var CMSApplication
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected CMSApplication $app;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param Component|null $component The component class.
|
||||
* @param CMSApplication|null $app The app object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null, ?Component $component = null,
|
||||
?CMSApplication $app = null)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->component = $component ?: Compiler::_('Component');
|
||||
$this->app = $app ?: Factory::getApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Dynamic Dashboard
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
// only add the dynamic dashboard if all checks out
|
||||
if ($this->component->get('dashboard_type', 0) == 2
|
||||
&& ($dashboard_ = $this->component->get('dashboard')) !== null
|
||||
&& StringHelper::check($dashboard_)
|
||||
&& strpos((string) $dashboard_, '_') !== false)
|
||||
{
|
||||
// set the default view
|
||||
$getter = explode('_', (string) $dashboard_);
|
||||
if (count((array) $getter) == 2 && is_numeric($getter[1]))
|
||||
{
|
||||
// the pointers
|
||||
$t = StringHelper::safe($getter[0], 'U');
|
||||
$id = (int) $getter[1];
|
||||
|
||||
// the dynamic stuff
|
||||
$targets = array('A' => 'admin_views',
|
||||
'C' => 'custom_admin_views');
|
||||
$names = array('A' => 'admin view',
|
||||
'C' => 'custom admin view');
|
||||
$types = array('A' => 'adminview', 'C' => 'customadminview');
|
||||
$keys = array('A' => 'name_list', 'C' => 'code');
|
||||
|
||||
// check the target values
|
||||
if (isset($targets[$t]) && $id > 0)
|
||||
{
|
||||
// set the type name
|
||||
$type_names = StringHelper::safe(
|
||||
$targets[$t], 'w'
|
||||
);
|
||||
// set the dynamic dash
|
||||
if (($target_ = $this->component->get($targets[$t])) !== null
|
||||
&& ArrayHelper::check($target_))
|
||||
{
|
||||
// search the target views
|
||||
$dashboard = (array) array_filter(
|
||||
$target_,
|
||||
function ($view) use ($id, $t, $types) {
|
||||
if (isset($view[$types[$t]])
|
||||
&& $id == $view[$types[$t]])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
// set dashboard
|
||||
if (ArrayHelper::check($dashboard))
|
||||
{
|
||||
$dashboard = array_values($dashboard)[0];
|
||||
}
|
||||
|
||||
// check if view was found (this should be true)
|
||||
if (isset($dashboard['settings'])
|
||||
&& isset($dashboard['settings']->{$keys[$t]}))
|
||||
{
|
||||
$this->registry->set('build.dashboard',
|
||||
StringHelper::safe(
|
||||
$dashboard['settings']->{$keys[$t]}
|
||||
)
|
||||
);
|
||||
$this->registry->set('build.dashboard.type',
|
||||
$targets[$t]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set massage that something is wrong
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEDASHBOARD_ERRORHTHREE'),
|
||||
'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_BSB_BSB_IS_NOT_AVAILABLE_IN_YOUR_COMPONENT_PLEASE_INSURE_TO_ONLY_USED_S_FOR_A_DYNAMIC_DASHBOARD_THAT_ARE_STILL_LINKED_TO_YOUR_COMPONENT',
|
||||
$names[$t], $dashboard_,
|
||||
$type_names
|
||||
), 'Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// set massage that something is wrong
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEDASHBOARD_ERRORHTHREE'), 'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_BSB_BSB_IS_NOT_AVAILABLE_IN_YOUR_COMPONENT_PLEASE_INSURE_TO_ONLY_USED_S_FOR_A_DYNAMIC_DASHBOARD_THAT_ARE_STILL_LINKED_TO_YOUR_COMPONENT',
|
||||
$names[$t], $dashboard_,
|
||||
$type_names
|
||||
), 'Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the target value is wrong
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEDASHBOARD_ERRORHTHREE'), 'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_BSB_VALUE_FOR_THE_DYNAMIC_DASHBOARD_IS_INVALID',
|
||||
$dashboard_
|
||||
), 'Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the target value is wrong
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEDASHBOARD_ERRORHTHREE'), 'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_BSB_VALUE_FOR_THE_DYNAMIC_DASHBOARD_IS_INVALID',
|
||||
$dashboard_
|
||||
), 'Error'
|
||||
);
|
||||
}
|
||||
|
||||
// if default was changed to dynamic dashboard the remove default tab and methods
|
||||
if ($this->registry->get('build.dashboard'))
|
||||
{
|
||||
// dynamic dashboard is used
|
||||
$this->component->remove('dashboard_tab');
|
||||
$this->component->remove('php_dashboard_methods');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -482,6 +482,21 @@ class Data
|
||||
);
|
||||
}
|
||||
|
||||
// build the build date
|
||||
if ($this->config->get('add_build_date', 1) == 3)
|
||||
{
|
||||
if (empty($this->component->modified) ||
|
||||
$this->component->modified == '0000-00-00' ||
|
||||
$this->component->modified == '0000-00-00 00:00:00')
|
||||
{
|
||||
$this->config->set('build_date', $this->component->created);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set('build_date', $this->component->modified);
|
||||
}
|
||||
}
|
||||
|
||||
// build update SQL
|
||||
$this->history->set($component);
|
||||
|
||||
|
@@ -0,0 +1,756 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Paths;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Dynamicpath;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Pathfix;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Component (Joomla Version) Settings
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
/**
|
||||
* The standard folders
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $standardFolders = [
|
||||
'site',
|
||||
'admin',
|
||||
'media'
|
||||
];
|
||||
|
||||
/**
|
||||
* The standard root files
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $standardRootFiles = [
|
||||
'access.xml',
|
||||
'config.xml',
|
||||
'controller.php',
|
||||
'index.html',
|
||||
'README.txt'
|
||||
];
|
||||
|
||||
/**
|
||||
* Compiler Joomla Version Data
|
||||
*
|
||||
* @var object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?object $data = null;
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Event
|
||||
*
|
||||
* @var EventInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected EventInterface $event;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Component
|
||||
*
|
||||
* @var Component
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Component $component;
|
||||
|
||||
/**
|
||||
* Compiler Utilities Paths
|
||||
*
|
||||
* @var Paths
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Paths $paths;
|
||||
|
||||
/**
|
||||
* Compiler Component Dynamic Path
|
||||
*
|
||||
* @var Dynamicpath
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Dynamicpath $dynamicpath;
|
||||
|
||||
/**
|
||||
* Compiler Component Pathfix
|
||||
*
|
||||
* @var Pathfix
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Pathfix $pathfix;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param EventInterface|null $event The compiler event api object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Component|null $component The component class.
|
||||
* @param Paths|null $paths The compiler paths object.
|
||||
* @param Dynamicpath|null $dynamicpath The compiler dynamic path object.
|
||||
* @param Pathfix|null $pathfix The compiler path fixing object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Registry $registry = null,
|
||||
?EventInterface $event = null, ?Placeholder $placeholder = null,
|
||||
?Component $component = null, ?Paths $paths = null,
|
||||
?Dynamicpath $dynamicpath = null, ?Pathfix $pathfix = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->event = $event ?: Compiler::_('Event');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->component = $component ?: Compiler::_('Component');
|
||||
$this->paths = $paths ?: Compiler::_('Utilities.Paths');
|
||||
$this->dynamicpath = $dynamicpath ?: Compiler::_('Utilities.Dynamicpath');
|
||||
$this->pathfix = $pathfix ?: Compiler::_('Utilities.Pathfix');
|
||||
|
||||
// add component endpoint file to stander list of root files
|
||||
$this->standardRootFiles[] = $this->component->get('name_code') . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if data set is loaded
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(): bool
|
||||
{
|
||||
if (!$this->isSet())
|
||||
{
|
||||
// load the data
|
||||
$this->data = $this->get();
|
||||
|
||||
if (!$this->isSet())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Joomla - Folder Structure to Create
|
||||
*
|
||||
* @return object The version related structure
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function structure(): object
|
||||
{
|
||||
return $this->data->create;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Joomla - Move Multiple Structure
|
||||
*
|
||||
* @return object The version related multiple structure
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function multiple(): object
|
||||
{
|
||||
return $this->data->move->dynamic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Joomla - Move Single Structure
|
||||
*
|
||||
* @return object The version related single structure
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function single(): object
|
||||
{
|
||||
return $this->data->move->static;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Folder is a Standard Folder
|
||||
*
|
||||
* @param string $folder The folder name
|
||||
*
|
||||
* @return bool true if the folder exists
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function standardFolder(string $folder): bool
|
||||
{
|
||||
return in_array($folder, $this->standardFolders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if File is a Standard Root File
|
||||
*
|
||||
* @param string $file The file name
|
||||
*
|
||||
* @return bool true if the file exists
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function standardRootFile(string $file): bool
|
||||
{
|
||||
return in_array($file, $this->standardRootFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Data is Set
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function isSet(): bool
|
||||
{
|
||||
return is_object($this->data) &&
|
||||
isset($this->data->create) &&
|
||||
isset($this->data->move) &&
|
||||
isset($this->data->move->static) &&
|
||||
isset($this->data->move->dynamic);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the Joomla Version Data
|
||||
*
|
||||
* @return object|null The version data
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function get(): ?object
|
||||
{
|
||||
// override option
|
||||
$customSettings = $this->paths->template_path . '/settings_' .
|
||||
$this->config->component_code_name . '.json';
|
||||
|
||||
// get the data
|
||||
$version_data = $this->readJsonFile($customSettings);
|
||||
|
||||
if (is_null($version_data) || !$this->isValidData($version_data))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->loadExtraFolders();
|
||||
$this->loadExtraFiles();
|
||||
|
||||
$this->addFolders($version_data);
|
||||
$this->addFiles($version_data);
|
||||
|
||||
// for plugin event TODO change event api signatures
|
||||
$component_context = $this->config->component_context;
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterSetJoomlaVersionData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterSetJoomlaVersionData',
|
||||
array(&$component_context, &$version_data)
|
||||
);
|
||||
|
||||
return $version_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the Json file data
|
||||
*
|
||||
* @param string $filePath
|
||||
*
|
||||
* @return object|null The version data
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function readJsonFile(string $filePath): ?object
|
||||
{
|
||||
if (FileHelper::exists($filePath))
|
||||
{
|
||||
$jsonContent = FileHelper::getContent($filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsonContent = FileHelper::getContent($this->paths->template_path . '/settings.json');
|
||||
}
|
||||
|
||||
if (JsonHelper::check($jsonContent))
|
||||
{
|
||||
return json_decode((string) $jsonContent);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this is valid data
|
||||
*
|
||||
* @param object $versionData
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function isValidData(object $versionData): bool
|
||||
{
|
||||
return isset($versionData->create) &&
|
||||
isset($versionData->move) &&
|
||||
isset($versionData->move->static) &&
|
||||
isset($versionData->move->dynamic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Extra/Dynamic folders
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function loadExtraFolders()
|
||||
{
|
||||
if ($this->component->isArray('folders') ||
|
||||
$this->config->get('add_eximport', false) ||
|
||||
$this->config->get('uikit', 0) ||
|
||||
$this->config->get('footable', false))
|
||||
{
|
||||
$this->addImportViewFolder();
|
||||
$this->addPhpSpreadsheetFolder();
|
||||
$this->addUikitFolder();
|
||||
$this->addFooTableFolder();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Import and Export Folder
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addImportViewFolder()
|
||||
{
|
||||
if ($this->config->get('add_eximport', false))
|
||||
{
|
||||
$this->component->appendArray('folders', [
|
||||
'folder' => 'importViews',
|
||||
'path' => 'admin/views/import',
|
||||
'rename' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Php Spreadsheet Folder
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addPhpSpreadsheetFolder()
|
||||
{
|
||||
// move the phpspreadsheet Folder (TODO we must move this to a library package)
|
||||
if ($this->config->get('add_eximport', false))
|
||||
{
|
||||
$this->component->appendArray('folders', [
|
||||
'folderpath' => 'JPATH_LIBRARIES/phpspreadsheet/vendor',
|
||||
'path' => '/libraries/phpspreadsheet/',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Uikit Folders
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addUikitFolder()
|
||||
{
|
||||
$uikit = $this->config->get('uikit', 0);
|
||||
if (2 == $uikit || 1 == $uikit)
|
||||
{
|
||||
// move the UIKIT Folder into place
|
||||
$this->component->appendArray('folders', [
|
||||
'folder' => 'uikit-v2',
|
||||
'path' => 'media',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
if (2 == $uikit || 3 == $uikit)
|
||||
{
|
||||
// move the UIKIT-3 Folder into place
|
||||
$this->component->appendArray('folders', [
|
||||
'folder' => 'uikit-v3',
|
||||
'path' => 'media',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Foo Table Folder
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addFooTableFolder()
|
||||
{
|
||||
if (!$this->config->get('footable', false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$footable_version = $this->config->get('footable_version', 2);
|
||||
|
||||
if (2 == $footable_version)
|
||||
{
|
||||
// move the footable folder into place
|
||||
$this->component->appendArray('folders', [
|
||||
'folder' => 'footable-v2',
|
||||
'path' => 'media',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
elseif (3 == $footable_version)
|
||||
{
|
||||
// move the footable folder into place
|
||||
$this->component->appendArray('folders', [
|
||||
'folder' => 'footable-v3',
|
||||
'path' => 'media',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Extra/Dynamic files
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function loadExtraFiles()
|
||||
{
|
||||
if ($this->component->isArray('files') ||
|
||||
$this->config->get('google_chart', false))
|
||||
{
|
||||
$this->addGoogleChartFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Google Chart Files
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addGoogleChartFiles()
|
||||
{
|
||||
if ($this->config->get('google_chart', false))
|
||||
{
|
||||
// move the google chart files
|
||||
$this->component->appendArray('files', [
|
||||
'file' => 'google.jsapi.js',
|
||||
'path' => 'media/js',
|
||||
'rename' => 0
|
||||
]);
|
||||
$this->component->appendArray('files', [
|
||||
'file' => 'chartbuilder.php',
|
||||
'path' => 'admin/helpers',
|
||||
'rename' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Folders
|
||||
*
|
||||
* @param object $versionData
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addFolders(object &$versionData)
|
||||
{
|
||||
if (!$this->component->isArray('folders'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// pointer tracker
|
||||
$pointer_tracker = 'h';
|
||||
foreach ($this->component->get('folders') as $custom)
|
||||
{
|
||||
// check type of target type
|
||||
$_target_type = 'c0mp0n3nt';
|
||||
if (isset($custom['target_type']))
|
||||
{
|
||||
$_target_type = $custom['target_type'];
|
||||
}
|
||||
|
||||
// for good practice
|
||||
$this->pathfix->set(
|
||||
$custom, ['path', 'folder', 'folderpath']
|
||||
);
|
||||
|
||||
// fix custom path
|
||||
if (isset($custom['path'])
|
||||
&& StringHelper::check($custom['path']))
|
||||
{
|
||||
$custom['path'] = trim((string) $custom['path'], '/');
|
||||
}
|
||||
|
||||
// by default custom path is true
|
||||
$customPath = 'custom';
|
||||
|
||||
// set full path if this is a full path folder
|
||||
if (!isset($custom['folder']) && isset($custom['folderpath']))
|
||||
{
|
||||
// update the dynamic path
|
||||
$custom['folderpath'] = $this->dynamicpath->update(
|
||||
$custom['folderpath']
|
||||
);
|
||||
|
||||
// set the folder path with / if does not have a drive/windows full path
|
||||
$custom['folder'] = (preg_match(
|
||||
'/^[a-z]:/i', $custom['folderpath']
|
||||
)) ? trim($custom['folderpath'], '/')
|
||||
: '/' . trim($custom['folderpath'], '/');
|
||||
|
||||
// remove the file path
|
||||
unset($custom['folderpath']);
|
||||
|
||||
// triget fullpath
|
||||
$customPath = 'full';
|
||||
}
|
||||
|
||||
// make sure we use the correct name
|
||||
$pathArray = (array) explode('/', (string) $custom['path']);
|
||||
$lastFolder = end($pathArray);
|
||||
|
||||
// only rename folder if last has folder name
|
||||
if (isset($custom['rename']) && $custom['rename'] == 1)
|
||||
{
|
||||
$custom['path'] = str_replace(
|
||||
'/' . $lastFolder, '', (string) $custom['path']
|
||||
);
|
||||
$rename = 'new';
|
||||
$newname = $lastFolder;
|
||||
}
|
||||
elseif ('full' === $customPath)
|
||||
{
|
||||
// make sure we use the correct name
|
||||
$folderArray = (array) explode('/', (string) $custom['folder']);
|
||||
$lastFolder = end($folderArray);
|
||||
$rename = 'new';
|
||||
$newname = $lastFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
$rename = false;
|
||||
$newname = '';
|
||||
}
|
||||
|
||||
// insure we have no duplicates
|
||||
$key_pointer = StringHelper::safe(
|
||||
$custom['folder']
|
||||
) . '_f' . $pointer_tracker;
|
||||
|
||||
$pointer_tracker++;
|
||||
|
||||
// fix custom path
|
||||
$custom['path'] = ltrim((string) $custom['path'], '/');
|
||||
|
||||
// set new folder to object
|
||||
$versionData->move->static->{$key_pointer} = new \stdClass();
|
||||
$versionData->move->static->{$key_pointer}->naam = str_replace('//', '/', (string) $custom['folder']);
|
||||
$versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path'];
|
||||
$versionData->move->static->{$key_pointer}->rename = $rename;
|
||||
$versionData->move->static->{$key_pointer}->newName = $newname;
|
||||
$versionData->move->static->{$key_pointer}->type = 'folder';
|
||||
$versionData->move->static->{$key_pointer}->custom = $customPath;
|
||||
|
||||
// set the target if type and id is found
|
||||
if (isset($custom['target_id']) && isset($custom['target_type']))
|
||||
{
|
||||
$versionData->move->static->{$key_pointer}->_target = [
|
||||
'key' => $custom['target_id'] . '_' . $custom['target_type'],
|
||||
'type' => $custom['target_type']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->component->remove('folders');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Files
|
||||
*
|
||||
* @param object $versionData
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function addFiles(object &$versionData)
|
||||
{
|
||||
if (!$this->component->isArray('files')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// pointer tracker
|
||||
$pointer_tracker = 'h';
|
||||
foreach ($this->component->get('files') as $custom)
|
||||
{
|
||||
// check type of target type
|
||||
$_target_type = 'c0mp0n3nt';
|
||||
if (isset($custom['target_type']))
|
||||
{
|
||||
$_target_type = $custom['target_type'];
|
||||
}
|
||||
|
||||
// for good practice
|
||||
$this->pathfix->set(
|
||||
$custom, ['path', 'file', 'filepath']
|
||||
);
|
||||
|
||||
// by default custom path is true
|
||||
$customPath = 'custom';
|
||||
|
||||
// set full path if this is a full path file
|
||||
if (!isset($custom['file']) && isset($custom['filepath']))
|
||||
{
|
||||
// update the dynamic path
|
||||
$custom['filepath'] = $this->dynamicpath->update(
|
||||
$custom['filepath']
|
||||
);
|
||||
|
||||
// set the file path with / if does not have a drive/windows full path
|
||||
$custom['file'] = (preg_match('/^[a-z]:/i', $custom['filepath']))
|
||||
? trim($custom['filepath'], '/') : '/' . trim($custom['filepath'], '/');
|
||||
|
||||
// remove the file path
|
||||
unset($custom['filepath']);
|
||||
|
||||
// triget fullpath
|
||||
$customPath = 'full';
|
||||
}
|
||||
|
||||
// make sure we have not duplicates
|
||||
$key_pointer = StringHelper::safe(
|
||||
$custom['file']
|
||||
) . '_g' . $pointer_tracker;
|
||||
|
||||
$pointer_tracker++;
|
||||
|
||||
// set new file to object
|
||||
$versionData->move->static->{$key_pointer} = new \stdClass();
|
||||
$versionData->move->static->{$key_pointer}->naam = str_replace('//', '/', (string) $custom['file']);
|
||||
|
||||
// update the dynamic component name placholders in file names
|
||||
$custom['path'] = $this->placeholder->update_(
|
||||
$custom['path']
|
||||
);
|
||||
|
||||
// get the path info
|
||||
$pathInfo = pathinfo((string) $custom['path']);
|
||||
if (isset($pathInfo['extension']) && $pathInfo['extension'])
|
||||
{
|
||||
$pathInfo['dirname'] = trim($pathInfo['dirname'], '/');
|
||||
|
||||
// set the info
|
||||
$versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $pathInfo['dirname'];
|
||||
$versionData->move->static->{$key_pointer}->rename = 'new';
|
||||
$versionData->move->static->{$key_pointer}->newName = $pathInfo['basename'];
|
||||
}
|
||||
elseif ('full' === $customPath)
|
||||
{
|
||||
// fix custom path
|
||||
$custom['path'] = ltrim((string) $custom['path'], '/');
|
||||
|
||||
// get file array
|
||||
$fileArray = (array) explode('/', (string) $custom['file']);
|
||||
|
||||
// set the info
|
||||
$versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path'];
|
||||
$versionData->move->static->{$key_pointer}->rename = 'new';
|
||||
$versionData->move->static->{$key_pointer}->newName = end($fileArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
// fix custom path
|
||||
$custom['path'] = ltrim((string) $custom['path'], '/');
|
||||
|
||||
// set the info
|
||||
$versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path'];
|
||||
$versionData->move->static->{$key_pointer}->rename = false;
|
||||
}
|
||||
|
||||
$versionData->move->static->{$key_pointer}->type = 'file';
|
||||
$versionData->move->static->{$key_pointer}->custom = $customPath;
|
||||
|
||||
// set the target if type and id is found
|
||||
if (isset($custom['target_id'])
|
||||
&& isset($custom['target_type']))
|
||||
{
|
||||
$versionData->move->static->{$key_pointer}->_target = [
|
||||
'key' => $custom['target_id'] . '_' . $custom['target_type'],
|
||||
'type' => $custom['target_type']
|
||||
];
|
||||
}
|
||||
|
||||
// check if file should be updated
|
||||
if (!isset($custom['notnew']) || $custom['notnew'] == 0
|
||||
|| $custom['notnew'] != 1)
|
||||
{
|
||||
$this->registry->appendArray('files.not.new', $key_pointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// update the file content
|
||||
$this->registry->set('update.file.content.' . $key_pointer, true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->component->remove('files');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component\Settings;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Paths;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Folder;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Build/Create Component Structure
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Structure
|
||||
{
|
||||
/**
|
||||
* Compiler Component Joomla Version Settings
|
||||
*
|
||||
* @var Settings
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Settings $settings;
|
||||
|
||||
/**
|
||||
* Compiler Paths
|
||||
*
|
||||
* @var Paths
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Paths $paths;
|
||||
|
||||
/**
|
||||
* Compiler Utilities Folder
|
||||
*
|
||||
* @var Folder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Folder $folder;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Settings|null $settings The compiler component joomla version settings object.
|
||||
* @param Paths|null $paths The compiler paths object.
|
||||
* @param Folder|null $folder The compiler folder object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Settings $settings = null, ?Paths $paths = null, ?Folder $folder = null)
|
||||
{
|
||||
$this->settings = $settings ?: Compiler::_('Component.Settings');
|
||||
$this->paths = $paths ?: Compiler::_('Utilities.Paths');
|
||||
$this->folder = $folder ?: Compiler::_('Utilities.Folder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Component Structure
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function build(): bool
|
||||
{
|
||||
if ($this->settings->exists())
|
||||
{
|
||||
// setup the main component path
|
||||
$this->folder->create($this->paths->component_path);
|
||||
|
||||
// build the version structure
|
||||
$this->folders(
|
||||
$this->settings->structure(),
|
||||
$this->paths->component_path
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the folder and subfolders
|
||||
*
|
||||
* @param object $folders The object[] of folders
|
||||
* @param string $path The path
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function folders(object $folders, string $path)
|
||||
{
|
||||
foreach ($folders as $folder => $sub_folders)
|
||||
{
|
||||
$new_path = $path . '/' . $folder;
|
||||
$this->folder->create($new_path);
|
||||
|
||||
if (ObjectHelper::check($sub_folders))
|
||||
{
|
||||
$this->folders($sub_folders, $new_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component\Settings;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Model\Createdate;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Model\Modifieddate;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Structure;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
|
||||
|
||||
/**
|
||||
* Multiple Files and Folders Builder Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Structuremultiple
|
||||
{
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Component Joomla Version Settings
|
||||
*
|
||||
* @var Settings
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Settings $settings;
|
||||
|
||||
/**
|
||||
* Compiler Component
|
||||
*
|
||||
* @var Component
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Component $component;
|
||||
|
||||
/**
|
||||
* Compiler Model Createdate
|
||||
*
|
||||
* @var Createdate
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Createdate $createdate;
|
||||
|
||||
/**
|
||||
* Compiler Model Modifieddate
|
||||
*
|
||||
* @var Modifieddate
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Modifieddate $modifieddate;
|
||||
|
||||
/**
|
||||
* Compiler Utility to Build Structure
|
||||
*
|
||||
* @var Structure
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Structure $structure;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param Settings|null $settings The compiler component Joomla version settings object.
|
||||
* @param Component|null $component The component class.
|
||||
* @param Createdate|null $createdate The compiler model to get create date class.
|
||||
* @param Modifieddate|null $modifieddate The compiler model to get modified date class.
|
||||
* @param Structure|null $structure The compiler structure to build dynamic folder and files class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Registry $registry = null,
|
||||
?Settings $settings = null, ?Component $component = null,
|
||||
?Createdate $createdate = null, ?Modifieddate $modifieddate = null,
|
||||
?Structure $structure = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->settings = $settings ?: Compiler::_('Component.Settings');
|
||||
$this->component = $component ?: Compiler::_('Component');
|
||||
$this->createdate = $createdate ?: Compiler::_('Model.Createdate');
|
||||
$this->modifieddate = $modifieddate ?: Compiler::_('Model.Modifieddate');
|
||||
$this->structure = $structure ?: Compiler::_('Utilities.Structure');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Multiple Files & Folders
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function build(): bool
|
||||
{
|
||||
$success = false;
|
||||
|
||||
if ($this->settings->exists())
|
||||
{
|
||||
$success = $this->admin();
|
||||
$success = $this->site() || $success;
|
||||
$success = $this->custom() || $success;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Dynamic Admin Files & Folders
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function admin(): bool
|
||||
{
|
||||
if (!$this->component->isArray('admin_views'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if we have a dynamic dashboard
|
||||
if (!$this->registry->get('build.dashboard'))
|
||||
{
|
||||
// setup the default dashboard
|
||||
$target = ['admin' => $this->component->get('name_code')];
|
||||
$this->structure->build($target, 'dashboard');
|
||||
}
|
||||
|
||||
$config = [];
|
||||
$checkin = false;
|
||||
|
||||
foreach ($this->component->get('admin_views') as $view)
|
||||
{
|
||||
if (!$this->isValidAdminView($view, $config))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->buildAdminView($view, $config);
|
||||
|
||||
// quick set of checkin once
|
||||
if (!$checkin && isset($view['checkin']) && $view['checkin'] == 1)
|
||||
{
|
||||
// switch to add checking to config
|
||||
$checkin = true;
|
||||
$this->config->set('add_checkin', $checkin);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Dynamic Site Files & Folders
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function site(): bool
|
||||
{
|
||||
if (!$this->component->isArray('site_views'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = [];
|
||||
|
||||
foreach ($this->component->get('site_views') as $view)
|
||||
{
|
||||
if (!$this->isValidView($view, $config))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->buildView($view, $config, 'site');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Dynamic Custom Admin Files & Folders
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function custom(): bool
|
||||
{
|
||||
if (!$this->component->isArray('custom_admin_views'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = [];
|
||||
|
||||
foreach ($this->component->get('custom_admin_views') as $view)
|
||||
{
|
||||
if (!$this->isValidView($view, $config))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->buildView($view, $config, 'custom_admin');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the view is a valid view
|
||||
*
|
||||
* @param array $view
|
||||
* @param array $config
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function isValidAdminView(array $view, array &$config): bool
|
||||
{
|
||||
if (!isset($view['settings']) || !ObjectHelper::check($view['settings'])
|
||||
|| ((!isset($view['settings']->name_list) || $view['settings']->name_list == 'null')
|
||||
&& (!isset($view['settings']->name_single) || $view['settings']->name_single == 'null')))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$created = $this->createdate->get($view);
|
||||
$modified = $this->modifieddate->get($view);
|
||||
|
||||
$config = [
|
||||
Placefix::_h('CREATIONDATE') => $created,
|
||||
Placefix::_h('BUILDDATE') => $modified,
|
||||
Placefix::_h('VERSION') => $view['settings']->version
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the view is a valid view
|
||||
*
|
||||
* @param array $view
|
||||
* @param array $config
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function isValidView(array $view, array &$config): bool
|
||||
{
|
||||
if (!isset($view['settings']) || !ObjectHelper::check($view['settings'])
|
||||
|| !isset($view['settings']->main_get)
|
||||
|| !ObjectHelper::check($view['settings']->main_get)
|
||||
|| !isset($view['settings']->main_get->gettype)
|
||||
|| ($view['settings']->main_get->gettype != 1 && $view['settings']->main_get->gettype != 2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$created = $this->createdate->get($view);
|
||||
$modified = $this->modifieddate->get($view);
|
||||
|
||||
$config = [
|
||||
Placefix::_h('CREATIONDATE') => $created,
|
||||
Placefix::_h('BUILDDATE') => $modified,
|
||||
Placefix::_h('VERSION') => $view['settings']->version
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the admin view
|
||||
*
|
||||
* @param array $view
|
||||
* @param array $config
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function buildAdminView(array $view, array $config)
|
||||
{
|
||||
// build the admin edit view
|
||||
if ($view['settings']->name_single != 'null')
|
||||
{
|
||||
$target = ['admin' => $view['settings']->name_single];
|
||||
$this->structure->build($target, 'single', false, $config);
|
||||
|
||||
// build the site edit view (of this admin view)
|
||||
if (isset($view['edit_create_site_view'])
|
||||
&& is_numeric($view['edit_create_site_view'])
|
||||
&& $view['edit_create_site_view'] > 0)
|
||||
{
|
||||
// setup the front site edit-view files
|
||||
$target = ['site' => $view['settings']->name_single];
|
||||
$this->structure->build($target, 'edit', false, $config);
|
||||
}
|
||||
}
|
||||
|
||||
// build the list view
|
||||
if ($view['settings']->name_list != 'null')
|
||||
{
|
||||
$target = ['admin' => $view['settings']->name_list];
|
||||
$this->structure->build($target, 'list', false, $config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the custom view
|
||||
*
|
||||
* @param array $view
|
||||
* @param array $config
|
||||
* @param string $type
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function buildView(array $view, array $config, string $type)
|
||||
{
|
||||
$target = [$type => $view['settings']->code];
|
||||
$view_type = ($view['settings']->main_get->gettype == 1) ? 'single' : 'list';
|
||||
|
||||
$this->structure->build($target, $view_type, false, $config);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,609 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component\Settings;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Content;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Component;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Counter;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Paths;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Files;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
|
||||
|
||||
/**
|
||||
* Single Files and Folders Builder Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Structuresingle
|
||||
{
|
||||
/**
|
||||
* The new name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $newName;
|
||||
|
||||
/**
|
||||
* Current Full Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $currentFullPath;
|
||||
|
||||
/**
|
||||
* Package Full Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $packageFullPath;
|
||||
|
||||
/**
|
||||
* ZIP Full Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $zipFullPath;
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Component Joomla Version Settings
|
||||
*
|
||||
* @var Settings
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Settings $settings;
|
||||
|
||||
/**
|
||||
* Compiler Component
|
||||
*
|
||||
* @var Component
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Component $component;
|
||||
|
||||
/**
|
||||
* Compiler Content
|
||||
*
|
||||
* @var Content
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Content $content;
|
||||
|
||||
/**
|
||||
* Compiler Counter
|
||||
*
|
||||
* @var Counter
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Counter $counter;
|
||||
|
||||
/**
|
||||
* Compiler Paths
|
||||
*
|
||||
* @var Paths
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Paths $paths;
|
||||
|
||||
/**
|
||||
* Compiler Utilities Files
|
||||
*
|
||||
* @var Files
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Files $files;
|
||||
|
||||
/**
|
||||
* Application object.
|
||||
*
|
||||
* @var CMSApplication
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected CMSApplication $app;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param Settings|null $settings The compiler component Joomla version settings object.
|
||||
* @param Component|null $component The component class.
|
||||
* @param Content|null $content The compiler content object.
|
||||
* @param Counter|null $counter The compiler counter object.
|
||||
* @param Paths|null $paths The compiler paths object.
|
||||
* @param Files|null $files The compiler files object.
|
||||
* @param CMSApplication|null $app The CMS Application object.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Registry $registry = null,
|
||||
?Settings $settings = null, ?Component $component = null,
|
||||
?Content $content = null, ?Counter $counter = null, ?Paths $paths = null,
|
||||
?Files $files = null, ?CMSApplication $app = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->settings = $settings ?: Compiler::_('Component.Settings');
|
||||
$this->component = $component ?: Compiler::_('Component');
|
||||
$this->content = $content ?: Compiler::_('Content');
|
||||
$this->counter = $counter ?: Compiler::_('Utilities.Counter');
|
||||
$this->paths = $paths ?: Compiler::_('Utilities.Paths');
|
||||
$this->files = $files ?: Compiler::_('Utilities.Files');
|
||||
$this->app = $app ?: Factory::getApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Single Files & Folders
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function build(): bool
|
||||
{
|
||||
if ($this->settings->exists())
|
||||
{
|
||||
// TODO needs more looking at this must be dynamic actually
|
||||
$this->registry->appendArray('files.not.new', 'LICENSE.txt');
|
||||
|
||||
// do license check
|
||||
$LICENSE = $this->doLicenseCheck();
|
||||
|
||||
// do README check
|
||||
$README = $this->doReadmeCheck();
|
||||
|
||||
// start moving
|
||||
foreach ($this->settings->single() as $target => $details)
|
||||
{
|
||||
// if not gnu/gpl license dont add the LICENSE.txt file
|
||||
if ($details->naam === 'LICENSE.txt' && !$LICENSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// if not needed do not add
|
||||
if (($details->naam === 'README.md' || $details->naam === 'README.txt')
|
||||
&& !$README)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// set new name
|
||||
$this->setNewName($details);
|
||||
|
||||
// set all paths
|
||||
$this->setPaths($details);
|
||||
|
||||
// check if the path exists
|
||||
if ($this->pathExist($details))
|
||||
{
|
||||
// set the target
|
||||
$this->setTarget($target, $details);
|
||||
}
|
||||
|
||||
// set dynamic target as needed
|
||||
$this->setDynamicTarget($details);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if license must be added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function doLicenseCheck(): bool
|
||||
{
|
||||
$licenseChecker = strtolower((string) $this->component->get('license', ''));
|
||||
|
||||
if (strpos($licenseChecker, 'gnu') !== false
|
||||
&& strpos(
|
||||
$licenseChecker, '2'
|
||||
) !== false
|
||||
&& (strpos($licenseChecker, 'gpl') !== false
|
||||
|| strpos(
|
||||
$licenseChecker, 'General public license'
|
||||
) !== false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if readme must be added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function doReadmeCheck(): bool
|
||||
{
|
||||
if ($this->component->get('addreadme', false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the new name
|
||||
*
|
||||
* @param object $details
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function setNewName(object $details)
|
||||
{
|
||||
// do the file renaming
|
||||
if (isset($details->rename) && $details->rename)
|
||||
{
|
||||
if ($details->rename === 'new')
|
||||
{
|
||||
$this->newName = $details->newName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->newName = str_replace(
|
||||
$details->rename,
|
||||
$this->config->component_code_name,
|
||||
(string) $details->naam
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->newName = $details->naam;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all needed paths
|
||||
*
|
||||
* @param object $details
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function setPaths(object $details)
|
||||
{
|
||||
// check if we have a target value
|
||||
if (isset($details->_target))
|
||||
{
|
||||
// set destination path
|
||||
$zipPath = str_replace(
|
||||
$details->_target['type'] . '/', '', (string) $details->path
|
||||
);
|
||||
$path = str_replace(
|
||||
$details->_target['type'] . '/',
|
||||
$this->registry->get('dynamic_paths.' . $details->_target['key'], '') . '/',
|
||||
(string) $details->path
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set destination path
|
||||
$zipPath = str_replace('c0mp0n3nt/', '', (string) $details->path);
|
||||
$path = str_replace(
|
||||
'c0mp0n3nt/', $this->paths->component_path . '/', (string) $details->path
|
||||
);
|
||||
}
|
||||
|
||||
// set the template folder path
|
||||
$templatePath = (isset($details->custom) && $details->custom)
|
||||
? (($details->custom !== 'full') ? $this->paths->template_path_custom
|
||||
. '/' : '') : $this->paths->template_path . '/';
|
||||
|
||||
// set the final paths
|
||||
$currentFullPath = (preg_match('/^[a-z]:/i', (string) $details->naam)) ? $details->naam
|
||||
: $templatePath . '/' . $details->naam;
|
||||
|
||||
$this->currentFullPath = str_replace('//', '/', (string) $currentFullPath);
|
||||
|
||||
$this->packageFullPath = str_replace('//', '/', $path . '/' . $this->newName);
|
||||
|
||||
$this->zipFullPath = str_replace(
|
||||
'//', '/', $zipPath . '/' . $this->newName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if path exists
|
||||
*
|
||||
* @param object $details
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function pathExist(object $details): bool
|
||||
{
|
||||
// check if this has a type
|
||||
if (!isset($details->type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// take action based on type
|
||||
elseif ($details->type === 'file' && !File::exists($this->currentFullPath))
|
||||
{
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEFILE_PATH_ERRORHTHREE'), 'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_FILE_PATH_BSB_DOES_NOT_EXIST_AND_WAS_NOT_ADDED',
|
||||
$this->currentFullPath
|
||||
), 'Error'
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
elseif ($details->type === 'folder' && !Folder::exists($this->currentFullPath))
|
||||
{
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEFOLDER_PATH_ERRORHTHREE'),
|
||||
'Error'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_THE_FOLDER_PATH_BSB_DOES_NOT_EXIST_AND_WAS_NOT_ADDED',
|
||||
$this->currentFullPath
|
||||
), 'Error'
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target based on target type
|
||||
*
|
||||
* @param string $target
|
||||
* @param object $details
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function setTarget(string $target, object $details)
|
||||
{
|
||||
// take action based on type
|
||||
if ($details->type === 'file')
|
||||
{
|
||||
// move the file
|
||||
$this->moveFile();
|
||||
|
||||
// register the file
|
||||
$this->registerFile($target, $details);
|
||||
}
|
||||
elseif ($details->type === 'folder')
|
||||
{
|
||||
// move the folder to its place
|
||||
Folder::copy(
|
||||
$this->currentFullPath, $this->packageFullPath, '', true
|
||||
);
|
||||
|
||||
// count the folder created
|
||||
$this->counter->folder++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move/Copy the file into place
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function moveFile()
|
||||
{
|
||||
// get base name && get the path only
|
||||
$packageFullPath0nly = str_replace(
|
||||
basename($this->packageFullPath), '', $this->packageFullPath
|
||||
);
|
||||
|
||||
// check if path exist, if not creat it
|
||||
if (!Folder::exists($packageFullPath0nly))
|
||||
{
|
||||
Folder::create($packageFullPath0nly);
|
||||
}
|
||||
|
||||
// move the file to its place
|
||||
File::copy($this->currentFullPath, $this->packageFullPath);
|
||||
|
||||
// count the file created
|
||||
$this->counter->file++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the file
|
||||
*
|
||||
* @param string $target
|
||||
* @param object $details
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function registerFile(string $target, object $details)
|
||||
{
|
||||
// store the new files
|
||||
if (!in_array($target, $this->registry->get('files.not.new', [])))
|
||||
{
|
||||
if (isset($details->_target))
|
||||
{
|
||||
$this->files->appendArray($details->_target['key'],
|
||||
[
|
||||
'path' => $this->packageFullPath,
|
||||
'name' => $this->newName,
|
||||
'zip' => $this->zipFullPath
|
||||
]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->files->appendArray('static',
|
||||
[
|
||||
'path' => $this->packageFullPath,
|
||||
'name' => $this->newName,
|
||||
'zip' => $this->zipFullPath
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ensure we update this file if needed
|
||||
if ($this->registry->exists('update.file.content.' . $target))
|
||||
{
|
||||
// remove the pointer
|
||||
$this->registry->remove('update.file.content.' . $target);
|
||||
|
||||
// set the full path
|
||||
$this->registry->set('update.file.content.' . $this->packageFullPath, $this->packageFullPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Dynamic Target
|
||||
*
|
||||
* @param object $details
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function setDynamicTarget(object $details)
|
||||
{
|
||||
// only add if no target found since those belong to plugins and modules
|
||||
if (!isset($details->_target))
|
||||
{
|
||||
// check if we should add the dynamic folder moving script to the installer script
|
||||
$checker = array_values((array) explode('/', $this->zipFullPath));
|
||||
|
||||
// TODO <-- this may not be the best way, will keep an eye on this.
|
||||
// We basicly only want to check if a folder is added that is not in the stdFolders array
|
||||
if (isset($checker[0])
|
||||
&& StringHelper::check($checker[0])
|
||||
&& !$this->settings->standardFolder($checker[0]))
|
||||
{
|
||||
// activate dynamic folders
|
||||
$this->setDynamicFolders();
|
||||
}
|
||||
elseif (count((array) $checker) == 2
|
||||
&& StringHelper::check($checker[0]))
|
||||
{
|
||||
$add_to_extra = false;
|
||||
|
||||
// set the target
|
||||
$eNAME = 'FILES';
|
||||
$ename = 'filename';
|
||||
|
||||
// this should not happen and must have been caught by the above if statment
|
||||
if ($details->type === 'folder')
|
||||
{
|
||||
// only folders outside the standard folder are added
|
||||
$eNAME = 'FOLDERS';
|
||||
$ename = 'folder';
|
||||
$add_to_extra = true;
|
||||
}
|
||||
// if this is a file, it can only be added to the admin/site/media folders
|
||||
// all other folders are moved as a whole so their files do not need to be declared
|
||||
elseif ($this->settings->standardFolder($checker[0])
|
||||
&& !$this->settings->standardRootFile($checker[1]))
|
||||
{
|
||||
$add_to_extra = true;
|
||||
}
|
||||
|
||||
// add if valid folder/file
|
||||
if ($add_to_extra)
|
||||
{
|
||||
// set the tab
|
||||
$eTab = Indent::_(2);
|
||||
if ('admin' === $checker[0])
|
||||
{
|
||||
$eTab = Indent::_(3);
|
||||
}
|
||||
|
||||
// set the xml file
|
||||
$key_ = 'EXSTRA_'
|
||||
. StringHelper::safe(
|
||||
$checker[0], 'U'
|
||||
) . '_' . $eNAME;
|
||||
$this->content->add($key_,
|
||||
PHP_EOL . $eTab . "<" . $ename . ">"
|
||||
. $checker[1] . "</" . $ename . ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the dynamic folders
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function setDynamicFolders()
|
||||
{
|
||||
// check if we should add the dynamic folder moving script to the installer script
|
||||
if (!$this->registry->get('set_move_folders_install_script'))
|
||||
{
|
||||
// add the setDynamicF0ld3rs() method to the install scipt.php file
|
||||
$this->registry->set('set_move_folders_install_script', true);
|
||||
|
||||
// set message that this was done (will still add a tutorial link later)
|
||||
$this->app->enqueueMessage(
|
||||
Text::_('COM_COMPONENTBUILDER_HR_HTHREEDYNAMIC_FOLDERS_WERE_DETECTEDHTHREE'),
|
||||
'Notice'
|
||||
);
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_A_METHOD_SETDYNAMICFZEROLDTHREERS_WAS_ADDED_TO_THE_INSTALL_BSCRIPTPHPB_OF_THIS_PACKAGE_TO_INSURE_THAT_THE_FOLDERS_ARE_COPIED_INTO_THE_CORRECT_PLACE_WHEN_THIS_COMPONENT_IS_INSTALLED'),
|
||||
'Notice'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user