Fix the update server #978 issue. Fixed the change log to load all entries, not just the last one. Fixed #983 so that database updates are created when adding a new adminview. Moved a few builder arrays to the Compiler Registry. Adds super powers to JCB. Adds Gitea API library. Improves Power filters. Fix #991 to add the Utilities service class. Adds Superpower Key (SPK) replacement feature. Adds Superpower search (GREP) feature. Adds Power Insert/Update Classe. Fix #995 that all update sites are using the correct URL.

This commit is contained in:
2023-05-02 02:10:55 +02:00
parent d6c73987f5
commit df16b2e3ad
246 changed files with 24890 additions and 4141 deletions

View File

@ -23,9 +23,9 @@ if (file_exists($composer_autoloader))
spl_autoload_register(function ($class) {
// project-specific base directories and namespace prefix
$search = [
'libraries/jcb_powers/VDM.Joomla.Gitea' => 'VDM\\Joomla\\Gitea',
'libraries/jcb_powers/VDM.Joomla' => 'VDM\\Joomla',
'libraries/jcb_powers/VDM.Minify' => 'VDM\\Minify',
'libraries/jcb_powers/VDM.Gitea' => 'VDM\\Gitea',
'libraries/jcb_powers/VDM.Psr' => 'VDM\\Psr'
];
// Start the search and load if found
@ -5520,571 +5520,6 @@ abstract class ComponentbuilderHelper
}
/**
* get extensions grouped list xml
**/
public static function getExtensionGroupedListXml()
{
// the extension types
$extensions = array(
'joomla_component' => 'COM_COMPONENTBUILDER_COMPONENT',
'joomla_module' => 'COM_COMPONENTBUILDER_MODULE',
'joomla_plugin' => 'COM_COMPONENTBUILDER_PLUGIN'
);
// get the extension values
foreach ($extensions as $extension => $label)
{
${$extension} = self::getByTypeTheIdsSystemNames($extension);
}
$xml = new DOMDocument();
$xml->formatOutput = true;
$root = $xml->createElement('field');
$root->setAttributeNode(new DOMAttr('name', 'extension'));
$root->setAttributeNode(new DOMAttr('type', 'groupedlist'));
$root->setAttributeNode(new DOMAttr('onchange', 'this.form.submit();'));
$root
->appendChild($xml->createElement('option', '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_EXTENSION') . ' -'))
->setAttributeNode(new DOMAttr('value', ''));
foreach ($extensions as $extension => $label)
{
$extension_node = $xml->createElement('group');
$extension_node->setAttributeNode(new DOMAttr('label', $label));
if (!self::checkArray(${$extension}))
{
$extension_node
->appendChild($xml->createElement('option', '- ' . JText::_('COM_COMPONENTBUILDER_NONE') . ' -'))
->setAttributeNode(new DOMAttr('disabled', 'true'));
}
else
{
foreach (${$extension} as $id => $element)
{
$extension_node
->appendChild($xml->createElement('option', $element))
->setAttributeNode(new DOMAttr('value', $extension . '__' . $id));
}
}
$root->appendChild($extension_node);
}
$xml->appendChild($root);
return $xml->saveXML();
}
/**
* get by type the ids and system names
**/
public static function getByTypeTheIdsSystemNames($type, $limiter = null)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('id', 'system_name')))
->from($db->quoteName('#__componentbuilder_' . $type))
->where($db->quoteName('published') . ' >= 1')
->order($db->quoteName('modified') . ' desc')
->order($db->quoteName('created') . ' desc');
// check if we have a limter for admin views
if ($type === 'admin_view' && $limiter)
{
// first get all views
$adminviewIds = array();
// if this is a plugin or a module, then no views
if (strpos($limiter, 'joomla_component') !== false)
{
$component = (int) str_replace('joomla_component__', '', $limiter);
// get the views of this component
if ($addViews = self::getVar('component_admin_views', (int) $component, 'joomla_component', 'addadmin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['adminview']))
{
$adminviewIds[(int) $addView['adminview']] = (int) $addView['adminview'];
}
}
}
}
}
}
// now check if we still have admin views
if (self::checkArray($adminviewIds))
{
$query->where($db->quoteName('id') . ' IN (' . implode(',', $adminviewIds) . ')');
}
else
{
return false;
}
}
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadAssocList('id', 'system_name');
}
return false;
}
/**
* get any area linked IDs
*/
public static function getAreaLinkedIDs($extension, $type)
{
// What ever...
if ($type === 'joomla_component_admin_views')
{
return self::getComponentAdminViewsIDs($extension);
}
elseif ($type === 'joomla_component_custom_admin_views')
{
return self::getComponentCustomAdminViewsIDs($extension);
}
elseif ($type === 'joomla_component_site_views')
{
return self::getComponentSiteViewsIDs($extension);
}
elseif ($type === 'joomla_component')
{
return self::getComponentFieldsIDs($extension);
}
elseif ($type === 'joomla_module')
{
return self::getModuleFieldsIDs($extension);
}
elseif ($type === 'joomla_plugin')
{
return self::getPluginFieldsIDs($extension);
}
elseif ($type === 'admin_view')
{
return self::getAdminViewFieldsIDs($extension);
}
return false;
}
/**
* get a component admin views IDs
*/
public static function getComponentAdminViewsIDs($id)
{
// get all this components views
$adminviewIds = array();
// get the views of this component
if ($addViews = self::getVar('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['adminview']))
{
$adminviewIds[(int) $addView['adminview']] = (int) $addView['adminview'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($adminviewIds))
{
return array_values($adminviewIds);
}
return false;
}
/**
* get a component custom admin views IDs
*/
public static function getComponentCustomAdminViewsIDs($id)
{
// get all this components views
$adminviewIds = array();
// get the views of this component
if ($addViews = self::getVar('component_custom_admin_views', (int) $id, 'joomla_component', 'addcustom_admin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['customadminview']))
{
$adminviewIds[(int) $addView['customadminview']] = (int) $addView['customadminview'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($adminviewIds))
{
return array_values($adminviewIds);
}
return false;
}
/**
* get a component site views IDs
*/
public static function getComponentSiteViewsIDs($id)
{
// get all this components views
$adminviewIds = array();
// get the views of this component
if ($addViews = self::getVar('component_site_views', (int) $id, 'joomla_component', 'addsite_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['siteview']))
{
$adminviewIds[(int) $addView['siteview']] = (int) $addView['siteview'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($adminviewIds))
{
return array_values($adminviewIds);
}
return false;
}
/**
* get a component fields IDs
*/
public static function getComponentFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
// first get all views
$adminviewIds = array();
// get the views of this component
if ($addViews = self::getVar('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['adminview']))
{
$adminviewIds[(int) $addView['adminview']] = (int) $addView['adminview'];
}
}
}
}
}
// check that we have views
if (self::checkArray($adminviewIds))
{
foreach ($adminviewIds as $adminView)
{
// get all the fields linked to the admin view
if ($addFields = self::getVar('admin_fields', (int) $adminView, 'admin_view', 'addfields'))
{
if (self::checkJson($addFields))
{
$addFields = json_decode($addFields, true);
if (self::checkArray($addFields))
{
foreach($addFields as $addField)
{
if (isset($addField['field']))
{
$fieldIds[(int) $addField['field']] = (int) $addField['field'];
}
}
}
}
}
}
}
// get config values
if ($addconfig = self::getVar('component_config', (int) $id, 'joomla_component', 'addconfig'))
{
if (self::checkJson($addconfig))
{
$addconfig = json_decode($addconfig, true);
if (self::checkArray($addconfig))
{
foreach($addconfig as $addconf)
{
if (isset($addconf['field']))
{
$fieldIds[(int) $addconf['field']] = (int) $addconf['field'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get a module fields IDs
*/
public static function getModuleFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
if ($fields = self::getVar('joomla_module', (int) $id, 'id', 'fields'))
{
if (self::checkJson($fields))
{
$fields = json_decode($fields, true);
if (self::checkArray($fields))
{
foreach($fields as $form)
{
if (isset($form['fields']) && self::checkArray($form['fields']))
{
foreach ($form['fields'] as $field)
{
if (isset($field['field']))
{
$fieldIds[(int) $field['field']] = (int) $field['field'];
}
}
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get a plugin fields IDs
*/
public static function getPluginFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
if ($fields = self::getVar('joomla_plugin', (int) $id, 'id', 'fields'))
{
if (self::checkJson($fields))
{
$fields = json_decode($fields, true);
if (self::checkArray($fields))
{
foreach($fields as $form)
{
if (isset($form['fields']) && self::checkArray($form['fields']))
{
foreach ($form['fields'] as $field)
{
if (isset($field['field']))
{
$fieldIds[(int) $field['field']] = (int) $field['field'];
}
}
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get an admin view fields IDs
*/
public static function getAdminViewFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
// get all the fields linked to the admin view
if ($addFields = self::getVar('admin_fields', (int) $id, 'admin_view', 'addfields'))
{
if (self::checkJson($addFields))
{
$addFields = json_decode($addFields, true);
if (self::checkArray($addFields))
{
foreach($addFields as $addField)
{
if (isset($addField['field']))
{
$fieldIds[(int) $addField['field']] = (int) $addField['field'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get translation extension ids
**/
public static function getTranslationExtensionsIds($extension, $type)
{
// only allow these columns (extension types)
$columns = array(
'joomla_component' => 'components',
'joomla_module' => 'modules',
'joomla_plugin' => 'plugins'
);
// check if the column name is correct
if (isset($columns[$type]))
{
$column = $columns[$type];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('id', $column)))
->from($db->quoteName('#__componentbuilder_language_translation'))
->where($db->quoteName($column) . ' != ' . $db->quote(''));
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
$results = $db->loadAssocList();
$matches = array();
foreach ($results as $k => $v)
{
$value = json_decode($v[$column], true);
if (in_array($extension, $value))
{
$matches[$v['id']] = $v['id'];
}
}
// Checks that we found matches
if (self::checkArray($matches))
{
return array_values($matches);
}
}
}
return false;
}
/**
* get translation ids
**/
public static function getTranslationIds($language, $translated = true)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName('id'))
->from($db->quoteName('#__componentbuilder_language_translation'));
// Build the where condition
if ($translated === true) // Translated
{
if ($language === 'all')
{
if (($languages = self::getAvailableLanguages()) !== false)
{
$wheres = array();
foreach ($languages as $k => $v)
{
$wheres[] = $db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $k . '%');
}
$query->where($wheres);
}
}
else
{
$query->where($db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $language . '%'));
}
}
else // Not translated
{
if ($language === 'none')
{
$query->where(
array(
$db->quoteName('translation') . ' = ' . $db->quote(''),
$db->quoteName('translation') . ' = ' . $db->quote('[]'),
$db->quoteName('translation') . ' = ' . $db->quote('{}')
), 'OR'
);
}
else
{
$query->where($db->quoteName('translation') . ' NOT LIKE ' . $db->quote('%' . $language . '%'));
}
}
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return array_unique($db->loadColumn());
}
return false;
}
/**
* get available languages
**/
public static function getAvailableLanguages()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('langtag', 'name')))
->from($db->quoteName('#__componentbuilder_language'))
->where($db->quoteName('published') . ' = 1')
->order($db->quoteName('name') . ' desc');
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadAssocList('langtag', 'name');
}
return false;
}
/**
* Check if a row already exist
*