Skip to content

Commit

Permalink
2.0.5
Browse files Browse the repository at this point in the history
fix "Event onContentAfterDisplay only accepts String results" error if show in category = false
Refactor plugin as service provider
+Dynamic version from manifest file
  • Loading branch information
conseilgouz committed Oct 8, 2023
1 parent 0fd7acd commit 80c1400
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 14 deletions.
11 changes: 7 additions & 4 deletions cglike.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="content" method="upgrade">
<name>PLG_CONTENT_CG_LIKE</name>
<creationDate>2023/06/22</creationDate>
<creationDate>2023-10-08</creationDate>
<author>ConseilGouz</author>
<authorEmail>pascal.leconte@conseilgouz.com</authorEmail>
<authorUrl>https://www.conseilgouz.com</authorUrl>
<copyright>Copyright 2023(c) ConseilGouz. All rights reserved</copyright>
<license>GNU GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html</license>
<version>2.0.4</version>
<version>2.0.5</version>
<namespace path="src">ConseilGouz\Plugin\Content\Cglike</namespace>
<description>PLG_CONTENT_CG_LIKE_XML_DESCRIPTION</description>
<files>
<filename plugin="cglike">cglike.php</filename>
<folder plugin="cglike">services</folder>
<folder>src</folder>
<filename >cglike.xml</filename>
<filename>index.html</filename>
<folder>sql</folder>
Expand Down Expand Up @@ -39,7 +41,8 @@
</uninstall>
<config>
<fields name="params">
<fieldset name="basic">
<fieldset name="basic" addfieldprefix="ConseilGouz\Plugin\Content\Cglike\Field">
<field name="version" type="version" extension="cglike" margintop="-3em" xml="/plugins/content/cglike/cglike.xml"/>>
<field
name="regonly"
type="radio"
Expand Down
2 changes: 1 addition & 1 deletion language/en-GB/plg_content_cglike.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PLG_CONTENT_CG_LIKE="Content - CG Like"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin - version 2.0.4.</p><p>Don't forget to activate <b>Ajax CG Like plugin</b>, and this plugin, of course.</p>"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin.</p><p>Don't forget to activate <b>Ajax CG Like plugin</b>, and this plugin, of course.</p>"
CG_ACTIVATE="Activez <b>Ajax -CG Like plugin</b>."
PLG_CONTENT_CG_LIKE_PLG_POSITION="Plugin Position"
PLG_CONTENT_CG_LIKE_PLG_POSITION_DESC="Select the position of plugin in article"
Expand Down
2 changes: 1 addition & 1 deletion language/en-GB/plg_content_cglike.sys.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PLG_CONTENT_CG_LIKE="Content - CG Like"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin - version 2.0.4.</p><p>Don't forget to activate <b>Ajax CG Like plugin</b>, and this plugin, of course.</p>"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin.</p><p>Don't forget to activate <b>Ajax CG Like plugin</b>, and this plugin, of course.</p>"
2 changes: 1 addition & 1 deletion language/fr-FR/plg_content_cglike.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PLG_CONTENT_CG_LIKE="Contenu - CG Like"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin - version 2.0.4.</p><p>N'oubliez pas d'activer <b>Ajax -CG Like plugin</b> ainsi que ce plugin.</p>"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin.</p><p>N'oubliez pas d'activer <b>Ajax -CG Like plugin</b> ainsi que ce plugin.</p>"
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"
Expand Down
2 changes: 1 addition & 1 deletion language/fr-FR/plg_content_cglike.sys.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PLG_CONTENT_CG_LIKE="Contenu - CG Like"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin - version 2.0.4.</p><p>N'oubliez pas d'activer le plugin <b>Ajax CG Like</b> ainsi que ce plugin</p>"
PLG_CONTENT_CG_LIKE_XML_DESCRIPTION="<p>CG Like - Content Plugin.</p><p>N'oubliez pas d'activer le plugin <b>Ajax CG Like</b> ainsi que ce plugin</p>"
17 changes: 17 additions & 0 deletions plg_cg_like_changelog.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<changelogs>
<changelog>
<element>cg_like</element>
<type>plugin</type>
<version>2.0.5</version>
<note>
<item>08/10/2023</item>
</note>
<fix>
<item>fix "Event onContentAfterDisplay only accepts String results" error if show in category = false </item>
</fix>
<change>
<item>Refactor plugin as service provider</item>
</change>
<addition>
<item>Dynamic version from manifest file</item>
</addition>
</changelog>
<changelog>
<element>cg_like</element>
<type>plugin</type>
Expand Down
46 changes: 46 additions & 0 deletions services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* CG Like plugin for Joomla 4.x/5.x
* @author ConseilgGouz
* @copyright (C) 2023 www.conseilgouz.com. All Rights Reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use ConseilGouz\Plugin\Content\Cglike\Extension\Cglike;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.3.0
*/
public function register(Container $container)
{
$container->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;
}
);
}
};
13 changes: 7 additions & 6 deletions cglike.php → src/Extension/Cglike.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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 "";
}
}
}
Expand Down
111 changes: 111 additions & 0 deletions src/Field/VersionField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* CG Like plugin
*
* @author ConseilgGouz
* @copyright (C) 2023 www.conseilgouz.com. All Rights Reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace ConseilGouz\Plugin\Content\Cglike\Field;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Language\Text;
use Joomla\String\StringHelper;

// Prevent direct access
defined('_JEXEC') || die;

class VersionField extends FormField
{
/**
* Element name
*
* @var string
*/
protected $_name = 'Version';
private $plg_full_name;
private $default_lang;
private $langShortCode;

function getInput()
{
$return = '';

$xml = $this->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 .= '<span class="version">' . Text::_('JVERSION') . ' ' . $version . "</span>";

return $return;
}
public function def($val, $default = '')
{
return ( isset( $this->element[$val] ) && (string) $this->element[$val] != '' ) ? (string) $this->element[$val] : $default;
}

}
1 change: 1 addition & 0 deletions src/Field/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><body></body></html>

0 comments on commit 80c1400

Please sign in to comment.