From 24e826aeea6c8cbe2e02dc03ef78020ef247a3c2 Mon Sep 17 00:00:00 2001 From: pmleconte Date: Sun, 10 Mar 2024 11:41:33 +0100 Subject: [PATCH] 2.1.0 Plugin becomes a service provider --- cglike.xml | 12 ++--- plg_cg_like_ajax_changelog.xml | 12 +++++ services/index.html | 4 ++ services/provider.php | 47 ++++++++++++++++ cglike.php => src/Extension/Cglike.php | 33 ++++++++---- src/Extension/index.html | 4 ++ src/Field/VersionField.php | 75 ++++++++++++++++++++++++++ src/Field/index.html | 1 + src/index.html | 4 ++ 9 files changed, 175 insertions(+), 17 deletions(-) create mode 100644 services/index.html create mode 100644 services/provider.php rename cglike.php => src/Extension/Cglike.php (79%) create mode 100644 src/Extension/index.html create mode 100644 src/Field/VersionField.php create mode 100644 src/Field/index.html create mode 100644 src/index.html diff --git a/cglike.xml b/cglike.xml index c307d21..5003b4e 100644 --- a/cglike.xml +++ b/cglike.xml @@ -1,18 +1,18 @@ Ajax - CG Like plugin - 2.0.4 - 2023-10-13 + 2.1.0 + 2024-03-10 ConseilGouz pascal.leconte@conseilgouz.com https://www.conseilgouz.com GNU General Public License version 3 or later - Copyright (C) 2023 ConseilGouz. All rights reserved. + Copyright (C) 2024 ConseilGouz. All rights reserved. Joomla Ajax Like Plugin - + ConseilGouz\Plugin\Ajax\Cglike - cglike.php - cglike.xml + services + src index.html diff --git a/plg_cg_like_ajax_changelog.xml b/plg_cg_like_ajax_changelog.xml index 3c26184..dc1ec59 100644 --- a/plg_cg_like_ajax_changelog.xml +++ b/plg_cg_like_ajax_changelog.xml @@ -1,4 +1,16 @@ + + cg_like + plugin + ajax + 2.1.0 + + 10/03/2023 + + + Plugin becomes a service provider + + cg_like plugin diff --git a/services/index.html b/services/index.html new file mode 100644 index 0000000..6bfc798 --- /dev/null +++ b/services/index.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/services/provider.php b/services/provider.php new file mode 100644 index 0000000..9de9f19 --- /dev/null +++ b/services/provider.php @@ -0,0 +1,47 @@ +set( + PluginInterface::class, + function (Container $container) { + $displatcher = $container->get(DispatcherInterface::class); + $plugin = new Cglike( + $displatcher, + (array) PluginHelper::getPlugin('ajax', 'cglike') + ); + $plugin->setApplication(Factory::getApplication()); + $plugin->setDatabase($container->get(DatabaseInterface::class)); + return $plugin; + } + ); + } +}; diff --git a/cglike.php b/src/Extension/Cglike.php similarity index 79% rename from cglike.php rename to src/Extension/Cglike.php index dc30091..ed6c881 100644 --- a/cglike.php +++ b/src/Extension/Cglike.php @@ -1,41 +1,52 @@ 'goAjax', + ]; + } + function goAjax($event) { $input = Factory::getApplication()->input; $id = $input->get('id', '', 'integer'); $out = ""; if (!self::cookie($id)) {// cookie exist => exit $out .='{"ret":"9","msg":"'.Text::_("CG_AJAX_ALREADY").'"}'; - return $out; + return $event->addResult($out); } $plugin = PluginHelper::getPlugin('content', 'cglike'); $params = new Registry($plugin->params); self::setcookie($id,$params); if (!self::addOne($id)) { $out .= '{"ret":"9","msg":"'.Text::_("CG_AJAX_SQL_ERROR").'"}'; - return $out; + return $event->addResult($out); } $count = self::countId($id); $out .='{"ret":"0","msg":"'.Text::_("CG_AJAX_THANKS").'","cnt":"'.$count.'"}'; - return $out; + return $event->addResult($out); } function cookie($id) { $jinput = Factory::getApplication()->input; @@ -73,7 +84,7 @@ function setcookie($id,$params) { } } function addOne($id) { - $db = Factory::getDbo(); + $db = $this->getDatabase(); $query = $db->getQuery(true); $query->insert('#__cg_like'); $query->set('cid = '.$db->quote($id)); @@ -85,7 +96,7 @@ function addOne($id) { return true; } function countId($id) { - $db = Factory::getDbo(); + $db = $this->getDatabase(); $query = $db->getQuery(true); $query ->select( 'COUNT(id)') ->from($db->quoteName('#__cg_like')) diff --git a/src/Extension/index.html b/src/Extension/index.html new file mode 100644 index 0000000..6bfc798 --- /dev/null +++ b/src/Extension/index.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Field/VersionField.php b/src/Field/VersionField.php new file mode 100644 index 0000000..d41e452 --- /dev/null +++ b/src/Field/VersionField.php @@ -0,0 +1,75 @@ +def('extension'); + + $version = ''; + + $jinput = Factory::getApplication()->input; + $db = Factory::getDBO(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName('manifest_cache')) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('element') . '=' . $db->Quote($extension)); + $db->setQuery($query, 0, 1); + $row = $db->loadAssoc(); + $tmp = json_decode($row['manifest_cache']); + $version = $tmp->version; + + $document = Factory::getDocument(); + $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;}"; + $document->addStyleDeclaration($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."'; + })"; + $document->addScriptDeclaration($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; + } + +} \ No newline at end of file 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 diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..6bfc798 --- /dev/null +++ b/src/index.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file