Skip to content

Commit

Permalink
- small code refactor
Browse files Browse the repository at this point in the history
- joomla 5 test
- changelog url
  • Loading branch information
sergeytolkachyov committed Oct 21, 2023
1 parent c9086e7 commit 34ca280
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 166 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# WT-Content-spoiler-Joomla-plugin
This plugin hide a **part of text** between short codes {spoiler} {/spoiler} to spoiler
Support Joomla 4+
This plugin hide a **part of text** between short codes `{spoiler} {/spoiler}` to spoiler
Support Joomla 4 and Joomla 5.
4 changes: 2 additions & 2 deletions language/en-GB/plg_content_wt_content_spoiler.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ PLG_WT_CONTENT_SPOILER_DESC="<p>This plugin hide a part of text between short co
PLG_WT_CONTENT_SPOILER_AFTER_INSTALL = "Thank you for intalling extension"
PLG_WT_CONTENT_SPOILER_AFTER_DISCOVER_INSTALL = "Thank you for intalling extension"
PLG_WT_CONTENT_SPOILER_AFTER_UPDATE = "Thank you for updating extension"
PLG_WT_CONTENT_SPOILER_MAYBE_INTERESTING="<h4>It might 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/joomla-plugins/wt-digitally-signed-pdf.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">WT Digitally signed PDF - Plugin for displaying digital signature data from PDF files signed with attached signature (the signature is inside the PDF file).</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/en/dev/joomla-plugins/jlsitemap-phoca-gallery.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">JLSitemap - Phoca Gallery plugin for XML sitemap</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/en/dev/joomla-plugins/jlsitemap-phoca-gallery.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">JLSitemap - Phoca Gallery plugin for XML sitemap</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/en/dev/joomla-plugins/jlsitemap-phoca-gallery.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">JLSitemap - Phoca Gallery plugin for XML sitemap</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/dev/joomla-plugins/wt-on-fly-image-handler.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">WT On fly image handler for JoomShopping.</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/en/dev/joomshopping/action-log-joomshopping.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">Action log - JoomShopping. Free plugin for Joomla core action logs.</a></li><li class="list-group-item"><a href=\"https://web-tolk.ru/en/dev/joomshopping/shablon-joomshopping-na-bootstrap-4-6.html\" target=\"_blank\" title=\"Go to https://web-tolk.ru\">JoomShopping Bootstrap 4.6 free template.</a></li></ul>"
PLG_WT_CONTENT_SPOILER_WHATS_NEW="<h3>v.1.0.0 What's new?</h3><p>First extension version.</p>"
PLG_WT_CONTENT_SPOILER_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>"
PLG_WT_CONTENT_SPOILER_WHATS_NEW="<h3>v.1.0.1 What's new?</h3><p>First extension version.</p>"
2 changes: 1 addition & 1 deletion language/ru-RU/plg_content_wt_content_spoiler.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ PLG_WT_CONTENT_SPOILER_DESC="<p>Плагин скрывает часть тек
PLG_WT_CONTENT_SPOILER_AFTER_INSTALL = "Спасибо за установку расширения"
PLG_WT_CONTENT_SPOILER_AFTER_DISCOVER_INSTALL = "Спасибо за установку расширения"
PLG_WT_CONTENT_SPOILER_AFTER_UPDATE = "Спасибо за обновление расширения"
PLG_WT_CONTENT_SPOILER_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/joomla-plugins/wt-digitally-signed-pdf.html\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">WT Digitally signed PDF - Плагин для отображения данных электронной подписи из файлов PDF в Joomla 3 и Joomla 4</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomshopping/wt-sm-otpravka-pochta-ru.html\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">Интеграция JoomShopping с Почтой России для Бизнеса</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomshopping/wt-joomshopping-favorite.html\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">WT JoomShopping Favorites, альтернативный список пожеланий (wishlist) для JoomShopping.</a></li><li class=\"list-group-item\"><a href=\"https://web-tolk.ru/dev/joomla-plugins/wt-joomshopping-bitrix24-pro.html\" target=\"_blank\" title=\"Перейти на https://web-tolk.ru\">WT JoomShopping Bitrix24 PRO, плагин двухсторонней интеграции интернет-магазина JoomShopping и CRM Битрикс24.</a></li></ul>"
PLG_WT_CONTENT_SPOILER_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>"
PLG_WT_CONTENT_SPOILER_WHATS_NEW="<h3>v.1.0.0 Что нового?</h3><p>Первая версия расширения.</p>"
347 changes: 207 additions & 140 deletions script.php
Original file line number Diff line number Diff line change
@@ -1,143 +1,210 @@
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;

