Skip to content

Commit

Permalink
The plugin crashed with an error if the contact with the specified id…
Browse files Browse the repository at this point in the history
… did not exist or was removed from publication. Fixed it.
  • Loading branch information
sergeytolkachyov committed Apr 19, 2024
1 parent e884be9 commit 3453240
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 37 deletions.
2 changes: 1 addition & 1 deletion language/en-GB/pkg_wtcontactwithfields.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ PKG_WTCONTACTWITHFIELDS_AFTER_INSTALL = "Thank you for intalling extension"
PKG_WTCONTACTWITHFIELDS_AFTER_DISCOVER_INSTALL = "Thank you for intalling extension"
PKG_WTCONTACTWITHFIELDS_AFTER_UPDATE = "Thank you for updating extension"
PKG_WTCONTACTWITHFIELDS_MAYBE_INTERESTING="<h4>It may be interesting</h4><ul class=\"nav nav-tabs nav-stacked list-group\"><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/web-assets\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Joomla 4 & Joomla 5 Web Assets.</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/joomshopping\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">JoomShopping extensions</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/joomla-plugins\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Joomla plugins</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/joomla-modules\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Joomla modules</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/components\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Joomla components</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/en/dev/joomla-libraries\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Joomla libraries for developers.</a></li></ul>"
PKG_WTCONTACTWITHFIELDS_WHATS_NEW="<h3>v.1.0.0 What's new?</h3><h4>Joomla 5</h4><p>First extension version.</p>"
PKG_WTCONTACTWITHFIELDS_WHATS_NEW="<h3>v.1.0.1 What's new?</h3><h4>Bug fix</h4><p>The plugin crashed with an error if the contact with the specified id did not exist or was removed from publication. Fixed it.</p>"
PKG_WTCONTACTWITHFIELDS_AFTER_UNINSTALL="Very sorry..."
PKG_WTCONTACTWITHFIELDS_JOOMLARU_TELEGRAM_CHAT="Telegram Joomla community"
2 changes: 1 addition & 1 deletion language/ru-RU/pkg_wtcontactwithfields.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ PKG_WTCONTACTWITHFIELDS_AFTER_INSTALL = "Спасибо за установку
PKG_WTCONTACTWITHFIELDS_AFTER_DISCOVER_INSTALL = "Спасибо за установку расширения"
PKG_WTCONTACTWITHFIELDS_AFTER_UPDATE = "Спасибо за обновление расширения"
PKG_WTCONTACTWITHFIELDS_MAYBE_INTERESTING="<h4>Может быть интересно</h4><ul class=\"nav nav-tabs nav-stacked list-group\"><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/web-assets\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Joomla 4 & Joomla 5 Web Assets</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomshopping\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Расширения для JoomShopping</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomla-plugins\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Плагины Joomla</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomla-modules\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Модули Joomla</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/components\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Компоненты Joomla</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/biblioteki\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Библиотеки Joomla для разработчиков</a></li></ul>"
PKG_WTCONTACTWITHFIELDS_WHATS_NEW="<h3>v.1.0.0 Что нового?</h3><h4>Joomla 5</h4><p>Первая версия расширения.</p>"
PKG_WTCONTACTWITHFIELDS_WHATS_NEW="<h3>v.1.0.1 Что нового?</h3><h4>Исправление ошибок</h4><p>Плагин падал с ошибкой в случае если контакт с указанным id не существовал или был снят с публикации. Исправлено.</p>"
PKG_WTCONTACTWITHFIELDS_AFTER_UNINSTALL="Очень жаль..."
PKG_WTCONTACTWITHFIELDS_JOOMLARU_TELEGRAM_CHAT="Joomla сообщество в Телеграм"
27 changes: 14 additions & 13 deletions pkg_script.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @package WT Amocrm Library
* @version 1.2.1
* @package WT Contact anywhere with fields package
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @сopyright (c) 2022 - October 2023 Sergey Tolkachyov. All rights reserved.
* @сopyright (c) April 2024 Sergey Tolkachyov. All rights reserved.
* @license GNU/GPL3 http://www.gnu.org/licenses/gpl-3.0.html
* @since 1.0.0
*/
Expand Down Expand Up @@ -134,12 +134,13 @@ public function preflight(string $type, InstallerAdapter $adapter): bool
{

$version = new Version();
if(!$version->isCompatible('5.0.0'))
if (!$version->isCompatible('5.0.0'))
{
$this->app->enqueueMessage('&#128546; <strong>WT Contact everywhere with fields</strong> package doesn\'t support Joomla versions <span class="alert-link">lower 5</span>. Your Joomla version is <span class="badge bg-danger">'.$version->getShortVersion().'</span>','error');
$this->app->enqueueMessage('&#128546; <strong>WT Contact everywhere with fields</strong> package doesn\'t support Joomla versions <span class="alert-link">lower 5</span>. Your Joomla version is <span class="badge bg-danger">' . $version->getShortVersion() . '</span>', 'error');

return false;
}

return true;

}
Expand Down Expand Up @@ -167,14 +168,14 @@ public function postflight(string $type, InstallerAdapter $adapter): bool
}

