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

Commit 432b508

Browse files
author
AlekVolsk
committed
v1.0.10
1 parent 1627901 commit 432b508

File tree

7 files changed

+48
-39
lines changed

7 files changed

+48
-39
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.9-0366d6.svg?style=for-the-badge)
3+
![Version](https://img.shields.io/badge/VERSION-1.0.10-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.9-0366d6.svg?style=for-the-badge)
3+
![Version](https://img.shields.io/badge/VERSION-1.0.10-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

cfi.php

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function _initConstruct($ajax = false)
5656
return;
5757
}
5858

59-
if (!$ajax) {
59+
if ($ajax) {
6060
$option = $this->_app->input->get('option');
6161
$view = $this->_app->input->get('view');
6262
if (!($option == 'com_content' && (in_array($view, ['articles', 'featured', ''])))) {
@@ -336,9 +336,7 @@ private function _importData()
336336

337337
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/tables/');
338338
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/models/forms');
339-
//Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/model/form');
340339
Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/models/fields');
341-
//Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_content/model/field');
342340

343341
set_time_limit(0);
344342

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

349347
// check count columns
350348
if (count($fieldsData) != count($columns)) {
351-
$errors[$strNum] = Text::_('PLG_CFI_IMPORT_COLUMN_EXCEPT');
349+
$errors[$strNum + 1] = Text::_('PLG_CFI_IMPORT_COLUMN_EXCEPT');
352350
$continues++;
353351
continue;
354352
}
@@ -374,30 +372,31 @@ private function _importData()
374372
$model = BaseDatabaseModel::getInstance('Article', 'ContentModel');
375373

376374
$article = [];
375+
$isNewArticle = true;
376+
$state = 1;
377377
if ($articleData['articleid'] > 0) {
378-
// load existing article item
379-
//savefile("d:\cfi_1.txt", $model);
380378
$article = $model->getItem((int)$articleData['articleid']);
381-
//savefile("d:\cfi_2.txt", $article);
382379

383-
if (!$article) {
380+
if (!$article->id) {
384381
unset($article);
385-
$errors[$strNum] = Text::sprintf('PLG_CFI_IMPORT_LOAD_ARTICLE', $articleData['articleid']);
386-
$continues++;
387-
continue;
388-
}
382+
$state = 0;
383+
$errors[$strNum + 1] = Text::sprintf('PLG_CFI_IMPORT_LOAD_ARTICLE', $articleData['articleid']);
384+
} else {
385+
$isNewArticle = false;
386+
$article = (array)$article;
387+
unset($article[array_key_first($article)]);
388+
if (isset($article['tags'])) {
389+
$article['tags'] = explode(',', $article['tags']->tags);
390+
}
389391

390-
$article = (array)$article;
391-
unset($article[array_key_first($article)]);
392-
if (isset($article['tags'])) {
393-
$article['tags'] = explode(',', $article['tags']->tags);
392+
// set new data on existing article item
393+
$article['title'] = $articleData['articletitle'];
394+
$article['introtext'] = $articleData['articleintrotext'];
395+
$article['fulltext'] = $articleData['articlefulltext'];
394396
}
397+
}
395398

396-
// set new data on existing article item
397-
$article['title'] = $articleData['articletitle'];
398-
$article['introtext'] = $articleData['articleintrotext'];
399-
$article['fulltext'] = $articleData['articlefulltext'];
400-
} else {
399+
if ($isNewArticle) {
401400
//set data on new article item
402401
$article['id'] = 0;
403402
$article['title'] = $articleData['articletitle'];
@@ -408,7 +407,7 @@ private function _importData()
408407
$article['language'] = $articleData['articlelang'];
409408
$article['created'] = Factory::getDate()->toSql();
410409
$article['created_by'] = explode(':', $this->_user)[0];
411-
$article['state'] = 1;
410+
$article['state'] = $state;
412411
$article['access'] = $this->_app->get('access', 1);
413412
$article['metadata'] = json_decode('{"robots":"","author":"","rights":"","xreference":""}', true);
414413
$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);
@@ -419,19 +418,27 @@ private function _importData()
419418
// save article item
420419
if ($model->save($article) === false) {
421420
unset($article);
422-
$errors[$strNum] = Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
421+
if (!empty($errors[$strNum + 1])) {
422+
$errors[$strNum + 1] .= '. ' . Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
423+
} else {
424+
$errors[$strNum + 1] = Text::_('PLG_CFI_IMPORT_SAVE_ARTICLE');
425+
}
423426
$continues++;
424427
continue;
428+
} else {
429+
if (!empty($errors[$strNum + 1])) {
430+
$errors[$strNum + 1] .= '. ' . Text::_('PLG_CFI_IMPORT_SAVENEW_ARTICLE');
431+
}
425432
}
426433

427-
if ($articleData['articleid']) {
428-
$updates++;
429-
} else {
434+
if ($isNewArticle) {
430435
$inserts++;
431-
}
432436

433-
// reload article from model
434-
$article = (array) $model->getItem();
437+
// get ID for the new article
438+
$article['id'] = $model->getState($model->getName() . '.id');
439+
} else {
440+
$updates++;
441+
}
435442

436443
// get article custom fields
437444
$jsFields = FieldsHelper::getFields('com_content.article', $article, true);
@@ -456,7 +463,7 @@ private function _importData()
456463
}
457464
}
458465
if ($fieldsErrors) {
459-
$errors[$strNum] = Text::sprintf('PLG_CFI_IMPORT_SAVE_FIELDS', implode(', ', $fieldsErrors));
466+
$errors[$strNum + 1] = Text::sprintf('PLG_CFI_IMPORT_SAVE_FIELDS', implode(', ', $fieldsErrors));
460467
}
461468

462469
// destroy article instance

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.9</version>
5-
<creationDate>March 2021</creationDate>
4+
<version>1.0.10</version>
5+
<creationDate>April 2021</creationDate>
66
<author>Aleksey A. Morozov</author>
77
<authorEmail>alekvolsk@yandex.ru</authorEmail>
88
<authorUrl>https://alekvolsk.pw</authorUrl>

language/en-GB/en-GB.plg_system_cfi.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ PLG_CFI_IMPORT_NO_COLUMN="There are no required articleid and articletitle field
4141
PLG_CFI_IMPORT_COLUMN_EXCEPT="The number of values ​​in the row does not match the number of declared columns"
4242
PLG_CFI_IMPORT_LOAD_ARTICLE="Error loading article with id %s"
4343
PLG_CFI_IMPORT_SAVE_ARTICLE="Error saving article"
44+
PLG_CFI_IMPORT_SAVENEW_ARTICLE="Article saved as new"
4445
PLG_CFI_IMPORT_SAVE_FIELDS="Error saving field values: %s"
4546

4647
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>"
4748
PLG_CFI_RESULT_ERROR="<span class='text-error'>Raw file lines: <strong>%s</strong></span>"
4849

4950
PLG_CFI_DESC_FORMAT_LABEL="Description of the file format"
50-
PLG_CFI_DESC_FORMAT="<p><strong>Description of the file format of the imported materials with additional fields</strong></p>
51+
PLG_CFI_DESC_FORMAT="<p><strong>Description of the file format of the imported articles with additional fields</strong></p>
5152
<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>
5253
<p>The first line of a file is always the file field headers.</p>
5354
<p>Reserved field names:</p>

language/ru-RU/ru-RU.plg_system_cfi.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ PLG_CFI_IMPORT_NO_COLUMN="Отсутсвуют обязательные поля
4141
PLG_CFI_IMPORT_COLUMN_EXCEPT="Кол-во значений в строке не соответствует кол-ву объявленных колонок"
4242
PLG_CFI_IMPORT_LOAD_ARTICLE="Ошибка загрузки материала с id %s"
4343
PLG_CFI_IMPORT_SAVE_ARTICLE="Ошибка сохранения материала"
44+
PLG_CFI_IMPORT_SAVENEW_ARTICLE="Материал сохранён как новый"
4445
PLG_CFI_IMPORT_SAVE_FIELDS="Ошибка сохранения значений полей: %s"
4546

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

6667
PLG_CFI_DESC_WARN_LABEL="Отказ от ответственности"
67-
PLG_CFI_DESC_WARN="<p>Данные дополнительных полей записываются в БД прямыми запросами и не подвергаются какой-либо обработке.
68-
Ввиду того, что в этих данных могут присутствовать теги html-разметки, json-строки или иные строковые конструкции, содержащие специализированные символы,
68+
PLG_CFI_DESC_WARN="<p>Данные дополнительных полей записываются в БД прямыми запросами и не подвергаются какой-либо обработке.
69+
Ввиду того, что в этих данных могут присутствовать теги html-разметки, json-строки или иные строковые конструкции, содержащие специализированные символы,
6970
<strong>экранирование данных не производится!</strong> Пожалуйста, обеспечьте безопасность импортируемых данных на этапе генерации файла для импорта данных в Joomla.</p>
7071
<hr>
7172
<p class='text-error'><strong>Разработчик плагина не несёт ответственность за некорректное содержимое импортируемых файлов, которое может вывести из строя ваш сайт</strong>.</p>"

layouts/toolbar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
$title = Text::_('PLG_CFI_BUTTON');
1212
?>
1313
<button id="js-cfi-toolbarbtn" class="btn btn-small btn-primary cfi-tollbarbtn">
14-
<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>
15-
<?php echo $title; ?>
14+
<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>
15+
&nbsp;<?php echo $title; ?>
1616
</button>

0 commit comments

Comments
 (0)