Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 223ed5b

Browse files
author
AlekVolsk
committed
v1.0.3
1 parent 45b68b1 commit 223ed5b

File tree

7 files changed

+53
-57
lines changed

7 files changed

+53
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CFI
22

3-
![Version](https://img.shields.io/badge/VERSION-1.0.2-0366d6.svg?style=for-the-badge)
3+
![Version](https://img.shields.io/badge/VERSION-1.0.3-0366d6.svg?style=for-the-badge)
44
![Joomla](https://img.shields.io/badge/joomla-3.7+-1A3867.svg?style=for-the-badge)
55
![Php](https://img.shields.io/badge/php-5.6+-8892BF.svg?style=for-the-badge)
66

README.ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CFI
22

3-
![Version](https://img.shields.io/badge/VERSION-1.0.2-0366d6.svg?style=for-the-badge)
3+
![Version](https://img.shields.io/badge/VERSION-1.0.3-0366d6.svg?style=for-the-badge)
44
![Joomla](https://img.shields.io/badge/joomla-3.7+-1A3867.svg?style=for-the-badge)
55
![Php](https://img.shields.io/badge/php-5.6+-8892BF.svg?style=for-the-badge)
66

assets/cfi.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@
132132
border-top: none;
133133
border-bottom: .5px solid var(--cfi-hr);
134134
}
135+
136+
#js-cfi-exportlabel {
137+
margin-bottom: 0;
138+
cursor: default;
139+
}

assets/cfi.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,25 @@ document.addEventListener('DOMContentLoaded', function () {
141141
cfiDropArea.style.pointerEvents = 'none';
142142
cfiExportArea.style.pointerEvents = 'none';
143143
var url = location.protocol + '//' + location.host + Joomla.getOptions('system.paths')['base'] +
144-
'/index.php?option=com_ajax&group=system&plugin=cfi&method=post&format=raw';
144+
'/index.php?option=com_ajax&group=system&plugin=cfi';
145145
var xhr = new XMLHttpRequest();
146146
var formData = new FormData();
147-
xhr.open('POST', url, true);
147+
xhr.open('POST', url + '&format=json', true);
148148
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
149149
xhr.setRequestHeader('X-CSRF-Token', Joomla.getOptions('csrf.token'));
150150

151151
xhr.addEventListener('readystatechange', function (e) {
152152
if (xhr.readyState == 4 && xhr.status == 200) {
153153
try {
154-
response = JSON.parse(xhr.response);
155-
cfiLabelExport.classList.add('text-success');
156-
cfiLabelExport.innerHTML = cfiBtnExport.dataset.success;
157-
window.location = url + '&cfistate=download&f=' + response.f + '&' + Joomla.getOptions('csrf.token') + '=1';
154+
var response = JSON.parse(xhr.response);
155+
if (response.result) {
156+
cfiLabelExport.classList.add('text-success');
157+
cfiLabelExport.innerHTML = cfiBtnExport.dataset.success;
158+
window.location = url + '&format=raw&cfistate=download&f=' + response.f + '&' + Joomla.getOptions('csrf.token') + '=1';
159+
} else {
160+
cfiLabelExport.classList.add('text-error');
161+
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + response.message;
162+
}
158163
} catch (e) {
159164
cfiLabelExport.classList.add('text-error');
160165
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + xhr.response;

cfi.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
class plgSystemCfi extends CMSPlugin
2727
{
28+
const BOM = "\xEF" . "\xBB" . "\xBF"; // UTF BOM signature
29+
2830
private $_app;
2931
private $_doc;
3032
private $_user;
@@ -115,10 +117,10 @@ public function onAfterRender()
115117

116118
$db = Factory::getDbo();
117119
$query = $db->getQuery(true)
118-
->select('`id`, `title`')
119-
->from('`#__categories`')
120-
->where('`extension` = "com_content"')
121-
->order('`title`');
120+
->select('id, title')
121+
->from('#__categories')
122+
->where('extension = "com_content"')
123+
->order('title');
122124
$db->setQuery($query);
123125
try {
124126
$categories = $db->loadObjectList();
@@ -147,17 +149,17 @@ public function onAfterRender()
147149

148150
public function onAjaxCfi()
149151
{
150-
Log::addLogger(['text_file' => 'cfi.php', 'text_entry_format' => "{DATETIME}\t{PRIORITY}\t{MESSAGE}"], Log::ALL);
152+
Log::addLogger(['textfile' => 'cfi.php', 'text_entry_format' => "{DATETIME}\t{PRIORITY}\t{MESSAGE}"], Log::ALL);
151153

152154
$state = $this->_app->input->get('cfistate', '');
153155

154156
if (!Session::checkToken($state == 'download' ? 'get' : 'post')) {
155157
$data = [
156158
'result' => Text::_('JINVALID_TOKEN'),
157159
'user' => $this->_user,
158-
'file' => $_FILES,
159-
'get' => $_GET,
160-
'post' => $_POST
160+
'file' => $this->_app->input->files->getArray(),
161+
'get' => $this->_app->input->get->getArray(),
162+
'post' => $this->_app->input->post->getArray()
161163
];
162164
Log::add(json_encode($data), Log::ERROR);
163165
$this->_printJson($data['result']);
@@ -175,7 +177,7 @@ public function onAjaxCfi()
175177
if ($state == 'download') {
176178
$this->_file = $this->_app->input->get('f', '');
177179
if ($this->_file) {
178-
$this->_file = base64_decode($this->_file);
180+
$this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/' . urldecode($this->_file));
179181
$this->_fileDownload($this->_file);
180182
@unlink($this->_file);
181183
}
@@ -201,34 +203,34 @@ private function _checkFile($file)
201203
if (is_array($file) && count($file)) {
202204

203205
if ($file['error'] != 0) {
204-
$data['result'] = Text::_('PLG_CFI_FILE_ERROR');
206+
$data['result'] = Text::_('PLG_CFIfile_ERROR');
205207
Log::add(json_encode($data), Log::ERROR);
206208
$this->_printJson($data['result']);
207209
}
208210

209211
if (!$file['size']) {
210-
$data['result'] = Text::_('PLG_CFI_FILE_SIZE');
212+
$data['result'] = Text::_('PLG_CFIfile_SIZE');
211213
Log::add(json_encode($data), Log::ERROR);
212214
$this->_printJson($data['result']);
213215
}
214216

215217
if (pathinfo($file['name'], PATHINFO_EXTENSION) !== 'csv') {
216-
$data['result'] = Text::_('PLG_CFI_FILE_TYPE');
218+
$data['result'] = Text::_('PLG_CFIfile_TYPE');
217219
Log::add(json_encode($data), Log::ERROR);
218220
$this->_printJson($data['result']);
219221
}
220222

221223
$this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/cfi_' . date('Y-m-d-H-i-s') . '.csv');
222224
if (!@move_uploaded_file($file['tmp_name'], $this->_file)) {
223-
$data['result'] = Text::_('PLG_CFI_FILE_MOVE');
225+
$data['result'] = Text::_('PLG_CFIfile_MOVE');
224226
Log::add(json_encode($data), Log::ERROR);
225227
$this->_printJson($data['result']);
226228
}
227229

228230
return true;
229231
}
230232

231-
$data['result'] = Text::_('PLG_CFI_FILE_NOTHING');
233+
$data['result'] = Text::_('PLG_CFIfile_NOTHING');
232234
Log::add(json_encode($data), Log::ERROR);
233235
$this->_printJson($data['result']);
234236
}
@@ -259,7 +261,7 @@ private function _importData()
259261
}
260262

261263
// unset utf-8 bom
262-
$content = str_replace("\xEF\xBB\xBF", '', $content);
264+
$content = str_replace($this->BOM, '', $content);
263265

264266
// line separator definition
265267
$rowDelimiter = "\r\n";
@@ -425,10 +427,10 @@ private function _getCategories()
425427
{
426428
$db = Factory::getDbo();
427429
$query = $db->getQuery(true)
428-
->select('`id`')
429-
->from('`#__categories`')
430-
->where('`extension` = "com_content"')
431-
->order('`id`');
430+
->select('id')
431+
->from('#__categories')
432+
->where('extension = "com_content"')
433+
->order('id');
432434
$db->setQuery($query);
433435
try {
434436
return $db->loadColumn();
@@ -456,11 +458,11 @@ private function _exportData()
456458
// get articles
457459
$db = Factory::getDbo();
458460
$query = $db->getQuery(true)
459-
->select('`id`, `title`, `language`, `introtext`, `fulltext`')
460-
->from('`#__content`')
461-
->where('`state` >= 0')
462-
->where('`catid` = ' . $catid)
463-
->order('`id`');
461+
->select('id, title, language, introtext, \'fulltext\'')
462+
->from('#__content')
463+
->where('state >= 0')
464+
->where('catid = ' . (int)$catid)
465+
->order('id');
464466
$db->setQuery($query);
465467
try {
466468
$articles = $db->loadObjectList();
@@ -479,7 +481,7 @@ private function _exportData()
479481
// file handler
480482
$this->_file = Path::clean(Factory::getConfig()->get('tmp_path') . '/cfi_export_' . date('Y-m-d-H-i-s') . '.csv');
481483
if (($fileHandle = fopen($this->_file, 'w')) === false) {
482-
$data['result'] = Text::_('PLG_CFI_EXPORT_FILE_CREATE');
484+
$data['result'] = Text::_('PLG_CFI_EXPORTfile_CREATE');
483485
Log::add(json_encode($data), Log::ERROR);
484486
$this->_printJson($data['result']);
485487
}
@@ -555,7 +557,7 @@ private function _exportData()
555557
$data['result'] = Text::_('PLG_CFI_EXPORT_SUCCESS');
556558
$date['file'] = $this->_file;
557559
Log::add(json_encode($data), Log::INFO);
558-
$this->_printJson($data['result'], true, ['f' => base64_encode($this->_file)]);
560+
$this->_printJson($data['result'], true, ['f' => urlencode(pathinfo($this->_file, PATHINFO_BASENAME))]);
559561

560562
exit;
561563
}

cfi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<extension version="3.7" type="plugin" group="system" method="upgrade">
33
<name>PLG_CFI</name>
4-
<version>1.0.2</version>
5-
<creationDate>November 2019</creationDate>
4+
<version>1.0.3</version>
5+
<creationDate>December 2019</creationDate>
66
<author>Aleksey A. Morozov</author>
77
<authorEmail>[email protected]</authorEmail>
88
<authorUrl>https://alekvolsk.pw</authorUrl>

script.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
class plgSystemCfiInstallerScript
1414
{
15-
/**
16-
* preflight
17-
*
18-
* @param mixed $type
19-
* @param mixed $parent
20-
*
21-
* @return void
22-
*/
2315
function preflight($type, $parent)
2416
{
2517
if (strtolower($type) === 'uninstall') {
@@ -52,14 +44,6 @@ function preflight($type, $parent)
5244
}
5345
}
5446

55-
/**
56-
* postflight
57-
*
58-
* @param mixed $type
59-
* @param mixed $parent
60-
*
61-
* @return void
62-
*/
6347
public function postflight($type, $parent)
6448
{
6549
if (strtolower($type) === 'uninstall') {
@@ -68,11 +52,11 @@ public function postflight($type, $parent)
6852

6953
$db = Factory::getDbo();
7054
$query = $db->getQuery(true)
71-
->update('`#__extensions`')
72-
->set('`enabled` = 1')
73-
->where('`element` = ' . $db->quote('cfi'))
74-
->where('`type` = ' . $db->quote('plugin'))
75-
->where('`folder` = ' . $db->quote('system'));
55+
->update('#__extensions')
56+
->set('enabled = 1')
57+
->where('element = ' . $db->quote('cfi'))
58+
->where('type = ' . $db->quote('plugin'))
59+
->where('folder = ' . $db->quote('system'));
7660
$db->setQuery($query);
7761
try {
7862
$db->execute();

0 commit comments

Comments
 (0)