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

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekVolsk committed Dec 15, 2019
1 parent 45b68b1 commit 223ed5b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
5 changes: 5 additions & 0 deletions assets/cfi.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@
border-top: none;
border-bottom: .5px solid var(--cfi-hr);
}

#js-cfi-exportlabel {
margin-bottom: 0;
cursor: default;
}
17 changes: 11 additions & 6 deletions assets/cfi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '<br>' + response.message;
}
} catch (e) {
cfiLabelExport.classList.add('text-error');
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + xhr.response;
Expand Down
54 changes: 28 additions & 26 deletions cfi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

class plgSystemCfi extends CMSPlugin
{
const BOM = "\xEF" . "\xBB" . "\xBF"; // UTF BOM signature

private $_app;
private $_doc;
private $_user;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -147,17 +149,17 @@ 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', '');

if (!Session::checkToken($state == 'download' ? 'get' : 'post')) {
$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']);
Expand All @@ -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);
}
Expand All @@ -201,34 +203,34 @@ 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']);
}

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']);
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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']);
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions cfi.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7" type="plugin" group="system" method="upgrade">
<name>PLG_CFI</name>
<version>1.0.2</version>
<creationDate>November 2019</creationDate>
<version>1.0.3</version>
<creationDate>December 2019</creationDate>
<author>Aleksey A. Morozov</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://alekvolsk.pw</authorUrl>
Expand Down
26 changes: 5 additions & 21 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@

class plgSystemCfiInstallerScript
{
/**
* preflight
*
* @param mixed $type
* @param mixed $parent
*
* @return void
*/
function preflight($type, $parent)
{
if (strtolower($type) === 'uninstall') {
Expand Down Expand Up @@ -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') {
Expand All @@ -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();
Expand Down

0 comments on commit 223ed5b

Please sign in to comment.