Release of v5.1.1-alpha5
Refactor initialization flow to accommodate future scalability and integration with all designated areas. Refactor the Creator Builders class. Refactor the FieldString and FieldXML classes.
This commit is contained in:
@ -28,7 +28,6 @@ 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;
|
||||
@ -41,6 +40,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\Interfaces\Remote\GetInterface;
|
||||
use Joomla\CMS\Form\FormHelper as FormFormHelper;
|
||||
|
||||
// No direct access to this file
|
||||
@ -87,95 +92,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.
|
||||
*
|
||||
@ -4321,269 +4237,189 @@ class AjaxModel extends ListModel
|
||||
|
||||
// Used in snippet
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
// 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
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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.
|
||||
$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();
|
||||
if ($db->getNumRows())
|
||||
|
||||
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.2.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();
|
||||
$snippet->snippet = base64_decode($snippet->snippet);
|
||||
// return found snippet settings
|
||||
|
||||
if (isset($snippet->snippet))
|
||||
{
|
||||
$snippet->snippet = base64_decode($snippet->snippet);
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setSnippetGithub($path, $status)
|
||||
/**
|
||||
* 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.2.1
|
||||
*/
|
||||
protected function resolveSnippetKeyField($key)
|
||||
{
|
||||
// get user
|
||||
$user = Factory::getUser();
|
||||
$access = $user->authorise('snippet.access', 'com_componentbuilder');
|
||||
if ($access)
|
||||
if (GuidHelper::valid($key))
|
||||
{
|
||||
// secure path
|
||||
$path = StringHelper::safe(str_replace('.json','',$path), 'filename', '', false).'.json';
|
||||
// base path
|
||||
$base_path = basename($path);
|
||||
// set url
|
||||
$url = ComponentbuilderHelper::$snippetPath.rawurlencode($base_path);
|
||||
// get the snippets
|
||||
if (($snippet = ComponentbuilderHelper::getGithubRepoData('lib_snippet_' . $base_path, $url, null, 'array')) !== false)
|
||||
{
|
||||
return $this->saveSnippet($snippet, $status, $user);
|
||||
}
|
||||
// see if we have any errors from github
|
||||
if (UtilitiesArrayHelper::check(ComponentbuilderHelper::$githubRepoDataErrors))
|
||||
{
|
||||
return array('message' => Text::sprintf('COM_COMPONENTBUILDER_ERROR_BR_S', implode('<br />', ComponentbuilderHelper::$githubRepoDataErrors)), 'status' => 'danger');
|
||||
}
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_THE_PATH_HAS_A_MISMATCH_AND_COULD_THEREFORE_NOT_RETRIEVE_THE_SNIPPET_FROM_GITHUB'), 'status' => 'danger');
|
||||
return 'guid';
|
||||
}
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THE_SNIPPETS'), 'status' => 'danger');
|
||||
}
|
||||
|
||||
protected function saveSnippet($item, $status, $user)
|
||||
{
|
||||
// set some defaults
|
||||
$todayDate = Factory::getDate()->toSql();
|
||||
// get the type id
|
||||
$item['type'] = ($id = GetHelper::var('snippet_type', $item['type'], 'name', 'id')) ? $id : $this->createNew($item['type'], 'snippet_type', $user, $todayDate);
|
||||
// get the library id
|
||||
$item['library'] = ($id = GetHelper::var('library', $item['library'], 'name', 'id')) ? $id : $this->createNew($item['library'], 'library', $user, $todayDate);
|
||||
// remove type if zero
|
||||
if ($item['type'] == 0)
|
||||
if (is_numeric($key))
|
||||
{
|
||||
unset($item['type']);
|
||||
return 'id';
|
||||
}
|
||||
// remove library if zero
|
||||
if ($item['library'] == 0)
|
||||
{
|
||||
unset($item['library']);
|
||||
}
|
||||
// get the snippet ID
|
||||
$item['id'] = $this->getSnippetId($item);
|
||||
if ($item['id'] == 0)
|
||||
{
|
||||
$canCreate = $user->authorise('snippet.create', 'com_componentbuilder');
|
||||
if ('new' === $status && !$canCreate)
|
||||
{
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_PERMISSION_TO_CREATE_THE_SNIPPET'), 'status' => 'danger');
|
||||
}
|
||||
}
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel('snippet', JPATH_COMPONENT_ADMINISTRATOR);
|
||||
// save the snippet
|
||||
if ($model->save($item))
|
||||
{
|
||||
if ($item['id'] == 0)
|
||||
{
|
||||
// get the saved item
|
||||
$updatedItem = $model->getItem();
|
||||
$item['id']= $updatedItem->get('id');
|
||||
}
|
||||
// we have to force modified date since the model does not allow you
|
||||
if ($this->forchDateFix($item))
|
||||
{
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED'), 'status' => 'success');
|
||||
}
|
||||
// return error
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED_BUT_THE_MODIFIED_DATE_COULD_NOT_BE_ADJUSTED_BR_BR_BTHIS_MEANS_THE_SNIPPETS_WILL_CONTINUE_TO_APPEAR_OUT_OF_DATEB'), 'status' => 'warning');
|
||||
}
|
||||
// return error
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_THE_SNIPPET_IS_FAULTY_AND_COULD_NOT_BE_SAVED'), 'status' => 'danger');
|
||||
}
|
||||
|
||||
protected function forchDateFix($item)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = (int) $item['id'];
|
||||
$object->created = $item['created'];
|
||||
$object->modified = $item['modified'];
|
||||
// force update
|
||||
return Factory::getDbo()->updateObject('#__componentbuilder_snippet', $object, 'id');
|
||||
}
|
||||
|
||||
protected function getSnippetId($item)
|
||||
{
|
||||
// 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.name') . ' = ' . (string) $db->quote($item['name']));
|
||||
if (is_numeric($item['type']))
|
||||
{
|
||||
$query->where($db->quoteName('a.type') . ' = ' . (int) $item['type']);
|
||||
}
|
||||
if (is_numeric($item['library']))
|
||||
{
|
||||
$query->where($db->quoteName('a.library') . ' = ' . (int) $item['library']);
|
||||
}
|
||||
// Reset the query using our newly populated query object.
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
return $db->loadResult();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function createNew($name, $type, $user, $todayDate)
|
||||
{
|
||||
// verify that we can continue
|
||||
if (ComponentbuilderHelper::getActions($type)->get('core.create'))
|
||||
{
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel($type, JPATH_COMPONENT_ADMINISTRATOR);
|
||||
// build array to save
|
||||
$item['id'] = 0;
|
||||
$item['name'] = $name;
|
||||
$item['published'] = 1;
|
||||
$item['version'] = 1;
|
||||
$item['created'] = $todayDate;
|
||||
$item['created_by'] = $user->id;
|
||||
// save the new
|
||||
$model->save($item);
|
||||
// get the saved item
|
||||
$item = $model->getItem();
|
||||
return $item->get('id');
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used in validation_rule
|
||||
@ -5434,4 +5270,150 @@ 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.2.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.2.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 ($result !== null)
|
||||
{
|
||||
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.2.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')];
|
||||
}
|
||||
|
||||
/**
|
||||
* The powers that we can initialize
|
||||
*
|
||||
* @var array
|
||||
* @since 5.2.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',
|
||||
'Module' => 'PackageFactory',
|
||||
'Power' => 'PowerFactory',
|
||||
'Plugin' => 'PackageFactory',
|
||||
'SiteView' => 'PackageFactory',
|
||||
'Snippet' => 'SnippetFactory',
|
||||
'Template' => 'PackageFactory'
|
||||
];
|
||||
|
||||
/**
|
||||
* Method to get the power get class
|
||||
*
|
||||
* @param string $factoryName The factory name
|
||||
* @param string $getClass The remote power class name
|
||||
*
|
||||
* @return GetInterface|null
|
||||
* @since 5.2.1
|
||||
*/
|
||||
protected function getPowerClass(string $factoryName, string $getClass): ?GetInterface
|
||||
{
|
||||
return match ($factoryName) {
|
||||
'PowerFactory' => PowerFactory::_($getClass),
|
||||
'JoomlaPowerFactory' => JoomlaPowerFactory::_($getClass),
|
||||
'FieldtypeFactory' => FieldtypeFactory::_($getClass),
|
||||
'SnippetFactory' => SnippetFactory::_($getClass),
|
||||
'PackageFactory' => PackageFactory::_($getClass),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ class FieldsModel extends ListModel
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search) . '%');
|
||||
$query->where('(a.name LIKE '.$search.' OR a.fieldtype LIKE '.$search.' OR g.name LIKE '.$search.' OR a.datatype LIKE '.$search.' OR a.indexes LIKE '.$search.' OR a.null_switch LIKE '.$search.' OR a.store LIKE '.$search.' OR a.catid LIKE '.$search.' OR a.xml LIKE '.$search.')');
|
||||
$query->where('(a.name LIKE '.$search.' OR a.fieldtype LIKE '.$search.' OR g.name LIKE '.$search.' OR a.datatype LIKE '.$search.' OR a.indexes LIKE '.$search.' OR a.null_switch LIKE '.$search.' OR a.store LIKE '.$search.' OR a.catid LIKE '.$search.' OR a.xml LIKE '.$search.' OR a.guid LIKE '.$search.')');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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\CMS\Filesystem\Folder as FilesystemFolder;
|
||||
|
||||
|
412
admin/src/Model/Initialization_selectionModel.php
Normal file
412
admin/src/Model/Initialization_selectionModel.php
Normal file
@ -0,0 +1,412 @@
|
||||
<?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\Interfaces\Remote\GetInterface;
|
||||
|
||||
// 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.2.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.2.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.2.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',
|
||||
'Module' => 'PackageFactory',
|
||||
'Power' => 'PowerFactory',
|
||||
'Plugin' => 'PackageFactory',
|
||||
'SiteView' => 'PackageFactory',
|
||||
'Snippet' => 'SnippetFactory',
|
||||
'Template' => 'PackageFactory'
|
||||
];
|
||||
|
||||
/**
|
||||
* Method to get the power get class
|
||||
*
|
||||
* @param string $factoryName The factory name
|
||||
* @param string $getClass The remote power class name
|
||||
*
|
||||
* @return GetInterface|null
|
||||
* @since 5.2.1
|
||||
*/
|
||||
protected function getPowerClass(string $factoryName, string $getClass): ?GetInterface
|
||||
{
|
||||
return match ($factoryName) {
|
||||
'PowerFactory' => PowerFactory::_($getClass),
|
||||
'JoomlaPowerFactory' => JoomlaPowerFactory::_($getClass),
|
||||
'FieldtypeFactory' => FieldtypeFactory::_($getClass),
|
||||
'SnippetFactory' => SnippetFactory::_($getClass),
|
||||
'PackageFactory' => PackageFactory::_($getClass),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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,11 @@ class RepositoriesModel extends ListModel
|
||||
{
|
||||
$targetArray = array(
|
||||
0 => 'COM_COMPONENTBUILDER_REPOSITORY_SELECT_AN_OPTION',
|
||||
1 => 'COM_COMPONENTBUILDER_REPOSITORY_SUPER_POWER',
|
||||
4 => 'COM_COMPONENTBUILDER_REPOSITORY_JCB_PACKAGES',
|
||||
3 => 'COM_COMPONENTBUILDER_REPOSITORY_JOOMLA_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'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($targetArray[$value]) && StringHelper::check($targetArray[$value]))
|
||||
|
@ -29,6 +29,7 @@ use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
@ -293,13 +294,21 @@ class SnippetModel extends AdminModel
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only load if new item
|
||||
if (0 == $id)
|
||||
{
|
||||
$form->setValue('contributor_company', null, Helper::getParams('com_componentbuilder')->get('export_company', 'Vast Development Method'));
|
||||
$form->setValue('contributor_name', null, Helper::getParams('com_componentbuilder')->get('export_owner', 'Llewellyn van der Merwe'));
|
||||
$form->setValue('contributor_email', null, Helper::getParams('com_componentbuilder')->get('export_email', 'joomla@vdm.io'));
|
||||
$form->setValue('contributor_website', null, Helper::getParams('com_componentbuilder')->get('export_website', 'https://www.vdm.io/'));
|
||||
}
|
||||
|
||||
// Only load the GUID if new item (or empty)
|
||||
if (0 == $id || !($val = $form->getValue('guid')))
|
||||
{
|
||||
$form->setValue('guid', null, GuidHelper::get());
|
||||
}
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -905,23 +914,6 @@ class SnippetModel extends AdminModel
|
||||
$data['metadata'] = (string) $metadata;
|
||||
}
|
||||
|
||||
// set the contributor details if not set
|
||||
if (strlen($data['contributor_company']) < 1 || strlen($data['contributor_name']) < 1 || strlen($data['contributor_email']) < 3 || strlen($data['contributor_website']) < 3)
|
||||
{
|
||||
// get the library name
|
||||
$library = ($name = GetHelper::var('library', $item['library'], 'id', 'name')) ? $name:'Common';
|
||||
// get the library name
|
||||
$type = ($name = GetHelper::var('snippet_type', $item['type'], 'id', 'name')) ? $name:'No Library';
|
||||
// build the filename
|
||||
$filename = UtilitiesStringHelper::safe($library . ' - (' . $type . ') ' . $item['name'], 'filename', '', false). '.json';
|
||||
// now get the contributor details (slow)
|
||||
$contributor = ComponentbuilderHelper::getContributorDetails($filename);
|
||||
// now update the local snippet contributor details
|
||||
$data['contributor_company'] = $contributor['contributor_company'];
|
||||
$data['contributor_name'] = $contributor['contributor_name'];
|
||||
$data['contributor_email'] = $contributor['contributor_email'];
|
||||
$data['contributor_website'] = $contributor['contributor_website'];
|
||||
}
|
||||
|
||||
// Set the GUID if empty or not valid
|
||||
if (empty($data['guid']) && $data['id'] > 0)
|
||||
|
@ -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