Stable release of v3.2.0-beta1
Move beta to main repo. Fix #1053 so that the right and left tabs display correctly in Joomla 4&5.
This commit is contained in:
@ -12,12 +12,21 @@
|
||||
// No direct access to this file
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Filter\OutputFilter;
|
||||
use Joomla\CMS\MVC\Model\AdminModel;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\CMS\UCM\UCMType;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
|
||||
/**
|
||||
@ -83,18 +92,18 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
* @param string $prefix A prefix for the table class name. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return JTable A database object
|
||||
* @return Table A database object
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getTable($type = 'snippet', $prefix = 'ComponentbuilderTable', $config = array())
|
||||
public function getTable($type = 'snippet', $prefix = 'ComponentbuilderTable', $config = [])
|
||||
{
|
||||
// add table path for when model gets used from other component
|
||||
$this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables');
|
||||
// get instance of the table
|
||||
return JTable::getInstance($type, $prefix, $config);
|
||||
return Table::getInstance($type, $prefix, $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
@ -145,7 +154,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true, $options = array('control' => 'jform'))
|
||||
public function getForm($data = [], $loadData = true, $options = array('control' => 'jform'))
|
||||
{
|
||||
// set load data option
|
||||
$options['load_data'] = $loadData;
|
||||
@ -172,7 +181,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
return false;
|
||||
}
|
||||
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$jinput = Factory::getApplication()->input;
|
||||
|
||||
// The front end calls this model and uses a_id to avoid id clashes so we need to check for that first.
|
||||
if ($jinput->get('a_id'))
|
||||
@ -185,7 +194,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
$id = $jinput->get('id', 0, 'INT');
|
||||
}
|
||||
|
||||
$user = JFactory::getUser();
|
||||
$user = Factory::getUser();
|
||||
|
||||
// Check for existing item.
|
||||
// Modify the form based on Edit State access controls.
|
||||
@ -253,13 +262,13 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
/**
|
||||
* Method to get the script that have to be included on the form
|
||||
*
|
||||
* @return string script files
|
||||
* @return string script files
|
||||
*/
|
||||
public function getScript()
|
||||
{
|
||||
return 'media/com_componentbuilder/js/snippet.js';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to test whether a record can be deleted.
|
||||
*
|
||||
@ -278,7 +287,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
return;
|
||||
}
|
||||
|
||||
$user = JFactory::getUser();
|
||||
$user = Factory::getUser();
|
||||
// The record has been set. Check the record permissions.
|
||||
return $user->authorise('core.delete', 'com_componentbuilder.snippet.' . (int) $record->id);
|
||||
}
|
||||
@ -296,8 +305,8 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*/
|
||||
protected function canEditState($record)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$recordId = (!empty($record->id)) ? $record->id : 0;
|
||||
$user = Factory::getUser();
|
||||
$recordId = $record->id ?? 0;
|
||||
|
||||
if ($recordId)
|
||||
{
|
||||
@ -311,28 +320,28 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
// In the absence of better information, revert to the component permissions.
|
||||
return parent::canEditState($record);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method override to check if you can edit an existing record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
* @param string $key The name of the key for the primary key.
|
||||
* @param array $data An array of input data.
|
||||
* @param string $key The name of the key for the primary key.
|
||||
*
|
||||
* @return boolean
|
||||
* @since 2.5
|
||||
* @return boolean
|
||||
* @since 2.5
|
||||
*/
|
||||
protected function allowEdit($data = array(), $key = 'id')
|
||||
protected function allowEdit($data = [], $key = 'id')
|
||||
{
|
||||
// Check specific edit permission then general edit permission.
|
||||
$user = JFactory::getUser();
|
||||
$user = Factory::getUser();
|
||||
|
||||
return $user->authorise('core.edit', 'com_componentbuilder.snippet.'. ((int) isset($data[$key]) ? $data[$key] : 0)) or $user->authorise('core.edit', 'com_componentbuilder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare and sanitise the table data prior to saving.
|
||||
*
|
||||
* @param JTable $table A JTable object.
|
||||
* @param Table $table A Table object.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
@ -340,19 +349,19 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
$date = JFactory::getDate();
|
||||
$user = JFactory::getUser();
|
||||
|
||||
$date = Factory::getDate();
|
||||
$user = Factory::getUser();
|
||||
|
||||
if (isset($table->name))
|
||||
{
|
||||
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
|
||||
}
|
||||
|
||||
|
||||
if (isset($table->alias) && empty($table->alias))
|
||||
{
|
||||
$table->generateAlias();
|
||||
}
|
||||
|
||||
|
||||
if (empty($table->id))
|
||||
{
|
||||
$table->created = $date->toSql();
|
||||
@ -364,7 +373,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
// Set ordering to the last item if not set
|
||||
if (empty($table->ordering))
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('MAX(ordering)')
|
||||
->from($db->quoteName('#__componentbuilder_snippet'));
|
||||
@ -379,7 +388,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
$table->modified = $date->toSql();
|
||||
$table->modified_by = $user->id;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($table->id))
|
||||
{
|
||||
// Increment the items version number.
|
||||
@ -394,10 +403,10 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_componentbuilder.edit.snippet.data', array());
|
||||
$data = Factory::getApplication()->getUserState('com_componentbuilder.edit.snippet.data', []);
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
@ -420,7 +429,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
return array('guid');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to delete one or more records.
|
||||
*
|
||||
@ -436,7 +445,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -456,10 +465,10 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to perform batch operations on an item or a set of items.
|
||||
*
|
||||
@ -485,30 +494,30 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
|
||||
if (empty($pks))
|
||||
{
|
||||
$this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED'));
|
||||
$this->setError(Text::_('JGLOBAL_NO_ITEM_SELECTED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$done = false;
|
||||
|
||||
// Set some needed variables.
|
||||
$this->user = JFactory::getUser();
|
||||
$this->table = $this->getTable();
|
||||
$this->tableClassName = get_class($this->table);
|
||||
$this->contentType = new JUcmType;
|
||||
$this->type = $this->contentType->getTypeByTable($this->tableClassName);
|
||||
$this->canDo = ComponentbuilderHelper::getActions('snippet');
|
||||
$this->batchSet = true;
|
||||
$this->user = Factory::getUser();
|
||||
$this->table = $this->getTable();
|
||||
$this->tableClassName = get_class($this->table);
|
||||
$this->contentType = new UCMType;
|
||||
$this->type = $this->contentType->getTypeByTable($this->tableClassName);
|
||||
$this->canDo = ComponentbuilderHelper::getActions('snippet');
|
||||
$this->batchSet = true;
|
||||
|
||||
if (!$this->canDo->get('core.batch'))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
|
||||
$this->setError(Text::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ($this->type == false)
|
||||
{
|
||||
$type = new JUcmType;
|
||||
$type = new UCMType;
|
||||
$this->type = $type->getTypeByAlias($this->typeAlias);
|
||||
}
|
||||
|
||||
@ -545,8 +554,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
|
||||
if (!$done)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
|
||||
|
||||
$this->setError(Text::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -572,7 +580,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
if (empty($this->batchSet))
|
||||
{
|
||||
// Set some needed variables.
|
||||
$this->user = JFactory::getUser();
|
||||
$this->user = Factory::getUser();
|
||||
$this->table = $this->getTable();
|
||||
$this->tableClassName = get_class($this->table);
|
||||
$this->canDo = ComponentbuilderHelper::getActions('snippet');
|
||||
@ -598,7 +606,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
$values['published'] = 0;
|
||||
}
|
||||
|
||||
$newIds = array();
|
||||
$newIds = [];
|
||||
// Parent exists so let's proceed
|
||||
while (!empty($pks))
|
||||
{
|
||||
@ -611,7 +619,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
if (!$this->user->authorise('core.edit', $contexts[$pk]))
|
||||
{
|
||||
// Not fatal error
|
||||
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -627,19 +635,19 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
else
|
||||
{
|
||||
// Not fatal error
|
||||
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Only for strings
|
||||
if (ComponentbuilderHelper::checkString($this->table->name) && !is_numeric($this->table->name))
|
||||
if (UtilitiesStringHelper::check($this->table->name) && !is_numeric($this->table->name))
|
||||
{
|
||||
$this->table->name = $this->generateUnique('name',$this->table->name);
|
||||
}
|
||||
|
||||
// insert all set values
|
||||
if (ComponentbuilderHelper::checkArray($values))
|
||||
if (UtilitiesArrayHelper::check($values))
|
||||
{
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
@ -651,7 +659,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
}
|
||||
|
||||
// update all unique fields
|
||||
if (ComponentbuilderHelper::checkArray($uniqueFields))
|
||||
if (UtilitiesArrayHelper::check($uniqueFields))
|
||||
{
|
||||
foreach ($uniqueFields as $uniqueField)
|
||||
{
|
||||
@ -715,7 +723,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
if (empty($this->batchSet))
|
||||
{
|
||||
// Set some needed variables.
|
||||
$this->user = JFactory::getUser();
|
||||
$this->user = Factory::getUser();
|
||||
$this->table = $this->getTable();
|
||||
$this->tableClassName = get_class($this->table);
|
||||
$this->canDo = ComponentbuilderHelper::getActions('snippet');
|
||||
@ -723,7 +731,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
|
||||
if (!$this->canDo->get('core.edit') && !$this->canDo->get('snippet.batch'))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
|
||||
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -740,7 +748,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
if (!$this->user->authorise('core.edit', $contexts[$pk]))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
|
||||
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -756,13 +764,13 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
else
|
||||
{
|
||||
// Not fatal error
|
||||
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// insert all set values.
|
||||
if (ComponentbuilderHelper::checkArray($values))
|
||||
if (UtilitiesArrayHelper::check($values))
|
||||
{
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
@ -806,7 +814,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
@ -818,15 +826,15 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$input = JFactory::getApplication()->input;
|
||||
$filter = JFilterInput::getInstance();
|
||||
|
||||
$input = Factory::getApplication()->input;
|
||||
$filter = InputFilter::getInstance();
|
||||
|
||||
// set the metadata to the Item Data
|
||||
if (isset($data['metadata']) && isset($data['metadata']['author']))
|
||||
{
|
||||
$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
|
||||
|
||||
$metadata = new JRegistry;
|
||||
|
||||
$metadata = new Registry;
|
||||
$metadata->loadArray($data['metadata']);
|
||||
$data['metadata'] = (string) $metadata;
|
||||
}
|
||||
@ -835,9 +843,9 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
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 = ComponentbuilderHelper::getVar('library', $item['library'], 'id', 'name')) ? $name:'Common';
|
||||
$library = ($name = GetHelper::var('library', $item['library'], 'id', 'name')) ? $name:'Common';
|
||||
// get the library name
|
||||
$type = ($name = ComponentbuilderHelper::getVar('snippet_type', $item['type'], 'id', 'name')) ? $name:'No Library';
|
||||
$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)
|
||||
@ -868,11 +876,11 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
$data['snippet'] = base64_encode($data['snippet']);
|
||||
}
|
||||
|
||||
|
||||
// Set the Params Items to data
|
||||
if (isset($data['params']) && is_array($data['params']))
|
||||
{
|
||||
$params = new JRegistry;
|
||||
$params = new Registry;
|
||||
$params->loadArray($data['params']);
|
||||
$data['params'] = (string) $params;
|
||||
}
|
||||
@ -882,7 +890,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
{
|
||||
// Automatic handling of other unique fields
|
||||
$uniqueFields = $this->getUniqueFields();
|
||||
if (ComponentbuilderHelper::checkArray($uniqueFields))
|
||||
if (UtilitiesArrayHelper::check($uniqueFields))
|
||||
{
|
||||
foreach ($uniqueFields as $uniqueField)
|
||||
{
|
||||
@ -890,14 +898,14 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (parent::save($data))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to generate a unique value.
|
||||
*
|
||||
@ -910,7 +918,6 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
*/
|
||||
protected function generateUnique($field,$value)
|
||||
{
|
||||
|
||||
// set field value unique
|
||||
$table = $this->getTable();
|
||||
|
||||
@ -936,7 +943,7 @@ class ComponentbuilderModelSnippet extends AdminModel
|
||||
// Alter the title
|
||||
$table = $this->getTable();
|
||||
|
||||
while ($table->load(array('title' => $title)))
|
||||
while ($table->load(['title' => $title]))
|
||||
{
|
||||
$title = StringHelper::increment($title);
|
||||
}
|
||||
|
Reference in New Issue
Block a user