Fix the linked [new] button to use the correct init_default params. Fix the Components list view to better display long website urls. Fix language text area css. #1264. Refactor the JS selText method. Add fix for empty currentFullPath in the Structuresingle class. Fix the buildSelectPart method to not access an empty select value in the Queries class. Fix that ensure that we always load and int into loadUserById. Fix the subform permission behaviour to use removeField. Add version 6 to the version 5 update server, for easier upgrade path. Fixed linked admin views with New and New & Close buttons to correctly initialize fields using global unique IDs and default conventions. Resolved missing language strings when linked admin views are also configured as site edit views. Corrected misconfiguration of the isModal property for site-linked views to default to false since modals are not yet supported on the site area. Enhanced security in edit views by moving access validation into the model, ensuring protection even when Joomla bypasses the controller layer. Added user access verification logic in the model to prevent unauthorized direct item loading. Refactored the view class to introduce a class constructor that initializes key dependencies more reliably. Began aligning the view class structure with Joomla 6's updated MVC architecture for future compatibility. Improved initialization handling in the view to reduce dependency errors during rendering. Fixed a bug caused by missing option settings in the model configuration. Updated and refined the site view class for greater consistency with backend view logic. Continued progressive improvements across view classes to ensure compatibility with Joomla's evolving MVC patterns. Fix permission issue in the list view. #1266. Refactor the list view buttons. Refactor the getActions helper method. Rename Custom Buttons tab to Toolbar for clearer grouping of toolbar functions. #1268. Add options for overriding default toolbars in all Admin, Site, and Custom Admin Views. #1268. Refactor toolbar into version specific classes to resolve getToolbar errors. #1267. Add method to unify getDatabase handling across Joomla versions and prevent undefined method calls. #1270. Fix php8.3 deprecation warnings in compiler templates. #1265. Refactor and enhance the JCB Email Helper class for a more robust and maintainable design. Fix an issue where the Email Helper send() function was executed twice. Fix a issue where layouts added to the PHP Ajax Model were not loaded during compilation. Add new functionality to the toolbar override system, enabling the inclusion of custom buttons via placeholders. Fix the Compiler success message to display both build seconds and project weeks. Add Development Valuation Model to calculate JCB component pricing. Add functionality to push JCB packages to Self hosted Git system that uses a self signed SSL. Add functionality that will include Validation Rules linked to fields in JCB packages. #1273. Refactor and Improve Router Helper Class to new standard Site Router practice. Refactor and Improve JCB Search engine for better searching of JCB areas. Fix bug in the search editor in JCB Search Engine. Fix issue where Custom Gets linked to a Site view did not ship correctly with JCB packages. #1272. Fix issue where the Icon linked to a Custom Admin Menu did not ship with JCB packages. #1271. Fix and Improve Normalize Class to better handle different files Linked to JCB packages. #1274. Remove batch feature from JCB compiler Templates due to lack of use and outdated code. Refactor Utilities/Response classes for Joomla 6+ compatibility and improved version-agnostic behavior. Refactor the File Upload Manager to achieve improved maintainability, greater customization flexibility, and easier extensibility. Refactor the Item Importer to improve data management, structural clarity, and long-term maintainability of the import process. Add a Pull button to all main JCB entities, allowing a complete reset of a selected entity together with all entities linked to it, from a selected remote repository. Add functionality to the compiler to automatically pull missing entities from a remote repository when they are referenced by a component but not present locally in JCB. Refactor the Packaging Engine into separate set and get classes to improve separation of concerns, readability, and overall maintainability. Refactor and restructure the demo console item import plugin to improve usability, maintainability, and reusability across other areas of JCB. Refactor the Compiler to remove deprecated code paths and legacy classes that are no longer maintained. Add new Compiler Classes to modernise ancient tech previously embedded in the compiler and replace it with a clean, modern architecture. Add a dedicated CLI plugin to the JCB core, enabling direct interaction with JCB through the Joomla CLI console. Add structured CLI commands and options to Init, Reset, Push, and Pull JCB entities via the Joomla CLI. Add full support for compiling Components directly via the CLI, enabling automated and headless build workflows. Add functionality to place Super Power classes into the component src folder for both Admin and Site areas, using the correct namespaced structure. Add functionality to the CLI compiler to directly install compiled components and apply compiler options used during compilation. Add functionality to the compiler to automatically pull a missing component from a remote repository when a compilation is triggered and the component is not locally available. Add functionality to add and replace classes in module and plugin src folders that are linked to a component, when using correct namespace resolution. Add a Documentation tab to the Joomla Component Builder dashboard. Fix an issue with the JCB version notice on Joomla 5. Fix an issue where components without a component image failed to compile successfully. #1282. Add functionality for importing translated language strings directly into the Language Translations area of JCB. Fix issue where the Language Translations export button was not displayed due to recent toolbar changes. Fix a bug that caused language filters to malfunction because of a broken field configuration. #1278. Fix issue where components without a layout added to the Component failed to compile correctly. #1132.
449 lines
12 KiB
PHP
449 lines
12 KiB
PHP
<?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\Table;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\Table\Table;
|
|
use Joomla\CMS\Table\Asset;
|
|
use Joomla\CMS\Language\Text;
|
|
use Joomla\CMS\String\PunycodeHelper;
|
|
use Joomla\CMS\Access\Access as AccessRules;
|
|
use Joomla\CMS\Access\Rules;
|
|
use Joomla\CMS\Tag\TaggableTableInterface;
|
|
use Joomla\CMS\Tag\TaggableTableTrait;
|
|
use Joomla\CMS\User\CurrentUserInterface;
|
|
use Joomla\CMS\User\CurrentUserTrait;
|
|
use Joomla\CMS\Versioning\VersionableTableInterface;
|
|
use Joomla\CMS\Application\ApplicationHelper;
|
|
use Joomla\Registry\Registry;
|
|
use Joomla\Database\DatabaseInterface;
|
|
use Joomla\Database\DatabaseDriver;
|
|
use Joomla\Database\Exception\DatabaseNotFoundException;
|
|
use Joomla\Event\DispatcherInterface;
|
|
use Joomla\String\StringHelper;
|
|
use Joomla\Utilities\ArrayHelper;
|
|
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
|
|
|
// No direct access to this file
|
|
\defined('_JEXEC') or die;
|
|
|
|
/**
|
|
* Joomla_plugins Table class
|
|
*
|
|
* @since 1.6
|
|
*/
|
|
class Joomla_pluginTable extends Table implements VersionableTableInterface, TaggableTableInterface, CurrentUserInterface
|
|
{
|
|
use TaggableTableTrait;
|
|
use CurrentUserTrait;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param DatabaseDriver $db Database connector object
|
|
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
|
|
*
|
|
* @param object Database connector object
|
|
* @since 4.0
|
|
*/
|
|
function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null)
|
|
{
|
|
// The type alias generally is the internal component name with the
|
|
// content type. Ex.: com_content.article
|
|
$this->typeAlias = 'com_componentbuilder.joomla_plugin';
|
|
|
|
// Ensure the params and metadata in json encoded in the bind method
|
|
$this->_jsonEncode = ['params', 'metadata'];
|
|
|
|
// Indicates that columns fully support the NULL value in the database
|
|
$this->_supportNullValue = true;
|
|
|
|
parent::__construct('#__componentbuilder_joomla_plugin', 'id', $db, $dispatcher);
|
|
}
|
|
|
|
/**
|
|
* Method to bind an associative array or object to the Table instance.This
|
|
* method only binds properties that are publicly accessible and optionally
|
|
* takes an array of properties to ignore when binding.
|
|
*
|
|
* @param array|object $src An associative array or object to bind to the Table instance.
|
|
* @param array|string $ignore An optional array or space separated list of properties to ignore while binding.
|
|
*
|
|
* @return boolean True on success.
|
|
*
|
|
* @since 1.7.0
|
|
* @throws \InvalidArgumentException
|
|
*/
|
|
public function bind($array, $ignore = '')
|
|
{
|
|
// Bind the rules.
|
|
if (isset($array['rules']) && is_array($array['rules']))
|
|
{
|
|
$rules = new AccessRules($array['rules']);
|
|
$this->setRules($rules);
|
|
}
|
|
|
|
return parent::bind($array, $ignore);
|
|
}
|
|
|
|
/**
|
|
* Overload the store method for the Joomla_plugin table.
|
|
*
|
|
* @param boolean Toggle whether null values should be updated.
|
|
*
|
|
* @return boolean True on success, false on failure.
|
|
* @since 1.6
|
|
*/
|
|
public function store($updateNulls = true)
|
|
{
|
|
$date = Factory::getDate()->toSql();
|
|
$userId = $this->getCurrentUser()->id;
|
|
|
|
if ($this->id)
|
|
{
|
|
// Existing item
|
|
$this->modified = $date;
|
|
$this->modified_by = $userId;
|
|
}
|
|
else
|
|
{
|
|
// New joomla_plugin. A joomla_plugin created and created_by field can be set by the user,
|
|
// so we don't touch either of these if they are set.
|
|
if (!(int) $this->created)
|
|
{
|
|
$this->created = $date;
|
|
}
|
|
if (empty($this->created_by))
|
|
{
|
|
$this->created_by = $userId;
|
|
}
|
|
}
|
|
|
|
if (isset($this->alias))
|
|
{
|
|
// Verify that the alias is unique
|
|
$table = new self($this->getDatabase(), $this->getDispatcher());
|
|
|
|
if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0))
|
|
{
|
|
$this->setError(Text::_('COM_COMPONENTBUILDER_JOOMLA_PLUGIN_ERROR_UNIQUE_ALIAS'));
|
|
|
|
if ($table->published === -2)
|
|
{
|
|
$this->setError(Text::_('COM_COMPONENTBUILDER_JOOMLA_PLUGIN_ERROR_UNIQUE_ALIAS_TRASHED'));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (isset($this->url))
|
|
{
|
|
// Convert IDN urls to punycode
|
|
$this->url = PunycodeHelper::urlToPunycode($this->url);
|
|
}
|
|
|
|
if (isset($this->website))
|
|
{
|
|
// Convert IDN urls to punycode
|
|
$this->website = PunycodeHelper::urlToPunycode($this->website);
|
|
}
|
|
|
|
return parent::store($updateNulls);
|
|
}
|
|
|
|
/**
|
|
* Overloaded check method to ensure data integrity.
|
|
*
|
|
* @return boolean True on success.
|
|
*
|
|
* @see \Joomla\CMS\Table\Table::check
|
|
* @since 1.5
|
|
*/
|
|
public function check()
|
|
{
|
|
try {
|
|
parent::check();
|
|
} catch (\Exception $e) {
|
|
$this->setError($e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
if (isset($this->alias))
|
|
{
|
|
// Generate a valid alias
|
|
$this->generateAlias();
|
|
|
|
$table = new self($this->getDatabase(), $this->getDispatcher());
|
|
|
|
while ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0))
|
|
{
|
|
$this->alias = StringHelper::increment($this->alias, 'dash');
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Clean up keywords -- eliminate extra spaces between phrases
|
|
* and cr (\r) and lf (\n) characters from string.
|
|
* Only process if not empty.
|
|
*/
|
|
if (!empty($this->metakey))
|
|
{
|
|
// Array of characters to remove.
|
|
$bad_characters = array("\n", "\r", "\"", "<", ">");
|
|
|
|
// Remove bad characters.
|
|
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
|
|
|
|
// Create array using commas as delimiter.
|
|
$keys = explode(',', $after_clean);
|
|
$clean_keys = [];
|
|
|
|
foreach ($keys as $key)
|
|
{
|
|
// Ignore blank keywords.
|
|
if (trim($key))
|
|
{
|
|
$clean_keys[] = trim($key);
|
|
}
|
|
}
|
|
|
|
// Put array back together delimited by ", "
|
|
$this->metakey = implode(", ", $clean_keys);
|
|
}
|
|
|
|
// Clean up description -- eliminate quotes and <> brackets
|
|
if (!empty($this->metadesc))
|
|
{
|
|
// Only process if not empty
|
|
$bad_characters = array("\"", "<", ">");
|
|
$this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
|
|
}
|
|
|
|
// If we don't have any access rules set at this point just use an empty AccessRules class
|
|
if (!$this->getRules())
|
|
{
|
|
$rules = $this->getDefaultAssetValues('com_componentbuilder.joomla_plugin.'.$this->id);
|
|
$this->setRules($rules);
|
|
}
|
|
|
|
// Set ordering
|
|
if ($this->published < 0)
|
|
{
|
|
// Set ordering to 0 if state is archived or trashed
|
|
$this->ordering = 0;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Gets the default asset values for a component.
|
|
*
|
|
* @param string $component The component asset name to search for
|
|
* @param bool $try The retry flag
|
|
*
|
|
* @return Rules The AccessRules object for the asset
|
|
* @since 2.5.0
|
|
*/
|
|
protected function getDefaultAssetValues(string $component, bool $try = true)
|
|
{
|
|
// Need to find the asset id by the name of the component.
|
|
$db = $this->getDatabase();
|
|
$query = $db->getQuery(true)
|
|
->select($db->quoteName('id'))
|
|
->from($db->quoteName('#__assets'))
|
|
->where($db->quoteName('name') . ' = ' . $db->quote($component));
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->loadRowList())
|
|
{
|
|
// asset already set so use saved rules
|
|
$assetId = (int) $db->loadResult();
|
|
return AccessRules::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed.
|
|
}
|
|
// try again
|
|
elseif ($try)
|
|
{
|
|
$try = explode('.', $component);
|
|
$result = $this->getDefaultAssetValues($try[0], false);
|
|
if ($result instanceof Rules)
|
|
{
|
|
if (isset($try[1]))
|
|
{
|
|
$_result = (string) $result;
|
|
$_result = json_decode($_result);
|
|
foreach ($_result as $name => &$rule)
|
|
{
|
|
$v = explode('.', $name);
|
|
if ($try[1] !== $v[0])
|
|
{
|
|
// remove since it is not part of this view
|
|
unset($_result->$name);
|
|
}
|
|
else
|
|
{
|
|
// clear the value since we inherit
|
|
$rule = [];
|
|
}
|
|
}
|
|
// check if there are any view values remaining
|
|
if (count( (array) $_result))
|
|
{
|
|
$_result = json_encode($_result);
|
|
$_result = array($_result);
|
|
// Instantiate and return the AccessRules object for the asset rules.
|
|
$rules = new Rules;
|
|
$rules->mergeCollection($_result);
|
|
|
|
return $rules;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
return AccessRules::getAssetRules(0);
|
|
}
|
|
|
|
/**
|
|
* Get the type alias for the history table
|
|
*
|
|
* The type alias generally is the internal component name with the
|
|
* content type. Ex.: com_content.article
|
|
*
|
|
* @return string The alias as described above
|
|
*
|
|
* @since 3.10.0
|
|
*/
|
|
public function getTypeAlias()
|
|
{
|
|
return $this->typeAlias;
|
|
}
|
|
|
|
/**
|
|
* Method to compute the default name of the asset.
|
|
* The default name is in the form table_name.id
|
|
* where id is the value of the primary key of the table.
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.7.0
|
|
*/
|
|
protected function _getAssetName()
|
|
{
|
|
$k = $this->_tbl_key;
|
|
|
|
return $this->getTypeAlias() . '.' . (int) $this->$k;
|
|
}
|
|
|
|
/**
|
|
* Method to get the parent asset under which to register this one.
|
|
*
|
|
* By default, all assets are registered to the ROOT node with ID, which will default to 1 if none exists.
|
|
* An extended class can define a table and ID to lookup. If the asset does not exist it will be created.
|
|
*
|
|
* @param ?Table $table A Table object for the asset parent.
|
|
* @param ?integer $id Id to look up
|
|
*
|
|
* @return integer
|
|
*
|
|
* @since 1.7.0
|
|
*/
|
|
protected function _getAssetParentId(?Table $table = null, $id = null)
|
|
{
|
|
/** @var Asset $assets */
|
|
$assets = new Asset($this->getDatabase(), $this->getDispatcher());
|
|
$rootId = $assets->getRootId();
|
|
|
|
// load the componentbuilder asset
|
|
$assets->loadByName('com_componentbuilder');
|
|
|
|
return $assets->id ?? $rootId ?? 1;
|
|
}
|
|
|
|
/**
|
|
* Retrieve the database connection in a version-safe and cached manner.
|
|
*
|
|
* Compatible with Joomla 4 -> 7:
|
|
* - If the parent class implements getDatabase() (DatabaseAwareTrait), that is used.
|
|
* - Otherwise it falls back to getDbo() for legacy versions.
|
|
* - The detected instance is cached to avoid repeated reflection or lookups.
|
|
*
|
|
* @return DatabaseInterface
|
|
*
|
|
* @throws DatabaseNotFoundException If the database connection cannot be determined.
|
|
* @since 5.1.4
|
|
*/
|
|
protected function getDatabase(): DatabaseInterface
|
|
{
|
|
static $cache = null;
|
|
|
|
// Return cached connection if available
|
|
if ($cache instanceof DatabaseInterface)
|
|
{
|
|
return $cache;
|
|
}
|
|
|
|
// --- Step 1: Use parent::getDatabase() if available (J7+ or DatabaseAwareTrait) ---
|
|
$parent = get_parent_class($this);
|
|
|
|
if ($parent && method_exists($parent, 'getDatabase'))
|
|
{
|
|
try
|
|
{
|
|
$db = parent::getDatabase();
|
|
|
|
if ($db instanceof DatabaseInterface)
|
|
{
|
|
$cache = $db;
|
|
return $cache;
|
|
}
|
|
}
|
|
catch (\Throwable)
|
|
{
|
|
// Continue to next fallback
|
|
}
|
|
}
|
|
|
|
// --- Step 2: Fallback to getDbo() (J3-J6 style) ---
|
|
if (method_exists($this, 'getDbo'))
|
|
{
|
|
try
|
|
{
|
|
$db = $this->getDbo();
|
|
|
|
if ($db instanceof DatabaseInterface)
|
|
{
|
|
$cache = $db;
|
|
return $cache;
|
|
}
|
|
}
|
|
catch (\Throwable)
|
|
{
|
|
// Continue to next fallback
|
|
}
|
|
}
|
|
|
|
// --- Step 3: No valid database found ---
|
|
throw new DatabaseNotFoundException('Database not set in ' . static::class);
|
|
}
|
|
|
|
/**
|
|
* This view does not actually have an alias
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function generateAlias()
|
|
{
|
|
return false;
|
|
}
|
|
}
|