$element = strtoupper($adapter->getElement());
$type = strtoupper($type);
$html = '
<div class="row bg-white m-0">
$type = strtoupper($type);
$html = '
<div class="row m-0">
<div class="col-12 col-md-8 p-0 pe-2">
<h2>'.$smile.' '.Text::_($element.'_AFTER_'.$type).' <br/>'.Text::_($element).'</h2>
'.Text::_($element.'_DESC');
<h2>' . $smile . ' ' . Text::_($element . '_AFTER_' . $type) . ' <br/>' . Text::_($element) . '</h2>
' . Text::_($element . '_DESC');

$html .= Text::_($element.'_WHATS_NEW');
$html .= Text::_($element . '_WHATS_NEW');

$html .= '</div>
<div class="col-12 col-md-4 p-0 d-flex flex-column justify-content-start">
Expand All @@ -185,7 +186,7 @@ public function postflight(string $type, InstallerAdapter $adapter): bool
<a class="btn btn-sm btn-outline-primary" href="mailto:info@web-tolk.ru"><i class="icon-envelope"></i> info@web-tolk.ru</a>
</p>
<p><a class="btn btn-danger w-100" href="https://t.me/joomlaru" target="_blank">' . Text::_($element . '_JOOMLARU_TELEGRAM_CHAT') . '</a></p>
'.Text::_($element."_MAYBE_INTERESTING").'
' . Text::_($element . "_MAYBE_INTERESTING") . '
</div>
';
Expand Down
4 changes: 2 additions & 2 deletions pkg_wtcontactwithfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<extension type="package" method="upgrade">
<name>PKG_WTCONTACTWITHFIELDS</name>
<author>Sergey Tolkachyov</author>
<creationDate>12/02/2024</creationDate>
<creationDate>April 2024</creationDate>
<packagename>wtcontactwithfields</packagename>
<version>1.0.0</version>
<version>1.0.1</version>
<url>https://web-tolk.ru/</url>
<packager>Sergey Tolkachyov</packager>
<packagerurl>https://web-tolk.ru/</packagerurl>
Expand Down
2 changes: 1 addition & 1 deletion plg_content_wtcontactwithfields/services/provider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand All @@ -17,15 +17,14 @@
use Joomla\CMS\Event\Content\BeforeDisplayEvent;
use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Registry\Registry;


final class Wtcontactwithfields extends CMSPlugin implements SubscriberInterface
Expand All @@ -40,6 +39,13 @@ final class Wtcontactwithfields extends CMSPlugin implements SubscriberInterface
*/
protected $autoloadLanguage = true;

public function __construct(DispatcherInterface $dispatcher, array $config = [],)
{
parent::__construct($dispatcher, $config);
Log::addLogger(['text_file' => 'plg_content_wtcontactwithfields.php'], Log::ALL, ['plg_content_wtcontactwithfields']);
}


