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,13 +12,20 @@
|
||||
// No direct access to this file
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filter\OutputFilter;
|
||||
use Joomla\CMS\Installer\InstallerHelper;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\String\StringHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
|
||||
/**
|
||||
* Componentbuilder Import_language_translations Base Database Model
|
||||
@ -28,8 +35,8 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
// set uploading values
|
||||
protected $use_streams = false;
|
||||
protected $allow_unsafe = false;
|
||||
protected $safeFileOptions = array();
|
||||
|
||||
protected $safeFileOptions = [];
|
||||
|
||||
/**
|
||||
* @var object JTable object
|
||||
*/
|
||||
@ -46,13 +53,13 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = 'com_componentbuilder.import_language_translations';
|
||||
|
||||
|
||||
/**
|
||||
* Import Settings
|
||||
*/
|
||||
protected $getType = NULL;
|
||||
protected $dataType = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
@ -63,7 +70,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = JFactory::getApplication('administrator');
|
||||
$app = Factory::getApplication('administrator');
|
||||
|
||||
$this->setState('message', $app->getUserState('com_componentbuilder.message'));
|
||||
$app->setUserState('com_componentbuilder.message', '');
|
||||
@ -83,8 +90,8 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
public function import()
|
||||
{
|
||||
$this->setState('action', 'import');
|
||||
$app = JFactory::getApplication();
|
||||
$session = JFactory::getSession();
|
||||
$app = Factory::getApplication();
|
||||
$session = Factory::getSession();
|
||||
$package = null;
|
||||
$continue = false;
|
||||
// get import type
|
||||
@ -121,7 +128,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
break;
|
||||
|
||||
default:
|
||||
$app->setUserState('com_componentbuilder.message', JText::_('COM_COMPONENTBUILDER_IMPORT_NO_IMPORT_TYPE_FOUND'));
|
||||
$app->setUserState('com_componentbuilder.message', Text::_('COM_COMPONENTBUILDER_IMPORT_NO_IMPORT_TYPE_FOUND'));
|
||||
|
||||
return false;
|
||||
break;
|
||||
@ -135,7 +142,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
$this->remove($package['packagename']);
|
||||
}
|
||||
|
||||
$app->setUserState('com_componentbuilder.message', JText::_('COM_COMPONENTBUILDER_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));
|
||||
$app->setUserState('com_componentbuilder.message', Text::_('COM_COMPONENTBUILDER_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -152,7 +159,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
if (!$this->setData($package,$this->dataType,$headerList))
|
||||
{
|
||||
// There was an error importing the package
|
||||
$msg = JText::_('COM_COMPONENTBUILDER_IMPORT_ERROR');
|
||||
$msg = Text::_('COM_COMPONENTBUILDER_IMPORT_ERROR');
|
||||
$back = $session->get('backto_VDM_IMPORT', NULL);
|
||||
if ($back)
|
||||
{
|
||||
@ -164,7 +171,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
else
|
||||
{
|
||||
// Package imported sucessfully
|
||||
$msg = JText::sprintf('COM_COMPONENTBUILDER_IMPORT_SUCCESS', $package['packagename']);
|
||||
$msg = Text::sprintf('COM_COMPONENTBUILDER_IMPORT_SUCCESS', $package['packagename']);
|
||||
$back = $session->get('backto_VDM_IMPORT', NULL);
|
||||
if ($back)
|
||||
{
|
||||
@ -181,7 +188,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
$this->remove($package['packagename']);
|
||||
$session->clear($this->getType.'_VDM_IMPORTHEADERS');
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out an importation spreadsheet from a HTTP upload
|
||||
@ -189,37 +196,37 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
* @return spreadsheet definition or false on failure
|
||||
*/
|
||||
protected function _getPackageFromUpload()
|
||||
{
|
||||
{
|
||||
// Get the uploaded file information
|
||||
$app = JFactory::getApplication();
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
|
||||
// Do not change the filter type 'raw'. We need this to let files containing PHP code to upload. See JInputFiles::get.
|
||||
$userfile = $input->files->get('import_package', null, 'raw');
|
||||
|
||||
|
||||
// Make sure that file uploads are enabled in php
|
||||
if (!(bool) ini_get('file_uploads'))
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_WARNIMPORTFILE'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_WARNIMPORTFILE'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there is no uploaded file, we have a problem...
|
||||
if (!is_array($userfile))
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_NO_FILE_SELECTED'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_NO_FILE_SELECTED'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if there was a problem uploading the file.
|
||||
if ($userfile['error'] || $userfile['size'] < 1)
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_WARNIMPORTUPLOADERROR'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_WARNIMPORTUPLOADERROR'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build the appropriate paths
|
||||
$config = JFactory::getConfig();
|
||||
$config = Factory::getConfig();
|
||||
$tmp_dest = $config->get('tmp_path') . '/' . $userfile['name'];
|
||||
$tmp_src = $userfile['tmp_name'];
|
||||
|
||||
@ -229,7 +236,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
// Was the package downloaded?
|
||||
if (!$p_file)
|
||||
{
|
||||
$session = JFactory::getSession();
|
||||
$session = Factory::getSession();
|
||||
$session->clear('package');
|
||||
$session->clear('dataType');
|
||||
$session->clear('hasPackage');
|
||||
@ -251,16 +258,16 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
*/
|
||||
protected function _getPackageFromFolder()
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
|
||||
// Get the path to the package to import
|
||||
$p_dir = $input->getString('import_directory');
|
||||
$p_dir = JPath::clean($p_dir);
|
||||
$p_dir = Path::clean($p_dir);
|
||||
// Did you give us a valid path?
|
||||
if (!file_exists($p_dir))
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_PLEASE_ENTER_A_PACKAGE_DIRECTORY'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_PLEASE_ENTER_A_PACKAGE_DIRECTORY'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -270,17 +277,17 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
// Did you give us a valid package?
|
||||
if (!$type)
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE'), 'warning');
|
||||
}
|
||||
|
||||
|
||||
// check the extention
|
||||
if(!$this->checkExtension($p_dir))
|
||||
{
|
||||
// set error message
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_DOES_NOT_HAVE_A_VALID_FILE_TYPE'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_DOES_NOT_HAVE_A_VALID_FILE_TYPE'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$package['packagename'] = null;
|
||||
$package['dir'] = $p_dir;
|
||||
$package['type'] = $type;
|
||||
@ -296,7 +303,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
*/
|
||||
protected function _getPackageFromUrl()
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
|
||||
// Get the URL of the package to import
|
||||
@ -305,17 +312,17 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
// Did you give us a URL?
|
||||
if (!$url)
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_ENTER_A_URL'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_ENTER_A_URL'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Download the package at the URL given
|
||||
$p_file = JInstallerHelper::downloadPackage($url);
|
||||
$p_file = InstallerHelper::downloadPackage($url);
|
||||
|
||||
// Was the package downloaded?
|
||||
if (!$p_file)
|
||||
{
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_INVALID_URL'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_INVALID_URL'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -324,7 +331,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a file and verifies it as a spreadsheet file
|
||||
* Supports .csv .xlsx .xls and .ods
|
||||
@ -336,29 +343,29 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
*/
|
||||
protected function check($archivename)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$app = Factory::getApplication();
|
||||
// Clean the name
|
||||
$archivename = JPath::clean($archivename);
|
||||
|
||||
$archivename = Path::clean($archivename);
|
||||
|
||||
// check the extention
|
||||
if(!$this->checkExtension($archivename))
|
||||
{
|
||||
// Cleanup the import files
|
||||
$this->remove($archivename);
|
||||
$app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_IMPORT_MSG_DOES_NOT_HAVE_A_VALID_FILE_TYPE'), 'warning');
|
||||
$app->enqueueMessage(Text::_('COM_COMPONENTBUILDER_IMPORT_MSG_DOES_NOT_HAVE_A_VALID_FILE_TYPE'), 'warning');
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
$config = Factory::getConfig();
|
||||
// set Package Name
|
||||
$check['packagename'] = $archivename;
|
||||
|
||||
|
||||
// set directory
|
||||
$check['dir'] = $config->get('tmp_path'). '/' .$archivename;
|
||||
|
||||
|
||||
// set type
|
||||
$check['type'] = $this->getType;
|
||||
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
@ -394,9 +401,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
*/
|
||||
protected function remove($package)
|
||||
{
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
$config = Factory::getConfig();
|
||||
$package = $config->get('tmp_path'). '/' .$package;
|
||||
|
||||
// Is the package file a valid file?
|
||||
@ -404,10 +409,10 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
{
|
||||
File::delete($package);
|
||||
}
|
||||
elseif (is_file(JPath::clean($package)))
|
||||
elseif (is_file(Path::clean($package)))
|
||||
{
|
||||
// It might also be just a base filename
|
||||
File::delete(JPath::clean($package));
|
||||
File::delete(Path::clean($package));
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +430,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
{
|
||||
// make sure the file is loaded
|
||||
ComponentbuilderHelper::composerAutoload('phpspreadsheet');
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$jinput = Factory::getApplication()->input;
|
||||
foreach($target_headers as $header)
|
||||
{
|
||||
if (($column = $jinput->getString($header, false)) !== false ||
|
||||
@ -465,10 +470,10 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
protected function save($data, $table)
|
||||
{
|
||||
// import the data if there is any
|
||||
if(ComponentbuilderHelper::checkArray($data['array']))
|
||||
if(UtilitiesArrayHelper::check($data['array']))
|
||||
{
|
||||
// get user object
|
||||
$user = JFactory::getUser();
|
||||
$user = Factory::getUser();
|
||||
// remove header if it has headers
|
||||
$id_key = $data['target_headers']['id'];
|
||||
if (isset($data['target_headers']['Source']))
|
||||
@ -491,14 +496,14 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
array_shift($data['array']);
|
||||
}
|
||||
// make sure there is still values in array and that it was not only headers
|
||||
if(ComponentbuilderHelper::checkArray($data['array']) && $user->authorise($table.'.import', 'com_componentbuilder') && $user->authorise('core.import', 'com_componentbuilder'))
|
||||
if(UtilitiesArrayHelper::check($data['array']) && $user->authorise($table.'.import', 'com_componentbuilder') && $user->authorise('core.import', 'com_componentbuilder'))
|
||||
{
|
||||
// set target.
|
||||
$target = array_flip($data['target_headers']);
|
||||
// Get a db connection.
|
||||
$db = JFactory::getDbo();
|
||||
$db = Factory::getDbo();
|
||||
// set some defaults
|
||||
$todayDate = JFactory::getDate()->toSql();
|
||||
$todayDate = Factory::getDate()->toSql();
|
||||
// get global action permissions
|
||||
$canDo = ComponentbuilderHelper::getActions($table);
|
||||
$canEdit = $canDo->get('core.edit');
|
||||
@ -512,7 +517,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
$found = false;
|
||||
$has_id = false;
|
||||
// check that we have a string or a number<-(which is weird... but happens at times)
|
||||
if ($canEdit && isset($row[$source_key]) && (StringHelper::check($row[$source_key]) || is_numeric($row[$source_key])))
|
||||
if ($canEdit && isset($row[$source_key]) && (UtilitiesStringHelper::check($row[$source_key]) || is_numeric($row[$source_key])))
|
||||
{
|
||||
// raw items import & update!
|
||||
$query = $db->getQuery(true);
|
||||
@ -549,7 +554,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
$item = $db->loadObject();
|
||||
$id = $item->id;
|
||||
// load previous translation strings
|
||||
if (ComponentbuilderHelper::checkJson($item->translation))
|
||||
if (JsonHelper::check($item->translation))
|
||||
{
|
||||
$translations = json_decode($item->translation, true);
|
||||
$counter = count($translations) + 2;
|
||||
@ -586,7 +591,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
if(in_array($target[$key], $languages))
|
||||
{
|
||||
// only add if it has a string
|
||||
if (ComponentbuilderHelper::checkString($cell))
|
||||
if (UtilitiesStringHelper::check($cell))
|
||||
{
|
||||
// remove if was set previously
|
||||
if ($pre)
|
||||
@ -622,7 +627,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
}
|
||||
}
|
||||
// set the translation
|
||||
if (ComponentbuilderHelper::checkArray($translations))
|
||||
if (UtilitiesArrayHelper::check($translations))
|
||||
{
|
||||
$fields[] = $db->quoteName('translation') . ' = ' . $db->quote(json_encode($translations, JSON_FORCE_OBJECT));
|
||||
// load the defaults
|
||||
@ -663,7 +668,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
if(in_array($target[$key], $languages))
|
||||
{
|
||||
// only add if it has a string
|
||||
if (ComponentbuilderHelper::checkString($cell))
|
||||
if (UtilitiesStringHelper::check($cell))
|
||||
{
|
||||
$translations['translation'.$counter] = array('language' => $target[$key], 'translation' => $cell);
|
||||
$counter++;
|
||||
@ -694,13 +699,13 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
}
|
||||
}
|
||||
// set the translation
|
||||
if (ComponentbuilderHelper::checkArray($translations))
|
||||
if (UtilitiesArrayHelper::check($translations))
|
||||
{
|
||||
$columns[] = 'translation';
|
||||
$values[] = $db->quote(json_encode($translations, JSON_FORCE_OBJECT));
|
||||
}
|
||||
// check if we have values
|
||||
if (ComponentbuilderHelper::checkArray($values))
|
||||
if (UtilitiesArrayHelper::check($values))
|
||||
{
|
||||
// load the defaults
|
||||
$columns[] = 'created_by';
|
||||
@ -725,13 +730,13 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
protected function getAlias($name,$type = false)
|
||||
{
|
||||
// sanitize the name to an alias
|
||||
if (JFactory::getConfig()->get('unicodeslugs') == 1)
|
||||
if (Factory::getConfig()->get('unicodeslugs') == 1)
|
||||
{
|
||||
$alias = JFilterOutput::stringURLUnicodeSlug($name);
|
||||
$alias = OutputFilter::stringURLUnicodeSlug($name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$alias = JFilterOutput::stringURLSafe($name);
|
||||
$alias = OutputFilter::stringURLSafe($name);
|
||||
}
|
||||
// must be a uniqe alias
|
||||
if ($type)
|
||||
@ -740,7 +745,7 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
}
|
||||
return $alias;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to generate a uniqe value.
|
||||
*
|
||||
@ -755,16 +760,16 @@ class ComponentbuilderModelImport_language_translations extends BaseDatabaseMode
|
||||
// insure the filed is always uniqe
|
||||
while (isset($this->uniqeValueArray[$type][$field][$value]))
|
||||
{
|
||||
$value = JString::increment($value, 'dash');
|
||||
$value = StringHelper::increment($value, 'dash');
|
||||
}
|
||||
$this->uniqeValueArray[$type][$field][$value] = $value;
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
protected function getAliasesUsed($table)
|
||||
{
|
||||
// Get a db connection.
|
||||
$db = JFactory::getDbo();
|
||||
$db = Factory::getDbo();
|
||||
// first we check if there is a alias column
|
||||
$columns = $db->getTableColumns('#__componentbuilder_'.$table);
|
||||
if(isset($columns['alias'])){
|
||||
|
Reference in New Issue
Block a user