From 223ed5bbc6ea908a7f0446976a50150e815bedca Mon Sep 17 00:00:00 2001 From: AlekVolsk Date: Mon, 16 Dec 2019 00:37:36 +0400 Subject: [PATCH] v1.0.3 --- README.md | 2 +- README.ru.md | 2 +- assets/cfi.css | 5 +++++ assets/cfi.js | 17 ++++++++++------ cfi.php | 54 ++++++++++++++++++++++++++------------------------ cfi.xml | 4 ++-- script.php | 26 +++++------------------- 7 files changed, 53 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index e785d23..722b78e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # CFI -![Version](https://img.shields.io/badge/VERSION-1.0.2-0366d6.svg?style=for-the-badge) +![Version](https://img.shields.io/badge/VERSION-1.0.3-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 31e73ad..34cf19d 100644 --- a/README.ru.md +++ b/README.ru.md @@ -1,6 +1,6 @@ # CFI -![Version](https://img.shields.io/badge/VERSION-1.0.2-0366d6.svg?style=for-the-badge) +![Version](https://img.shields.io/badge/VERSION-1.0.3-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.css b/assets/cfi.css index eacf1b0..02c2434 100644 --- a/assets/cfi.css +++ b/assets/cfi.css @@ -132,3 +132,8 @@ border-top: none; border-bottom: .5px solid var(--cfi-hr); } + +#js-cfi-exportlabel { + margin-bottom: 0; + cursor: default; +} diff --git a/assets/cfi.js b/assets/cfi.js index abf9fe3..a68ed36 100644 --- a/assets/cfi.js +++ b/assets/cfi.js @@ -141,20 +141,25 @@ document.addEventListener('DOMContentLoaded', function () { cfiDropArea.style.pointerEvents = 'none'; cfiExportArea.style.pointerEvents = 'none'; var url = location.protocol + '//' + location.host + Joomla.getOptions('system.paths')['base'] + - '/index.php?option=com_ajax&group=system&plugin=cfi&method=post&format=raw'; + '/index.php?option=com_ajax&group=system&plugin=cfi'; var xhr = new XMLHttpRequest(); var formData = new FormData(); - xhr.open('POST', url, true); + xhr.open('POST', url + '&format=json', true); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('X-CSRF-Token', Joomla.getOptions('csrf.token')); xhr.addEventListener('readystatechange', function (e) { if (xhr.readyState == 4 && xhr.status == 200) { try { - response = JSON.parse(xhr.response); - cfiLabelExport.classList.add('text-success'); - cfiLabelExport.innerHTML = cfiBtnExport.dataset.success; - window.location = url + '&cfistate=download&f=' + response.f + '&' + Joomla.getOptions('csrf.token') + '=1'; + 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 + '
' + xhr.response; diff --git a/cfi.php b/cfi.php index c31cc8f..920f83a 100644 --- a/cfi.php +++ b/cfi.php @@ -25,6 +25,8 @@ class plgSystemCfi extends CMSPlugin { + const BOM = "\xEF" . "\xBB" . "\xBF"; // UTF BOM signature + private $_app; private $_doc; private $_user; @@ -115,10 +117,10 @@ public function onAfterRender() $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('`id`, `title`') - ->from('`#__categories`') - ->where('`extension` = "com_content"') - ->order('`title`'); + ->select('id, title') + ->from('#__categories') + ->where('extension = "com_content"') + ->order('title'); $db->setQuery($query); try { $categories = $db->loadObjectList(); @@ -147,7 +149,7 @@ public function onAfterRender() public function onAjaxCfi() { - Log::addLogger(['text_file' => 'cfi.php', 'text_entry_format' => "{DATETIME}\t{PRIORITY}\t{MESSAGE}"], Log::ALL); + Log::addLogger(['textfile' => 'cfi.php', 'text_entry_format' => "{DATETIME}\t{PRIORITY}\t{MESSAGE}"], Log::ALL); $state = $this->_app->input->get('cfistate', ''); @@ -155,9 +157,9 @@ public function onAjaxCfi() $data = [ 'result' => Text::_('JINVALID_TOKEN'), 'user' => $this->_user, - 'file' => $_FILES, - 'get' => $_GET, - 'post' => $_POST + 'file' => $this->_app->input->files->getArray(), + 'get' => $this->_app->input->get->getArray(), + 'post' => $this->_app->input->post->getArray() ]; Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); @@ -175,7 +177,7 @@ public function onAjaxCfi() if ($state == 'download') { $this->_file = $this->_app->input->get('f', ''); if ($this->_file) { - $this->_file = base64_decode($this->_file); + $this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/' . urldecode($this->_file)); $this->_fileDownload($this->_file); @unlink($this->_file); } @@ -201,26 +203,26 @@ private function _checkFile($file) if (is_array($file) && count($file)) { if ($file['error'] != 0) { - $data['result'] = Text::_('PLG_CFI_FILE_ERROR'); + $data['result'] = Text::_('PLG_CFIfile_ERROR'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } if (!$file['size']) { - $data['result'] = Text::_('PLG_CFI_FILE_SIZE'); + $data['result'] = Text::_('PLG_CFIfile_SIZE'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } if (pathinfo($file['name'], PATHINFO_EXTENSION) !== 'csv') { - $data['result'] = Text::_('PLG_CFI_FILE_TYPE'); + $data['result'] = Text::_('PLG_CFIfile_TYPE'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } $this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/cfi_' . date('Y-m-d-H-i-s') . '.csv'); if (!@move_uploaded_file($file['tmp_name'], $this->_file)) { - $data['result'] = Text::_('PLG_CFI_FILE_MOVE'); + $data['result'] = Text::_('PLG_CFIfile_MOVE'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } @@ -228,7 +230,7 @@ private function _checkFile($file) return true; } - $data['result'] = Text::_('PLG_CFI_FILE_NOTHING'); + $data['result'] = Text::_('PLG_CFIfile_NOTHING'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } @@ -259,7 +261,7 @@ private function _importData() } // unset utf-8 bom - $content = str_replace("\xEF\xBB\xBF", '', $content); + $content = str_replace($this->BOM, '', $content); // line separator definition $rowDelimiter = "\r\n"; @@ -425,10 +427,10 @@ private function _getCategories() { $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('`id`') - ->from('`#__categories`') - ->where('`extension` = "com_content"') - ->order('`id`'); + ->select('id') + ->from('#__categories') + ->where('extension = "com_content"') + ->order('id'); $db->setQuery($query); try { return $db->loadColumn(); @@ -456,11 +458,11 @@ private function _exportData() // get articles $db = Factory::getDbo(); $query = $db->getQuery(true) - ->select('`id`, `title`, `language`, `introtext`, `fulltext`') - ->from('`#__content`') - ->where('`state` >= 0') - ->where('`catid` = ' . $catid) - ->order('`id`'); + ->select('id, title, language, introtext, \'fulltext\'') + ->from('#__content') + ->where('state >= 0') + ->where('catid = ' . (int)$catid) + ->order('id'); $db->setQuery($query); try { $articles = $db->loadObjectList(); @@ -479,7 +481,7 @@ private function _exportData() // file handler $this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/cfi_export_' . date('Y-m-d-H-i-s') . '.csv'); if (($fileHandle = fopen($this->_file, 'w')) === false) { - $data['result'] = Text::_('PLG_CFI_EXPORT_FILE_CREATE'); + $data['result'] = Text::_('PLG_CFI_EXPORTfile_CREATE'); Log::add(json_encode($data), Log::ERROR); $this->_printJson($data['result']); } @@ -555,7 +557,7 @@ private function _exportData() $data['result'] = Text::_('PLG_CFI_EXPORT_SUCCESS'); $date['file'] = $this->_file; Log::add(json_encode($data), Log::INFO); - $this->_printJson($data['result'], true, ['f' => base64_encode($this->_file)]); + $this->_printJson($data['result'], true, ['f' => urlencode(pathinfo($this->_file, PATHINFO_BASENAME))]); exit; } diff --git a/cfi.xml b/cfi.xml index 58a5435..5f40b2c 100644 --- a/cfi.xml +++ b/cfi.xml @@ -1,8 +1,8 @@ PLG_CFI - 1.0.2 - November 2019 + 1.0.3 + December 2019 Aleksey A. Morozov alekvolsk@yandex.ru https://alekvolsk.pw diff --git a/script.php b/script.php index dbcdda2..33c3021 100644 --- a/script.php +++ b/script.php @@ -12,14 +12,6 @@ class plgSystemCfiInstallerScript { - /** - * preflight - * - * @param mixed $type - * @param mixed $parent - * - * @return void - */ function preflight($type, $parent) { if (strtolower($type) === 'uninstall') { @@ -52,14 +44,6 @@ function preflight($type, $parent) } } - /** - * postflight - * - * @param mixed $type - * @param mixed $parent - * - * @return void - */ public function postflight($type, $parent) { if (strtolower($type) === 'uninstall') { @@ -68,11 +52,11 @@ public function postflight($type, $parent) $db = Factory::getDbo(); $query = $db->getQuery(true) - ->update('`#__extensions`') - ->set('`enabled` = 1') - ->where('`element` = ' . $db->quote('cfi')) - ->where('`type` = ' . $db->quote('plugin')) - ->where('`folder` = ' . $db->quote('system')); + ->update('#__extensions') + ->set('enabled = 1') + ->where('element = ' . $db->quote('cfi')) + ->where('type = ' . $db->quote('plugin')) + ->where('folder = ' . $db->quote('system')); $db->setQuery($query); try { $db->execute();