diff --git a/README.md b/README.md index f28e8ca..fba4738 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # CFI -![Version](https://img.shields.io/badge/VERSION-1.0.8-0366d6.svg?style=for-the-badge) +![Version](https://img.shields.io/badge/VERSION-1.0.9-0366d6.svg?style=for-the-badge) ![Joomla](https://img.shields.io/badge/joomla-3.7+-1A3867.svg?style=for-the-badge) ![Php](https://img.shields.io/badge/php-5.6+-8892BF.svg?style=for-the-badge) diff --git a/README.ru.md b/README.ru.md index 9a89a1d..f21c55a 100644 --- a/README.ru.md +++ b/README.ru.md @@ -1,6 +1,6 @@ # CFI -![Version](https://img.shields.io/badge/VERSION-1.0.8-0366d6.svg?style=for-the-badge) +![Version](https://img.shields.io/badge/VERSION-1.0.9-0366d6.svg?style=for-the-badge) ![Joomla](https://img.shields.io/badge/joomla-3.7+-1A3867.svg?style=for-the-badge) ![Php](https://img.shields.io/badge/php-5.6+-8892BF.svg?style=for-the-badge) diff --git a/assets/cfi.js b/assets/cfi.js index 3b593be..299fbe2 100644 --- a/assets/cfi.js +++ b/assets/cfi.js @@ -94,36 +94,38 @@ document.addEventListener('DOMContentLoaded', function () { xhr.setRequestHeader('X-CSRF-Token', Joomla.getOptions('csrf.token')); xhr.addEventListener('readystatechange', function (e) { - if (xhr.readyState == 4 && xhr.status == 200) { - var response = false; - try { - response = JSON.parse(xhr.response); - cfiDropArea.classList.remove('cfi-dropzone-highlight'); - cfiDropArea.classList.add('alert-' + (response.result ? 'success' : 'error')); - cfiDropLabel.innerHTML = '' + (response.result ? cfiDropArea.dataset.success : cfiDropArea.dataset.error) + '
' + response.message; - } catch (e) { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var response = false; + try { + response = JSON.parse(xhr.response); + cfiDropArea.classList.remove('cfi-dropzone-highlight'); + cfiDropArea.classList.add('alert-' + (response.result ? 'success' : 'error')); + cfiDropLabel.innerHTML = '' + (response.result ? cfiDropArea.dataset.success : cfiDropArea.dataset.error) + '
' + response.message; + } catch (e) { + cfiDropArea.classList.remove('cfi-dropzone-highlight'); + cfiDropArea.classList.add('alert-error'); + cfiDropLabel.innerHTML = '' + cfiDropArea.dataset.error + '' + xhr.response + ''; + } + cfiDropArea.style.pointerEvents = 'auto'; + cfiExportArea.style.pointerEvents = 'auto'; + if (response && response.result) { + var t = 10; + setInterval(function () { + t--; + document.getElementById('cfi-result-counter').innerText = t; + if (!t) { + location.reload(); + } + }, 1000); + } + } else { cfiDropArea.classList.remove('cfi-dropzone-highlight'); cfiDropArea.classList.add('alert-error'); - cfiDropLabel.innerHTML = '' + cfiDropArea.dataset.error + '' + xhr.response + ''; - } - cfiDropArea.style.pointerEvents = 'auto'; - cfiExportArea.style.pointerEvents = 'auto'; - if (response && response.result) { - var t = 10; - setInterval(function () { - t--; - document.getElementById('cfi-result-counter').innerText = t; - if (!t) { - location.reload(); - } - }, 1000); + cfiDropLabel.innerHTML = '' + xhr.status + 'Unknown error, look at the log'; + cfiDropArea.style.pointerEvents = 'auto'; + cfiExportArea.style.pointerEvents = 'auto'; } - } else { - cfiDropArea.classList.remove('cfi-dropzone-highlight'); - cfiDropArea.classList.add('alert-error'); - cfiDropLabel.innerHTML = '' + xhr.status + 'Unknown error, look at the log'; - cfiDropArea.style.pointerEvents = 'auto'; - cfiExportArea.style.pointerEvents = 'auto'; } }); @@ -155,29 +157,31 @@ document.addEventListener('DOMContentLoaded', function () { xhr.setRequestHeader('X-CSRF-Token', Joomla.getOptions('csrf.token')); xhr.addEventListener('readystatechange', function (e) { - if (xhr.readyState == 4 && xhr.status == 200) { - try { - var response = JSON.parse(xhr.response); - if (response.result) { - cfiLabelExport.classList.add('text-success'); - cfiLabelExport.innerHTML = cfiBtnExport.dataset.success; - window.location = url + '&format=raw&cfistate=download&f=' + response.f + '&' + Joomla.getOptions('csrf.token') + '=1'; - } else { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + try { + var response = JSON.parse(xhr.response); + if (response.result) { + cfiLabelExport.classList.add('text-success'); + cfiLabelExport.innerHTML = cfiBtnExport.dataset.success; + window.location = url + '&format=raw&cfistate=download&f=' + response.f + '&' + Joomla.getOptions('csrf.token') + '=1'; + } else { + cfiLabelExport.classList.add('text-error'); + cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '
' + response.message; + } + } catch (e) { cfiLabelExport.classList.add('text-error'); - cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '
' + response.message; + cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '
' + xhr.response; } - } catch (e) { - cfiLabelExport.classList.add('text-error'); - cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '
' + xhr.response; + cfiDropArea.style.pointerEvents = 'auto'; + cfiExportArea.style.pointerEvents = 'auto'; + } else { + cfiDropArea.classList.remove('cfi-dropzone-highlight'); + cfiDropArea.classList.add('alert-error'); + cfiLabelExport.innerHTML = '' + xhr.status + 'Unknown error, look at the log'; + cfiDropArea.style.pointerEvents = 'auto'; + cfiExportArea.style.pointerEvents = 'auto'; } - cfiDropArea.style.pointerEvents = 'auto'; - cfiExportArea.style.pointerEvents = 'auto'; - } else { - cfiDropArea.classList.remove('cfi-dropzone-highlight'); - cfiDropArea.classList.add('alert-error'); - cfiLabelExport.innerHTML = '' + xhr.status + 'Unknown error, look at the log'; - cfiDropArea.style.pointerEvents = 'auto'; - cfiExportArea.style.pointerEvents = 'auto'; } }); diff --git a/cfi.php b/cfi.php index d9a0153..0fe7f32 100644 --- a/cfi.php +++ b/cfi.php @@ -10,6 +10,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\URI\URI; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Filesystem\Path; @@ -43,7 +44,11 @@ class plgSystemCfi extends CMSPlugin public function __construct(&$subject, $config) { parent::__construct($subject, $config); + $this->_initConstruct(); + } + private function _initConstruct($ajax = false) + { $this->_app = Factory::getApplication('administrator'); $this->_doc = Factory::getDocument(); @@ -51,15 +56,17 @@ public function __construct(&$subject, $config) return; } - $option = $this->_app->input->get('option'); - $view = $this->_app->input->get('view'); - if (!($option == 'com_content' && (in_array($view, ['articles', 'featured', ''])))) { - return; + if (!$ajax) { + $option = $this->_app->input->get('option'); + $view = $this->_app->input->get('view'); + if (!($option == 'com_content' && (in_array($view, ['articles', 'featured', ''])))) { + return; + } + } else { + $this->_doc->addScript(URI::root(true) . '/plugins/system/cfi/assets/cfi.js'); + $this->_doc->addStylesheet(URI::root(true) . '/plugins/system/cfi/assets/cfi.css'); } - $this->_doc->addScript('/plugins/system/cfi/assets/cfi.js'); - $this->_doc->addStylesheet('/plugins/system/cfi/assets/cfi.css'); - $user = Factory::getUser(); $this->_user = $user->id . ':' . $user->username; @@ -166,6 +173,8 @@ public function onAjaxCfi() { Log::addLogger(['text_file' => 'cfi.php', 'text_entry_format' => "{DATETIME}\t{PRIORITY}\t{MESSAGE}"], Log::ALL); + $this->_initConstruct(true); + $state = $this->_app->input->get('cfistate', ''); if (!Session::checkToken($state == 'download' ? 'get' : 'post')) { @@ -272,6 +281,7 @@ private function _importData() // convert to UTF-8 $isConvert = (int) $this->_app->input->get('cficonvert', 0); + if ($isConvert > 0) { $content = mb_convert_encoding($content, 'UTF-8', $this->_cp); } @@ -326,9 +336,9 @@ private function _importData() Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/tables/'); Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/models/forms'); - Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/model/form'); + //Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/model/form'); Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/models/fields'); - Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/model/field'); + //Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/model/field'); set_time_limit(0); @@ -366,7 +376,9 @@ private function _importData() $article = []; if ($articleData['articleid'] > 0) { // load existing article item - $article = $model->getItem($articleData['articleid']); + //savefile("d:\cfi_1.txt", $model); + $article = $model->getItem((int)$articleData['articleid']); + //savefile("d:\cfi_2.txt", $article); if (!$article) { unset($article); diff --git a/cfi.xml b/cfi.xml index 3892262..10f3f93 100644 --- a/cfi.xml +++ b/cfi.xml @@ -1,8 +1,8 @@ PLG_CFI - 1.0.8 - February 2021 + 1.0.9 + March 2021 Aleksey A. Morozov alekvolsk@yandex.ru https://alekvolsk.pw