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

Commit

Permalink
v1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekVolsk committed Apr 15, 2021
1 parent 1627901 commit 432b508
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 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.9-0366d6.svg?style=for-the-badge)
![Version](https://img.shields.io/badge/VERSION-1.0.10-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.9-0366d6.svg?style=for-the-badge)
![Version](https://img.shields.io/badge/VERSION-1.0.10-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
67 changes: 37 additions & 30 deletions cfi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function _initConstruct($ajax = false)
return;
}

if (!$ajax) {
if ($ajax) {
$option = $this->_app->input->get('option');
$view = $this->_app->input->get('view');
if (!($option == 'com_content' && (in_array($view, ['articles', 'featured', ''])))) {
Expand Down Expand Up @@ -336,9 +336,7 @@ 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::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/models/fields');
//Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/model/field');

set_time_limit(0);

Expand All @@ -348,7 +346,7 @@ private function _importData()

// check count columns
if (count($fieldsData) != count($columns)) {
$errors[$strNum] = Text::_('PLG_CFI_IMPORT_COLUMN_EXCEPT');
$errors[$strNum + 1] = Text::_('PLG_CFI_IMPORT_COLUMN_EXCEPT');
$continues++;
continue;
}
Expand All @@ -374,30 +372,31 @@ private function _importData()
$model = BaseDatabaseModel::getInstance('Article', 'ContentModel');

$article = [];
$isNewArticle = true;
$state = 1;
if ($articleData['articleid'] > 0) {
// load existing article item
//savefile("d:\cfi_1.txt", $model);
$article = $model->getItem((int)$articleData['articleid']);
//savefile("d:\cfi_2.txt", $article);

if (!$article) {
if (!$article->id) {
unset($article);
$errors[$strNum] = Text::sprintf('PLG_CFI_IMPORT_LOAD_ARTICLE', $articleData['articleid']);
$continues++;
continue;
}
$state = 0;
$errors[$strNum + 1] = Text::sprintf('PLG_CFI_IMPORT_LOAD_ARTICLE', $articleData['articleid']);
} else {
$isNewArticle = false;
$article = (array)$article;
unset($article[array_key_first($article)]);
if (isset($article['tags'])) {
$article['tags'] = explode(',', $article['tags']->tags);
}

$article = (array)$article;
unset($article[array_key_first($article)]);
if (isset($article['tags'])) {
$article['tags'] = explode(',', $article['tags']->tags);
// set new data on existing article item
$article['title'] = $articleData['articletitle'];
$article['introtext'] = $articleData['articleintrotext'];
$article['fulltext'] = $articleData['articlefulltext'];
}
}

// set new data on existing article item
$article['title'] = $articleData['articletitle'];
$article['introtext'] = $articleData['articleintrotext'];
$article['fulltext'] = $articleData['articlefulltext'];
} else {
if ($isNewArticle) {
//set data on new article item
$article['id'] = 0;
$article['title'] = $articleData['articletitle'];
Expand All @@ -408,7 +407,7 @@ private function _importData()
$article['language'] = $articleData['articlelang'];
$article['created'] = Factory::getDate()->toSql();
$article['created_by'] = explode(':', $this->_user)[0];
$article['state'] = 1;
$article['state'] = $state;
$article['access'] = $this->_app->get('access', 1);
$article['metadata'] = json_decode('{"robots":"","author":"","rights":"","xreference":""}', true);
$article['images'] = json_decode('{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}', true);
Expand All @@ -419,19 +418,27 @@ private function _importData()
// save article item
if ($model->save($article) === false) {
unset($article);
$errors[$strNum] = Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
if (!empty($errors[$strNum + 1])) {
$errors[$strNum + 1] .= '. ' . Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
} else {
$errors[$strNum + 1] = Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
}
$continues++;
continue;
} else {
if (!empty($errors[$strNum + 1])) {
$errors[$strNum + 1] .= '. ' . Text::_('PLG_CFI_IMPORT_SAVENEW_ARTICLE');
}
}

if ($articleData['articleid']) {
$updates++;
} else {
if ($isNewArticle) {
$inserts++;
}

// reload article from model
$article = (array) $model->getItem();
// get ID for the new article
$article['id'] = $model->getState($model->getName() . '.id');
} else {
$updates++;
}

// get article custom fields
$jsFields = FieldsHelper::getFields('com_content.article', $article, true);
Expand All @@ -456,7 +463,7 @@ private function _importData()
}
}
if ($fieldsErrors) {
$errors[$strNum] = Text::sprintf('PLG_CFI_IMPORT_SAVE_FIELDS', implode(', ', $fieldsErrors));
$errors[$strNum + 1] = Text::sprintf('PLG_CFI_IMPORT_SAVE_FIELDS', implode(', ', $fieldsErrors));
}

// destroy article instance
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.9</version>
<creationDate>March 2021</creationDate>
<version>1.0.10</version>
<creationDate>April 2021</creationDate>
<author>Aleksey A. Morozov</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://alekvolsk.pw</authorUrl>
Expand Down
3 changes: 2 additions & 1 deletion language/en-GB/en-GB.plg_system_cfi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ PLG_CFI_IMPORT_NO_COLUMN="There are no required articleid and articletitle field
PLG_CFI_IMPORT_COLUMN_EXCEPT="The number of values ​​in the row does not match the number of declared columns"
PLG_CFI_IMPORT_LOAD_ARTICLE="Error loading article with id %s"
PLG_CFI_IMPORT_SAVE_ARTICLE="Error saving article"
PLG_CFI_IMPORT_SAVENEW_ARTICLE="Article saved as new"
PLG_CFI_IMPORT_SAVE_FIELDS="Error saving field values: %s"

PLG_CFI_RESULT="<span>Imported records from file: <strong>%s</strong><br>New articles added: <strong>%s</strong><br>Updated articles: <strong>%s</strong></span>"
PLG_CFI_RESULT_ERROR="<span class='text-error'>Raw file lines: <strong>%s</strong></span>"

PLG_CFI_DESC_FORMAT_LABEL="Description of the file format"
PLG_CFI_DESC_FORMAT="<p><strong>Description of the file format of the imported materials with additional fields</strong></p>
PLG_CFI_DESC_FORMAT="<p><strong>Description of the file format of the imported articles with additional fields</strong></p>
<p>File format for imported data: <strong>CSV</strong>. Default a file encoding, if the option «Convert encoding…» is not set: <strong>UTF-8 w/o BOM</strong>. The data separator in the CSV file must be only the <code>;</code> symbol.</p>
<p>The first line of a file is always the file field headers.</p>
<p>Reserved field names:</p>
Expand Down
5 changes: 3 additions & 2 deletions language/ru-RU/ru-RU.plg_system_cfi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ PLG_CFI_IMPORT_NO_COLUMN="Отсутсвуют обязательные поля
PLG_CFI_IMPORT_COLUMN_EXCEPT="Кол-во значений в строке не соответствует кол-ву объявленных колонок"
PLG_CFI_IMPORT_LOAD_ARTICLE="Ошибка загрузки материала с id %s"
PLG_CFI_IMPORT_SAVE_ARTICLE="Ошибка сохранения материала"
PLG_CFI_IMPORT_SAVENEW_ARTICLE="Материал сохранён как новый"
PLG_CFI_IMPORT_SAVE_FIELDS="Ошибка сохранения значений полей: %s"

PLG_CFI_RESULT="<span>Импортировано записей из файла: <strong>%s</strong> <br>Добавлено новых материалов: <strong>%s</strong> <br>Обновлено материалов: <strong>%s</strong></span>"
Expand All @@ -64,8 +65,8 @@ PLG_CFI_DESC_FORMAT="<p><strong>Описание формата файла им
<p>При отсутсвии ошибок импорта данных импортируемый файл удаляется, в противном случае файл сохраняется в стандартной папке временных файлов Joomla.</p>"

PLG_CFI_DESC_WARN_LABEL="Отказ от ответственности"
PLG_CFI_DESC_WARN="<p>Данные дополнительных полей записываются в БД прямыми запросами и не подвергаются какой-либо обработке.
Ввиду того, что в этих данных могут присутствовать теги html-разметки, json-строки или иные строковые конструкции, содержащие специализированные символы,
PLG_CFI_DESC_WARN="<p>Данные дополнительных полей записываются в БД прямыми запросами и не подвергаются какой-либо обработке.
Ввиду того, что в этих данных могут присутствовать теги html-разметки, json-строки или иные строковые конструкции, содержащие специализированные символы,
<strong>экранирование данных не производится!</strong> Пожалуйста, обеспечьте безопасность импортируемых данных на этапе генерации файла для импорта данных в Joomla.</p>
<hr>
<p class='text-error'><strong>Разработчик плагина не несёт ответственность за некорректное содержимое импортируемых файлов, которое может вывести из строя ваш сайт</strong>.</p>"
Expand Down
4 changes: 2 additions & 2 deletions layouts/toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$title = Text::_('PLG_CFI_BUTTON');
?>
<button id="js-cfi-toolbarbtn" class="btn btn-small btn-primary cfi-tollbarbtn">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="14" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"></path></svg>
<?php echo $title; ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="14" viewBox="0 0 20 17" fill="#fff"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"></path></svg>
&nbsp;<?php echo $title; ?>
</button>

0 comments on commit 432b508

Please sign in to comment.