/**
* Returns an array of events this subscriber will listen to.
*
Expand Down Expand Up @@ -89,7 +95,7 @@ public function onContentPrepare(ContentPrepareEvent $event): void
return;
}

//Проверка есть ли строка замены в контенте
// Проверка есть ли строка замены в контенте
if (strpos($article->text, 'wt_contact_wf') === false)
{
return;
Expand Down Expand Up @@ -120,7 +126,10 @@ public function onContentPrepare(ContentPrepareEvent $event): void

$contact = $this->getContactInfo((int) $short_code_params["contact_id"]);

$html = $this->renderContact($contact, $tmpl);
if (!empty($contact))
{
$html = $this->renderContact($contact, $tmpl);
}

$article->text = str_replace($short_codes[0][$i], $html, $article->text);
if(property_exists($article,'introtext') && !empty($article->introtext))
Expand All @@ -138,6 +147,7 @@ public function onContentPrepare(ContentPrepareEvent $event): void
return;
}
$i++;
$html = '';
}
}

Expand Down Expand Up @@ -303,8 +313,14 @@ private function getContactInfo(int $contact_id): mixed
->getMVCFactory()
->createModel('Contact', 'Site', ['ignore_request' => false]);

return $model->getItem((int) $contact_id);
try
{
return $model->getItem($contact_id);
} catch (\Exception $e) {

Log::add('WT Contact anywhere with fields: '.($e->getMessage()).'. Contact id '.$contact_id,Log::ERROR);
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
2 changes: 1 addition & 1 deletion plg_content_wtcontactwithfields/tmpl/author_info.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
2 changes: 1 addition & 1 deletion plg_content_wtcontactwithfields/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
2 changes: 1 addition & 1 deletion plg_content_wtcontactwithfields/tmpl/link.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
4 changes: 2 additions & 2 deletions plg_content_wtcontactwithfields/wtcontactwithfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<extension type="plugin" group="content" method="upgrade">
<name>PLG_WTCONTACTWITHFIELDS</name>
<author>Sergey Tolkachyov</author>
<creationDate>07/02/2024</creationDate>
<creationDate>April 2024</creationDate>
<copyright>Copyright (C) 2019-2023. All rights reserved.</copyright>
<license>GNU/GPL 3.0</license>
<authorEmail>info@web-tolk.ru</authorEmail>
<authorUrl>https://web-tolk.ru</authorUrl>
<version>1.0.0</version>
<version>1.0.1</version>
<description>PLG_WTCONTACTWITHFIELDS_DESC</description>
<namespace path="src">Joomla\Plugin\Content\Wtcontactwithfields</namespace>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright Copyright (C) 2024 Sergey Tolkachyov. All rights reserved.
* @author Sergey Tolkachyov - https://web-tolk.ru
* @link https://web-tolk.ru
* @version 1.0.0
* @version 1.0.1
* @license GNU General Public License version 3 or later
*/
(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package WT Contacts anywhere with fields
* @version 1.0.0
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @copyright Copyright (C) 2024 Sergey Tolkachyov
* @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<extension type="plugin" group="editors-xtd" method="upgrade">
<name>Editors-xtd - WT Contact anywhere with fields</name>
<author>Sergey Tolkachyov</author>
<creationDate>08/02/2024</creationDate>
<creationDate>April 2024</creationDate>
<copyright>Copyright (C) Sergey Tolkachyov. All rights reserved.</copyright>
<license>GNU General Public License version 3</license>
<authorEmail>info@web-tolk.ru</authorEmail>
<authorUrl>https://web-tolk.ru</authorUrl>
<version>1.0.0</version>
<version>1.0.1</version>
<description>PLG_WTCONTACTWITHFIELDSBUTTON_DESC</description>
<namespace path="src">Joomla\Plugin\EditorsXtd\Wtcontactwithfieldsbutton</namespace>
<media folder="media" destination="plg_editors-xtd_wtcontactwithfieldsbutton">
Expand Down

0 comments on commit 3453240

Please sign in to comment.