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

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekVolsk committed Mar 15, 2021
1 parent 8c36350 commit d3c8763
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 61 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.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)

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.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)

Expand Down
98 changes: 51 additions & 47 deletions assets/cfi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<strong>' + (response.result ? cfiDropArea.dataset.success : cfiDropArea.dataset.error) + '</strong><br>' + 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 = '<strong>' + (response.result ? cfiDropArea.dataset.success : cfiDropArea.dataset.error) + '</strong><br>' + response.message;
} catch (e) {
cfiDropArea.classList.remove('cfi-dropzone-highlight');
cfiDropArea.classList.add('alert-error');
cfiDropLabel.innerHTML = '<strong>' + cfiDropArea.dataset.error + '</strong><span>' + xhr.response + '</span>';
}
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 = '<strong>' + cfiDropArea.dataset.error + '</strong><span>' + xhr.response + '</span>';
}
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 = '<strong>' + xhr.status + '</strong><span>Unknown error, look at the log</span>';
cfiDropArea.style.pointerEvents = 'auto';
cfiExportArea.style.pointerEvents = 'auto';
}
} else {
cfiDropArea.classList.remove('cfi-dropzone-highlight');
cfiDropArea.classList.add('alert-error');
cfiDropLabel.innerHTML = '<strong>' + xhr.status + '</strong><span>Unknown error, look at the log</span>';
cfiDropArea.style.pointerEvents = 'auto';
cfiExportArea.style.pointerEvents = 'auto';
}
});

Expand Down Expand Up @@ -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 + '<br>' + response.message;
}
} catch (e) {
cfiLabelExport.classList.add('text-error');
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + response.message;
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + xhr.response;
}
} catch (e) {
cfiLabelExport.classList.add('text-error');
cfiLabelExport.innerHTML = cfiBtnExport.dataset.error + '<br>' + xhr.response;
cfiDropArea.style.pointerEvents = 'auto';
cfiExportArea.style.pointerEvents = 'auto';
} else {
cfiDropArea.classList.remove('cfi-dropzone-highlight');
cfiDropArea.classList.add('alert-error');
cfiLabelExport.innerHTML = '<strong>' + xhr.status + '</strong><span>Unknown error, look at the log</span>';
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 = '<strong>' + xhr.status + '</strong><span>Unknown error, look at the log</span>';
cfiDropArea.style.pointerEvents = 'auto';
cfiExportArea.style.pointerEvents = 'auto';
}
});

Expand Down
32 changes: 22 additions & 10 deletions cfi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,23 +44,29 @@ 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();

if (!$this->_app->isClient('administrator')) {
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;

Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
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.8</version>
<creationDate>February 2021</creationDate>
<version>1.0.9</version>
<creationDate>March 2021</creationDate>
<author>Aleksey A. Morozov</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://alekvolsk.pw</authorUrl>
Expand Down

0 comments on commit d3c8763

Please sign in to comment.