Convert the content plugins to service providers (#40561)

* Convert the content plugins to service providers

* functions

* namespaces

* doc

* get application from plugin (#29)

* get application from plugin

* Revert pagenavigation

---------

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
This commit is contained in:
Allon Moritz 2023-05-23 15:08:47 +02:00 committed by GitHub
parent 83ef3c246c
commit c19e8072bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 357 additions and 141 deletions

View File

@ -9,9 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_FINDER_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\Finder</namespace>
<files>
<filename plugin="finder">finder.php</filename>
<folder plugin="finder">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_finder.ini</language>

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.finder
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
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 Joomla\Plugin\Content\Finder\Extension\Finder;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Finder(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'finder')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -6,11 +6,10 @@
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Factory;
namespace Joomla\Plugin\Content\Finder\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
@ -23,7 +22,7 @@ use Joomla\CMS\Plugin\PluginHelper;
*
* @since 2.5
*/
class PlgContentFinder extends CMSPlugin
final class Finder extends CMSPlugin
{
/**
* Smart Search after save content method.
@ -43,7 +42,7 @@ class PlgContentFinder extends CMSPlugin
PluginHelper::importPlugin('finder');
// Trigger the onFinderAfterSave event.
Factory::getApplication()->triggerEvent('onFinderAfterSave', [$context, $article, $isNew]);
$this->getApplication()->triggerEvent('onFinderAfterSave', [$context, $article, $isNew]);
}
/**
@ -63,7 +62,7 @@ class PlgContentFinder extends CMSPlugin
PluginHelper::importPlugin('finder');
// Trigger the onFinderBeforeSave event.
Factory::getApplication()->triggerEvent('onFinderBeforeSave', [$context, $article, $isNew]);
$this->getApplication()->triggerEvent('onFinderBeforeSave', [$context, $article, $isNew]);
}
/**
@ -82,7 +81,7 @@ class PlgContentFinder extends CMSPlugin
PluginHelper::importPlugin('finder');
// Trigger the onFinderAfterDelete event.
Factory::getApplication()->triggerEvent('onFinderAfterDelete', [$context, $article]);
$this->getApplication()->triggerEvent('onFinderAfterDelete', [$context, $article]);
}
/**
@ -104,7 +103,7 @@ class PlgContentFinder extends CMSPlugin
PluginHelper::importPlugin('finder');
// Trigger the onFinderChangeState event.
Factory::getApplication()->triggerEvent('onFinderChangeState', [$context, $pks, $value]);
$this->getApplication()->triggerEvent('onFinderChangeState', [$context, $pks, $value]);
}
/**
@ -125,6 +124,6 @@ class PlgContentFinder extends CMSPlugin
PluginHelper::importPlugin('finder');
// Trigger the onFinderCategoryChangeState event.
Factory::getApplication()->triggerEvent('onFinderCategoryChangeState', [$extension, $pks, $value]);
$this->getApplication()->triggerEvent('onFinderCategoryChangeState', [$extension, $pks, $value]);
}
}

View File

@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_JOOMLA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\Joomla</namespace>
<files>
<filename plugin="joomla">joomla.php</filename>
<folder plugin="joomla">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_joomla.ini</language>

View File

@ -0,0 +1,51 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.joomla
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Content\Joomla\Extension\Joomla;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Joomla(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'joomla')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));
return $plugin;
}
);
}
};

View File

@ -6,23 +6,24 @@
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Application\CMSApplicationInterface;
namespace Joomla\Plugin\Content\Joomla\Extension;
use Exception;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Language;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Table\CoreContent;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\CMS\Workflow\WorkflowServiceInterface;
use Joomla\Component\Workflow\Administrator\Table\StageTable;
use Joomla\Component\Workflow\Administrator\Table\WorkflowTable;
use Joomla\Database\DatabaseDriver;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;
use RuntimeException;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
@ -33,23 +34,10 @@ use Joomla\Utilities\ArrayHelper;
*
* @since 1.6
*/
class PlgContentJoomla extends CMSPlugin
final class Joomla extends CMSPlugin
{
/**
* Application object
*
* @var CMSApplicationInterface
* @since 4.0.0
*/
protected $app;
/**
* Database Driver Instance
*
* @var DatabaseDriver
* @since 4.0.0
*/
protected $db;
use DatabaseAwareTrait;
use UserFactoryAwareTrait;
/**
* The save event.
@ -83,10 +71,10 @@ class PlgContentJoomla extends CMSPlugin
if ($item->$publishedField > 0 && isset($data[$publishedField]) && $data[$publishedField] < 1) {
switch ($context) {
case 'com_workflow.workflow':
return $this->_workflowNotUsed($item->id);
return $this->workflowNotUsed($item->id);
case 'com_workflow.stage':
return $this->_stageNotUsed($item->id);
return $this->stageNotUsed($item->id);
}
}
@ -123,7 +111,7 @@ class PlgContentJoomla extends CMSPlugin
return;
}
$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
@ -136,17 +124,17 @@ class PlgContentJoomla extends CMSPlugin
return;
}
$user = $this->app->getIdentity();
$user = $this->getApplication()->getIdentity();
// Messaging for new items
$default_language = ComponentHelper::getParams('com_languages')->get('administrator');
$debug = $this->app->get('debug_lang');
$debug = $this->getApplication()->get('debug_lang');
foreach ($users as $user_id) {
if ($user_id != $user->id) {
// Load language for messaging
$receiver = User::getInstance($user_id);
$receiver = $this->getUserFactory()->loadUserById($user_id);
$lang = Language::getInstance($receiver->getParam('admin_language', $default_language), $debug);
$lang->load('com_content');
$message = [
@ -154,7 +142,7 @@ class PlgContentJoomla extends CMSPlugin
'subject' => $lang->_('COM_CONTENT_NEW_ARTICLE'),
'message' => sprintf($lang->_('COM_CONTENT_ON_NEW_CONTENT'), $user->get('name'), $article->title),
];
$model_message = $this->app->bootComponent('com_messages')->getMVCFactory()
$model_message = $this->getApplication()->bootComponent('com_messages')->getMVCFactory()
->createModel('Message', 'Administrator');
$model_message->save($message);
}
@ -180,13 +168,13 @@ class PlgContentJoomla extends CMSPlugin
switch ($context) {
case 'com_categories.category':
return $this->_canDeleteCategories($data);
return $this->canDeleteCategories($data);
case 'com_workflow.workflow':
return $this->_workflowNotUsed($data->id);
return $this->workflowNotUsed($data->id);
case 'com_workflow.stage':
return $this->_stageNotUsed($data->id);
return $this->stageNotUsed($data->id);
}
}
@ -212,11 +200,11 @@ class PlgContentJoomla extends CMSPlugin
foreach ($pks as $id) {
switch ($context) {
case 'com_workflow.workflow':
$result = $result && $this->_workflowNotUsed($id);
$result = $result && $this->workflowNotUsed($id);
break;
case 'com_workflow.stage':
$result = $result && $this->_stageNotUsed($id);
$result = $result && $this->stageNotUsed($id);
break;
}
}
@ -231,14 +219,14 @@ class PlgContentJoomla extends CMSPlugin
*
* @return boolean
*/
private function _canDeleteCategories($data)
private function canDeleteCategories($data)
{
// Check if this function is enabled.
if (!$this->params->def('check_categories', 1)) {
return true;
}
$extension = $this->app->getInput()->getString('extension');
$extension = $this->getApplication()->getInput()->getString('extension');
// Default to true if not a core extension
$result = true;
@ -258,7 +246,7 @@ class PlgContentJoomla extends CMSPlugin
$table = $tableInfo[$extension]['table_name'];
// See if this category has any content items
$count = $this->_countItemsInCategory($table, $data->get('id'));
$count = $this->countItemsInCategory($table, $data->get('id'));
// Return false if db error
if ($count === false) {
@ -268,20 +256,20 @@ class PlgContentJoomla extends CMSPlugin
if ($count > 0) {
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->get('title'))
. ' ' . Text::plural('COM_CATEGORIES_N_ITEMS_ASSIGNED', $count);
$this->app->enqueueMessage($msg, 'error');
$this->getApplication()->enqueueMessage($msg, 'error');
$result = false;
}
// Check for items in any child categories (if it is a leaf, there are no child categories)
if (!$data->isLeaf()) {
$count = $this->_countItemsInChildren($table, $data->get('id'), $data);
$count = $this->countItemsInChildren($table, $data->get('id'), $data);
if ($count === false) {
$result = false;
} elseif ($count > 0) {
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->get('title'))
. ' ' . Text::plural('COM_CATEGORIES_HAS_SUBCATEGORY_ITEMS', $count);
$this->app->enqueueMessage($msg, 'error');
$this->getApplication()->enqueueMessage($msg, 'error');
$result = false;
}
}
@ -300,10 +288,10 @@ class PlgContentJoomla extends CMSPlugin
*
* @since 4.0.0
*/
private function _workflowNotUsed($pk)
private function workflowNotUsed($pk)
{
// Check if this workflow is the default stage
$table = new WorkflowTable($this->db);
$table = new WorkflowTable($this->getDatabase());
$table->load($pk);
@ -312,12 +300,12 @@ class PlgContentJoomla extends CMSPlugin
}
if ($table->default) {
throw new Exception(Text::_('COM_WORKFLOW_MSG_DELETE_IS_DEFAULT'));
throw new Exception($this->getApplication()->getLanguage()->_('COM_WORKFLOW_MSG_DELETE_IS_DEFAULT'));
}
$parts = explode('.', $table->extension);
$component = $this->app->bootComponent($parts[0]);
$component = $this->getApplication()->bootComponent($parts[0]);
$section = '';
@ -331,7 +319,7 @@ class PlgContentJoomla extends CMSPlugin
}
/** @var \Joomla\Component\Workflow\Administrator\Model\StagesModel $model */
$model = $this->app->bootComponent('com_workflow')->getMVCFactory()
$model = $this->getApplication()->bootComponent('com_workflow')->getMVCFactory()
->createModel('Stages', 'Administrator', ['ignore_request' => true]);
$model->setState('filter.workflow_id', $pk);
@ -341,11 +329,11 @@ class PlgContentJoomla extends CMSPlugin
$stage_ids = array_column($stages, 'id');
$result = $this->_countItemsInStage($stage_ids, $table->extension);
$result = $this->countItemsInStage($stage_ids, $table->extension);
// Return false if db error
if ($result > 0) {
throw new Exception(Text::_('COM_WORKFLOW_MSG_DELETE_WORKFLOW_IS_ASSIGNED'));
throw new Exception($this->getApplication()->getLanguage()->_('COM_WORKFLOW_MSG_DELETE_WORKFLOW_IS_ASSIGNED'));
}
return true;
@ -360,9 +348,9 @@ class PlgContentJoomla extends CMSPlugin
*
* @since 4.0.0
*/
private function _stageNotUsed($pk)
private function stageNotUsed($pk)
{
$table = new StageTable($this->db);
$table = new StageTable($this->getDatabase());
$table->load($pk);
@ -372,10 +360,10 @@ class PlgContentJoomla extends CMSPlugin
// Check if this stage is the default stage
if ($table->default) {
throw new Exception(Text::_('COM_WORKFLOW_MSG_DELETE_IS_DEFAULT'));
throw new Exception($this->getApplication()->getLanguage()->_('COM_WORKFLOW_MSG_DELETE_IS_DEFAULT'));
}
$workflow = new WorkflowTable($this->db);
$workflow = new WorkflowTable($this->getDatabase());
$workflow->load($table->workflow_id);
@ -385,7 +373,7 @@ class PlgContentJoomla extends CMSPlugin
$parts = explode('.', $workflow->extension);
$component = $this->app->bootComponent($parts[0]);
$component = $this->getApplication()->bootComponent($parts[0]);
// No core interface => we're ok
if (!$component instanceof WorkflowServiceInterface) {
@ -394,11 +382,11 @@ class PlgContentJoomla extends CMSPlugin
$stage_ids = [$table->id];
$result = $this->_countItemsInStage($stage_ids, $workflow->extension);
$result = $this->countItemsInStage($stage_ids, $workflow->extension);
// Return false if db error
if ($result > 0) {
throw new Exception(Text::_('COM_WORKFLOW_MSG_DELETE_STAGE_IS_ASSIGNED'));
throw new Exception($this->getApplication()->getLanguage()->_('COM_WORKFLOW_MSG_DELETE_STAGE_IS_ASSIGNED'));
}
return true;
@ -414,9 +402,9 @@ class PlgContentJoomla extends CMSPlugin
*
* @since 1.6
*/
private function _countItemsInCategory($table, $catid)
private function countItemsInCategory($table, $catid)
{
$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Count the items in this category
@ -429,7 +417,7 @@ class PlgContentJoomla extends CMSPlugin
try {
$count = $db->loadResult();
} catch (RuntimeException $e) {
$this->app->enqueueMessage($e->getMessage(), 'error');
$this->getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
@ -447,9 +435,9 @@ class PlgContentJoomla extends CMSPlugin
*
* @since 4.0.0
*/
private function _countItemsInStage(array $stageIds, string $extension): bool
private function countItemsInStage(array $stageIds, string $extension): bool
{
$db = $this->db;
$db = $this->getDatabase();
$parts = explode('.', $extension);
@ -462,7 +450,7 @@ class PlgContentJoomla extends CMSPlugin
$section = $parts[1];
}
$component = $this->app->bootComponent($parts[0]);
$component = $this->getApplication()->bootComponent($parts[0]);
$table = $component->getWorkflowTableBySection($section);
@ -483,7 +471,7 @@ class PlgContentJoomla extends CMSPlugin
try {
return (int) $db->setQuery($query)->loadResult();
} catch (Exception $e) {
$this->app->enqueueMessage($e->getMessage(), 'error');
$this->getApplication()->enqueueMessage($e->getMessage(), 'error');
}
return false;
@ -500,9 +488,9 @@ class PlgContentJoomla extends CMSPlugin
*
* @since 1.6
*/
private function _countItemsInChildren($table, $catid, $data)
private function countItemsInChildren($table, $catid, $data)
{
$db = $this->db;
$db = $this->getDatabase();
// Create subquery for list of child categories
$childCategoryTree = $data->getTree();
@ -527,7 +515,7 @@ class PlgContentJoomla extends CMSPlugin
try {
$count = $db->loadResult();
} catch (RuntimeException $e) {
$this->app->enqueueMessage($e->getMessage(), 'error');
$this->getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
@ -555,7 +543,7 @@ class PlgContentJoomla extends CMSPlugin
if ($context === 'com_workflow.stage' && $value < 1) {
foreach ($pks as $pk) {
if (!$this->_stageNotUsed($pk)) {
if (!$this->stageNotUsed($pk)) {
return false;
}
}
@ -563,7 +551,7 @@ class PlgContentJoomla extends CMSPlugin
return true;
}
$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('core_content_id'))
->from($db->quoteName('#__ucm_content'))
@ -607,7 +595,7 @@ class PlgContentJoomla extends CMSPlugin
$params = json_decode($table->params, true);
if ($params['enable_category'] == 1 && empty($params['catid'])) {
$table->setError(Text::_('COM_CONTENT_CREATE_ARTICLE_ERROR'));
$table->setError($this->getApplication()->getLanguage()->_('COM_CONTENT_CREATE_ARTICLE_ERROR'));
return false;
}

View File

@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_LOADMODULE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\LoadModule</namespace>
<files>
<filename plugin="loadmodule">loadmodule.php</filename>
<folder plugin="loadmodule">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_loadmodule.ini</language>

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.loadmodule
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
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 Joomla\Plugin\Content\LoadModule\Extension\LoadModule;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new LoadModule(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'loadmodule')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -6,11 +6,10 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Factory;
namespace Joomla\Plugin\Content\LoadModule\Extension;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Plugin\CMSPlugin;
@ -24,7 +23,7 @@ use Joomla\CMS\Plugin\CMSPlugin;
*
* @since 1.5
*/
class PlgContentLoadmodule extends CMSPlugin
final class LoadModule extends CMSPlugin
{
protected static $modules = [];
@ -88,7 +87,7 @@ class PlgContentLoadmodule extends CMSPlugin
$position = trim($matcheslist[0]);
$style = trim($matcheslist[1]);
$output = $this->_load($position, $style);
$output = $this->load($position, $style);
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
if (($start = strpos($article->text, $match[0])) !== false) {
@ -124,7 +123,7 @@ class PlgContentLoadmodule extends CMSPlugin
$stylemod = trim($matchesmodlist[2]);
}
$output = $this->_loadmod($module, $title, $stylemod);
$output = $this->loadModule($module, $title, $stylemod);
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
if (($start = strpos($article->text, $matchmod[0])) !== false) {
@ -142,7 +141,7 @@ class PlgContentLoadmodule extends CMSPlugin
if ($matchesmodid) {
foreach ($matchesmodid as $match) {
$id = trim($match[1]);
$output = $this->_loadid($id);
$output = $this->loadID($id);
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
if (($start = strpos($article->text, $match[0])) !== false) {
@ -163,9 +162,9 @@ class PlgContentLoadmodule extends CMSPlugin
*
* @since 1.6
*/
protected function _load($position, $style = 'none')
private function load($position, $style = 'none')
{
$document = Factory::getDocument();
$document = $this->getApplication()->getDocument();
$renderer = $document->loadRenderer('module');
$modules = ModuleHelper::getModules($position);
$params = ['style' => $style];
@ -190,9 +189,9 @@ class PlgContentLoadmodule extends CMSPlugin
*
* @since 1.6
*/
protected function _loadmod($module, $title, $style = 'none')
private function loadModule($module, $title, $style = 'none')
{
$document = Factory::getDocument();
$document = $this->getApplication()->getDocument();
$renderer = $document->loadRenderer('module');
$mod = ModuleHelper::getModule($module, $title);
@ -222,9 +221,9 @@ class PlgContentLoadmodule extends CMSPlugin
*
* @since 3.9.0
*/
protected function _loadid($id)
private function loadID($id)
{
$document = Factory::getDocument();
$document = $this->getApplication()->getDocument();
$renderer = $document->loadRenderer('module');
$modules = ModuleHelper::getModuleById($id);
$params = ['style' => 'none'];

View File

@ -9,8 +9,11 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_PAGEBREAK_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\PageBreak</namespace>
<files>
<filename plugin="pagebreak">pagebreak.php</filename>
<folder plugin="pagebreak">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_pagebreak.ini</language>

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.pagebreak
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
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 Joomla\Plugin\Content\PageBreak\Extension\PageBreak;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new PageBreak(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'pagebreak')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -6,11 +6,11 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Factory;
namespace Joomla\Plugin\Content\PageBreak\Extension;
use Exception;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Pagination\Pagination;
@ -19,6 +19,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Utility\Utility;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\String\StringHelper;
use stdClass;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
@ -39,7 +40,7 @@ use Joomla\String\StringHelper;
*
* @since 1.6
*/
class PlgContentPagebreak extends CMSPlugin
final class PageBreak extends CMSPlugin
{
/**
* The navigation list with all page objects if parameter 'multipage_toc' is active.
@ -74,7 +75,7 @@ class PlgContentPagebreak extends CMSPlugin
// Expression to search for.
$regex = '#<hr(.*)class="system-pagebreak"(.*)\/?>#iU';
$input = Factory::getApplication()->getInput();
$input = $this->getApplication()->getInput();
$print = $input->getBool('print');
$showall = $input->getBool('showall');
@ -92,7 +93,7 @@ class PlgContentPagebreak extends CMSPlugin
// Simple performance check to determine whether bot should process further.
if (StringHelper::strpos($row->text, 'class="system-pagebreak') === false) {
if ($page > 0) {
throw new Exception(Text::_('JERROR_PAGE_NOT_FOUND'), 404);
throw new Exception($this->getApplication()->getLanguage()->_('JERROR_PAGE_NOT_FOUND'), 404);
}
return;
@ -124,7 +125,7 @@ class PlgContentPagebreak extends CMSPlugin
if ($hasToc) {
// Display TOC.
$page = 1;
$this->_createToc($row, $matches, $page);
$this->createToc($row, $matches, $page);
} else {
$row->toc = '';
}
@ -138,7 +139,7 @@ class PlgContentPagebreak extends CMSPlugin
$text = preg_split($regex, $row->text);
if (!isset($text[$page])) {
throw new Exception(Text::_('JERROR_PAGE_NOT_FOUND'), 404);
throw new Exception($this->getApplication()->getLanguage()->_('JERROR_PAGE_NOT_FOUND'), 404);
}
// Count the number of pages.
@ -164,7 +165,7 @@ class PlgContentPagebreak extends CMSPlugin
if ($style === 'pages') {
// Display TOC.
if ($hasToc) {
$this->_createToc($row, $matches, $page);
$this->createToc($row, $matches, $page);
} else {
$row->toc = '';
}
@ -189,7 +190,7 @@ class PlgContentPagebreak extends CMSPlugin
// Adds navigation between pages to bottom of text.
if ($hasToc) {
$this->_createNavigation($row, $page, $n);
$this->createNavigation($row, $page, $n);
}
// Page links shown at bottom of page if TOC disabled.
@ -260,16 +261,16 @@ class PlgContentPagebreak extends CMSPlugin
*
* @since 1.6
*/
protected function _createToc(&$row, &$matches, &$page)
private function createToc(&$row, &$matches, &$page)
{
$heading = $row->title ?? Text::_('PLG_CONTENT_PAGEBREAK_NO_TITLE');
$input = Factory::getApplication()->getInput();
$heading = $row->title ?? $this->getApplication()->getLanguage()->_('PLG_CONTENT_PAGEBREAK_NO_TITLE');
$input = $this->getApplication()->getInput();
$limitstart = $input->getUint('limitstart', 0);
$showall = $input->getInt('showall', 0);
$headingtext = '';
if ($this->params->get('article_index', 1) == 1) {
$headingtext = Text::_('PLG_CONTENT_PAGEBREAK_ARTICLE_INDEX');
$headingtext = $this->getApplication()->getLanguage()->_('PLG_CONTENT_PAGEBREAK_ARTICLE_INDEX');
if ($this->params->get('article_index_text')) {
$headingtext = htmlspecialchars($this->params->get('article_index_text'), ENT_QUOTES, 'UTF-8');
@ -310,7 +311,7 @@ class PlgContentPagebreak extends CMSPlugin
if ($this->params->get('showall')) {
$this->list[$i] = new stdClass();
$this->list[$i]->link = RouteHelper::getArticleRoute($row->slug, $row->catid, $row->language) . '&showall=1';
$this->list[$i]->title = Text::_('PLG_CONTENT_PAGEBREAK_ALL_PAGES');
$this->list[$i]->title = $this->getApplication()->getLanguage()->_('PLG_CONTENT_PAGEBREAK_ALL_PAGES');
$this->list[$i]->active = ($limitstart === $i - 1);
}
@ -332,7 +333,7 @@ class PlgContentPagebreak extends CMSPlugin
*
* @since 1.6
*/
protected function _createNavigation(&$row, $page, $n)
private function createNavigation(&$row, $page, $n)
{
$links = [
'next' => '',

View File

@ -10,7 +10,6 @@
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
@ -19,7 +18,7 @@ use Joomla\CMS\Router\Route;
* @var $page integer The page number
*/
$lang = Factory::getLanguage();
$lang = $this->getApplication()->getLanguage();
?>
<ul class="pagination">
<li class="previous page-item">

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.vote
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
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 Joomla\Plugin\Content\Vote\Extension\Vote;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Vote(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'vote')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -6,10 +6,10 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
namespace Joomla\Plugin\Content\Vote\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
@ -22,37 +22,18 @@ use Joomla\CMS\Plugin\PluginHelper;
*
* @since 1.5
*/
class PlgContentVote extends CMSPlugin
final class Vote extends CMSPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*
* @since 3.7.0
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0 as it is there only for layout overrides
* Use getApplication() instead
*/
protected $app;
/**
* The position the voting data is displayed in relative to the article.
*
* @var string
*
* @since 3.7.0
*/
protected $votingPosition;
/**
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
*
* @since 3.7.0
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$this->votingPosition = $this->params->get('position', 'top');
}
/**
* Displays the voting area when viewing an article and the voting section is displayed before the article
*
@ -67,7 +48,7 @@ class PlgContentVote extends CMSPlugin
*/
public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
{
if ($this->votingPosition !== 'top') {
if ($this->params->get('position', 'top') !== 'top') {
return '';
}
@ -88,7 +69,7 @@ class PlgContentVote extends CMSPlugin
*/
public function onContentAfterDisplay($context, &$row, &$params, $page = 0)
{
if ($this->votingPosition !== 'bottom') {
if ($this->params->get('position', 'top') !== 'bottom') {
return '';
}
@ -130,7 +111,7 @@ class PlgContentVote extends CMSPlugin
include $path;
$html = ob_get_clean();
if ($this->app->getInput()->getString('view', '') === 'article' && $row->state == 1) {
if ($this->getApplication()->getInput()->getString('view', '') === 'article' && $row->state == 1) {
// Get the path for the voting form layout file
$path = PluginHelper::getLayoutPath('content', 'vote', 'vote');

View File

@ -15,7 +15,7 @@ use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->app->getDocument()->getWebAssetManager();
$wa = $this->getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseStyle('plg_content_vote', 'plg_content_vote/rating.css');
/**

View File

@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_VOTE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\Vote</namespace>
<files>
<filename plugin="vote">vote.php</filename>
<folder plugin="vote">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<languages>