From 05eaf2cc570786bbf5f55adb4ba5eb70b88ec68e Mon Sep 17 00:00:00 2001 From: dmitriitsymbal Date: Fri, 16 Jan 2026 13:53:20 +0300 Subject: [PATCH] refactor fields, delete legacy --- fields/Layouts/Helper/LayoutPathsHelper.php | 12 +- fields/Layouts/LayoutsField.php | 8 +- fields/Layouts/LayoutsmoduleField.php | 16 +- fields/Layouts/LayoutspluginField.php | 19 +- fields/ListArticles/ListarticlesField.php | 2 +- fields/ListArticles/helpers/articles.php | 17 +- fields/ListComponents/ListcomponentsField.php | 68 ++---- fields/Modal/ModuleidField.php | 24 ++- .../QuantumaccessiblemediaField.php | 28 +-- .../QuantumuploadimageField.php | 20 +- .../QuantumUploadImage/layouts/pickimage.php | 4 +- fields/SelectMenuItem/SelectmenuitemField.php | 22 +- .../SelectMenuItem/layouts/selectmenuitem.php | 198 ++++++++++-------- fields/SubformMore/SubformmoreField.php | 19 +- fields/SubformMore/layouts/subformmore.php | 156 +++++++------- .../layouts/subformmore/section.php | 6 +- fields/SubformMore/media/js/subformmore.js | 1 - fields/UsersGroup/UsersgroupField.php | 13 +- fields/YandexMaps/YandexmapssuggestField.php | 39 ---- fields/YandexMaps/media/js/geocoder.js | 21 -- fields/YandexMaps/media/js/suggest.js | 24 --- .../libfieldsapikey/libfieldsapikey.php | 8 - .../libfieldsapikey/libfieldsapikey.xml | 0 script.php | 83 +------- 24 files changed, 296 insertions(+), 512 deletions(-) delete mode 100644 fields/YandexMaps/YandexmapssuggestField.php delete mode 100644 fields/YandexMaps/media/js/geocoder.js delete mode 100644 fields/YandexMaps/media/js/suggest.js delete mode 100644 plugins/system/libfieldsapikey/libfieldsapikey.php delete mode 100644 plugins/system/libfieldsapikey/libfieldsapikey.xml diff --git a/fields/Layouts/Helper/LayoutPathsHelper.php b/fields/Layouts/Helper/LayoutPathsHelper.php index eb3373f..916718f 100644 --- a/fields/Layouts/Helper/LayoutPathsHelper.php +++ b/fields/Layouts/Helper/LayoutPathsHelper.php @@ -1,6 +1,8 @@ -paths; } - protected function set($paths = []) { $this->paths = $paths; } - protected function add($path) { if (in_array($path['path'], $this->cache_paths)) @@ -149,5 +146,4 @@ protected function add($path) return true; } - } \ No newline at end of file diff --git a/fields/Layouts/LayoutsField.php b/fields/Layouts/LayoutsField.php index c56675c..0d9bfcc 100644 --- a/fields/Layouts/LayoutsField.php +++ b/fields/Layouts/LayoutsField.php @@ -1,6 +1,8 @@ -element['template']; $template = preg_replace('#\W#', '', $template); @@ -57,11 +59,11 @@ protected function getInput() $template_style_id = preg_replace('#\W#', '', $template_style_id); } - $lang = Factory::getLanguage(); + $lang = Factory::getApplication()->getLanguage(); $lang->load($module . '.sys', $client->path, null, false, true) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, true); - $db = Factory::getDbo(); + $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true); $query diff --git a/fields/Layouts/LayoutspluginField.php b/fields/Layouts/LayoutspluginField.php index 8220fb2..a49df40 100644 --- a/fields/Layouts/LayoutspluginField.php +++ b/fields/Layouts/LayoutspluginField.php @@ -1,6 +1,8 @@ -element['template']; $template = preg_replace('#\W#', '', $template); @@ -66,11 +66,12 @@ protected function getInput() $template_style_id = preg_replace('#\W#', '', $template_style_id); } - $lang = Factory::getLanguage(); + $lang = Factory::getApplication()->getLanguage(); $lang->load($plugin . '.sys', $client->path, null, false, true) || $lang->load($plugin . '.sys', $client->path . '/plugins/' . $folder . '/' . $plugin, null, false, true); - $db = Factory::getDbo(); + /** @var DatabaseDriver $db */ + $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true); $query diff --git a/fields/ListArticles/ListarticlesField.php b/fields/ListArticles/ListarticlesField.php index 5a0fb65..3f321c5 100644 --- a/fields/ListArticles/ListarticlesField.php +++ b/fields/ListArticles/ListarticlesField.php @@ -20,7 +20,7 @@ class ListarticlesField extends ListField * @var string * @since 1.6 */ - public $type = 'ListArticles'; + public $type = 'Listarticles'; /** * diff --git a/fields/ListArticles/helpers/articles.php b/fields/ListArticles/helpers/articles.php index 5273a4b..120f611 100644 --- a/fields/ListArticles/helpers/articles.php +++ b/fields/ListArticles/helpers/articles.php @@ -2,6 +2,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\Database\DatabaseDriver; use Joomla\Utilities\ArrayHelper; /** @@ -35,20 +36,22 @@ public static function options($config = []) $config = array_merge($config, [ 'filter.published' => [0, 1] ]); - $hash = md5('lib_fields' . '.' . serialize($config)); + $hash = md5('lib_fields' . '.' . serialize($config)); if (!isset(static::$items[$hash])) { $config = (array) $config; - $db = Factory::getDbo(); - $user = Factory::getUser(); + /** @var DatabaseDriver $db */ + $db = Factory::getContainer()->get(DatabaseDriver::class); + $user = Factory::getApplication()->getIdentity(); $groups = implode(',', $user->getAuthorisedViewLevels()); $query = $db->getQuery(true) ->select("con.id, REPLACE(con.title, '\"', '') as title, con.language") ->from('#__content AS con'); - if(isset($config['filter.category'])) { + if (isset($config['filter.category'])) + { $category = (int) $config['filter.category']; $query->innerJoin("(SELECT node.id FROM #__categories AS node, #__categories AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND (parent.parent_id = " . $category . " OR parent.id = " . $category . ") ORDER BY node.lft) AS cat ON (con.catid = cat.id)"); } @@ -88,7 +91,7 @@ public static function options($config = []) // Filter on the language if (isset($config['filter.q'])) { - $search = $db->Quote( '%' . $db->escape( $config['filter.q'], true ) . '%' ); + $search = $db->Quote('%' . $db->escape($config['filter.q'], true) . '%'); $query->where("title LIKE " . $search); } @@ -96,13 +99,13 @@ public static function options($config = []) // Filter on the language if (isset($config['filter.limit'])) { - $query->setLimit((int)$config['filter.limit']); + $query->setLimit((int) $config['filter.limit']); } // Filter on the language if (isset($config['filter.ids'])) { - $ids = $db->escape( implode(',', $config['filter.ids']), true ); + $ids = $db->escape(implode(',', $config['filter.ids']), true); $query->where("con.id in (" . $ids . ')'); } diff --git a/fields/ListComponents/ListcomponentsField.php b/fields/ListComponents/ListcomponentsField.php index 0daea47..315414e 100644 --- a/fields/ListComponents/ListcomponentsField.php +++ b/fields/ListComponents/ListcomponentsField.php @@ -1,4 +1,6 @@ -_options === null) { - // Get components - $db = Factory::getDbo(); + /** @var DatabaseDriver $db */ + $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true) ->select(['e.element']) ->from($db->quoteName('#__extensions', 'e')) @@ -98,7 +76,6 @@ protected function getOptions() } } - // Convert options $options = parent::getOptions(); foreach ($options as $key => $option) @@ -133,9 +110,8 @@ protected function getOptions() } - // Prepare options $pluginConstant = 'LIB_FIELDS_FIELD_LIST_COMPONENTS'; - $language = Factory::getLanguage(); + $language = Factory::getApplication()->getLanguage(); $language_tag = $language->getTag(); $language->load('lib_fields', JPATH_SITE, $language_tag, true); foreach ($components as $component => $views) @@ -145,7 +121,6 @@ protected function getOptions() $componentText = ($language->hasKey($componentConstant)) ? Text::_($componentConstant) : ucfirst(str_replace('com_', '', $component)); - // Add views foreach ($views as $view => $layouts) { $viewValue = $componentValue . '.' . $view; @@ -158,7 +133,6 @@ protected function getOptions() $option->text = $viewText; $options[] = $option; - // Add layouts foreach ($layouts as $layout) { $layoutValue = $viewValue . ':' . $layout; @@ -181,14 +155,6 @@ protected function getOptions() return $this->_options; } - /** - * Check if relevant folder exists with different paths for J3 and J4 - * - * @param string $component - * @param string $rootComponents - * - * @return string|bool - */ private static function checkFolder(string $component, string $rootComponents = JPATH_ROOT) { $jversion = new Version(); @@ -209,14 +175,6 @@ private static function checkFolder(string $component, string $rootComponents = return false; } - /** - * Check if there is an edit option in views for J4 - * - * @param string $folder - * @param string $view - * - * @return bool - */ private static function checkEditOption(string $folder, string $view) { $editFile = $folder . DIRECTORY_SEPARATOR . $view . DIRECTORY_SEPARATOR . 'edit.php'; diff --git a/fields/Modal/ModuleidField.php b/fields/Modal/ModuleidField.php index 8007183..5eba6b2 100644 --- a/fields/Modal/ModuleidField.php +++ b/fields/Modal/ModuleidField.php @@ -1,11 +1,15 @@ -get(DatabaseDriver::class); $db->setQuery('SELECT id, title FROM #__modules'); try @@ -37,7 +42,6 @@ public function getInput() if (self::$declareScriptFlag) { - // Build the script. $script = array(); $script[] = ' function jInsertEditorText(text, elementId) {'; $script[] = ' var moduleData = ' . json_encode($data) . ';'; @@ -47,8 +51,10 @@ public function getInput() $script[] = ' SqueezeBox.close();'; $script[] = ' }'; - // Add the script to the document head. - Factory::getDocument()->addScriptDeclaration(implode("\n", $script)); + /** @var WebAssetManager $wa */ + $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); + $wa->addInlineScript(implode("\n", $script)); + self::$declareScriptFlag = false; } @@ -68,8 +74,8 @@ public function getInput() $html[] = ''; $html[] = ' - - ' . JText::_(self::BTN_VALUE) . ' + + ' . Text::_(self::BTN_VALUE) . ' '; $html[] = ''; $html[] = ''; diff --git a/fields/QuantumAccessibleMedia/QuantumaccessiblemediaField.php b/fields/QuantumAccessibleMedia/QuantumaccessiblemediaField.php index 6d21cea..66506fa 100644 --- a/fields/QuantumAccessibleMedia/QuantumaccessiblemediaField.php +++ b/fields/QuantumAccessibleMedia/QuantumaccessiblemediaField.php @@ -1,44 +1,26 @@ -load('com_modules'); + Factory::getApplication()->getLanguage()->load('com_modules'); + return parent::getLayoutData(); } - public function getInput() { HTMLHelper::_('stylesheet', 'lib_fields/selectmenuitem/selectmenuitem.css', [ - 'version' => filemtime(__FILE__), + 'version' => filemtime(__FILE__), 'relative' => true ]); HTMLHelper::_('script', 'lib_fields/selectmenuitem/selectmenuitem.js', [ - 'version' => filemtime(__FILE__), + 'version' => filemtime(__FILE__), 'relative' => true ]); return parent::getInput(); } - } \ No newline at end of file diff --git a/fields/SelectMenuItem/layouts/selectmenuitem.php b/fields/SelectMenuItem/layouts/selectmenuitem.php index 9c7f7e0..3d6d878 100644 --- a/fields/SelectMenuItem/layouts/selectmenuitem.php +++ b/fields/SelectMenuItem/layouts/selectmenuitem.php @@ -1,117 +1,129 @@ 'auto', 'relative' => true)); +HTMLHelper::_('script', 'jui/treeselectmenu.jquery.min.js', array('version' => 'auto', 'relative' => true)); extract($displayData); -if(!is_array($value)) +if (!is_array($value)) { - $value = []; + $value = []; } ?>
-
- - - -
- : - , - +
+ + + +
+ : + , + - | - : - , - + | + : + , + -
- -
    - - links)) : ?> - -
  • -
    -
    -
    -
    title; ?>
    +
    + +
      + + links)) : ?> + +
    • +
      +
      +
      +
      title; ?>
      +
      +
      + + links as $i => $link) : ?> + level) + { + echo '
        '; + } + elseif ($prevlevel > $link->level) + { + echo str_repeat('
      ', $prevlevel - $link->level); + } + else + { + echo '
    • '; + } + + // переписать выборку + $selected = 0; + if (in_array($link->value, $value)) + { + $selected = 1; + } + + ?> +
    • +
      +
      +
      + type, array('separator', 'heading', 'alias', 'url')); + ?> + /> + + +
      + , +
      -
      - links as $i => $link) : ?> - level) - { - echo '
        '; - } elseif ($prevlevel > $link->level) - { - echo str_repeat('
      ', $prevlevel - $link->level); - } else { - echo '
    • '; - } - - // переписать выборку - $selected = 0; - if(in_array($link->value, $value)) - { - $selected = 1; - } - - ?> -
    • -
      -
      -
      - type, array('separator', 'heading', 'alias', 'url')); - ?> - /> - - -
      - , - -
      - -
      -
      +
    +
