From 80c1400ad6d013be934632ec58bf588dd997e410 Mon Sep 17 00:00:00 2001
From: pmleconte
Date: Sun, 8 Oct 2023 18:10:26 +0200
Subject: [PATCH] 2.0.5
fix "Event onContentAfterDisplay only accepts String results" error if show in category = false
Refactor plugin as service provider
+Dynamic version from manifest file
---
cglike.xml | 11 ++-
language/en-GB/plg_content_cglike.ini | 2 +-
language/en-GB/plg_content_cglike.sys.ini | 2 +-
language/fr-FR/plg_content_cglike.ini | 2 +-
language/fr-FR/plg_content_cglike.sys.ini | 2 +-
plg_cg_like_changelog.xml | 17 ++++
services/provider.php | 46 +++++++++
cglike.php => src/Extension/Cglike.php | 13 +--
src/Field/VersionField.php | 111 ++++++++++++++++++++++
src/Field/index.html | 1 +
10 files changed, 193 insertions(+), 14 deletions(-)
create mode 100644 services/provider.php
rename cglike.php => src/Extension/Cglike.php (97%)
create mode 100644 src/Field/VersionField.php
create mode 100644 src/Field/index.html
diff --git a/cglike.xml b/cglike.xml
index 7e3ccc1..321e189 100644
--- a/cglike.xml
+++ b/cglike.xml
@@ -1,16 +1,18 @@
PLG_CONTENT_CG_LIKE
- 2023/06/22
+ 2023-10-08
ConseilGouz
pascal.leconte@conseilgouz.com
https://www.conseilgouz.com
Copyright 2023(c) ConseilGouz. All rights reserved
GNU GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html
- 2.0.4
+ 2.0.5
+ ConseilGouz\Plugin\Content\Cglike
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION
- cglike.php
+ services
+ src
cglike.xml
index.html
sql
@@ -39,7 +41,8 @@
-
Don't forget to activate Ajax CG Like plugin, and this plugin, of course.
"
+PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin.
Don't forget to activate Ajax CG Like plugin, and this plugin, of course.
"
CG_ACTIVATE="Activez Ajax -CG Like plugin."
PLG_CONTENT_CG_LIKE_PLG_POSITION="Plugin Position"
PLG_CONTENT_CG_LIKE_PLG_POSITION_DESC="Select the position of plugin in article"
diff --git a/language/en-GB/plg_content_cglike.sys.ini b/language/en-GB/plg_content_cglike.sys.ini
index 885727f..eab307e 100644
--- a/language/en-GB/plg_content_cglike.sys.ini
+++ b/language/en-GB/plg_content_cglike.sys.ini
@@ -1,2 +1,2 @@
PLG_CONTENT_CG_LIKE="Content - CG Like"
-PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin - version 2.0.4.
Don't forget to activate Ajax CG Like plugin, and this plugin, of course.
"
+PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin.
Don't forget to activate Ajax CG Like plugin, and this plugin, of course.
"
diff --git a/language/fr-FR/plg_content_cglike.ini b/language/fr-FR/plg_content_cglike.ini
index 925d74f..8dc1f23 100644
--- a/language/fr-FR/plg_content_cglike.ini
+++ b/language/fr-FR/plg_content_cglike.ini
@@ -1,5 +1,5 @@
PLG_CONTENT_CG_LIKE="Contenu - CG Like"
-PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin - version 2.0.4.
N'oubliez pas d'activer Ajax -CG Like plugin ainsi que ce plugin.
"
+PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin.
N'oubliez pas d'activer Ajax -CG Like plugin ainsi que ce plugin.
"
CG_ACTIVATE="Activez 'Ajax -CG Like plugin'."
PLG_CONTENT_CG_LIKE_PLG_POSITION="Position"
PLG_CONTENT_CG_LIKE_PLG_POSITION_DESC="Selectionner la position du plugin"
diff --git a/language/fr-FR/plg_content_cglike.sys.ini b/language/fr-FR/plg_content_cglike.sys.ini
index 65db7dc..9e8f5cf 100644
--- a/language/fr-FR/plg_content_cglike.sys.ini
+++ b/language/fr-FR/plg_content_cglike.sys.ini
@@ -1,2 +1,2 @@
PLG_CONTENT_CG_LIKE="Contenu - CG Like"
-PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin - version 2.0.4.
N'oubliez pas d'activer le plugin Ajax CG Like ainsi que ce plugin
"
+PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="CG Like - Content Plugin.
N'oubliez pas d'activer le plugin Ajax CG Like ainsi que ce plugin
"
diff --git a/plg_cg_like_changelog.xml b/plg_cg_like_changelog.xml
index bf1f0c8..0de5d2e 100644
--- a/plg_cg_like_changelog.xml
+++ b/plg_cg_like_changelog.xml
@@ -1,4 +1,21 @@
+
+ cg_like
+ plugin
+ 2.0.5
+
+ - 08/10/2023
+
+
+ - fix "Event onContentAfterDisplay only accepts String results" error if show in category = false
+
+
+ - Refactor plugin as service provider
+
+
+ - Dynamic version from manifest file
+
+
cg_like
plugin
diff --git a/services/provider.php b/services/provider.php
new file mode 100644
index 0000000..e1af649
--- /dev/null
+++ b/services/provider.php
@@ -0,0 +1,46 @@
+set(
+ PluginInterface::class,
+ function (Container $container) {
+ $dispatcher = $container->get(DispatcherInterface::class);
+ $plugin = new Cglike(
+ $dispatcher,
+ (array) PluginHelper::getPlugin('content', 'cglike')
+ );
+ $plugin->setApplication(Factory::getApplication());
+
+ return $plugin;
+ }
+ );
+ }
+};
diff --git a/cglike.php b/src/Extension/Cglike.php
similarity index 97%
rename from cglike.php
rename to src/Extension/Cglike.php
index 99c5795..4f1ff42 100644
--- a/cglike.php
+++ b/src/Extension/Cglike.php
@@ -4,13 +4,14 @@
* @author ConseilGouz
* @license GNU General Public License version 2 or later
*/
+namespace ConseilGouz\Plugin\Content\Cglike\Extension;
defined('_JEXEC') or die('Direct access denied!');
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
-class plgContentCGLike extends CMSPlugin
+class Cglike extends CMSPlugin
{
public function __construct(& $subject, $config)
{
@@ -53,15 +54,15 @@ public function CGLikePrepare ($article, $params)
$showinart = $this->params->get('showinart', 1);
$showincat = $this->params->get('showincat', 1);
if( ($view == 'article') and (!$showinart) )
- return false;
+ return "";
if( ($view == 'category') and (!$showincat) )
- return false;
+ return "";
// Categories and Articles filter
if($this->params->get('encats') or $this->params->get('discats') or $this->params->get('disarts'))
{
$db = Factory::getDBO();
if( $this->params->get('disarts') and (in_array($id, $this->params->get('disarts'))) ) {
- return false;
+ return "";
}
if($this->params->get('discats') or $this->params->get('encats')) {
// get article category
@@ -73,10 +74,10 @@ public function CGLikePrepare ($article, $params)
$cnres = $db->loadObject();
$catid = $cnres->catid;
if( $this->params->get('discats') and (in_array($catid, $this->params->get('discats'))) ) {
- return false;
+ return "";
}
if( $this->params->get('encats') and (!in_array($catid, $this->params->get('encats'))) ) {
- return false;
+ return "";
}
}
}
diff --git a/src/Field/VersionField.php b/src/Field/VersionField.php
new file mode 100644
index 0000000..53af677
--- /dev/null
+++ b/src/Field/VersionField.php
@@ -0,0 +1,111 @@
+def('xml');
+
+ // Load language
+ $jinput = Factory::getApplication()->input;
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query
+ ->select($db->quoteName(array('element','folder','type')))
+ ->from($db->quoteName('#__extensions'))
+ ->where($db->quoteName('extension_id') . '=' . $db->Quote($jinput->get('extension_id', null)));
+ $db->setQuery($query, 0, 1);
+ $row = $db->loadAssoc();
+
+ if ($row['type'] == 'plugin')
+ {
+ $this->plg_full_name = 'plg_' . $row['folder'] . '_' . $row['element'];
+
+ // Is used for building joomfish links
+ $this->langShortCode = null;
+
+ $this->default_lang = ComponentHelper::getParams('com_languages')->get('admin');
+ $language = Factory::getLanguage();
+ $language->load($this->plg_full_name, JPATH_ROOT . dirname($xml), 'en-GB', true);
+ $language->load($this->plg_full_name, JPATH_ROOT . dirname($xml), $this->default_lang, true);
+ }
+
+ $extension = $this->def('extension');
+
+ $user = Factory::getUser();
+ $authorise = $user->authorise('core.manage', 'com_installer');
+
+ if (!StringHelper::strlen($extension) || !StringHelper::strlen($xml) || !$authorise)
+ {
+ return;
+ }
+
+ $version = '';
+
+ if ($xml)
+ {
+ $xml = simplexml_load_file(JPATH_SITE . '/' . $xml);
+ if ($xml && isset($xml->version))
+ {
+ $version = $xml->version;
+ }
+ }
+ $margintop = $this->def('margintop');
+
+ /** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
+ $wa = Factory::getApplication()->getDocument()->getWebAssetManager();
+
+ $css = '';
+ $css .= ".version {display:block;text-align:right;color:brown;font-size:10px;}";
+ $css .= ".readonly.plg-desc {font-weight:normal;}";
+ $css .= "fieldset.radio label {width:auto;}";
+ $wa->addInlineStyle($css);
+ $margintop = $this->def('margintop');
+ if (StringHelper::strlen($margintop)) {
+ $js = "document.addEventListener('DOMContentLoaded', function() {
+ vers = document.querySelector('.version');
+ parent = vers.parentElement.parentElement;
+ parent.style.marginTop = '".$margintop."';
+ })";
+ $wa->addInlineScript($js);
+ }
+ $return .= '' . Text::_('JVERSION') . ' ' . $version . "";
+
+ return $return;
+ }
+ public function def($val, $default = '')
+ {
+ return ( isset( $this->element[$val] ) && (string) $this->element[$val] != '' ) ? (string) $this->element[$val] : $default;
+ }
+
+}
diff --git a/src/Field/index.html b/src/Field/index.html
new file mode 100644
index 0000000..9854954
--- /dev/null
+++ b/src/Field/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file