/**
* Script file of HelloWorld component.
*
* The name of this class is dependent on the component being installed.
* The class name should have the component's name, directly followed by
* the text InstallerScript (ex:. com_helloWorldInstallerScript).
*
* This class will be called by Joomla!'s installer, if specified in your component's
* manifest file, and is used for custom automation actions in its installation process.
*
* In order to use this automation script, you should reference it in your component's
* manifest file as follows:
* <scriptfile>script.php</scriptfile>
*
* @package Joomla.Administrator
* @subpackage com_helloworld
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package WT Content spoiler
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @сopyright (c) 2022 - October 2023 Sergey Tolkachyov. All rights reserved.
* @license GNU/GPL3 http://www.gnu.org/licenses/gpl-3.0.html
* @since 1.0.0
*/
class plgContentWt_content_spoilerInstallerScript
{
/**
* This method is called after a component is installed.
*
* @param \stdClass $parent - Parent object calling this method.
*
* @return void
*/
public function install($parent)
{

}

/**
* This method is called after a component is uninstalled.
*
* @param \stdClass $parent - Parent object calling this method.
*
* @return void
*/
public function uninstall($parent)
{


}

/**
* This method is called after a component is updated.
*
* @param \stdClass $parent - Parent object calling object.
*
* @return void
*/
public function update($parent)
{

}

/**
* Runs just before any installation action is performed on the component.
* Verifications and pre-requisites should run in this function.
*
* @param string $type - Type of PreFlight action. Possible values are:
* - * install
* - * update
* - * discover_install
* @param \stdClass $parent - Parent object calling object.
*
* @return void
*/
public function preflight($type, $parent)
{

}



/**
* Runs right after any installation action is performed on the component.
*
* @param string $type - Type of PostFlight action. Possible values are:
* - * install
* - * update
* - * discover_install
* @param \stdClass $parent - Parent object calling object.
*
* @return void
*/
function postflight($type, $installer)
{

$jversion = new JVersion();

// only for Joomla 3.x

if (version_compare($jversion->getShortVersion(), '4.0', '<')) {

$element = strtoupper($installer->get("element")); // ex. "$parent"
$class = 'span';
$web_tolk_site_icon = "<i class='icon-share-alt'></i>";

} else {

$element = strtoupper($installer->getElement());
$class = 'col-';
$web_tolk_site_icon = '';
}



echo "
<div class='row bg-white m-0' style='margin:25px auto; border:1px solid rgba(0,0,0,0.125); box-shadow:0px 0px 10px rgba(0,0,0,0.125); padding: 10px 20px;'>
<div class='".$class."8'>
<h2>".Text::_("PLG_".$element."_AFTER_".$type)." <br/>".Text::_("PLG_".$element)."</h2>
".Text::_("PLG_".$element."_DESC");

echo Text::_("PLG_".$element."_WHATS_NEW");

echo "</div>
<div class='".$class."4' style='display:flex; flex-direction:column; justify-content:center;'>
<img width='200px' src='https://web-tolk.ru/web_tolk_logo_wide.png'>
<p>Joomla Extensions</p>
<p class='btn-group'>
<a class='btn btn-sm btn-outline-primary' href='https://web-tolk.ru' target='_blank'>".$web_tolk_site_icon." https://web-tolk.ru</a>
<a class='btn btn-sm btn-outline-primary' href='mailto:[email protected]'><i class='icon-envelope'></i> [email protected]</a>
</p>
".Text::_("PLG_".$element."_MAYBE_INTERESTING")."
</div>
";

}
}
\defined('_JEXEC') or die;

use Joomla\CMS\Application\AdministratorApplication;
use Joomla\CMS\Cache\Cache;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\LibraryHelper;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseDriver;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