- links[$i + 1])) - { - echo str_repeat('', $link->level); - } - $prevlevel = $link->level; - ?> - - - - - + if (!isset($type->links[$i + 1])) + { + echo str_repeat('', $link->level); + } + $prevlevel = $link->level; + ?> + + + + + - -
+ +
\ No newline at end of file diff --git a/fields/SubformMore/SubformmoreField.php b/fields/SubformMore/SubformmoreField.php index 2e1af59..12b2e42 100644 --- a/fields/SubformMore/SubformmoreField.php +++ b/fields/SubformMore/SubformmoreField.php @@ -1,6 +1,8 @@ - true ]); - return parent::getInput(); // TODO: Change the autogenerated stub + return parent::getInput(); } - } \ No newline at end of file diff --git a/fields/SubformMore/layouts/subformmore.php b/fields/SubformMore/layouts/subformmore.php index 00e26da..71da06d 100644 --- a/fields/SubformMore/layouts/subformmore.php +++ b/fields/SubformMore/layouts/subformmore.php @@ -1,34 +1,38 @@ - 'auto', 'relative' => true)); + HTMLHelper::_('jquery.ui', array('core', 'sortable')); + HTMLHelper::_('script', 'system/subform-repeatable.js', array('version' => 'auto', 'relative' => true)); } -// Build heading $table_head = ''; -$count = count($tmpl->getFieldset('default')); +$count = count($tmpl->getFieldset('default')); -foreach ($tmpl->getFieldset('default') as $field) { +foreach ($tmpl->getFieldset('default') as $field) +{ $table_head .= '' . strip_tags($field->label); if ($field->description) @@ -43,66 +47,66 @@ ?>
-
-
- - - $form): - echo $this->sublayout( - $sublayout, - array( - 'form' => $form, - 'basegroup' => $fieldname, - 'group' => $fieldname . $k, - 'buttons' => $buttons, - 'unique_subform_id' => $unique_subform_id, - ) - ); - endforeach; ?> - +
+
+
+ + $form): + echo $this->sublayout( + $sublayout, + array( + 'form' => $form, + 'basegroup' => $fieldname, + 'group' => $fieldname . $k, + 'buttons' => $buttons, + 'unique_subform_id' => $unique_subform_id, + ) + ); + endforeach; ?> + - - - + aria-label="" + > + + + + -
- + + - - -
+ - - - -
-
+ + + +
+ diff --git a/fields/SubformMore/layouts/subformmore/section.php b/fields/SubformMore/layouts/subformmore/section.php index 88321f4..8301454 100644 --- a/fields/SubformMore/layouts/subformmore/section.php +++ b/fields/SubformMore/layouts/subformmore/section.php @@ -1,4 +1,6 @@ -getFieldset('default') as $field) { $table_head .= '' . strip_tags($field->label); @@ -27,7 +28,6 @@ $table_head .= ''; } - ?> _options === null) { - // Get components - $db = Factory::getDbo(); + $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true) ->select(['id', 'title']) ->from($db->quoteName('#__usergroups')); diff --git a/fields/YandexMaps/YandexmapssuggestField.php b/fields/YandexMaps/YandexmapssuggestField.php deleted file mode 100644 index e6abdde..0000000 --- a/fields/YandexMaps/YandexmapssuggestField.php +++ /dev/null @@ -1,39 +0,0 @@ -addScript('https://api-maps.yandex.ru/2.1/?lang=ru_RU'); - - HTMLHelper::script('lib_fields/yandexmaps/suggest.js', [ - 'version' => filemtime(__FILE__), - 'relative' => true, - ]); - - $id = "in-yandex-maps-" . random_int(1111, 9999); - $this->class = "in-yandex-maps span6 " . $this->class; - $this->id = $id; - - return '
' . parent::getInput() . '
'; - } - -} diff --git a/fields/YandexMaps/media/js/geocoder.js b/fields/YandexMaps/media/js/geocoder.js deleted file mode 100644 index 09127a1..0000000 --- a/fields/YandexMaps/media/js/geocoder.js +++ /dev/null @@ -1,21 +0,0 @@ -document.addEventListener("DOMContentLoaded", function () { - - ymaps.load(function () { - let list = document.querySelectorAll('.in-yandex-maps'); - for (let i = 0; i < list.length; i++) { - (new ymaps.SuggestView(list[i].getAttribute('id'))).events.add('select', function (event) { - ymaps.geocode(event.get('item').value).then(function (res) { - var id = event.get('target')._panel._anchor.id; - var obj = res.geoObjects.get(0), - error, hint; - var fulladdress = obj.properties.get('metaDataProperty.GeocoderMetaData.Address.formatted'); - var point = obj.properties.get('metaDataProperty.GeocoderMetaData.InternalToponymInfo.Point'); - list[i].value = fulladdress + ';' + point.coordinates[1] + ',' + point.coordinates[0]; - }, function (e) { - - }); - }); - } - }); - -}); \ No newline at end of file diff --git a/fields/YandexMaps/media/js/suggest.js b/fields/YandexMaps/media/js/suggest.js deleted file mode 100644 index adef8ef..0000000 --- a/fields/YandexMaps/media/js/suggest.js +++ /dev/null @@ -1,24 +0,0 @@ -document.addEventListener("DOMContentLoaded", function () { - - function initMaps(container) { - let list = container.querySelectorAll('.in-yandex-maps'); - for (let i = 0; i < list.length; i++) { - (new ymaps.SuggestView(list[i].getAttribute('id'))).events.add('select', function (event) { - list[i].value = event.get('item').value; - }); - } - } - - ymaps.load(function () { - initMaps(document); - }); - - if (window.jQuery !== undefined) { - jQuery(document).on('subform-row-add', function (event, row) { - initMaps(row); - }); - } - - - -}); \ No newline at end of file diff --git a/plugins/system/libfieldsapikey/libfieldsapikey.php b/plugins/system/libfieldsapikey/libfieldsapikey.php deleted file mode 100644 index b59622b..0000000 --- a/plugins/system/libfieldsapikey/libfieldsapikey.php +++ /dev/null @@ -1,8 +0,0 @@ -set(InstallerScriptInterface::class, new class ($container->get(AdministratorApplication::class)) implements InstallerScriptInterface { - /** - * The application object - * - * @var AdministratorApplication - * - * @since __DEPLOY_VERSION__ - */ + protected AdministratorApplication $app; - /** - * The Database object. - * - * @var DatabaseDriver - * - * @since __DEPLOY_VERSION__ - */ protected DatabaseDriver $db; - /** - * Constructor. - * - * @param AdministratorApplication $app The application object. - * - * @since __DEPLOY_VERSION__ - */ public function __construct(AdministratorApplication $app) { $this->app = $app; $this->db = Factory::getContainer()->get('DatabaseDriver'); } - /** - * Function called after the extension is installed. - * - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ public function install(InstallerAdapter $adapter): bool { $this->copyMedia(); @@ -72,15 +34,6 @@ public function install(InstallerAdapter $adapter): bool return true; } - /** - * Function called after the extension is updated. - * - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ public function update(InstallerAdapter $adapter): bool { $this->copyMedia(); @@ -88,15 +41,6 @@ public function update(InstallerAdapter $adapter): bool return true; } - /** - * Function called after the extension is uninstalled. - * - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ public function uninstall(InstallerAdapter $adapter): bool { $this->deleteMedia(); @@ -104,31 +48,11 @@ public function uninstall(InstallerAdapter $adapter): bool return true; } - /** - * Function called before extension installation/update/removal procedure commences. - * - * @param string $type The type of change (install or discover_install, update, uninstall) - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ public function preflight(string $type, InstallerAdapter $adapter): bool { return true; } - /** - * Function called after extension installation/update/removal procedure commences. - * - * @param string $type The type of change (install or discover_install, update, uninstall) - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ public function postflight(string $type, InstallerAdapter $adapter): bool { return true; @@ -176,7 +100,6 @@ protected function copyMedia() } - protected function deleteMedia() { $dest = JPATH_ROOT . '/media/lib_fields';