Release of v4.1.1-beta2
Adds new JCB package engine. Fix issue with loading the Component Builder Wiki. Adds advanced version update notice to the Component Builder Dashboard. Completely refactors the class that builds the Component Dashboard. #1134. Adds Initialize, Reset, and Push functionality to the Repository entities. Completely refactors the SQL teaks and SQL dump classes. Changes J4 fields to allow NULL. Fix a bug in Dynamic Get JavaScript that causes table columns to not load.
This commit is contained in:
@ -28,12 +28,13 @@ use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Registry\Registry;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use VDM\Joomla\Gitea\Factory as GiteaFactory;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory as SearchFactory;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Componentbuilder\Remote\Version;
|
||||
use VDM\Joomla\Github\Factory as GithubFactory;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\SessionHelper;
|
||||
@ -41,6 +42,12 @@ use VDM\Joomla\Utilities\Base64Helper;
|
||||
use VDM\Joomla\Componentbuilder\Table\Search;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\FieldHelper;
|
||||
use VDM\Joomla\Utilities\FormHelper;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Componentbuilder\Fieldtype\Factory as FieldtypeFactory;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Factory as JoomlaPowerFactory;
|
||||
use VDM\Joomla\Componentbuilder\Power\Factory as PowerFactory;
|
||||
use VDM\Joomla\Componentbuilder\Snippet\Factory as SnippetFactory;
|
||||
use VDM\Joomla\Componentbuilder\Repository\Factory as RepositoryFactory;
|
||||
use Joomla\CMS\Form\FormHelper as FormFormHelper;
|
||||
|
||||
// No direct access to this file
|
||||
@ -87,95 +94,6 @@ class AjaxModel extends ListModel
|
||||
}
|
||||
|
||||
// Used in joomla_component
|
||||
/**
|
||||
* Will be removed since we are going the AI route... instead.
|
||||
*/
|
||||
public function getCrowdinDetails($identifier, $key)
|
||||
{
|
||||
// set the url
|
||||
$url = "https://api.crowdin.com/api/project/$identifier/info?key=$key&json";
|
||||
// get the details
|
||||
if (($details = FileHelper::getContent($url, false)) !== false && JsonHelper::check($details))
|
||||
{
|
||||
$details = json_decode($details, true);
|
||||
// check if there is an error
|
||||
if (isset($details['error']))
|
||||
{
|
||||
return ['error' => '<div class="alert alert-error">' . $details['error']['message'] . '<br /><br /><small>Identifier: ' . $identifier . '</small></div>'];
|
||||
}
|
||||
// build the details html
|
||||
if (isset($details['details']))
|
||||
{
|
||||
$html = '<div class="alert alert-success" id="crowdin_message">';
|
||||
$html .= '<h1>' . Text::_('COM_COMPONENTBUILDER_COMPONENT_SUCCESSFULLY_LINKED') . '</h1>';
|
||||
$html .= '<h3>' . $details['details']['name'] . '</h3>';
|
||||
if (StringHelper::check($details['details']['description']))
|
||||
{
|
||||
$html .= '<p>';
|
||||
$html .= $details['details']['description'];
|
||||
$html .= '</p>';
|
||||
}
|
||||
$html .= '<ul>';
|
||||
$html .= '<li>Number of participants: <b>';
|
||||
$html .= $details['details']['participants_count'];
|
||||
$html .= '</b></li>';
|
||||
$html .= '<li>Total strings count: <b>';
|
||||
$html .= $details['details']['total_strings_count'];
|
||||
$html .= '</b></li>';
|
||||
$html .= '<li>Total words count: <b>';
|
||||
$html .= $details['details']['total_words_count'];
|
||||
$html .= '</b></li>';
|
||||
$html .= '<li>Created: <b>';
|
||||
$html .= ComponentbuilderHelper::fancyDate($details['details']['created']);
|
||||
$html .= '</b></li>';
|
||||
$html .= '<li>Last activity: <b>';
|
||||
$html .= ComponentbuilderHelper::fancyDate($details['details']['last_activity']);
|
||||
$html .= '</b></li>';
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
return ['html' => $html];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be removed since we are moving to the new SuperPowers distribution system.
|
||||
*/
|
||||
public function getJCBpackageInfo($package)
|
||||
{
|
||||
// convert URL
|
||||
$url = base64_decode($package);
|
||||
$url = str_replace('.zip', '.info', $url);
|
||||
|
||||
// check if url exist
|
||||
if ($info = FileHelper::getContent($url, false))
|
||||
{
|
||||
$_info = PackageFactory::_('Crypt')->decrypt($info, 'local.legacy');
|
||||
|
||||
// check if we had success
|
||||
if (!JsonHelper::check($_info))
|
||||
{
|
||||
$_info = PackageFactory::_('Crypt')->decrypt($info, 'local.fof');
|
||||
}
|
||||
|
||||
// check if we have json
|
||||
if (JsonHelper::check($_info))
|
||||
{
|
||||
$info = json_decode($_info, true);
|
||||
|
||||
return [
|
||||
'owner' => PackageFactory::_('Display.Details')->owner($info, true),
|
||||
'packages' => PackageFactory::_('Display.Details')->components($info)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'error' => Text::_('COM_COMPONENTBUILDER_JCB_PACKAGE_INFO_PATH_DOES_NOT_WORK_WE_ADVICE_YOU_BNOT_TO_CONTINUEB_WITH_THE_IMPORT_OF_THE_SELECTED_PACKAGE')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the component details as an HTML display and metadata.
|
||||
*
|
||||
@ -361,172 +279,46 @@ class AjaxModel extends ListModel
|
||||
|
||||
return implode("\n", $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be removed, since we will change to workflows soon :)
|
||||
*/
|
||||
public function getCronPath($type)
|
||||
{
|
||||
return ['error' => '<span style="color: red;">' . Text::_('COM_COMPONENTBUILDER_NO_CRONJOB_PATHS_WAS_REMOVED_WE_WILL_CHANGE_TO_WORKFLOWS_SOON') . '</span>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* get Current Version
|
||||
* Get the current version notice.
|
||||
*
|
||||
* @param string|null $message The error messages if any.
|
||||
* Compares the installed version of the component with the latest available
|
||||
* version from the repository tags and returns an appropriate message.
|
||||
*
|
||||
* @return array The array of the notice or error message
|
||||
* @param string|null $version Optional version to compare if manifest version not found.
|
||||
*
|
||||
* @return array The array with 'notice' or 'error' and optional 'github-error' / 'gitea-error'.
|
||||
* @since 2.3.0
|
||||
* @since 5.1.1 Improved with support for pre-releases and intelligent tag grouping.
|
||||
*/
|
||||
public function getVersion($version = null)
|
||||
public function getVersion(?string $version = null): array
|
||||
{
|
||||
try
|
||||
{
|
||||
// get the repository tags
|
||||
$tags = GiteaFactory::_('Gitea.Repository.Tags')->list('joomla', 'Component-Builder');
|
||||
}
|
||||
catch (DomainException $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
catch (InvalidArgumentException $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
// do we have tags returned
|
||||
if (isset($tags[0]) && isset($tags[0]->name))
|
||||
{
|
||||
// get the local version
|
||||
$manifest = ComponentbuilderHelper::manifest();
|
||||
$local_version = (string) $manifest->version;
|
||||
$latest_version = '1.0.0';
|
||||
$download_link = "https://git.vdm.dev/api/v1/joomla/Component-Builder";
|
||||
|
||||
// Filter tags by major version matching the local version's major number
|
||||
$major_version = explode('.', $local_version)[0];
|
||||
$filtered_tags = array_filter($tags, function($tag) use ($major_version) {
|
||||
return strpos($tag->name, "v$major_version") === 0;
|
||||
});
|
||||
|
||||
if (!empty($filtered_tags))
|
||||
{
|
||||
// Sort versions to find the latest one
|
||||
usort($filtered_tags, function($a, $b) {
|
||||
return \version_compare($b->name, $a->name);
|
||||
});
|
||||
|
||||
$latest_version = trim($filtered_tags[0]->name, 'vV');
|
||||
|
||||
// download link of the latest version
|
||||
$download_link = $filtered_tags[0]->zipball_url;
|
||||
}
|
||||
|
||||
// now check if this version is out dated
|
||||
if (\version_compare($local_version, $latest_version) === 0)
|
||||
{
|
||||
return ['notice' => '<small><span style="color:green;"><span class="icon-shield"></span> ' . Text::_('COM_COMPONENTBUILDER_UP_TO_DATE') . '</span></small>'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if this is beta version
|
||||
if (\version_compare($local_version, $latest_version) > 0)
|
||||
{
|
||||
return ['notice' => '<small><span style="color:#F7B033;"><span class="icon-wrench"></span> ' . Text::_('COM_COMPONENTBUILDER_PRE_RELEASE') . '</span></small>'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ['notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span> ' . Text::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '!</span> <a style="color:green;" href="' .
|
||||
$download_link . '" title="' . Text::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '">' . Text::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getTokenForVersion();
|
||||
return (new Version(
|
||||
'joomengine', 'pkg-component-builder',
|
||||
'joomla', 'pkg-component-builder'
|
||||
))->get($version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions to get Token for version
|
||||
* Get the content of a GitHub wiki page.
|
||||
*
|
||||
* @param string|null $message The error messages if any.
|
||||
* @param string $name The name of the wiki page (default: 'Home').
|
||||
*
|
||||
* @return array The array of the error message
|
||||
* @since 2.3.0
|
||||
*/
|
||||
protected function getTokenForVersion(?string $message = null): array
|
||||
{
|
||||
// the URL
|
||||
$url = 'https://git.vdm.dev/user/settings/applications';
|
||||
|
||||
// create link
|
||||
$a = '<small><a style="color:#F7B033;" href="' . $url . '" title="';
|
||||
$a_ = '">';
|
||||
$_a = '</a></small>';
|
||||
|
||||
if ($message)
|
||||
{
|
||||
return ['error' => $a . $message . $a_ . Text::_('COM_COMPONENTBUILDER_GET_TOKEN') . $_a];
|
||||
}
|
||||
|
||||
return ['error' => $a . Text::_('COM_COMPONENTBUILDER_GET_TOKEN_FROM_VDM_TO_GET_UPDATE_NOTICE_AND_ADD_IT_TO_YOUR_GLOBAL_OPTIONS') . $a_ . Text::_('COM_COMPONENTBUILDER_GET_TOKEN') . $_a];
|
||||
}
|
||||
|
||||
/**
|
||||
* get Wiki Page
|
||||
*
|
||||
* @param string|null $message The error messages if any.
|
||||
*
|
||||
* @return array The array of the page or error message
|
||||
* @return array Associative array with 'page' or 'error' key.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function getWiki(string $name = 'Home'): array
|
||||
{
|
||||
try
|
||||
{
|
||||
// get the gitea wiki page im markdown
|
||||
$wiki = GiteaFactory::_('Gitea.Repository.Wiki')->get('joomla', 'Component-Builder', $name);
|
||||
try {
|
||||
$wiki = GithubFactory::_('Github.Repository.Wiki')
|
||||
->get('joomengine', 'Joomla-Component-Builder', $name);
|
||||
|
||||
// now render the page in HTML
|
||||
$page = $wiki->content ?? null;
|
||||
}
|
||||
catch (\DomainException $e)
|
||||
{
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
catch (\InvalidArgumentException $e)
|
||||
{
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
|
||||
// get the html
|
||||
if (isset($page))
|
||||
{
|
||||
return ['page' => $page];
|
||||
}
|
||||
|
||||
return $this->getTokenForWiki();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions to get Token for wiki
|
||||
*
|
||||
* @param string|null $message The error messages if any.
|
||||
*
|
||||
* @return array The array of the error message
|
||||
* @since 2.3.0
|
||||
*/
|
||||
protected function getTokenForWiki(?string $message = null): array
|
||||
{
|
||||
if ($message)
|
||||
{
|
||||
return ['error' => $message];
|
||||
if (!empty($wiki->content)) {
|
||||
return ['page' => base64_decode($wiki->content)];
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
|
||||
return ['error' => Text::_('COM_COMPONENTBUILDER_THE_WIKI_CAN_ONLY_BE_LOADED_WHEN_YOUR_JCB_SYSTEM_HAS_INTERNET_CONNECTION')];
|
||||
@ -4320,132 +4112,6 @@ class AjaxModel extends ListModel
|
||||
}
|
||||
|
||||
// Used in snippet
|
||||
|
||||
public function getSnippets($libraries)
|
||||
{
|
||||
if (JsonHelper::check($libraries))
|
||||
{
|
||||
$libraries = json_decode($libraries, true);
|
||||
}
|
||||
// check if we have an array
|
||||
if (UtilitiesArrayHelper::check($libraries))
|
||||
{
|
||||
// insure we only have int values
|
||||
if ($libraries = $this->checkLibraries($libraries))
|
||||
{
|
||||
// Get a db connection.
|
||||
$db = Factory::getDbo();
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName( array('a.id') ));
|
||||
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
$query->where($db->quoteName('a.published') . ' = 1');
|
||||
// check for country and region
|
||||
$query->where($db->quoteName('a.library') . ' IN ('. implode(',',$libraries) .')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkLibraries($libraries)
|
||||
{
|
||||
$bucket = array();
|
||||
$libraries = array_map( function($id) use (&$bucket) {
|
||||
// now get bundled libraries
|
||||
$type = GetHelper::var('library', (int) $id, 'id', 'type');
|
||||
if (2 == $type && $bundled = GetHelper::var('library', (int) $id, 'id', 'libraries'))
|
||||
{
|
||||
// make sure we have an array if it was json
|
||||
if (JsonHelper::check($bundled))
|
||||
{
|
||||
$bundled = json_decode($bundled, true);
|
||||
}
|
||||
// load in the values if we have an array
|
||||
if (UtilitiesArrayHelper::check($bundled))
|
||||
{
|
||||
foreach ($bundled as $lib)
|
||||
{
|
||||
$bucket[$lib] = $lib;
|
||||
}
|
||||
}
|
||||
elseif (is_numeric($bundled))
|
||||
{
|
||||
$bucket[(int) $bundled] = (int) $bundled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int) $id;
|
||||
}
|
||||
}, $libraries);
|
||||
// check if we have any bundled libraries
|
||||
if (UtilitiesArrayHelper::check($bucket))
|
||||
{
|
||||
foreach ($bucket as $lib)
|
||||
{
|
||||
$libraries[] = (int) $lib;
|
||||
}
|
||||
}
|
||||
// check that we have libraries
|
||||
if (UtilitiesArrayHelper::check($libraries))
|
||||
{
|
||||
$libraries = array_values(array_unique(array_filter($libraries, function($id){return is_int($id);})));
|
||||
// check if we have any libraries remaining
|
||||
if (UtilitiesArrayHelper::check($libraries))
|
||||
{
|
||||
return $libraries;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getSnippetDetails($key)
|
||||
{
|
||||
if (GuidHelper::valid($key))
|
||||
{
|
||||
$target = 'guid';
|
||||
}
|
||||
elseif (is_numeric($key))
|
||||
{
|
||||
$target = 'id';
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a db connection.
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.name', 'a.heading', 'a.usage', 'a.description', 'b.name', 'a.snippet', 'a.url', 'c.name'), array('name', 'heading', 'usage', 'description', 'type', 'snippet', 'url', 'library')));
|
||||
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
// From the componentbuilder_snippet_type table.
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.id') . ')');
|
||||
// From the componentbuilder_library table.
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.id') . ')');
|
||||
$query->where($db->quoteName('a.published') . ' >= 1');
|
||||
$query->where($db->quoteName('a.' . $target) . ' = ' . $db->quote($key));
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
$snippet = $db->loadObject();
|
||||
$snippet->snippet = base64_decode($snippet->snippet);
|
||||
// return found snippet settings
|
||||
return $snippet;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setSnippetGithub($path, $status)
|
||||
{
|
||||
// get user
|
||||
@ -4503,7 +4169,7 @@ class AjaxModel extends ListModel
|
||||
}
|
||||
}
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel('snippet', JPATH_COMPONENT_ADMINISTRATOR);
|
||||
$model = ComponentbuilderHelper::getModel('snippet', JPATH_ADMINISTRATOR . '/components/com_componentbuilder');
|
||||
// save the snippet
|
||||
if ($model->save($item))
|
||||
{
|
||||
@ -4569,7 +4235,7 @@ class AjaxModel extends ListModel
|
||||
if (ComponentbuilderHelper::getActions($type)->get('core.create'))
|
||||
{
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel($type, JPATH_COMPONENT_ADMINISTRATOR);
|
||||
$model = ComponentbuilderHelper::getModel($type, JPATH_ADMINISTRATOR . '/components/com_componentbuilder');
|
||||
// build array to save
|
||||
$item['id'] = 0;
|
||||
$item['name'] = $name;
|
||||
@ -4584,6 +4250,191 @@ class AjaxModel extends ListModel
|
||||
return $item->get('id');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves published snippet GUIDs for valid libraries.
|
||||
*
|
||||
* @param mixed $libraries JSON string or array of library GUIDs.
|
||||
*
|
||||
* @return array|false List of snippet IDs or false on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getSnippets($libraries)
|
||||
{
|
||||
// Decode JSON if required
|
||||
if (JsonHelper::check($libraries))
|
||||
{
|
||||
$libraries = json_decode($libraries, true);
|
||||
}
|
||||
|
||||
// Ensure we have a valid array of libraries
|
||||
if (!UtilitiesArrayHelper::check($libraries))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate and expand libraries
|
||||
$validatedLibraries = $this->expandAndValidateLibraries($libraries);
|
||||
|
||||
if (!$validatedLibraries)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('a.id'))
|
||||
->from($db->quoteName('#__componentbuilder_snippet', 'a'))
|
||||
->where($db->quoteName('a.published') . ' = 1')
|
||||
->where($db->quoteName('a.library') . ' IN ("' . implode('","', $validatedLibraries) . '")');
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return $db->getNumRows() ? $db->loadColumn() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and expands library GUIDs to ensure only integers and valid references remain.
|
||||
*
|
||||
* @param array $libraries The original list of library GUIDs.
|
||||
*
|
||||
* @return array|false Sanitized and validated list of libraries, or false.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function expandAndValidateLibraries(array $libraries)
|
||||
{
|
||||
$expanded = [];
|
||||
|
||||
foreach ($libraries as $guid)
|
||||
{
|
||||
$guid = (string) $guid;
|
||||
$type = GetHelper::var('library', $guid, 'guid', 'type');
|
||||
|
||||
if ((int) $type === 2)
|
||||
{
|
||||
$bundled = GetHelper::var('library', $guid, 'guid', 'libraries');
|
||||
|
||||
if (JsonHelper::check($bundled))
|
||||
{
|
||||
$bundled = json_decode($bundled, true);
|
||||
}
|
||||
|
||||
if (UtilitiesArrayHelper::check($bundled))
|
||||
{
|
||||
foreach ($bundled as $lib)
|
||||
{
|
||||
$expanded[$lib] = $lib;
|
||||
}
|
||||
}
|
||||
elseif (is_numeric($bundled))
|
||||
{
|
||||
$expanded[$bundled] = $bundled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$expanded[$guid] = $guid;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove invalid entries and duplicates
|
||||
$valid = array_filter(array_unique($expanded), function ($guid) {
|
||||
return GuidHelper::valid($guid);
|
||||
});
|
||||
|
||||
return UtilitiesArrayHelper::check($valid) ? array_values($valid) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves snippet details by GUID or ID.
|
||||
*
|
||||
* @param string|int $key The snippet GUID (string) or ID (int).
|
||||
*
|
||||
* @return object|false The snippet data object or false on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getSnippetDetails($key)
|
||||
{
|
||||
$target = $this->resolveSnippetKeyField($key);
|
||||
|
||||
if ($target === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query
|
||||
->select($db->quoteName(
|
||||
[
|
||||
'a.name',
|
||||
'a.heading',
|
||||
'a.usage',
|
||||
'a.description',
|
||||
'b.name',
|
||||
'a.snippet',
|
||||
'a.url',
|
||||
'c.name'
|
||||
],
|
||||
[
|
||||
'name',
|
||||
'heading',
|
||||
'usage',
|
||||
'description',
|
||||
'type',
|
||||
'snippet',
|
||||
'url',
|
||||
'library'
|
||||
]
|
||||
))
|
||||
->from($db->quoteName('#__componentbuilder_snippet', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON ' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.guid'))
|
||||
->join('LEFT', $db->quoteName('#__componentbuilder_library', 'c') . ' ON ' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.guid'))
|
||||
->where($db->quoteName('a.published') . ' >= 1')
|
||||
->where($db->quoteName("a.$target") . ' = ' . $db->quote($key));
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows() > 0)
|
||||
{
|
||||
$snippet = $db->loadObject();
|
||||
|
||||
if (isset($snippet->snippet))
|
||||
{
|
||||
$snippet->snippet = base64_decode($snippet->snippet);
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves whether the given key is a GUID or numeric ID and returns the appropriate field.
|
||||
*
|
||||
* @param mixed $key The value used to identify the snippet.
|
||||
*
|
||||
* @return string|false 'guid', 'id', or false if invalid.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function resolveSnippetKeyField($key)
|
||||
{
|
||||
if (GuidHelper::valid($key))
|
||||
{
|
||||
return 'guid';
|
||||
}
|
||||
|
||||
if (is_numeric($key))
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used in validation_rule
|
||||
@ -5434,4 +5285,225 @@ class AjaxModel extends ListModel
|
||||
return ['error' => Text::_('COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN')];
|
||||
}
|
||||
|
||||
|
||||
// Used in initialization_selection
|
||||
/**
|
||||
* Method to get the target power
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getTargetAreaPower($power): ?string
|
||||
{
|
||||
return $this->powers[$power] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the power get class
|
||||
*
|
||||
* @param string $repo The repo to list index
|
||||
* @param string $area The target area
|
||||
*
|
||||
* @return array
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getRepoIndex(string $repo, string $area): array
|
||||
{
|
||||
if (!GuidHelper::valid($repo))
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_REPO_SELECTED')];
|
||||
}
|
||||
|
||||
if (($Power = $this->getTargetAreaPower($area)) === null)
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_AREA_SELECTED')];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$class = $this->getPowerClass($Power, "{$area}.Remote.Get");
|
||||
if ($class !== null)
|
||||
{
|
||||
$result = $class->list($repo);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
|
||||
if (!empty($result))
|
||||
{
|
||||
foreach($result as &$values)
|
||||
{
|
||||
// ensure we don't leak the repo token
|
||||
if (isset($values->token))
|
||||
{
|
||||
$values->token = '***redacted***';
|
||||
}
|
||||
}
|
||||
|
||||
return ['success' => true, 'index' => $result];
|
||||
}
|
||||
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_THE_REPO_INDEX_FAILED_TO_LOAD_PLEASE_TRY_AGAIN')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to initialize the selected powers
|
||||
*
|
||||
* @param string $repo The repo to list index
|
||||
* @param string $area The target area
|
||||
* @param array $selected The selected powers
|
||||
*
|
||||
* @return array
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function initSelectedPowers(string $repo, string $area, array $selected): array
|
||||
{
|
||||
if (!GuidHelper::valid($repo))
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_REPO_SELECTED')];
|
||||
}
|
||||
|
||||
if (($Power = $this->getTargetAreaPower($area)) === null)
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_AREA_SELECTED')];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
try
|
||||
{
|
||||
$class = $this->getPowerClass($Power, "{$area}.Remote.Get");
|
||||
if ($class !== null)
|
||||
{
|
||||
$repo_path = $class->path($repo);
|
||||
$result = $class->init($selected, $repo_path);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
|
||||
if ($result !== [])
|
||||
{
|
||||
return ['success' => true, 'result_log' => $result];
|
||||
}
|
||||
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_THE_REPO_INDEX_FAILED_TO_LOAD_PLEASE_TRY_AGAIN')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to initialize the selected packages
|
||||
*
|
||||
* @param string $repo The repo to list index
|
||||
* @param string $area The target area
|
||||
* @param array $selected The selected powers
|
||||
*
|
||||
* @return array
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function initSelectedPackages(string $repo, string $area, array $selected): array
|
||||
{
|
||||
if (!GuidHelper::valid($repo))
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_REPO_SELECTED')];
|
||||
}
|
||||
|
||||
if (($Power = $this->getTargetAreaPower($area)) === null)
|
||||
{
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_INVALID_AREA_SELECTED')];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
try
|
||||
{
|
||||
$class = $this->getPowerClass($Power, "Package.Builder.Get");
|
||||
$entity = $this->getPowerClass($Power, "{$area}.Remote.Get");
|
||||
if (!empty($selected) && $class !== null && $entity !== null)
|
||||
{
|
||||
$table = $entity->getTable();
|
||||
$repo_path = $entity->path($repo);
|
||||
$result = $class->init($table, $selected, $repo_path);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
|
||||
if ($this->hasIntResults($result))
|
||||
{
|
||||
return ['success' => true, 'result_log' => $result];
|
||||
}
|
||||
|
||||
return ['success' => false, 'message' => Text::_('COM_COMPONENTBUILDER_THE_INITIALIZATION_FAILED_PLEASE_TRY_AGAIN')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if at least one key in the array has a non-empty value.
|
||||
*
|
||||
* @param array $data The result array (with 'local', 'not_found', 'added' keys)
|
||||
*
|
||||
* @return bool True if some values are non-empty; false if all are empty.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected static function hasIntResults(array $data): bool
|
||||
{
|
||||
return (bool) array_filter($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The powers that we can initialize
|
||||
*
|
||||
* @var array
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected array $powers = [
|
||||
'AdminView' => 'PackageFactory',
|
||||
'Component' => 'PackageFactory',
|
||||
'CustomAdminView' => 'PackageFactory',
|
||||
'CustomCode' => 'PackageFactory',
|
||||
'DynamicGet' => 'PackageFactory',
|
||||
'Field' => 'PackageFactory',
|
||||
'Joomla.Fieldtype' => 'FieldtypeFactory',
|
||||
'Joomla.Power' => 'JoomlaPowerFactory',
|
||||
'Layout' => 'PackageFactory',
|
||||
'Library' => 'PackageFactory',
|
||||
'JoomlaModule' => 'PackageFactory',
|
||||
'JoomlaPlugin' => 'PackageFactory',
|
||||
'Power' => 'PowerFactory',
|
||||
'SiteView' => 'PackageFactory',
|
||||
'Snippet' => 'SnippetFactory',
|
||||
'Template' => 'PackageFactory',
|
||||
'ClassExtends' => 'PackageFactory',
|
||||
'ClassProperty' => 'PackageFactory',
|
||||
'ClassMethod' => 'PackageFactory',
|
||||
'Placeholder' => 'PackageFactory',
|
||||
'Repository' => 'RepositoryFactory'
|
||||
];
|
||||
|
||||
/**
|
||||
* Method to get the power get class
|
||||
*
|
||||
* @param string $factoryName The factory name
|
||||
* @param string $getClass The remote power class name
|
||||
*
|
||||
* @return mixed
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getPowerClass(string $factoryName, string $getClass)
|
||||
{
|
||||
return match ($factoryName) {
|
||||
'PowerFactory' => PowerFactory::_($getClass),
|
||||
'JoomlaPowerFactory' => JoomlaPowerFactory::_($getClass),
|
||||
'FieldtypeFactory' => FieldtypeFactory::_($getClass),
|
||||
'SnippetFactory' => SnippetFactory::_($getClass),
|
||||
'PackageFactory' => PackageFactory::_($getClass),
|
||||
'RepositoryFactory' => RepositoryFactory::_($getClass),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Helper\Compiler;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\Filesystem\Folder;
|
||||
use Joomla\Filesystem\File;
|
||||
use Joomla\CMS\Installer\InstallerHelper;
|
||||
use Joomla\CMS\Installer\Installer;
|
||||
|
@ -38,6 +38,233 @@ use VDM\Joomla\Utilities\StringHelper;
|
||||
*/
|
||||
class ComponentbuilderModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Represents the current user object.
|
||||
*
|
||||
* @var User The user object representing the current user.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected User $user;
|
||||
|
||||
/**
|
||||
* View groups of this component
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected array $viewGroups = [
|
||||
'main' => ['png.compiler', 'png.joomla_components', 'png.joomla_modules', 'png.joomla_plugins', 'png.powers', 'png.search', 'png.admin_views', 'png.custom_admin_views', 'png.site_views', 'png.template.add', 'png.templates', 'png.layouts', 'png.dynamic_get.add', 'png.dynamic_gets', 'png.custom_codes', 'png.placeholders', 'png.libraries', 'png.snippets', 'png.validation_rules', 'png.field.add', 'png.fields', 'png.fields.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_field', 'png.fieldtypes', 'png.fieldtypes.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_fieldtype', 'png.language_translations', 'png.languages', 'png.servers', 'png.repositories', 'png.help_documents'],
|
||||
];
|
||||
|
||||
/**
|
||||
* View access array.
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected array $viewAccess = [
|
||||
'compiler.submenu' => 'compiler.submenu',
|
||||
'compiler.dashboard_list' => 'compiler.dashboard_list',
|
||||
'search.access' => 'search.access',
|
||||
'search.submenu' => 'search.submenu',
|
||||
'search.dashboard_list' => 'search.dashboard_list',
|
||||
'joomla_component.create' => 'joomla_component.create',
|
||||
'joomla_components.access' => 'joomla_component.access',
|
||||
'joomla_component.access' => 'joomla_component.access',
|
||||
'joomla_components.submenu' => 'joomla_component.submenu',
|
||||
'joomla_components.dashboard_list' => 'joomla_component.dashboard_list',
|
||||
'joomla_module.create' => 'joomla_module.create',
|
||||
'joomla_modules.access' => 'joomla_module.access',
|
||||
'joomla_module.access' => 'joomla_module.access',
|
||||
'joomla_modules.submenu' => 'joomla_module.submenu',
|
||||
'joomla_modules.dashboard_list' => 'joomla_module.dashboard_list',
|
||||
'joomla_plugin.create' => 'joomla_plugin.create',
|
||||
'joomla_plugins.access' => 'joomla_plugin.access',
|
||||
'joomla_plugin.access' => 'joomla_plugin.access',
|
||||
'joomla_plugins.submenu' => 'joomla_plugin.submenu',
|
||||
'joomla_plugins.dashboard_list' => 'joomla_plugin.dashboard_list',
|
||||
'joomla_power.create' => 'joomla_power.create',
|
||||
'joomla_powers.access' => 'joomla_power.access',
|
||||
'joomla_power.access' => 'joomla_power.access',
|
||||
'joomla_powers.submenu' => 'joomla_power.submenu',
|
||||
'power.create' => 'power.create',
|
||||
'powers.access' => 'power.access',
|
||||
'power.access' => 'power.access',
|
||||
'powers.submenu' => 'power.submenu',
|
||||
'powers.dashboard_list' => 'power.dashboard_list',
|
||||
'admin_view.create' => 'admin_view.create',
|
||||
'admin_views.access' => 'admin_view.access',
|
||||
'admin_view.access' => 'admin_view.access',
|
||||
'admin_views.submenu' => 'admin_view.submenu',
|
||||
'admin_views.dashboard_list' => 'admin_view.dashboard_list',
|
||||
'custom_admin_views.access' => 'custom_admin_view.access',
|
||||
'custom_admin_view.access' => 'custom_admin_view.access',
|
||||
'custom_admin_views.submenu' => 'custom_admin_view.submenu',
|
||||
'custom_admin_views.dashboard_list' => 'custom_admin_view.dashboard_list',
|
||||
'site_views.access' => 'site_view.access',
|
||||
'site_view.access' => 'site_view.access',
|
||||
'site_views.submenu' => 'site_view.submenu',
|
||||
'site_views.dashboard_list' => 'site_view.dashboard_list',
|
||||
'templates.access' => 'template.access',
|
||||
'template.access' => 'template.access',
|
||||
'templates.submenu' => 'template.submenu',
|
||||
'templates.dashboard_list' => 'template.dashboard_list',
|
||||
'template.dashboard_add' => 'template.dashboard_add',
|
||||
'layouts.access' => 'layout.access',
|
||||
'layout.access' => 'layout.access',
|
||||
'layouts.submenu' => 'layout.submenu',
|
||||
'layouts.dashboard_list' => 'layout.dashboard_list',
|
||||
'dynamic_get.create' => 'dynamic_get.create',
|
||||
'dynamic_gets.access' => 'dynamic_get.access',
|
||||
'dynamic_get.access' => 'dynamic_get.access',
|
||||
'dynamic_gets.submenu' => 'dynamic_get.submenu',
|
||||
'dynamic_gets.dashboard_list' => 'dynamic_get.dashboard_list',
|
||||
'dynamic_get.dashboard_add' => 'dynamic_get.dashboard_add',
|
||||
'custom_code.create' => 'custom_code.create',
|
||||
'custom_codes.access' => 'custom_code.access',
|
||||
'custom_code.access' => 'custom_code.access',
|
||||
'custom_codes.submenu' => 'custom_code.submenu',
|
||||
'custom_codes.dashboard_list' => 'custom_code.dashboard_list',
|
||||
'class_extends.create' => 'class_extends.create',
|
||||
'class_extendings.access' => 'class_extends.access',
|
||||
'class_extends.access' => 'class_extends.access',
|
||||
'class_property.create' => 'class_property.create',
|
||||
'class_properties.access' => 'class_property.access',
|
||||
'class_property.access' => 'class_property.access',
|
||||
'class_method.create' => 'class_method.create',
|
||||
'class_methods.access' => 'class_method.access',
|
||||
'class_method.access' => 'class_method.access',
|
||||
'placeholder.create' => 'placeholder.create',
|
||||
'placeholders.access' => 'placeholder.access',
|
||||
'placeholder.access' => 'placeholder.access',
|
||||
'placeholders.submenu' => 'placeholder.submenu',
|
||||
'placeholders.dashboard_list' => 'placeholder.dashboard_list',
|
||||
'library.create' => 'library.create',
|
||||
'libraries.access' => 'library.access',
|
||||
'library.access' => 'library.access',
|
||||
'libraries.submenu' => 'library.submenu',
|
||||
'libraries.dashboard_list' => 'library.dashboard_list',
|
||||
'snippets.access' => 'snippet.access',
|
||||
'snippet.access' => 'snippet.access',
|
||||
'snippets.submenu' => 'snippet.submenu',
|
||||
'snippets.dashboard_list' => 'snippet.dashboard_list',
|
||||
'validation_rule.create' => 'validation_rule.create',
|
||||
'validation_rules.access' => 'validation_rule.access',
|
||||
'validation_rule.access' => 'validation_rule.access',
|
||||
'validation_rules.submenu' => 'validation_rule.submenu',
|
||||
'validation_rules.dashboard_list' => 'validation_rule.dashboard_list',
|
||||
'field.create' => 'field.create',
|
||||
'fields.access' => 'field.access',
|
||||
'field.access' => 'field.access',
|
||||
'fields.submenu' => 'field.submenu',
|
||||
'fields.dashboard_list' => 'field.dashboard_list',
|
||||
'field.dashboard_add' => 'field.dashboard_add',
|
||||
'fieldtype.create' => 'fieldtype.create',
|
||||
'fieldtypes.access' => 'fieldtype.access',
|
||||
'fieldtype.access' => 'fieldtype.access',
|
||||
'fieldtypes.submenu' => 'fieldtype.submenu',
|
||||
'fieldtypes.dashboard_list' => 'fieldtype.dashboard_list',
|
||||
'language_translation.create' => 'language_translation.create',
|
||||
'language_translations.access' => 'language_translation.access',
|
||||
'language_translation.access' => 'language_translation.access',
|
||||
'language_translations.submenu' => 'language_translation.submenu',
|
||||
'language_translations.dashboard_list' => 'language_translation.dashboard_list',
|
||||
'language.create' => 'language.create',
|
||||
'languages.access' => 'language.access',
|
||||
'language.access' => 'language.access',
|
||||
'languages.submenu' => 'language.submenu',
|
||||
'languages.dashboard_list' => 'language.dashboard_list',
|
||||
'server.create' => 'server.create',
|
||||
'servers.access' => 'server.access',
|
||||
'server.access' => 'server.access',
|
||||
'servers.submenu' => 'server.submenu',
|
||||
'servers.dashboard_list' => 'server.dashboard_list',
|
||||
'repository.create' => 'repository.create',
|
||||
'repositories.access' => 'repository.access',
|
||||
'repository.access' => 'repository.access',
|
||||
'repositories.submenu' => 'repository.submenu',
|
||||
'repositories.dashboard_list' => 'repository.dashboard_list',
|
||||
'help_document.create' => 'help_document.create',
|
||||
'help_documents.access' => 'help_document.access',
|
||||
'help_document.access' => 'help_document.access',
|
||||
'help_documents.submenu' => 'help_document.submenu',
|
||||
'help_documents.dashboard_list' => 'help_document.dashboard_list',
|
||||
'admin_fields.create' => 'admin_fields.create',
|
||||
'admins_fields.access' => 'admin_fields.access',
|
||||
'admin_fields.access' => 'admin_fields.access',
|
||||
'admin_fields_conditions.create' => 'admin_fields_conditions.create',
|
||||
'admins_fields_conditions.access' => 'admin_fields_conditions.access',
|
||||
'admin_fields_conditions.access' => 'admin_fields_conditions.access',
|
||||
'admin_fields_relations.create' => 'admin_fields_relations.create',
|
||||
'admins_fields_relations.access' => 'admin_fields_relations.access',
|
||||
'admin_fields_relations.access' => 'admin_fields_relations.access',
|
||||
'admin_custom_tabs.create' => 'admin_custom_tabs.create',
|
||||
'admins_custom_tabs.access' => 'admin_custom_tabs.access',
|
||||
'admin_custom_tabs.access' => 'admin_custom_tabs.access',
|
||||
'component_admin_views.create' => 'component_admin_views.create',
|
||||
'components_admin_views.access' => 'component_admin_views.access',
|
||||
'component_admin_views.access' => 'component_admin_views.access',
|
||||
'component_site_views.create' => 'component_site_views.create',
|
||||
'components_site_views.access' => 'component_site_views.access',
|
||||
'component_site_views.access' => 'component_site_views.access',
|
||||
'component_custom_admin_views.create' => 'component_custom_admin_views.create',
|
||||
'components_custom_admin_views.access' => 'component_custom_admin_views.access',
|
||||
'component_custom_admin_views.access' => 'component_custom_admin_views.access',
|
||||
'component_updates.create' => 'component_updates.create',
|
||||
'components_updates.access' => 'component_updates.access',
|
||||
'component_updates.access' => 'component_updates.access',
|
||||
'component_mysql_tweaks.create' => 'component_mysql_tweaks.create',
|
||||
'components_mysql_tweaks.access' => 'component_mysql_tweaks.access',
|
||||
'component_mysql_tweaks.access' => 'component_mysql_tweaks.access',
|
||||
'component_custom_admin_menus.create' => 'component_custom_admin_menus.create',
|
||||
'components_custom_admin_menus.access' => 'component_custom_admin_menus.access',
|
||||
'component_custom_admin_menus.access' => 'component_custom_admin_menus.access',
|
||||
'component_router.create' => 'component_router.create',
|
||||
'components_routers.access' => 'component_router.access',
|
||||
'component_router.access' => 'component_router.access',
|
||||
'component_config.create' => 'component_config.create',
|
||||
'components_config.access' => 'component_config.access',
|
||||
'component_config.access' => 'component_config.access',
|
||||
'component_dashboard.create' => 'component_dashboard.create',
|
||||
'components_dashboard.access' => 'component_dashboard.access',
|
||||
'component_dashboard.access' => 'component_dashboard.access',
|
||||
'component_files_folders.create' => 'component_files_folders.create',
|
||||
'components_files_folders.access' => 'component_files_folders.access',
|
||||
'component_files_folders.access' => 'component_files_folders.access',
|
||||
'component_placeholders.create' => 'component_placeholders.create',
|
||||
'components_placeholders.access' => 'component_placeholders.access',
|
||||
'component_placeholders.access' => 'component_placeholders.access',
|
||||
'component_plugins.create' => 'component_plugins.create',
|
||||
'components_plugins.access' => 'component_plugins.access',
|
||||
'component_plugins.access' => 'component_plugins.access',
|
||||
'component_modules.create' => 'component_modules.create',
|
||||
'components_modules.access' => 'component_modules.access',
|
||||
'component_modules.access' => 'component_modules.access',
|
||||
'snippet_type.create' => 'snippet_type.create',
|
||||
'snippet_types.access' => 'snippet_type.access',
|
||||
'snippet_type.access' => 'snippet_type.access',
|
||||
'library_config.create' => 'library_config.create',
|
||||
'libraries_config.access' => 'library_config.access',
|
||||
'library_config.access' => 'library_config.access',
|
||||
'library_files_folders_urls.create' => 'library_files_folders_urls.create',
|
||||
'libraries_files_folders_urls.access' => 'library_files_folders_urls.access',
|
||||
'library_files_folders_urls.access' => 'library_files_folders_urls.access',
|
||||
'joomla_module_updates.create' => 'joomla_module_updates.create',
|
||||
'joomla_modules_updates.access' => 'joomla_module_updates.access',
|
||||
'joomla_module_updates.access' => 'joomla_module_updates.access',
|
||||
'joomla_module_files_folders_urls.create' => 'joomla_module_files_folders_urls.create',
|
||||
'joomla_modules_files_folders_urls.access' => 'joomla_module_files_folders_urls.access',
|
||||
'joomla_module_files_folders_urls.access' => 'joomla_module_files_folders_urls.access',
|
||||
'joomla_plugin_groups.access' => 'joomla_plugin_group.access',
|
||||
'joomla_plugin_group.access' => 'joomla_plugin_group.access',
|
||||
'joomla_plugin_updates.create' => 'joomla_plugin_updates.create',
|
||||
'joomla_plugins_updates.access' => 'joomla_plugin_updates.access',
|
||||
'joomla_plugin_updates.access' => 'joomla_plugin_updates.access',
|
||||
'joomla_plugin_files_folders_urls.create' => 'joomla_plugin_files_folders_urls.create',
|
||||
'joomla_plugins_files_folders_urls.access' => 'joomla_plugin_files_folders_urls.access',
|
||||
'joomla_plugin_files_folders_urls.access' => 'joomla_plugin_files_folders_urls.access',
|
||||
];
|
||||
|
||||
/**
|
||||
* The styles array.
|
||||
*
|
||||
@ -59,402 +286,50 @@ class ComponentbuilderModel extends ListModel
|
||||
'administrator/components/com_componentbuilder/assets/js/admin.js'
|
||||
];
|
||||
|
||||
public function getIcons()
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($config = [], MVCFactoryInterface $factory = null)
|
||||
{
|
||||
// load user for access menus
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
// reset icon array
|
||||
$icons = [];
|
||||
// view groups array
|
||||
$viewGroups = array(
|
||||
'main' => array('png.compiler', 'png.joomla_components', 'png.joomla_modules', 'png.joomla_plugins', 'png.powers', 'png.search', 'png.admin_views', 'png.custom_admin_views', 'png.site_views', 'png.template.add', 'png.templates', 'png.layouts', 'png.dynamic_get.add', 'png.dynamic_gets', 'png.custom_codes', 'png.placeholders', 'png.libraries', 'png.snippets', 'png.validation_rules', 'png.field.add', 'png.fields', 'png.fields.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_field', 'png.fieldtypes', 'png.fieldtypes.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_fieldtype', 'png.language_translations', 'png.languages', 'png.servers', 'png.repositories', 'png.help_documents')
|
||||
);
|
||||
// view access array
|
||||
$viewAccess = [
|
||||
'compiler.submenu' => 'compiler.submenu',
|
||||
'compiler.dashboard_list' => 'compiler.dashboard_list',
|
||||
'search.access' => 'search.access',
|
||||
'search.submenu' => 'search.submenu',
|
||||
'search.dashboard_list' => 'search.dashboard_list',
|
||||
'joomla_component.create' => 'joomla_component.create',
|
||||
'joomla_components.access' => 'joomla_component.access',
|
||||
'joomla_component.access' => 'joomla_component.access',
|
||||
'joomla_components.submenu' => 'joomla_component.submenu',
|
||||
'joomla_components.dashboard_list' => 'joomla_component.dashboard_list',
|
||||
'joomla_module.create' => 'joomla_module.create',
|
||||
'joomla_modules.access' => 'joomla_module.access',
|
||||
'joomla_module.access' => 'joomla_module.access',
|
||||
'joomla_modules.submenu' => 'joomla_module.submenu',
|
||||
'joomla_modules.dashboard_list' => 'joomla_module.dashboard_list',
|
||||
'joomla_plugin.create' => 'joomla_plugin.create',
|
||||
'joomla_plugins.access' => 'joomla_plugin.access',
|
||||
'joomla_plugin.access' => 'joomla_plugin.access',
|
||||
'joomla_plugins.submenu' => 'joomla_plugin.submenu',
|
||||
'joomla_plugins.dashboard_list' => 'joomla_plugin.dashboard_list',
|
||||
'joomla_power.create' => 'joomla_power.create',
|
||||
'joomla_powers.access' => 'joomla_power.access',
|
||||
'joomla_power.access' => 'joomla_power.access',
|
||||
'joomla_powers.submenu' => 'joomla_power.submenu',
|
||||
'power.create' => 'power.create',
|
||||
'powers.access' => 'power.access',
|
||||
'power.access' => 'power.access',
|
||||
'powers.submenu' => 'power.submenu',
|
||||
'powers.dashboard_list' => 'power.dashboard_list',
|
||||
'admin_view.create' => 'admin_view.create',
|
||||
'admin_views.access' => 'admin_view.access',
|
||||
'admin_view.access' => 'admin_view.access',
|
||||
'admin_views.submenu' => 'admin_view.submenu',
|
||||
'admin_views.dashboard_list' => 'admin_view.dashboard_list',
|
||||
'custom_admin_views.access' => 'custom_admin_view.access',
|
||||
'custom_admin_view.access' => 'custom_admin_view.access',
|
||||
'custom_admin_views.submenu' => 'custom_admin_view.submenu',
|
||||
'custom_admin_views.dashboard_list' => 'custom_admin_view.dashboard_list',
|
||||
'site_views.access' => 'site_view.access',
|
||||
'site_view.access' => 'site_view.access',
|
||||
'site_views.submenu' => 'site_view.submenu',
|
||||
'site_views.dashboard_list' => 'site_view.dashboard_list',
|
||||
'templates.access' => 'template.access',
|
||||
'template.access' => 'template.access',
|
||||
'templates.submenu' => 'template.submenu',
|
||||
'templates.dashboard_list' => 'template.dashboard_list',
|
||||
'template.dashboard_add' => 'template.dashboard_add',
|
||||
'layouts.access' => 'layout.access',
|
||||
'layout.access' => 'layout.access',
|
||||
'layouts.submenu' => 'layout.submenu',
|
||||
'layouts.dashboard_list' => 'layout.dashboard_list',
|
||||
'dynamic_get.create' => 'dynamic_get.create',
|
||||
'dynamic_gets.access' => 'dynamic_get.access',
|
||||
'dynamic_get.access' => 'dynamic_get.access',
|
||||
'dynamic_gets.submenu' => 'dynamic_get.submenu',
|
||||
'dynamic_gets.dashboard_list' => 'dynamic_get.dashboard_list',
|
||||
'dynamic_get.dashboard_add' => 'dynamic_get.dashboard_add',
|
||||
'custom_code.create' => 'custom_code.create',
|
||||
'custom_codes.access' => 'custom_code.access',
|
||||
'custom_code.access' => 'custom_code.access',
|
||||
'custom_codes.submenu' => 'custom_code.submenu',
|
||||
'custom_codes.dashboard_list' => 'custom_code.dashboard_list',
|
||||
'class_property.create' => 'class_property.create',
|
||||
'class_properties.access' => 'class_property.access',
|
||||
'class_property.access' => 'class_property.access',
|
||||
'class_method.create' => 'class_method.create',
|
||||
'class_methods.access' => 'class_method.access',
|
||||
'class_method.access' => 'class_method.access',
|
||||
'placeholder.create' => 'placeholder.create',
|
||||
'placeholders.access' => 'placeholder.access',
|
||||
'placeholder.access' => 'placeholder.access',
|
||||
'placeholders.submenu' => 'placeholder.submenu',
|
||||
'placeholders.dashboard_list' => 'placeholder.dashboard_list',
|
||||
'library.create' => 'library.create',
|
||||
'libraries.access' => 'library.access',
|
||||
'library.access' => 'library.access',
|
||||
'libraries.submenu' => 'library.submenu',
|
||||
'libraries.dashboard_list' => 'library.dashboard_list',
|
||||
'snippets.access' => 'snippet.access',
|
||||
'snippet.access' => 'snippet.access',
|
||||
'snippets.submenu' => 'snippet.submenu',
|
||||
'snippets.dashboard_list' => 'snippet.dashboard_list',
|
||||
'validation_rule.create' => 'validation_rule.create',
|
||||
'validation_rules.access' => 'validation_rule.access',
|
||||
'validation_rule.access' => 'validation_rule.access',
|
||||
'validation_rules.submenu' => 'validation_rule.submenu',
|
||||
'validation_rules.dashboard_list' => 'validation_rule.dashboard_list',
|
||||
'field.create' => 'field.create',
|
||||
'fields.access' => 'field.access',
|
||||
'field.access' => 'field.access',
|
||||
'fields.submenu' => 'field.submenu',
|
||||
'fields.dashboard_list' => 'field.dashboard_list',
|
||||
'field.dashboard_add' => 'field.dashboard_add',
|
||||
'fieldtype.create' => 'fieldtype.create',
|
||||
'fieldtypes.access' => 'fieldtype.access',
|
||||
'fieldtype.access' => 'fieldtype.access',
|
||||
'fieldtypes.submenu' => 'fieldtype.submenu',
|
||||
'fieldtypes.dashboard_list' => 'fieldtype.dashboard_list',
|
||||
'language_translation.create' => 'language_translation.create',
|
||||
'language_translations.access' => 'language_translation.access',
|
||||
'language_translation.access' => 'language_translation.access',
|
||||
'language_translations.submenu' => 'language_translation.submenu',
|
||||
'language_translations.dashboard_list' => 'language_translation.dashboard_list',
|
||||
'language.create' => 'language.create',
|
||||
'languages.access' => 'language.access',
|
||||
'language.access' => 'language.access',
|
||||
'languages.submenu' => 'language.submenu',
|
||||
'languages.dashboard_list' => 'language.dashboard_list',
|
||||
'server.create' => 'server.create',
|
||||
'servers.access' => 'server.access',
|
||||
'server.access' => 'server.access',
|
||||
'servers.submenu' => 'server.submenu',
|
||||
'servers.dashboard_list' => 'server.dashboard_list',
|
||||
'repository.create' => 'repository.create',
|
||||
'repositories.access' => 'repository.access',
|
||||
'repository.access' => 'repository.access',
|
||||
'repositories.submenu' => 'repository.submenu',
|
||||
'repositories.dashboard_list' => 'repository.dashboard_list',
|
||||
'help_document.create' => 'help_document.create',
|
||||
'help_documents.access' => 'help_document.access',
|
||||
'help_document.access' => 'help_document.access',
|
||||
'help_documents.submenu' => 'help_document.submenu',
|
||||
'help_documents.dashboard_list' => 'help_document.dashboard_list',
|
||||
'admin_fields.create' => 'admin_fields.create',
|
||||
'admins_fields.access' => 'admin_fields.access',
|
||||
'admin_fields.access' => 'admin_fields.access',
|
||||
'admin_fields_conditions.create' => 'admin_fields_conditions.create',
|
||||
'admins_fields_conditions.access' => 'admin_fields_conditions.access',
|
||||
'admin_fields_conditions.access' => 'admin_fields_conditions.access',
|
||||
'admin_fields_relations.create' => 'admin_fields_relations.create',
|
||||
'admins_fields_relations.access' => 'admin_fields_relations.access',
|
||||
'admin_fields_relations.access' => 'admin_fields_relations.access',
|
||||
'admin_custom_tabs.create' => 'admin_custom_tabs.create',
|
||||
'admins_custom_tabs.access' => 'admin_custom_tabs.access',
|
||||
'admin_custom_tabs.access' => 'admin_custom_tabs.access',
|
||||
'component_admin_views.create' => 'component_admin_views.create',
|
||||
'components_admin_views.access' => 'component_admin_views.access',
|
||||
'component_admin_views.access' => 'component_admin_views.access',
|
||||
'component_site_views.create' => 'component_site_views.create',
|
||||
'components_site_views.access' => 'component_site_views.access',
|
||||
'component_site_views.access' => 'component_site_views.access',
|
||||
'component_custom_admin_views.create' => 'component_custom_admin_views.create',
|
||||
'components_custom_admin_views.access' => 'component_custom_admin_views.access',
|
||||
'component_custom_admin_views.access' => 'component_custom_admin_views.access',
|
||||
'component_updates.create' => 'component_updates.create',
|
||||
'components_updates.access' => 'component_updates.access',
|
||||
'component_updates.access' => 'component_updates.access',
|
||||
'component_mysql_tweaks.create' => 'component_mysql_tweaks.create',
|
||||
'components_mysql_tweaks.access' => 'component_mysql_tweaks.access',
|
||||
'component_mysql_tweaks.access' => 'component_mysql_tweaks.access',
|
||||
'component_custom_admin_menus.create' => 'component_custom_admin_menus.create',
|
||||
'components_custom_admin_menus.access' => 'component_custom_admin_menus.access',
|
||||
'component_custom_admin_menus.access' => 'component_custom_admin_menus.access',
|
||||
'component_router.create' => 'component_router.create',
|
||||
'components_routers.access' => 'component_router.access',
|
||||
'component_router.access' => 'component_router.access',
|
||||
'component_config.create' => 'component_config.create',
|
||||
'components_config.access' => 'component_config.access',
|
||||
'component_config.access' => 'component_config.access',
|
||||
'component_dashboard.create' => 'component_dashboard.create',
|
||||
'components_dashboard.access' => 'component_dashboard.access',
|
||||
'component_dashboard.access' => 'component_dashboard.access',
|
||||
'component_files_folders.create' => 'component_files_folders.create',
|
||||
'components_files_folders.access' => 'component_files_folders.access',
|
||||
'component_files_folders.access' => 'component_files_folders.access',
|
||||
'component_placeholders.create' => 'component_placeholders.create',
|
||||
'components_placeholders.access' => 'component_placeholders.access',
|
||||
'component_placeholders.access' => 'component_placeholders.access',
|
||||
'component_plugins.create' => 'component_plugins.create',
|
||||
'components_plugins.access' => 'component_plugins.access',
|
||||
'component_plugins.access' => 'component_plugins.access',
|
||||
'component_modules.create' => 'component_modules.create',
|
||||
'components_modules.access' => 'component_modules.access',
|
||||
'component_modules.access' => 'component_modules.access',
|
||||
'snippet_type.create' => 'snippet_type.create',
|
||||
'snippet_types.access' => 'snippet_type.access',
|
||||
'snippet_type.access' => 'snippet_type.access',
|
||||
'library_config.create' => 'library_config.create',
|
||||
'libraries_config.access' => 'library_config.access',
|
||||
'library_config.access' => 'library_config.access',
|
||||
'library_files_folders_urls.create' => 'library_files_folders_urls.create',
|
||||
'libraries_files_folders_urls.access' => 'library_files_folders_urls.access',
|
||||
'library_files_folders_urls.access' => 'library_files_folders_urls.access',
|
||||
'class_extends.create' => 'class_extends.create',
|
||||
'class_extendings.access' => 'class_extends.access',
|
||||
'class_extends.access' => 'class_extends.access',
|
||||
'joomla_module_updates.create' => 'joomla_module_updates.create',
|
||||
'joomla_modules_updates.access' => 'joomla_module_updates.access',
|
||||
'joomla_module_updates.access' => 'joomla_module_updates.access',
|
||||
'joomla_module_files_folders_urls.create' => 'joomla_module_files_folders_urls.create',
|
||||
'joomla_modules_files_folders_urls.access' => 'joomla_module_files_folders_urls.access',
|
||||
'joomla_module_files_folders_urls.access' => 'joomla_module_files_folders_urls.access',
|
||||
'joomla_plugin_groups.access' => 'joomla_plugin_group.access',
|
||||
'joomla_plugin_group.access' => 'joomla_plugin_group.access',
|
||||
'joomla_plugin_updates.create' => 'joomla_plugin_updates.create',
|
||||
'joomla_plugins_updates.access' => 'joomla_plugin_updates.access',
|
||||
'joomla_plugin_updates.access' => 'joomla_plugin_updates.access',
|
||||
'joomla_plugin_files_folders_urls.create' => 'joomla_plugin_files_folders_urls.create',
|
||||
'joomla_plugins_files_folders_urls.access' => 'joomla_plugin_files_folders_urls.access',
|
||||
'joomla_plugin_files_folders_urls.access' => 'joomla_plugin_files_folders_urls.access',
|
||||
];
|
||||
// loop over the $views
|
||||
foreach($viewGroups as $group => $views)
|
||||
parent::__construct($config, $factory);
|
||||
|
||||
$this->user ??= $this->getCurrentUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dashboard icons, grouped by view sections.
|
||||
*
|
||||
* @return array<string, array<int, \stdClass|false>>
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getIcons(): array
|
||||
{
|
||||
$icons = [];
|
||||
|
||||
foreach ($this->viewGroups as $group => $views)
|
||||
{
|
||||
$i = 0;
|
||||
if (UtilitiesArrayHelper::check($views))
|
||||
if (!UtilitiesArrayHelper::check($views))
|
||||
{
|
||||
foreach($views as $view)
|
||||
$icons[$group][] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($views as $view)
|
||||
{
|
||||
$icon = $this->buildIconObject($view);
|
||||
if ($icon !== null)
|
||||
{
|
||||
$add = false;
|
||||
// external views (links)
|
||||
if (strpos($view,'||') !== false)
|
||||
{
|
||||
$dwd = explode('||', $view);
|
||||
if (count($dwd) == 3)
|
||||
{
|
||||
list($type, $name, $url) = $dwd;
|
||||
$viewName = $name;
|
||||
$alt = $name;
|
||||
$url = $url;
|
||||
$image = $name . '.' . $type;
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' . StringHelper::safe($name,'U');
|
||||
}
|
||||
}
|
||||
// internal views
|
||||
elseif (strpos($view,'.') !== false)
|
||||
{
|
||||
$dwd = explode('.', $view);
|
||||
if (count($dwd) == 3)
|
||||
{
|
||||
list($type, $name, $action) = $dwd;
|
||||
}
|
||||
elseif (count($dwd) == 2)
|
||||
{
|
||||
list($type, $name) = $dwd;
|
||||
$action = false;
|
||||
}
|
||||
if ($action)
|
||||
{
|
||||
$viewName = $name;
|
||||
switch($action)
|
||||
{
|
||||
case 'add':
|
||||
$url = 'index.php?option=com_componentbuilder&view=' . $name . '&layout=edit';
|
||||
$image = $name . '_' . $action. '.' . $type;
|
||||
$alt = $name . ' ' . $action;
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_'.StringHelper::safe($name,'U').'_ADD';
|
||||
$add = true;
|
||||
break;
|
||||
default:
|
||||
// check for new convention (more stable)
|
||||
if (strpos($action, '_qpo0O0oqp_') !== false)
|
||||
{
|
||||
list($action, $extension) = (array) explode('_qpo0O0oqp_', $action);
|
||||
$extension = str_replace('_po0O0oq_', '.', $extension);
|
||||
}
|
||||
else
|
||||
{
|
||||
$extension = 'com_componentbuilder.' . $name;
|
||||
}
|
||||
$url = 'index.php?option=com_categories&view=categories&extension=' . $extension;
|
||||
$image = $name . '_' . $action . '.' . $type;
|
||||
$alt = $viewName . ' ' . $action;
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' . StringHelper::safe($name,'U') . '_' . StringHelper::safe($action,'U');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$viewName = $name;
|
||||
$alt = $name;
|
||||
$url = 'index.php?option=com_componentbuilder&view=' . $name;
|
||||
$image = $name . '.' . $type;
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' . StringHelper::safe($name,'U');
|
||||
$hover = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$viewName = $view;
|
||||
$alt = $view;
|
||||
$url = 'index.php?option=com_componentbuilder&view=' . $view;
|
||||
$image = $view . '.png';
|
||||
$name = ucwords($view).'<br /><br />';
|
||||
$hover = false;
|
||||
}
|
||||
// first make sure the view access is set
|
||||
if (UtilitiesArrayHelper::check($viewAccess))
|
||||
{
|
||||
// setup some defaults
|
||||
$dashboard_add = false;
|
||||
$dashboard_list = false;
|
||||
$accessTo = '';
|
||||
$accessAdd = '';
|
||||
// access checking start
|
||||
$accessCreate = (isset($viewAccess[$viewName.'.create'])) ? StringHelper::check($viewAccess[$viewName.'.create']):false;
|
||||
$accessAccess = (isset($viewAccess[$viewName.'.access'])) ? StringHelper::check($viewAccess[$viewName.'.access']):false;
|
||||
// set main controllers
|
||||
$accessDashboard_add = (isset($viewAccess[$viewName.'.dashboard_add'])) ? StringHelper::check($viewAccess[$viewName.'.dashboard_add']):false;
|
||||
$accessDashboard_list = (isset($viewAccess[$viewName.'.dashboard_list'])) ? StringHelper::check($viewAccess[$viewName.'.dashboard_list']):false;
|
||||
// check for adding access
|
||||
if ($add && $accessCreate)
|
||||
{
|
||||
$accessAdd = $viewAccess[$viewName.'.create'];
|
||||
}
|
||||
elseif ($add)
|
||||
{
|
||||
$accessAdd = 'core.create';
|
||||
}
|
||||
// check if access to view is set
|
||||
if ($accessAccess)
|
||||
{
|
||||
$accessTo = $viewAccess[$viewName.'.access'];
|
||||
}
|
||||
// set main access controllers
|
||||
if ($accessDashboard_add)
|
||||
{
|
||||
$dashboard_add = $user->authorise($viewAccess[$viewName.'.dashboard_add'], 'com_componentbuilder');
|
||||
}
|
||||
if ($accessDashboard_list)
|
||||
{
|
||||
$dashboard_list = $user->authorise($viewAccess[$viewName.'.dashboard_list'], 'com_componentbuilder');
|
||||
}
|
||||
if (StringHelper::check($accessAdd) && StringHelper::check($accessTo))
|
||||
{
|
||||
// check access
|
||||
if($user->authorise($accessAdd, 'com_componentbuilder') && $user->authorise($accessTo, 'com_componentbuilder') && $dashboard_add)
|
||||
{
|
||||
$icons[$group][$i] = new \StdClass;
|
||||
$icons[$group][$i]->url = $url;
|
||||
$icons[$group][$i]->name = $name;
|
||||
$icons[$group][$i]->image = $image;
|
||||
$icons[$group][$i]->alt = $alt;
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($accessTo))
|
||||
{
|
||||
// check access
|
||||
if($user->authorise($accessTo, 'com_componentbuilder') && $dashboard_list)
|
||||
{
|
||||
$icons[$group][$i] = new \StdClass;
|
||||
$icons[$group][$i]->url = $url;
|
||||
$icons[$group][$i]->name = $name;
|
||||
$icons[$group][$i]->image = $image;
|
||||
$icons[$group][$i]->alt = $alt;
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($accessAdd))
|
||||
{
|
||||
// check access
|
||||
if($user->authorise($accessAdd, 'com_componentbuilder') && $dashboard_add)
|
||||
{
|
||||
$icons[$group][$i] = new \StdClass;
|
||||
$icons[$group][$i]->url = $url;
|
||||
$icons[$group][$i]->name = $name;
|
||||
$icons[$group][$i]->image = $image;
|
||||
$icons[$group][$i]->alt = $alt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$icons[$group][$i] = new \StdClass;
|
||||
$icons[$group][$i]->url = $url;
|
||||
$icons[$group][$i]->name = $name;
|
||||
$icons[$group][$i]->image = $image;
|
||||
$icons[$group][$i]->alt = $alt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$icons[$group][$i] = new \StdClass;
|
||||
$icons[$group][$i]->url = $url;
|
||||
$icons[$group][$i]->name = $name;
|
||||
$icons[$group][$i]->image = $image;
|
||||
$icons[$group][$i]->alt = $alt;
|
||||
}
|
||||
$i++;
|
||||
$icons[$group][] = $icon;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$icons[$group][$i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $icons;
|
||||
}
|
||||
|
||||
@ -502,13 +377,208 @@ class ComponentbuilderModel extends ListModel
|
||||
$this->scripts[] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a single dashboard icon if access is granted.
|
||||
*
|
||||
* @param string $view The view string to parse.
|
||||
*
|
||||
* @return \stdClass|null The icon object or null if access denied.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function buildIconObject(string $view): ?\stdClass
|
||||
{
|
||||
$parsed = $this->parseViewDefinition($view);
|
||||
if (!$parsed)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
[
|
||||
'type' => $type,
|
||||
'name' => $name,
|
||||
'url' => $url,
|
||||
'image' => $image,
|
||||
'alt' => $alt,
|
||||
'viewName' => $viewName,
|
||||
'add' => $add,
|
||||
] = $parsed;
|
||||
|
||||
if (!$this->hasAccessToView($viewName, $add))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createIconObject($url, $name, $image, $alt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a view string into structured components.
|
||||
*
|
||||
* @param string $view The view definition string.
|
||||
*
|
||||
* @return array<string, mixed>|null Parsed values or null on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function parseViewDefinition(string $view): ?array
|
||||
{
|
||||
$add = false;
|
||||
|
||||
if (strpos($view, '||') !== false)
|
||||
{
|
||||
$parts = explode('||', $view);
|
||||
if (count($parts) === 3)
|
||||
{
|
||||
[$type, $name, $url] = $parts;
|
||||
return [
|
||||
'type' => $type,
|
||||
'name' => 'COM_COMPONENTBUILDER_DASHBOARD_' . StringHelper::safe($name, 'U'),
|
||||
'url' => $url,
|
||||
'image' => "{$name}.{$type}",
|
||||
'alt' => $name,
|
||||
'viewName' => $name,
|
||||
'add' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($view, '.') !== false)
|
||||
{
|
||||
$parts = explode('.', $view);
|
||||
$type = $parts[0] ?? '';
|
||||
$name = $parts[1] ?? '';
|
||||
$action = $parts[2] ?? null;
|
||||
$viewName = $name;
|
||||
|
||||
if ($action)
|
||||
{
|
||||
if ($action === 'add')
|
||||
{
|
||||
$url = "index.php?option=com_componentbuilder&view={$name}&layout=edit";
|
||||
$image = "{$name}_{$action}.{$type}";
|
||||
$alt = "{$name} {$action}";
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' .
|
||||
StringHelper::safe($name, 'U') . '_ADD';
|
||||
$add = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strpos($action, '_qpo0O0oqp_') !== false)
|
||||
{
|
||||
[$action, $ext] = explode('_qpo0O0oqp_', $action);
|
||||
$extension = str_replace('_po0O0oq_', '.', $ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
$extension = "com_componentbuilder.{$name}";
|
||||
}
|
||||
$url = "index.php?option=com_categories&view=categories&extension={$extension}";
|
||||
$image = "{$name}_{$action}.{$type}";
|
||||
$alt = "{$name} {$action}";
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' .
|
||||
StringHelper::safe($name, 'U') . '_' .
|
||||
StringHelper::safe($action, 'U');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = "index.php?option=com_componentbuilder&view={$name}";
|
||||
$image = "{$name}.{$type}";
|
||||
$alt = $name;
|
||||
$name = 'COM_COMPONENTBUILDER_DASHBOARD_' .
|
||||
StringHelper::safe($name, 'U');
|
||||
}
|
||||
|
||||
return compact('type', 'name', 'url', 'image', 'alt', 'viewName', 'add');
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'png',
|
||||
'name' => ucwords($view) . '<br /><br />',
|
||||
'url' => "index.php?option=com_componentbuilder&view={$view}",
|
||||
'image' => "{$view}.png",
|
||||
'alt' => $view,
|
||||
'viewName' => $view,
|
||||
'add' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user has access to view or create the item.
|
||||
*
|
||||
* @param string $viewName The base name of the view.
|
||||
* @param bool $add If this is an add-action.
|
||||
*
|
||||
* @return bool
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function hasAccessToView(string $viewName, bool $add): bool
|
||||
{
|
||||
$viewAccess = $this->viewAccess;
|
||||
$accessAdd = $add && isset($viewAccess["{$viewName}.create"])
|
||||
? $viewAccess["{$viewName}.create"]
|
||||
: ($add ? 'core.create' : '');
|
||||
|
||||
$accessTo = $viewAccess["{$viewName}.access"] ?? '';
|
||||
|
||||
$dashboardAdd = isset($viewAccess["{$viewName}.dashboard_add"]) &&
|
||||
$this->user->authorise($viewAccess["{$viewName}.dashboard_add"], 'com_componentbuilder');
|
||||
|
||||
$dashboardList = isset($viewAccess["{$viewName}.dashboard_list"]) &&
|
||||
$this->user->authorise($viewAccess["{$viewName}.dashboard_list"], 'com_componentbuilder');
|
||||
|
||||
if ($add && StringHelper::check($accessAdd))
|
||||
{
|
||||
return $this->user->authorise($accessAdd, 'com_componentbuilder') && $dashboardAdd;
|
||||
}
|
||||
|
||||
if (StringHelper::check($accessTo))
|
||||
{
|
||||
return $this->user->authorise($accessTo, 'com_componentbuilder') && $dashboardList;
|
||||
}
|
||||
|
||||
return !$accessTo && !$accessAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a \stdClass icon object.
|
||||
*
|
||||
* @param string $url Icon URL.
|
||||
* @param string $name Language string or label.
|
||||
* @param string $image Image filename.
|
||||
* @param string $alt Alt text.
|
||||
*
|
||||
* @return \stdClass
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function createIconObject(string $url, string $name, string $image, string $alt): \stdClass
|
||||
{
|
||||
$icon = new \stdClass;
|
||||
$icon->url = $url;
|
||||
$icon->name = $name;
|
||||
$icon->image = $image;
|
||||
$icon->alt = $alt;
|
||||
return $icon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load and display the wiki page content using an AJAX call to the component endpoint.
|
||||
*
|
||||
* This method injects an inline JavaScript script that asynchronously fetches the wiki page content
|
||||
* via a JSON API endpoint in the component. It uses the `marked` library to render markdown content
|
||||
* and inserts the result into the `wiki-md` container. Errors are displayed in a separate element.
|
||||
*
|
||||
* @return string HTML markup including a container for the wiki content and an error message area.
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function getWiki()
|
||||
{
|
||||
// the call URL
|
||||
// call the ajax get wiki endpoint
|
||||
$call_url = Uri::base() . 'index.php?option=com_componentbuilder&task=ajax.getWiki&format=json&raw=true&' . Session::getFormToken() . '=1&name=Home';
|
||||
$document = Factory::getDocument();
|
||||
$document->addScriptDeclaration('
|
||||
|
||||
/** \Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
$wa->addInlineScript('
|
||||
function getWikiPage(){
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
@ -528,13 +598,27 @@ class ComponentbuilderModel extends ListModel
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load and display the component's README file using JavaScript fetch and markdown rendering.
|
||||
*
|
||||
* This method injects an inline script into the document that, once the DOM is fully loaded,
|
||||
* fetches the README.txt file located in the administrator component directory, parses it using
|
||||
* the `marked` JavaScript library, and inserts the HTML into the `readme-md` div.
|
||||
*
|
||||
* @return string HTML markup including a container for the README content and a loading message.
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function getReadme()
|
||||
{
|
||||
$document = Factory::getDocument();
|
||||
$document->addScriptDeclaration('
|
||||
var getreadme = "'. Uri::root() . 'administrator/components/com_componentbuilder/README.txt";
|
||||
// get readme text path
|
||||
$call_url = Uri::root() . 'administrator/components/com_componentbuilder/README.txt';
|
||||
|
||||
/** \Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
|
||||
$wa->addInlineScript('
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
fetch(getreadme)
|
||||
fetch("'. $call_url . '")
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
@ -554,31 +638,45 @@ class ComponentbuilderModel extends ListModel
|
||||
}
|
||||
|
||||
/**
|
||||
* get Current Version Bay adding JavaScript to the Page
|
||||
* Inject JavaScript that fetches and displays the current component version status.
|
||||
*
|
||||
* @return void
|
||||
* @since 2.3.0
|
||||
* This method adds an inline script to the page which asynchronously calls the component's
|
||||
* AJAX endpoint to check the latest version. It updates the `#component-update-notice` element
|
||||
* with the fetched version notice or error message.
|
||||
*
|
||||
* @return void
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
// the call URL
|
||||
$call_url = Uri::base() . 'index.php?option=com_componentbuilder&task=ajax.getVersion&format=json&raw=true&' . Session::getFormToken() . '=1&version=1';
|
||||
$document = Factory::getDocument();
|
||||
$document->addScriptDeclaration('
|
||||
function getComponentVersionStatus() {
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then((result) => {
|
||||
if (typeof result.notice !== "undefined") {
|
||||
document.getElementById("component-update-notice").innerHTML = result.notice;
|
||||
} else if (typeof result.error !== "undefined") {
|
||||
document.getElementById("component-update-notice").innerHTML = result.error;
|
||||
}
|
||||
});
|
||||
// call the ajax get version endpoint
|
||||
$call_url = Uri::base()
|
||||
. 'index.php?option=com_componentbuilder&task=ajax.getVersion&format=json&raw=true&'
|
||||
. Session::getFormToken() . '=1&version=1.0.0';
|
||||
|
||||
try {
|
||||
/** \Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
|
||||
$wa->addInlineScript('
|
||||
function getComponentVersionStatus() {
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then((result) => {
|
||||
const target = document.getElementById("component-update-notice");
|
||||
if (!target) return;
|
||||
if (typeof result.notice !== "undefined") {
|
||||
target.innerHTML = result.notice;
|
||||
} else if (typeof result.error !== "undefined") {
|
||||
target.innerHTML = result.error;
|
||||
}
|
||||
});
|
||||
}
|
||||
setTimeout(getComponentVersionStatus, 800);');
|
||||
} catch (\Throwable $e) {
|
||||
// we do nothing....
|
||||
}
|
||||
setTimeout(getComponentVersionStatus, 800);');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ class Custom_codesModel extends ListModel
|
||||
|
||||
$item->target_code = $item->target;
|
||||
// making sure we have the component details
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1189,7 +1189,7 @@ class FieldModel extends AdminModel
|
||||
}
|
||||
break;
|
||||
case 'type':
|
||||
$property['value'] = TypeHelper::safe($property['value']);
|
||||
$property['value'] = TypeHelper::safe($property['value'], 'com_componentbuilder');
|
||||
break;
|
||||
}
|
||||
// load the property
|
||||
|
@ -288,253 +288,10 @@ class FieldtypeModel extends AdminModel
|
||||
$this->db->updateObject('#__componentbuilder_fieldtype', $objectUpdate, 'id');
|
||||
}
|
||||
}
|
||||
$this->fieldtypevvvv = $item->guid;
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get list data.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
*/
|
||||
public function getVxlfields()
|
||||
{
|
||||
// Get the user object.
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select some fields
|
||||
$query->select('a.*');
|
||||
$query->select($db->quoteName('c.title','category_title'));
|
||||
|
||||
// From the componentbuilder_field table
|
||||
$query->from($db->quoteName('#__componentbuilder_field', 'a'));
|
||||
$query->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('c.id') . ')');
|
||||
|
||||
// Filtering "extension"
|
||||
$filter_extension = $this->state->get("filter.extension");
|
||||
$field_guids = [];
|
||||
$get_ids = true;
|
||||
if ($get_ids && $filter_extension !== null && !empty($filter_extension))
|
||||
{
|
||||
// column name, and id
|
||||
$type_extension = explode('__', $filter_extension);
|
||||
if (($guids = JCBFilterHelper::linked((string) $type_extension[1], (string) $type_extension[0])) !== null)
|
||||
{
|
||||
$field_guids = $guids;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
$get_ids = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filtering "admin_view"
|
||||
$filter_admin_view = $this->state->get("filter.admin_view");
|
||||
if ($get_ids && $filter_admin_view !== null && !empty($filter_admin_view))
|
||||
{
|
||||
if (($guids = JCBFilterHelper::linked((string) $filter_admin_view, 'admin_view')) !== null)
|
||||
{
|
||||
// view will return less fields, so we ignore the component
|
||||
$field_guids = $guids;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
$get_ids = false;
|
||||
}
|
||||
}
|
||||
// now check if we have GUIDs
|
||||
if ($get_ids && UtilitiesArrayHelper::check($field_guids))
|
||||
{
|
||||
$query->where($db->quoteName('a.guid') . ' IN ("' . implode('","', $field_guids) . '")');
|
||||
}
|
||||
|
||||
// From the componentbuilder_fieldtype table.
|
||||
$query->select($db->quoteName(['g.name','g.id'],['fieldtype_name','fieldtype_id']));
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'g') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('g.guid') . ')');
|
||||
|
||||
// Filter by fieldtypevvvv global.
|
||||
$fieldtypevvvv = $this->fieldtypevvvv;
|
||||
if (is_numeric($fieldtypevvvv ))
|
||||
{
|
||||
$query->where('a.fieldtype = ' . (int) $fieldtypevvvv );
|
||||
}
|
||||
elseif (is_string($fieldtypevvvv))
|
||||
{
|
||||
$query->where('a.fieldtype = ' . $db->quote($fieldtypevvvv));
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('a.fieldtype = -5');
|
||||
}
|
||||
|
||||
// Join over the asset groups.
|
||||
$query->select('ag.title AS access_level');
|
||||
$query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
|
||||
// Filter by access level.
|
||||
$_access = $this->getState('filter.access');
|
||||
if ($_access && is_numeric($_access))
|
||||
{
|
||||
$query->where('a.access = ' . (int) $_access);
|
||||
}
|
||||
elseif (UtilitiesArrayHelper::check($_access))
|
||||
{
|
||||
// Secure the array for the query
|
||||
$_access = ArrayHelper::toInteger($_access);
|
||||
// Filter by the Access Array.
|
||||
$query->where('a.access IN (' . implode(',', $_access) . ')');
|
||||
}
|
||||
// Implement View Level Access
|
||||
if (!$user->authorise('core.options', 'com_componentbuilder'))
|
||||
{
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Order the results by ordering
|
||||
$query->order('a.published ASC');
|
||||
$query->order('a.ordering ASC');
|
||||
|
||||
// Load the items
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
$items = $db->loadObjectList();
|
||||
|
||||
// Set values to display correctly.
|
||||
if (UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
// Get the user object if not set.
|
||||
if (!isset($user) || !ObjectHelper::check($user))
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
}
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
// Remove items the user can't access.
|
||||
$access = ($user->authorise('field.access', 'com_componentbuilder.field.' . (int) $item->id) && $user->authorise('field.access', 'com_componentbuilder'));
|
||||
if (!$access)
|
||||
{
|
||||
unset($items[$nr]);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// set selection value to a translatable value
|
||||
if (UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
// convert datatype
|
||||
$item->datatype = $this->selectionTranslationVxlfields($item->datatype, 'datatype');
|
||||
// convert indexes
|
||||
$item->indexes = $this->selectionTranslationVxlfields($item->indexes, 'indexes');
|
||||
// convert null_switch
|
||||
$item->null_switch = $this->selectionTranslationVxlfields($item->null_switch, 'null_switch');
|
||||
// convert store
|
||||
$item->store = $this->selectionTranslationVxlfields($item->store, 'store');
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to convert selection values to translatable string.
|
||||
*
|
||||
* @return string The translatable string.
|
||||
*/
|
||||
public function selectionTranslationVxlfields($value,$name)
|
||||
{
|
||||
// Array of datatype language strings
|
||||
if ($name === 'datatype')
|
||||
{
|
||||
$datatypeArray = array(
|
||||
0 => 'COM_COMPONENTBUILDER_FIELD_SELECT_AN_OPTION',
|
||||
'CHAR' => 'COM_COMPONENTBUILDER_FIELD_CHAR',
|
||||
'VARCHAR' => 'COM_COMPONENTBUILDER_FIELD_VARCHAR',
|
||||
'TEXT' => 'COM_COMPONENTBUILDER_FIELD_TEXT',
|
||||
'MEDIUMTEXT' => 'COM_COMPONENTBUILDER_FIELD_MEDIUMTEXT',
|
||||
'LONGTEXT' => 'COM_COMPONENTBUILDER_FIELD_LONGTEXT',
|
||||
'BLOB' => 'COM_COMPONENTBUILDER_FIELD_BLOB',
|
||||
'TINYBLOB' => 'COM_COMPONENTBUILDER_FIELD_TINYBLOB',
|
||||
'MEDIUMBLOB' => 'COM_COMPONENTBUILDER_FIELD_MEDIUMBLOB',
|
||||
'LONGBLOB' => 'COM_COMPONENTBUILDER_FIELD_LONGBLOB',
|
||||
'DATETIME' => 'COM_COMPONENTBUILDER_FIELD_DATETIME',
|
||||
'DATE' => 'COM_COMPONENTBUILDER_FIELD_DATE',
|
||||
'TIME' => 'COM_COMPONENTBUILDER_FIELD_TIME',
|
||||
'INT' => 'COM_COMPONENTBUILDER_FIELD_INT',
|
||||
'TINYINT' => 'COM_COMPONENTBUILDER_FIELD_TINYINT',
|
||||
'BIGINT' => 'COM_COMPONENTBUILDER_FIELD_BIGINT',
|
||||
'FLOAT' => 'COM_COMPONENTBUILDER_FIELD_FLOAT',
|
||||
'DECIMAL' => 'COM_COMPONENTBUILDER_FIELD_DECIMAL',
|
||||
'DOUBLE' => 'COM_COMPONENTBUILDER_FIELD_DOUBLE'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($datatypeArray[$value]) && UtilitiesStringHelper::check($datatypeArray[$value]))
|
||||
{
|
||||
return $datatypeArray[$value];
|
||||
}
|
||||
}
|
||||
// Array of indexes language strings
|
||||
if ($name === 'indexes')
|
||||
{
|
||||
$indexesArray = array(
|
||||
1 => 'COM_COMPONENTBUILDER_FIELD_UNIQUE_KEY',
|
||||
2 => 'COM_COMPONENTBUILDER_FIELD_KEY',
|
||||
0 => 'COM_COMPONENTBUILDER_FIELD_NONE'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($indexesArray[$value]) && UtilitiesStringHelper::check($indexesArray[$value]))
|
||||
{
|
||||
return $indexesArray[$value];
|
||||
}
|
||||
}
|
||||
// Array of null_switch language strings
|
||||
if ($name === 'null_switch')
|
||||
{
|
||||
$null_switchArray = array(
|
||||
'NULL' => 'COM_COMPONENTBUILDER_FIELD_NULL',
|
||||
'NOT NULL' => 'COM_COMPONENTBUILDER_FIELD_NOT_NULL'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($null_switchArray[$value]) && UtilitiesStringHelper::check($null_switchArray[$value]))
|
||||
{
|
||||
return $null_switchArray[$value];
|
||||
}
|
||||
}
|
||||
// Array of store language strings
|
||||
if ($name === 'store')
|
||||
{
|
||||
$storeArray = array(
|
||||
0 => 'COM_COMPONENTBUILDER_FIELD_DEFAULT',
|
||||
1 => 'COM_COMPONENTBUILDER_FIELD_JSON',
|
||||
2 => 'COM_COMPONENTBUILDER_FIELD_BASE64',
|
||||
3 => 'COM_COMPONENTBUILDER_FIELD_BASIC_ENCRYPTION_LOCALDBKEY',
|
||||
5 => 'COM_COMPONENTBUILDER_FIELD_MEDIUM_ENCRYPTION_LOCALFILEKEY',
|
||||
6 => 'COM_COMPONENTBUILDER_FIELD_EXPERT_MODE_CUSTOM'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($storeArray[$value]) && UtilitiesStringHelper::check($storeArray[$value]))
|
||||
{
|
||||
return $storeArray[$value];
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
|
@ -1,283 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @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\Component\Componentbuilder\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Application\CMSApplicationInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\User\User;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Componentbuilder List Model for Get_snippets
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class Get_snippetsModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Represents the current user object.
|
||||
*
|
||||
* @var User The user object representing the current user.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected User $user;
|
||||
|
||||
/**
|
||||
* The unique identifier of the current user.
|
||||
*
|
||||
* @var int|null The ID of the current user.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?int $userId;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the current user is a guest.
|
||||
*
|
||||
* @var int 1 if the user is a guest, 0 otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $guest;
|
||||
|
||||
/**
|
||||
* An array of groups that the current user belongs to.
|
||||
*
|
||||
* @var array|null An array of user group IDs.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?array $groups;
|
||||
|
||||
/**
|
||||
* An array of view access levels for the current user.
|
||||
*
|
||||
* @var array|null An array of access level IDs.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?array $levels;
|
||||
|
||||
/**
|
||||
* The application object.
|
||||
*
|
||||
* @var CMSApplicationInterface The application instance.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CMSApplicationInterface $app;
|
||||
|
||||
/**
|
||||
* The input object, providing access to the request data.
|
||||
*
|
||||
* @var Input The input object.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Input $input;
|
||||
|
||||
/**
|
||||
* The styles array.
|
||||
*
|
||||
* @var array
|
||||
* @since 4.3
|
||||
*/
|
||||
protected array $styles = [
|
||||
'administrator/components/com_componentbuilder/assets/css/admin.css',
|
||||
'administrator/components/com_componentbuilder/assets/css/get_snippets.css'
|
||||
];
|
||||
|
||||
/**
|
||||
* The scripts array.
|
||||
*
|
||||
* @var array
|
||||
* @since 4.3
|
||||
*/
|
||||
protected array $scripts = [
|
||||
'administrator/components/com_componentbuilder/assets/js/admin.js'
|
||||
];
|
||||
|
||||
/**
|
||||
* A custom property for UI Kit components.
|
||||
*
|
||||
* @var mixed Property for storing UI Kit component-related data or objects.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $uikitComp = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($config = [], MVCFactoryInterface $factory = null)
|
||||
{
|
||||
parent::__construct($config, $factory);
|
||||
|
||||
$this->app ??= Factory::getApplication();
|
||||
$this->input ??= $this->app->getInput();
|
||||
|
||||
// Set the current user for authorisation checks (for those calling this model directly)
|
||||
$this->user ??= $this->getCurrentUser();
|
||||
$this->userId = $this->user->get('id');
|
||||
$this->guest = $this->user->get('guest');
|
||||
$this->groups = $this->user->get('groups');
|
||||
$this->authorisedGroups = $this->user->getAuthorisedGroups();
|
||||
$this->levels = $this->user->getAuthorisedViewLevels();
|
||||
|
||||
// will be removed
|
||||
$this->initSet = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build an SQL query to load the list data.
|
||||
*
|
||||
* @return string An SQL query
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Make sure all records load, since no pagination allowed.
|
||||
$this->setState('list.limit', 0);
|
||||
// Get a db connection.
|
||||
$db = $this->getDatabase();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Get from #__componentbuilder_snippet as a
|
||||
$query->select($db->quoteName(
|
||||
array('a.id','a.heading','a.name','a.url','a.created','a.modified'),
|
||||
array('id','heading','name','url','created','modified')));
|
||||
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
|
||||
// Get from #__componentbuilder_snippet_type as b
|
||||
$query->select($db->quoteName(
|
||||
array('b.name'),
|
||||
array('type')));
|
||||
$query->join('LEFT', ($db->quoteName('#__componentbuilder_snippet_type', 'b')) . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.id') . ')');
|
||||
|
||||
// Get from #__componentbuilder_library as c
|
||||
$query->select($db->quoteName(
|
||||
array('c.name'),
|
||||
array('library')));
|
||||
$query->join('LEFT', ($db->quoteName('#__componentbuilder_library', 'c')) . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.id') . ')');
|
||||
|
||||
// return the query object
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an array of data items.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$user = $this->user;
|
||||
// check if this user has permission to access items
|
||||
if (!$user->authorise('get_snippets.access', 'com_componentbuilder'))
|
||||
{
|
||||
$this->app->enqueueMessage(Text::_('Not authorised!'), 'error');
|
||||
// redirect away if not a correct to default view
|
||||
$this->app->redirect('index.php?option=com_componentbuilder');
|
||||
return false;
|
||||
}
|
||||
// load parent items
|
||||
$items = parent::getItems();
|
||||
|
||||
// Get the global params
|
||||
$globalParams = ComponentHelper::getParams('com_componentbuilder', true);
|
||||
|
||||
// Insure all item fields are adapted where needed.
|
||||
if (UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
// Always create a slug for sef URL's
|
||||
$item->slug = ($item->id ?? '0') . (isset($item->alias) ? ':' . $item->alias : '');
|
||||
}
|
||||
}
|
||||
|
||||
// return items
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the styles that have to be included on the view
|
||||
*
|
||||
* @return array styles files
|
||||
* @since 4.3
|
||||
*/
|
||||
public function getStyles(): array
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the styles that have to be included on the view
|
||||
*
|
||||
* @return void
|
||||
* @since 4.3
|
||||
*/
|
||||
public function setStyles(string $path): void
|
||||
{
|
||||
$this->styles[] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the script that have to be included on the view
|
||||
*
|
||||
* @return array script files
|
||||
* @since 4.3
|
||||
*/
|
||||
public function getScripts(): array
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the script that have to be included on the view
|
||||
*
|
||||
* @return void
|
||||
* @since 4.3
|
||||
*/
|
||||
public function setScript(string $path): void
|
||||
{
|
||||
$this->scripts[] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the uikit needed components
|
||||
*
|
||||
* @return mixed An array of objects on success.
|
||||
*
|
||||
*/
|
||||
public function getUikitComp()
|
||||
{
|
||||
if (isset($this->uikitComp) && UtilitiesArrayHelper::check($this->uikitComp))
|
||||
{
|
||||
return $this->uikitComp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace VDM\Component\Componentbuilder\Administrator\Model;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\Filesystem\Folder;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filter\OutputFilter;
|
||||
use Joomla\CMS\Installer\InstallerHelper;
|
||||
@ -22,14 +22,8 @@ use Joomla\String\StringHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use Joomla\Filesystem\File as FilesystemFile;
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace VDM\Component\Componentbuilder\Administrator\Model;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\Filesystem\Folder;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filter\OutputFilter;
|
||||
use Joomla\CMS\Installer\InstallerHelper;
|
||||
|
418
admin/src/Model/Initialization_selectionModel.php
Normal file
418
admin/src/Model/Initialization_selectionModel.php
Normal file
@ -0,0 +1,418 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @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\Component\Componentbuilder\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Application\CMSApplicationInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\MVC\Model\ItemModel;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\User\User;
|
||||
use Joomla\Input\Input;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Componentbuilder\Fieldtype\Factory as FieldtypeFactory;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Factory as JoomlaPowerFactory;
|
||||
use VDM\Joomla\Componentbuilder\Power\Factory as PowerFactory;
|
||||
use VDM\Joomla\Componentbuilder\Snippet\Factory as SnippetFactory;
|
||||
use VDM\Joomla\Componentbuilder\Repository\Factory as RepositoryFactory;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Componentbuilder Initialization_selection Item Model
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class Initialization_selectionModel extends ItemModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $_context = 'com_componentbuilder.initialization_selection';
|
||||
|
||||
/**
|
||||
* Represents the current user object.
|
||||
*
|
||||
* @var User The user object representing the current user.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected User $user;
|
||||
|
||||
/**
|
||||
* The unique identifier of the current user.
|
||||
*
|
||||
* @var int|null The ID of the current user.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?int $userId;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the current user is a guest.
|
||||
*
|
||||
* @var int 1 if the user is a guest, 0 otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $guest;
|
||||
|
||||
/**
|
||||
* An array of groups that the current user belongs to.
|
||||
*
|
||||
* @var array|null An array of user group IDs.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?array $groups;
|
||||
|
||||
/**
|
||||
* An array of view access levels for the current user.
|
||||
*
|
||||
* @var array|null An array of access level IDs.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?array $levels;
|
||||
|
||||
/**
|
||||
* The application object.
|
||||
*
|
||||
* @var CMSApplicationInterface The application instance.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CMSApplicationInterface $app;
|
||||
|
||||
/**
|
||||
* The input object, providing access to the request data.
|
||||
*
|
||||
* @var Input The input object.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Input $input;
|
||||
|
||||
/**
|
||||
* The styles array.
|
||||
*
|
||||
* @var array
|
||||
* @since 4.3
|
||||
*/
|
||||
protected array $styles = [
|
||||
'administrator/components/com_componentbuilder/assets/css/admin.css',
|
||||
'administrator/components/com_componentbuilder/assets/css/initialization_selection.css'
|
||||
];
|
||||
|
||||
/**
|
||||
* The scripts array.
|
||||
*
|
||||
* @var array
|
||||
* @since 4.3
|
||||
*/
|
||||
protected array $scripts = [
|
||||
'administrator/components/com_componentbuilder/assets/js/admin.js'
|
||||
];
|
||||
|
||||
/**
|
||||
* A custom property for UI Kit components.
|
||||
*
|
||||
* @var mixed Property for storing UI Kit component-related data or objects.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $uikitComp = [];
|
||||
|
||||
/**
|
||||
* @var object item
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
*
|
||||
* @since 3.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($config = [], MVCFactoryInterface $factory = null)
|
||||
{
|
||||
parent::__construct($config, $factory);
|
||||
|
||||
$this->app ??= Factory::getApplication();
|
||||
$this->input ??= $this->app->getInput();
|
||||
|
||||
// Set the current user for authorisation checks (for those calling this model directly)
|
||||
$this->user ??= $this->getCurrentUser();
|
||||
$this->userId = $this->user->get('id');
|
||||
$this->guest = $this->user->get('guest');
|
||||
$this->groups = $this->user->get('groups');
|
||||
$this->authorisedGroups = $this->user->getAuthorisedGroups();
|
||||
$this->levels = $this->user->getAuthorisedViewLevels();
|
||||
|
||||
// will be removed
|
||||
$this->initSet = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Get the item main id
|
||||
$id = $this->input->getInt('id', null);
|
||||
$this->setState('initialization_selection.id', $id);
|
||||
|
||||
// Load the parameters.
|
||||
parent::populateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get article data.
|
||||
*
|
||||
* @param integer $pk The id of the article.
|
||||
*
|
||||
* @return mixed Menu item data object on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
// check if this user has permission to access item
|
||||
if (!$this->user->authorise('initialization_selection.access', 'com_componentbuilder'))
|
||||
{
|
||||
$this->app->enqueueMessage(Text::_('Not authorised!'), 'error');
|
||||
// redirect away if not a correct to cPanel/default view
|
||||
$this->app->redirect('index.php?option=com_componentbuilder');
|
||||
return false;
|
||||
}
|
||||
|
||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('initialization_selection.id');
|
||||
|
||||
if ($this->_item === null)
|
||||
{
|
||||
$this->_item = [];
|
||||
}
|
||||
|
||||
if (!isset($this->_item[$pk]))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get a db connection.
|
||||
$db = $this->getDatabase();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Get data
|
||||
$data = $this->getPaths();
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
// If no data is found redirect to default page and show warning.
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_NOT_FOUND_OR_ACCESS_DENIED'), 'warning');
|
||||
$app->redirect('index.php?option=com_componentbuilder');
|
||||
return false;
|
||||
}
|
||||
|
||||
// set data object to item.
|
||||
$this->_item[$pk] = $data;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
if ($e->getCode() == 404)
|
||||
{
|
||||
// Need to go thru the error handler to allow Redirect to work.
|
||||
throw $e;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError($e);
|
||||
$this->_item[$pk] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_item[$pk];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the styles that have to be included on the view
|
||||
*
|
||||
* @return array styles files
|
||||
* @since 4.3
|
||||
*/
|
||||
public function getStyles(): array
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the styles that have to be included on the view
|
||||
*
|
||||
* @return void
|
||||
* @since 4.3
|
||||
*/
|
||||
public function setStyles(string $path): void
|
||||
{
|
||||
$this->styles[] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the script that have to be included on the view
|
||||
*
|
||||
* @return array script files
|
||||
* @since 4.3
|
||||
*/
|
||||
public function getScripts(): array
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the script that have to be included on the view
|
||||
*
|
||||
* @return void
|
||||
* @since 4.3
|
||||
*/
|
||||
public function setScript(string $path): void
|
||||
{
|
||||
$this->scripts[] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the uikit needed components
|
||||
*
|
||||
* @return mixed An array of objects on success.
|
||||
*
|
||||
*/
|
||||
public function getUikitComp()
|
||||
{
|
||||
if (isset($this->uikitComp) && UtilitiesArrayHelper::check($this->uikitComp))
|
||||
{
|
||||
return $this->uikitComp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the target power
|
||||
*
|
||||
* @return array|null
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getTargetAreaPower(): ?array
|
||||
{
|
||||
$power = $this->input->getString('power', null) ?? 'error';
|
||||
return $this->powers[$power] ? ['class' => $this->powers[$power], 'area' => $power] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the paths (repos) of this area.
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getPaths(): ?array
|
||||
{
|
||||
if (($Power = $this->getTargetAreaPower()) !== null)
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = $this->getPowerClass($Power['class'], "{$Power['area']}.Remote.Get");
|
||||
if ($class === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ['repos' => $class->paths(), 'area_class' => $Power['area'], 'headers' => $class->getIndexHeader(), 'area_name' => $class->getArea()];
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
if ($e->getCode() == 404)
|
||||
{
|
||||
// Need to go thru the error handler to allow Redirect to work.
|
||||
throw $e;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The powers that we can initialize
|
||||
*
|
||||
* @var array
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected array $powers = [
|
||||
'AdminView' => 'PackageFactory',
|
||||
'Component' => 'PackageFactory',
|
||||
'CustomAdminView' => 'PackageFactory',
|
||||
'CustomCode' => 'PackageFactory',
|
||||
'DynamicGet' => 'PackageFactory',
|
||||
'Field' => 'PackageFactory',
|
||||
'Joomla.Fieldtype' => 'FieldtypeFactory',
|
||||
'Joomla.Power' => 'JoomlaPowerFactory',
|
||||
'Layout' => 'PackageFactory',
|
||||
'Library' => 'PackageFactory',
|
||||
'JoomlaModule' => 'PackageFactory',
|
||||
'JoomlaPlugin' => 'PackageFactory',
|
||||
'Power' => 'PowerFactory',
|
||||
'SiteView' => 'PackageFactory',
|
||||
'Snippet' => 'SnippetFactory',
|
||||
'Template' => 'PackageFactory',
|
||||
'ClassExtends' => 'PackageFactory',
|
||||
'ClassProperty' => 'PackageFactory',
|
||||
'ClassMethod' => 'PackageFactory',
|
||||
'Placeholder' => 'PackageFactory',
|
||||
'Repository' => 'RepositoryFactory'
|
||||
];
|
||||
|
||||
/**
|
||||
* Method to get the power get class
|
||||
*
|
||||
* @param string $factoryName The factory name
|
||||
* @param string $getClass The remote power class name
|
||||
*
|
||||
* @return mixed
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getPowerClass(string $factoryName, string $getClass)
|
||||
{
|
||||
return match ($factoryName) {
|
||||
'PowerFactory' => PowerFactory::_($getClass),
|
||||
'JoomlaPowerFactory' => JoomlaPowerFactory::_($getClass),
|
||||
'FieldtypeFactory' => FieldtypeFactory::_($getClass),
|
||||
'SnippetFactory' => SnippetFactory::_($getClass),
|
||||
'PackageFactory' => PackageFactory::_($getClass),
|
||||
'RepositoryFactory' => RepositoryFactory::_($getClass),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
@ -93,6 +93,37 @@ class Joomla_componentModel extends AdminModel
|
||||
'not_required'
|
||||
)
|
||||
),
|
||||
'libs_helpers' => array(
|
||||
'fullwidth' => array(
|
||||
'creatuserhelper',
|
||||
'adduikit',
|
||||
'addfootable',
|
||||
'add_email_helper',
|
||||
'add_php_helper_both',
|
||||
'php_helper_both',
|
||||
'add_php_helper_admin',
|
||||
'php_helper_admin',
|
||||
'add_admin_event',
|
||||
'php_admin_event',
|
||||
'add_php_helper_site',
|
||||
'php_helper_site',
|
||||
'add_site_event',
|
||||
'php_site_event',
|
||||
'add_javascript',
|
||||
'javascript',
|
||||
'add_css_admin',
|
||||
'css_admin',
|
||||
'add_css_site',
|
||||
'css_site'
|
||||
)
|
||||
),
|
||||
'dynamic_build' => array(
|
||||
'fullwidth' => array(
|
||||
'note_buildcomp_dynamic_mysql',
|
||||
'buildcomp',
|
||||
'buildcompsql'
|
||||
)
|
||||
),
|
||||
'dynamic_integration' => array(
|
||||
'left' => array(
|
||||
'add_update_server',
|
||||
@ -122,13 +153,13 @@ class Joomla_componentModel extends AdminModel
|
||||
'crowdin_account_api_key'
|
||||
)
|
||||
),
|
||||
'mysql' => array(
|
||||
'fullwidth' => array(
|
||||
'add_sql',
|
||||
'sql',
|
||||
'add_sql_uninstall',
|
||||
'sql_uninstall',
|
||||
'assets_table_fix'
|
||||
'readme' => array(
|
||||
'left' => array(
|
||||
'addreadme',
|
||||
'readme'
|
||||
),
|
||||
'right' => array(
|
||||
'note_readme'
|
||||
)
|
||||
),
|
||||
'dash_install' => array(
|
||||
@ -155,44 +186,13 @@ class Joomla_componentModel extends AdminModel
|
||||
'php_method_install'
|
||||
)
|
||||
),
|
||||
'libs_helpers' => array(
|
||||
'mysql' => array(
|
||||
'fullwidth' => array(
|
||||
'creatuserhelper',
|
||||
'adduikit',
|
||||
'addfootable',
|
||||
'add_email_helper',
|
||||
'add_php_helper_both',
|
||||
'php_helper_both',
|
||||
'add_php_helper_admin',
|
||||
'php_helper_admin',
|
||||
'add_admin_event',
|
||||
'php_admin_event',
|
||||
'add_php_helper_site',
|
||||
'php_helper_site',
|
||||
'add_site_event',
|
||||
'php_site_event',
|
||||
'add_javascript',
|
||||
'javascript',
|
||||
'add_css_admin',
|
||||
'css_admin',
|
||||
'add_css_site',
|
||||
'css_site'
|
||||
)
|
||||
),
|
||||
'readme' => array(
|
||||
'left' => array(
|
||||
'addreadme',
|
||||
'readme'
|
||||
),
|
||||
'right' => array(
|
||||
'note_readme'
|
||||
)
|
||||
),
|
||||
'dynamic_build' => array(
|
||||
'fullwidth' => array(
|
||||
'note_buildcomp_dynamic_mysql',
|
||||
'buildcomp',
|
||||
'buildcompsql'
|
||||
'add_sql',
|
||||
'sql',
|
||||
'add_sql_uninstall',
|
||||
'sql_uninstall',
|
||||
'assets_table_fix'
|
||||
)
|
||||
),
|
||||
'settings' => array(
|
||||
@ -216,14 +216,9 @@ class Joomla_componentModel extends AdminModel
|
||||
'spacer_hr_6',
|
||||
'to_ignore_note',
|
||||
'toignore',
|
||||
'spacer_hr_7',
|
||||
'jcb_export_package_note',
|
||||
'export_key',
|
||||
'joomla_source_link',
|
||||
'export_buy_link'
|
||||
'spacer_hr_7'
|
||||
),
|
||||
'fullwidth' => array(
|
||||
'spacer_hr_8',
|
||||
'note_on_contributors',
|
||||
'addcontributors',
|
||||
'emptycontributors',
|
||||
@ -388,16 +383,10 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->metadata = $registry->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->sql_uninstall))
|
||||
if (!empty($item->javascript))
|
||||
{
|
||||
// base64 Decode sql_uninstall.
|
||||
$item->sql_uninstall = base64_decode($item->sql_uninstall);
|
||||
}
|
||||
|
||||
if (!empty($item->php_postflight_update))
|
||||
{
|
||||
// base64 Decode php_postflight_update.
|
||||
$item->php_postflight_update = base64_decode($item->php_postflight_update);
|
||||
// base64 Decode javascript.
|
||||
$item->javascript = base64_decode($item->javascript);
|
||||
}
|
||||
|
||||
if (!empty($item->css_site))
|
||||
@ -412,22 +401,16 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->php_helper_site = base64_decode($item->php_helper_site);
|
||||
}
|
||||
|
||||
if (!empty($item->javascript))
|
||||
if (!empty($item->php_preflight_update))
|
||||
{
|
||||
// base64 Decode javascript.
|
||||
$item->javascript = base64_decode($item->javascript);
|
||||
// base64 Decode php_preflight_update.
|
||||
$item->php_preflight_update = base64_decode($item->php_preflight_update);
|
||||
}
|
||||
|
||||
if (!empty($item->php_method_install))
|
||||
if (!empty($item->sql_uninstall))
|
||||
{
|
||||
// base64 Decode php_method_install.
|
||||
$item->php_method_install = base64_decode($item->php_method_install);
|
||||
}
|
||||
|
||||
if (!empty($item->php_admin_event))
|
||||
{
|
||||
// base64 Decode php_admin_event.
|
||||
$item->php_admin_event = base64_decode($item->php_admin_event);
|
||||
// base64 Decode sql_uninstall.
|
||||
$item->sql_uninstall = base64_decode($item->sql_uninstall);
|
||||
}
|
||||
|
||||
if (!empty($item->php_site_event))
|
||||
@ -442,10 +425,10 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->css_admin = base64_decode($item->css_admin);
|
||||
}
|
||||
|
||||
if (!empty($item->php_preflight_update))
|
||||
if (!empty($item->php_postflight_update))
|
||||
{
|
||||
// base64 Decode php_preflight_update.
|
||||
$item->php_preflight_update = base64_decode($item->php_preflight_update);
|
||||
// base64 Decode php_postflight_update.
|
||||
$item->php_postflight_update = base64_decode($item->php_postflight_update);
|
||||
}
|
||||
|
||||
if (!empty($item->php_preflight_install))
|
||||
@ -454,6 +437,12 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->php_preflight_install = base64_decode($item->php_preflight_install);
|
||||
}
|
||||
|
||||
if (!empty($item->php_method_install))
|
||||
{
|
||||
// base64 Decode php_method_install.
|
||||
$item->php_method_install = base64_decode($item->php_method_install);
|
||||
}
|
||||
|
||||
if (!empty($item->php_postflight_install))
|
||||
{
|
||||
// base64 Decode php_postflight_install.
|
||||
@ -496,6 +485,12 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->php_helper_admin = base64_decode($item->php_helper_admin);
|
||||
}
|
||||
|
||||
if (!empty($item->php_admin_event))
|
||||
{
|
||||
// base64 Decode php_admin_event.
|
||||
$item->php_admin_event = base64_decode($item->php_admin_event);
|
||||
}
|
||||
|
||||
// Get the basic encryption.
|
||||
$basickey = ComponentbuilderHelper::getCryptKey('basic');
|
||||
// Get the encryption object.
|
||||
@ -507,12 +502,6 @@ class Joomla_componentModel extends AdminModel
|
||||
$item->crowdin_username = rtrim($basic->decryptString($item->crowdin_username), "\0");
|
||||
}
|
||||
|
||||
if (!empty($item->export_key) && $basickey && !is_numeric($item->export_key) && $item->export_key === base64_encode(base64_decode($item->export_key, true)))
|
||||
{
|
||||
// basic decrypt data export_key.
|
||||
$item->export_key = rtrim($basic->decryptString($item->export_key), "\0");
|
||||
}
|
||||
|
||||
if (!empty($item->crowdin_project_api_key) && $basickey && !is_numeric($item->crowdin_project_api_key) && $item->crowdin_project_api_key === base64_encode(base64_decode($item->crowdin_project_api_key, true)))
|
||||
{
|
||||
// basic decrypt data crowdin_project_api_key.
|
||||
@ -1507,16 +1496,10 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['addcontributors'] = '';
|
||||
}
|
||||
|
||||
// Set the sql_uninstall string to base64 string.
|
||||
if (isset($data['sql_uninstall']))
|
||||
// Set the javascript string to base64 string.
|
||||
if (isset($data['javascript']))
|
||||
{
|
||||
$data['sql_uninstall'] = base64_encode($data['sql_uninstall']);
|
||||
}
|
||||
|
||||
// Set the php_postflight_update string to base64 string.
|
||||
if (isset($data['php_postflight_update']))
|
||||
{
|
||||
$data['php_postflight_update'] = base64_encode($data['php_postflight_update']);
|
||||
$data['javascript'] = base64_encode($data['javascript']);
|
||||
}
|
||||
|
||||
// Set the css_site string to base64 string.
|
||||
@ -1531,22 +1514,16 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['php_helper_site'] = base64_encode($data['php_helper_site']);
|
||||
}
|
||||
|
||||
// Set the javascript string to base64 string.
|
||||
if (isset($data['javascript']))
|
||||
// Set the php_preflight_update string to base64 string.
|
||||
if (isset($data['php_preflight_update']))
|
||||
{
|
||||
$data['javascript'] = base64_encode($data['javascript']);
|
||||
$data['php_preflight_update'] = base64_encode($data['php_preflight_update']);
|
||||
}
|
||||
|
||||
// Set the php_method_install string to base64 string.
|
||||
if (isset($data['php_method_install']))
|
||||
// Set the sql_uninstall string to base64 string.
|
||||
if (isset($data['sql_uninstall']))
|
||||
{
|
||||
$data['php_method_install'] = base64_encode($data['php_method_install']);
|
||||
}
|
||||
|
||||
// Set the php_admin_event string to base64 string.
|
||||
if (isset($data['php_admin_event']))
|
||||
{
|
||||
$data['php_admin_event'] = base64_encode($data['php_admin_event']);
|
||||
$data['sql_uninstall'] = base64_encode($data['sql_uninstall']);
|
||||
}
|
||||
|
||||
// Set the php_site_event string to base64 string.
|
||||
@ -1561,10 +1538,10 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['css_admin'] = base64_encode($data['css_admin']);
|
||||
}
|
||||
|
||||
// Set the php_preflight_update string to base64 string.
|
||||
if (isset($data['php_preflight_update']))
|
||||
// Set the php_postflight_update string to base64 string.
|
||||
if (isset($data['php_postflight_update']))
|
||||
{
|
||||
$data['php_preflight_update'] = base64_encode($data['php_preflight_update']);
|
||||
$data['php_postflight_update'] = base64_encode($data['php_postflight_update']);
|
||||
}
|
||||
|
||||
// Set the php_preflight_install string to base64 string.
|
||||
@ -1573,6 +1550,12 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['php_preflight_install'] = base64_encode($data['php_preflight_install']);
|
||||
}
|
||||
|
||||
// Set the php_method_install string to base64 string.
|
||||
if (isset($data['php_method_install']))
|
||||
{
|
||||
$data['php_method_install'] = base64_encode($data['php_method_install']);
|
||||
}
|
||||
|
||||
// Set the php_postflight_install string to base64 string.
|
||||
if (isset($data['php_postflight_install']))
|
||||
{
|
||||
@ -1615,6 +1598,12 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['php_helper_admin'] = base64_encode($data['php_helper_admin']);
|
||||
}
|
||||
|
||||
// Set the php_admin_event string to base64 string.
|
||||
if (isset($data['php_admin_event']))
|
||||
{
|
||||
$data['php_admin_event'] = base64_encode($data['php_admin_event']);
|
||||
}
|
||||
|
||||
// Get the basic encryption key.
|
||||
$basickey = ComponentbuilderHelper::getCryptKey('basic');
|
||||
// Get the encryption object
|
||||
@ -1626,12 +1615,6 @@ class Joomla_componentModel extends AdminModel
|
||||
$data['crowdin_username'] = $basic->encryptString($data['crowdin_username']);
|
||||
}
|
||||
|
||||
// Encrypt data export_key.
|
||||
if (isset($data['export_key']) && $basickey)
|
||||
{
|
||||
$data['export_key'] = $basic->encryptString($data['export_key']);
|
||||
}
|
||||
|
||||
// Encrypt data crowdin_project_api_key.
|
||||
if (isset($data['crowdin_project_api_key']) && $basickey)
|
||||
{
|
||||
|
@ -23,7 +23,6 @@ use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
@ -485,28 +484,26 @@ class Joomla_componentsModel extends ListModel
|
||||
continue;
|
||||
}
|
||||
|
||||
// decode sql_uninstall
|
||||
$item->sql_uninstall = base64_decode($item->sql_uninstall);
|
||||
// decode php_postflight_update
|
||||
$item->php_postflight_update = base64_decode($item->php_postflight_update);
|
||||
// decode javascript
|
||||
$item->javascript = base64_decode($item->javascript);
|
||||
// decode css_site
|
||||
$item->css_site = base64_decode($item->css_site);
|
||||
// decode php_helper_site
|
||||
$item->php_helper_site = base64_decode($item->php_helper_site);
|
||||
// decode javascript
|
||||
$item->javascript = base64_decode($item->javascript);
|
||||
// decode php_method_install
|
||||
$item->php_method_install = base64_decode($item->php_method_install);
|
||||
// decode php_admin_event
|
||||
$item->php_admin_event = base64_decode($item->php_admin_event);
|
||||
// decode php_preflight_update
|
||||
$item->php_preflight_update = base64_decode($item->php_preflight_update);
|
||||
// decode sql_uninstall
|
||||
$item->sql_uninstall = base64_decode($item->sql_uninstall);
|
||||
// decode php_site_event
|
||||
$item->php_site_event = base64_decode($item->php_site_event);
|
||||
// decode css_admin
|
||||
$item->css_admin = base64_decode($item->css_admin);
|
||||
// decode php_preflight_update
|
||||
$item->php_preflight_update = base64_decode($item->php_preflight_update);
|
||||
// decode php_postflight_update
|
||||
$item->php_postflight_update = base64_decode($item->php_postflight_update);
|
||||
// decode php_preflight_install
|
||||
$item->php_preflight_install = base64_decode($item->php_preflight_install);
|
||||
// decode php_method_install
|
||||
$item->php_method_install = base64_decode($item->php_method_install);
|
||||
// decode php_postflight_install
|
||||
$item->php_postflight_install = base64_decode($item->php_postflight_install);
|
||||
// decode php_method_uninstall
|
||||
@ -520,27 +517,24 @@ class Joomla_componentsModel extends ListModel
|
||||
}
|
||||
// decode buildcompsql
|
||||
$item->buildcompsql = base64_decode($item->buildcompsql);
|
||||
if ($basickey && !is_numeric($item->export_key) && $item->export_key === base64_encode(base64_decode($item->export_key, true)))
|
||||
{
|
||||
// decrypt export_key
|
||||
$item->export_key = $basic->decryptString($item->export_key);
|
||||
}
|
||||
// decode readme
|
||||
$item->readme = base64_decode($item->readme);
|
||||
// decode php_helper_both
|
||||
$item->php_helper_both = base64_decode($item->php_helper_both);
|
||||
if ($basickey && !is_numeric($item->crowdin_project_api_key) && $item->crowdin_project_api_key === base64_encode(base64_decode($item->crowdin_project_api_key, true)))
|
||||
{
|
||||
// decrypt crowdin_project_api_key
|
||||
$item->crowdin_project_api_key = $basic->decryptString($item->crowdin_project_api_key);
|
||||
}
|
||||
// decode php_helper_both
|
||||
$item->php_helper_both = base64_decode($item->php_helper_both);
|
||||
// decode php_helper_admin
|
||||
$item->php_helper_admin = base64_decode($item->php_helper_admin);
|
||||
if ($basickey && !is_numeric($item->crowdin_account_api_key) && $item->crowdin_account_api_key === base64_encode(base64_decode($item->crowdin_account_api_key, true)))
|
||||
{
|
||||
// decrypt crowdin_account_api_key
|
||||
$item->crowdin_account_api_key = $basic->decryptString($item->crowdin_account_api_key);
|
||||
}
|
||||
// decode php_helper_admin
|
||||
$item->php_helper_admin = base64_decode($item->php_helper_admin);
|
||||
// decode php_admin_event
|
||||
$item->php_admin_event = base64_decode($item->php_admin_event);
|
||||
// unset the values we don't want exported.
|
||||
unset($item->asset_id);
|
||||
unset($item->checked_out);
|
||||
|
@ -24,9 +24,8 @@ use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -98,175 +97,6 @@ class Joomla_pluginsModel extends ListModel
|
||||
$this->app ??= Factory::getApplication();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get Boilerplate
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getBoilerplate()
|
||||
{
|
||||
// get boilerplate repo root details
|
||||
if (($repo_tree = ComponentbuilderHelper::getGithubRepoFileList('boilerplate', ComponentbuilderHelper::$bolerplateAPI)) !== false)
|
||||
{
|
||||
$found = array_values(array_filter(
|
||||
$repo_tree,
|
||||
function($tree) {
|
||||
if (isset($tree->path) && $tree->path === 'plugins')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
));
|
||||
// make sure we have the correct boilerplate
|
||||
if (UtilitiesArrayHelper::check($found) && count($found) == 1 && method_exists(__CLASS__, 'getPluginsBoilerplate'))
|
||||
{
|
||||
// get the plugins boilerplate
|
||||
return $this->getPluginsBoilerplate($found[0]->url);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Plugin Boilerplate
|
||||
*
|
||||
* @return boolean true on success
|
||||
*
|
||||
*/
|
||||
protected function getPluginsBoilerplate($url)
|
||||
{
|
||||
// get boilerplate root for plugins
|
||||
if (($plugin_tree = ComponentbuilderHelper::getGithubRepoFileList('boilerplate_plugins', $url)) !== false)
|
||||
{
|
||||
// get the app object
|
||||
$app = Factory::getApplication();
|
||||
// set the table names
|
||||
$tables = array();
|
||||
$tables['e'] = 'class_extends';
|
||||
$tables['g'] = 'joomla_plugin_group';
|
||||
$tables['m'] = 'class_method';
|
||||
$tables['p'] = 'class_property';
|
||||
// load the needed models
|
||||
$models = array();
|
||||
$models['e'] = ComponentbuilderHelper::getModel($tables['e']);
|
||||
$models['g'] = ComponentbuilderHelper::getModel($tables['g']);
|
||||
$models['p'] = ComponentbuilderHelper::getModel($tables['p']);
|
||||
$models['m'] = ComponentbuilderHelper::getModel($tables['m']);
|
||||
// get the needed data of each plugin group
|
||||
$groups = array_map(
|
||||
function($tree) use(&$app, &$models, &$tables){
|
||||
if (($fooClass = ComponentbuilderHelper::getFileContents(ComponentbuilderHelper::$bolerplatePath . '/plugins/' . $tree->path . '/foo.php')) !== false && StringHelper::check($fooClass))
|
||||
{
|
||||
// extract the boilerplate class extends and check if already set
|
||||
if (($classExtends = ComponentbuilderHelper::extractBoilerplateClassExtends($fooClass, 'plugins')) !== false &&
|
||||
($classExtendsID = GetHelper::var('class_extends', $classExtends, 'name', 'id')) === false)
|
||||
{
|
||||
// load the extends class name
|
||||
$class = array('id' => 0, 'published' => 1, 'version' => 1, 'name' => $classExtends);
|
||||
// extract the boilerplate class header
|
||||
$class['head'] = ComponentbuilderHelper::extractBoilerplateClassHeader($fooClass, $classExtends, 'plugins');
|
||||
// extract the boilerplate class comment
|
||||
$class['comment'] = ComponentbuilderHelper::extractBoilerplateClassComment($fooClass, $classExtends, 'plugins');
|
||||
// set the extension type
|
||||
$class['extension_type'] = 'plugins';
|
||||
// store the class
|
||||
$this->storePluginBoilerplate($tables['e'], $models['e'], $class, $app);
|
||||
// work around
|
||||
$classExtendsID = GetHelper::var('class_extends', $classExtends, 'name', 'id');
|
||||
}
|
||||
// set plugin group if not already set
|
||||
if (($pluginGroupID = GetHelper::var('joomla_plugin_group', $tree->path, 'name', 'id')) === false)
|
||||
{
|
||||
// load the plugin group name
|
||||
$pluginGroup = array('id' => 0, 'published' => 1, 'version' => 1, 'name' => $tree->path, 'class_extends' => $classExtendsID);
|
||||
// store the group
|
||||
$this->storePluginBoilerplate($tables['g'], $models['g'], $pluginGroup, $app);
|
||||
// work around
|
||||
$pluginGroupID = GetHelper::var('joomla_plugin_group', $tree->path, 'name', 'id');
|
||||
}
|
||||
// extract the boilerplate class property and methods
|
||||
if (($classProperiesMethods = ComponentbuilderHelper::extractBoilerplateClassPropertiesMethods($fooClass, $classExtends, 'plugins', $pluginGroupID)) !== false)
|
||||
{
|
||||
// create the properties found
|
||||
if (isset($classProperiesMethods['property']) && UtilitiesArrayHelper::check($classProperiesMethods['property']))
|
||||
{
|
||||
foreach ($classProperiesMethods['property'] as $_property)
|
||||
{
|
||||
// force update by default
|
||||
$this->storePluginBoilerplate($tables['p'], $models['p'], $_property, $app);
|
||||
}
|
||||
}
|
||||
// create the method found (TODO just create for now but we could later add a force update)
|
||||
if (isset($classProperiesMethods['method']) && UtilitiesArrayHelper::check($classProperiesMethods['method']))
|
||||
{
|
||||
foreach ($classProperiesMethods['method'] as $_method)
|
||||
{
|
||||
// force update by default
|
||||
$this->storePluginBoilerplate($tables['m'], $models['m'], $_method, $app);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
$plugin_tree
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* store Plugin Boilerplate
|
||||
*
|
||||
* @return boolean true on success
|
||||
*
|
||||
*/
|
||||
protected function storePluginBoilerplate(&$table, &$method, &$boilerplate, &$app)
|
||||
{
|
||||
// Sometimes the form needs some posted data, such as for plugins and modules.
|
||||
$form = $method->getForm($boilerplate, false);
|
||||
if (!$form)
|
||||
{
|
||||
$app->enqueueMessage($method->getError(), 'error');
|
||||
return false;
|
||||
}
|
||||
// Send an object which can be modified through the plugin event
|
||||
$objData = (object) $boilerplate;
|
||||
$app->triggerEvent(
|
||||
'onContentNormaliseRequestData',
|
||||
array('com_componentbuilder.' . $table, $objData, $form)
|
||||
);
|
||||
$boilerplate = (array) $objData;
|
||||
// Test whether the data is valid.
|
||||
$validData = $method->validate($form, $boilerplate);
|
||||
// Check for validation errors.
|
||||
if ($validData === false)
|
||||
{
|
||||
// Get the validation messages.
|
||||
$errors = $method->getErrors();
|
||||
// Push up to three validation messages out to the user.
|
||||
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
|
||||
{
|
||||
if ($errors[$i] instanceof \Exception)
|
||||
{
|
||||
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
|
||||
}
|
||||
else
|
||||
{
|
||||
$app->enqueueMessage($errors[$i], 'warning');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Attempt to save the data.
|
||||
if (!$method->save($validData))
|
||||
{
|
||||
$app->enqueueMessage(Text::sprintf('COM_COMPONENTBUILDER_BOILERPLATE_PLUGIN_S_DATA_COULD_NOT_BE_SAVED', $table), 'error');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
|
@ -257,7 +257,7 @@ class Joomla_powersModel extends ListModel
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search) . '%');
|
||||
$query->where('(a.system_name LIKE '.$search.' OR a.guid LIKE '.$search.' OR a.description LIKE '.$search.')');
|
||||
$query->where('(a.system_name LIKE '.$search.' OR a.guid LIKE '.$search.' OR a.description LIKE '.$search.' OR a.settings LIKE '.$search.')');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,9 +248,12 @@ class RepositoriesModel extends ListModel
|
||||
{
|
||||
$targetArray = array(
|
||||
0 => 'COM_COMPONENTBUILDER_REPOSITORY_SELECT_AN_OPTION',
|
||||
1 => 'COM_COMPONENTBUILDER_REPOSITORY_SUPER_POWER',
|
||||
4 => 'COM_COMPONENTBUILDER_REPOSITORY_PACKAGES',
|
||||
3 => 'COM_COMPONENTBUILDER_REPOSITORY_FIELD_TYPES',
|
||||
2 => 'COM_COMPONENTBUILDER_REPOSITORY_JOOMLA_POWER',
|
||||
3 => 'COM_COMPONENTBUILDER_REPOSITORY_JOOMLA_FIELD_TYPES'
|
||||
5 => 'COM_COMPONENTBUILDER_REPOSITORY_SNIPPETS',
|
||||
1 => 'COM_COMPONENTBUILDER_REPOSITORY_SUPER_POWER',
|
||||
6 => 'COM_COMPONENTBUILDER_REPOSITORY_REPOSITORIES'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($targetArray[$value]) && StringHelper::check($targetArray[$value]))
|
||||
@ -263,7 +266,8 @@ class RepositoriesModel extends ListModel
|
||||
{
|
||||
$typeArray = array(
|
||||
0 => 'COM_COMPONENTBUILDER_REPOSITORY_SELECT_AN_OPTION',
|
||||
1 => 'COM_COMPONENTBUILDER_REPOSITORY_GITEA'
|
||||
1 => 'COM_COMPONENTBUILDER_REPOSITORY_GITEA',
|
||||
2 => 'COM_COMPONENTBUILDER_REPOSITORY_GITHUB'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($typeArray[$value]) && StringHelper::check($typeArray[$value]))
|
||||
@ -338,7 +342,7 @@ class RepositoriesModel extends ListModel
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search) . '%');
|
||||
$query->where('(a.organisation LIKE '.$search.' OR a.repository LIKE '.$search.' OR a.target LIKE '.$search.' OR a.type LIKE '.$search.' OR a.base LIKE '.$search.' OR a.guid LIKE '.$search.' OR a.username LIKE '.$search.')');
|
||||
$query->where('(a.organisation LIKE '.$search.' OR a.repository LIKE '.$search.' OR a.target LIKE '.$search.' OR a.type LIKE '.$search.' OR a.base LIKE '.$search.' OR a.guid LIKE '.$search.' OR a.author_email LIKE '.$search.' OR a.author_name LIKE '.$search.' OR a.username LIKE '.$search.')');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,9 @@ class RepositoryModel extends AdminModel
|
||||
'type',
|
||||
'base',
|
||||
'username',
|
||||
'token'
|
||||
'token',
|
||||
'author_name',
|
||||
'author_email'
|
||||
),
|
||||
'right' => array(
|
||||
'organisation',
|
||||
|
@ -26,8 +26,6 @@ use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\Filesystem\File;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -101,120 +99,6 @@ class SnippetsModel extends ListModel
|
||||
$this->app ??= Factory::getApplication();
|
||||
}
|
||||
|
||||
public $user;
|
||||
public $zipPath;
|
||||
|
||||
/**
|
||||
* Method to build the export package
|
||||
*
|
||||
* @return bool on success.
|
||||
*/
|
||||
public function shareSnippets($pks)
|
||||
{
|
||||
// setup the query
|
||||
if (UtilitiesArrayHelper::check($pks))
|
||||
{
|
||||
// Get the user object.
|
||||
if (!ObjectHelper::check($this->user))
|
||||
{
|
||||
$this->user = Factory::getUser();
|
||||
}
|
||||
// Create a new query object.
|
||||
if (!ObjectHelper::check($this->_db))
|
||||
{
|
||||
$this->_db = Factory::getDBO();
|
||||
}
|
||||
$query = $this->_db->getQuery(true);
|
||||
|
||||
// Select some fields
|
||||
$query->select($this->_db->quoteName(
|
||||
array('a.name','a.heading','a.description','a.usage','a.snippet','a.url','b.name','c.name','a.created','a.modified','a.contributor_company','a.contributor_name','a.contributor_email','a.contributor_website'),
|
||||
array('name','heading','description','usage','snippet','url','type','library','created','modified','contributor_company','contributor_name','contributor_email','contributor_website')
|
||||
));
|
||||
|
||||
// From the componentbuilder_snippet table
|
||||
$query->from($this->_db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
// From the componentbuilder_snippet_type table.
|
||||
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $this->_db->quoteName('a.type') . ' = ' . $this->_db->quoteName('b.id') . ')');
|
||||
// From the componentbuilder_library table.
|
||||
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $this->_db->quoteName('a.library') . ' = ' . $this->_db->quoteName('c.id') . ')');
|
||||
$query->where('a.id IN (' . implode(',',$pks) . ')');
|
||||
|
||||
// Implement View Level Access
|
||||
if (!$this->user->authorise('core.options', 'com_componentbuilder'))
|
||||
{
|
||||
$groups = implode(',', $this->user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Order the results by ordering
|
||||
$query->order('a.ordering ASC');
|
||||
|
||||
// Load the items
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
if ($this->_db->getNumRows())
|
||||
{
|
||||
// load the items from db
|
||||
$items = $this->_db->loadObjectList();
|
||||
// check if we have items
|
||||
if (UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
// get the shared paths
|
||||
$this->fullPath = rtrim(ComponentbuilderHelper::getFolderPath('path', 'sharepath', Factory::getConfig()->get('tmp_path')), '/') . '/snippets';
|
||||
// remove old folder with the same name
|
||||
if (is_dir($this->fullPath))
|
||||
{
|
||||
// remove if old folder is found
|
||||
ComponentbuilderHelper::removeFolder($this->fullPath);
|
||||
}
|
||||
// create the full path
|
||||
Folder::create($this->fullPath);
|
||||
// set zip path
|
||||
$this->zipPath = $this->fullPath .'.zip';
|
||||
// remove old zip files with the same name
|
||||
if (is_file($this->zipPath))
|
||||
{
|
||||
// remove file if found
|
||||
File::delete($this->zipPath);
|
||||
}
|
||||
// prep the item
|
||||
foreach($items as $item)
|
||||
{
|
||||
// just unlock the snippet
|
||||
$item->snippet = base64_decode($item->snippet);
|
||||
// build filename
|
||||
$fileName = StringHelper::safe($item->library . ' - (' . $item->type . ') ' . $item->name, 'filename', '', false) . '.json';
|
||||
// if the snippet has its own contributor details set, then do not change
|
||||
if (!strlen($item->contributor_company) || !strlen($item->contributor_name) || !strlen($item->contributor_email) || !strlen($item->contributor_website))
|
||||
{
|
||||
// load the correct contributor details to each snippet (this is very slow)
|
||||
$_contributor = ComponentbuilderHelper::getContributorDetails($fileName);
|
||||
$item->contributor_company = $_contributor['contributor_company'];
|
||||
$item->contributor_name = $_contributor['contributor_name'];
|
||||
$item->contributor_email = $_contributor['contributor_email'];
|
||||
$item->contributor_website = $_contributor['contributor_website'];
|
||||
}
|
||||
// now store the snippet info
|
||||
ComponentbuilderHelper::writeFile($this->fullPath . '/' . $fileName, json_encode($item, JSON_PRETTY_PRINT));
|
||||
}
|
||||
// zip the folder
|
||||
if (!ComponentbuilderHelper::zip($this->fullPath, $this->zipPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// remove the folder
|
||||
if (!ComponentbuilderHelper::removeFolder($this->fullPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
|
Reference in New Issue
Block a user