30
1
mirror of https://github.com/joomla-extensions/weblinks.git synced 2024-06-03 06:50:49 +00:00

Switch to PSR-12

This commit is contained in:
Hannes Papenberg 2023-05-18 18:45:59 +02:00
parent 9f6606a8a4
commit 4292a06af6
69 changed files with 5877 additions and 6032 deletions

20
.editorconfig Normal file
View File

@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style end of lines and a blank line at the end of the file
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.php]
indent_style = space
indent_size = 4
[*.{js,json,scss,css,yml,vue}]
indent_style = space
indent_size = 2

View File

@ -19,13 +19,22 @@
<rule ref="PSR1.Classes.ClassDeclaration"> <rule ref="PSR1.Classes.ClassDeclaration">
<exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern> <exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern>
<exclude-pattern type="relative">src/administrator/manifests/packages/weblinks/script\.php</exclude-pattern>
<exclude-pattern type="relative">src/administrator/components/com_weblinks/helpers/weblinks\.php</exclude-pattern>
<exclude-pattern type="relative">src/components/com_weblinks/helpers/icon\.php</exclude-pattern>
<exclude-pattern type="relative">src/components/com_weblinks/helpers/route\.php</exclude-pattern>
</rule> </rule>
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore"> <rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<exclude-pattern type="relative">src/components/com_weblinks/src/Model/CategoriesModel\.php</exclude-pattern>
<exclude-pattern type="relative">src/components/com_weblinks/src/Model/CategoryModel\.php</exclude-pattern>
<exclude-pattern type="relative">src/components/com_weblinks/src/Model/WeblinkModel\.php</exclude-pattern>
<exclude-pattern type="relative">src/administrator/components/com_weblinks/src/Table/*\.php</exclude-pattern>
</rule> </rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> <rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern> <exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern>
<exclude-pattern type="relative">src/administrator/manifests/packages/weblinks/script\.php</exclude-pattern>
</rule> </rule>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore"> <rule ref="PSR2.Methods.MethodDeclaration.Underscore">
@ -34,5 +43,6 @@
<rule ref="Squiz.Classes.ValidClassName"> <rule ref="Squiz.Classes.ValidClassName">
<exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern> <exclude-pattern type="relative">src/administrator/components/com_weblinks/script\.php</exclude-pattern>
<exclude-pattern type="relative">src/administrator/manifests/packages/weblinks/script\.php</exclude-pattern>
</rule> </rule>
</ruleset> </ruleset>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblinks helper. * Weblinks helper.
@ -16,5 +19,4 @@ defined('_JEXEC') or die;
*/ */
class WeblinksHelper extends \Joomla\Component\Weblinks\Administrator\Helper\WeblinksHelper class WeblinksHelper extends \Joomla\Component\Weblinks\Administrator\Helper\WeblinksHelper
{ {
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\File;
@ -60,18 +63,14 @@ class Com_WeblinksInstallerScript
'/administrator/components/com_weblinks/sql/updates/sqlsrv', '/administrator/components/com_weblinks/sql/updates/sqlsrv',
]; ];
foreach ($files as $file) foreach ($files as $file) {
{ if (File::exists(JPATH_ROOT . $file)) {
if (File::exists(JPATH_ROOT . $file))
{
File::delete(JPATH_ROOT . $file); File::delete(JPATH_ROOT . $file);
} }
} }
foreach ($folders as $folder) foreach ($folders as $folder) {
{ if (Folder::exists(JPATH_ROOT . $folder)) {
if (Folder::exists(JPATH_ROOT . $folder))
{
Folder::delete(JPATH_ROOT . $folder); Folder::delete(JPATH_ROOT . $folder);
} }
} }
@ -95,8 +94,7 @@ class Com_WeblinksInstallerScript
$category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\'); $category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
// Check if the Uncategorised category exists before adding it // Check if the Uncategorised category exists before adding it
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised'))) if (!$category->load(['extension' => 'com_weblinks', 'title' => 'Uncategorised'])) {
{
$category->extension = 'com_weblinks'; $category->extension = 'com_weblinks';
$category->title = 'Uncategorised'; $category->title = 'Uncategorised';
$category->description = ''; $category->description = '';
@ -117,16 +115,14 @@ class Com_WeblinksInstallerScript
$category->setLocation(1, 'last-child'); $category->setLocation(1, 'last-child');
// Check to make sure our data is valid // Check to make sure our data is valid
if (!$category->check()) if (!$category->check()) {
{
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
return; return;
} }
// Now store the category // Now store the category
if (!$category->store(true)) if (!$category->store(true)) {
{
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
return; return;
@ -152,8 +148,7 @@ class Com_WeblinksInstallerScript
// Only execute database changes on MySQL databases // Only execute database changes on MySQL databases
$dbName = Factory::getDbo()->name; $dbName = Factory::getDbo()->name;
if (strpos($dbName, 'mysql') !== false) if (strpos($dbName, 'mysql') !== false) {
{
// Add Missing Table Columns if needed // Add Missing Table Columns if needed
$this->addColumnsIfNeeded(); $this->addColumnsIfNeeded();
@ -194,7 +189,7 @@ class Com_WeblinksInstallerScript
$categoryTypeId = $db->loadResult(); $categoryTypeId = $db->loadResult();
// Set the table columns to insert table to // Set the table columns to insert table to
$columnsArray = array( $columnsArray = [
$db->quoteName('type_title'), $db->quoteName('type_title'),
$db->quoteName('type_alias'), $db->quoteName('type_alias'),
$db->quoteName('table'), $db->quoteName('table'),
@ -202,11 +197,10 @@ class Com_WeblinksInstallerScript
$db->quoteName('field_mappings'), $db->quoteName('field_mappings'),
$db->quoteName('router'), $db->quoteName('router'),
$db->quoteName('content_history_options'), $db->quoteName('content_history_options'),
); ];
// If we have no type id for com_weblinks.weblink insert it // If we have no type id for com_weblinks.weblink insert it
if (!$weblinkTypeId) if (!$weblinkTypeId) {
{
// Insert the data. // Insert the data.
$query->clear(); $query->clear();
$query->insert($db->quoteName('#__content_types')); $query->insert($db->quoteName('#__content_types'));
@ -244,8 +238,7 @@ class Com_WeblinksInstallerScript
} }
// If we have no type id for com_weblinks.category insert it // If we have no type id for com_weblinks.category insert it
if (!$categoryTypeId) if (!$categoryTypeId) {
{
// Insert the data. // Insert the data.
$query->clear(); $query->clear();
$query->insert($db->quoteName('#__content_types')); $query->insert($db->quoteName('#__content_types'));
@ -255,8 +248,7 @@ class Com_WeblinksInstallerScript
. $db->quote('com_weblinks.category') . ', ' . $db->quote('com_weblinks.category') . ', '
. $db->quote(' . $db->quote('
{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"}, {"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}' "common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}') . ', '
) . ', '
. $db->quote('') . ', ' . $db->quote('') . ', '
. $db->quote(' . $db->quote('
{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias", {"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias",
@ -265,8 +257,7 @@ class Com_WeblinksInstallerScript
"core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language",
"core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey",
"core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"},
"special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}' "special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}') . ', '
) . ', '
. $db->quote('WeblinksHelperRoute::getCategoryRoute') . ', ' . $db->quote('WeblinksHelperRoute::getCategoryRoute') . ', '
. $db->quote(' . $db->quote('
{"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml", {"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml",
@ -277,8 +268,7 @@ class Com_WeblinksInstallerScript
"displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id", "displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id",
"displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id", "displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id",
"displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id", "displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id",
"displayColumn":"title"}]}' "displayColumn":"title"}]}')
)
); );
$db->setQuery($query); $db->setQuery($query);
@ -295,20 +285,19 @@ class Com_WeblinksInstallerScript
*/ */
private function dropColumnsIfNeeded() private function dropColumnsIfNeeded()
{ {
$oldColumns = array( $oldColumns = [
'sid', 'sid',
'date', 'date',
'archived', 'archived',
'approved', 'approved',
); ];
$db = Factory::getDbo(); $db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks'); $table = $db->getTableColumns('#__weblinks');
$columns = array_intersect($oldColumns, array_keys($table)); $columns = array_intersect($oldColumns, array_keys($table));
foreach ($columns as $column) foreach ($columns as $column) {
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' DROP COLUMN ' . $db->quoteName($column); $sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' DROP COLUMN ' . $db->quoteName($column);
$db->setQuery($sql); $db->setQuery($sql);
$db->execute(); $db->execute();
@ -327,15 +316,13 @@ class Com_WeblinksInstallerScript
$db = Factory::getDbo(); $db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks'); $table = $db->getTableColumns('#__weblinks');
if (!array_key_exists('version', $table)) if (!array_key_exists('version', $table)) {
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int unsigned NOT NULL DEFAULT '1'"; $sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int unsigned NOT NULL DEFAULT '1'";
$db->setQuery($sql); $db->setQuery($sql);
$db->execute(); $db->execute();
} }
if (!array_key_exists('images', $table)) if (!array_key_exists('images', $table)) {
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL'; $sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL';
$db->setQuery($sql); $db->setQuery($sql);
$db->execute(); $db->execute();

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -6,8 +7,10 @@
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Association\AssociationExtensionInterface; use Joomla\CMS\Association\AssociationExtensionInterface;
use Joomla\CMS\Categories\CategoryFactoryInterface; use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Component\Router\RouterFactoryInterface; use Joomla\CMS\Component\Router\RouterFactoryInterface;
@ -29,8 +32,7 @@ use Joomla\DI\ServiceProviderInterface;
* *
* @since 4.0.0 * @since 4.0.0
*/ */
return new class implements ServiceProviderInterface return new class () implements ServiceProviderInterface {
{
/** /**
* Registers the service provider with a DI container. * Registers the service provider with a DI container.
* *
@ -42,28 +44,20 @@ return new class implements ServiceProviderInterface
*/ */
public function register(Container $container) public function register(Container $container)
{ {
$container->set(AssociationExtensionInterface::class, new AssociationsHelper); $container->set(AssociationExtensionInterface::class, new AssociationsHelper());
$componentNamespace = '\\Joomla\\Component\\Weblinks'; $componentNamespace = '\\Joomla\\Component\\Weblinks';
$container->registerServiceProvider(new CategoryFactory($componentNamespace)); $container->registerServiceProvider(new CategoryFactory($componentNamespace));
$container->registerServiceProvider(new MVCFactory($componentNamespace)); $container->registerServiceProvider(new MVCFactory($componentNamespace));
$container->registerServiceProvider(new ComponentDispatcherFactory($componentNamespace)); $container->registerServiceProvider(new ComponentDispatcherFactory($componentNamespace));
$container->registerServiceProvider(new RouterFactory($componentNamespace)); $container->registerServiceProvider(new RouterFactory($componentNamespace));
$container->set(ComponentInterface::class, function (Container $container) {
$container->set(
ComponentInterface::class,
function (Container $container) {
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class)); $component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setRegistry($container->get(Registry::class)); $component->setRegistry($container->get(Registry::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class)); $component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class)); $component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class)); $component->setAssociationExtension($container->get(AssociationExtensionInterface::class));
$component->setRouterFactory($container->get(RouterFactoryInterface::class)); $component->setRouterFactory($container->get(RouterFactoryInterface::class));
return $component; return $component;
} });
);
} }
}; };

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Controller; namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
@ -29,7 +31,6 @@ class DisplayController extends BaseController
* @since 1.6 * @since 1.6
*/ */
protected $default_view = 'weblinks'; protected $default_view = 'weblinks';
/** /**
* Method to display a view. * Method to display a view.
* *
@ -46,18 +47,14 @@ class DisplayController extends BaseController
$view = $this->input->get('view', 'weblinks'); $view = $this->input->get('view', 'weblinks');
$layout = $this->input->get('layout', 'default'); $layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('id'); $id = $this->input->getInt('id');
// Check for edit form. // Check for edit form.
if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) {
{
// Somehow the person just went to the form - we don't allow that. // Somehow the person just went to the form - we don't allow that.
if (!\count($this->app->getMessageQueue())) if (!\count($this->app->getMessageQueue())) {
{
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
} }
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false)); $this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
return false; return false;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Controller; namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\MVC\Model\BaseDatabaseModel;
@ -35,12 +38,11 @@ class WeblinkController extends FormController
* *
* @since 1.6 * @since 1.6
*/ */
protected function allowAdd($data = array()) protected function allowAdd($data = [])
{ {
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int'); $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
if ($categoryId) if ($categoryId) {
{
// If the category has been passed in the URL check it. // If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId); return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
} }
@ -59,13 +61,12 @@ class WeblinkController extends FormController
* *
* @since 1.6 * @since 1.6
*/ */
protected function allowEdit($data = array(), $key = 'id') protected function allowEdit($data = [], $key = 'id')
{ {
$recordId = (int) isset($data[$key]) ? $data[$key] : 0; $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
// Since there is no asset tracking, fallback to the component permissions. // Since there is no asset tracking, fallback to the component permissions.
if (!$recordId) if (!$recordId) {
{
return parent::allowEdit($data, $key); return parent::allowEdit($data, $key);
} }
@ -73,8 +74,7 @@ class WeblinkController extends FormController
$item = $this->getModel()->getItem($recordId); $item = $this->getModel()->getItem($recordId);
// Since there is no item, return false. // Since there is no item, return false.
if (empty($item)) if (empty($item)) {
{
return false; return false;
} }
@ -101,7 +101,7 @@ class WeblinkController extends FormController
$this->checkToken(); $this->checkToken();
// Set the model // Set the model
$model = $this->getModel('Weblink', 'Administrator', array()); $model = $this->getModel('Weblink', 'Administrator', []);
// Preset the redirect // Preset the redirect
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false)); $this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
@ -123,8 +123,7 @@ class WeblinkController extends FormController
{ {
$task = $this->getTask(); $task = $this->getTask();
if ($task == 'save') if ($task == 'save') {
{
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false)); $this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Controller; namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\MVC\Controller\AdminController;
/** /**
@ -31,7 +33,7 @@ class WeblinksController extends AdminController
* *
* @since 1.6 * @since 1.6
*/ */
public function getModel($name = 'Weblink', $prefix = 'Administrator', $config = array('ignore_request' => true)) public function getModel($name = 'Weblink', $prefix = 'Administrator', $config = ['ignore_request' => true])
{ {
return parent::getModel($name, $prefix, $config); return parent::getModel($name, $prefix, $config);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Extension; namespace Joomla\Component\Weblinks\Administrator\Extension;
defined('JPATH_PLATFORM') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\SiteApplication; use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Association\AssociationServiceTrait; use Joomla\CMS\Association\AssociationServiceTrait;
@ -35,15 +37,19 @@ use Psr\Container\ContainerInterface;
* *
* @since 4.0.0 * @since 4.0.0
*/ */
class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface, class WeblinksComponent extends MVCComponent implements
TagServiceInterface, RouterServiceInterface, BootableExtensionInterface, FieldsServiceInterface CategoryServiceInterface,
AssociationServiceInterface,
TagServiceInterface,
RouterServiceInterface,
BootableExtensionInterface,
FieldsServiceInterface
{ {
use CategoryServiceTrait; use CategoryServiceTrait;
use AssociationServiceTrait; use AssociationServiceTrait;
use HTMLRegistryAwareTrait; use HTMLRegistryAwareTrait;
use RouterServiceTrait; use RouterServiceTrait;
use CategoryServiceTrait, TagServiceTrait use CategoryServiceTrait, TagServiceTrait {
{
CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait; CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait; CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
} }
@ -61,9 +67,11 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface
* *
* @since 4.0.0 * @since 4.0.0
*/ */
public function boot(ContainerInterface $container) public function boot(ContainerInterface $container)
{ {
$this->getRegistry()->register('weblinksadministrator', new AdministratorService); $this->getRegistry()->register('weblinksadministrator', new AdministratorService());
$this->getRegistry()->register('weblinkicon', new Icon($container->get(SiteApplication::class))); $this->getRegistry()->register('weblinkicon', new Icon($container->get(SiteApplication::class)));
} }
@ -80,8 +88,7 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface
*/ */
public function validateSection($section, $item = null) public function validateSection($section, $item = null)
{ {
if ($section != 'weblink') if ($section != 'weblink') {
{
// We don't know other sections // We don't know other sections
return null; return null;
} }
@ -99,11 +106,9 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface
public function getContexts(): array public function getContexts(): array
{ {
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR); Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
$contexts = [
$contexts = array(
'com_weblinks.weblink' => Text::_('COM_WEBLINKS'), 'com_weblinks.weblink' => Text::_('COM_WEBLINKS'),
); ];
return $contexts; return $contexts;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -16,8 +17,9 @@ use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session; use Joomla\CMS\Session\Session;
use Joomla\Database\ParameterType; use Joomla\Database\ParameterType;
defined('JPATH_BASE') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Supports a modal weblink picker. * Supports a modal weblink picker.
* *
@ -32,7 +34,6 @@ class WeblinkField extends FormField
* @since __DEPLOY_VERSION__ * @since __DEPLOY_VERSION__
*/ */
protected $type = 'Modal_Weblink'; protected $type = 'Modal_Weblink';
/** /**
* Method to get the field input markup. * Method to get the field input markup.
* *
@ -46,44 +47,33 @@ class WeblinkField extends FormField
$allowEdit = ((string) $this->element['edit'] == 'true'); $allowEdit = ((string) $this->element['edit'] == 'true');
$allowClear = ((string) $this->element['clear'] != 'false'); $allowClear = ((string) $this->element['clear'] != 'false');
$allowSelect = ((string) $this->element['select'] != 'false'); $allowSelect = ((string) $this->element['select'] != 'false');
// Load language // Load language
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR); Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
// The active weblink id field. // The active weblink id field.
$value = (int) $this->value > 0 ? (int) $this->value : ''; $value = (int) $this->value > 0 ? (int) $this->value : '';
// Create the modal id. // Create the modal id.
$modalId = 'Weblink_' . $this->id; $modalId = 'Weblink_' . $this->id;
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Add the modal field script to the document head. // Add the modal field script to the document head.
$wa->useScript('field.modal-fields'); $wa->useScript('field.modal-fields');
// Script to proxy the select modal function to the modal-fields.js file. // Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect) if ($allowSelect) {
{
static $scriptSelect = null; static $scriptSelect = null;
if (is_null($scriptSelect)) {
if (is_null($scriptSelect)) $scriptSelect = [];
{
$scriptSelect = array();
} }
if (!isset($scriptSelect[$this->id])) if (!isset($scriptSelect[$this->id])) {
{ $wa->addInlineScript(
$wa->addInlineScript(" "
window.jSelectWeblink_" . $this->id . " = function (id, title, catid, object, url, language) { window.jSelectWeblink_" . $this->id . " = function (id, title, catid, object, url, language) {
window.processModalSelect('Article', '" . $this->id . "', id, title, catid, object, url, language); window.processModalSelect('Article', '" . $this->id . "', id, title, catid, object, url, language);
}", }",
[], [],
['type' => 'module'] ['type' => 'module']
); );
Text::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); Text::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED');
$scriptSelect[$this->id] = true; $scriptSelect[$this->id] = true;
} }
} }
@ -92,9 +82,7 @@ class WeblinkField extends FormField
$linkWeblinks = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;' . Session::getFormToken() . '=1'; $linkWeblinks = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;' . Session::getFormToken() . '=1';
$linkWeblink = 'index.php?option=com_weblinks&amp;view=weblink&amp;layout=modal&amp;tmpl=component&amp;' . Session::getFormToken() . '=1'; $linkWeblink = 'index.php?option=com_weblinks&amp;view=weblink&amp;layout=modal&amp;tmpl=component&amp;' . Session::getFormToken() . '=1';
$modalTitle = Text::_('COM_WEBLINKS_CHANGE_WEBLINK'); $modalTitle = Text::_('COM_WEBLINKS_CHANGE_WEBLINK');
if (isset($this->element['language'])) {
if (isset($this->element['language']))
{
$linkWeblinks .= '&amp;forcedLanguage=' . $this->element['language']; $linkWeblinks .= '&amp;forcedLanguage=' . $this->element['language'];
$linkWeblink .= '&amp;forcedLanguage=' . $this->element['language']; $linkWeblink .= '&amp;forcedLanguage=' . $this->element['language'];
$modalTitle .= ' &#8212; ' . $this->element['label']; $modalTitle .= ' &#8212; ' . $this->element['label'];
@ -103,9 +91,7 @@ class WeblinkField extends FormField
$urlSelect = $linkWeblinks . '&amp;function=jSelectWeblink_' . $this->id; $urlSelect = $linkWeblinks . '&amp;function=jSelectWeblink_' . $this->id;
$urlEdit = $linkWeblink . '&amp;task=weblink.edit&amp;id=\' + document.getElementById("' . $this->id . '_id").value + \''; $urlEdit = $linkWeblink . '&amp;task=weblink.edit&amp;id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkWeblink . '&amp;task=weblink.add'; $urlNew = $linkWeblink . '&amp;task=weblink.add';
if ($value) {
if ($value)
{
$db = Factory::getDbo(); $db = Factory::getDbo();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select($db->quoteName('title')) ->select($db->quoteName('title'))
@ -113,32 +99,23 @@ class WeblinkField extends FormField
->where($db->quoteName('id') . ' = :id') ->where($db->quoteName('id') . ' = :id')
->bind(':id', $value, ParameterType::INTEGER); ->bind(':id', $value, ParameterType::INTEGER);
$db->setQuery($query); $db->setQuery($query);
try {
try
{
$title = $db->loadResult(); $title = $db->loadResult();
} } catch (\RuntimeException $e) {
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
} }
} }
$title = empty($title) ? Text::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); $title = empty($title) ? Text::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The current weblink display field. // The current weblink display field.
$html = ''; $html = '';
if ($allowSelect || $allowNew || $allowEdit || $allowClear) {
if ($allowSelect || $allowNew || $allowEdit || $allowClear)
{
$html .= '<span class="input-group">'; $html .= '<span class="input-group">';
} }
$html .= '<input class="form-control" id="' . $this->id . '_name" type="text" value="' . $title . '" readonly size="35">'; $html .= '<input class="form-control" id="' . $this->id . '_name" type="text" value="' . $title . '" readonly size="35">';
// Select weblink button // Select weblink button
if ($allowSelect) if ($allowSelect) {
{
$html .= '<button' $html .= '<button'
. ' class="btn btn-primary' . ($value ? ' hidden' : '') . '"' . ' class="btn btn-primary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"' . ' id="' . $this->id . '_select"'
@ -150,8 +127,7 @@ class WeblinkField extends FormField
} }
// New weblink button // New weblink button
if ($allowNew) if ($allowNew) {
{
$html .= '<button' $html .= '<button'
. ' class="btn btn-secondary' . ($value ? ' hidden' : '') . '"' . ' class="btn btn-secondary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_new"' . ' id="' . $this->id . '_new"'
@ -163,8 +139,7 @@ class WeblinkField extends FormField
} }
// Edit weblink button // Edit weblink button
if ($allowEdit) if ($allowEdit) {
{
$html .= '<button' $html .= '<button'
. ' class="btn btn-primary' . ($value ? '' : ' hidden') . '"' . ' class="btn btn-primary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"' . ' id="' . $this->id . '_edit"'
@ -176,8 +151,7 @@ class WeblinkField extends FormField
} }
// Clear weblink button // Clear weblink button
if ($allowClear) if ($allowClear) {
{
$html .= '<button' $html .= '<button'
. ' class="btn btn-secondary' . ($value ? '' : ' hidden') . '"' . ' class="btn btn-secondary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"' . ' id="' . $this->id . '_clear"'
@ -187,18 +161,13 @@ class WeblinkField extends FormField
. '</button>'; . '</button>';
} }
if ($allowSelect || $allowNew || $allowEdit || $allowClear) if ($allowSelect || $allowNew || $allowEdit || $allowClear) {
{
$html .= '</span>'; $html .= '</span>';
} }
// Select weblink modal // Select weblink modal
if ($allowSelect) if ($allowSelect) {
{ $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalSelect' . $modalId, [
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalSelect' . $modalId,
array(
'title' => $modalTitle, 'title' => $modalTitle,
'url' => $urlSelect, 'url' => $urlSelect,
'height' => '400px', 'height' => '400px',
@ -207,21 +176,15 @@ class WeblinkField extends FormField
'modalWidth' => 80, 'modalWidth' => 80,
'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">' 'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>', . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>',
) ]);
);
} }
$closeButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'cancel', 'weblink-form'); return false;"; $closeButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'cancel', 'weblink-form'); return false;";
$saveButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'save', 'weblink-form'); return false;"; $saveButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'save', 'weblink-form'); return false;";
$applyButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'apply', 'weblink-form'); return false;"; $applyButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'apply', 'weblink-form'); return false;";
// New weblink modal // New weblink modal
if ($allowNew) if ($allowNew) {
{ $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalNew' . $modalId, [
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
'title' => Text::_('COM_WEBLINKS_NEW_WEBLINK'), 'title' => Text::_('COM_WEBLINKS_NEW_WEBLINK'),
'backdrop' => 'static', 'backdrop' => 'static',
'keyboard' => false, 'keyboard' => false,
@ -240,17 +203,12 @@ class WeblinkField extends FormField
. '<a role="button" class="btn btn-success" aria-hidden="true"' . '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">' . ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>', . Text::_('JAPPLY') . '</a>',
) ]);
);
} }
// Edit weblink modal // Edit weblink modal
if ($allowEdit) if ($allowEdit) {
{ $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalEdit' . $modalId, [
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => Text::_('COM_WEBLINKS_EDIT_WEBLINK'), 'title' => Text::_('COM_WEBLINKS_EDIT_WEBLINK'),
'backdrop' => 'static', 'backdrop' => 'static',
'keyboard' => false, 'keyboard' => false,
@ -269,15 +227,13 @@ class WeblinkField extends FormField
. '<a role="button" class="btn btn-success" aria-hidden="true"' . '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">' . ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>', . Text::_('JAPPLY') . '</a>',
) ]);
);
} }
// Note: class='required' for client side validation. // Note: class='required' for client side validation.
$class = $this->required ? ' class="required modal-value"' : ''; $class = $this->required ? ' class="required modal-value"' : '';
$html .= '<input type="hidden" id="' . $this->id . '_id" ' . $class . ' data-required="' . (int) $this->required . '" name="' . $this->name $html .= '<input type="hidden" id="' . $this->id . '_id" ' . $class . ' data-required="' . (int) $this->required . '" name="' . $this->name
. '" data-text="' . htmlspecialchars(Text::_('COM_WEBLINKS_SELECT_A_WEBLINK', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />'; . '" data-text="' . htmlspecialchars(Text::_('COM_WEBLINKS_SELECT_A_WEBLINK', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';
return $html; return $html;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Helper; namespace Joomla\Component\Weblinks\Administrator\Helper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Association\AssociationExtensionHelper; use Joomla\CMS\Association\AssociationExtensionHelper;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
@ -39,7 +41,7 @@ class AssociationsHelper extends AssociationExtensionHelper
* *
* @since __DEPLOY_VERSION__ * @since __DEPLOY_VERSION__
*/ */
protected $itemTypes = array('weblink', 'category'); protected $itemTypes = ['weblink', 'category'];
/** /**
* Has the extension association support * Has the extension association support
@ -78,27 +80,15 @@ class AssociationsHelper extends AssociationExtensionHelper
public function getAssociations($typeName, $id) public function getAssociations($typeName, $id)
{ {
$type = $this->getType($typeName); $type = $this->getType($typeName);
$context = $this->extension . '.item'; $context = $this->extension . '.item';
$catidField = 'catid'; $catidField = 'catid';
if ($typeName === 'category') {
if ($typeName === 'category')
{
$context = 'com_categories.item'; $context = 'com_categories.item';
$catidField = ''; $catidField = '';
} }
// Get the associations. // Get the associations.
$associations = Associations::getAssociations( $associations = Associations::getAssociations($this->extension, $type['tables']['a'], $context, $id, 'id', 'alias', $catidField);
$this->extension,
$type['tables']['a'],
$context,
$id,
'id',
'alias',
$catidField
);
return $associations; return $associations;
} }
@ -114,31 +104,27 @@ class AssociationsHelper extends AssociationExtensionHelper
*/ */
public function getItem($typeName, $id) public function getItem($typeName, $id)
{ {
if (empty($id)) if (empty($id)) {
{
return null; return null;
} }
$table = null; $table = null;
switch ($typeName) {
switch ($typeName)
{
case 'weblink': case 'weblink':
$table = Table::getInstance('WeblinkTable', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\'); $table = Table::getInstance('WeblinkTable', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\');
break;
break;
case 'category': case 'category':
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\'); $table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
break; break;
} }
if (empty($table)) if (empty($table)) {
{
return null; return null;
} }
$table->load($id); $table->load($id);
return $table; return $table;
} }
@ -154,57 +140,49 @@ class AssociationsHelper extends AssociationExtensionHelper
public function getType($typeName = '') public function getType($typeName = '')
{ {
$fields = $this->getFieldsTemplate(); $fields = $this->getFieldsTemplate();
$tables = array(); $tables = [];
$joins = array(); $joins = [];
$support = $this->getSupportTemplate(); $support = $this->getSupportTemplate();
$title = ''; $title = '';
if (in_array($typeName, $this->itemTypes)) {
if (in_array($typeName, $this->itemTypes)) switch ($typeName) {
{
switch ($typeName)
{
case 'weblink': case 'weblink':
$support['state'] = true; $support['state'] = true;
$support['acl'] = true; $support['acl'] = true;
$support['checkout'] = true; $support['checkout'] = true;
$support['category'] = true; $support['category'] = true;
$support['save2copy'] = true; $support['save2copy'] = true;
$tables = [
$tables = array(
'a' => '#__weblinks', 'a' => '#__weblinks',
); ];
$title = 'weblink'; $title = 'weblink';
break;
break;
case 'category': case 'category':
$fields['created_user_id'] = 'a.created_user_id'; $fields['created_user_id'] = 'a.created_user_id';
$fields['ordering'] = 'a.lft'; $fields['ordering'] = 'a.lft';
$fields['level'] = 'a.level'; $fields['level'] = 'a.level';
$fields['catid'] = ''; $fields['catid'] = '';
$fields['state'] = 'a.published'; $fields['state'] = 'a.published';
$support['state'] = true; $support['state'] = true;
$support['acl'] = true; $support['acl'] = true;
$support['checkout'] = true; $support['checkout'] = true;
$support['level'] = true; $support['level'] = true;
$tables = [
$tables = array(
'a' => '#__categories', 'a' => '#__categories',
); ];
$title = 'category'; $title = 'category';
break; break;
} }
} }
return array( return [
'fields' => $fields, 'fields' => $fields,
'support' => $support, 'support' => $support,
'tables' => $tables, 'tables' => $tables,
'joins' => $joins, 'joins' => $joins,
'title' => $title, 'title' => $title,
); ];
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Helper; namespace Joomla\Component\Weblinks\Administrator\Helper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Helper\ContentHelper;
/** /**
@ -20,5 +22,4 @@ use Joomla\CMS\Helper\ContentHelper;
*/ */
class WeblinksHelper extends ContentHelper class WeblinksHelper extends ContentHelper
{ {
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Model; namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
@ -66,8 +69,7 @@ class WeblinkModel extends AdminModel
*/ */
protected function canDelete($record) protected function canDelete($record)
{ {
if (empty($record->id) || $record->state != -2) if (empty($record->id) || $record->state != -2) {
{
return false; return false;
} }
@ -85,8 +87,7 @@ class WeblinkModel extends AdminModel
*/ */
protected function canEditState($record) protected function canEditState($record)
{ {
if (!empty($record->catid)) if (!empty($record->catid)) {
{
return $this->getCurrentUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid); return $this->getCurrentUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
} }
@ -103,31 +104,26 @@ class WeblinkModel extends AdminModel
* *
* @since 1.6 * @since 1.6
*/ */
public function getForm($data = array(), $loadData = true) public function getForm($data = [], $loadData = true)
{ {
// Get the form. // Get the form.
$form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData)); $form = $this->loadForm('com_weblinks.weblink', 'weblink', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) if (empty($form)) {
{
return false; return false;
} }
// Determine correct permissions to check. // Determine correct permissions to check.
if ($this->getState('weblink.id')) if ($this->getState('weblink.id')) {
{
// Existing record. Can only edit in selected categories. // Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit'); $form->setFieldAttribute('catid', 'action', 'core.edit');
} } else {
else
{
// New record. Can only create in selected categories. // New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create'); $form->setFieldAttribute('catid', 'action', 'core.create');
} }
// Modify the form based on access controls. // Modify the form based on access controls.
if (!$this->canEditState((object) $data)) if (!$this->canEditState((object) $data)) {
{
// Disable fields for display. // Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true'); $form->setFieldAttribute('state', 'disabled', 'true');
@ -143,8 +139,7 @@ class WeblinkModel extends AdminModel
} }
// Don't allow to change the created_by user if not allowed to access com_users. // Don't allow to change the created_by user if not allowed to access com_users.
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users')) if (!$this->getCurrentUser()->authorise('core.manage', 'com_users')) {
{
$form->setFieldAttribute('created_by', 'filter', 'unset'); $form->setFieldAttribute('created_by', 'filter', 'unset');
} }
@ -163,15 +158,13 @@ class WeblinkModel extends AdminModel
$app = Factory::getApplication(); $app = Factory::getApplication();
// Check the session for previously entered form data. // Check the session for previously entered form data.
$data = $app->getUserState('com_weblinks.edit.weblink.data', array()); $data = $app->getUserState('com_weblinks.edit.weblink.data', []);
if (empty($data)) if (empty($data)) {
{
$data = $this->getItem(); $data = $this->getItem();
// Prime some default values. // Prime some default values.
if ($this->getState('weblink.id') == 0) if ($this->getState('weblink.id') == 0) {
{
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int')); $data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
} }
} }
@ -192,8 +185,7 @@ class WeblinkModel extends AdminModel
*/ */
public function getItem($pk = null) public function getItem($pk = null)
{ {
if ($item = parent::getItem($pk)) if ($item = parent::getItem($pk)) {
{
// Convert the metadata field to an array. // Convert the metadata field to an array.
$registry = new Registry($item->metadata ?? ''); $registry = new Registry($item->metadata ?? '');
$item->metadata = $registry->toArray(); $item->metadata = $registry->toArray();
@ -205,24 +197,20 @@ class WeblinkModel extends AdminModel
// Load associated web links items // Load associated web links items
$assoc = Associations::isEnabled(); $assoc = Associations::isEnabled();
if ($assoc) if ($assoc) {
{ $item->associations = [];
$item->associations = array();
if ($item->id != null) if ($item->id != null) {
{
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id); $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
foreach ($associations as $tag => $association) foreach ($associations as $tag => $association) {
{
$item->associations[$tag] = $association->id; $item->associations[$tag] = $association->id;
} }
} }
} }
if (!empty($item->id)) if (!empty($item->id)) {
{ $item->tags = new TagsHelper();
$item->tags = new TagsHelper;
$item->tags->getTagIds($item->id, 'com_weblinks.weblink'); $item->tags->getTagIds($item->id, 'com_weblinks.weblink');
$item->metadata['tags'] = $item->tags; $item->metadata['tags'] = $item->tags;
} }
@ -248,18 +236,15 @@ class WeblinkModel extends AdminModel
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES); $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = ApplicationHelper::stringURLSafe($table->alias); $table->alias = ApplicationHelper::stringURLSafe($table->alias);
if (empty($table->alias)) if (empty($table->alias)) {
{
$table->alias = ApplicationHelper::stringURLSafe($table->title); $table->alias = ApplicationHelper::stringURLSafe($table->title);
} }
if (empty($table->id)) if (empty($table->id)) {
{
// Set the values // Set the values
// Set ordering to the last item if not set // Set ordering to the last item if not set
if (empty($table->ordering)) if (empty($table->ordering)) {
{
$db = $this->getDatabase(); $db = $this->getDatabase();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select('MAX(ordering)') ->select('MAX(ordering)')
@ -269,9 +254,7 @@ class WeblinkModel extends AdminModel
$max = $db->loadResult(); $max = $db->loadResult();
$table->ordering = $max + 1; $table->ordering = $max + 1;
} } else {
else
{
// Set the values // Set the values
$table->modified = $date->toSql(); $table->modified = $date->toSql();
$table->modified_by = $user->id; $table->modified_by = $user->id;
@ -293,7 +276,7 @@ class WeblinkModel extends AdminModel
*/ */
protected function getReorderConditions($table) protected function getReorderConditions($table)
{ {
$condition = array(); $condition = [];
$condition[] = 'catid = ' . (int) $table->catid; $condition[] = 'catid = ' . (int) $table->catid;
return $condition; return $condition;
@ -316,15 +299,13 @@ class WeblinkModel extends AdminModel
$catid = (int) $data['catid']; $catid = (int) $data['catid'];
// Check if New Category exists // Check if New Category exists
if ($catid > 0) if ($catid > 0) {
{
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks'); $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
} }
// Save New Category // Save New Category
if ($catid == 0 && $this->canCreateCategory()) if ($catid == 0 && $this->canCreateCategory()) {
{ $table = [];
$table = array();
$table['title'] = $data['catid']; $table['title'] = $data['catid'];
$table['parent_id'] = 1; $table['parent_id'] = 1;
$table['extension'] = 'com_weblinks'; $table['extension'] = 'com_weblinks';
@ -336,8 +317,7 @@ class WeblinkModel extends AdminModel
} }
// Alter the title for save as copy // Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') if ($app->input->get('task') == 'save2copy') {
{
[$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); [$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name; $data['title'] = $name;
$data['alias'] = $alias; $data['alias'] = $alias;
@ -363,17 +343,15 @@ class WeblinkModel extends AdminModel
// Alter the title & alias // Alter the title & alias
$table = $this->getTable(); $table = $this->getTable();
while ($table->load(array('alias' => $alias, 'catid' => $category_id))) while ($table->load(['alias' => $alias, 'catid' => $category_id])) {
{ if ($name == $table->title) {
if ($name == $table->title)
{
$name = StringHelper::increment($name); $name = StringHelper::increment($name);
} }
$alias = StringHelper::increment($alias, 'dash'); $alias = StringHelper::increment($alias, 'dash');
} }
return array($name, $alias); return [$name, $alias];
} }
/** /**
@ -389,26 +367,22 @@ class WeblinkModel extends AdminModel
*/ */
protected function preprocessForm(\JForm $form, $data, $group = 'content') protected function preprocessForm(\JForm $form, $data, $group = 'content')
{ {
if ($this->canCreateCategory()) if ($this->canCreateCategory()) {
{
$form->setFieldAttribute('catid', 'allowAdd', 'true'); $form->setFieldAttribute('catid', 'allowAdd', 'true');
} }
// Association weblinks items // Association weblinks items
if (Associations::isEnabled()) if (Associations::isEnabled()) {
{
$languages = LanguageHelper::getContentLanguages(false, false, null, 'ordering', 'asc'); $languages = LanguageHelper::getContentLanguages(false, false, null, 'ordering', 'asc');
if (count($languages) > 1) if (count($languages) > 1) {
{
$addform = new \SimpleXMLElement('<form />'); $addform = new \SimpleXMLElement('<form />');
$fields = $addform->addChild('fields'); $fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations'); $fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset'); $fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('name', 'item_associations');
foreach ($languages as $language) foreach ($languages as $language) {
{
$field = $fieldset->addChild('field'); $field = $fieldset->addChild('field');
$field->addAttribute('name', $language->lang_code); $field->addAttribute('name', $language->lang_code);
$field->addAttribute('type', 'modal_weblink'); $field->addAttribute('type', 'modal_weblink');

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Model; namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
@ -34,11 +37,10 @@ class WeblinksModel extends ListModel
* @see JControllerLegacy * @see JControllerLegacy
* @since 1.6 * @since 1.6
*/ */
public function __construct($config = array(), MVCFactoryInterface $factory = null) public function __construct($config = [], MVCFactoryInterface $factory = null)
{ {
if (empty($config['filter_fields'])) if (empty($config['filter_fields'])) {
{ $config['filter_fields'] = [
$config['filter_fields'] = array(
'id', 'a.id', 'id', 'a.id',
'title', 'a.title', 'title', 'a.title',
'alias', 'a.alias', 'alias', 'a.alias',
@ -61,12 +63,11 @@ class WeblinksModel extends ListModel
'url', 'a.url', 'url', 'a.url',
'tag', 'tag',
'level', 'c.level', 'level', 'c.level',
); ];
$assoc = Associations::isEnabled(); $assoc = Associations::isEnabled();
if ($assoc) if ($assoc) {
{
$config['filter_fields'][] = 'association'; $config['filter_fields'][] = 'association';
} }
} }
@ -92,14 +93,12 @@ class WeblinksModel extends ListModel
$forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd');
// Adjust the context to support modal layouts. // Adjust the context to support modal layouts.
if ($layout = $app->input->get('layout')) if ($layout = $app->input->get('layout')) {
{
$this->context .= '.' . $layout; $this->context .= '.' . $layout;
} }
// Adjust the context to support forced languages. // Adjust the context to support forced languages.
if ($forcedLanguage) if ($forcedLanguage) {
{
$this->context .= '.' . $forcedLanguage; $this->context .= '.' . $forcedLanguage;
} }
@ -108,8 +107,7 @@ class WeblinksModel extends ListModel
$this->setState('params', $params); $this->setState('params', $params);
// Force a language. // Force a language.
if (!empty($forcedLanguage)) if (!empty($forcedLanguage)) {
{
$this->setState('filter.language', $forcedLanguage); $this->setState('filter.language', $forcedLanguage);
} }
@ -188,8 +186,7 @@ class WeblinksModel extends ListModel
// Join over the associations. // Join over the associations.
$assoc = Associations::isEnabled(); $assoc = Associations::isEnabled();
if ($assoc) if ($assoc) {
{
$query->select('COUNT(asso2.id)>1 AS association') $query->select('COUNT(asso2.id)>1 AS association')
->join('LEFT', $db->quoteName('#__associations', 'asso') . ' ON asso.id = a.id AND asso.context = ' . $db->quote('com_weblinks.item')) ->join('LEFT', $db->quoteName('#__associations', 'asso') . ' ON asso.id = a.id AND asso.context = ' . $db->quote('com_weblinks.item'))
->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON asso2.key = asso.key') ->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON asso2.key = asso.key')
@ -197,43 +194,36 @@ class WeblinksModel extends ListModel
} }
// Filter by access level. // Filter by access level.
if ($access = $this->getState('filter.access')) if ($access = $this->getState('filter.access')) {
{
$query->where($db->quoteName('a.access') . ' = :access') $query->where($db->quoteName('a.access') . ' = :access')
->bind(':access', $access, ParameterType::INTEGER); ->bind(':access', $access, ParameterType::INTEGER);
} }
// Implement View Level Access // Implement View Level Access
if (!$user->authorise('core.admin')) if (!$user->authorise('core.admin')) {
{
$query->whereIn($db->quoteName('a.access'), $user->getAuthorisedViewLevels()); $query->whereIn($db->quoteName('a.access'), $user->getAuthorisedViewLevels());
} }
// Filter by published state // Filter by published state
$published = (string) $this->getState('filter.published'); $published = (string) $this->getState('filter.published');
if (is_numeric($published)) if (is_numeric($published)) {
{
$query->where($db->quoteName('a.state') . ' = :state') $query->where($db->quoteName('a.state') . ' = :state')
->bind(':state', $published, ParameterType::INTEGER); ->bind(':state', $published, ParameterType::INTEGER);
} } elseif ($published === '') {
elseif ($published === '')
{
$query->whereIn($db->quoteName('a.state'), [0, 1]); $query->whereIn($db->quoteName('a.state'), [0, 1]);
} }
// Filter by category. // Filter by category.
$categoryId = $this->getState('filter.category_id'); $categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId)) if (is_numeric($categoryId)) {
{
$query->where($db->quoteName('a.catid') . ' = :catid') $query->where($db->quoteName('a.catid') . ' = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER); ->bind(':catid', $categoryId, ParameterType::INTEGER);
} }
// Filter on the level. // Filter on the level.
if ($level = $this->getState('filter.level')) if ($level = $this->getState('filter.level')) {
{
$query->where($db->quoteName('c.level') . ' <= :level') $query->where($db->quoteName('c.level') . ' <= :level')
->bind(':level', $level, ParameterType::INTEGER); ->bind(':level', $level, ParameterType::INTEGER);
} }
@ -241,16 +231,12 @@ class WeblinksModel extends ListModel
// Filter by search in title // Filter by search in title
$search = $this->getState('filter.search'); $search = $this->getState('filter.search');
if (!empty($search)) if (!empty($search)) {
{ if (stripos($search, 'id:') === 0) {
if (stripos($search, 'id:') === 0)
{
$search = substr($search, 3); $search = substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id') $query->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $search, ParameterType::INTEGER); ->bind(':id', $search, ParameterType::INTEGER);
} } else {
else
{
$search = '%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'); $search = '%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%');
$query->where('(' . $db->quoteName('a.title') . ' LIKE :title OR ' . $db->quoteName('a.alias') . ' LIKE :alias)') $query->where('(' . $db->quoteName('a.title') . ' LIKE :title OR ' . $db->quoteName('a.alias') . ' LIKE :alias)')
->bind(':title', $search) ->bind(':title', $search)
@ -259,8 +245,7 @@ class WeblinksModel extends ListModel
} }
// Filter on the language. // Filter on the language.
if ($language = $this->getState('filter.language')) if ($language = $this->getState('filter.language')) {
{
$query->where($db->quoteName('a.language') . ' = :language') $query->where($db->quoteName('a.language') . ' = :language')
->bind(':language', $language); ->bind(':language', $language);
} }
@ -268,12 +253,12 @@ class WeblinksModel extends ListModel
$tagId = $this->getState('filter.tag'); $tagId = $this->getState('filter.tag');
// Filter by a single tag. // Filter by a single tag.
if (is_numeric($tagId)) if (is_numeric($tagId)) {
{
$query->where($db->quoteName('tagmap.tag_id') . ' = :tagId') $query->where($db->quoteName('tagmap.tag_id') . ' = :tagId')
->bind(':tagId', $tagId, ParameterType::INTEGER) ->bind(':tagId', $tagId, ParameterType::INTEGER)
->join( ->join(
'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') 'LEFT',
$db->quoteName('#__contentitem_tag_map', 'tagmap')
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink')
); );
@ -283,8 +268,7 @@ class WeblinksModel extends ListModel
$orderCol = $this->state->get('list.ordering', 'a.title'); $orderCol = $this->state->get('list.ordering', 'a.title');
$orderDirn = $this->state->get('list.direction', 'ASC'); $orderDirn = $this->state->get('list.direction', 'ASC');
if ($orderCol == 'a.ordering' || $orderCol == 'category_title') if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering'; $orderCol = 'c.title ' . $orderDirn . ', a.ordering';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Service\HTML; namespace Joomla\Component\Weblinks\Administrator\Service\HTML;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\LanguageHelper;
@ -39,20 +41,16 @@ class AdministratorService
{ {
// Defaults // Defaults
$html = ''; $html = '';
// Get the associations // Get the associations
if ($associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $weblinkid)) if ($associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $weblinkid)) {
{ foreach ($associations as $tag => $associated) {
foreach ($associations as $tag => $associated)
{
$associations[$tag] = (int) $associated->id; $associations[$tag] = (int) $associated->id;
} }
// Get the associated contact items // Get the associated contact items
$db = Factory::getDbo(); $db = Factory::getDbo();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select( ->select([
[
$db->quoteName('c.id'), $db->quoteName('c.id'),
$db->quoteName('c.title', 'title'), $db->quoteName('c.title', 'title'),
$db->quoteName('l.sef', 'lang_sef'), $db->quoteName('l.sef', 'lang_sef'),
@ -60,8 +58,7 @@ class AdministratorService
$db->quoteName('cat.title', 'category_title'), $db->quoteName('cat.title', 'category_title'),
$db->quoteName('l.image'), $db->quoteName('l.image'),
$db->quoteName('l.title', 'language_title'), $db->quoteName('l.title', 'language_title'),
] ])
)
->from($db->quoteName('#__weblinks', 'c')) ->from($db->quoteName('#__weblinks', 'c'))
->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) ->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid'))
->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')) ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code'))
@ -69,38 +66,27 @@ class AdministratorService
->where($db->quoteName('c.id') . ' != :id') ->where($db->quoteName('c.id') . ' != :id')
->bind(':id', $weblinkid, ParameterType::INTEGER); ->bind(':id', $weblinkid, ParameterType::INTEGER);
$db->setQuery($query); $db->setQuery($query);
try {
try
{
$items = $db->loadObjectList('id'); $items = $db->loadObjectList('id');
} } catch (\RuntimeException $e) {
catch (\RuntimeException $e)
{
throw new \Exception($e->getMessage(), 500, $e); throw new \Exception($e->getMessage(), 500, $e);
} }
if ($items) if ($items) {
{
$app = Factory::getApplication(); $app = Factory::getApplication();
$languages = LanguageHelper::getContentLanguages(array(0, 1)); $languages = LanguageHelper::getContentLanguages([0, 1]);
$content_languages = array_column($languages, 'lang_code'); $content_languages = array_column($languages, 'lang_code');
foreach ($items as &$item) {
foreach ($items as &$item) if (in_array($item->lang_code, $content_languages)) {
{
if (in_array($item->lang_code, $content_languages))
{
$text = $item->lang_code; $text = $item->lang_code;
$url = Route::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id); $url = Route::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id);
$tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>' $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>'
. htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8')
. '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$classes = 'badge bg-secondary'; $classes = 'badge bg-secondary';
$item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>' $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>'
. '<div role="tooltip" id="tip-' . (int) $weblinkid . '-' . (int) $item->id . '">' . $tooltip . '</div>'; . '<div role="tooltip" id="tip-' . (int) $weblinkid . '-' . (int) $item->id . '">' . $tooltip . '</div>';
} } else {
else
{
// Display warning if Content Language is trashed or deleted // Display warning if Content Language is trashed or deleted
$app->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning'); $app->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Service\HTML; namespace Joomla\Component\Weblinks\Administrator\Service\HTML;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
@ -36,7 +38,6 @@ class Icon
* @since 4.0.0 * @since 4.0.0
*/ */
private $application; private $application;
/** /**
* Service constructor * Service constructor
* *
@ -60,28 +61,20 @@ class Icon
* *
* @since 4.0.0 * @since 4.0.0
*/ */
public static function create($category, $params, $attribs = array()) public static function create($category, $params, $attribs = [])
{ {
$uri = Uri::getInstance(); $uri = Uri::getInstance();
$url = 'index.php?option=com_weblinks&task=weblink.add&return=' . base64_encode($uri) . '&w_id=0&catid=' . $category->id; $url = 'index.php?option=com_weblinks&task=weblink.add&return=' . base64_encode($uri) . '&w_id=0&catid=' . $category->id;
$text = LayoutHelper::render('joomla.content.icons.create', ['params' => $params, 'legacy' => false]);
$text = LayoutHelper::render('joomla.content.icons.create', array('params' => $params, 'legacy' => false));
// Add the button classes to the attribs array // Add the button classes to the attribs array
if (isset($attribs['class'])) if (isset($attribs['class'])) {
{
$attribs['class'] .= ' btn btn-primary'; $attribs['class'] .= ' btn btn-primary';
} } else {
else
{
$attribs['class'] = 'btn btn-primary'; $attribs['class'] = 'btn btn-primary';
} }
$button = HTMLHelper::_('link', Route::_($url), $text, $attribs); $button = HTMLHelper::_('link', Route::_($url), $text, $attribs);
$output = '<span class="hasTooltip" title="' . HTMLHelper::_('tooltipText', 'COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>'; $output = '<span class="hasTooltip" title="' . HTMLHelper::_('tooltipText', 'COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>';
return $output; return $output;
} }
@ -100,73 +93,62 @@ class Icon
* *
* @since 4.0.0 * @since 4.0.0
*/ */
public static function edit($weblink, $params, $attribs = array(), $legacy = false) public static function edit($weblink, $params, $attribs = [], $legacy = false)
{ {
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
$uri = Uri::getInstance(); $uri = Uri::getInstance();
// Ignore if in a popup window. // Ignore if in a popup window.
if ($params && $params->get('popup')) if ($params && $params->get('popup')) {
{
return ''; return '';
} }
// Ignore if the state is negative (trashed). // Ignore if the state is negative (trashed).
if ($weblink->state < 0) if ($weblink->state < 0) {
{
return ''; return '';
} }
// Show checked_out icon if the contact is checked out by a different user // Show checked_out icon if the contact is checked out by a different user
if (property_exists($weblink, 'checked_out') if (
property_exists($weblink, 'checked_out')
&& property_exists($weblink, 'checked_out_time') && property_exists($weblink, 'checked_out_time')
&& $weblink->checked_out && $weblink->checked_out
&& $weblink->checked_out !== $user->get('id')) && $weblink->checked_out !== $user->get('id')
{ ) {
$checkoutUser = Factory::getUser($weblink->checked_out); $checkoutUser = Factory::getUser($weblink->checked_out);
$date = HTMLHelper::_('date', $weblink->checked_out_time); $date = HTMLHelper::_('date', $weblink->checked_out_time);
$tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name) $tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name)
. ' <br> ' . $date; . ' <br> ' . $date;
$text = LayoutHelper::render('joomla.content.icons.edit_lock', ['contact' => $weblink, 'tooltip' => $tooltip, 'legacy' => $legacy]);
$text = LayoutHelper::render('joomla.content.icons.edit_lock', array('contact' => $weblink, 'tooltip' => $tooltip, 'legacy' => $legacy));
$attribs['aria-describedby'] = 'editweblink-' . (int) $weblink->id; $attribs['aria-describedby'] = 'editweblink-' . (int) $weblink->id;
$output = HTMLHelper::_('link', '#', $text, $attribs); $output = HTMLHelper::_('link', '#', $text, $attribs);
return $output; return $output;
} }
$weblinkUrl = RouteHelper::getWeblinkRoute($weblink->slug, $weblink->catid, $weblink->language); $weblinkUrl = RouteHelper::getWeblinkRoute($weblink->slug, $weblink->catid, $weblink->language);
$url = $weblinkUrl . '&task=weblink.edit&w_id=' . $weblink->id . '&return=' . base64_encode($uri); $url = $weblinkUrl . '&task=weblink.edit&w_id=' . $weblink->id . '&return=' . base64_encode($uri);
if ((int) $weblink->state === 0) {
if ((int) $weblink->state === 0)
{
$tooltip = Text::_('COM_WEBLINKS_EDIT_UNPUBLISHED_WEBLINK'); $tooltip = Text::_('COM_WEBLINKS_EDIT_UNPUBLISHED_WEBLINK');
} } else {
else
{
$tooltip = Text::_('COM_WEBLINKS_EDIT_PUBLISHED_WEBLINK'); $tooltip = Text::_('COM_WEBLINKS_EDIT_PUBLISHED_WEBLINK');
} }
$nowDate = strtotime(Factory::getDate()); $nowDate = strtotime(Factory::getDate());
$icon = $weblink->state ? 'edit' : 'eye-slash'; $icon = $weblink->state ? 'edit' : 'eye-slash';
if (($weblink->publish_up !== null && strtotime($weblink->publish_up) > $nowDate) if (
($weblink->publish_up !== null && strtotime($weblink->publish_up) > $nowDate)
|| ($weblink->publish_down !== null && strtotime($weblink->publish_down) < $nowDate || ($weblink->publish_down !== null && strtotime($weblink->publish_down) < $nowDate
&& $weblink->publish_down !== Factory::getDbo()->getNullDate())) && $weblink->publish_down !== Factory::getDbo()->getNullDate())
{ ) {
$icon = 'eye-slash'; $icon = 'eye-slash';
} }
$aria_described = 'editweblink-' . (int) $weblink->id; $aria_described = 'editweblink-' . (int) $weblink->id;
$text = '<span class="icon-' . $icon . '" aria-hidden="true"></span>'; $text = '<span class="icon-' . $icon . '" aria-hidden="true"></span>';
$text .= Text::_('JGLOBAL_EDIT'); $text .= Text::_('JGLOBAL_EDIT');
$text .= '<div role="tooltip" id="' . $aria_described . '">' . $tooltip . '</div>'; $text .= '<div role="tooltip" id="' . $aria_described . '">' . $tooltip . '</div>';
$attribs['aria-describedby'] = $aria_described; $attribs['aria-describedby'] = $aria_described;
$output = HTMLHelper::_('link', Route::_($url), $text, $attribs); $output = HTMLHelper::_('link', Route::_($url), $text, $attribs);
return $output; return $output;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -21,8 +22,9 @@ use Joomla\CMS\Versioning\VersionableTableInterface;
use Joomla\Database\ParameterType; use Joomla\Database\ParameterType;
use Joomla\String\StringHelper; use Joomla\String\StringHelper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblink Table class * Weblink Table class
* *
@ -38,16 +40,16 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
* @var boolean * @var boolean
* @since __DEPLOY_VERSION__ * @since __DEPLOY_VERSION__
*/ */
protected $_supportNullValue = true;
protected $_supportNullValue = true;
/** /**
* Ensure the params and metadata in json encoded in the bind method * Ensure the params and metadata in json encoded in the bind method
* *
* @var array * @var array
* @since 3.4 * @since 3.4
*/ */
protected $_jsonEncode = array('params', 'metadata', 'images'); protected $_jsonEncode = ['params', 'metadata', 'images'];
/** /**
* Constructor * Constructor
* *
@ -58,9 +60,7 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
public function __construct($db) public function __construct($db)
{ {
$this->typeAlias = 'com_weblinks.weblink'; $this->typeAlias = 'com_weblinks.weblink';
parent::__construct('#__weblinks', 'id', $db); parent::__construct('#__weblinks', 'id', $db);
// Set the published column alias // Set the published column alias
$this->setColumnAlias('published', 'state'); $this->setColumnAlias('published', 'state');
} }
@ -78,71 +78,58 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
{ {
$date = Factory::getDate()->toSql(); $date = Factory::getDate()->toSql();
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
$this->modified = $date; $this->modified = $date;
if ($this->id) {
if ($this->id)
{
// Existing item // Existing item
$this->modified_by = $user->id; $this->modified_by = $user->id;
$this->modified = $date; $this->modified = $date;
} } else {
else
{
// New weblink. A weblink created and created_by field can be set by the user, // New weblink. A weblink created and created_by field can be set by the user,
// so we don't touch either of these if they are set. // so we don't touch either of these if they are set.
if (!(int) $this->created) if (!(int) $this->created) {
{
$this->created = $date; $this->created = $date;
} }
if (empty($this->created_by)) if (empty($this->created_by)) {
{
$this->created_by = $user->id; $this->created_by = $user->id;
} }
if (!(int) $this->modified) if (!(int) $this->modified) {
{
$this->modified = $date; $this->modified = $date;
} }
if (empty($this->modified_by)) if (empty($this->modified_by)) {
{
$this->modified_by = $user->id; $this->modified_by = $user->id;
} }
if (empty($this->hits)) if (empty($this->hits)) {
{
$this->hits = 0; $this->hits = 0;
} }
} }
// Set publish_up to null if not set // Set publish_up to null if not set
if (!$this->publish_up) if (!$this->publish_up) {
{
$this->publish_up = null; $this->publish_up = null;
} }
// Set publish_down to null if not set // Set publish_down to null if not set
if (!$this->publish_down) if (!$this->publish_down) {
{
$this->publish_down = null; $this->publish_down = null;
} }
// Verify that the alias is unique // Verify that the alias is unique
$table = new WeblinkTable($this->getDbo()); $table = new WeblinkTable($this->getDbo());
if ($table->load(array('language' => $this->language, 'alias' => $this->alias, 'catid' => (int) $this->catid)) if (
&& ($table->id != $this->id || $this->id == 0)) $table->load(['language' => $this->language, 'alias' => $this->alias, 'catid' => (int) $this->catid])
{ && ($table->id != $this->id || $this->id == 0)
) {
$this->setError(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS')); $this->setError(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
return false; return false;
} }
// Convert IDN urls to punycode // Convert IDN urls to punycode
$this->url = PunycodeHelper::urlToPunycode($this->url); $this->url = PunycodeHelper::urlToPunycode($this->url);
return parent::store($updateNulls); return parent::store($updateNulls);
} }
@ -155,24 +142,19 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
*/ */
public function check() public function check()
{ {
if (InputFilter::checkAttribute(array('href', $this->url))) if (InputFilter::checkAttribute(['href', $this->url])) {
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL')); $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
return false; return false;
} }
// Check for valid name // Check for valid name
if (trim($this->title) == '') if (trim($this->title) == '') {
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE')); $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
return false; return false;
} }
// Check for existing name // Check for existing name
$db = $this->getDbo(); $db = $this->getDbo();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select($db->quoteName('id')) ->select($db->quoteName('id'))
->from($db->quoteName('#__weblinks')) ->from($db->quoteName('#__weblinks'))
@ -183,33 +165,24 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
->bind(':language', $this->language) ->bind(':language', $this->language)
->bind(':catid', $this->catid, ParameterType::INTEGER); ->bind(':catid', $this->catid, ParameterType::INTEGER);
$db->setQuery($query); $db->setQuery($query);
$xid = (int) $db->loadResult(); $xid = (int) $db->loadResult();
if ($xid && $xid != (int) $this->id) {
if ($xid && $xid != (int) $this->id)
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME')); $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME'));
return false; return false;
} }
if (empty($this->alias)) if (empty($this->alias)) {
{
$this->alias = $this->title; $this->alias = $this->title;
} }
$this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '') {
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = Factory::getDate()->format("Y-m-d-H-i-s"); $this->alias = Factory::getDate()->format("Y-m-d-H-i-s");
} }
// Check the publish down date is not earlier than publish up. // Check the publish down date is not earlier than publish up.
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
{
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false; return false;
} }
@ -217,19 +190,15 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
* Clean up keywords -- eliminate extra spaces between phrases * Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string * and cr (\r) and lf (\n) characters from string
*/ */
if (!empty($this->metakey)) if (!empty($this->metakey)) {
{
// Array of characters to remove // Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">"); $bad_characters = ["\n", "\r", "\"", "<", ">"];
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey); $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean); $keys = explode(',', $after_clean);
$clean_keys = array(); $clean_keys = [];
foreach ($keys as $key) {
foreach ($keys as $key)
{
// Ignore blank keywords // Ignore blank keywords
if (trim($key)) if (trim($key)) {
{
$clean_keys[] = trim($key); $clean_keys[] = trim($key);
} }
} }
@ -242,35 +211,28 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
* Ensure any new items have compulsory fields set. This is needed for things like * Ensure any new items have compulsory fields set. This is needed for things like
* frontend editing where we don't show all the fields or using some kind of API * frontend editing where we don't show all the fields or using some kind of API
*/ */
if (!$this->id) if (!$this->id) {
{ if (!isset($this->xreference)) {
if (!isset($this->xreference))
{
$this->xreference = ''; $this->xreference = '';
} }
if (!isset($this->metakey)) if (!isset($this->metakey)) {
{
$this->metakey = ''; $this->metakey = '';
} }
if (!isset($this->metadesc)) if (!isset($this->metadesc)) {
{
$this->metadesc = ''; $this->metadesc = '';
} }
if (!isset($this->images)) if (!isset($this->images)) {
{
$this->images = '{}'; $this->images = '{}';
} }
if (!isset($this->metadata)) if (!isset($this->metadata)) {
{
$this->metadata = '{}'; $this->metadata = '{}';
} }
if (!isset($this->params)) if (!isset($this->params)) {
{
$this->params = '{}'; $this->params = '{}';
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\View\Weblink; namespace Joomla\Component\Weblinks\Administrator\View\Weblink;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
@ -62,14 +65,12 @@ class HtmlView extends BaseHtmlView
$this->form = $this->get('Form'); $this->form = $this->get('Form');
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors'))) {
{
throw new GenericDataException(implode("\n", $errors), 500); throw new GenericDataException(implode("\n", $errors), 500);
} }
// If we are forcing a language in modal (used for associations). // If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
{
// Set the language field to the forcedLanguage and disable changing it. // Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage); $this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true'); $this->form->setFieldAttribute('language', 'readonly', 'true');
@ -108,48 +109,41 @@ class HtmlView extends BaseHtmlView
ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks'); ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
// Build the actions for new and existing records. // Build the actions for new and existing records.
if ($isNew) if ($isNew) {
{
// For new records, check the create permission. // For new records, check the create permission.
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) {
{
ToolbarHelper::apply('weblink.apply'); ToolbarHelper::apply('weblink.apply');
ToolbarHelper::saveGroup( ToolbarHelper::saveGroup(
[ [
['save', 'weblink.save'], ['save', 'weblink.save'],
['save2new', 'weblink.save2new'] ['save2new', 'weblink.save2new'],
], ],
'btn-success' 'btn-success'
); );
} }
ToolbarHelper::cancel('weblink.cancel'); ToolbarHelper::cancel('weblink.cancel');
} } else {
else
{
// Since it's an existing record, check the edit permission, or fall back to edit own if the owner. // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
$itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $user->id); $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $user->id);
$toolbarButtons = []; $toolbarButtons = [];
// Can't save the record if it's checked out and editable // Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable) if (!$checkedOut && $itemEditable) {
{
ToolbarHelper::apply('weblink.apply'); ToolbarHelper::apply('weblink.apply');
$toolbarButtons[] = ['save', 'weblink.save']; $toolbarButtons[] = ['save', 'weblink.save'];
// We can save this record, but check the create permission to see if we can return to make a new one. // We can save this record, but check the create permission to see if we can return to make a new one.
if ($canDo->get('core.create')) if ($canDo->get('core.create')) {
{
$toolbarButtons[] = ['save2new', 'weblink.save2new']; $toolbarButtons[] = ['save2new', 'weblink.save2new'];
} }
} }
// If checked out, we can still save // If checked out, we can still save
if ($canDo->get('core.create')) if ($canDo->get('core.create')) {
{
$toolbarButtons[] = ['save2copy', 'weblink.save2copy']; $toolbarButtons[] = ['save2copy', 'weblink.save2copy'];
} }
@ -160,13 +154,11 @@ class HtmlView extends BaseHtmlView
ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) {
{
ToolbarHelper::versions('com_weblinks.weblink', $this->item->id); ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
} }
if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) {
{
ToolbarHelper::custom('weblink.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false); ToolbarHelper::custom('weblink.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\View\Weblinks; namespace Joomla\Component\Weblinks\Administrator\View\Weblinks;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Helper\ContentHelper;
@ -85,27 +88,21 @@ class HtmlView extends BaseHtmlView
$this->activeFilters = $this->get('ActiveFilters'); $this->activeFilters = $this->get('ActiveFilters');
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors'))) {
{
throw new GenericDataException(implode("\n", $errors), 500); throw new GenericDataException(implode("\n", $errors), 500);
} }
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
{
$this->setLayout('emptystate'); $this->setLayout('emptystate');
} }
// We don't need toolbar in the modal layout. // We don't need toolbar in the modal layout.
if ($this->getLayout() !== 'modal') if ($this->getLayout() !== 'modal') {
{
$this->addToolbar(); $this->addToolbar();
} } else {
else
{
// In article associations modal we need to remove language filter if forcing a language. // In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language. // We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
{
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field. // If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />'); $languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true); $this->filterForm->setField($languageXml, 'filter', true);
@ -138,13 +135,11 @@ class HtmlView extends BaseHtmlView
ToolbarHelper::title(Text::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); ToolbarHelper::title(Text::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) {
{
ToolbarHelper::addNew('weblink.add'); ToolbarHelper::addNew('weblink.add');
} }
if (!$this->isEmptyState && $canDo->get('core.edit.state')) if (!$this->isEmptyState && $canDo->get('core.edit.state')) {
{
$dropdown = $toolbar->dropdownButton('status-group') $dropdown = $toolbar->dropdownButton('status-group')
->text('JTOOLBAR_CHANGE_STATUS') ->text('JTOOLBAR_CHANGE_STATUS')
->toggleSplit(false) ->toggleSplit(false)
@ -160,21 +155,20 @@ class HtmlView extends BaseHtmlView
$childBar->archive('weblinks.archive')->listCheck(true); $childBar->archive('weblinks.archive')->listCheck(true);
if ($user->authorise('core.admin')) if ($user->authorise('core.admin')) {
{
$childBar->checkin('weblinks.checkin')->listCheck(true); $childBar->checkin('weblinks.checkin')->listCheck(true);
} }
if ($this->state->get('filter.published') != -2) if ($this->state->get('filter.published') != -2) {
{
$childBar->trash('weblinks.trash')->listCheck(true); $childBar->trash('weblinks.trash')->listCheck(true);
} }
// Add a batch button // Add a batch button
if ($user->authorise('core.create', 'com_weblinks') if (
$user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')) && $user->authorise('core.edit.state', 'com_weblinks')
{ ) {
$childBar->popupButton('batch') $childBar->popupButton('batch')
->text('JTOOLBAR_BATCH') ->text('JTOOLBAR_BATCH')
->selector('collapseModal') ->selector('collapseModal')
@ -182,16 +176,14 @@ class HtmlView extends BaseHtmlView
} }
} }
if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete')) if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
{
$toolbar->delete('weblinks.delete') $toolbar->delete('weblinks.delete')
->text('JTOOLBAR_EMPTY_TRASH') ->text('JTOOLBAR_EMPTY_TRASH')
->message('JGLOBAL_CONFIRM_DELETE') ->message('JGLOBAL_CONFIRM_DELETE')
->listCheck(true); ->listCheck(true);
} }
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks')) if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks')) {
{
ToolbarHelper::preferences('com_weblinks'); ToolbarHelper::preferences('com_weblinks');
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,26 +8,22 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
HTMLHelper::_('behavior.formvalidator'); HTMLHelper::_('behavior.formvalidator');
$app = Factory::getApplication(); $app = Factory::getApplication();
$input = $app->input; $input = $app->input;
$assoc = Associations::isEnabled(); $assoc = Associations::isEnabled();
// Fieldsets to not automatically render by /layouts/joomla/edit/params.php // Fieldsets to not automatically render by /layouts/joomla/edit/params.php
$this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata'); $this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata');
$this->useCoreUI = true; $this->useCoreUI = true;
// In case of modal // In case of modal
$isModal = $input->get('layout') == 'modal' ? true : false; $isModal = $input->get('layout') == 'modal' ? true : false;
$layout = $isModal ? 'modal' : 'edit'; $layout = $isModal ? 'modal' : 'edit';
@ -65,9 +62,11 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<legend><?php echo Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS'); ?></legend> <legend><?php echo Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS'); ?></legend>
<div> <div>
<?php echo $this->form->renderField('imaJGLOBAL_FIELDSET_IMAGE_OPTIONSges'); ?> <?php echo $this->form->renderField('imaJGLOBAL_FIELDSET_IMAGE_OPTIONSges'); ?>
<?php foreach ($this->form->getGroup('images') as $field) : ?> <?php foreach ($this->form->getGroup('images') as $field) :
?>
<?php echo $field->renderField(); ?> <?php echo $field->renderField(); ?>
<?php endforeach; ?> <?php
endforeach; ?>
</div> </div>
</fieldset> </fieldset>
</div> </div>
@ -94,16 +93,20 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo LayoutHelper::render('joomla.edit.params', $this); ?> <?php echo LayoutHelper::render('joomla.edit.params', $this); ?>
<?php if (!$isModal && $assoc) : ?> <?php if (!$isModal && $assoc) :
?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'associations', Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?> <?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'associations', Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<fieldset id="fieldset-associations" class="options-form"> <fieldset id="fieldset-associations" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS'); ?></legend> <legend><?php echo Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.associations', $this); ?> <?php echo LayoutHelper::render('joomla.edit.associations', $this); ?>
</fieldset> </fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?> <?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php elseif ($isModal && $assoc) : ?> <?php
elseif ($isModal && $assoc) :
?>
<div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div> <div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
<?php endif; ?> <?php
endif; ?>
<?php echo HTMLHelper::_('uitab.endTabSet'); ?> <?php echo HTMLHelper::_('uitab.endTabSet'); ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
echo LayoutHelper::render('joomla.edit.associations', $this); echo LayoutHelper::render('joomla.edit.associations', $this);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,8 +8,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
echo LayoutHelper::render('joomla.edit.metadata', $this); echo LayoutHelper::render('joomla.edit.metadata', $this);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,21 +8,27 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
$fieldSets = $this->form->getFieldsets('params'); ?> $fieldSets = $this->form->getFieldsets('params'); ?>
<?php foreach ($fieldSets as $name => $fieldSet) : ?> <?php foreach ($fieldSets as $name => $fieldSet) :
?>
<div class="tab-pane" id="params-<?php echo $name; ?>"> <div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) : ?> <?php if (isset($fieldSet->description) && trim($fieldSet->description)) :
?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?> <?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php endif; ?> <?php
<?php foreach ($this->form->getFieldset($name) as $field) : ?> endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) :
?>
<div class="control-group"> <div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div> <div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div> <div class="controls"><?php echo $field->input; ?></div>
</div> </div>
<?php endforeach; ?> <?php
endforeach; ?>
</div> </div>
<?php endforeach; ?> <?php
endforeach; ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -6,16 +7,15 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom')); HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
// @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since 3.7.0. // @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since 3.7.0.
$function = Factory::getApplication()->input->getCmd('function', 'jEditWeblink_' . (int) $this->item->id); $function = Factory::getApplication()->input->getCmd('function', 'jEditWeblink_' . (int) $this->item->id);
// Function to update input title when changed // Function to update input title when changed
Factory::getDocument()->addScriptDeclaration(' Factory::getDocument()->addScriptDeclaration('
function jEditWeblinkModal() { function jEditWeblinkModal() {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
echo LayoutHelper::render('joomla.edit.associations', $this); echo LayoutHelper::render('joomla.edit.associations', $this);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
echo LayoutHelper::render('joomla.edit.metadata', $this); echo LayoutHelper::render('joomla.edit.metadata', $this);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,21 +8,27 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
$fieldSets = $this->form->getFieldsets('params'); ?> $fieldSets = $this->form->getFieldsets('params'); ?>
<?php foreach ($fieldSets as $name => $fieldSet) : ?> <?php foreach ($fieldSets as $name => $fieldSet) :
?>
<div class="tab-pane" id="params-<?php echo $name; ?>"> <div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) : ?> <?php if (isset($fieldSet->description) && trim($fieldSet->description)) :
?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?> <?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php endif; ?> <?php
<?php foreach ($this->form->getFieldset($name) as $field) : ?> endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) :
?>
<div class="control-group"> <div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div> <div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div> <div class="controls"><?php echo $field->input; ?></div>
</div> </div>
<?php endforeach; ?> <?php
endforeach; ?>
</div> </div>
<?php endforeach; ?> <?php
endforeach; ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
@ -16,20 +18,16 @@ use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\Weblinks\Administrator\View\Weblinks\HtmlView $this */ /** @var \Joomla\Component\Weblinks\Administrator\View\Weblinks\HtmlView $this */
HTMLHelper::_('behavior.multiselect'); HTMLHelper::_('behavior.multiselect');
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
$userId = $user->get('id'); $userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering')); $listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction')); $listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering'; $saveOrder = $listOrder == 'a.ordering';
$assoc = Associations::isEnabled(); $assoc = Associations::isEnabled();
if ($saveOrder && !empty($this->items)) {
if ($saveOrder && !empty($this->items))
{
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component'; $saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable'); HTMLHelper::_('draggablelist.draggable');
} }
@ -42,12 +40,15 @@ if ($saveOrder && !empty($this->items))
// Search tools bar // Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
?> ?>
<?php if (empty($this->items)) : ?> <?php if (empty($this->items)) :
?>
<div class="alert alert-info"> <div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span> <span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?> <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div> </div>
<?php else : ?> <?php
else :
?>
<table class="table" id="weblinkList"> <table class="table" id="weblinkList">
<caption class="visually-hidden"> <caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>, <?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
@ -74,23 +75,30 @@ if ($saveOrder && !empty($this->items))
<th scope="col" class="w-10 d-none d-md-table-cell"> <th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?>
</th> </th>
<?php if ($assoc) : ?> <?php if ($assoc) :
?>
<th scope="col" class="w-10"> <th scope="col" class="w-10">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?>
</th> </th>
<?php endif; ?> <?php
<?php if (Multilanguage::isEnabled()) : ?> endif; ?>
<?php if (Multilanguage::isEnabled()) :
?>
<th scope="col" class="w-10 d-none d-md-table-cell"> <th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?>
</th> </th>
<?php endif; ?> <?php
endif; ?>
<th scope="col" class="w-5 d-none d-md-table-cell"> <th scope="col" class="w-5 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody <?php if ($saveOrder) :?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo strtolower($listDirn); ?>" data-nested="true"<?php endif; ?>> <tbody <?php if ($saveOrder) :
<?php foreach ($this->items as $i => $item) : ?> ?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo strtolower($listDirn); ?>" data-nested="true"<?php
endif; ?>>
<?php foreach ($this->items as $i => $item) :
?>
<?php $item->cat_link = Route::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]=' . $item->catid); ?> <?php $item->cat_link = Route::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]=' . $item->catid); ?>
<?php $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); ?> <?php $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); ?>
<?php $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); ?> <?php $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); ?>
@ -104,37 +112,42 @@ if ($saveOrder && !empty($this->items))
<td class="text-center d-none d-md-table-cell"> <td class="text-center d-none d-md-table-cell">
<?php <?php
$iconClass = ''; $iconClass = '';
if (!$canChange) if (!$canChange) {
{
$iconClass = ' inactive'; $iconClass = ' inactive';
} } elseif (!$saveOrder) {
elseif (!$saveOrder)
{
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED'); $iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
} }
?> ?>
<span class="sortable-handler<?php echo $iconClass; ?>"> <span class="sortable-handler<?php echo $iconClass; ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span> <span class="icon-ellipsis-v" aria-hidden="true"></span>
</span> </span>
<?php if ($canChange && $saveOrder) : ?> <?php if ($canChange && $saveOrder) :
?>
<input type="text" name="order[]" size="5" <input type="text" name="order[]" size="5"
value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden"> value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
<?php endif; ?> <?php
endif; ?>
</td> </td>
<td class="text-center"> <td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?> <?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
</td> </td>
<th scope="row" class="has-context"> <th scope="row" class="has-context">
<div> <div>
<?php if ($item->checked_out) : ?> <?php if ($item->checked_out) :
?>
<?php echo HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?> <?php echo HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?>
<?php endif; ?> <?php
<?php if ($canEdit || $canEditOwn) : ?> endif; ?>
<?php if ($canEdit || $canEditOwn) :
?>
<a href="<?php echo Route::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id); ?>" title="<?php echo Text::_('JACTION_EDIT'); ?> <?php echo $this->escape($item->title); ?>"> <a href="<?php echo Route::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id); ?>" title="<?php echo Text::_('JACTION_EDIT'); ?> <?php echo $this->escape($item->title); ?>">
<?php echo $this->escape($item->title); ?></a> <?php echo $this->escape($item->title); ?></a>
<?php else : ?> <?php
else :
?>
<?php echo $this->escape($item->title); ?> <?php echo $this->escape($item->title); ?>
<?php endif; ?> <?php
endif; ?>
<span class="small"> <span class="small">
<?php echo Text::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?> <?php echo Text::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?>
</span> </span>
@ -149,23 +162,30 @@ if ($saveOrder && !empty($this->items))
<td class="d-none d-md-table-cell"> <td class="d-none d-md-table-cell">
<?php echo $item->hits; ?> <?php echo $item->hits; ?>
</td> </td>
<?php if ($assoc) : ?> <?php if ($assoc) :
?>
<td class="hidden-phone hidden-tablet"> <td class="hidden-phone hidden-tablet">
<?php if ($item->association) : ?> <?php if ($item->association) :
?>
<?php echo HTMLHelper::_('weblinksadministrator.association', $item->id); ?> <?php echo HTMLHelper::_('weblinksadministrator.association', $item->id); ?>
<?php endif; ?> <?php
endif; ?>
</td> </td>
<?php endif; ?> <?php
<?php if (Multilanguage::isEnabled()) : ?> endif; ?>
<?php if (Multilanguage::isEnabled()) :
?>
<td class="small d-none d-md-table-cell"> <td class="small d-none d-md-table-cell">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?> <?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td> </td>
<?php endif; ?> <?php
endif; ?>
<td class="d-none d-md-table-cell"> <td class="d-none d-md-table-cell">
<?php echo (int) $item->id; ?> <?php echo (int) $item->id; ?>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php
endforeach; ?>
</tbody> </tbody>
</table> </table>
@ -173,20 +193,20 @@ if ($saveOrder && !empty($this->items))
<?php echo $this->pagination->getListFooter(); ?> <?php echo $this->pagination->getListFooter(); ?>
<?php // Load the batch processing form. ?> <?php // Load the batch processing form. ?>
<?php if ($user->authorise('core.create', 'com_weblinks') <?php if (
$user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')) : ?> && $user->authorise('core.edit.state', 'com_weblinks')
<?php echo HTMLHelper::_( ) :
'bootstrap.renderModal', ?>
'collapseModal', <?php echo HTMLHelper::_('bootstrap.renderModal', 'collapseModal', [
[
'title' => Text::_('COM_WEBLINKS_BATCH_OPTIONS'), 'title' => Text::_('COM_WEBLINKS_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer') 'footer' => $this->loadTemplate('batch_footer')
], ], $this->loadTemplate('batch_body')); ?>
$this->loadTemplate('batch_body') <?php
); ?> endif; ?>
<?php endif; ?> <?php
<?php endif; ?> endif; ?>
<input type="hidden" name="task" value=""> <input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0"> <input type="hidden" name="boxchecked" value="0">

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -6,23 +7,26 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
$published = $this->state->get('filter.published'); $published = $this->state->get('filter.published');
?> ?>
<div class="p-3"> <div class="p-3">
<div class="row"> <div class="row">
<?php if (Multilanguage::isEnabled()) : ?> <?php if (Multilanguage::isEnabled()) :
?>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<div class="controls"> <div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.language', []); ?> <?php echo LayoutHelper::render('joomla.html.batch.language', []); ?>
</div> </div>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<div class="controls"> <div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.access', []); ?> <?php echo LayoutHelper::render('joomla.html.batch.access', []); ?>
@ -30,13 +34,15 @@ $published = $this->state->get('filter.published');
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<?php if ($published >= 0) : ?> <?php if ($published >= 0) :
?>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<div class="controls"> <div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.item', ['extension' => 'com_weblinks']); ?> <?php echo LayoutHelper::render('joomla.html.batch.item', ['extension' => 'com_weblinks']); ?>
</div> </div>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<div class="controls"> <div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.tag', []); ?> <?php echo LayoutHelper::render('joomla.html.batch.tag', []); ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -6,8 +7,10 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
?> ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,22 +8,19 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
$displayData = [ $displayData = [
'textPrefix' => 'COM_WEBLINKS', 'textPrefix' => 'COM_WEBLINKS',
'formURL' => 'index.php?option=com_weblinks', 'formURL' => 'index.php?option=com_weblinks',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help4.x:Weblinks', 'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help4.x:Weblinks',
'icon' => 'icon-globe weblink', 'icon' => 'icon-globe weblink',
]; ];
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
if ($user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) {
if ($user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{
$displayData['createURL'] = 'index.php?option=com_weblinks&task=weblink.add'; $displayData['createURL'] = 'index.php?option=com_weblinks&task=weblink.add';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Multilanguage;
@ -17,29 +19,22 @@ use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session; use Joomla\CMS\Session\Session;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
$app = Factory::getApplication(); $app = Factory::getApplication();
if ($app->isClient('site')) {
if ($app->isClient('site'))
{
Session::checkToken('get') or die(Text::_('JINVALID_TOKEN')); Session::checkToken('get') or die(Text::_('JINVALID_TOKEN'));
} }
HTMLHelper::_('behavior.multiselect'); HTMLHelper::_('behavior.multiselect');
$this->document->getWebAssetManager() $this->document->getWebAssetManager()
->registerAndUseScript('com_weblinks.admin-weblinks-modal', 'media/com_weblinks/js/admin-weblinks-modal.js', [], ['defer' => true], ['core']); ->registerAndUseScript('com_weblinks.admin-weblinks-modal', 'media/com_weblinks/js/admin-weblinks-modal.js', [], ['defer' => true], ['core']);
$function = $app->input->getCmd('function', 'jSelectWeblink'); $function = $app->input->getCmd('function', 'jSelectWeblink');
$editor = $app->input->getCmd('editor', ''); $editor = $app->input->getCmd('editor', '');
$listOrder = $this->escape($this->state->get('list.ordering')); $listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction')); $listDirn = $this->escape($this->state->get('list.direction'));
$onclick = $this->escape($function); $onclick = $this->escape($function);
$multilang = Multilanguage::isEnabled(); $multilang = Multilanguage::isEnabled();
if (!empty($editor)) {
if (!empty($editor)) // This view is used also in com_menus. Load the xtd script only if the editor is set!
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
$this->document->addScriptOptions('xtd-weblinks', array('editor' => $editor)); $this->document->addScriptOptions('xtd-weblinks', array('editor' => $editor));
$onclick = "jSelectWeblink"; $onclick = "jSelectWeblink";
} }
@ -58,11 +53,14 @@ $iconStates = array(
<?php echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> <?php echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<?php if (empty($this->items)) : ?> <?php if (empty($this->items)) :
?>
<div class="alert alert-no-items"> <div class="alert alert-no-items">
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?> <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div> </div>
<?php else : ?> <?php
else :
?>
<table class="table table-sm"> <table class="table table-sm">
<caption class="visually-hidden"> <caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>, <?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
@ -80,11 +78,13 @@ $iconStates = array(
<th scope="col" class="w-10 d-none d-md-table-cell"> <th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $listDirn, $listOrder); ?>
</th> </th>
<?php if ($multilang) : ?> <?php if ($multilang) :
?>
<th scope="col" class="w-15"> <th scope="col" class="w-15">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language', $listDirn, $listOrder); ?>
</th> </th>
<?php endif; ?> <?php
endif; ?>
<th scope="col" class="w-10 d-none d-md-table-cell"> <th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JDATE', 'a.created', $listDirn, $listOrder); ?> <?php echo HTMLHelper::_('searchtools.sort', 'JDATE', 'a.created', $listDirn, $listOrder); ?>
</th> </th>
@ -94,16 +94,23 @@ $iconStates = array(
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($this->items as $i => $item) : ?> <?php foreach ($this->items as $i => $item) :
?>
<?php $lang = ''; ?> <?php $lang = ''; ?>
<?php if ($item->language && $multilang) : ?> <?php if ($item->language && $multilang) :
?>
<?php $tag = strlen($item->language); ?> <?php $tag = strlen($item->language); ?>
<?php if ($tag == 5) : ?> <?php if ($tag == 5) :
?>
<?php $lang = substr($item->language, 0, 2); ?> <?php $lang = substr($item->language, 0, 2); ?>
<?php elseif ($tag == 6) : ?> <?php
elseif ($tag == 6) :
?>
<?php $lang = substr($item->language, 0, 3); ?> <?php $lang = substr($item->language, 0, 3); ?>
<?php endif; ?> <?php
<?php endif; ?> endif; ?>
<?php
endif; ?>
<tr class="row<?php echo $i % 2; ?>"> <tr class="row<?php echo $i % 2; ?>">
<td class="center"> <td class="center">
<span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span> <span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span>
@ -126,11 +133,13 @@ $iconStates = array(
<td class="small d-none d-md-table-cell"> <td class="small d-none d-md-table-cell">
<?php echo $this->escape($item->access_level); ?> <?php echo $this->escape($item->access_level); ?>
</td> </td>
<?php if ($multilang) : ?> <?php if ($multilang) :
?>
<td class="small"> <td class="small">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?> <?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td> </td>
<?php endif; ?> <?php
endif; ?>
<td class="small d-none d-md-table-cell"> <td class="small d-none d-md-table-cell">
<?php echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC4')); ?> <?php echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC4')); ?>
</td> </td>
@ -138,10 +147,12 @@ $iconStates = array(
<?php echo (int) $item->id; ?> <?php echo (int) $item->id; ?>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php
endforeach; ?>
</tbody> </tbody>
</table> </table>
<?php endif; ?> <?php
endif; ?>
<?php // load the pagination. ?> <?php // load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?> <?php echo $this->pagination->getListFooter(); ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Installation class to perform additional changes during install/uninstall/update * Installation class to perform additional changes during install/uninstall/update
* *

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblink Component HTML Helper. * Weblink Component HTML Helper.
* *
@ -38,7 +40,7 @@ class JHtmlIcon
* *
* @return string * @return string
*/ */
public static function edit($weblink, $params, $attribs = array()) public static function edit($weblink, $params, $attribs = [])
{ {
return self::getIcon()->edit($weblink, $params, $attribs); return self::getIcon()->edit($weblink, $params, $attribs);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
/** /**
@ -18,5 +20,4 @@ use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
*/ */
abstract class WeblinksHelperRoute extends RouteHelper abstract class WeblinksHelperRoute extends RouteHelper
{ {
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Controller; namespace Joomla\Component\Weblinks\Site\Controller;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\MVC\Controller\BaseController;
@ -36,7 +38,6 @@ class DisplayController extends BaseController
{ {
// Huh? Why not just put that in the constructor? // Huh? Why not just put that in the constructor?
$cacheable = true; $cacheable = true;
/** /**
* Set the default view name and format from the Request. * Set the default view name and format from the Request.
* Note we are using w_id to avoid collisions with the router and the return page. * Note we are using w_id to avoid collisions with the router and the return page.
@ -45,24 +46,20 @@ class DisplayController extends BaseController
$id = $this->input->getInt('w_id'); $id = $this->input->getInt('w_id');
$vName = $this->input->get('view', 'categories'); $vName = $this->input->get('view', 'categories');
$this->input->set('view', $vName); $this->input->set('view', $vName);
if ($this->app->getIdentity()->id || ($this->input->getMethod() == 'POST' && $vName == 'categories')) {
if ($this->app->getIdentity()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories'))
{
$cacheable = false; $cacheable = false;
} }
$safeurlparams = array( $safeurlparams = [
'id' => 'INT', 'id' => 'INT',
'limit' => 'UINT', 'limit' => 'UINT',
'limitstart' => 'UINT', 'limitstart' => 'UINT',
'filter_order' => 'CMD', 'filter_order' => 'CMD',
'filter_order_Dir' => 'CMD', 'filter_order_Dir' => 'CMD',
'lang' => 'CMD' 'lang' => 'CMD',
); ];
// Check for edit form. // Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) {
{
// Somehow the person just went to the form - we don't allow that. // Somehow the person just went to the form - we don't allow that.
throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403); throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Controller; namespace Joomla\Component\Weblinks\Site\Controller;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Uri\Uri; use Joomla\CMS\Uri\Uri;
@ -30,7 +32,6 @@ class WeblinkController extends FormController
* @since 1.6 * @since 1.6
*/ */
protected $view_item = 'form'; protected $view_item = 'form';
/** /**
* The URL view list variable. * The URL view list variable.
* *
@ -38,7 +39,6 @@ class WeblinkController extends FormController
* @since 1.6 * @since 1.6
*/ */
protected $view_list = 'categories'; protected $view_list = 'categories';
/** /**
* The URL edit variable. * The URL edit variable.
* *
@ -46,7 +46,6 @@ class WeblinkController extends FormController
* @since 3.2 * @since 3.2
*/ */
protected $urlVar = 'a.id'; protected $urlVar = 'a.id';
/** /**
* Method to add a new record. * Method to add a new record.
* *
@ -56,11 +55,9 @@ class WeblinkController extends FormController
*/ */
public function add() public function add()
{ {
if (!parent::add()) if (!parent::add()) {
{
// Redirect to the return page. // Redirect to the return page.
$this->setRedirect($this->getReturnPage()); $this->setRedirect($this->getReturnPage());
return false; return false;
} }
@ -76,12 +73,10 @@ class WeblinkController extends FormController
* *
* @since 1.6 * @since 1.6
*/ */
protected function allowAdd($data = array()) protected function allowAdd($data = [])
{ {
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int'); $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int');
if ($categoryId) {
if ($categoryId)
{
// If the category has been passed in the URL check it. // If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId); return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
} }
@ -100,32 +95,25 @@ class WeblinkController extends FormController
* *
* @since 1.6 * @since 1.6
*/ */
protected function allowEdit($data = array(), $key = 'id') protected function allowEdit($data = [], $key = 'id')
{ {
$recordId = (int) isset($data[$key]) ? $data[$key] : 0; $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
if (!$recordId) {
if (!$recordId)
{
return false; return false;
} }
$record = $this->getModel()->getItem($recordId); $record = $this->getModel()->getItem($recordId);
$categoryId = (int) $record->catid; $categoryId = (int) $record->catid;
if ($categoryId) {
if ($categoryId)
{
// The category has been set. Check the category permissions. // The category has been set. Check the category permissions.
$user = $this->app->getIdentity(); $user = $this->app->getIdentity();
// First, check edit permission // First, check edit permission
if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId)) if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId)) {
{
return true; return true;
} }
// Fallback on edit.own // Fallback on edit.own
if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId) && $record->created_by == $user->id) if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId) && $record->created_by == $user->id) {
{
return true; return true;
} }
@ -148,10 +136,8 @@ class WeblinkController extends FormController
public function cancel($key = 'w_id') public function cancel($key = 'w_id')
{ {
$return = parent::cancel($key); $return = parent::cancel($key);
// Redirect to the return page. // Redirect to the return page.
$this->setRedirect($this->getReturnPage()); $this->setRedirect($this->getReturnPage());
return $return; return $return;
} }
@ -181,7 +167,7 @@ class WeblinkController extends FormController
* *
* @since 1.5 * @since 1.5
*/ */
public function getModel($name = 'form', $prefix = 'Site', $config = array('ignore_request' => true)) public function getModel($name = 'form', $prefix = 'Site', $config = ['ignore_request' => true])
{ {
return parent::getModel($name, $prefix, $config); return parent::getModel($name, $prefix, $config);
} }
@ -201,14 +187,11 @@ class WeblinkController extends FormController
$append = parent::getRedirectToItemAppend($recordId, $urlVar); $append = parent::getRedirectToItemAppend($recordId, $urlVar);
$itemId = $this->input->getInt('Itemid'); $itemId = $this->input->getInt('Itemid');
$return = $this->getReturnPage(); $return = $this->getReturnPage();
if ($itemId) {
if ($itemId)
{
$append .= '&Itemid=' . $itemId; $append .= '&Itemid=' . $itemId;
} }
if ($return) if ($return) {
{
$append .= '&return=' . base64_encode($return); $append .= '&return=' . base64_encode($return);
} }
@ -225,9 +208,7 @@ class WeblinkController extends FormController
protected function getReturnPage() protected function getReturnPage()
{ {
$return = $this->input->get('return', null, 'base64'); $return = $this->input->get('return', null, 'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
if (empty($return) || !Uri::isInternal(base64_decode($return)))
{
return Uri::base(); return Uri::base();
} }
@ -248,17 +229,13 @@ class WeblinkController extends FormController
{ {
// Get the application // Get the application
$app = $this->app; $app = $this->app;
// Get the data from POST // Get the data from POST
$data = $this->input->post->get('jform', array(), 'array'); $data = $this->input->post->get('jform', [], 'array');
// Save the data in the session. // Save the data in the session.
$app->setUserState('com_weblinks.edit.weblink.data', $data); $app->setUserState('com_weblinks.edit.weblink.data', $data);
$result = parent::save($key, $urlVar); $result = parent::save($key, $urlVar);
// If ok, redirect to the return page. // If ok, redirect to the return page.
if ($result) if ($result) {
{
// Flush the data from the session // Flush the data from the session
$app->setUserState('com_weblinks.edit.weblink.data', null); $app->setUserState('com_weblinks.edit.weblink.data', null);
$this->setRedirect($this->getReturnPage()); $this->setRedirect($this->getReturnPage());
@ -280,50 +257,39 @@ class WeblinkController extends FormController
{ {
// Get the ID from the request // Get the ID from the request
$id = $this->input->getInt('id'); $id = $this->input->getInt('id');
// Get the model, requiring published items // Get the model, requiring published items
$modelLink = $this->getModel('Weblink'); $modelLink = $this->getModel('Weblink');
$modelLink->setState('filter.published', 1); $modelLink->setState('filter.published', 1);
// Get the item // Get the item
$link = $modelLink->getItem($id); $link = $modelLink->getItem($id);
// Make sure the item was found. // Make sure the item was found.
if (empty($link)) if (empty($link)) {
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check whether item access level allows access. // Check whether item access level allows access.
$groups = $this->app->getIdentity()->getAuthorisedViewLevels(); $groups = $this->app->getIdentity()->getAuthorisedViewLevels();
if (!in_array($link->access, $groups)) {
if (!in_array($link->access, $groups))
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
} }
// Check whether category access level allows access. // Check whether category access level allows access.
$modelCat = $this->getModel('Category', 'Site', array('ignore_request' => true)); $modelCat = $this->getModel('Category', 'Site', ['ignore_request' => true]);
$modelCat->setState('filter.published', 1); $modelCat->setState('filter.published', 1);
// Get the category // Get the category
$category = $modelCat->getCategory($link->catid); $category = $modelCat->getCategory($link->catid);
// Make sure the category was found. // Make sure the category was found.
if (empty($category)) if (empty($category)) {
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check whether item access level allows access. // Check whether item access level allows access.
if (!in_array($category->access, $groups)) if (!in_array($category->access, $groups)) {
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
} }
// Redirect to the URL // Redirect to the URL
if ($link->url) if ($link->url) {
{
$modelLink->hit($id); $modelLink->hit($id);
$this->app->redirect($link->url, 301); $this->app->redirect($link->url, 301);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Helper; namespace Joomla\Component\Weblinks\Site\Helper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper; use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
@ -37,17 +39,11 @@ abstract class AssociationHelper extends CategoryAssociationHelper
$input = Factory::getApplication()->input; $input = Factory::getApplication()->input;
$view = is_null($view) ? $input->get('view') : $view; $view = is_null($view) ? $input->get('view') : $view;
$id = empty($id) ? $input->getInt('id') : $id; $id = empty($id) ? $input->getInt('id') : $id;
if ($view === 'weblink') {
if ($view === 'weblink') if ($id) {
{
if ($id)
{
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id); $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id);
$return = [];
$return = array(); foreach ($associations as $tag => $item) {
foreach ($associations as $tag => $item)
{
$return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language); $return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language);
} }
@ -55,11 +51,10 @@ abstract class AssociationHelper extends CategoryAssociationHelper
} }
} }
if ($view == 'category' || $view == 'categories') if ($view == 'category' || $view == 'categories') {
{
return self::getCategoryAssociations($id, 'com_weblinks'); return self::getCategoryAssociations($id, 'com_weblinks');
} }
return array(); return [];
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -12,8 +13,9 @@ namespace Joomla\Component\Weblinks\Site\Helper;
use Joomla\CMS\Categories\CategoryNode; use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Multilanguage;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblinks Component Route Helper. * Weblinks Component Route Helper.
* *
@ -34,14 +36,11 @@ abstract class RouteHelper
{ {
// Create the link // Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id=' . $id; $link = 'index.php?option=com_weblinks&view=weblink&id=' . $id;
if ($catid > 1) {
if ($catid > 1)
{
$link .= '&catid=' . $catid; $link .= '&catid=' . $catid;
} }
if ($language && $language !== '*' && Multilanguage::isEnabled()) if ($language && $language !== '*' && Multilanguage::isEnabled()) {
{
$link .= '&lang=' . $language; $link .= '&lang=' . $language;
} }
@ -59,17 +58,13 @@ abstract class RouteHelper
public static function getFormRoute($id, $return = null) public static function getFormRoute($id, $return = null)
{ {
// Create the link. // Create the link.
if ($id) if ($id) {
{
$link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id; $link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id;
} } else {
else
{
$link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0'; $link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0';
} }
if ($return) if ($return) {
{
$link .= '&return=' . $return; $link .= '&return=' . $return;
} }
@ -86,26 +81,18 @@ abstract class RouteHelper
*/ */
public static function getCategoryRoute($catid, $language = 0) public static function getCategoryRoute($catid, $language = 0)
{ {
if ($catid instanceof CategoryNode) if ($catid instanceof CategoryNode) {
{
$id = $catid->id; $id = $catid->id;
} } else {
else
{
$id = (int) $catid; $id = (int) $catid;
} }
if ($id < 1) if ($id < 1) {
{
$link = ''; $link = '';
} } else {
else
{
// Create the link // Create the link
$link = 'index.php?option=com_weblinks&view=category&id=' . $id; $link = 'index.php?option=com_weblinks&view=category&id=' . $id;
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
if ($language && $language !== '*' && Multilanguage::isEnabled())
{
$link .= '&lang=' . $language; $link .= '&lang=' . $language;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -15,8 +16,9 @@ use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* This models supports retrieving lists of article categories. * This models supports retrieving lists of article categories.
* *
@ -31,28 +33,24 @@ class CategoriesModel extends ListModel
* @var string * @var string
*/ */
protected $context = 'com_weblinks.categories'; protected $context = 'com_weblinks.categories';
/** /**
* The category context (allows other extensions to derived from this model). * The category context (allows other extensions to derived from this model).
* *
* @var string * @var string
*/ */
protected $_extension = 'com_weblinks'; protected $_extension = 'com_weblinks';
/** /**
* Parent category * Parent category
* *
* @var CategoryNode|null * @var CategoryNode|null
*/ */
private $_parent = null; private $_parent = null;
/** /**
* Categories data * Categories data
* *
* @var false|array * @var false|array
*/ */
private $_items = null; private $_items = null;
/** /**
* Method to auto-populate the model state. * Method to auto-populate the model state.
* *
@ -69,14 +67,11 @@ class CategoriesModel extends ListModel
{ {
$app = Factory::getApplication(); $app = Factory::getApplication();
$this->setState('filter.extension', $this->_extension); $this->setState('filter.extension', $this->_extension);
// Get the parent id if defined. // Get the parent id if defined.
$parentId = $app->input->getInt('id'); $parentId = $app->input->getInt('id');
$this->setState('filter.parentId', $parentId); $this->setState('filter.parentId', $parentId);
$params = $app->getParams(); $params = $app->getParams();
$this->setState('params', $params); $this->setState('params', $params);
$this->setState('filter.published', 1); $this->setState('filter.published', 1);
$this->setState('filter.access', true); $this->setState('filter.access', true);
} }
@ -99,7 +94,6 @@ class CategoriesModel extends ListModel
$id .= ':' . $this->getState('filter.published'); $id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.access'); $id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.parentId'); $id .= ':' . $this->getState('filter.parentId');
return parent::getStoreId($id); return parent::getStoreId($id);
} }
@ -110,23 +104,17 @@ class CategoriesModel extends ListModel
*/ */
public function getItems() public function getItems()
{ {
if ($this->_items === null) if ($this->_items === null) {
{ $params = $this->getState('params', new Registry());
$params = $this->getState('params', new Registry); $options = [];
$options = array();
$options['access'] = $this->getState('filter.access'); $options['access'] = $this->getState('filter.access');
$options['published'] = $this->getState('filter.published'); $options['published'] = $this->getState('filter.published');
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0); $options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = Categories::getInstance('Weblinks', $options); $categories = Categories::getInstance('Weblinks', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root')); $this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (is_object($this->_parent)) {
if (is_object($this->_parent))
{
$this->_items = $this->_parent->getChildren(); $this->_items = $this->_parent->getChildren();
} } else {
else
{
$this->_items = false; $this->_items = false;
} }
} }
@ -141,8 +129,7 @@ class CategoriesModel extends ListModel
*/ */
public function getParent() public function getParent()
{ {
if (!is_object($this->_parent)) if (!is_object($this->_parent)) {
{
$this->getItems(); $this->getItems();
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Model; namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Categories\Categories; use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryNode; use Joomla\CMS\Categories\CategoryNode;
@ -71,16 +74,15 @@ class CategoryModel extends ListModel
* @see JControllerLegacy * @see JControllerLegacy
* @since 1.6 * @since 1.6
*/ */
public function __construct($config = array()) public function __construct($config = [])
{ {
if (empty($config['filter_fields'])) if (empty($config['filter_fields'])) {
{ $config['filter_fields'] = [
$config['filter_fields'] = array(
'id', 'a.id', 'id', 'a.id',
'title', 'a.title', 'title', 'a.title',
'hits', 'a.hits', 'hits', 'a.hits',
'ordering', 'a.ordering', 'ordering', 'a.ordering',
); ];
} }
parent::__construct($config); parent::__construct($config);
@ -100,29 +102,24 @@ class CategoryModel extends ListModel
$taggedItems = []; $taggedItems = [];
// Convert the params field into an object, saving original in _params // Convert the params field into an object, saving original in _params
foreach ($items as $item) foreach ($items as $item) {
{ if (!isset($this->_params)) {
if (!isset($this->_params))
{
$item->params = new Registry($item->params); $item->params = new Registry($item->params);
} }
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data // Some contexts may not use tags data at all, so we allow callers to disable loading tag data
if ($this->getState('load_tags', true)) if ($this->getState('load_tags', true)) {
{ $item->tags = new TagsHelper();
$item->tags = new TagsHelper;
$taggedItems[$item->id] = $item; $taggedItems[$item->id] = $item;
} }
} }
// Load tags of all items. // Load tags of all items.
if ($taggedItems) if ($taggedItems) {
{
$tagsHelper = new TagsHelper(); $tagsHelper = new TagsHelper();
$itemIds = \array_keys($taggedItems); $itemIds = \array_keys($taggedItems);
foreach ($tagsHelper->getMultipleItemTags('com_weblinks.weblink', $itemIds) as $id => $tags) foreach ($tagsHelper->getMultipleItemTags('com_weblinks.weblink', $itemIds) as $id => $tags) {
{
$taggedItems[$id]->tags->itemTags = $tags; $taggedItems[$id]->tags->itemTags = $tags;
} }
} }
@ -151,19 +148,15 @@ class CategoryModel extends ListModel
->whereIn($db->quoteName('a.access'), $viewLevels); ->whereIn($db->quoteName('a.access'), $viewLevels);
// Filter by category. // Filter by category.
if ($categoryId = $this->getState('category.id')) if ($categoryId = $this->getState('category.id')) {
{
// Group by subcategory // Group by subcategory
if ($this->getState('category.group', 0)) if ($this->getState('category.group', 0)) {
{
$query->select('c.title AS category_title') $query->select('c.title AS category_title')
->where('c.parent_id = :parent_id') ->where('c.parent_id = :parent_id')
->bind(':parent_id', $categoryId, ParameterType::INTEGER) ->bind(':parent_id', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid') ->join('LEFT', '#__categories AS c ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $viewLevels); ->whereIn($db->quoteName('c.access'), $viewLevels);
} } else {
else
{
$query->where('a.catid = :catid') $query->where('a.catid = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER) ->bind(':catid', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid') ->join('LEFT', '#__categories AS c ON c.id = a.catid')
@ -173,8 +166,7 @@ class CategoryModel extends ListModel
// Filter by published category // Filter by published category
$cpublished = $this->getState('filter.c.published'); $cpublished = $this->getState('filter.c.published');
if (is_numeric($cpublished)) if (is_numeric($cpublished)) {
{
$query->where('c.published = :published') $query->where('c.published = :published')
->bind(':published', $cpublished, ParameterType::INTEGER); ->bind(':published', $cpublished, ParameterType::INTEGER);
} }
@ -189,8 +181,7 @@ class CategoryModel extends ListModel
// Filter by state // Filter by state
$state = $this->getState('filter.state'); $state = $this->getState('filter.state');
if (is_numeric($state)) if (is_numeric($state)) {
{
$query->where('a.state = :state') $query->where('a.state = :state')
->bind(':state', $state, ParameterType::INTEGER); ->bind(':state', $state, ParameterType::INTEGER);
} }
@ -199,38 +190,32 @@ class CategoryModel extends ListModel
$query->where('a.state != -2'); $query->where('a.state != -2');
// Filter by start and end dates. // Filter by start and end dates.
if ($this->getState('filter.publish_date')) if ($this->getState('filter.publish_date')) {
{
$nowDate = Factory::getDate()->toSql(); $nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up') $query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)' . ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
)
->where('(' . $db->quoteName('a.publish_down') ->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)' . ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
)
->bind(':publish_up', $nowDate) ->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate); ->bind(':publish_down', $nowDate);
} }
// Filter by language // Filter by language
if ($this->getState('filter.language')) if ($this->getState('filter.language')) {
{
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING); $query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
} }
// Filter by search in title // Filter by search in title
$search = $this->getState('list.filter'); $search = $this->getState('list.filter');
if (!empty($search)) if (!empty($search)) {
{
$search = '%' . trim($search) . '%'; $search = '%' . trim($search) . '%';
$query->where('(a.title LIKE :search)') $query->where('(a.title LIKE :search)')
->bind(':search', $search); ->bind(':search', $search);
} }
// If grouping by subcategory, add the subcategory list ordering clause. // If grouping by subcategory, add the subcategory list ordering clause.
if ($this->getState('category.group', 0)) if ($this->getState('category.group', 0)) {
{
$query->order( $query->order(
$db->escape($this->getState('category.ordering', 'c.lft')) . ' ' . $db->escape($this->getState('category.ordering', 'c.lft')) . ' ' .
$db->escape($this->getState('category.direction', 'ASC')) $db->escape($this->getState('category.direction', 'ASC'))
@ -277,8 +262,7 @@ class CategoryModel extends ListModel
$orderCol = $app->input->get('filter_order', 'ordering'); $orderCol = $app->input->get('filter_order', 'ordering');
if (!in_array($orderCol, $this->filter_fields)) if (!in_array($orderCol, $this->filter_fields)) {
{
$orderCol = 'ordering'; $orderCol = 'ordering';
} }
@ -286,8 +270,7 @@ class CategoryModel extends ListModel
$listOrder = $app->input->get('filter_order_Dir', 'ASC'); $listOrder = $app->input->get('filter_order_Dir', 'ASC');
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) if (!in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
{
$listOrder = 'ASC'; $listOrder = 'ASC';
} }
@ -298,8 +281,7 @@ class CategoryModel extends ListModel
$user = $this->getCurrentUser(); $user = $this->getCurrentUser();
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) {
{
// Limit to published for people who can't edit or edit.state. // Limit to published for people who can't edit or edit.state.
$this->setState('filter.state', 1); $this->setState('filter.state', 1);
@ -319,32 +301,27 @@ class CategoryModel extends ListModel
*/ */
public function getCategory() public function getCategory()
{ {
if (!is_object($this->_item)) if (!is_object($this->_item)) {
{ $params = $this->getState('params', new Registry());
$params = $this->getState('params', new Registry);
$options = array(); $options = [];
$options['countItems'] = $params->get('show_cat_num_links_cat', 1) $options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0); || $params->get('show_empty_categories', 0);
$categories = Categories::getInstance('Weblinks', $options); $categories = Categories::getInstance('Weblinks', $options);
$this->_item = $categories->get($this->getState('category.id', 'root')); $this->_item = $categories->get($this->getState('category.id', 'root'));
if (is_object($this->_item)) if (is_object($this->_item)) {
{
$this->_children = $this->_item->getChildren(); $this->_children = $this->_item->getChildren();
$this->_parent = false; $this->_parent = false;
if ($this->_item->getParent()) if ($this->_item->getParent()) {
{
$this->_parent = $this->_item->getParent(); $this->_parent = $this->_item->getParent();
} }
$this->_rightsibling = $this->_item->getSibling(); $this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling = $this->_item->getSibling(false); $this->_leftsibling = $this->_item->getSibling(false);
} } else {
else
{
$this->_children = false; $this->_children = false;
$this->_parent = false; $this->_parent = false;
} }
@ -360,8 +337,7 @@ class CategoryModel extends ListModel
*/ */
public function getParent() public function getParent()
{ {
if (!is_object($this->_item)) if (!is_object($this->_item)) {
{
$this->getCategory(); $this->getCategory();
} }
@ -375,8 +351,7 @@ class CategoryModel extends ListModel
*/ */
public function &getLeftSibling() public function &getLeftSibling()
{ {
if (!is_object($this->_item)) if (!is_object($this->_item)) {
{
$this->getCategory(); $this->getCategory();
} }
@ -390,8 +365,7 @@ class CategoryModel extends ListModel
*/ */
public function &getRightSibling() public function &getRightSibling()
{ {
if (!is_object($this->_item)) if (!is_object($this->_item)) {
{
$this->getCategory(); $this->getCategory();
} }
@ -405,8 +379,7 @@ class CategoryModel extends ListModel
*/ */
public function &getChildren() public function &getChildren()
{ {
if (!is_object($this->_item)) if (!is_object($this->_item)) {
{
$this->getCategory(); $this->getCategory();
} }
@ -426,8 +399,7 @@ class CategoryModel extends ListModel
{ {
$hitcount = Factory::getApplication()->input->getInt('hitcount', 1); $hitcount = Factory::getApplication()->input->getInt('hitcount', 1);
if ($hitcount) if ($hitcount) {
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id'); $pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\'); $table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
$table->load($pk); $table->load($pk);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Model; namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
@ -68,8 +71,7 @@ class FormModel extends WeblinkModel
$return = $app->input->get('return', '', 'base64'); $return = $app->input->get('return', '', 'base64');
if ($return && !Uri::isInternal(base64_decode($return))) if ($return && !Uri::isInternal(base64_decode($return))) {
{
$return = ''; $return = '';
} }
@ -92,13 +94,12 @@ class FormModel extends WeblinkModel
* *
* @since __DEPLOY_VERSION__ * @since __DEPLOY_VERSION__
*/ */
public function getForm($data = array(), $loadData = true) public function getForm($data = [], $loadData = true)
{ {
$form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData)); $form = $this->loadForm('com_weblinks.form', 'weblink', ['control' => 'jform', 'load_data' => $loadData]);
// Disable the buttons and just allow editor none for not authenticated users // Disable the buttons and just allow editor none for not authenticated users
if ($this->getCurrentUser()->guest) if ($this->getCurrentUser()->guest) {
{
$form->setFieldAttribute('description', 'editor', 'none'); $form->setFieldAttribute('description', 'editor', 'none');
$form->setFieldAttribute('description', 'buttons', 'no'); $form->setFieldAttribute('description', 'buttons', 'no');
} }
@ -118,7 +119,7 @@ class FormModel extends WeblinkModel
* @since 4.0.0 * @since 4.0.0
* @throws \Exception * @throws \Exception
*/ */
public function getTable($name = 'Weblink', $prefix = 'Administrator', $options = array()) public function getTable($name = 'Weblink', $prefix = 'Administrator', $options = [])
{ {
return parent::getTable($name, $prefix, $options); return parent::getTable($name, $prefix, $options);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Model; namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper; use Joomla\CMS\Helper\TagsHelper;
@ -65,8 +68,7 @@ class WeblinkModel extends ItemModel
$user = $this->getCurrentUser(); $user = $this->getCurrentUser();
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) {
{
$this->setState('filter.published', 1); $this->setState('filter.published', 1);
$this->setState('filter.archived', 2); $this->setState('filter.archived', 2);
} }
@ -87,15 +89,12 @@ class WeblinkModel extends ItemModel
$pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id'); $pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id');
if ($this->_item === null) if ($this->_item === null) {
{ $this->_item = [];
$this->_item = array();
} }
if (!isset($this->_item[$pk])) if (!isset($this->_item[$pk])) {
{ try {
try
{
$db = $this->getDatabase(); $db = $this->getDatabase();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select($this->getState('item.select', 'a.*')) ->select($this->getState('item.select', 'a.*'))
@ -113,8 +112,7 @@ class WeblinkModel extends ItemModel
->join('LEFT', '#__users AS u on u.id = a.created_by'); ->join('LEFT', '#__users AS u on u.id = a.created_by');
// Filter by language // Filter by language
if ($this->getState('filter.language')) if ($this->getState('filter.language')) {
{
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING); $query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
} }
@ -122,16 +120,13 @@ class WeblinkModel extends ItemModel
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias') $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias')
->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); ->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) {
{
// Filter by start and end dates. // Filter by start and end dates.
$nowDate = Factory::getDate()->toSql(); $nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up') $query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)' . ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
)
->where('(' . $db->quoteName('a.publish_down') ->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)' . ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
)
->bind(':publish_up', $nowDate) ->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate); ->bind(':publish_down', $nowDate);
} }
@ -140,8 +135,7 @@ class WeblinkModel extends ItemModel
$published = $this->getState('filter.published'); $published = $this->getState('filter.published');
$archived = $this->getState('filter.archived'); $archived = $this->getState('filter.archived');
if (is_numeric($published)) if (is_numeric($published)) {
{
$query->whereIn($db->quoteName('a.state'), [$published, $archived]); $query->whereIn($db->quoteName('a.state'), [$published, $archived]);
} }
@ -149,14 +143,12 @@ class WeblinkModel extends ItemModel
$data = $db->loadObject(); $data = $db->loadObject();
if (empty($data)) if (empty($data)) {
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check for published state if filter set. // Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived))) if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived))) {
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
@ -165,29 +157,23 @@ class WeblinkModel extends ItemModel
$data->metadata = new Registry($data->metadata); $data->metadata = new Registry($data->metadata);
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data // Some contexts may not use tags data at all, so we allow callers to disable loading tag data
if ($this->getState('load_tags', true)) if ($this->getState('load_tags', true)) {
{ $data->tags = new TagsHelper();
$data->tags = new TagsHelper;
$data->tags->getItemTags('com_weblinks.weblink', $data->id); $data->tags->getItemTags('com_weblinks.weblink', $data->id);
} }
// Compute access permissions. // Compute access permissions.
if ($access = $this->getState('filter.access')) if ($access = $this->getState('filter.access')) {
{
// If the access filter has been set, we already know this user can view. // If the access filter has been set, we already know this user can view.
$data->params->set('access-view', true); $data->params->set('access-view', true);
} } else {
else
{
// If no access filter is set, the layout takes some responsibility for display of limited information. // If no access filter is set, the layout takes some responsibility for display of limited information.
$groups = $user->getAuthorisedViewLevels(); $groups = $user->getAuthorisedViewLevels();
$data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups));
} }
$this->_item[$pk] = $data; $this->_item[$pk] = $data;
} } catch (\Exception $e) {
catch (\Exception $e)
{
$this->setError($e); $this->setError($e);
$this->_item[$pk] = false; $this->_item[$pk] = false;
} }
@ -207,7 +193,7 @@ class WeblinkModel extends ItemModel
* *
* @since 1.6 * @since 1.6
*/ */
public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = array()) public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = [])
{ {
return parent::getTable($type, $prefix, $config); return parent::getTable($type, $prefix, $config);
} }
@ -221,8 +207,7 @@ class WeblinkModel extends ItemModel
*/ */
public function hit($pk = null) public function hit($pk = null)
{ {
if (empty($pk)) if (empty($pk)) {
{
$pk = $this->getState('weblink.id'); $pk = $this->getState('weblink.id');
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Service; namespace Joomla\Component\Weblinks\Site\Service;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Categories\Categories; use Joomla\CMS\Categories\Categories;
/** /**
@ -27,11 +29,10 @@ class Category extends Categories
* *
* @since 1.7.0 * @since 1.7.0
*/ */
public function __construct($options = array()) public function __construct($options = [])
{ {
$options['table'] = '#__weblinks'; $options['table'] = '#__weblinks';
$options['extension'] = 'com_weblinks'; $options['extension'] = 'com_weblinks';
parent::__construct($options); parent::__construct($options);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Service; namespace Joomla\Component\Weblinks\Site\Service;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\SiteApplication; use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Categories\CategoryFactoryInterface; use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Categories\CategoryInterface; use Joomla\CMS\Categories\CategoryInterface;
@ -37,7 +39,6 @@ class Router extends RouterView
* @var boolean * @var boolean
*/ */
protected $noIDs = false; protected $noIDs = false;
/** /**
* The category factory * The category factory
* *
@ -46,7 +47,6 @@ class Router extends RouterView
* @since 4.0.0 * @since 4.0.0
*/ */
private $categoryFactory; private $categoryFactory;
/** /**
* The category cache * The category cache
* *
@ -55,7 +55,6 @@ class Router extends RouterView
* @since 4.0.0 * @since 4.0.0
*/ */
private $categoryCache = []; private $categoryCache = [];
/** /**
* The db * The db
* *
@ -64,7 +63,6 @@ class Router extends RouterView
* @since 4.0.0 * @since 4.0.0
*/ */
private $db; private $db;
/** /**
* Weblinks Component router constructor * Weblinks Component router constructor
* *
@ -77,7 +75,6 @@ class Router extends RouterView
{ {
$this->categoryFactory = $categoryFactory; $this->categoryFactory = $categoryFactory;
$this->db = $db; $this->db = $db;
$params = ComponentHelper::getParams('com_weblinks'); $params = ComponentHelper::getParams('com_weblinks');
$this->noIDs = (bool) $params->get('sef_ids'); $this->noIDs = (bool) $params->get('sef_ids');
$categories = new RouterViewConfiguration('categories'); $categories = new RouterViewConfiguration('categories');
@ -92,9 +89,7 @@ class Router extends RouterView
$form = new RouterViewConfiguration('form'); $form = new RouterViewConfiguration('form');
$form->setKey('w_id'); $form->setKey('w_id');
$this->registerView($form); $this->registerView($form);
parent::__construct($app, $menu); parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this)); $this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this)); $this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this)); $this->attachRule(new NomenuRules($this));
@ -111,16 +106,11 @@ class Router extends RouterView
public function getCategorySegment($id, $query) public function getCategorySegment($id, $query)
{ {
$category = $this->getCategories()->get($id); $category = $this->getCategories()->get($id);
if ($category) {
if ($category)
{
$path = array_reverse($category->getPath(), true); $path = array_reverse($category->getPath(), true);
$path[0] = '1:root'; $path[0] = '1:root';
if ($this->noIDs) {
if ($this->noIDs) foreach ($path as &$segment) {
{
foreach ($path as &$segment)
{
list($id, $segment) = explode(':', $segment, 2); list($id, $segment) = explode(':', $segment, 2);
} }
} }
@ -128,7 +118,7 @@ class Router extends RouterView
return $path; return $path;
} }
return array(); return [];
} }
/** /**
@ -154,8 +144,7 @@ class Router extends RouterView
*/ */
public function getWeblinkSegment($id, $query) public function getWeblinkSegment($id, $query)
{ {
if (!strpos($id, ':')) if (!strpos($id, ':')) {
{
$id = (int) $id; $id = (int) $id;
$dbquery = $this->db->getQuery(true); $dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('alias')) $dbquery->select($this->db->quoteName('alias'))
@ -163,18 +152,15 @@ class Router extends RouterView
->where($this->db->quoteName('id') . ' = :id') ->where($this->db->quoteName('id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER); ->bind(':id', $id, ParameterType::INTEGER);
$this->db->setQuery($dbquery); $this->db->setQuery($dbquery);
$id .= ':' . $this->db->loadResult(); $id .= ':' . $this->db->loadResult();
} }
if ($this->noIDs) if ($this->noIDs) {
{
list($void, $segment) = explode(':', $id, 2); list($void, $segment) = explode(':', $id, 2);
return [$void => $segment];
return array($void => $segment);
} }
return array((int) $id => $id); return [(int) $id => $id];
} }
/** /**
@ -202,25 +188,16 @@ class Router extends RouterView
*/ */
public function getCategoryId($segment, $query) public function getCategoryId($segment, $query)
{ {
if (isset($query['id'])) if (isset($query['id'])) {
{
$category = $this->getCategories(['access' => false])->get($query['id']); $category = $this->getCategories(['access' => false])->get($query['id']);
if ($category) {
if ($category) foreach ($category->getChildren() as $child) {
{ if ($this->noIDs) {
foreach ($category->getChildren() as $child) if ($child->alias == $segment) {
{
if ($this->noIDs)
{
if ($child->alias == $segment)
{
return $child->id; return $child->id;
} }
} } else {
else if ($child->id == (int) $segment) {
{
if ($child->id == (int) $segment)
{
return $child->id; return $child->id;
} }
} }
@ -254,21 +231,17 @@ class Router extends RouterView
*/ */
public function getWeblinkId($segment, $query) public function getWeblinkId($segment, $query)
{ {
if ($this->noIDs) if ($this->noIDs) {
{
$dbquery = $this->db->getQuery(true); $dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('id')) $dbquery->select($this->db->quoteName('id'))
->from($this->db->quoteName('#__weblinks')) ->from($this->db->quoteName('#__weblinks'))
->where( ->where([
[
$this->db->quoteName('alias') . ' = :alias', $this->db->quoteName('alias') . ' = :alias',
$this->db->quoteName('catid') . ' = :catid', $this->db->quoteName('catid') . ' = :catid',
] ])
)
->bind(':alias', $segment) ->bind(':alias', $segment)
->bind(':catid', $query['id'], ParameterType::INTEGER); ->bind(':catid', $query['id'], ParameterType::INTEGER);
$this->db->setQuery($dbquery); $this->db->setQuery($dbquery);
return (int) $this->db->loadResult(); return (int) $this->db->loadResult();
} }
@ -287,9 +260,7 @@ class Router extends RouterView
private function getCategories(array $options = []): CategoryInterface private function getCategories(array $options = []): CategoryInterface
{ {
$key = serialize($options); $key = serialize($options);
if (!isset($this->categoryCache[$key])) {
if (!isset($this->categoryCache[$key]))
{
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options); $this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -11,8 +12,9 @@ namespace Joomla\Component\Weblinks\Site\View\Categories;
use Joomla\CMS\MVC\View\CategoriesView; use Joomla\CMS\MVC\View\CategoriesView;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblinks categories view. * Weblinks categories view.
* *
@ -25,7 +27,6 @@ class HtmlView extends CategoriesView
* @since 3.2 * @since 3.2
*/ */
protected $pageHeading = 'COM_WEBLINKS_DEFAULT_PAGE_TITLE'; protected $pageHeading = 'COM_WEBLINKS_DEFAULT_PAGE_TITLE';
/** /**
* @var string The name of the extension for the category * @var string The name of the extension for the category
* @since 3.2 * @since 3.2

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -11,8 +12,9 @@ namespace Joomla\Component\Weblinks\Site\View\Category;
use Joomla\CMS\MVC\View\CategoryFeedView; use Joomla\CMS\MVC\View\CategoryFeedView;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* HTML View class for the WebLinks component * HTML View class for the WebLinks component
* *

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -13,8 +14,9 @@ use Joomla\CMS\MVC\View\CategoryView;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* HTML View class for the WebLinks component * HTML View class for the WebLinks component
* *
@ -27,7 +29,6 @@ class HtmlView extends CategoryView
* @since 3.2 * @since 3.2
*/ */
protected $extension = 'com_weblinks'; protected $extension = 'com_weblinks';
/** /**
* Execute and display a template script. * Execute and display a template script.
* *
@ -38,22 +39,16 @@ class HtmlView extends CategoryView
public function display($tpl = null) public function display($tpl = null)
{ {
parent::commonCategoryDisplay(); parent::commonCategoryDisplay();
// Prepare the data. // Prepare the data.
// Compute the weblink slug & link url. // Compute the weblink slug & link url.
foreach ($this->items as $item) foreach ($this->items as $item) {
{
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params; $temp = $item->params;
$item->params = clone $this->params; $item->params = clone $this->params;
$item->params->merge($temp); $item->params->merge($temp);
if ($item->params->get('count_clicks', 1) == 1) {
if ($item->params->get('count_clicks', 1) == 1)
{
$item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id); $item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id);
} } else {
else
{
$item->link = $item->url; $item->link = $item->url;
} }
} }
@ -69,11 +64,8 @@ class HtmlView extends CategoryView
protected function prepareDocument() protected function prepareDocument()
{ {
parent::prepareDocument(); parent::prepareDocument();
parent::addFeed(); parent::addFeed();
if ($this->menuItemMatchCategory) {
if ($this->menuItemMatchCategory)
{
// If the active menu item is linked directly to the category being displayed, no further process is needed // If the active menu item is linked directly to the category being displayed, no further process is needed
return; return;
} }
@ -81,29 +73,24 @@ class HtmlView extends CategoryView
// Get ID of the category from active menu item // Get ID of the category from active menu item
$menu = $this->menu; $menu = $this->menu;
if ($menu && $menu->component == 'com_weblinks' && isset($menu->query['view']) if (
&& in_array($menu->query['view'], ['categories', 'category'])) $menu && $menu->component == 'com_weblinks' && isset($menu->query['view'])
{ && in_array($menu->query['view'], ['categories', 'category'])
) {
$id = $menu->query['id']; $id = $menu->query['id'];
} } else {
else
{
$id = 0; $id = 0;
} }
$path = [['title' => $this->category->title, 'link' => '']]; $path = [['title' => $this->category->title, 'link' => '']];
$category = $this->category->getParent(); $category = $this->category->getParent();
while ($category !== null && $category->id != $id && $category->id !== 'root') {
while ($category !== null && $category->id != $id && $category->id !== 'root')
{
$path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)]; $path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)];
$category = $category->getParent(); $category = $category->getParent();
} }
$path = array_reverse($path); $path = array_reverse($path);
foreach ($path as $item) {
foreach ($path as $item)
{
$this->pathway->addItem($item['title'], $item['link']); $this->pathway->addItem($item['title'], $item['link']);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -9,7 +10,9 @@
namespace Joomla\Component\Weblinks\Site\View\Form; namespace Joomla\Component\Weblinks\Site\View\Form;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
@ -76,27 +79,21 @@ class HtmlView extends BaseHtmlView
$this->form = $this->get('Form'); $this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage'); $this->return_page = $this->get('ReturnPage');
if (empty($this->item->id)) if (empty($this->item->id)) {
{
$authorised = $user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create')); $authorised = $user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create'));
} } else {
else
{
$authorised = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid); $authorised = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
} }
if ($authorised !== true) if ($authorised !== true) {
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
} }
if (!empty($this->item)) if (!empty($this->item)) {
{
// Override the base weblink data with any data in the session. // Override the base weblink data with any data in the session.
$temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); $temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', []);
foreach ($temp as $k => $v) foreach ($temp as $k => $v) {
{
$this->item->$k = $v; $this->item->$k = $v;
} }
@ -104,8 +101,7 @@ class HtmlView extends BaseHtmlView
} }
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors'))) {
{
throw new GenericDataException(implode("\n", $errors), 500); throw new GenericDataException(implode("\n", $errors), 500);
} }
@ -118,7 +114,7 @@ class HtmlView extends BaseHtmlView
$this->params = $params; $this->params = $params;
$this->user = $user; $this->user = $user;
$this->_prepareDocument(); $this->prepareDocument();
parent::display($tpl); parent::display($tpl);
} }
@ -128,7 +124,7 @@ class HtmlView extends BaseHtmlView
* *
* @return void * @return void
*/ */
protected function _prepareDocument() protected function prepareDocument()
{ {
$app = Factory::getApplication(); $app = Factory::getApplication();
@ -136,21 +132,15 @@ class HtmlView extends BaseHtmlView
// we need to get it from the menu item itself // we need to get it from the menu item itself
$menu = $app->getMenu()->getActive(); $menu = $app->getMenu()->getActive();
if (empty($this->item->id)) if (empty($this->item->id)) {
{
$head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK'); $head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK');
} } else {
else
{
$head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK'); $head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK');
} }
if ($menu) if ($menu) {
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title)); $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
} } else {
else
{
$this->params->def('page_heading', $head); $this->params->def('page_heading', $head);
} }
@ -158,18 +148,15 @@ class HtmlView extends BaseHtmlView
$this->setDocumentTitle($title); $this->setDocumentTitle($title);
if ($this->params->get('menu-meta_description')) if ($this->params->get('menu-meta_description')) {
{
$this->document->setDescription($this->params->get('menu-meta_description')); $this->document->setDescription($this->params->get('menu-meta_description'));
} }
if ($this->params->get('menu-meta_keywords')) if ($this->params->get('menu-meta_keywords')) {
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
} }
if ($this->params->get('robots')) if ($this->params->get('robots')) {
{
$this->document->setMetadata('robots', $this->params->get('robots')); $this->document->setMetadata('robots', $this->params->get('robots'));
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -12,8 +13,9 @@ namespace Joomla\Component\Weblinks\Site\View\Weblink;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* HTML Weblink View class for the Weblinks component * HTML Weblink View class for the Weblinks component
* *
@ -27,14 +29,12 @@ class HtmlView extends BaseHtmlView
* @var \JObject * @var \JObject
*/ */
protected $item; protected $item;
/** /**
* The page parameters * The page parameters
* *
* @var \Joomla\Registry\Registry|null * @var \Joomla\Registry\Registry|null
*/ */
protected $params; protected $params;
/** /**
* The item model state * The item model state
* *
@ -42,7 +42,6 @@ class HtmlView extends BaseHtmlView
* @since 1.6 * @since 1.6
*/ */
protected $state; protected $state;
/** /**
* Execute and display a template script. * Execute and display a template script.
* *
@ -55,35 +54,24 @@ class HtmlView extends BaseHtmlView
public function display($tpl = null) public function display($tpl = null)
{ {
$app = Factory::getApplication(); $app = Factory::getApplication();
$this->item = $this->get('Item'); $this->item = $this->get('Item');
$this->state = $this->get('State'); $this->state = $this->get('State');
$this->params = $this->state->get('params'); $this->params = $this->state->get('params');
// Create a shortcut for $item. // Create a shortcut for $item.
$item = $this->item; $item = $this->item;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params; $temp = $item->params;
$item->params = clone $app->getParams(); $item->params = clone $app->getParams();
$item->params->merge($temp); $item->params->merge($temp);
$offset = $this->state->get('list.offset'); $offset = $this->state->get('list.offset');
$app->triggerEvent('onContentPrepare', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$app->triggerEvent('onContentPrepare', array('com_weblinks.weblink', &$item, &$item->params, $offset)); $item->event = new \stdClass();
$results = $app->triggerEvent('onContentAfterTitle', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$item->event = new \stdClass;
$results = $app->triggerEvent('onContentAfterTitle', array('com_weblinks.weblink', &$item, &$item->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results)); $item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $app->triggerEvent('onContentBeforeDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$results = $app->triggerEvent('onContentBeforeDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results)); $item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $app->triggerEvent('onContentAfterDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$results = $app->triggerEvent('onContentAfterDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results)); $item->event->afterDisplayContent = trim(implode("\n", $results));
parent::display($tpl); parent::display($tpl);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,15 +8,14 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
// Add strings for translations in Javascript. // Add strings for translations in Javascript.
Text::script('JGLOBAL_EXPAND_CATEGORIES'); Text::script('JGLOBAL_EXPAND_CATEGORIES');
Text::script('JGLOBAL_COLLAPSE_CATEGORIES'); Text::script('JGLOBAL_COLLAPSE_CATEGORIES');
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ /** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager(); $wa = $this->document->getWebAssetManager();
$wa->getRegistry()->addExtensionRegistryFile('com_categories'); $wa->getRegistry()->addExtensionRegistryFile('com_categories');

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,29 +8,35 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) : if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
?> ?>
<div class="com-content-categories__items"> <div class="com-content-categories__items">
<?php foreach ($this->items[$this->parent->id] as $id => $item) : ?> <?php foreach ($this->items[$this->parent->id] as $id => $item) :
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : ?> ?>
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) :
?>
<div class="com-content-categories__item"> <div class="com-content-categories__item">
<div class="w-100"> <div class="w-100">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id, $item->language)); ?>"> <a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id, $item->language)); ?>">
<?php echo $this->escape($item->title); ?></a> <?php echo $this->escape($item->title); ?></a>
<?php if ($this->params->get('show_cat_num_links_cat') == 1) :?> <?php if ($this->params->get('show_cat_num_links_cat') == 1) :
?>
<span class="badge bg-info "> <span class="badge bg-info ">
<?php echo Text::_('COM_WEBLINKS_NUM_ITEMS'); ?>&nbsp; <?php echo Text::_('COM_WEBLINKS_NUM_ITEMS'); ?>&nbsp;
<?php echo $item->numitems; ?> <?php echo $item->numitems; ?>
</span> </span>
<?php endif; ?> <?php
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?> endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) :
?>
<button <button
type="button" type="button"
id="category-btn-<?php echo $item->id; ?>" id="category-btn-<?php echo $item->id; ?>"
@ -40,16 +47,20 @@ if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
> >
<span class="icon-plus" aria-hidden="true"></span> <span class="icon-plus" aria-hidden="true"></span>
</button> </button>
<?php endif; ?> <?php
endif; ?>
</div> </div>
<?php if ($this->params->get('show_subcat_desc_cat') == 1 && !empty($item->description)) : ?> <?php if ($this->params->get('show_subcat_desc_cat') == 1 && !empty($item->description)) :
?>
<div class="category-desc"> <div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?> <?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<?php if ($this->params->get('show_description_image') && !empty($item->getParams()->get('image'))) : ?> <?php if ($this->params->get('show_description_image') && !empty($item->getParams()->get('image'))) :
?>
<?php <?php
$params = $item->getParams(); $params = $item->getParams();
$img = HTMLHelper::cleanImageURL($params->get('image')); $img = HTMLHelper::cleanImageURL($params->get('image'));
@ -61,10 +72,12 @@ if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
endif; endif;
?> ?>
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"<?php echo $alt; ?>> <img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"<?php echo $alt; ?>>
<?php endif; ?> <?php
endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?> <?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) :
?>
<div class="com-content-categories__children" id="category-<?php echo $item->id; ?>" hidden> <div class="com-content-categories__children" id="category-<?php echo $item->id; ?>" hidden>
<?php <?php
$this->items[$item->id] = $item->getChildren(); $this->items[$item->id] = $item->getChildren();
@ -75,9 +88,13 @@ if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
$this->maxLevelcat++; $this->maxLevelcat++;
?> ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
</div> </div>
<?php endif; ?> <?php
<?php endforeach; ?> endif; ?>
<?php
endforeach; ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,8 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
?> ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,38 +8,47 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) : if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) :
?> ?>
<ul class="com-weblinks-category__children list-group list-unstyled"> <ul class="com-weblinks-category__children list-group list-unstyled">
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?> <?php foreach ($this->children[$this->category->id] as $id => $child) :
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : ?> ?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) :
?>
<li class="list-group-item"> <li class="list-group-item">
<div class="item-title"> <div class="item-title">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($child->id, $child->language)); ?>"> <a href="<?php echo Route::_(RouteHelper::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?> <?php echo $this->escape($child->title); ?>
</a> </a>
<?php if ($this->params->get('show_cat_num_links') == 1) : ?> <?php if ($this->params->get('show_cat_num_links') == 1) :
?>
<span class="badge bg-info float-end" title="<?php echo Text::_('COM_WEBLINKS_CAT_NUM'); ?>"><?php echo $child->numitems; ?></span> <span class="badge bg-info float-end" title="<?php echo Text::_('COM_WEBLINKS_CAT_NUM'); ?>"><?php echo $child->numitems; ?></span>
<?php endif; ?> <?php
endif; ?>
</div> </div>
<?php if ($this->params->get('show_subcat_desc') == 1) : ?> <?php if ($this->params->get('show_subcat_desc') == 1) :
<?php if ($child->description) : ?> ?>
<?php if ($child->description) :
?>
<div class="category-desc"> <div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $child->description, '', 'com_weblinks.category'); ?> <?php echo HTMLHelper::_('content.prepare', $child->description, '', 'com_weblinks.category'); ?>
</div> </div>
<?php endif; ?> <?php
<?php endif; ?> endif; ?>
<?php
endif; ?>
<?php if (count($child->getChildren()) > 0 ) : <?php if (count($child->getChildren()) > 0) :
$this->children[$child->id] = $child->getChildren(); $this->children[$child->id] = $child->getChildren();
$this->category = $child; $this->category = $child;
$this->maxLevel--; $this->maxLevel--;
@ -47,7 +57,10 @@ if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) :
$this->maxLevel++; $this->maxLevel++;
endif; ?> endif; ?>
</li> </li>
<?php endif; ?> <?php
<?php endforeach; ?> endif; ?>
<?php
endforeach; ?>
</ul> </ul>
<?php endif; ?> <?php
endif; ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,31 +8,29 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Uri\Uri; use Joomla\CMS\Uri\Uri;
HTMLHelper::_('behavior.core'); HTMLHelper::_('behavior.core');
// Get the user object. // Get the user object.
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
// Check if user is allowed to add/edit based on weblinks permission. // Check if user is allowed to add/edit based on weblinks permission.
$canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->category->id); $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->category->id);
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->category->id); $canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->category->id);
$canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $this->category->id); $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $this->category->id);
$listOrder = $this->escape($this->state->get('list.ordering')); $listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction')); $listDirn = $this->escape($this->state->get('list.direction'));
?> ?>
<div class="com-weblinks-category__items"> <div class="com-weblinks-category__items">
<form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm"> <form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
<?php if ($this->params->get('filter_field')) : ?> <?php if ($this->params->get('filter_field')) :
?>
<div class="com-weblinks-category__filter btn-group"> <div class="com-weblinks-category__filter btn-group">
<label class="filter-search-lbl visually-hidden" for="filter-search"> <label class="filter-search-lbl visually-hidden" for="filter-search">
<?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?> <?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?>
@ -48,49 +47,70 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<button type="button" name="filter-clear-button" class="btn btn-secondary" <button type="button" name="filter-clear-button" class="btn btn-secondary"
onclick="this.form.elements['filter-search'].value = ''; this.form.submit();"><?php echo Text::_('JSEARCH_FILTER_CLEAR'); ?></button> onclick="this.form.elements['filter-search'].value = ''; this.form.submit();"><?php echo Text::_('JSEARCH_FILTER_CLEAR'); ?></button>
</div> </div>
<?php endif; ?> <?php
<?php if ($this->params->get('show_pagination_limit')) : ?> endif; ?>
<?php if ($this->params->get('show_pagination_limit')) :
?>
<div class="com-weblinks-category__pagination btn-group float-end"> <div class="com-weblinks-category__pagination btn-group float-end">
<label for="limit" class="visually-hidden"> <label for="limit" class="visually-hidden">
<?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?> <?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?>
</label> </label>
<?php echo $this->pagination->getLimitBox(); ?> <?php echo $this->pagination->getLimitBox(); ?>
</div> </div>
<?php endif; ?> <?php
<?php if (empty($this->items)) : ?> endif; ?>
<?php if (empty($this->items)) :
?>
<div class="alert alert-info"> <div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span> <span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo Text::_('COM_WEBLINKS_NO_WEBLINKS'); ?> <?php echo Text::_('COM_WEBLINKS_NO_WEBLINKS'); ?>
</div> </div>
<?php else : ?> <?php
else :
?>
<ul class="category list-unstyled"> <ul class="category list-unstyled">
<?php foreach ($this->items as $i => $item) : ?> <?php foreach ($this->items as $i => $item) :
?>
<?php <?php
// Shouldn't this be only for users with admin rights? // Shouldn't this be only for users with admin rights?
// @ToDo: what is the difference -class system-unbublished? // @ToDo: what is the difference -class system-unbublished?
if ($item->state == 0) : ?> if ($item->state == 0) :
?>
<li class="system-unpublished list-group mt-3"> <li class="system-unpublished list-group mt-3">
<?php else : ?> <?php
else :
?>
<li class="list-group mt-3"> <li class="list-group mt-3">
<?php endif; ?> <?php
endif; ?>
<?php if ($canEdit || ($canEditOwn && $item->created_by == $userId)) : ?> <?php if ($canEdit || ($canEditOwn && $item->created_by == $userId)) :
?>
<div class="icons list-group-item"> <div class="icons list-group-item">
<?php echo HTMLHelper::_('weblinkicon.edit', $item, $item->params); ?> <?php echo HTMLHelper::_('weblinkicon.edit', $item, $item->params); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<div class="list-title list-group-item "> <div class="list-title list-group-item ">
<?php if ($this->params->get('icons', 1) == 0) : ?> <?php if ($this->params->get('icons', 1) == 0) :
?>
<?php echo Text::_('COM_WEBLINKS_LINK'); ?> <?php echo Text::_('COM_WEBLINKS_LINK'); ?>
<?php elseif ($this->params->get('icons', 1) == 1) : ?> <?php
elseif ($this->params->get('icons', 1) == 1) :
?>
<?php // ToDo css icons as variables ?> <?php // ToDo css icons as variables ?>
<?php if (!$this->params->get('link_icons')) : ?> <?php if (!$this->params->get('link_icons')) :
?>
<span class="icon-globe" aria-hidden="true"></span> <span class="icon-globe" aria-hidden="true"></span>
<?php else: ?> <?php
else :
?>
<?php echo '<img src="' . $this->params->get('link_icons') . '" alt="' . Text::_('COM_WEBLINKS_LINK') . '" />'; ?> <?php echo '<img src="' . $this->params->get('link_icons') . '" alt="' . Text::_('COM_WEBLINKS_LINK') . '" />'; ?>
<?php endif; ?> <?php
<?php endif; ?> endif; ?>
<?php
endif; ?>
<?php // Compute the correct link ?> <?php // Compute the correct link ?>
<?php $menuclass = 'category' . $this->pageclass_sfx; ?> <?php $menuclass = 'category' . $this->pageclass_sfx; ?>
@ -98,24 +118,26 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<?php $width = $item->params->get('width', 600); ?> <?php $width = $item->params->get('width', 600); ?>
<?php $height = $item->params->get('height', 500); ?> <?php $height = $item->params->get('height', 500); ?>
<?php if ($item->state == 0) : ?> <?php if ($item->state == 0) :
?>
<span class="badge bg-warning"><?php echo Text::_('JUNPUBLISHED'); ?></span> <span class="badge bg-warning"><?php echo Text::_('JUNPUBLISHED'); ?></span>
<?php endif; ?> <?php
endif; ?>
<?php <?php
switch ($item->params->get('target', $this->params->get('target'))) switch ($item->params->get('target', $this->params->get('target'))) {
{
case 1: case 1:
// Open in a new window // Open in a new window
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '" rel="nofollow">' . echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . '</a>'; $this->escape($item->title) . '</a>';
break;
break;
case 2: case 2:
// Open in a popup window // Open in a popup window
$attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $this->escape($width) . ',height=' . $this->escape($height) . ''; $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $this->escape($width) . ',height=' . $this->escape($height) . '';
echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" . echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" .
$this->escape($item->title) . '</a>'; $this->escape($item->title) . '</a>';
break; break;
case 3: case 3:
// Open in a modal window // Open in a modal window
@ -130,34 +152,44 @@ $listDirn = $this->escape($this->state->get('list.direction'));
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '"> echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . ' ' . $item->title . '
</button>'; </button>';
break; break;
default: default:
// Open in parent window // Open in parent window
echo '<a href="' . $link . '" class="' . $menuclass . '" rel="nofollow">' . echo '<a href="' . $link . '" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . ' </a>'; $this->escape($item->title) . ' </a>';
break; break;
} }
?> ?>
<?php if ($this->params->get('show_link_hits', 1)) : ?> <?php if ($this->params->get('show_link_hits', 1)) :
?>
<div class="list-hits badge bg-info float-end"> <div class="list-hits badge bg-info float-end">
<?php echo Text::sprintf('JGLOBAL_HITS_COUNT', $item->hits); ?> <?php echo Text::sprintf('JGLOBAL_HITS_COUNT', $item->hits); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<?php if ($this->params->get('show_tags', 1) && !empty($item->tags->itemTags)) : ?> <?php if ($this->params->get('show_tags', 1) && !empty($item->tags->itemTags)) :
?>
<div class="mt-2 mb-2"> <div class="mt-2 mb-2">
<?php echo LayoutHelper::render('joomla.content.tags', $item->tags->itemTags); ?> <?php echo LayoutHelper::render('joomla.content.tags', $item->tags->itemTags); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<?php if ($this->params->get('show_link_description') && ($item->description != '')) : ?> <?php if ($this->params->get('show_link_description') && ($item->description != '')) :
?>
<div class="mt-2 mb-2"> <div class="mt-2 mb-2">
<?php $images = json_decode($item->images); ?> <?php $images = json_decode($item->images); ?>
<?php if (!empty($images->image_first)) : ?> <?php if (!empty($images->image_first)) :
?>
<?php $imgFloat = '';?> <?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) : ?> <?php if (!empty($images->float_first)) :
?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?> <?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?> <?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?> <?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty) <?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? '' ? ''
@ -165,17 +197,23 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<figure class="item-image <?php echo $imgFloat; ?>"> <figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>" <img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" /> <?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) : ?> <?php if (!empty($images->image_first_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption> <figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?> <?php
endif; ?>
</figure> </figure>
<?php endif; ?> <?php
endif; ?>
<?php if (!empty($images->image_second)) : ?> <?php if (!empty($images->image_second)) :
?>
<?php $imgFloat = ''; ?> <?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) : ?> <?php if (!empty($images->float_second)) :
?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?> <?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?> <?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?> <?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty) <?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? '' ? ''
@ -183,39 +221,51 @@ $listDirn = $this->escape($this->state->get('list.direction'));
<figure class="item-image <?php echo $imgFloat; ?>"> <figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>" <img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" /> <?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) : ?> <?php if (!empty($images->image_second_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption> <figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?> <?php
endif; ?>
</figure> </figure>
<?php endif; ?> <?php
endif; ?>
<?php echo $item->description; ?> <?php echo $item->description; ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
</div> </div>
</li> </li>
<?php endforeach; ?> <?php
endforeach; ?>
</ul> </ul>
<?php if ($this->params->get('show_pagination')) : ?> <?php if ($this->params->get('show_pagination')) :
?>
<div class="com-weblinks-category__counter w-100"> <div class="com-weblinks-category__counter w-100">
<?php if ($this->params->def('show_pagination_results', 1)) : ?> <?php if ($this->params->def('show_pagination_results', 1)) :
?>
<p class="com-weblinks-category__counter counter float-end pt-3 pe-2"> <p class="com-weblinks-category__counter counter float-end pt-3 pe-2">
<?php echo $this->pagination->getPagesCounter(); ?> <?php echo $this->pagination->getPagesCounter(); ?>
</p> </p>
<?php endif; ?> <?php
endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?> <?php echo $this->pagination->getPagesLinks(); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<?php endif; ?> <?php
endif; ?>
<?php if ($canCreate) : ?> <?php if ($canCreate) :
?>
<?php echo HTMLHelper::_('weblinkicon.create', $this->category, $this->category->params); ?> <?php echo HTMLHelper::_('weblinkicon.create', $this->category, $this->category->params); ?>
<?php endif; ?> <?php
endif; ?>
</form> </form>
</div> </div>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,24 +8,20 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
HTMLHelper::_('behavior.keepalive'); HTMLHelper::_('behavior.keepalive');
HTMLHelper::_('behavior.formvalidator'); HTMLHelper::_('behavior.formvalidator');
$captchaEnabled = false; $captchaEnabled = false;
$captchaSet = $this->params->get('captcha', Factory::getApplication()->get('captcha', '0')); $captchaSet = $this->params->get('captcha', Factory::getApplication()->get('captcha', '0'));
foreach (PluginHelper::getPlugin('captcha') as $plugin) {
foreach (PluginHelper::getPlugin('captcha') as $plugin) if ($captchaSet === $plugin->name) {
{
if ($captchaSet === $plugin->name)
{
$captchaEnabled = true; $captchaEnabled = true;
break; break;
} }
@ -34,13 +31,15 @@ foreach (PluginHelper::getPlugin('captcha') as $plugin)
$params = $this->state->get('params'); $params = $this->state->get('params');
?> ?>
<div class="edit item-page<?php echo $this->pageclass_sfx; ?>"> <div class="edit item-page<?php echo $this->pageclass_sfx; ?>">
<?php if ($this->params->get('show_page_heading')) : ?> <?php if ($this->params->get('show_page_heading')) :
?>
<div class="page-header"> <div class="page-header">
<h1> <h1>
<?php echo $this->escape($this->params->get('page_heading')); ?> <?php echo $this->escape($this->params->get('page_heading')); ?>
</h1> </h1>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<form action="<?php echo Route::_('index.php?option=com_weblinks&view=form&w_id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate form-vertical"> <form action="<?php echo Route::_('index.php?option=com_weblinks&view=form&w_id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate form-vertical">
<?php echo $this->form->renderField('title'); ?> <?php echo $this->form->renderField('title'); ?>
@ -49,13 +48,17 @@ $params = $this->state->get('params');
<?php echo $this->form->renderField('url'); ?> <?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('tags'); ?> <?php echo $this->form->renderField('tags'); ?>
<?php if ($params->get('save_history', 0)) : ?> <?php if ($params->get('save_history', 0)) :
?>
<?php echo $this->form->renderField('version_note'); ?> <?php echo $this->form->renderField('version_note'); ?>
<?php endif; ?> <?php
endif; ?>
<?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) : ?> <?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) :
?>
<?php echo $this->form->renderField('state'); ?> <?php echo $this->form->renderField('state'); ?>
<?php endif; ?> <?php
endif; ?>
<?php echo $this->form->renderField('language'); ?> <?php echo $this->form->renderField('language'); ?>
<?php echo $this->form->renderField('description'); ?> <?php echo $this->form->renderField('description'); ?>
@ -72,11 +75,13 @@ $params = $this->state->get('params');
<?php echo $this->form->renderField('image_second_caption', 'images'); ?> <?php echo $this->form->renderField('image_second_caption', 'images'); ?>
<?php if ($captchaEnabled) : ?> <?php if ($captchaEnabled) :
?>
<div class="btn-group"> <div class="btn-group">
<?php echo $this->form->renderField('captcha'); ?> <?php echo $this->form->renderField('captcha'); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<div class="mb-2"> <div class="mb-2">
<button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('weblink.save')"> <button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('weblink.save')">
@ -87,9 +92,11 @@ $params = $this->state->get('params');
<span class="icon-times" aria-hidden="true"></span> <span class="icon-times" aria-hidden="true"></span>
<?php echo Text::_('JCANCEL'); ?> <?php echo Text::_('JCANCEL'); ?>
</button> </button>
<?php if ($this->params->get('save_history', 0) && $this->item->id) : ?> <?php if ($this->params->get('save_history', 0) && $this->item->id) :
?>
<?php echo $this->form->getInput('contenthistory'); ?> <?php echo $this->form->getInput('contenthistory'); ?>
<?php endif; ?> <?php
endif; ?>
</div> </div>
<input type="hidden" name="return" value="<?php echo $this->return_page;?>" /> <input type="hidden" name="return" value="<?php echo $this->return_page;?>" />

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Site * @package Joomla.Site
* @subpackage com_weblinks * @subpackage com_weblinks
@ -7,20 +8,17 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\String\PunycodeHelper; use Joomla\CMS\String\PunycodeHelper;
$weblinkUrl = PunycodeHelper::urlToUTF8($this->item->url); $weblinkUrl = PunycodeHelper::urlToUTF8($this->item->url);
$user = Factory::getApplication()->getIdentity(); $user = Factory::getApplication()->getIdentity();
$canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid); $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
if (!$canEdit) {
if (!$canEdit)
{
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->item->catid); $canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->item->catid);
$canEdit = $canEditOwn && $this->item->created_by == $user->id; $canEdit = $canEditOwn && $this->item->created_by == $user->id;
} }
@ -32,7 +30,8 @@ if (!$canEdit)
<?php echo $this->escape($this->item->title); ?> <?php echo $this->escape($this->item->title); ?>
</h2> </h2>
</div> </div>
<?php if ($canEdit) : ?> <?php if ($canEdit) :
?>
<div class="icons"> <div class="icons">
<div class="float-end"> <div class="float-end">
<div> <div>
@ -40,7 +39,8 @@ if (!$canEdit)
</div> </div>
</div> </div>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?> <?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $this->item->event->afterDisplayTitle; ?> <?php echo $this->item->event->afterDisplayTitle; ?>
@ -55,19 +55,24 @@ if (!$canEdit)
</a> </a>
</div> </div>
<?php if ($this->params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) : ?> <?php if ($this->params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) :
?>
<div class="p-2"> <div class="p-2">
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?> <?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
</div> </div>
<?php endif; ?> <?php
endif; ?>
<div class="p-3"> <div class="p-3">
<?php $images = json_decode($this->item->images); ?> <?php $images = json_decode($this->item->images); ?>
<?php if (!empty($images->image_first)) : ?> <?php if (!empty($images->image_first)) :
?>
<?php $imgFloat = '';?> <?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) : ?> <?php if (!empty($images->float_first)) :
?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?> <?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?> <?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?> <?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty) <?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? '' ? ''
@ -75,17 +80,23 @@ if (!$canEdit)
<figure class="item-image <?php echo $imgFloat; ?>"> <figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>" <img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" /> <?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) : ?> <?php if (!empty($images->image_first_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption> <figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?> <?php
endif; ?>
</figure> </figure>
<?php endif; ?> <?php
endif; ?>
<?php if (!empty($images->image_second)) : ?> <?php if (!empty($images->image_second)) :
?>
<?php $imgFloat = ''; ?> <?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) : ?> <?php if (!empty($images->float_second)) :
?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?> <?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?> <?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?> <?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty) <?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? '' ? ''
@ -93,15 +104,20 @@ if (!$canEdit)
<figure class="item-image <?php echo $imgFloat; ?>"> <figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>" <img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" /> <?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) : ?> <?php if (!empty($images->image_second_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption> <figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?> <?php
endif; ?>
</figure> </figure>
<?php endif; ?> <?php
endif; ?>
<?php if (!empty($this->item->description)) : ?> <?php if (!empty($this->item->description)) :
?>
<?php echo $this->item->description; ?> <?php echo $this->item->description; ?>
<?php endif; ?> <?php
endif; ?>
</div> </div>

View File

@ -8,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Extension\Service\Provider\HelperFactory; use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module; use Joomla\CMS\Extension\Service\Provider\Module;

View File

@ -14,9 +14,11 @@ use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface; use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait; use Joomla\CMS\Helper\HelperFactoryAwareTrait;
// phpcs:disable PSR1.Files.SideEffects
// phpcs:disable PSR1.Files.SideEffects // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects // phpcs:enable PSR1.Files.SideEffects
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Dispatcher class for mod_weblinks * Dispatcher class for mod_weblinks

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Module\Weblinks\Site\Helper; namespace Joomla\Module\Weblinks\Site\Helper;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\CMSApplicationInterface; use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Component\ComponentHelper;
@ -96,20 +99,15 @@ class WeblinksHelper
$items = $model->getItems(); $items = $model->getItems();
if ($items) if ($items) {
{ foreach ($items as $item) {
foreach ($items as $item)
{
$temp = $item->params; $temp = $item->params;
$item->params = clone $cParams; $item->params = clone $cParams;
$item->params->merge($temp); $item->params->merge($temp);
if ($item->params->get('count_clicks', 1) == 1) if ($item->params->get('count_clicks', 1) == 1) {
{
$item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&catid=' . $item->catslug . '&id=' . $item->slug); $item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&catid=' . $item->catslug . '&id=' . $item->slug);
} } else {
else
{
$item->link = $item->url; $item->link = $item->url;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -7,47 +8,61 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
?> ?>
<?php if ($params->get('groupby', 0)) : ?> <?php if ($params->get('groupby', 0)) :
?>
<?php $cats = [] ?> <?php $cats = [] ?>
<?php $cols = $params->get('groupby_columns', 3); ?> <?php $cols = $params->get('groupby_columns', 3); ?>
<?php foreach ($list as $l) : ?> <?php foreach ($list as $l) :
?>
<?php $cats[] = array('catid' => $l->catid, 'title' => $l->category_title); ?> <?php $cats[] = array('catid' => $l->catid, 'title' => $l->category_title); ?>
<?php endforeach; ?> <?php
endforeach; ?>
<?php $cats = array_values(array_map('unserialize', array_unique(array_map('serialize', $cats)))); ?> <?php $cats = array_values(array_map('unserialize', array_unique(array_map('serialize', $cats)))); ?>
<?php foreach ($cats as $k => $cat) : ?> <?php foreach ($cats as $k => $cat) :
?>
<?php $items = []; ?> <?php $items = []; ?>
<?php foreach ($list as $item) : ?> <?php foreach ($list as $item) :
<?php if ($item->catid == $cat['catid']) : ?> ?>
<?php if ($item->catid == $cat['catid']) :
?>
<?php $items[] = $item; ?> <?php $items[] = $item; ?>
<?php endif; ?> <?php
<?php endforeach; ?> endif; ?>
<?php if ($cols > 1) :?> <?php
<?php if ($k % $cols == 0) : ?> endforeach; ?>
<?php if ($cols > 1) :
?>
<?php if ($k % $cols == 0) :
?>
<div class="row row-fluid"> <div class="row row-fluid">
<?php endif; ?> <?php
endif; ?>
<div class="col-' . 12 / $cols . '"> <div class="col-' . 12 / $cols . '">
<?php endif; ?> <?php
<?php if ($params->get('groupby_showtitle', 1)) :?> endif; ?>
<?php if ($params->get('groupby_showtitle', 1)) :
?>
<strong> <?php echo htmlspecialchars($cat['title'], ENT_COMPAT, 'UTF-8'); ?></strong> <strong> <?php echo htmlspecialchars($cat['title'], ENT_COMPAT, 'UTF-8'); ?></strong>
<?php endif; ?>; <?php
endif; ?>;
<ul class="weblinks<?php echo $moduleclass_sfx; ?>"> <ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($items as $item) : ?> <?php foreach ($items as $item) :
?>
<li><div class="d-flex flex-wrap"> <li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1"> <div class="col flex-sm-grow-1">
<?php <?php
$link = $item->link; $link = $item->link;
$width = (int) $item->params->get('width', 600); $width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500); $height = (int) $item->params->get('height', 500);
switch ($item->params->get('target')) {
switch ($item->params->get('target'))
{
case 1: case 1:
// Open in a new window // Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' . echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
@ -58,6 +73,7 @@ use Joomla\CMS\Language\Text;
$attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $width . ',height=' . $height; $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $width . ',height=' . $height;
echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" . echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>'; htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break; break;
case 3: case 3:
// Open in a modal window // Open in a modal window
@ -70,55 +86,67 @@ use Joomla\CMS\Language\Text;
$modalParams['modalWidth'] = 80; $modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams); echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '"> echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . ' ' . $item->title . '</button>';
</button>';
break; break;
default: default:
// Open in parent window // Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' . echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>'; htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break; break;
} }
?> ?>
</div> </div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?> <?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) : ?> <?php if ($params->get('hits', 0)) :
?>
<div class="col flex-sm-grow-1"> <div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"> <?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span> <span class="badge bg-info float-md-end"> <?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div> </div>
<?php endif; ?> <?php
endif; ?>
</li> </li>
<?php endforeach; ?> <?php
endforeach; ?>
</ul> </ul>
<?php if ($cols > 1) :?> <?php if ($cols > 1) :
?>
</div> </div>
<?php if (($k + 1) % $cols == 0 || $k == count($cats) - 1) : ?> <?php if (($k + 1) % $cols == 0 || $k == count($cats) - 1) :
?>
</div> </div>
<?php endif; ?> <?php
<?php endif; ?> endif; ?>
<?php endforeach; ?> <?php
<?php else : ?> endif; ?>
<?php
endforeach; ?>
<?php
else :
?>
<ul class="weblinks<?php echo $moduleclass_sfx; ?>"> <ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :?> <?php foreach ($list as $item) :
?>
<li><div class="d-flex flex-wrap"> <li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1"> <div class="col flex-sm-grow-1">
<?php <?php
$link = $item->link; $link = $item->link;
$width = (int) $item->params->get('width', 600); $width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500); $height = (int) $item->params->get('height', 500);
switch ($item->params->get('target')) {
switch ($item->params->get('target'))
{
case 1: case 1:
// Open in a new window // Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' . echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>'; htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break; break;
case 2: case 2:
// Open in a popup window // Open in a popup window
$attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $width . ',height=' . $height; $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' . $width . ',height=' . $height;
echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" . echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>'; htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break; break;
case 3: case 3:
// Open in a modal window // Open in a modal window
@ -133,22 +161,28 @@ use Joomla\CMS\Language\Text;
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '"> echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . ' ' . $item->title . '
</button>'; </button>';
break; break;
default: default:
// Open in parent window // Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' . echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>'; htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break; break;
} }
?> ?>
</div> </div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?> <?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) : ?> <?php if ($params->get('hits', 0)) :
?>
<div class="col flex-sm-grow-1"> <div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"><?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span> <span class="badge bg-info float-md-end"><?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div> </div>
<?php endif; ?> <?php
endif; ?>
</li> </li>
<?php endforeach; ?> <?php
endforeach; ?>
</ul> </ul>
<?php endif; ?> <?php
endif; ?>

View File

@ -8,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Plugin * @package Joomla.Plugin
* @subpackage Editors-xtd.weblink * @subpackage Editors-xtd.weblink
@ -9,7 +10,9 @@
namespace Joomla\Plugin\EditorsXtd\Weblink\Extension; namespace Joomla\Plugin\EditorsXtd\Weblink\Extension;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\CMSApplicationInterface; use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
@ -62,24 +65,26 @@ final class Weblink extends CMSPlugin
{ {
$user = $this->getApplication()->getIdentity(); $user = $this->getApplication()->getIdentity();
if ($user->authorise('core.create', 'com_weblinks') if (
$user->authorise('core.create', 'com_weblinks')
|| $user->authorise('core.edit', 'com_weblinks') || $user->authorise('core.edit', 'com_weblinks')
|| $user->authorise('core.edit.own', 'com_weblinks')) || $user->authorise('core.edit.own', 'com_weblinks')
{ ) {
// The URL for the weblinks list // The URL for the weblinks list
$link = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;' $link = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;'
. Session::getFormToken() . '=1&amp;editor=' . $name; . Session::getFormToken() . '=1&amp;editor=' . $name;
$button = new CMSObject; $button = new CMSObject();
$button->modal = true; $button->modal = true;
$button->link = $link; $button->link = $link;
$button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK'); $button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK');
$button->name = $this->_type . '_' . $this->_name; $button->name = $this->_type . '_' . $this->_name;
$button->icon = 'globe'; $button->icon = 'globe';
// phpcs:disable Generic.Files.LineLength
$button->iconSVG = '<svg xmlns="http://www.w3.org/2000/svg" width="24 height="24" fill="currentColor" class="bi bi-globe" viewBox="0 0 16 16"> $button->iconSVG = '<svg xmlns="http://www.w3.org/2000/svg" width="24 height="24" fill="currentColor" class="bi bi-globe" viewBox="0 0 16 16">
<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 0 0 5.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 0 1 .64-1.539 6.7 6.7 0 0 1 .597-.933A7.025 7.025 0 0 0 2.255 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.958 6.958 0 0 0-.656 2.5h2.49zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 0 0-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 0 1-.597-.933A9.268 9.268 0 0 1 4.09 12H2.255a7.024 7.024 0 0 0 3.072 2.472zM3.82 11a13.652 13.652 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A7.024 7.024 0 0 0 13.745 12H11.91a9.27 9.27 0 0 1-.64 1.539 6.688 6.688 0 0 1-.597.933zM8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.65 13.65 0 0 1-.312 2.5zm2.802-3.5a6.959 6.959 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5h2.49zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7.024 7.024 0 0 0-3.072-2.472c.218.284.418.598.597.933zM10.855 4a7.966 7.966 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4h2.355z"/> <path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 0 0 5.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 0 1 .64-1.539 6.7 6.7 0 0 1 .597-.933A7.025 7.025 0 0 0 2.255 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.958 6.958 0 0 0-.656 2.5h2.49zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 0 0-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 0 1-.597-.933A9.268 9.268 0 0 1 4.09 12H2.255a7.024 7.024 0 0 0 3.072 2.472zM3.82 11a13.652 13.652 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A7.024 7.024 0 0 0 13.745 12H11.91a9.27 9.27 0 0 1-.64 1.539 6.688 6.688 0 0 1-.597.933zM8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.65 13.65 0 0 1-.312 2.5zm2.802-3.5a6.959 6.959 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5h2.49zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7.024 7.024 0 0 0-3.072-2.472c.218.284.418.598.597.933zM10.855 4a7.966 7.966 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4h2.355z"/>
</svg>'; </svg>';
// phpcs:enable Generic.Files.LineLength
$button->options = [ $button->options = [
'height' => '300px', 'height' => '300px',
'width' => '800px', 'width' => '800px',

View File

@ -8,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Plugin\PluginHelper;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -9,7 +10,9 @@
namespace Joomla\Plugin\Finder\Weblinks\Extension; namespace Joomla\Plugin\Finder\Weblinks\Extension;
defined('JPATH_BASE') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Categories\Categories; use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Component\ComponentHelper;
@ -112,8 +115,7 @@ final class Weblinks extends Adapter
public function onFinderCategoryChangeState($extension, $pks, $value) public function onFinderCategoryChangeState($extension, $pks, $value)
{ {
// Make sure we're handling com_weblinks categories. // Make sure we're handling com_weblinks categories.
if ($extension == 'com_weblinks') if ($extension == 'com_weblinks') {
{
$this->categoryStateChange($pks, $value); $this->categoryStateChange($pks, $value);
} }
} }
@ -131,16 +133,11 @@ final class Weblinks extends Adapter
*/ */
public function onFinderAfterDelete($context, $table) public function onFinderAfterDelete($context, $table)
{ {
if ($context == 'com_weblinks.weblink') if ($context == 'com_weblinks.weblink') {
{
$id = $table->id; $id = $table->id;
} } elseif ($context == 'com_finder.index') {
elseif ($context == 'com_finder.index')
{
$id = $table->link_id; $id = $table->link_id;
} } else {
else
{
return true; return true;
} }
@ -166,11 +163,9 @@ final class Weblinks extends Adapter
public function onFinderAfterSave($context, $row, $isNew) public function onFinderAfterSave($context, $row, $isNew)
{ {
// We only want to handle web links here. We need to handle front end and back end editing. // We only want to handle web links here. We need to handle front end and back end editing.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') {
{
// Check if the access levels are different. // Check if the access levels are different.
if (!$isNew && $this->old_access != $row->access) if (!$isNew && $this->old_access != $row->access) {
{
// Process the change. // Process the change.
$this->itemAccessChange($row); $this->itemAccessChange($row);
} }
@ -180,11 +175,9 @@ final class Weblinks extends Adapter
} }
// Check for access changes in the category. // Check for access changes in the category.
if ($context == 'com_categories.category') if ($context == 'com_categories.category') {
{
// Check if the access levels are different. // Check if the access levels are different.
if (!$isNew && $this->old_cataccess != $row->access) if (!$isNew && $this->old_cataccess != $row->access) {
{
$this->categoryAccessChange($row); $this->categoryAccessChange($row);
} }
} }
@ -208,21 +201,17 @@ final class Weblinks extends Adapter
public function onFinderBeforeSave($context, $row, $isNew) public function onFinderBeforeSave($context, $row, $isNew)
{ {
// We only want to handle web links here. // We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') {
{
// Query the database for the old access level if the item isn't new. // Query the database for the old access level if the item isn't new.
if (!$isNew) if (!$isNew) {
{
$this->checkItemAccess($row); $this->checkItemAccess($row);
} }
} }
// Check for access levels from the category. // Check for access levels from the category.
if ($context == 'com_categories.category') if ($context == 'com_categories.category') {
{
// Query the database for the old access level if the item isn't new. // Query the database for the old access level if the item isn't new.
if (!$isNew) if (!$isNew) {
{
$this->checkCategoryAccess($row); $this->checkCategoryAccess($row);
} }
} }
@ -246,14 +235,12 @@ final class Weblinks extends Adapter
public function onFinderChangeState($context, $pks, $value) public function onFinderChangeState($context, $pks, $value)
{ {
// We only want to handle web links here. // We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') {
{
$this->itemStateChange($pks, $value); $this->itemStateChange($pks, $value);
} }
// Handle when the plugin is disabled. // Handle when the plugin is disabled.
if ($context == 'com_plugins.plugin' && $value === 0) if ($context == 'com_plugins.plugin' && $value === 0) {
{
$this->pluginDisable($pks); $this->pluginDisable($pks);
} }
} }
@ -271,8 +258,7 @@ final class Weblinks extends Adapter
protected function index(Result $item) protected function index(Result $item)
{ {
// Check if the extension is enabled // Check if the extension is enabled
if (ComponentHelper::isEnabled($this->extension) == false) if (ComponentHelper::isEnabled($this->extension) == false) {
{
return; return;
} }
@ -312,8 +298,7 @@ final class Weblinks extends Adapter
$category = $categories->get($item->catid); $category = $categories->get($item->catid);
// Category does not exist, stop here // Category does not exist, stop here
if (!$category) if (!$category) {
{
return; return;
} }

View File

@ -8,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -19,7 +20,9 @@ use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType; use Joomla\Database\ParameterType;
use Joomla\Event\DispatcherInterface; use Joomla\Event\DispatcherInterface;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* Weblinks search plugin. * Weblinks search plugin.
@ -93,9 +96,10 @@ final class Weblinks extends CMSPlugin
$searchText = $text; $searchText = $text;
if (is_array($areas) if (
&& !array_intersect($areas, array_keys($this->onContentSearchAreas()))) is_array($areas)
{ && !array_intersect($areas, array_keys($this->onContentSearchAreas()))
) {
return []; return [];
} }
@ -104,32 +108,27 @@ final class Weblinks extends CMSPlugin
$limit = $this->params->def('search_limit', 50); $limit = $this->params->def('search_limit', 50);
$state = []; $state = [];
if ($sContent) if ($sContent) {
{
$state[] = 1; $state[] = 1;
} }
if ($sArchived) if ($sArchived) {
{
$state[] = 2; $state[] = 2;
} }
if (empty($state)) if (empty($state)) {
{
return []; return [];
} }
$text = trim($text); $text = trim($text);
if ($text == '') if ($text == '') {
{
return []; return [];
} }
$searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS'); $searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS');
switch ($phrase) switch ($phrase) {
{
case 'exact': case 'exact':
$text = $db->quote('%' . $db->escape($text, true) . '%', false); $text = $db->quote('%' . $db->escape($text, true) . '%', false);
$wheres2 = []; $wheres2 = [];
@ -145,8 +144,7 @@ final class Weblinks extends CMSPlugin
$words = explode(' ', $text); $words = explode(' ', $text);
$wheres = []; $wheres = [];
foreach ($words as $word) foreach ($words as $word) {
{
$word = $db->quote('%' . $db->escape($word, true) . '%', false); $word = $db->quote('%' . $db->escape($word, true) . '%', false);
$wheres2 = []; $wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $word; $wheres2[] = 'a.url LIKE ' . $word;
@ -159,8 +157,7 @@ final class Weblinks extends CMSPlugin
break; break;
} }
switch ($ordering) switch ($ordering) {
{
case 'oldest': case 'oldest':
$order = 'a.created ASC'; $order = 'a.created ASC';
break; break;
@ -214,8 +211,7 @@ final class Weblinks extends CMSPlugin
// Filter by language. // Filter by language.
if ($app->isClient('site') && Multilanguage::isEnabled()) if ($app->isClient('site') && Multilanguage::isEnabled()) {
{
$languages = [$app->getLanguage()->getTag(), '*']; $languages = [$app->getLanguage()->getTag(), '*'];
$query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING) $query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING)
->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING); ->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING);
@ -226,17 +222,13 @@ final class Weblinks extends CMSPlugin
$return = []; $return = [];
if ($rows) if ($rows) {
{ foreach ($rows as $key => $row) {
foreach ($rows as $key => $row)
{
$rows[$key]->href = RouteHelper::getWeblinkRoute($row->slug, $row->catslug); $rows[$key]->href = RouteHelper::getWeblinkRoute($row->slug, $row->catslug);
} }
foreach ($rows as $weblink) foreach ($rows as $weblink) {
{ if (\searchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title'])) {
if (\searchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title']))
{
$return[] = $weblink; $return[] = $weblink;
} }
} }

View File

@ -8,7 +8,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Plugin\PluginHelper;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @package Joomla.Administrator * @package Joomla.Administrator
* @subpackage Weblinks * @subpackage Weblinks
@ -18,7 +19,9 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Event\Event; use Joomla\Event\Event;
use Joomla\Event\SubscriberInterface; use Joomla\Event\SubscriberInterface;
defined('_JEXEC') or die; // phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** /**
* System plugin for Joomla Web Links. * System plugin for Joomla Web Links.
@ -87,15 +90,13 @@ final class Weblinks extends CMSPlugin implements SubscriberInterface
*/ */
public function onGetStats(Event $event) public function onGetStats(Event $event)
{ {
if (!ComponentHelper::isEnabled('com_weblinks')) if (!ComponentHelper::isEnabled('com_weblinks')) {
{
return; return;
} }
[$extension] = $event->getArguments(); [$extension] = $event->getArguments();
if (!in_array($extension, $this->supportedExtensions)) if (!in_array($extension, $this->supportedExtensions)) {
{
return; return;
} }
@ -106,8 +107,7 @@ final class Weblinks extends CMSPlugin implements SubscriberInterface
->where('state = 1'); ->where('state = 1');
$webLinks = $db->setQuery($query)->loadResult(); $webLinks = $db->setQuery($query)->loadResult();
if (!$webLinks) if (!$webLinks) {
{
return; return;
} }