return new class () implements ServiceProviderInterface {
public function register(Container $container)
{
$container->set(InstallerScriptInterface::class, new class ($container->get(AdministratorApplication::class)) implements InstallerScriptInterface {

/**
* The application object
*
* @var AdministratorApplication
*
* @since 1.0.0
*/
protected AdministratorApplication $app;

/**
* The Database object.
*
* @var DatabaseDriver
*
* @since 1.0.0
*/
protected DatabaseDriver $db;

/**
* Minimum Joomla version required to install the extension.
*
* @var string
*
* @since 1.0.0
*/
protected string $minimumJoomla = '4.0';

/**
* Minimum PHP version required to install the extension.
*
* @var string
*
* @since 1.0.0
*/
protected string $minimumPhp = '7.4';

/**
* Constructor.
*
* @param AdministratorApplication $app The application object.
*
* @since 1.0.0
*/
public function __construct(AdministratorApplication $app)
{
$this->app = $app;
$this->db = Factory::getContainer()->get('DatabaseDriver');
}

/**
* This method is called after a component is installed.
*
* @param \stdClass $installer - Parent object calling this method.
*
* @return void
*/
public function install(InstallerAdapter $adapter): bool
{

return true;

}

/**
* Function called after the extension is uninstalled.
*
* @param InstallerAdapter $adapter The adapter calling this method
*
* @return boolean True on success
*
* @since 1.0.0
*/
public function uninstall(InstallerAdapter $adapter): bool
{

return true;
}

/**
* Function called after the extension is updated.
*
* @param InstallerAdapter $adapter The adapter calling this method
*
* @return boolean True on success
*
* @since 1.0.0
*/
public function update(InstallerAdapter $adapter): bool
{

return true;

}

/**
* Function called before extension installation/update/removal procedure commences.
*
* @param string $type The type of change (install or discover_install, update, uninstall)
* @param InstallerAdapter $adapter The adapter calling this method
*
* @return boolean True on success
*
* @since 1.0.0
*/
public function preflight(string $type, InstallerAdapter $adapter): bool
{

return true;

}


/**
* Function called after extension installation/update/removal procedure commences.
*
* @param string $type The type of change (install or discover_install, update, uninstall)
* @param InstallerAdapter $adapter The adapter calling this method
*
* @return boolean True on success
*
* @since 1.0.0
*/
public function postflight(string $type, InstallerAdapter $adapter): bool
{

$smile = '';
if ($type != 'uninstall')
{
$smiles = ['&#9786;', '&#128512;', '&#128521;', '&#128525;', '&#128526;', '&#128522;', '&#128591;'];
$smile_key = array_rand($smiles, 1);
$smile = $smiles[$smile_key];
}

$element = strtoupper($adapter->getElement());
$type = strtoupper($type);
$html = '
<div class="row bg-white 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');

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

$html .= '</div>
<div class="col-12 col-md-4 p-0 d-flex flex-column justify-content-start">
<img width="180" src="https://web-tolk.ru/web_tolk_logo_wide.png">
<p>Joomla Extensions</p>
<p class="btn-group">
<a class="btn btn-sm btn-outline-primary" href="https://web-tolk.ru" target="_blank"> https://web-tolk.ru</a>
<a class="btn btn-sm btn-outline-primary" href="mailto:[email protected]"><i class="icon-envelope"></i> [email protected]</a>
</p>
'.Text::_($element."_MAYBE_INTERESTING").'
</div>
';
$this->app->enqueueMessage($html, 'info');

return true;
}

/**
* Enable plugin after installation.
*
* @param InstallerAdapter $adapter Parent object calling object.
*
* @since 1.0.0
*/
protected function enablePlugin(InstallerAdapter $adapter)
{
// Prepare plugin object
$plugin = new \stdClass();
$plugin->type = 'plugin';
$plugin->element = $adapter->getElement();
$plugin->folder = (string) $adapter->getParent()->manifest->attributes()['group'];
$plugin->enabled = 1;

// Update record
$this->db->updateObject('#__extensions', $plugin, ['type', 'element', 'folder']);
}

});
}
};
10 changes: 7 additions & 3 deletions services/provider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

/**
* @package WT JoomShopping Bitrix24 PRO
* @copyright Copyright Sergey Tolkachyov
* @license GNU General Public License version 3, or later
* @package WT Content spoiler
* @version 1.0.1
* @Author Sergey Tolkachyov, https://web-tolk.ru
* @сopyright (c) 2022 - October 2023 Sergey Tolkachyov. All rights reserved.
* @license GNU/GPL3 http://www.gnu.org/licenses/gpl-3.0.html
* @since 1.0.0
*/

defined('_JEXEC') || die;
Expand Down
Loading

0 comments on commit 34ca280

Please sign in to comment.