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

@ -18,14 +18,23 @@
</rule>
<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 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 ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<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 ref="PSR2.Methods.MethodDeclaration.Underscore">
@ -34,5 +43,6 @@
<rule ref="Squiz.Classes.ValidClassName">
<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>
</ruleset>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,7 +8,9 @@
* @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.
@ -16,5 +19,4 @@ defined('_JEXEC') or die;
*/
class WeblinksHelper extends \Joomla\Component\Weblinks\Administrator\Helper\WeblinksHelper
{
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,7 +8,9 @@
* @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\Filesystem\File;
@ -23,252 +26,240 @@ use Joomla\CMS\Table\Table;
*/
class Com_WeblinksInstallerScript
{
/**
* Function called before extension installation/update/removal procedure commences
*
* @param string $type The type of change (install, update or discover_install, not uninstall)
* @param InstallerAdapter $parent The class calling this method
*
* @return boolean True on success
*
* @since 4.0
*/
public function preflight($type, $parent)
{
$files = [
'/administrator/components/com_weblinks/helpers/associations.php',
'/administrator/components/com_weblinks/sql/install.sqlsrv.sql',
'/administrator/components/com_weblinks/sql/uninstall.sqlsrv.sql',
'/administrator/language/en-GB/en-GB.com_weblinks.ini',
'/administrator/language/en-GB/en-GB.com_weblinks.sys.ini',
'/components/com_weblinks/helpers/association.php',
'/components/com_weblinks/helpers/category.php',
'/language/en-GB/en-GB.com_weblinks.ini',
'/language/en-GB/en-GB.mod_weblinks.ini',
'/language/en-GB/en-GB.mod_weblinks.sys.ini',
'/language/en-GB/en-GB.pkg_weblinks.sys.ini',
'/modules/mod_weblinks/helper.php',
'/modules/mod_weblinks/mod_weblinks.php',
'/plugins/search/weblinks/weblinks.php',
'/plugins/finder/weblinks/weblinks.php',
'/plugins/editors-xtd/weblink/weblink.php',
'plugins/system/weblinks/weblinks.php',
];
/**
* Function called before extension installation/update/removal procedure commences
*
* @param string $type The type of change (install, update or discover_install, not uninstall)
* @param InstallerAdapter $parent The class calling this method
*
* @return boolean True on success
*
* @since 4.0
*/
public function preflight($type, $parent)
{
$files = [
'/administrator/components/com_weblinks/helpers/associations.php',
'/administrator/components/com_weblinks/sql/install.sqlsrv.sql',
'/administrator/components/com_weblinks/sql/uninstall.sqlsrv.sql',
'/administrator/language/en-GB/en-GB.com_weblinks.ini',
'/administrator/language/en-GB/en-GB.com_weblinks.sys.ini',
'/components/com_weblinks/helpers/association.php',
'/components/com_weblinks/helpers/category.php',
'/language/en-GB/en-GB.com_weblinks.ini',
'/language/en-GB/en-GB.mod_weblinks.ini',
'/language/en-GB/en-GB.mod_weblinks.sys.ini',
'/language/en-GB/en-GB.pkg_weblinks.sys.ini',
'/modules/mod_weblinks/helper.php',
'/modules/mod_weblinks/mod_weblinks.php',
'/plugins/search/weblinks/weblinks.php',
'/plugins/finder/weblinks/weblinks.php',
'/plugins/editors-xtd/weblink/weblink.php',
'plugins/system/weblinks/weblinks.php',
];
$folders = [
'/administrator/components/com_weblinks/helpers/html',
'/administrator/components/com_weblinks/sql/updates/sqlsrv',
];
$folders = [
'/administrator/components/com_weblinks/helpers/html',
'/administrator/components/com_weblinks/sql/updates/sqlsrv',
];
foreach ($files as $file)
{
if (File::exists(JPATH_ROOT . $file))
{
File::delete(JPATH_ROOT . $file);
}
}
foreach ($files as $file) {
if (File::exists(JPATH_ROOT . $file)) {
File::delete(JPATH_ROOT . $file);
}
}
foreach ($folders as $folder)
{
if (Folder::exists(JPATH_ROOT . $folder))
{
Folder::delete(JPATH_ROOT . $folder);
}
}
foreach ($folders as $folder) {
if (Folder::exists(JPATH_ROOT . $folder)) {
Folder::delete(JPATH_ROOT . $folder);
}
}
return true;
}
return true;
}
/**
* Function to perform changes during install
*
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 3.4
*/
public function install($parent)
{
// Initialize a new category
/** @type Joomla\CMS\Table\Category $category */
$category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
/**
* Function to perform changes during install
*
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 3.4
*/
public function install($parent)
{
// Initialize a new category
/** @type Joomla\CMS\Table\Category $category */
$category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
// Check if the Uncategorised category exists before adding it
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised')))
{
$category->extension = 'com_weblinks';
$category->title = 'Uncategorised';
$category->description = '';
$category->published = 1;
$category->access = 1;
$category->params = '{"category_layout":"","image":""}';
$category->metadata = '{"author":"","robots":""}';
$category->metadesc = '';
$category->metakey = '';
$category->language = '*';
$category->checked_out_time = null;
$category->version = 1;
$category->hits = 0;
$category->modified_user_id = 0;
$category->checked_out = null;
// Check if the Uncategorised category exists before adding it
if (!$category->load(['extension' => 'com_weblinks', 'title' => 'Uncategorised'])) {
$category->extension = 'com_weblinks';
$category->title = 'Uncategorised';
$category->description = '';
$category->published = 1;
$category->access = 1;
$category->params = '{"category_layout":"","image":""}';
$category->metadata = '{"author":"","robots":""}';
$category->metadesc = '';
$category->metakey = '';
$category->language = '*';
$category->checked_out_time = null;
$category->version = 1;
$category->hits = 0;
$category->modified_user_id = 0;
$category->checked_out = null;
// Set the location in the tree
$category->setLocation(1, 'last-child');
// Set the location in the tree
$category->setLocation(1, 'last-child');
// Check to make sure our data is valid
if (!$category->check())
{
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
// Check to make sure our data is valid
if (!$category->check()) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
return;
}
return;
}
// Now store the category
if (!$category->store(true))
{
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
// Now store the category
if (!$category->store(true)) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
return;
}
return;
}
// Build the path for our category
$category->rebuildPath($category->id);
}
}
// Build the path for our category
$category->rebuildPath($category->id);
}
}
/**
* Method to run after the install routine.
*
* @param string $type The action being performed
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 3.4.1
*/
public function postflight($type, $parent)
{
// Only execute database changes on MySQL databases
$dbName = Factory::getDbo()->name;
/**
* Method to run after the install routine.
*
* @param string $type The action being performed
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 3.4.1
*/
public function postflight($type, $parent)
{
// Only execute database changes on MySQL databases
$dbName = Factory::getDbo()->name;
if (strpos($dbName, 'mysql') !== false)
{
// Add Missing Table Columns if needed
$this->addColumnsIfNeeded();
if (strpos($dbName, 'mysql') !== false) {
// Add Missing Table Columns if needed
$this->addColumnsIfNeeded();
// Drop the Table Columns if needed
$this->dropColumnsIfNeeded();
}
// Drop the Table Columns if needed
$this->dropColumnsIfNeeded();
}
// Insert missing UCM Records if needed
$this->insertMissingUcmRecords();
}
// Insert missing UCM Records if needed
$this->insertMissingUcmRecords();
}
/**
* Method to insert missing records for the UCM tables
*
* @return void
*
* @since 3.4.1
*/
private function insertMissingUcmRecords()
{
// Insert the rows in the #__content_types table if they don't exist already
$db = Factory::getDbo();
/**
* Method to insert missing records for the UCM tables
*
* @return void
*
* @since 3.4.1
*/
private function insertMissingUcmRecords()
{
// Insert the rows in the #__content_types table if they don't exist already
$db = Factory::getDbo();
// Get the type ID for a Weblink
$query = $db->getQuery(true);
$query->select($db->quoteName('type_id'))
->from($db->quoteName('#__content_types'))
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.weblink'));
$db->setQuery($query);
// Get the type ID for a Weblink
$query = $db->getQuery(true);
$query->select($db->quoteName('type_id'))
->from($db->quoteName('#__content_types'))
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.weblink'));
$db->setQuery($query);
$weblinkTypeId = $db->loadResult();
$weblinkTypeId = $db->loadResult();
// Get the type ID for a Weblink Category
$query->clear('where');
$query->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.category'));
$db->setQuery($query);
// Get the type ID for a Weblink Category
$query->clear('where');
$query->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.category'));
$db->setQuery($query);
$categoryTypeId = $db->loadResult();
$categoryTypeId = $db->loadResult();
// Set the table columns to insert table to
$columnsArray = array(
$db->quoteName('type_title'),
$db->quoteName('type_alias'),
$db->quoteName('table'),
$db->quoteName('rules'),
$db->quoteName('field_mappings'),
$db->quoteName('router'),
$db->quoteName('content_history_options'),
);
// Set the table columns to insert table to
$columnsArray = [
$db->quoteName('type_title'),
$db->quoteName('type_alias'),
$db->quoteName('table'),
$db->quoteName('rules'),
$db->quoteName('field_mappings'),
$db->quoteName('router'),
$db->quoteName('content_history_options'),
];
// If we have no type id for com_weblinks.weblink insert it
if (!$weblinkTypeId)
{
// Insert the data.
$query->clear();
$query->insert($db->quoteName('#__content_types'));
$query->columns($columnsArray);
$query->values(
$db->quote('Weblink') . ', '
. $db->quote('com_weblinks.weblink') . ', '
. $db->quote(
'{"special":{"dbtable":"#__weblinks","key":"id","type":"Weblink","prefix":"WeblinksTable","config":"array()"},
// If we have no type id for com_weblinks.weblink insert it
if (!$weblinkTypeId) {
// Insert the data.
$query->clear();
$query->insert($db->quoteName('#__content_types'));
$query->columns($columnsArray);
$query->values(
$db->quote('Weblink') . ', '
. $db->quote('com_weblinks.weblink') . ', '
. $db->quote(
'{"special":{"dbtable":"#__weblinks","key":"id","type":"Weblink","prefix":"WeblinksTable","config":"array()"},
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}'
) . ', '
. $db->quote('') . ', '
. $db->quote(
'{"common":{"core_content_item_id":"id","core_title":"title","core_state":"state","core_alias":"alias",
) . ', '
. $db->quote('') . ', '
. $db->quote(
'{"common":{"core_content_item_id":"id","core_title":"title","core_state":"state","core_alias":"alias",
"core_created_time":"created","core_modified_time":"modified","core_body":"description", "core_hits":"hits",
"core_publish_up":"publish_up","core_publish_down":"publish_down","core_access":"access", "core_params":"params",
"core_featured":"featured", "core_metadata":"metadata", "core_language":"language", "core_images":"images", "core_urls":"url",
"core_version":"version", "core_ordering":"ordering", "core_metakey":"metakey", "core_metadesc":"metadesc",
"core_catid":"catid", "core_xreference":"xreference", "asset_id":"null"}, "special":{}}'
) . ', '
. $db->quote('WeblinksHelperRoute::getWeblinkRoute') . ', '
. $db->quote(
'{"formFile":"administrator\\/components\\/com_weblinks\\/models\\/forms\\/weblink.xml",
) . ', '
. $db->quote('WeblinksHelperRoute::getWeblinkRoute') . ', '
. $db->quote(
'{"formFile":"administrator\\/components\\/com_weblinks\\/models\\/forms\\/weblink.xml",
"hideFields":["asset_id","checked_out","checked_out_time","version","featured","images"], "ignoreChanges":["modified_by",
"modified", "checked_out", "checked_out_time", "version", "hits"], "convertToInt":["publish_up", "publish_down", "featured",
"ordering"], "displayLookup":[{"sourceColumn":"catid","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"},
{"sourceColumn":"created_by","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},
{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},
{"sourceColumn":"modified_by","targetTable":"#__users","targetColumn":"id","displayColumn":"name"} ]}'
)
);
)
);
$db->setQuery($query);
$db->execute();
}
$db->setQuery($query);
$db->execute();
}
// If we have no type id for com_weblinks.category insert it
if (!$categoryTypeId)
{
// Insert the data.
$query->clear();
$query->insert($db->quoteName('#__content_types'));
$query->columns($columnsArray);
$query->values(
$db->quote('Weblinks Category') . ', '
. $db->quote('com_weblinks.category') . ', '
. $db->quote('
// If we have no type id for com_weblinks.category insert it
if (!$categoryTypeId) {
// Insert the data.
$query->clear();
$query->insert($db->quoteName('#__content_types'));
$query->columns($columnsArray);
$query->values(
$db->quote('Weblinks Category') . ', '
. $db->quote('com_weblinks.category') . ', '
. $db->quote('
{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}'
) . ', '
. $db->quote('') . ', '
. $db->quote('
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}') . ', '
. $db->quote('') . ', '
. $db->quote('
{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias",
"core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description",
"core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access",
"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_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"}}'
) . ', '
. $db->quote('WeblinksHelperRoute::getCategoryRoute') . ', '
. $db->quote('
"special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}') . ', '
. $db->quote('WeblinksHelperRoute::getCategoryRoute') . ', '
. $db->quote('
{"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml",
"hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"],
"ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version",
@ -277,68 +268,64 @@ class Com_WeblinksInstallerScript
"displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id",
"displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id",
"displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id",
"displayColumn":"title"}]}'
)
);
"displayColumn":"title"}]}')
);
$db->setQuery($query);
$db->execute();
}
}
$db->setQuery($query);
$db->execute();
}
}
/**
* Method to drop colums from #__weblinks if they still there.
*
* @return void
*
* @since 3.4.1
*/
private function dropColumnsIfNeeded()
{
$oldColumns = array(
'sid',
'date',
'archived',
'approved',
);
/**
* Method to drop colums from #__weblinks if they still there.
*
* @return void
*
* @since 3.4.1
*/
private function dropColumnsIfNeeded()
{
$oldColumns = [
'sid',
'date',
'archived',
'approved',
];
$db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks');
$db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks');
$columns = array_intersect($oldColumns, array_keys($table));
$columns = array_intersect($oldColumns, array_keys($table));
foreach ($columns as $column)
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' DROP COLUMN ' . $db->quoteName($column);
$db->setQuery($sql);
$db->execute();
}
}
foreach ($columns as $column) {
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' DROP COLUMN ' . $db->quoteName($column);
$db->setQuery($sql);
$db->execute();
}
}
/**
* Method to add colums from #__weblinks if they are missing.
*
* @return void
*
* @since 3.4.1
*/
private function addColumnsIfNeeded()
{
$db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks');
/**
* Method to add colums from #__weblinks if they are missing.
*
* @return void
*
* @since 3.4.1
*/
private function addColumnsIfNeeded()
{
$db = Factory::getDbo();
$table = $db->getTableColumns('#__weblinks');
if (!array_key_exists('version', $table))
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int unsigned NOT NULL DEFAULT '1'";
$db->setQuery($sql);
$db->execute();
}
if (!array_key_exists('version', $table)) {
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int unsigned NOT NULL DEFAULT '1'";
$db->setQuery($sql);
$db->execute();
}
if (!array_key_exists('images', $table))
{
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL';
$db->setQuery($sql);
$db->execute();
}
}
if (!array_key_exists('images', $table)) {
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL';
$db->setQuery($sql);
$db->execute();
}
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -6,8 +7,10 @@
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @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\Categories\CategoryFactoryInterface;
use Joomla\CMS\Component\Router\RouterFactoryInterface;
@ -29,41 +32,32 @@ use Joomla\DI\ServiceProviderInterface;
*
* @since 4.0.0
*/
return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->set(AssociationExtensionInterface::class, new AssociationsHelper);
$componentNamespace = '\\Joomla\\Component\\Weblinks';
$container->registerServiceProvider(new CategoryFactory($componentNamespace));
$container->registerServiceProvider(new MVCFactory($componentNamespace));
$container->registerServiceProvider(new ComponentDispatcherFactory($componentNamespace));
$container->registerServiceProvider(new RouterFactory($componentNamespace));
$container->set(
ComponentInterface::class,
function (Container $container) {
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setRegistry($container->get(Registry::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class));
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
return $component;
}
);
}
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->set(AssociationExtensionInterface::class, new AssociationsHelper());
$componentNamespace = '\\Joomla\\Component\\Weblinks';
$container->registerServiceProvider(new CategoryFactory($componentNamespace));
$container->registerServiceProvider(new MVCFactory($componentNamespace));
$container->registerServiceProvider(new ComponentDispatcherFactory($componentNamespace));
$container->registerServiceProvider(new RouterFactory($componentNamespace));
$container->set(ComponentInterface::class, function (Container $container) {
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setRegistry($container->get(Registry::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class));
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
return $component;
});
}
};

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,8 +10,9 @@
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\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
@ -22,45 +24,40 @@ use Joomla\CMS\Router\Route;
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'weblinks';
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'weblinks';
/**
* Method to display a view.
*
* @param boolean $cacheable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return BaseController|boolean This object to support chaining.
*
* @since 1.5
*/
public function display($cacheable = false, $urlparams = false)
{
$view = $this->input->get('view', 'weblinks');
$layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('id');
// Check for edit form.
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.
if (!\count($this->app->getMessageQueue())) {
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
}
/**
* Method to display a view.
*
* @param boolean $cacheable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return BaseController|boolean This object to support chaining.
*
* @since 1.5
*/
public function display($cacheable = false, $urlparams = false)
{
$view = $this->input->get('view', 'weblinks');
$layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('id');
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
return false;
}
// Check for edit form.
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.
if (!\count($this->app->getMessageQueue()))
{
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
}
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
return false;
}
return parent::display();
}
return parent::display();
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Model\BaseDatabaseModel;
@ -24,108 +27,104 @@ use Joomla\Utilities\ArrayHelper;
*/
class WeblinkController extends FormController
{
use VersionableControllerTrait;
use VersionableControllerTrait;
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 1.6
*/
protected function allowAdd($data = array())
{
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 1.6
*/
protected function allowAdd($data = [])
{
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
if ($categoryId)
{
// If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
if ($categoryId) {
// If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
// In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
}
// In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
}
/**
* Method to check if you can add a new record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
/**
* Method to check if you can add a new record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowEdit($data = [], $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
// Since there is no asset tracking, fallback to the component permissions.
if (!$recordId)
{
return parent::allowEdit($data, $key);
}
// Since there is no asset tracking, fallback to the component permissions.
if (!$recordId) {
return parent::allowEdit($data, $key);
}
// Get the item.
$item = $this->getModel()->getItem($recordId);
// Get the item.
$item = $this->getModel()->getItem($recordId);
// Since there is no item, return false.
if (empty($item))
{
return false;
}
// Since there is no item, return false.
if (empty($item)) {
return false;
}
$user = $this->app->getIdentity();
$user = $this->app->getIdentity();
// Check if can edit own core.edit.own.
$canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id;
// Check if can edit own core.edit.own.
$canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id;
// Check the category core.edit permissions.
return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $item->catid);
}
// Check the category core.edit permissions.
return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $item->catid);
}
/**
* Method to run batch operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 1.7
*/
public function batch($model = null)
{
$this->checkToken();
/**
* Method to run batch operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 1.7
*/
public function batch($model = null)
{
$this->checkToken();
// Set the model
$model = $this->getModel('Weblink', 'Administrator', array());
// Set the model
$model = $this->getModel('Weblink', 'Administrator', []);
// Preset the redirect
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
// Preset the redirect
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
return parent::batch($model);
}
return parent::batch($model);
}
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 1.6
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
$task = $this->getTask();
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 1.6
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
$task = $this->getTask();
if ($task == 'save')
{
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
}
}
if ($task == 'save') {
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
}
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,8 +10,9 @@
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;
/**
@ -20,19 +22,19 @@ use Joomla\CMS\MVC\Controller\AdminController;
*/
class WeblinksController extends AdminController
{
/**
* Proxy for getModel
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config The array of possible config values. Optional.
*
* @return object The model.
*
* @since 1.6
*/
public function getModel($name = 'Weblink', $prefix = 'Administrator', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}
/**
* Proxy for getModel
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config The array of possible config values. Optional.
*
* @return object The model.
*
* @since 1.6
*/
public function getModel($name = 'Weblink', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -9,8 +10,9 @@
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\Association\AssociationServiceInterface;
use Joomla\CMS\Association\AssociationServiceTrait;
@ -35,104 +37,107 @@ use Psr\Container\ContainerInterface;
*
* @since 4.0.0
*/
class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface,
TagServiceInterface, RouterServiceInterface, BootableExtensionInterface, FieldsServiceInterface
class WeblinksComponent extends MVCComponent implements
CategoryServiceInterface,
AssociationServiceInterface,
TagServiceInterface,
RouterServiceInterface,
BootableExtensionInterface,
FieldsServiceInterface
{
use CategoryServiceTrait;
use AssociationServiceTrait;
use HTMLRegistryAwareTrait;
use RouterServiceTrait;
use CategoryServiceTrait, TagServiceTrait
{
CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
}
use CategoryServiceTrait;
use AssociationServiceTrait;
use HTMLRegistryAwareTrait;
use RouterServiceTrait;
use CategoryServiceTrait, TagServiceTrait {
CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
}
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('weblinksadministrator', new AdministratorService);
$this->getRegistry()->register('weblinkicon', new Icon($container->get(SiteApplication::class)));
}
/**
* Returns a valid section for the given section. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
* @param object $item The item
*
* @return string|null The new section
*
* @since 4.0.0
*/
public function validateSection($section, $item = null)
{
if ($section != 'weblink')
{
// We don't know other sections
return null;
}
return $section;
}
/**
* Returns valid contexts
*
* @return array
*
* @since 4.0.0
*/
public function getContexts(): array
{
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
$contexts = array(
'com_weblinks.weblink' => Text::_('COM_WEBLINKS'),
);
return $contexts;
}
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
/**
* Returns the table for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getTableNameForSection(string $section = null)
{
return ($section === 'category' ? 'categories' : 'weblinks');
}
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('weblinksadministrator', new AdministratorService());
$this->getRegistry()->register('weblinkicon', new Icon($container->get(SiteApplication::class)));
}
/**
* Returns the state column for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getStateColumnForSection(string $section = null)
{
return 'state';
}
/**
* Returns a valid section for the given section. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
* @param object $item The item
*
* @return string|null The new section
*
* @since 4.0.0
*/
public function validateSection($section, $item = null)
{
if ($section != 'weblink') {
// We don't know other sections
return null;
}
return $section;
}
/**
* Returns valid contexts
*
* @return array
*
* @since 4.0.0
*/
public function getContexts(): array
{
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
$contexts = [
'com_weblinks.weblink' => Text::_('COM_WEBLINKS'),
];
return $contexts;
}
/**
* Returns the table for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getTableNameForSection(string $section = null)
{
return ($section === 'category' ? 'categories' : 'weblinks');
}
/**
* Returns the state column for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getStateColumnForSection(string $section = null)
{
return 'state';
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -16,8 +17,9 @@ use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
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.
*
@ -25,271 +27,225 @@ defined('JPATH_BASE') or die;
*/
class WeblinkField extends FormField
{
/**
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $type = 'Modal_Weblink';
/**
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $type = 'Modal_Weblink';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since __DEPLOY_VERSION__
*/
protected function getInput()
{
$allowNew = ((string) $this->element['new'] == 'true');
$allowEdit = ((string) $this->element['edit'] == 'true');
$allowClear = ((string) $this->element['clear'] != 'false');
$allowSelect = ((string) $this->element['select'] != 'false');
// Load language
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
// The active weblink id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';
// Create the modal id.
$modalId = 'Weblink_' . $this->id;
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Add the modal field script to the document head.
$wa->useScript('field.modal-fields');
// Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect) {
static $scriptSelect = null;
if (is_null($scriptSelect)) {
$scriptSelect = [];
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since __DEPLOY_VERSION__
*/
protected function getInput()
{
$allowNew = ((string) $this->element['new'] == 'true');
$allowEdit = ((string) $this->element['edit'] == 'true');
$allowClear = ((string) $this->element['clear'] != 'false');
$allowSelect = ((string) $this->element['select'] != 'false');
// Load language
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
// The active weblink id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';
// Create the modal id.
$modalId = 'Weblink_' . $this->id;
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Add the modal field script to the document head.
$wa->useScript('field.modal-fields');
// Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect)
{
static $scriptSelect = null;
if (is_null($scriptSelect))
{
$scriptSelect = array();
}
if (!isset($scriptSelect[$this->id]))
{
$wa->addInlineScript("
if (!isset($scriptSelect[$this->id])) {
$wa->addInlineScript(
"
window.jSelectWeblink_" . $this->id . " = function (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');
$scriptSelect[$this->id] = true;
}
}
Text::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED');
// Setup variables for display.
$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';
$modalTitle = Text::_('COM_WEBLINKS_CHANGE_WEBLINK');
if (isset($this->element['language'])) {
$linkWeblinks .= '&amp;forcedLanguage=' . $this->element['language'];
$linkWeblink .= '&amp;forcedLanguage=' . $this->element['language'];
$modalTitle .= ' &#8212; ' . $this->element['label'];
}
$scriptSelect[$this->id] = true;
}
}
$urlSelect = $linkWeblinks . '&amp;function=jSelectWeblink_' . $this->id;
$urlEdit = $linkWeblink . '&amp;task=weblink.edit&amp;id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkWeblink . '&amp;task=weblink.add';
if ($value) {
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__weblinks'))
->where($db->quoteName('id') . ' = :id')
->bind(':id', $value, ParameterType::INTEGER);
$db->setQuery($query);
try {
$title = $db->loadResult();
} catch (\RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
// Setup variables for display.
$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';
$modalTitle = Text::_('COM_WEBLINKS_CHANGE_WEBLINK');
$title = empty($title) ? Text::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The current weblink display field.
$html = '';
if ($allowSelect || $allowNew || $allowEdit || $allowClear) {
$html .= '<span class="input-group">';
}
if (isset($this->element['language']))
{
$linkWeblinks .= '&amp;forcedLanguage=' . $this->element['language'];
$linkWeblink .= '&amp;forcedLanguage=' . $this->element['language'];
$modalTitle .= ' &#8212; ' . $this->element['label'];
}
$html .= '<input class="form-control" id="' . $this->id . '_name" type="text" value="' . $title . '" readonly size="35">';
// Select weblink button
if ($allowSelect) {
$html .= '<button'
. ' class="btn btn-primary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalSelect' . $modalId . '">'
. '<span class="icon-file" aria-hidden="true"></span> ' . Text::_('JSELECT')
. '</button>';
}
$urlSelect = $linkWeblinks . '&amp;function=jSelectWeblink_' . $this->id;
$urlEdit = $linkWeblink . '&amp;task=weblink.edit&amp;id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkWeblink . '&amp;task=weblink.add';
// New weblink button
if ($allowNew) {
$html .= '<button'
. ' class="btn btn-secondary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_new"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalNew' . $modalId . '">'
. '<span class="icon-plus" aria-hidden="true"></span> ' . Text::_('JACTION_CREATE')
. '</button>';
}
if ($value)
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__weblinks'))
->where($db->quoteName('id') . ' = :id')
->bind(':id', $value, ParameterType::INTEGER);
$db->setQuery($query);
// Edit weblink button
if ($allowEdit) {
$html .= '<button'
. ' class="btn btn-primary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalEdit' . $modalId . '">'
. '<span class="icon-pen-square" aria-hidden="true"></span> ' . Text::_('JACTION_EDIT')
. '</button>';
}
try
{
$title = $db->loadResult();
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
// Clear weblink button
if ($allowClear) {
$html .= '<button'
. ' class="btn btn-secondary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"'
. ' type="button"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-times" aria-hidden="true"></span> ' . Text::_('JCLEAR')
. '</button>';
}
$title = empty($title) ? Text::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
if ($allowSelect || $allowNew || $allowEdit || $allowClear) {
$html .= '</span>';
}
// The current weblink display field.
$html = '';
// Select weblink modal
if ($allowSelect) {
$html .= HTMLHelper::_('bootstrap.renderModal', 'ModalSelect' . $modalId, [
'title' => $modalTitle,
'url' => $urlSelect,
'height' => '400px',
'width' => '800px',
'bodyHeight' => 70,
'modalWidth' => 80,
'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>',
]);
}
if ($allowSelect || $allowNew || $allowEdit || $allowClear)
{
$html .= '<span class="input-group">';
}
$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;";
$applyButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'apply', 'weblink-form'); return false;";
// New weblink modal
if ($allowNew) {
$html .= HTMLHelper::_('bootstrap.renderModal', 'ModalNew' . $modalId, [
'title' => Text::_('COM_WEBLINKS_NEW_WEBLINK'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlNew,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="' . $closeButtonClick . '">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="' . $saveButtonClick . '">'
. Text::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>',
]);
}
$html .= '<input class="form-control" id="' . $this->id . '_name" type="text" value="' . $title . '" readonly size="35">';
// Edit weblink modal
if ($allowEdit) {
$html .= HTMLHelper::_('bootstrap.renderModal', 'ModalEdit' . $modalId, [
'title' => Text::_('COM_WEBLINKS_EDIT_WEBLINK'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlEdit,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="' . $closeButtonClick . '">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="' . $saveButtonClick . '">'
. Text::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>',
]);
}
// Select weblink button
if ($allowSelect)
{
$html .= '<button'
. ' class="btn btn-primary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalSelect' . $modalId . '">'
. '<span class="icon-file" aria-hidden="true"></span> ' . Text::_('JSELECT')
. '</button>';
}
// Note: class='required' for client side validation.
$class = $this->required ? ' class="required modal-value"' : '';
$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 . '" />';
return $html;
}
// New weblink button
if ($allowNew)
{
$html .= '<button'
. ' class="btn btn-secondary' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_new"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalNew' . $modalId . '">'
. '<span class="icon-plus" aria-hidden="true"></span> ' . Text::_('JACTION_CREATE')
. '</button>';
}
// Edit weblink button
if ($allowEdit)
{
$html .= '<button'
. ' class="btn btn-primary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"'
. ' data-bs-toggle="modal"'
. ' type="button"'
. ' data-bs-target="#ModalEdit' . $modalId . '">'
. '<span class="icon-pen-square" aria-hidden="true"></span> ' . Text::_('JACTION_EDIT')
. '</button>';
}
// Clear weblink button
if ($allowClear)
{
$html .= '<button'
. ' class="btn btn-secondary' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"'
. ' type="button"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-times" aria-hidden="true"></span> ' . Text::_('JCLEAR')
. '</button>';
}
if ($allowSelect || $allowNew || $allowEdit || $allowClear)
{
$html .= '</span>';
}
// Select weblink modal
if ($allowSelect)
{
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalSelect' . $modalId,
array(
'title' => $modalTitle,
'url' => $urlSelect,
'height' => '400px',
'width' => '800px',
'bodyHeight' => 70,
'modalWidth' => 80,
'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>',
)
);
}
$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;";
$applyButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'apply', 'weblink-form'); return false;";
// New weblink modal
if ($allowNew)
{
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
'title' => Text::_('COM_WEBLINKS_NEW_WEBLINK'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlNew,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="' . $closeButtonClick . '">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="' . $saveButtonClick . '">'
. Text::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>',
)
);
}
// Edit weblink modal
if ($allowEdit)
{
$html .= HTMLHelper::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => Text::_('COM_WEBLINKS_EDIT_WEBLINK'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlEdit,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="' . $closeButtonClick . '">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="' . $saveButtonClick . '">'
. Text::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="' . $applyButtonClick . '">'
. Text::_('JAPPLY') . '</a>',
)
);
}
// Note: class='required' for client side validation.
$class = $this->required ? ' class="required modal-value"' : '';
$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 . '" />';
return $html;
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since __DEPLOY_VERSION__
*/
protected function getLabel()
{
return str_replace($this->id, $this->id . '_name', parent::getLabel());
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since __DEPLOY_VERSION__
*/
protected function getLabel()
{
return str_replace($this->id, $this->id . '_name', parent::getLabel());
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -9,8 +10,9 @@
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\Language\Associations;
use Joomla\CMS\Table\Table;
@ -23,188 +25,164 @@ use Joomla\Component\Weblinks\Site\Helper\AssociationHelper;
*/
class AssociationsHelper extends AssociationExtensionHelper
{
/**
* The extension name
*
* @var string $extension
*
* @since __DEPLOY_VERSION__
*/
protected $extension = 'com_weblinks';
/**
* The extension name
*
* @var string $extension
*
* @since __DEPLOY_VERSION__
*/
protected $extension = 'com_weblinks';
/**
* Array of item types
*
* @var array $itemTypes
*
* @since __DEPLOY_VERSION__
*/
protected $itemTypes = array('weblink', 'category');
/**
* Array of item types
*
* @var array $itemTypes
*
* @since __DEPLOY_VERSION__
*/
protected $itemTypes = ['weblink', 'category'];
/**
* Has the extension association support
*
* @var boolean $associationsSupport
*
* @since __DEPLOY_VERSION__
*/
protected $associationsSupport = true;
/**
* Has the extension association support
*
* @var boolean $associationsSupport
*
* @since __DEPLOY_VERSION__
*/
protected $associationsSupport = true;
/**
* Method to get the associations for a given item.
*
* @param integer $id Id of the item
* @param string $view Name of the view
*
* @return array Array of associations for the item
*
* @since 4.0.0
*/
public function getAssociationsForItem($id = 0, $view = null)
{
return AssociationHelper::getAssociations($id, $view);
}
/**
* Method to get the associations for a given item.
*
* @param integer $id Id of the item
* @param string $view Name of the view
*
* @return array Array of associations for the item
*
* @since 4.0.0
*/
public function getAssociationsForItem($id = 0, $view = null)
{
return AssociationHelper::getAssociations($id, $view);
}
/**
* Get the associated items for an item
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function getAssociations($typeName, $id)
{
$type = $this->getType($typeName);
/**
* Get the associated items for an item
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function getAssociations($typeName, $id)
{
$type = $this->getType($typeName);
$context = $this->extension . '.item';
$catidField = 'catid';
if ($typeName === 'category') {
$context = 'com_categories.item';
$catidField = '';
}
$context = $this->extension . '.item';
$catidField = 'catid';
// Get the associations.
$associations = Associations::getAssociations($this->extension, $type['tables']['a'], $context, $id, 'id', 'alias', $catidField);
return $associations;
}
if ($typeName === 'category')
{
$context = 'com_categories.item';
$catidField = '';
}
/**
* Get item information
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return Table|null
*
* @since __DEPLOY_VERSION__
*/
public function getItem($typeName, $id)
{
if (empty($id)) {
return null;
}
// Get the associations.
$associations = Associations::getAssociations(
$this->extension,
$type['tables']['a'],
$context,
$id,
'id',
'alias',
$catidField
);
$table = null;
switch ($typeName) {
case 'weblink':
$table = Table::getInstance('WeblinkTable', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\');
return $associations;
}
break;
case 'category':
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
/**
* Get item information
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return Table|null
*
* @since __DEPLOY_VERSION__
*/
public function getItem($typeName, $id)
{
if (empty($id))
{
return null;
}
break;
}
$table = null;
if (empty($table)) {
return null;
}
switch ($typeName)
{
case 'weblink':
$table = Table::getInstance('WeblinkTable', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\');
break;
$table->load($id);
return $table;
}
case 'category':
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
break;
}
/**
* Get information about the type
*
* @param string $typeName The item type
*
* @return array Array of item types
*
* @since __DEPLOY_VERSION__
*/
public function getType($typeName = '')
{
$fields = $this->getFieldsTemplate();
$tables = [];
$joins = [];
$support = $this->getSupportTemplate();
$title = '';
if (in_array($typeName, $this->itemTypes)) {
switch ($typeName) {
case 'weblink':
$support['state'] = true;
$support['acl'] = true;
$support['checkout'] = true;
$support['category'] = true;
$support['save2copy'] = true;
$tables = [
'a' => '#__weblinks',
];
$title = 'weblink';
if (empty($table))
{
return null;
}
break;
case 'category':
$fields['created_user_id'] = 'a.created_user_id';
$fields['ordering'] = 'a.lft';
$fields['level'] = 'a.level';
$fields['catid'] = '';
$fields['state'] = 'a.published';
$support['state'] = true;
$support['acl'] = true;
$support['checkout'] = true;
$support['level'] = true;
$tables = [
'a' => '#__categories',
];
$title = 'category';
$table->load($id);
break;
}
}
return $table;
}
/**
* Get information about the type
*
* @param string $typeName The item type
*
* @return array Array of item types
*
* @since __DEPLOY_VERSION__
*/
public function getType($typeName = '')
{
$fields = $this->getFieldsTemplate();
$tables = array();
$joins = array();
$support = $this->getSupportTemplate();
$title = '';
if (in_array($typeName, $this->itemTypes))
{
switch ($typeName)
{
case 'weblink':
$support['state'] = true;
$support['acl'] = true;
$support['checkout'] = true;
$support['category'] = true;
$support['save2copy'] = true;
$tables = array(
'a' => '#__weblinks',
);
$title = 'weblink';
break;
case 'category':
$fields['created_user_id'] = 'a.created_user_id';
$fields['ordering'] = 'a.lft';
$fields['level'] = 'a.level';
$fields['catid'] = '';
$fields['state'] = 'a.published';
$support['state'] = true;
$support['acl'] = true;
$support['checkout'] = true;
$support['level'] = true;
$tables = array(
'a' => '#__categories',
);
$title = 'category';
break;
}
}
return array(
'fields' => $fields,
'support' => $support,
'tables' => $tables,
'joins' => $joins,
'title' => $title,
);
}
return [
'fields' => $fields,
'support' => $support,
'tables' => $tables,
'joins' => $joins,
'title' => $title,
];
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,8 +10,9 @@
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;
/**
@ -20,5 +22,4 @@ use Joomla\CMS\Helper\ContentHelper;
*/
class WeblinksHelper extends ContentHelper
{
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Factory;
@ -29,415 +32,386 @@ use Joomla\String\StringHelper;
*/
class WeblinkModel extends AdminModel
{
use VersionableModelTrait;
use VersionableModelTrait;
/**
* The type alias for this content type.
*
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
/**
* The type alias for this content type.
*
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
/**
* The context used for the associations table
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $associationsContext = 'com_weblinks.item';
/**
* The context used for the associations table
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $associationsContext = 'com_weblinks.item';
/**
* The prefix to use with controller messages.
*
* @var string
* @since 1.6
*/
protected $text_prefix = 'COM_WEBLINKS';
/**
* The prefix to use with controller messages.
*
* @var string
* @since 1.6
*/
protected $text_prefix = 'COM_WEBLINKS';
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canDelete($record)
{
if (empty($record->id) || $record->state != -2)
{
return false;
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canDelete($record)
{
if (empty($record->id) || $record->state != -2) {
return false;
}
return $this->getCurrentUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
return $this->getCurrentUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canEditState($record)
{
if (!empty($record->catid))
{
return $this->getCurrentUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission for the component.
*
* @since 1.6
*/
protected function canEditState($record)
{
if (!empty($record->catid)) {
return $this->getCurrentUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canEditState($record);
}
return parent::canEditState($record);
}
/**
* Abstract method for getting the form from the model.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
*
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
/**
* Abstract method for getting the form from the model.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
*
* @since 1.6
*/
public function getForm($data = [], $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_weblinks.weblink', 'weblink', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form))
{
return false;
}
if (empty($form)) {
return false;
}
// Determine correct permissions to check.
if ($this->getState('weblink.id'))
{
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
}
else
{
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
}
// Determine correct permissions to check.
if ($this->getState('weblink.id')) {
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
} else {
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data))
{
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('publish_down', 'disabled', 'true');
// Modify the form based on access controls.
if (!$this->canEditState((object) $data)) {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('publish_down', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('publish_up', 'filter', 'unset');
$form->setFieldAttribute('publish_down', 'filter', 'unset');
}
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('publish_up', 'filter', 'unset');
$form->setFieldAttribute('publish_down', 'filter', 'unset');
}
// Don't allow to change the created_by user if not allowed to access com_users.
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
// Don't allow to change the created_by user if not allowed to access com_users.
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users')) {
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
return $form;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 1.6
*/
protected function loadFormData()
{
$app = Factory::getApplication();
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 1.6
*/
protected function loadFormData()
{
$app = Factory::getApplication();
// Check the session for previously entered form data.
$data = $app->getUserState('com_weblinks.edit.weblink.data', array());
// Check the session for previously entered form data.
$data = $app->getUserState('com_weblinks.edit.weblink.data', []);
if (empty($data))
{
$data = $this->getItem();
if (empty($data)) {
$data = $this->getItem();
// Prime some default values.
if ($this->getState('weblink.id') == 0)
{
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
}
}
// Prime some default values.
if ($this->getState('weblink.id') == 0) {
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
}
}
$this->preprocessData('com_weblinks.weblink', $data);
$this->preprocessData('com_weblinks.weblink', $data);
return $data;
}
return $data;
}
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*
* @since 1.6
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
// Convert the metadata field to an array.
$registry = new Registry($item->metadata ?? '');
$item->metadata = $registry->toArray();
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*
* @since 1.6
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk)) {
// Convert the metadata field to an array.
$registry = new Registry($item->metadata ?? '');
$item->metadata = $registry->toArray();
// Convert the images field to an array.
$registry = new Registry($item->images ?? '');
$item->images = $registry->toArray();
// Convert the images field to an array.
$registry = new Registry($item->images ?? '');
$item->images = $registry->toArray();
// Load associated web links items
$assoc = Associations::isEnabled();
// Load associated web links items
$assoc = Associations::isEnabled();
if ($assoc)
{
$item->associations = array();
if ($assoc) {
$item->associations = [];
if ($item->id != null)
{
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
if ($item->id != null) {
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
foreach ($associations as $tag => $association)
{
$item->associations[$tag] = $association->id;
}
}
}
foreach ($associations as $tag => $association) {
$item->associations[$tag] = $association->id;
}
}
}
if (!empty($item->id))
{
$item->tags = new TagsHelper;
$item->tags->getTagIds($item->id, 'com_weblinks.weblink');
$item->metadata['tags'] = $item->tags;
}
}
if (!empty($item->id)) {
$item->tags = new TagsHelper();
$item->tags->getTagIds($item->id, 'com_weblinks.weblink');
$item->metadata['tags'] = $item->tags;
}
}
return $item;
}
return $item;
}
/**
* Prepare and sanitise the table data prior to saving.
*
* @param \Joomla\CMS\Table\Table $table A reference to a JTable object.
*
* @return void
*
* @since 1.6
*/
protected function prepareTable($table)
{
$date = Factory::getDate();
$user = $this->getCurrentUser();
/**
* Prepare and sanitise the table data prior to saving.
*
* @param \Joomla\CMS\Table\Table $table A reference to a JTable object.
*
* @return void
*
* @since 1.6
*/
protected function prepareTable($table)
{
$date = Factory::getDate();
$user = $this->getCurrentUser();
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = ApplicationHelper::stringURLSafe($table->alias);
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = ApplicationHelper::stringURLSafe($table->alias);
if (empty($table->alias))
{
$table->alias = ApplicationHelper::stringURLSafe($table->title);
}
if (empty($table->alias)) {
$table->alias = ApplicationHelper::stringURLSafe($table->title);
}
if (empty($table->id))
{
// Set the values
if (empty($table->id)) {
// Set the values
// Set ordering to the last item if not set
if (empty($table->ordering))
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('MAX(ordering)')
->from($db->quoteName('#__weblinks'));
// Set ordering to the last item if not set
if (empty($table->ordering)) {
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('MAX(ordering)')
->from($db->quoteName('#__weblinks'));
$db->setQuery($query);
$max = $db->loadResult();
$db->setQuery($query);
$max = $db->loadResult();
$table->ordering = $max + 1;
}
else
{
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->id;
}
}
$table->ordering = $max + 1;
} else {
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->id;
}
}
// Increment the weblink version number.
$table->version++;
}
// Increment the weblink version number.
$table->version++;
}
/**
* A protected method to get a set of ordering conditions.
*
* @param \Joomla\CMS\Table\Table $table A JTable object.
*
* @return array An array of conditions to add to ordering queries.
*
* @since 1.6
*/
protected function getReorderConditions($table)
{
$condition = array();
$condition[] = 'catid = ' . (int) $table->catid;
/**
* A protected method to get a set of ordering conditions.
*
* @param \Joomla\CMS\Table\Table $table A JTable object.
*
* @return array An array of conditions to add to ordering queries.
*
* @since 1.6
*/
protected function getReorderConditions($table)
{
$condition = [];
$condition[] = 'catid = ' . (int) $table->catid;
return $condition;
}
return $condition;
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 3.1
*/
public function save($data)
{
$app = Factory::getApplication();
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 3.1
*/
public function save($data)
{
$app = Factory::getApplication();
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0)
{
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
}
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
}
// Save New Category
if ($catid == 0 && $this->canCreateCategory())
{
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_weblinks';
$table['language'] = $data['language'];
$table['published'] = 1;
// Save New Category
if ($catid == 0 && $this->canCreateCategory()) {
$table = [];
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_weblinks';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy')
{
[$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name;
$data['alias'] = $alias;
$data['state'] = 0;
}
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') {
[$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name;
$data['alias'] = $alias;
$data['state'] = 0;
}
return parent::save($data);
}
return parent::save($data);
}
/**
* Method to change the title & alias.
*
* @param integer $category_id The id of the parent.
* @param string $alias The alias.
* @param string $name The title.
*
* @return array Contains the modified title and alias.
*
* @since 3.1
*/
protected function generateNewTitle($category_id, $alias, $name)
{
// Alter the title & alias
$table = $this->getTable();
/**
* Method to change the title & alias.
*
* @param integer $category_id The id of the parent.
* @param string $alias The alias.
* @param string $name The title.
*
* @return array Contains the modified title and alias.
*
* @since 3.1
*/
protected function generateNewTitle($category_id, $alias, $name)
{
// Alter the title & alias
$table = $this->getTable();
while ($table->load(array('alias' => $alias, 'catid' => $category_id)))
{
if ($name == $table->title)
{
$name = StringHelper::increment($name);
}
while ($table->load(['alias' => $alias, 'catid' => $category_id])) {
if ($name == $table->title) {
$name = StringHelper::increment($name);
}
$alias = StringHelper::increment($alias, 'dash');
}
$alias = StringHelper::increment($alias, 'dash');
}
return array($name, $alias);
}
return [$name, $alias];
}
/**
* Allows preprocessing of the JForm object.
*
* @param \JForm $form The form object
* @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed
*
* @return void
*
* @since 3.6.0
*/
protected function preprocessForm(\JForm $form, $data, $group = 'content')
{
if ($this->canCreateCategory())
{
$form->setFieldAttribute('catid', 'allowAdd', 'true');
}
/**
* Allows preprocessing of the JForm object.
*
* @param \JForm $form The form object
* @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed
*
* @return void
*
* @since 3.6.0
*/
protected function preprocessForm(\JForm $form, $data, $group = 'content')
{
if ($this->canCreateCategory()) {
$form->setFieldAttribute('catid', 'allowAdd', 'true');
}
// Association weblinks items
if (Associations::isEnabled())
{
$languages = LanguageHelper::getContentLanguages(false, false, null, 'ordering', 'asc');
// Association weblinks items
if (Associations::isEnabled()) {
$languages = LanguageHelper::getContentLanguages(false, false, null, 'ordering', 'asc');
if (count($languages) > 1)
{
$addform = new \SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations');
if (count($languages) > 1) {
$addform = new \SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations');
foreach ($languages as $language)
{
$field = $fieldset->addChild('field');
$field->addAttribute('name', $language->lang_code);
$field->addAttribute('type', 'modal_weblink');
$field->addAttribute('language', $language->lang_code);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('select', 'true');
$field->addAttribute('new', 'true');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
$field->addAttribute('addfieldprefix', 'Joomla\\Component\\Weblinks\\Administrator\\Field');
}
foreach ($languages as $language) {
$field = $fieldset->addChild('field');
$field->addAttribute('name', $language->lang_code);
$field->addAttribute('type', 'modal_weblink');
$field->addAttribute('language', $language->lang_code);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('select', 'true');
$field->addAttribute('new', 'true');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
$field->addAttribute('addfieldprefix', 'Joomla\\Component\\Weblinks\\Administrator\\Field');
}
$form->load($addform, false);
}
}
$form->load($addform, false);
}
}
parent::preprocessForm($form, $data, $group);
}
parent::preprocessForm($form, $data, $group);
}
/**
* Is the user allowed to create an on the fly category?
*
* @return bool
*
* @since 3.6.0
*/
private function canCreateCategory()
{
return $this->getCurrentUser()->authorise('core.create', 'com_weblinks');
}
/**
* Is the user allowed to create an on the fly category?
*
* @return bool
*
* @since 3.6.0
*/
private function canCreateCategory()
{
return $this->getCurrentUser()->authorise('core.create', 'com_weblinks');
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Factory;
@ -25,271 +28,252 @@ use Joomla\Database\ParameterType;
*/
class WeblinksModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'alias', 'a.alias',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_id',
'c.title', 'category_title',
'state', 'a.state', 'published',
'access', 'a.access',
'ag.title', 'access_level',
'created', 'a.created',
'created_by', 'a.created_by',
'ordering', 'a.ordering',
'featured', 'a.featured',
'language', 'a.language',
'l.title', 'language_title',
'hits', 'a.hits',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'url', 'a.url',
'tag',
'level', 'c.level',
);
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = [], MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'title', 'a.title',
'alias', 'a.alias',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_id',
'c.title', 'category_title',
'state', 'a.state', 'published',
'access', 'a.access',
'ag.title', 'access_level',
'created', 'a.created',
'created_by', 'a.created_by',
'ordering', 'a.ordering',
'featured', 'a.featured',
'language', 'a.language',
'l.title', 'language_title',
'hits', 'a.hits',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'url', 'a.url',
'tag',
'level', 'c.level',
];
$assoc = Associations::isEnabled();
$assoc = Associations::isEnabled();
if ($assoc)
{
$config['filter_fields'][] = 'association';
}
}
if ($assoc) {
$config['filter_fields'][] = 'association';
}
}
parent::__construct($config, $factory);
}
parent::__construct($config, $factory);
}
/**
* Method to auto-populate the model state.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 1.6
*/
protected function populateState($ordering = 'a.title', $direction = 'asc')
{
$app = Factory::getApplication();
/**
* Method to auto-populate the model state.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 1.6
*/
protected function populateState($ordering = 'a.title', $direction = 'asc')
{
$app = Factory::getApplication();
$forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd');
$forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd');
// Adjust the context to support modal layouts.
if ($layout = $app->input->get('layout'))
{
$this->context .= '.' . $layout;
}
// Adjust the context to support modal layouts.
if ($layout = $app->input->get('layout')) {
$this->context .= '.' . $layout;
}
// Adjust the context to support forced languages.
if ($forcedLanguage)
{
$this->context .= '.' . $forcedLanguage;
}
// Adjust the context to support forced languages.
if ($forcedLanguage) {
$this->context .= '.' . $forcedLanguage;
}
// Load the parameters.
$params = ComponentHelper::getParams('com_weblinks');
$this->setState('params', $params);
// Load the parameters.
$params = ComponentHelper::getParams('com_weblinks');
$this->setState('params', $params);
// Force a language.
if (!empty($forcedLanguage))
{
$this->setState('filter.language', $forcedLanguage);
}
// Force a language.
if (!empty($forcedLanguage)) {
$this->setState('filter.language', $forcedLanguage);
}
// List state information.
parent::populateState($ordering, $direction);
}
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.category_id');
$id .= ':' . $this->getState('filter.language');
$id .= ':' . $this->getState('filter.tag');
$id .= ':' . $this->getState('filter.level');
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.category_id');
$id .= ':' . $this->getState('filter.language');
$id .= ':' . $this->getState('filter.tag');
$id .= ':' . $this->getState('filter.level');
return parent::getStoreId($id);
}
return parent::getStoreId($id);
}
/**
* Build an SQL query to load the list data.
*
* @return \JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = $this->getCurrentUser();
/**
* Build an SQL query to load the list data.
*
* @return \JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = $this->getCurrentUser();
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, ' .
'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
)
);
$query->from($db->quoteName('#__weblinks', 'a'));
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, ' .
'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
)
);
$query->from($db->quoteName('#__weblinks', 'a'));
// Join over the language
$query->select($db->quoteName('l.title', 'language_title'))
->select($db->quoteName('l.image', 'language_image'))
->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->qn('l.lang_code') . ' = ' . $db->qn('a.language'));
// Join over the language
$query->select($db->quoteName('l.title', 'language_title'))
->select($db->quoteName('l.image', 'language_image'))
->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->qn('l.lang_code') . ' = ' . $db->qn('a.language'));
// Join over the users for the checked out user.
$query->select($db->quoteName('uc.name', 'editor'))
->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->qn('uc.id') . ' = ' . $db->qn('a.checked_out'));
// Join over the users for the checked out user.
$query->select($db->quoteName('uc.name', 'editor'))
->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->qn('uc.id') . ' = ' . $db->qn('a.checked_out'));
// Join over the asset groups.
$query->select($db->quoteName('ag.title', 'access_level'))
->join('LEFT', $db->quoteName('#__viewlevels', 'ag') . ' ON ' . $db->qn('ag.id') . ' = ' . $db->qn('a.access'));
// Join over the asset groups.
$query->select($db->quoteName('ag.title', 'access_level'))
->join('LEFT', $db->quoteName('#__viewlevels', 'ag') . ' ON ' . $db->qn('ag.id') . ' = ' . $db->qn('a.access'));
// Join over the categories.
$query->select('c.title AS category_title')
->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON ' . $db->qn('c.id') . ' = ' . $db->qn('a.catid'));
// Join over the categories.
$query->select('c.title AS category_title')
->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON ' . $db->qn('c.id') . ' = ' . $db->qn('a.catid'));
// Join over the associations.
$assoc = Associations::isEnabled();
// Join over the associations.
$assoc = Associations::isEnabled();
if ($assoc)
{
$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', 'asso2') . ' ON asso2.key = asso.key')
->group('a.id, l.title, l.image, uc.name, ag.title, c.title');
}
if ($assoc) {
$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', 'asso2') . ' ON asso2.key = asso.key')
->group('a.id, l.title, l.image, uc.name, ag.title, c.title');
}
// Filter by access level.
if ($access = $this->getState('filter.access'))
{
$query->where($db->quoteName('a.access') . ' = :access')
->bind(':access', $access, ParameterType::INTEGER);
}
// Filter by access level.
if ($access = $this->getState('filter.access')) {
$query->where($db->quoteName('a.access') . ' = :access')
->bind(':access', $access, ParameterType::INTEGER);
}
// Implement View Level Access
if (!$user->authorise('core.admin'))
{
$query->whereIn($db->quoteName('a.access'), $user->getAuthorisedViewLevels());
}
// Implement View Level Access
if (!$user->authorise('core.admin')) {
$query->whereIn($db->quoteName('a.access'), $user->getAuthorisedViewLevels());
}
// Filter by published state
$published = (string) $this->getState('filter.published');
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published))
{
$query->where($db->quoteName('a.state') . ' = :state')
->bind(':state', $published, ParameterType::INTEGER);
}
elseif ($published === '')
{
$query->whereIn($db->quoteName('a.state'), [0, 1]);
}
if (is_numeric($published)) {
$query->where($db->quoteName('a.state') . ' = :state')
->bind(':state', $published, ParameterType::INTEGER);
} elseif ($published === '') {
$query->whereIn($db->quoteName('a.state'), [0, 1]);
}
// Filter by category.
$categoryId = $this->getState('filter.category_id');
// Filter by category.
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId))
{
$query->where($db->quoteName('a.catid') . ' = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER);
}
if (is_numeric($categoryId)) {
$query->where($db->quoteName('a.catid') . ' = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER);
}
// Filter on the level.
if ($level = $this->getState('filter.level'))
{
$query->where($db->quoteName('c.level') . ' <= :level')
->bind(':level', $level, ParameterType::INTEGER);
}
// Filter on the level.
if ($level = $this->getState('filter.level')) {
$query->where($db->quoteName('c.level') . ' <= :level')
->bind(':level', $level, ParameterType::INTEGER);
}
// Filter by search in title
$search = $this->getState('filter.search');
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$search = substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $search, ParameterType::INTEGER);
}
else
{
$search = '%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%');
$query->where('(' . $db->quoteName('a.title') . ' LIKE :title OR ' . $db->quoteName('a.alias') . ' LIKE :alias)')
->bind(':title', $search)
->bind(':alias', $search);
}
}
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$search = substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $search, ParameterType::INTEGER);
} else {
$search = '%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%');
$query->where('(' . $db->quoteName('a.title') . ' LIKE :title OR ' . $db->quoteName('a.alias') . ' LIKE :alias)')
->bind(':title', $search)
->bind(':alias', $search);
}
}
// Filter on the language.
if ($language = $this->getState('filter.language'))
{
$query->where($db->quoteName('a.language') . ' = :language')
->bind(':language', $language);
}
// Filter on the language.
if ($language = $this->getState('filter.language')) {
$query->where($db->quoteName('a.language') . ' = :language')
->bind(':language', $language);
}
$tagId = $this->getState('filter.tag');
$tagId = $this->getState('filter.tag');
// Filter by a single tag.
if (is_numeric($tagId))
{
$query->where($db->quoteName('tagmap.tag_id') . ' = :tagId')
->bind(':tagId', $tagId, ParameterType::INTEGER)
->join(
'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap')
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink')
);
}
// Filter by a single tag.
if (is_numeric($tagId)) {
$query->where($db->quoteName('tagmap.tag_id') . ' = :tagId')
->bind(':tagId', $tagId, ParameterType::INTEGER)
->join(
'LEFT',
$db->quoteName('#__contentitem_tag_map', 'tagmap')
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink')
);
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'a.title');
$orderDirn = $this->state->get('list.direction', 'ASC');
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'a.title');
$orderDirn = $this->state->get('list.direction', 'ASC');
if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}
if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}
$query->order($db->escape($orderCol . ' ' . $orderDirn));
$query->order($db->escape($orderCol . ' ' . $orderDirn));
return $query;
}
return $query;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Service\HTML;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
@ -26,90 +28,74 @@ use Joomla\Database\ParameterType;
*/
class AdministratorService
{
/**
* Get the associated language flags
*
* @param integer $weblinkid The item id to search associations
*
* @return string The language HTML
*
* @throws \Exception
*/
public function association($weblinkid)
{
// Defaults
$html = '';
/**
* Get the associated language flags
*
* @param integer $weblinkid The item id to search associations
*
* @return string The language HTML
*
* @throws \Exception
*/
public function association($weblinkid)
{
// Defaults
$html = '';
// Get the associations
if ($associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $weblinkid)) {
foreach ($associations as $tag => $associated) {
$associations[$tag] = (int) $associated->id;
}
// Get the associations
if ($associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $weblinkid))
{
foreach ($associations as $tag => $associated)
{
$associations[$tag] = (int) $associated->id;
}
// Get the associated contact items
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select([
$db->quoteName('c.id'),
$db->quoteName('c.title', 'title'),
$db->quoteName('l.sef', 'lang_sef'),
$db->quoteName('lang_code'),
$db->quoteName('cat.title', 'category_title'),
$db->quoteName('l.image'),
$db->quoteName('l.title', 'language_title'),
])
->from($db->quoteName('#__weblinks', 'c'))
->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'))
->whereIn($db->quoteName('c.id'), array_values($associations))
->where($db->quoteName('c.id') . ' != :id')
->bind(':id', $weblinkid, ParameterType::INTEGER);
$db->setQuery($query);
try {
$items = $db->loadObjectList('id');
} catch (\RuntimeException $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
// Get the associated contact items
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select(
[
$db->quoteName('c.id'),
$db->quoteName('c.title', 'title'),
$db->quoteName('l.sef', 'lang_sef'),
$db->quoteName('lang_code'),
$db->quoteName('cat.title', 'category_title'),
$db->quoteName('l.image'),
$db->quoteName('l.title', 'language_title'),
]
)
->from($db->quoteName('#__weblinks', 'c'))
->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'))
->whereIn($db->quoteName('c.id'), array_values($associations))
->where($db->quoteName('c.id') . ' != :id')
->bind(':id', $weblinkid, ParameterType::INTEGER);
$db->setQuery($query);
if ($items) {
$app = Factory::getApplication();
$languages = LanguageHelper::getContentLanguages([0, 1]);
$content_languages = array_column($languages, 'lang_code');
foreach ($items as &$item) {
if (in_array($item->lang_code, $content_languages)) {
$text = $item->lang_code;
$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>'
. htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8')
. '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$classes = 'badge bg-secondary';
$item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>'
. '<div role="tooltip" id="tip-' . (int) $weblinkid . '-' . (int) $item->id . '">' . $tooltip . '</div>';
} else {
// Display warning if Content Language is trashed or deleted
$app->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
}
}
}
try
{
$items = $db->loadObjectList('id');
}
catch (\RuntimeException $e)
{
throw new \Exception($e->getMessage(), 500, $e);
}
$html = LayoutHelper::render('joomla.content.associations', $items);
}
if ($items)
{
$app = Factory::getApplication();
$languages = LanguageHelper::getContentLanguages(array(0, 1));
$content_languages = array_column($languages, 'lang_code');
foreach ($items as &$item)
{
if (in_array($item->lang_code, $content_languages))
{
$text = $item->lang_code;
$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>'
. htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8')
. '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$classes = 'badge bg-secondary';
$item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>'
. '<div role="tooltip" id="tip-' . (int) $weblinkid . '-' . (int) $item->id . '">' . $tooltip . '</div>';
}
else
{
// Display warning if Content Language is trashed or deleted
$app->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
}
}
}
$html = LayoutHelper::render('joomla.content.associations', $items);
}
return $html;
}
return $html;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Administrator\Service\HTML;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
@ -28,145 +30,125 @@ use Joomla\Registry\Registry;
*/
class Icon
{
/**
* The application
*
* @var CMSApplication
*
* @since 4.0.0
*/
private $application;
/**
* The application
*
* @var CMSApplication
*
* @since 4.0.0
*/
private $application;
/**
* Service constructor
*
* @param CMSApplication $application The application
*
* @since 4.0.0
*/
public function __construct(CMSApplication $application)
{
$this->application = $application;
}
/**
* Service constructor
*
* @param CMSApplication $application The application
*
* @since 4.0.0
*/
public function __construct(CMSApplication $application)
{
$this->application = $application;
}
/**
* Method to generate a link to the create item page for the given category
*
* @param object $category The category information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
*
* @return string The HTML markup for the create item link
*
* @since 4.0.0
*/
public static function create($category, $params, $attribs = [])
{
$uri = Uri::getInstance();
$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]);
// Add the button classes to the attribs array
if (isset($attribs['class'])) {
$attribs['class'] .= ' btn btn-primary';
} else {
$attribs['class'] = 'btn btn-primary';
}
/**
* Method to generate a link to the create item page for the given category
*
* @param object $category The category information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
*
* @return string The HTML markup for the create item link
*
* @since 4.0.0
*/
public static function create($category, $params, $attribs = array())
{
$uri = Uri::getInstance();
$button = HTMLHelper::_('link', Route::_($url), $text, $attribs);
$output = '<span class="hasTooltip" title="' . HTMLHelper::_('tooltipText', 'COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>';
return $output;
}
$url = 'index.php?option=com_weblinks&task=weblink.add&return=' . base64_encode($uri) . '&w_id=0&catid=' . $category->id;
/**
* Display an edit icon for the weblink.
*
* This icon will not display in a popup window, nor if the weblink is trashed.
* Edit access checks must be performed in the calling code.
*
* @param object $weblink The weblink information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML for the weblink edit icon.
*
* @since 4.0.0
*/
public static function edit($weblink, $params, $attribs = [], $legacy = false)
{
$user = Factory::getApplication()->getIdentity();
$uri = Uri::getInstance();
// Ignore if in a popup window.
if ($params && $params->get('popup')) {
return '';
}
$text = LayoutHelper::render('joomla.content.icons.create', array('params' => $params, 'legacy' => false));
// Ignore if the state is negative (trashed).
if ($weblink->state < 0) {
return '';
}
// Add the button classes to the attribs array
if (isset($attribs['class']))
{
$attribs['class'] .= ' btn btn-primary';
}
else
{
$attribs['class'] = 'btn btn-primary';
}
// Show checked_out icon if the contact is checked out by a different user
if (
property_exists($weblink, 'checked_out')
&& property_exists($weblink, 'checked_out_time')
&& $weblink->checked_out
&& $weblink->checked_out !== $user->get('id')
) {
$checkoutUser = Factory::getUser($weblink->checked_out);
$date = HTMLHelper::_('date', $weblink->checked_out_time);
$tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name)
. ' <br> ' . $date;
$text = LayoutHelper::render('joomla.content.icons.edit_lock', ['contact' => $weblink, 'tooltip' => $tooltip, 'legacy' => $legacy]);
$attribs['aria-describedby'] = 'editweblink-' . (int) $weblink->id;
$output = HTMLHelper::_('link', '#', $text, $attribs);
return $output;
}
$button = HTMLHelper::_('link', Route::_($url), $text, $attribs);
$weblinkUrl = RouteHelper::getWeblinkRoute($weblink->slug, $weblink->catid, $weblink->language);
$url = $weblinkUrl . '&task=weblink.edit&w_id=' . $weblink->id . '&return=' . base64_encode($uri);
if ((int) $weblink->state === 0) {
$tooltip = Text::_('COM_WEBLINKS_EDIT_UNPUBLISHED_WEBLINK');
} else {
$tooltip = Text::_('COM_WEBLINKS_EDIT_PUBLISHED_WEBLINK');
}
$output = '<span class="hasTooltip" title="' . HTMLHelper::_('tooltipText', 'COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>';
$nowDate = strtotime(Factory::getDate());
$icon = $weblink->state ? 'edit' : 'eye-slash';
return $output;
}
if (
($weblink->publish_up !== null && strtotime($weblink->publish_up) > $nowDate)
|| ($weblink->publish_down !== null && strtotime($weblink->publish_down) < $nowDate
&& $weblink->publish_down !== Factory::getDbo()->getNullDate())
) {
$icon = 'eye-slash';
}
/**
* Display an edit icon for the weblink.
*
* This icon will not display in a popup window, nor if the weblink is trashed.
* Edit access checks must be performed in the calling code.
*
* @param object $weblink The weblink information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML for the weblink edit icon.
*
* @since 4.0.0
*/
public static function edit($weblink, $params, $attribs = array(), $legacy = false)
{
$user = Factory::getApplication()->getIdentity();
$uri = Uri::getInstance();
// Ignore if in a popup window.
if ($params && $params->get('popup'))
{
return '';
}
// Ignore if the state is negative (trashed).
if ($weblink->state < 0)
{
return '';
}
// Show checked_out icon if the contact is checked out by a different user
if (property_exists($weblink, 'checked_out')
&& property_exists($weblink, 'checked_out_time')
&& $weblink->checked_out
&& $weblink->checked_out !== $user->get('id'))
{
$checkoutUser = Factory::getUser($weblink->checked_out);
$date = HTMLHelper::_('date', $weblink->checked_out_time);
$tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name)
. ' <br> ' . $date;
$text = LayoutHelper::render('joomla.content.icons.edit_lock', array('contact' => $weblink, 'tooltip' => $tooltip, 'legacy' => $legacy));
$attribs['aria-describedby'] = 'editweblink-' . (int) $weblink->id;
$output = HTMLHelper::_('link', '#', $text, $attribs);
return $output;
}
$weblinkUrl = RouteHelper::getWeblinkRoute($weblink->slug, $weblink->catid, $weblink->language);
$url = $weblinkUrl . '&task=weblink.edit&w_id=' . $weblink->id . '&return=' . base64_encode($uri);
if ((int) $weblink->state === 0)
{
$tooltip = Text::_('COM_WEBLINKS_EDIT_UNPUBLISHED_WEBLINK');
}
else
{
$tooltip = Text::_('COM_WEBLINKS_EDIT_PUBLISHED_WEBLINK');
}
$nowDate = strtotime(Factory::getDate());
$icon = $weblink->state ? 'edit' : 'eye-slash';
if (($weblink->publish_up !== null && strtotime($weblink->publish_up) > $nowDate)
|| ($weblink->publish_down !== null && strtotime($weblink->publish_down) < $nowDate
&& $weblink->publish_down !== Factory::getDbo()->getNullDate()))
{
$icon = 'eye-slash';
}
$aria_described = 'editweblink-' . (int) $weblink->id;
$text = '<span class="icon-' . $icon . '" aria-hidden="true"></span>';
$text .= Text::_('JGLOBAL_EDIT');
$text .= '<div role="tooltip" id="' . $aria_described . '">' . $tooltip . '</div>';
$attribs['aria-describedby'] = $aria_described;
$output = HTMLHelper::_('link', Route::_($url), $text, $attribs);
return $output;
}
$aria_described = 'editweblink-' . (int) $weblink->id;
$text = '<span class="icon-' . $icon . '" aria-hidden="true"></span>';
$text .= Text::_('JGLOBAL_EDIT');
$text .= '<div role="tooltip" id="' . $aria_described . '">' . $tooltip . '</div>';
$attribs['aria-describedby'] = $aria_described;
$output = HTMLHelper::_('link', Route::_($url), $text, $attribs);
return $output;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -21,8 +22,9 @@ use Joomla\CMS\Versioning\VersionableTableInterface;
use Joomla\Database\ParameterType;
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
*
@ -30,263 +32,223 @@ defined('_JEXEC') or die;
*/
class WeblinkTable extends Table implements VersionableTableInterface, TaggableTableInterface
{
use TaggableTableTrait;
use TaggableTableTrait;
/**
* Indicates that columns fully support the NULL value in the database
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $_supportNullValue = true;
/**
* Indicates that columns fully support the NULL value in the database
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
/**
* Ensure the params and metadata in json encoded in the bind method
*
* @var array
* @since 3.4
*/
protected $_jsonEncode = array('params', 'metadata', 'images');
/**
* Constructor
*
* @param \JDatabaseDriver &$db A database connector object
*
* @since 1.5
*/
public function __construct($db)
{
$this->typeAlias = 'com_weblinks.weblink';
protected $_supportNullValue = true;
/**
* Ensure the params and metadata in json encoded in the bind method
*
* @var array
* @since 3.4
*/
protected $_jsonEncode = ['params', 'metadata', 'images'];
/**
* Constructor
*
* @param \JDatabaseDriver &$db A database connector object
*
* @since 1.5
*/
public function __construct($db)
{
$this->typeAlias = 'com_weblinks.weblink';
parent::__construct('#__weblinks', 'id', $db);
// Set the published column alias
$this->setColumnAlias('published', 'state');
}
parent::__construct('#__weblinks', 'id', $db);
/**
* Overload the store method for the Weblinks table.
*
* @param boolean $updateNulls Toggle whether null values should be updated.
*
* @return boolean True on success, false on failure.
*
* @since 1.6
*/
public function store($updateNulls = true)
{
$date = Factory::getDate()->toSql();
$user = Factory::getApplication()->getIdentity();
$this->modified = $date;
if ($this->id) {
// Existing item
$this->modified_by = $user->id;
$this->modified = $date;
} else {
// 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.
if (!(int) $this->created) {
$this->created = $date;
}
// Set the published column alias
$this->setColumnAlias('published', 'state');
}
if (empty($this->created_by)) {
$this->created_by = $user->id;
}
/**
* Overload the store method for the Weblinks table.
*
* @param boolean $updateNulls Toggle whether null values should be updated.
*
* @return boolean True on success, false on failure.
*
* @since 1.6
*/
public function store($updateNulls = true)
{
$date = Factory::getDate()->toSql();
$user = Factory::getApplication()->getIdentity();
if (!(int) $this->modified) {
$this->modified = $date;
}
$this->modified = $date;
if (empty($this->modified_by)) {
$this->modified_by = $user->id;
}
if ($this->id)
{
// Existing item
$this->modified_by = $user->id;
$this->modified = $date;
}
else
{
// 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.
if (!(int) $this->created)
{
$this->created = $date;
}
if (empty($this->hits)) {
$this->hits = 0;
}
}
if (empty($this->created_by))
{
$this->created_by = $user->id;
}
// Set publish_up to null if not set
if (!$this->publish_up) {
$this->publish_up = null;
}
if (!(int) $this->modified)
{
$this->modified = $date;
}
// Set publish_down to null if not set
if (!$this->publish_down) {
$this->publish_down = null;
}
if (empty($this->modified_by))
{
$this->modified_by = $user->id;
}
// Verify that the alias is unique
$table = new WeblinkTable($this->getDbo());
if (empty($this->hits))
{
$this->hits = 0;
}
}
if (
$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'));
return false;
}
// Set publish_up to null if not set
if (!$this->publish_up)
{
$this->publish_up = null;
}
// Convert IDN urls to punycode
$this->url = PunycodeHelper::urlToPunycode($this->url);
return parent::store($updateNulls);
}
// Set publish_down to null if not set
if (!$this->publish_down)
{
$this->publish_down = null;
}
/**
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
*
* @since 1.5
*/
public function check()
{
if (InputFilter::checkAttribute(['href', $this->url])) {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
return false;
}
// Verify that the alias is unique
$table = new WeblinkTable($this->getDbo());
// Check for valid name
if (trim($this->title) == '') {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
return false;
}
if ($table->load(array('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'));
// Check for existing name
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__weblinks'))
->where($db->quoteName('title') . ' = :title')
->where($db->quoteName('language') . ' = :language')
->where($db->quoteName('catid') . ' = :catid')
->bind(':title', $this->title)
->bind(':language', $this->language)
->bind(':catid', $this->catid, ParameterType::INTEGER);
$db->setQuery($query);
$xid = (int) $db->loadResult();
if ($xid && $xid != (int) $this->id) {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME'));
return false;
}
return false;
}
if (empty($this->alias)) {
$this->alias = $this->title;
}
// Convert IDN urls to punycode
$this->url = PunycodeHelper::urlToPunycode($this->url);
$this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '') {
$this->alias = Factory::getDate()->format("Y-m-d-H-i-s");
}
return parent::store($updateNulls);
}
// Check the publish down date is not earlier than publish up.
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
/**
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
*
* @since 1.5
*/
public function check()
{
if (InputFilter::checkAttribute(array('href', $this->url)))
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
/*
* Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string
*/
if (!empty($this->metakey)) {
// Array of characters to remove
$bad_characters = ["\n", "\r", "\"", "<", ">"];
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean);
$clean_keys = [];
foreach ($keys as $key) {
// Ignore blank keywords
if (trim($key)) {
$clean_keys[] = trim($key);
}
}
return false;
}
// Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys);
}
// Check for valid name
if (trim($this->title) == '')
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
/**
* 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
*/
if (!$this->id) {
if (!isset($this->xreference)) {
$this->xreference = '';
}
return false;
}
if (!isset($this->metakey)) {
$this->metakey = '';
}
// Check for existing name
$db = $this->getDbo();
if (!isset($this->metadesc)) {
$this->metadesc = '';
}
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__weblinks'))
->where($db->quoteName('title') . ' = :title')
->where($db->quoteName('language') . ' = :language')
->where($db->quoteName('catid') . ' = :catid')
->bind(':title', $this->title)
->bind(':language', $this->language)
->bind(':catid', $this->catid, ParameterType::INTEGER);
$db->setQuery($query);
if (!isset($this->images)) {
$this->images = '{}';
}
$xid = (int) $db->loadResult();
if (!isset($this->metadata)) {
$this->metadata = '{}';
}
if ($xid && $xid != (int) $this->id)
{
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME'));
if (!isset($this->params)) {
$this->params = '{}';
}
}
return false;
}
return parent::check();
}
if (empty($this->alias))
{
$this->alias = $this->title;
}
$this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = Factory::getDate()->format("Y-m-d-H-i-s");
}
// Check the publish down date is not earlier than publish up.
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up)
{
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
/*
* Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string
*/
if (!empty($this->metakey))
{
// Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">");
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean);
$clean_keys = array();
foreach ($keys as $key)
{
// Ignore blank keywords
if (trim($key))
{
$clean_keys[] = trim($key);
}
}
// Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys);
}
/**
* 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
*/
if (!$this->id)
{
if (!isset($this->xreference))
{
$this->xreference = '';
}
if (!isset($this->metakey))
{
$this->metakey = '';
}
if (!isset($this->metadesc))
{
$this->metadesc = '';
}
if (!isset($this->images))
{
$this->images = '{}';
}
if (!isset($this->metadata))
{
$this->metadata = '{}';
}
if (!isset($this->params))
{
$this->params = '{}';
}
}
return parent::check();
}
/**
* Get the type alias for the history table
*
* @return string The alias as described above
*
* @since 4.0.0
*/
public function getTypeAlias()
{
return $this->typeAlias;
}
/**
* Get the type alias for the history table
*
* @return string The alias as described above
*
* @since 4.0.0
*/
public function getTypeAlias()
{
return $this->typeAlias;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Factory;
@ -27,150 +30,139 @@ use Joomla\CMS\Toolbar\ToolbarHelper;
*/
class HtmlView extends BaseHtmlView
{
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The active item
*
* @var object
*/
protected $item;
/**
* The active item
*
* @var object
*/
protected $item;
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
*/
protected $state;
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
*/
protected $state;
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd'))
{
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
$this->addToolbar();
$this->addToolbar();
parent::display($tpl);
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$app = Factory::getApplication();
$app->input->set('hidemainmenu', true);
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$app = Factory::getApplication();
$app->input->set('hidemainmenu', true);
$user = $this->getCurrentUser();
$isNew = ($this->item->id == 0);
$checkedOut = $this->item->checked_out && $this->item->checked_out !== $user->get('id');
$user = $this->getCurrentUser();
$isNew = ($this->item->id == 0);
$checkedOut = $this->item->checked_out && $this->item->checked_out !== $user->get('id');
// Since we don't track these assets at the item level, use the category id.
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->item->catid);
// Since we don't track these assets at the item level, use the category id.
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->item->catid);
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.
if ($isNew)
{
// For new records, check the create permission.
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{
ToolbarHelper::apply('weblink.apply');
// Build the actions for new and existing records.
if ($isNew) {
// For new records, check the create permission.
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) {
ToolbarHelper::apply('weblink.apply');
ToolbarHelper::saveGroup(
[
['save', 'weblink.save'],
['save2new', 'weblink.save2new']
],
'btn-success'
);
}
ToolbarHelper::saveGroup(
[
['save', 'weblink.save'],
['save2new', 'weblink.save2new'],
],
'btn-success'
);
}
ToolbarHelper::cancel('weblink.cancel');
}
else
{
// 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);
ToolbarHelper::cancel('weblink.cancel');
} else {
// 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);
$toolbarButtons = [];
$toolbarButtons = [];
// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable)
{
ToolbarHelper::apply('weblink.apply');
// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable) {
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.
if ($canDo->get('core.create'))
{
$toolbarButtons[] = ['save2new', 'weblink.save2new'];
}
}
// 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')) {
$toolbarButtons[] = ['save2new', 'weblink.save2new'];
}
}
// If checked out, we can still save
if ($canDo->get('core.create'))
{
$toolbarButtons[] = ['save2copy', 'weblink.save2copy'];
}
// If checked out, we can still save
if ($canDo->get('core.create')) {
$toolbarButtons[] = ['save2copy', 'weblink.save2copy'];
}
ToolbarHelper::saveGroup(
$toolbarButtons,
'btn-success'
);
ToolbarHelper::saveGroup(
$toolbarButtons,
'btn-success'
);
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)
{
ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
}
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) {
ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
}
if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations'))
{
ToolbarHelper::custom('weblink.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false);
}
}
if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) {
ToolbarHelper::custom('weblink.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false);
}
}
ToolbarHelper::help('Components_Weblinks_Links_Edit');
}
ToolbarHelper::help('Components_Weblinks_Links_Edit');
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Helper\ContentHelper;
@ -26,175 +29,164 @@ use Joomla\CMS\Toolbar\ToolbarHelper;
*/
class HtmlView extends BaseHtmlView
{
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* The pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
*/
protected $pagination;
/**
* The pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
*/
protected $pagination;
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
*/
protected $state;
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
*/
protected $state;
/**
* Form object for search filters
*
* @var \Joomla\CMS\Form\Form
*/
public $filterForm;
/**
* Form object for search filters
*
* @var \Joomla\CMS\Form\Form
*/
public $filterForm;
/**
* The active search filters
*
* @var array
*/
public $activeFilters;
/**
* The active search filters
*
* @var array
*/
public $activeFilters;
/**
* Is this view an Empty State
*
* @var boolean
* @since 4.0.0
*/
private $isEmptyState = false;
/**
* Is this view an Empty State
*
* @var boolean
* @since 4.0.0
*/
private $isEmptyState = false;
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->setLayout('emptystate');
}
// We don't need toolbar in the modal layout.
if ($this->getLayout() !== 'modal')
{
$this->addToolbar();
}
else
{
// 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.
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.
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// We don't need toolbar in the modal layout.
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
} else {
// 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.
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.
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
}
}
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
}
}
parent::display($tpl);
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->state->get('filter.category_id'));
$user = $this->getCurrentUser();
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->state->get('filter.category_id'));
$user = $this->getCurrentUser();
// Get the toolbar object instance
$toolbar = Toolbar::getInstance('toolbar');
// Get the toolbar object instance
$toolbar = Toolbar::getInstance('toolbar');
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)
{
ToolbarHelper::addNew('weblink.add');
}
if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) {
ToolbarHelper::addNew('weblink.add');
}
if (!$this->isEmptyState && $canDo->get('core.edit.state'))
{
$dropdown = $toolbar->dropdownButton('status-group')
->text('JTOOLBAR_CHANGE_STATUS')
->toggleSplit(false)
->icon('icon-ellipsis-h')
->buttonClass('btn btn-action')
->listCheck(true);
if (!$this->isEmptyState && $canDo->get('core.edit.state')) {
$dropdown = $toolbar->dropdownButton('status-group')
->text('JTOOLBAR_CHANGE_STATUS')
->toggleSplit(false)
->icon('icon-ellipsis-h')
->buttonClass('btn btn-action')
->listCheck(true);
$childBar = $dropdown->getChildToolbar();
$childBar = $dropdown->getChildToolbar();
$childBar->publish('weblinks.publish')->listCheck(true);
$childBar->publish('weblinks.publish')->listCheck(true);
$childBar->unpublish('weblinks.unpublish')->listCheck(true);
$childBar->unpublish('weblinks.unpublish')->listCheck(true);
$childBar->archive('weblinks.archive')->listCheck(true);
$childBar->archive('weblinks.archive')->listCheck(true);
if ($user->authorise('core.admin'))
{
$childBar->checkin('weblinks.checkin')->listCheck(true);
}
if ($user->authorise('core.admin')) {
$childBar->checkin('weblinks.checkin')->listCheck(true);
}
if ($this->state->get('filter.published') != -2)
{
$childBar->trash('weblinks.trash')->listCheck(true);
}
if ($this->state->get('filter.published') != -2) {
$childBar->trash('weblinks.trash')->listCheck(true);
}
// Add a batch button
if ($user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks'))
{
$childBar->popupButton('batch')
->text('JTOOLBAR_BATCH')
->selector('collapseModal')
->listCheck(true);
}
}
// Add a batch button
if (
$user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')
) {
$childBar->popupButton('batch')
->text('JTOOLBAR_BATCH')
->selector('collapseModal')
->listCheck(true);
}
}
if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete'))
{
$toolbar->delete('weblinks.delete')
->text('JTOOLBAR_EMPTY_TRASH')
->message('JGLOBAL_CONFIRM_DELETE')
->listCheck(true);
}
if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
$toolbar->delete('weblinks.delete')
->text('JTOOLBAR_EMPTY_TRASH')
->message('JGLOBAL_CONFIRM_DELETE')
->listCheck(true);
}
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
{
ToolbarHelper::preferences('com_weblinks');
}
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks')) {
ToolbarHelper::preferences('com_weblinks');
}
ToolbarHelper::help('Components_Weblinks_Links');
}
ToolbarHelper::help('Components_Weblinks_Links');
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,26 +8,22 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
HTMLHelper::_('behavior.formvalidator');
$app = Factory::getApplication();
$input = $app->input;
$assoc = Associations::isEnabled();
// Fieldsets to not automatically render by /layouts/joomla/edit/params.php
$this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata');
$this->useCoreUI = true;
// In case of modal
$isModal = $input->get('layout') == 'modal' ? true : false;
$layout = $isModal ? 'modal' : 'edit';
@ -35,81 +32,87 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<form action="<?php echo Route::_('index.php?option=com_weblinks&layout=' . $layout . $tmpl . '&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="weblink-form" class="form-validate">
<?php echo LayoutHelper::render('joomla.edit.title_alias', $this); ?>
<?php echo LayoutHelper::render('joomla.edit.title_alias', $this); ?>
<div class="main-card">
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => 'details')); ?>
<div class="main-card">
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => 'details')); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'details', empty($this->item->id) ? Text::_('COM_WEBLINKS_NEW_WEBLINK', true) : Text::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?>
<div class="row">
<div class="col-md-9">
<div class="form-vertical">
<div>
<fieldset class="adminform">
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('description'); ?>
</fieldset>
</div>
</div>
</div>
<div class="col-md-3">
<?php echo LayoutHelper::render('joomla.edit.global', $this); ?>
</div>
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'details', empty($this->item->id) ? Text::_('COM_WEBLINKS_NEW_WEBLINK', true) : Text::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?>
<div class="row">
<div class="col-md-9">
<div class="form-vertical">
<div>
<fieldset class="adminform">
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('description'); ?>
</fieldset>
</div>
</div>
</div>
<div class="col-md-3">
<?php echo LayoutHelper::render('joomla.edit.global', $this); ?>
</div>
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'images', Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS', true)); ?>
<div class="row">
<div class="col-12">
<fieldset id="fieldset-image; ?>" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS'); ?></legend>
<div>
<?php echo $this->form->renderField('imaJGLOBAL_FIELDSET_IMAGE_OPTIONSges'); ?>
<?php foreach ($this->form->getGroup('images') as $field) : ?>
<?php echo $field->renderField(); ?>
<?php endforeach; ?>
</div>
</fieldset>
</div>
</div>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'images', Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS', true)); ?>
<div class="row">
<div class="col-12">
<fieldset id="fieldset-image; ?>" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS'); ?></legend>
<div>
<?php echo $this->form->renderField('imaJGLOBAL_FIELDSET_IMAGE_OPTIONSges'); ?>
<?php foreach ($this->form->getGroup('images') as $field) :
?>
<?php echo $field->renderField(); ?>
<?php
endforeach; ?>
</div>
</fieldset>
</div>
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'publishing', Text::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>
<div class="row">
<div class="col-12 col-lg-6">
<fieldset id="fieldset-publishingdata" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_PUBLISHING'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.publishingdata', $this); ?>
</fieldset>
</div>
<div class="col-12 col-lg-6">
<fieldset id="fieldset-metadata" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_METADATA_OPTIONS'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.metadata', $this); ?>
</fieldset>
</div>
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'publishing', Text::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>
<div class="row">
<div class="col-12 col-lg-6">
<fieldset id="fieldset-publishingdata" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_PUBLISHING'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.publishingdata', $this); ?>
</fieldset>
</div>
<div class="col-12 col-lg-6">
<fieldset id="fieldset-metadata" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_METADATA_OPTIONS'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.metadata', $this); ?>
</fieldset>
</div>
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php echo LayoutHelper::render('joomla.edit.params', $this); ?>
<?php echo LayoutHelper::render('joomla.edit.params', $this); ?>
<?php if (!$isModal && $assoc) : ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'associations', Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<fieldset id="fieldset-associations" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.associations', $this); ?>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php elseif ($isModal && $assoc) : ?>
<div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
<?php endif; ?>
<?php if (!$isModal && $assoc) :
?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'associations', Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<fieldset id="fieldset-associations" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_ASSOCIATIONS'); ?></legend>
<?php echo LayoutHelper::render('joomla.edit.associations', $this); ?>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php
elseif ($isModal && $assoc) :
?>
<div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
<?php
endif; ?>
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
</div>
</div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo HTMLHelper::_('form.token'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -7,8 +8,8 @@
* @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;
echo LayoutHelper::render('joomla.edit.associations', $this);

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,8 +8,8 @@
* @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;
echo LayoutHelper::render('joomla.edit.metadata', $this);

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,21 +8,27 @@
* @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;
$fieldSets = $this->form->getFieldsets('params'); ?>
<?php foreach ($fieldSets as $name => $fieldSet) : ?>
<div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) : ?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php foreach ($fieldSets as $name => $fieldSet) :
?>
<div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) :
?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php
endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) :
?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php
endforeach; ?>
</div>
<?php
endforeach; ?>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -6,16 +7,15 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @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\HTML\HTMLHelper;
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.
$function = Factory::getApplication()->input->getCmd('function', 'jEditWeblink_' . (int) $this->item->id);
// Function to update input title when changed
Factory::getDocument()->addScriptDeclaration('
function jEditWeblinkModal() {
@ -30,6 +30,6 @@ Factory::getDocument()->addScriptDeclaration('
<button id="closeBtn" type="button" class="hidden" onclick="Joomla.submitbutton('weblink.cancel');"></button>
<div class="container-popup">
<?php $this->setLayout('edit'); ?>
<?php echo $this->loadTemplate(); ?>
<?php $this->setLayout('edit'); ?>
<?php echo $this->loadTemplate(); ?>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -7,8 +8,8 @@
* @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;
echo LayoutHelper::render('joomla.edit.associations', $this);

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -7,8 +8,8 @@
* @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;
echo LayoutHelper::render('joomla.edit.metadata', $this);

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -7,21 +8,27 @@
* @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;
$fieldSets = $this->form->getFieldsets('params'); ?>
<?php foreach ($fieldSets as $name => $fieldSet) : ?>
<div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) : ?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php foreach ($fieldSets as $name => $fieldSet) :
?>
<div class="tab-pane" id="params-<?php echo $name; ?>">
<?php if (isset($fieldSet->description) && trim($fieldSet->description)) :
?>
<?php echo '<p class="alert alert-info">' . $this->escape(Text::_($fieldSet->description)) . '</p>'; ?>
<?php
endif; ?>
<?php foreach ($this->form->getFieldset($name) as $field) :
?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php
endforeach; ?>
</div>
<?php
endforeach; ?>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,8 +8,9 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations;
@ -16,182 +18,200 @@ use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\Weblinks\Administrator\View\Weblinks\HtmlView $this */
HTMLHelper::_('behavior.multiselect');
$user = Factory::getApplication()->getIdentity();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';
$assoc = Associations::isEnabled();
if ($saveOrder && !empty($this->items))
{
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
if ($saveOrder && !empty($this->items)) {
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
}
?>
<form action="<?php echo Route::_('index.php?option=com_weblinks&view=weblinks'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<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'); ?>
</div>
<?php else : ?>
<table class="table" id="weblinkList">
<caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
<span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
</caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<th scope="col" style="min-width:85px" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?>
</th>
<?php if ($assoc) : ?>
<th scope="col" class="w-10">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<?php if (Multilanguage::isEnabled()) : ?>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<th scope="col" class="w-5 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody <?php if ($saveOrder) :?> 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 $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); ?>
<?php $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); ?>
<?php $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || !$item->checked_out; ?>
<?php $canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $item->catid) && $item->created_by == $user->id; ?>
<?php $canChange = $user->authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin; ?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->catid; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php
$iconClass = '';
if (!$canChange)
{
$iconClass = ' inactive';
}
elseif (!$saveOrder)
{
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
}
?>
<span class="sortable-handler<?php echo $iconClass; ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span>
</span>
<?php if ($canChange && $saveOrder) : ?>
<input type="text" name="order[]" size="5"
value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
<?php endif; ?>
</td>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
</td>
<th scope="row" class="has-context">
<div>
<?php if ($item->checked_out) : ?>
<?php echo HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?>
<?php 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); ?>">
<?php echo $this->escape($item->title); ?></a>
<?php else : ?>
<?php echo $this->escape($item->title); ?>
<?php endif; ?>
<span class="small">
<?php echo Text::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?>
</span>
<div class="small">
<?php echo Text::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div>
</div>
</th>
<td class="small d-none d-md-table-cell">
<?php echo $this->escape($item->access_level); ?>
</td>
<td class="d-none d-md-table-cell">
<?php echo $item->hits; ?>
</td>
<?php if ($assoc) : ?>
<td class="hidden-phone hidden-tablet">
<?php if ($item->association) : ?>
<?php echo HTMLHelper::_('weblinksadministrator.association', $item->id); ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if (Multilanguage::isEnabled()) : ?>
<td class="small d-none d-md-table-cell">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td>
<?php endif; ?>
<td class="d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
?>
<?php if (empty($this->items)) :
?>
<div class="alert alert-info">
<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'); ?>
</div>
<?php
else :
?>
<table class="table" id="weblinkList">
<caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
<span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
</caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<th scope="col" style="min-width:85px" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?>
</th>
<?php if ($assoc) :
?>
<th scope="col" class="w-10">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?>
</th>
<?php
endif; ?>
<?php if (Multilanguage::isEnabled()) :
?>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?>
</th>
<?php
endif; ?>
<th scope="col" class="w-5 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody <?php if ($saveOrder) :
?> 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 $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); ?>
<?php $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); ?>
<?php $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || !$item->checked_out; ?>
<?php $canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $item->catid) && $item->created_by == $user->id; ?>
<?php $canChange = $user->authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin; ?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->catid; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php
$iconClass = '';
if (!$canChange) {
$iconClass = ' inactive';
} elseif (!$saveOrder) {
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
}
?>
<span class="sortable-handler<?php echo $iconClass; ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span>
</span>
<?php if ($canChange && $saveOrder) :
?>
<input type="text" name="order[]" size="5"
value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
<?php
endif; ?>
</td>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
</td>
<th scope="row" class="has-context">
<div>
<?php if ($item->checked_out) :
?>
<?php echo HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?>
<?php
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); ?>">
<?php echo $this->escape($item->title); ?></a>
<?php
else :
?>
<?php echo $this->escape($item->title); ?>
<?php
endif; ?>
<span class="small">
<?php echo Text::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?>
</span>
<div class="small">
<?php echo Text::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div>
</div>
</th>
<td class="small d-none d-md-table-cell">
<?php echo $this->escape($item->access_level); ?>
</td>
<td class="d-none d-md-table-cell">
<?php echo $item->hits; ?>
</td>
<?php if ($assoc) :
?>
<td class="hidden-phone hidden-tablet">
<?php if ($item->association) :
?>
<?php echo HTMLHelper::_('weblinksadministrator.association', $item->id); ?>
<?php
endif; ?>
</td>
<?php
endif; ?>
<?php if (Multilanguage::isEnabled()) :
?>
<td class="small d-none d-md-table-cell">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td>
<?php
endif; ?>
<td class="d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php
endforeach; ?>
</tbody>
</table>
<?php // Load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>
<?php // Load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>
<?php // Load the batch processing form. ?>
<?php if ($user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')) : ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
[
'title' => Text::_('COM_WEBLINKS_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer')
],
$this->loadTemplate('batch_body')
); ?>
<?php endif; ?>
<?php endif; ?>
<?php // Load the batch processing form. ?>
<?php if (
$user->authorise('core.create', 'com_weblinks')
&& $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')
) :
?>
<?php echo HTMLHelper::_('bootstrap.renderModal', 'collapseModal', [
'title' => Text::_('COM_WEBLINKS_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer')
], $this->loadTemplate('batch_body')); ?>
<?php
endif; ?>
<?php
endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
</form>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -6,41 +7,46 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @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\Layout\LayoutHelper;
$published = $this->state->get('filter.published');
?>
<div class="p-3">
<div class="row">
<?php if (Multilanguage::isEnabled()) : ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.language', []); ?>
</div>
</div>
<?php endif; ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.access', []); ?>
</div>
</div>
</div>
<div class="row">
<?php if ($published >= 0) : ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.item', ['extension' => 'com_weblinks']); ?>
</div>
</div>
<?php endif; ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.tag', []); ?>
</div>
</div>
</div>
<div class="row">
<?php if (Multilanguage::isEnabled()) :
?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.language', []); ?>
</div>
</div>
<?php
endif; ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.access', []); ?>
</div>
</div>
</div>
<div class="row">
<?php if ($published >= 0) :
?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.item', ['extension' => 'com_weblinks']); ?>
</div>
</div>
<?php
endif; ?>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.tag', []); ?>
</div>
</div>
</div>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -6,14 +7,16 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @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;
?>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<?php echo Text::_('JCANCEL'); ?>
<?php echo Text::_('JCANCEL'); ?>
</button>
<button type="submit" id='batch-submit-button-id' class="btn btn-success" onclick="Joomla.submitbutton('weblink.batch');return false;">
<?php echo Text::_('JGLOBAL_BATCH_PROCESS'); ?>
<?php echo Text::_('JGLOBAL_BATCH_PROCESS'); ?>
</button>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,23 +8,20 @@
* @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\Layout\LayoutHelper;
$displayData = [
'textPrefix' => 'COM_WEBLINKS',
'formURL' => 'index.php?option=com_weblinks',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help4.x:Weblinks',
'icon' => 'icon-globe weblink',
'textPrefix' => 'COM_WEBLINKS',
'formURL' => 'index.php?option=com_weblinks',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help4.x:Weblinks',
'icon' => 'icon-globe weblink',
];
$user = Factory::getApplication()->getIdentity();
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';
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';
}
echo LayoutHelper::render('joomla.content.emptystate', $displayData);
echo LayoutHelper::render('joomla.content.emptystate', $displayData);

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
@ -7,8 +8,9 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
@ -17,139 +19,148 @@ use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
$app = Factory::getApplication();
if ($app->isClient('site'))
{
Session::checkToken('get') or die(Text::_('JINVALID_TOKEN'));
if ($app->isClient('site')) {
Session::checkToken('get') or die(Text::_('JINVALID_TOKEN'));
}
HTMLHelper::_('behavior.multiselect');
$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');
$editor = $app->input->getCmd('editor', '');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$onclick = $this->escape($function);
$multilang = Multilanguage::isEnabled();
if (!empty($editor))
{
// 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));
$onclick = "jSelectWeblink";
if (!empty($editor)) {
// 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));
$onclick = "jSelectWeblink";
}
$iconStates = array(
-2 => 'icon-trash',
0 => 'icon-unpublish',
1 => 'icon-publish',
2 => 'icon-archive',
-2 => 'icon-trash',
0 => 'icon-unpublish',
1 => 'icon-publish',
2 => 'icon-archive',
);
?>
<div class="container-popup">
<form action="<?php echo Route::_('index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&function=' . $function . '&' . Session::getFormToken() . '=1&editor=' . $editor); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
<form action="<?php echo Route::_('index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&function=' . $function . '&' . Session::getFormToken() . '=1&editor=' . $editor); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
<?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)) : ?>
<div class="alert alert-no-items">
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else : ?>
<table class="table table-sm">
<caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
<span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
</caption>
<thead>
<tr>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="title">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $listDirn, $listOrder); ?>
</th>
<?php if ($multilang) : ?>
<th scope="col" class="w-15">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JDATE', 'a.created', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-1 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) : ?>
<?php $lang = ''; ?>
<?php if ($item->language && $multilang) : ?>
<?php $tag = strlen($item->language); ?>
<?php if ($tag == 5) : ?>
<?php $lang = substr($item->language, 0, 2); ?>
<?php elseif ($tag == 6) : ?>
<?php $lang = substr($item->language, 0, 3); ?>
<?php endif; ?>
<?php endif; ?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span>
</td>
<th scope="row">
<?php $attribs = 'data-function="' . $this->escape($onclick) . '"'
. ' data-id="' . $item->id . '"'
. ' data-title="' . $this->escape(addslashes($item->title)) . '"'
. ' data-cat-id="' . $this->escape($item->catid) . '"'
. ' data-uri="' . $this->escape(RouteHelper::getWeblinkRoute($item->id, $item->catid, $item->language)) . '"'
. ' data-language="' . $this->escape($lang) . '"';
?>
<a class="select-link" href="javascript:void(0)" <?php echo $attribs; ?>>
<?php echo $this->escape($item->title); ?>
</a>
<div class="small">
<?php echo Text::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div>
</th>
<td class="small d-none d-md-table-cell">
<?php echo $this->escape($item->access_level); ?>
</td>
<?php if ($multilang) : ?>
<td class="small">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td>
<?php endif; ?>
<td class="small d-none d-md-table-cell">
<?php echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC4')); ?>
</td>
<td class="small d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php if (empty($this->items)) :
?>
<div class="alert alert-no-items">
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php
else :
?>
<table class="table table-sm">
<caption class="visually-hidden">
<?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
<span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
</caption>
<thead>
<tr>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="title">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $listDirn, $listOrder); ?>
</th>
<?php if ($multilang) :
?>
<th scope="col" class="w-15">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language', $listDirn, $listOrder); ?>
</th>
<?php
endif; ?>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JDATE', 'a.created', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-1 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) :
?>
<?php $lang = ''; ?>
<?php if ($item->language && $multilang) :
?>
<?php $tag = strlen($item->language); ?>
<?php if ($tag == 5) :
?>
<?php $lang = substr($item->language, 0, 2); ?>
<?php
elseif ($tag == 6) :
?>
<?php $lang = substr($item->language, 0, 3); ?>
<?php
endif; ?>
<?php
endif; ?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span>
</td>
<th scope="row">
<?php $attribs = 'data-function="' . $this->escape($onclick) . '"'
. ' data-id="' . $item->id . '"'
. ' data-title="' . $this->escape(addslashes($item->title)) . '"'
. ' data-cat-id="' . $this->escape($item->catid) . '"'
. ' data-uri="' . $this->escape(RouteHelper::getWeblinkRoute($item->id, $item->catid, $item->language)) . '"'
. ' data-language="' . $this->escape($lang) . '"';
?>
<a class="select-link" href="javascript:void(0)" <?php echo $attribs; ?>>
<?php echo $this->escape($item->title); ?>
</a>
<div class="small">
<?php echo Text::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div>
</th>
<td class="small d-none d-md-table-cell">
<?php echo $this->escape($item->access_level); ?>
</td>
<?php if ($multilang) :
?>
<td class="small">
<?php echo LayoutHelper::render('joomla.content.language', $item); ?>
</td>
<?php
endif; ?>
<td class="small d-none d-md-table-cell">
<?php echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC4')); ?>
</td>
<td class="small d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php
endforeach; ?>
</tbody>
</table>
<?php
endif; ?>
<?php // load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>
<?php // load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="forcedLanguage" value="<?php echo $app->input->get('forcedLanguage', '', 'CMD'); ?>" />
<?php echo HTMLHelper::_('form.token'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="forcedLanguage" value="<?php echo $app->input->get('forcedLanguage', '', 'CMD'); ?>" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>
</form>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,8 +8,9 @@
* @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
*
@ -16,14 +18,14 @@ defined('_JEXEC') or die;
*/
class Pkg_WeblinksInstallerScript extends JInstallerScript
{
/**
* Extension script constructor.
*
* @since __DEPLOY_VERSION__
*/
public function __construct()
{
$this->minimumJoomla = '3.6.3';
$this->minimumPhp = JOOMLA_MINIMUM_PHP;
}
/**
* Extension script constructor.
*
* @since __DEPLOY_VERSION__
*/
public function __construct()
{
$this->minimumJoomla = '3.6.3';
$this->minimumPhp = JOOMLA_MINIMUM_PHP;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,8 +8,9 @@
* @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.
*
@ -16,40 +18,40 @@ defined('_JEXEC') or die;
*/
class JHtmlIcon
{
/**
* Create a link to create a new weblink
*
* @param object $category The category information
* @param \Joomla\Registry\Registry $params The item parameters
*
* @return string
*/
public static function create($category, $params)
{
return self::getIcon()->create($category, $params);
}
/**
* Create a link to create a new weblink
*
* @param object $category The category information
* @param \Joomla\Registry\Registry $params The item parameters
*
* @return string
*/
public static function create($category, $params)
{
return self::getIcon()->create($category, $params);
}
/**
* Create a link to edit an existing weblink
*
* @param object $weblink Weblink data
* @param \Joomla\Registry\Registry $params Item params
* @param array $attribs Unused
*
* @return string
*/
public static function edit($weblink, $params, $attribs = array())
{
return self::getIcon()->edit($weblink, $params, $attribs);
}
/**
* Create a link to edit an existing weblink
*
* @param object $weblink Weblink data
* @param \Joomla\Registry\Registry $params Item params
* @param array $attribs Unused
*
* @return string
*/
public static function edit($weblink, $params, $attribs = [])
{
return self::getIcon()->edit($weblink, $params, $attribs);
}
/**
* Creates an icon instance.
*
* @return \Joomla\Component\Weblinks\Administrator\Service\HTML\Icon
*/
private static function getIcon()
{
return (new \Joomla\Component\Weblinks\Administrator\Service\HTML\Icon(Joomla\CMS\Factory::getApplication()));
}
/**
* Creates an icon instance.
*
* @return \Joomla\Component\Weblinks\Administrator\Service\HTML\Icon
*/
private static function getIcon()
{
return (new \Joomla\Component\Weblinks\Administrator\Service\HTML\Icon(Joomla\CMS\Factory::getApplication()));
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,8 +8,9 @@
* @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;
/**
@ -18,5 +20,4 @@ use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
*/
abstract class WeblinksHelperRoute extends RouteHelper
{
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,8 +10,9 @@
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\MVC\Controller\BaseController;
@ -21,52 +23,47 @@ use Joomla\CMS\MVC\Controller\BaseController;
*/
class DisplayController extends BaseController
{
/**
* Method to display a view.
*
* @param boolean $cacheable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return BaseController This object to support chaining.
*
* @since 1.5
*/
public function display($cacheable = false, $urlparams = false)
{
// Huh? Why not just put that in the constructor?
$cacheable = true;
/**
* Method to display a view.
*
* @param boolean $cacheable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return BaseController This object to support chaining.
*
* @since 1.5
*/
public function display($cacheable = false, $urlparams = false)
{
// Huh? Why not just put that in the constructor?
$cacheable = true;
/**
* 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.
* Frontend is a bit messier than the backend.
*/
$id = $this->input->getInt('w_id');
$vName = $this->input->get('view', 'categories');
$this->input->set('view', $vName);
if ($this->app->getIdentity()->id || ($this->input->getMethod() == 'POST' && $vName == 'categories')) {
$cacheable = false;
}
/**
* 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.
* Frontend is a bit messier than the backend.
*/
$id = $this->input->getInt('w_id');
$vName = $this->input->get('view', 'categories');
$this->input->set('view', $vName);
$safeurlparams = [
'id' => 'INT',
'limit' => 'UINT',
'limitstart' => 'UINT',
'filter_order' => 'CMD',
'filter_order_Dir' => 'CMD',
'lang' => 'CMD',
];
// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) {
// 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);
}
if ($this->app->getIdentity()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories'))
{
$cacheable = false;
}
$safeurlparams = array(
'id' => 'INT',
'limit' => 'UINT',
'limitstart' => 'UINT',
'filter_order' => 'CMD',
'filter_order_Dir' => 'CMD',
'lang' => 'CMD'
);
// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{
// 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);
}
return parent::display($cacheable, $safeurlparams);
}
return parent::display($cacheable, $safeurlparams);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,8 +10,9 @@
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\MVC\Controller\FormController;
use Joomla\CMS\Uri\Uri;
@ -23,311 +25,275 @@ use Joomla\Utilities\ArrayHelper;
*/
class WeblinkController extends FormController
{
/**
* The URL view item variable.
*
* @var string
* @since 1.6
*/
protected $view_item = 'form';
/**
* The URL view item variable.
*
* @var string
* @since 1.6
*/
protected $view_item = 'form';
/**
* The URL view list variable.
*
* @var string
* @since 1.6
*/
protected $view_list = 'categories';
/**
* The URL edit variable.
*
* @var string
* @since 3.2
*/
protected $urlVar = 'a.id';
/**
* Method to add a new record.
*
* @return boolean True if the article can be added, false if not.
*
* @since 1.6
*/
public function add()
{
if (!parent::add()) {
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
return false;
}
/**
* The URL view list variable.
*
* @var string
* @since 1.6
*/
protected $view_list = 'categories';
return true;
}
/**
* The URL edit variable.
*
* @var string
* @since 3.2
*/
protected $urlVar = 'a.id';
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 1.6
*/
protected function allowAdd($data = [])
{
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int');
if ($categoryId) {
// If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
/**
* Method to add a new record.
*
* @return boolean True if the article can be added, false if not.
*
* @since 1.6
*/
public function add()
{
if (!parent::add())
{
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
// In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
}
return false;
}
/**
* Method to check if you can add a new record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowEdit($data = [], $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
if (!$recordId) {
return false;
}
return true;
}
$record = $this->getModel()->getItem($recordId);
$categoryId = (int) $record->catid;
if ($categoryId) {
// The category has been set. Check the category permissions.
$user = $this->app->getIdentity();
// First, check edit permission
if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId)) {
return true;
}
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 1.6
*/
protected function allowAdd($data = array())
{
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int');
// Fallback on edit.own
if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId) && $record->created_by == $user->id) {
return true;
}
if ($categoryId)
{
// If the category has been passed in the URL check it.
return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
return false;
}
// In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
/**
* Method to check if you can add a new record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 1.6
*/
public function cancel($key = 'w_id')
{
$return = parent::cancel($key);
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
return $return;
}
if (!$recordId)
{
return false;
}
/**
* Method to edit an existing record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if access level check and checkout passes, false otherwise.
*
* @since 1.6
*/
public function edit($key = null, $urlVar = 'w_id')
{
return parent::edit($key, $urlVar);
}
$record = $this->getModel()->getItem($recordId);
$categoryId = (int) $record->catid;
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 1.5
*/
public function getModel($name = 'form', $prefix = 'Site', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
if ($categoryId)
{
// The category has been set. Check the category permissions.
$user = $this->app->getIdentity();
/**
* Gets the URL arguments to append to an item redirect.
*
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*
* @since 1.6
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = null)
{
$append = parent::getRedirectToItemAppend($recordId, $urlVar);
$itemId = $this->input->getInt('Itemid');
$return = $this->getReturnPage();
if ($itemId) {
$append .= '&Itemid=' . $itemId;
}
// First, check edit permission
if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId))
{
return true;
}
if ($return) {
$append .= '&return=' . base64_encode($return);
}
// Fallback on edit.own
if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId) && $record->created_by == $user->id)
{
return true;
}
return $append;
}
return false;
}
/**
* Get the return URL if a "return" variable has been passed in the request
*
* @return string The return URL.
*
* @since 1.6
*/
protected function getReturnPage()
{
$return = $this->input->get('return', null, 'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
return Uri::base();
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
return base64_decode($return);
}
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 1.6
*/
public function cancel($key = 'w_id')
{
$return = parent::cancel($key);
/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*
* @since 1.6
*/
public function save($key = null, $urlVar = 'w_id')
{
// Get the application
$app = $this->app;
// Get the data from POST
$data = $this->input->post->get('jform', [], 'array');
// Save the data in the session.
$app->setUserState('com_weblinks.edit.weblink.data', $data);
$result = parent::save($key, $urlVar);
// If ok, redirect to the return page.
if ($result) {
// Flush the data from the session
$app->setUserState('com_weblinks.edit.weblink.data', null);
$this->setRedirect($this->getReturnPage());
}
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
return $result;
}
return $return;
}
/**
* Go to a weblink
*
* @return void
*
* @throws \Exception
*
* @since 1.6
*/
public function go()
{
// Get the ID from the request
$id = $this->input->getInt('id');
// Get the model, requiring published items
$modelLink = $this->getModel('Weblink');
$modelLink->setState('filter.published', 1);
// Get the item
$link = $modelLink->getItem($id);
// Make sure the item was found.
if (empty($link)) {
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
/**
* Method to edit an existing record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if access level check and checkout passes, false otherwise.
*
* @since 1.6
*/
public function edit($key = null, $urlVar = 'w_id')
{
return parent::edit($key, $urlVar);
}
// Check whether item access level allows access.
$groups = $this->app->getIdentity()->getAuthorisedViewLevels();
if (!in_array($link->access, $groups)) {
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 1.5
*/
public function getModel($name = 'form', $prefix = 'Site', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}
// Check whether category access level allows access.
$modelCat = $this->getModel('Category', 'Site', ['ignore_request' => true]);
$modelCat->setState('filter.published', 1);
// Get the category
$category = $modelCat->getCategory($link->catid);
// Make sure the category was found.
if (empty($category)) {
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
/**
* Gets the URL arguments to append to an item redirect.
*
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*
* @since 1.6
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = null)
{
$append = parent::getRedirectToItemAppend($recordId, $urlVar);
$itemId = $this->input->getInt('Itemid');
$return = $this->getReturnPage();
// Check whether item access level allows access.
if (!in_array($category->access, $groups)) {
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
if ($itemId)
{
$append .= '&Itemid=' . $itemId;
}
// Redirect to the URL
if ($link->url) {
$modelLink->hit($id);
$this->app->redirect($link->url, 301);
}
if ($return)
{
$append .= '&return=' . base64_encode($return);
}
return $append;
}
/**
* Get the return URL if a "return" variable has been passed in the request
*
* @return string The return URL.
*
* @since 1.6
*/
protected function getReturnPage()
{
$return = $this->input->get('return', null, 'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return)))
{
return Uri::base();
}
return base64_decode($return);
}
/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*
* @since 1.6
*/
public function save($key = null, $urlVar = 'w_id')
{
// Get the application
$app = $this->app;
// Get the data from POST
$data = $this->input->post->get('jform', array(), 'array');
// Save the data in the session.
$app->setUserState('com_weblinks.edit.weblink.data', $data);
$result = parent::save($key, $urlVar);
// If ok, redirect to the return page.
if ($result)
{
// Flush the data from the session
$app->setUserState('com_weblinks.edit.weblink.data', null);
$this->setRedirect($this->getReturnPage());
}
return $result;
}
/**
* Go to a weblink
*
* @return void
*
* @throws \Exception
*
* @since 1.6
*/
public function go()
{
// Get the ID from the request
$id = $this->input->getInt('id');
// Get the model, requiring published items
$modelLink = $this->getModel('Weblink');
$modelLink->setState('filter.published', 1);
// Get the item
$link = $modelLink->getItem($id);
// Make sure the item was found.
if (empty($link))
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
// Check whether item access level allows access.
$groups = $this->app->getIdentity()->getAuthorisedViewLevels();
if (!in_array($link->access, $groups))
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
// Check whether category access level allows access.
$modelCat = $this->getModel('Category', 'Site', array('ignore_request' => true));
$modelCat->setState('filter.published', 1);
// Get the category
$category = $modelCat->getCategory($link->catid);
// Make sure the category was found.
if (empty($category))
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
// Check whether item access level allows access.
if (!in_array($category->access, $groups))
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
// Redirect to the URL
if ($link->url)
{
$modelLink->hit($id);
$this->app->redirect($link->url, 301);
}
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'), 404);
}
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'), 404);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,8 +10,9 @@
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\Language\Associations;
use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
@ -22,44 +24,37 @@ use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
*/
abstract class AssociationHelper extends CategoryAssociationHelper
{
/**
* Method to get the associations for a given item
*
* @param integer $id Id of the item
* @param string $view Name of the view
*
* @return array Array of associations for the item
*
* @since 3.0
*/
public static function getAssociations($id = 0, $view = null)
{
$input = Factory::getApplication()->input;
$view = is_null($view) ? $input->get('view') : $view;
$id = empty($id) ? $input->getInt('id') : $id;
/**
* Method to get the associations for a given item
*
* @param integer $id Id of the item
* @param string $view Name of the view
*
* @return array Array of associations for the item
*
* @since 3.0
*/
public static function getAssociations($id = 0, $view = null)
{
$input = Factory::getApplication()->input;
$view = is_null($view) ? $input->get('view') : $view;
$id = empty($id) ? $input->getInt('id') : $id;
if ($view === 'weblink') {
if ($id) {
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id);
$return = [];
foreach ($associations as $tag => $item) {
$return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language);
}
if ($view === 'weblink')
{
if ($id)
{
$associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id);
return $return;
}
}
$return = array();
if ($view == 'category' || $view == 'categories') {
return self::getCategoryAssociations($id, 'com_weblinks');
}
foreach ($associations as $tag => $item)
{
$return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language);
}
return $return;
}
}
if ($view == 'category' || $view == 'categories')
{
return self::getCategoryAssociations($id, 'com_weblinks');
}
return array();
}
return [];
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -12,8 +13,9 @@ namespace Joomla\Component\Weblinks\Site\Helper;
use Joomla\CMS\Categories\CategoryNode;
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.
*
@ -21,95 +23,80 @@ defined('_JEXEC') or die;
*/
abstract class RouteHelper
{
/**
* Get the route of the weblink
*
* @param integer $id Web link ID
* @param integer $catid Category ID
* @param string $language Language
*
* @return string
*/
public static function getWeblinkRoute($id, $catid, $language = 0)
{
// Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id=' . $id;
/**
* Get the route of the weblink
*
* @param integer $id Web link ID
* @param integer $catid Category ID
* @param string $language Language
*
* @return string
*/
public static function getWeblinkRoute($id, $catid, $language = 0)
{
// Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id=' . $id;
if ($catid > 1) {
$link .= '&catid=' . $catid;
}
if ($catid > 1)
{
$link .= '&catid=' . $catid;
}
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $language;
}
if ($language && $language !== '*' && Multilanguage::isEnabled())
{
$link .= '&lang=' . $language;
}
return $link;
}
return $link;
}
/**
* Ge the form route
*
* @param integer $id The id of the weblink.
* @param string $return The return page variable.
*
* @return string
*/
public static function getFormRoute($id, $return = null)
{
// Create the link.
if ($id) {
$link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id;
} else {
$link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0';
}
/**
* Ge the form route
*
* @param integer $id The id of the weblink.
* @param string $return The return page variable.
*
* @return string
*/
public static function getFormRoute($id, $return = null)
{
// Create the link.
if ($id)
{
$link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id;
}
else
{
$link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0';
}
if ($return) {
$link .= '&return=' . $return;
}
if ($return)
{
$link .= '&return=' . $return;
}
return $link;
}
return $link;
}
/**
* Get the Category Route
*
* @param CategoryNode|string|integer $catid JCategoryNode object or category ID
* @param integer $language Language code
*
* @return string
*/
public static function getCategoryRoute($catid, $language = 0)
{
if ($catid instanceof CategoryNode) {
$id = $catid->id;
} else {
$id = (int) $catid;
}
/**
* Get the Category Route
*
* @param CategoryNode|string|integer $catid JCategoryNode object or category ID
* @param integer $language Language code
*
* @return string
*/
public static function getCategoryRoute($catid, $language = 0)
{
if ($catid instanceof CategoryNode)
{
$id = $catid->id;
}
else
{
$id = (int) $catid;
}
if ($id < 1) {
$link = '';
} else {
// Create the link
$link = 'index.php?option=com_weblinks&view=category&id=' . $id;
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $language;
}
}
if ($id < 1)
{
$link = '';
}
else
{
// Create the link
$link = 'index.php?option=com_weblinks&view=category&id=' . $id;
if ($language && $language !== '*' && Multilanguage::isEnabled())
{
$link .= '&lang=' . $language;
}
}
return $link;
}
return $link;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -15,8 +16,9 @@ use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
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.
*
@ -24,128 +26,113 @@ defined('_JEXEC') or die;
*/
class CategoriesModel extends ListModel
{
/**
* Context string for the model type. This is used to handle uniqueness
* when dealing with the getStoreId() method and caching data structures.
*
* @var string
*/
protected $context = 'com_weblinks.categories';
/**
* Context string for the model type. This is used to handle uniqueness
* when dealing with the getStoreId() method and caching data structures.
*
* @var string
*/
protected $context = 'com_weblinks.categories';
/**
* The category context (allows other extensions to derived from this model).
*
* @var string
*/
protected $_extension = 'com_weblinks';
/**
* Parent category
*
* @var CategoryNode|null
*/
private $_parent = null;
/**
* Categories data
*
* @var false|array
*/
private $_items = null;
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$this->setState('filter.extension', $this->_extension);
// Get the parent id if defined.
$parentId = $app->input->getInt('id');
$this->setState('filter.parentId', $parentId);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* The category context (allows other extensions to derived from this model).
*
* @var string
*/
protected $_extension = 'com_weblinks';
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.extension');
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.parentId');
return parent::getStoreId($id);
}
/**
* Parent category
*
* @var CategoryNode|null
*/
private $_parent = null;
/**
* Redefine the function and add some properties to make the styling more easy
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
if ($this->_items === null) {
$params = $this->getState('params', new Registry());
$options = [];
$options['access'] = $this->getState('filter.access');
$options['published'] = $this->getState('filter.published');
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = Categories::getInstance('Weblinks', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (is_object($this->_parent)) {
$this->_items = $this->_parent->getChildren();
} else {
$this->_items = false;
}
}
/**
* Categories data
*
* @var false|array
*/
private $_items = null;
return $this->_items;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$this->setState('filter.extension', $this->_extension);
/**
* Get the parent
*
* @return mixed An array of data items on success, false on failure.
*/
public function getParent()
{
if (!is_object($this->_parent)) {
$this->getItems();
}
// Get the parent id if defined.
$parentId = $app->input->getInt('id');
$this->setState('filter.parentId', $parentId);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.extension');
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.parentId');
return parent::getStoreId($id);
}
/**
* Redefine the function and add some properties to make the styling more easy
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
if ($this->_items === null)
{
$params = $this->getState('params', new Registry);
$options = array();
$options['access'] = $this->getState('filter.access');
$options['published'] = $this->getState('filter.published');
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = Categories::getInstance('Weblinks', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (is_object($this->_parent))
{
$this->_items = $this->_parent->getChildren();
}
else
{
$this->_items = false;
}
}
return $this->_items;
}
/**
* Get the parent
*
* @return mixed An array of data items on success, false on failure.
*/
public function getParent()
{
if (!is_object($this->_parent))
{
$this->getItems();
}
return $this->_parent;
}
return $this->_parent;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,7 +10,9 @@
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\CategoryNode;
@ -28,412 +31,381 @@ use Joomla\Registry\Registry;
*/
class CategoryModel extends ListModel
{
/**
* Category item data
*
* @var CategoryNode|null
*/
protected $_item = null;
/**
* Category left of this one
*
* @var CategoryNode|null
*/
protected $_leftsibling = null;
/**
* Category right right of this one
*
* @var CategoryNode|null
*/
protected $_rightsibling = null;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
protected $_children = null;
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
protected $_parent = null;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'hits', 'a.hits',
'ordering', 'a.ordering',
);
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
$taggedItems = [];
// Convert the params field into an object, saving original in _params
foreach ($items as $item)
{
if (!isset($this->_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
if ($this->getState('load_tags', true))
{
$item->tags = new TagsHelper;
$taggedItems[$item->id] = $item;
}
}
// Load tags of all items.
if ($taggedItems)
{
$tagsHelper = new TagsHelper();
$itemIds = \array_keys($taggedItems);
foreach ($tagsHelper->getMultipleItemTags('com_weblinks.weblink', $itemIds) as $id => $tags)
{
$taggedItems[$id]->tags->itemTags = $tags;
}
}
return $items;
}
/**
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
*
* @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
*
* @since 1.6
*/
protected function getListQuery()
{
$viewLevels = $this->getCurrentUser()->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select required fields from the categories.
$query->select($this->getState('list.select', 'a.*'))
->from($db->quoteName('#__weblinks') . ' AS a')
->whereIn($db->quoteName('a.access'), $viewLevels);
// Filter by category.
if ($categoryId = $this->getState('category.id'))
{
// Group by subcategory
if ($this->getState('category.group', 0))
{
$query->select('c.title AS category_title')
->where('c.parent_id = :parent_id')
->bind(':parent_id', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $viewLevels);
}
else
{
$query->where('a.catid = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $viewLevels);
}
// Filter by published category
$cpublished = $this->getState('filter.c.published');
if (is_numeric($cpublished))
{
$query->where('c.published = :published')
->bind(':published', $cpublished, ParameterType::INTEGER);
}
}
// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")
->select("ua.email AS author_email")
->join('LEFT', '#__users AS ua ON ua.id = a.created_by')
->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');
// Filter by state
$state = $this->getState('filter.state');
if (is_numeric($state))
{
$query->where('a.state = :state')
->bind(':state', $state, ParameterType::INTEGER);
}
// Do not show trashed links on the front-end
$query->where('a.state != -2');
// Filter by start and end dates.
if ($this->getState('filter.publish_date'))
{
$nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)'
)
->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)'
)
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by language
if ($this->getState('filter.language'))
{
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Filter by search in title
$search = $this->getState('list.filter');
if (!empty($search))
{
$search = '%' . trim($search) . '%';
$query->where('(a.title LIKE :search)')
->bind(':search', $search);
}
// If grouping by subcategory, add the subcategory list ordering clause.
if ($this->getState('category.group', 0))
{
$query->order(
$db->escape($this->getState('category.ordering', 'c.lft')) . ' ' .
$db->escape($this->getState('category.direction', 'ASC'))
);
}
// Add the list ordering clause.
$query->order(
$db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$params = $app->getParams();
$this->setState('params', $params);
// List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
$this->setState('list.limit', $limit);
$limitstart = $app->input->get('limitstart', 0, 'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$this->setState('list.filter', $app->input->getString('filter-search'));
$orderCol = $app->input->get('filter_order', 'ordering');
if (!in_array($orderCol, $this->filter_fields))
{
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $app->input->get('filter_order_Dir', 'ASC');
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', '')))
{
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id);
$user = $this->getCurrentUser();
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.
$this->setState('filter.state', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language', Multilanguage::isEnabled());
}
/**
* Method to get category data for the current category
*
* @return object
*
* @since 1.5
*/
public function getCategory()
{
if (!is_object($this->_item))
{
$params = $this->getState('params', new Registry);
$options = array();
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0);
$categories = Categories::getInstance('Weblinks', $options);
$this->_item = $categories->get($this->getState('category.id', 'root'));
if (is_object($this->_item))
{
$this->_children = $this->_item->getChildren();
$this->_parent = false;
if ($this->_item->getParent())
{
$this->_parent = $this->_item->getParent();
}
$this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling = $this->_item->getSibling(false);
}
else
{
$this->_children = false;
$this->_parent = false;
}
}
return $this->_item;
}
/**
* Get the parent category
*
* @return mixed An array of categories or false if an error occurs.
*/
public function getParent()
{
if (!is_object($this->_item))
{
$this->getCategory();
}
return $this->_parent;
}
/**
* Get the leftsibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getLeftSibling()
{
if (!is_object($this->_item))
{
$this->getCategory();
}
return $this->_leftsibling;
}
/**
* Get the rightsibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getRightSibling()
{
if (!is_object($this->_item))
{
$this->getCategory();
}
return $this->_rightsibling;
}
/**
* Get the child categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getChildren()
{
if (!is_object($this->_item))
{
$this->getCategory();
}
return $this->_children;
}
/**
* Increment the hit counter for the category.
*
* @param integer $pk Optional primary key of the category to increment.
*
* @return boolean True if successful; false otherwise and internal error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$hitcount = Factory::getApplication()->input->getInt('hitcount', 1);
if ($hitcount)
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
$table->load($pk);
$table->hit($pk);
}
return true;
}
/**
* Category item data
*
* @var CategoryNode|null
*/
protected $_item = null;
/**
* Category left of this one
*
* @var CategoryNode|null
*/
protected $_leftsibling = null;
/**
* Category right right of this one
*
* @var CategoryNode|null
*/
protected $_rightsibling = null;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
protected $_children = null;
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
protected $_parent = null;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'title', 'a.title',
'hits', 'a.hits',
'ordering', 'a.ordering',
];
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
$taggedItems = [];
// Convert the params field into an object, saving original in _params
foreach ($items as $item) {
if (!isset($this->_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
if ($this->getState('load_tags', true)) {
$item->tags = new TagsHelper();
$taggedItems[$item->id] = $item;
}
}
// Load tags of all items.
if ($taggedItems) {
$tagsHelper = new TagsHelper();
$itemIds = \array_keys($taggedItems);
foreach ($tagsHelper->getMultipleItemTags('com_weblinks.weblink', $itemIds) as $id => $tags) {
$taggedItems[$id]->tags->itemTags = $tags;
}
}
return $items;
}
/**
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
*
* @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
*
* @since 1.6
*/
protected function getListQuery()
{
$viewLevels = $this->getCurrentUser()->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select required fields from the categories.
$query->select($this->getState('list.select', 'a.*'))
->from($db->quoteName('#__weblinks') . ' AS a')
->whereIn($db->quoteName('a.access'), $viewLevels);
// Filter by category.
if ($categoryId = $this->getState('category.id')) {
// Group by subcategory
if ($this->getState('category.group', 0)) {
$query->select('c.title AS category_title')
->where('c.parent_id = :parent_id')
->bind(':parent_id', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $viewLevels);
} else {
$query->where('a.catid = :catid')
->bind(':catid', $categoryId, ParameterType::INTEGER)
->join('LEFT', '#__categories AS c ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $viewLevels);
}
// Filter by published category
$cpublished = $this->getState('filter.c.published');
if (is_numeric($cpublished)) {
$query->where('c.published = :published')
->bind(':published', $cpublished, ParameterType::INTEGER);
}
}
// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")
->select("ua.email AS author_email")
->join('LEFT', '#__users AS ua ON ua.id = a.created_by')
->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');
// Filter by state
$state = $this->getState('filter.state');
if (is_numeric($state)) {
$query->where('a.state = :state')
->bind(':state', $state, ParameterType::INTEGER);
}
// Do not show trashed links on the front-end
$query->where('a.state != -2');
// Filter by start and end dates.
if ($this->getState('filter.publish_date')) {
$nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Filter by search in title
$search = $this->getState('list.filter');
if (!empty($search)) {
$search = '%' . trim($search) . '%';
$query->where('(a.title LIKE :search)')
->bind(':search', $search);
}
// If grouping by subcategory, add the subcategory list ordering clause.
if ($this->getState('category.group', 0)) {
$query->order(
$db->escape($this->getState('category.ordering', 'c.lft')) . ' ' .
$db->escape($this->getState('category.direction', 'ASC'))
);
}
// Add the list ordering clause.
$query->order(
$db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$params = $app->getParams();
$this->setState('params', $params);
// List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
$this->setState('list.limit', $limit);
$limitstart = $app->input->get('limitstart', 0, 'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$this->setState('list.filter', $app->input->getString('filter-search'));
$orderCol = $app->input->get('filter_order', 'ordering');
if (!in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $app->input->get('filter_order_Dir', 'ASC');
if (!in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id);
$user = $this->getCurrentUser();
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.
$this->setState('filter.state', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language', Multilanguage::isEnabled());
}
/**
* Method to get category data for the current category
*
* @return object
*
* @since 1.5
*/
public function getCategory()
{
if (!is_object($this->_item)) {
$params = $this->getState('params', new Registry());
$options = [];
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0);
$categories = Categories::getInstance('Weblinks', $options);
$this->_item = $categories->get($this->getState('category.id', 'root'));
if (is_object($this->_item)) {
$this->_children = $this->_item->getChildren();
$this->_parent = false;
if ($this->_item->getParent()) {
$this->_parent = $this->_item->getParent();
}
$this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling = $this->_item->getSibling(false);
} else {
$this->_children = false;
$this->_parent = false;
}
}
return $this->_item;
}
/**
* Get the parent category
*
* @return mixed An array of categories or false if an error occurs.
*/
public function getParent()
{
if (!is_object($this->_item)) {
$this->getCategory();
}
return $this->_parent;
}
/**
* Get the leftsibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getLeftSibling()
{
if (!is_object($this->_item)) {
$this->getCategory();
}
return $this->_leftsibling;
}
/**
* Get the rightsibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getRightSibling()
{
if (!is_object($this->_item)) {
$this->getCategory();
}
return $this->_rightsibling;
}
/**
* Get the child categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getChildren()
{
if (!is_object($this->_item)) {
$this->getCategory();
}
return $this->_children;
}
/**
* Increment the hit counter for the category.
*
* @param integer $pk Optional primary key of the category to increment.
*
* @return boolean True if successful; false otherwise and internal error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$hitcount = Factory::getApplication()->input->getInt('hitcount', 1);
if ($hitcount) {
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
$table->load($pk);
$table->hit($pk);
}
return true;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,7 +10,9 @@
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\Table\Table;
@ -23,103 +26,101 @@ use Joomla\Component\Weblinks\Administrator\Model\WeblinkModel;
*/
class FormModel extends WeblinkModel
{
/**
* Model typeAlias string. Used for version history.
*
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
/**
* Model typeAlias string. Used for version history.
*
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
/**
* Get the return URL.
*
* @return string The return URL.
*
* @since 1.6
*/
public function getReturnPage()
{
return base64_encode($this->getState('return_page', ''));
}
/**
* Get the return URL.
*
* @return string The return URL.
*
* @since 1.6
*/
public function getReturnPage()
{
return base64_encode($this->getState('return_page', ''));
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
$app = Factory::getApplication();
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
$app = Factory::getApplication();
// Load state from the request.
$pk = $app->input->getInt('w_id');
$this->setState('weblink.id', $pk);
// Load state from the request.
$pk = $app->input->getInt('w_id');
$this->setState('weblink.id', $pk);
// Add compatibility variable for default naming conventions.
$this->setState('form.id', $pk);
// Add compatibility variable for default naming conventions.
$this->setState('form.id', $pk);
$categoryId = $app->input->getInt('catid');
$this->setState('weblink.catid', $categoryId);
$categoryId = $app->input->getInt('catid');
$this->setState('weblink.catid', $categoryId);
$return = $app->input->get('return', '', 'base64');
$return = $app->input->get('return', '', 'base64');
if ($return && !Uri::isInternal(base64_decode($return)))
{
$return = '';
}
if ($return && !Uri::isInternal(base64_decode($return))) {
$return = '';
}
$this->setState('return_page', base64_decode($return));
$this->setState('return_page', base64_decode($return));
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout', $app->input->getString('layout'));
}
$this->setState('layout', $app->input->getString('layout'));
}
/**
* Abstract method for getting the form from the model.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
*
* @since __DEPLOY_VERSION__
*/
public function getForm($data = array(), $loadData = true)
{
$form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
/**
* Abstract method for getting the form from the model.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
*
* @since __DEPLOY_VERSION__
*/
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm('com_weblinks.form', 'weblink', ['control' => 'jform', 'load_data' => $loadData]);
// Disable the buttons and just allow editor none for not authenticated users
if ($this->getCurrentUser()->guest)
{
$form->setFieldAttribute('description', 'editor', 'none');
$form->setFieldAttribute('description', 'buttons', 'no');
}
// Disable the buttons and just allow editor none for not authenticated users
if ($this->getCurrentUser()->guest) {
$form->setFieldAttribute('description', 'editor', 'none');
$form->setFieldAttribute('description', 'buttons', 'no');
}
return $form;
}
return $form;
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
*
* @return Table A Table object
*
* @since 4.0.0
* @throws \Exception
*/
public function getTable($name = 'Weblink', $prefix = 'Administrator', $options = array())
{
return parent::getTable($name, $prefix, $options);
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
*
* @return Table A Table object
*
* @since 4.0.0
* @throws \Exception
*/
public function getTable($name = 'Weblink', $prefix = 'Administrator', $options = [])
{
return parent::getTable($name, $prefix, $options);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,7 +10,9 @@
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\Helper\TagsHelper;
@ -27,205 +30,187 @@ use Joomla\Registry\Registry;
*/
class WeblinkModel extends ItemModel
{
/**
* Store loaded weblink items
*
* @var array
* @since 1.6
*/
protected $_item = null;
/**
* Store loaded weblink items
*
* @var array
* @since 1.6
*/
protected $_item = null;
/**
* Model context string.
*
* @var string
*/
protected $_context = 'com_weblinks.weblink';
/**
* Model context string.
*
* @var string
*/
protected $_context = 'com_weblinks.weblink';
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
$app = Factory::getApplication();
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
$app = Factory::getApplication();
// Load the object state.
$pk = $app->input->getInt('id');
$this->setState('weblink.id', $pk);
// Load the object state.
$pk = $app->input->getInt('id');
$this->setState('weblink.id', $pk);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$user = $this->getCurrentUser();
$user = $this->getCurrentUser();
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks'))
{
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) {
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
$this->setState('filter.language', Multilanguage::isEnabled());
}
$this->setState('filter.language', Multilanguage::isEnabled());
}
/**
* Method to get an object.
*
* @param integer $pk The id of the object to get.
*
* @return mixed Object on success, false on failure.
*/
public function getItem($pk = null)
{
$user = $this->getCurrentUser();
/**
* Method to get an object.
*
* @param integer $pk The id of the object to get.
*
* @return mixed Object on success, false on failure.
*/
public function getItem($pk = null)
{
$user = $this->getCurrentUser();
$pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id');
$pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id');
if ($this->_item === null)
{
$this->_item = array();
}
if ($this->_item === null) {
$this->_item = [];
}
if (!isset($this->_item[$pk]))
{
try
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($this->getState('item.select', 'a.*'))
->from('#__weblinks AS a')
->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $pk, ParameterType::INTEGER);
if (!isset($this->_item[$pk])) {
try {
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($this->getState('item.select', 'a.*'))
->from('#__weblinks AS a')
->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $pk, ParameterType::INTEGER);
// Join on category table.
$query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
->innerJoin('#__categories AS c on c.id = a.catid')
->where('c.published > 0');
// Join on category table.
$query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
->innerJoin('#__categories AS c on c.id = a.catid')
->where('c.published > 0');
// Join on user table.
$query->select('u.name AS author')
->join('LEFT', '#__users AS u on u.id = a.created_by');
// Join on user table.
$query->select('u.name AS author')
->join('LEFT', '#__users AS u on u.id = a.created_by');
// Filter by language
if ($this->getState('filter.language'))
{
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Join over the categories to get parent category titles
$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 over the categories to get parent category titles
$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');
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks'))
{
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)'
)
->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)'
)
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks')) {
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
$query->where('(' . $db->quoteName('a.publish_up')
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
->where('(' . $db->quoteName('a.publish_down')
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by published state.
$published = $this->getState('filter.published');
$archived = $this->getState('filter.archived');
// Filter by published state.
$published = $this->getState('filter.published');
$archived = $this->getState('filter.archived');
if (is_numeric($published))
{
$query->whereIn($db->quoteName('a.state'), [$published, $archived]);
}
if (is_numeric($published)) {
$query->whereIn($db->quoteName('a.state'), [$published, $archived]);
}
$db->setQuery($query);
$db->setQuery($query);
$data = $db->loadObject();
$data = $db->loadObject();
if (empty($data))
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
if (empty($data)) {
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
// Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived)))
{
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
// Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived))) {
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
}
// Convert parameter fields to objects.
$data->params = new Registry($data->params);
$data->metadata = new Registry($data->metadata);
// Convert parameter fields to objects.
$data->params = new Registry($data->params);
$data->metadata = new Registry($data->metadata);
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data
if ($this->getState('load_tags', true))
{
$data->tags = new TagsHelper;
$data->tags->getItemTags('com_weblinks.weblink', $data->id);
}
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data
if ($this->getState('load_tags', true)) {
$data->tags = new TagsHelper();
$data->tags->getItemTags('com_weblinks.weblink', $data->id);
}
// Compute access permissions.
if ($access = $this->getState('filter.access'))
{
// If the access filter has been set, we already know this user can view.
$data->params->set('access-view', true);
}
else
{
// If no access filter is set, the layout takes some responsibility for display of limited information.
$groups = $user->getAuthorisedViewLevels();
$data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups));
}
// Compute access permissions.
if ($access = $this->getState('filter.access')) {
// If the access filter has been set, we already know this user can view.
$data->params->set('access-view', true);
} else {
// If no access filter is set, the layout takes some responsibility for display of limited information.
$groups = $user->getAuthorisedViewLevels();
$data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups));
}
$this->_item[$pk] = $data;
}
catch (\Exception $e)
{
$this->setError($e);
$this->_item[$pk] = false;
}
}
$this->_item[$pk] = $data;
} catch (\Exception $e) {
$this->setError($e);
$this->_item[$pk] = false;
}
}
return $this->_item[$pk];
}
return $this->_item[$pk];
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A database object
*
* @since 1.6
*/
public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = array())
{
return parent::getTable($type, $prefix, $config);
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A database object
*
* @since 1.6
*/
public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = [])
{
return parent::getTable($type, $prefix, $config);
}
/**
* Method to increment the hit counter for the weblink
*
* @param integer $pk Optional ID of the weblink.
*
* @return boolean True on success
*/
public function hit($pk = null)
{
if (empty($pk))
{
$pk = $this->getState('weblink.id');
}
/**
* Method to increment the hit counter for the weblink
*
* @param integer $pk Optional ID of the weblink.
*
* @return boolean True on success
*/
public function hit($pk = null)
{
if (empty($pk)) {
$pk = $this->getState('weblink.id');
}
return $this->getTable('Weblink')->hit($pk);
}
return $this->getTable('Weblink')->hit($pk);
}
}

View File

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

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,8 +10,9 @@
namespace Joomla\Component\Weblinks\Site\Service;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Categories\CategoryInterface;
@ -31,268 +33,237 @@ use Joomla\Database\ParameterType;
*/
class Router extends RouterView
{
/**
* Flag to remove IDs
*
* @var boolean
*/
protected $noIDs = false;
/**
* Flag to remove IDs
*
* @var boolean
*/
protected $noIDs = false;
/**
* The category factory
*
* @var CategoryFactoryInterface
*
* @since 4.0.0
*/
private $categoryFactory;
/**
* The category cache
*
* @var array
*
* @since 4.0.0
*/
private $categoryCache = [];
/**
* The db
*
* @var DatabaseInterface
*
* @since 4.0.0
*/
private $db;
/**
* Weblinks Component router constructor
*
* @param SiteApplication $app The application object
* @param AbstractMenu $menu The menu object to work with
* @param CategoryFactoryInterface $categoryFactory The category object
* @param DatabaseInterface $db The database object
*/
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
{
$this->categoryFactory = $categoryFactory;
$this->db = $db;
$params = ComponentHelper::getParams('com_weblinks');
$this->noIDs = (bool) $params->get('sef_ids');
$categories = new RouterViewConfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
$category = new RouterViewConfiguration('category');
$category->setKey('id')->setParent($categories, 'catid')->setNestable();
$this->registerView($category);
$webLink = new RouterViewConfiguration('weblink');
$webLink->setKey('id')->setParent($category, 'catid');
$this->registerView($webLink);
$form = new RouterViewConfiguration('form');
$form->setKey('w_id');
$this->registerView($form);
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
/**
* The category factory
*
* @var CategoryFactoryInterface
*
* @since 4.0.0
*/
private $categoryFactory;
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategorySegment($id, $query)
{
$category = $this->getCategories()->get($id);
if ($category) {
$path = array_reverse($category->getPath(), true);
$path[0] = '1:root';
if ($this->noIDs) {
foreach ($path as &$segment) {
list($id, $segment) = explode(':', $segment, 2);
}
}
/**
* The category cache
*
* @var array
*
* @since 4.0.0
*/
private $categoryCache = [];
return $path;
}
/**
* The db
*
* @var DatabaseInterface
*
* @since 4.0.0
*/
private $db;
return [];
}
/**
* Weblinks Component router constructor
*
* @param SiteApplication $app The application object
* @param AbstractMenu $menu The menu object to work with
* @param CategoryFactoryInterface $categoryFactory The category object
* @param DatabaseInterface $db The database object
*/
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
{
$this->categoryFactory = $categoryFactory;
$this->db = $db;
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategoriesSegment($id, $query)
{
return $this->getCategorySegment($id, $query);
}
$params = ComponentHelper::getParams('com_weblinks');
$this->noIDs = (bool) $params->get('sef_ids');
$categories = new RouterViewConfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
$category = new RouterViewConfiguration('category');
$category->setKey('id')->setParent($categories, 'catid')->setNestable();
$this->registerView($category);
$webLink = new RouterViewConfiguration('weblink');
$webLink->setKey('id')->setParent($category, 'catid');
$this->registerView($webLink);
$form = new RouterViewConfiguration('form');
$form->setKey('w_id');
$this->registerView($form);
/**
* Method to get the segment(s) for a weblink
*
* @param string $id ID of the weblink to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getWeblinkSegment($id, $query)
{
if (!strpos($id, ':')) {
$id = (int) $id;
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('alias'))
->from($this->db->quoteName('#__weblinks'))
->where($this->db->quoteName('id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$this->db->setQuery($dbquery);
$id .= ':' . $this->db->loadResult();
}
parent::__construct($app, $menu);
if ($this->noIDs) {
list($void, $segment) = explode(':', $id, 2);
return [$void => $segment];
}
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
return [(int) $id => $id];
}
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategorySegment($id, $query)
{
$category = $this->getCategories()->get($id);
/**
* Method to get the segment(s) for a form
*
* @param string $id ID of the weblink form to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*
* @since 4.0.0
*/
public function getFormSegment($id, $query)
{
return $this->getWeblinkSegment($id, $query);
}
if ($category)
{
$path = array_reverse($category->getPath(), true);
$path[0] = '1:root';
/**
* Method to get the id for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoryId($segment, $query)
{
if (isset($query['id'])) {
$category = $this->getCategories(['access' => false])->get($query['id']);
if ($category) {
foreach ($category->getChildren() as $child) {
if ($this->noIDs) {
if ($child->alias == $segment) {
return $child->id;
}
} else {
if ($child->id == (int) $segment) {
return $child->id;
}
}
}
}
}
if ($this->noIDs)
{
foreach ($path as &$segment)
{
list($id, $segment) = explode(':', $segment, 2);
}
}
return false;
}
return $path;
}
/**
* Method to get the segment(s) for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoriesId($segment, $query)
{
return $this->getCategoryId($segment, $query);
}
return array();
}
/**
* Method to get the segment(s) for a weblink
*
* @param string $segment Segment of the weblink to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getWeblinkId($segment, $query)
{
if ($this->noIDs) {
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('id'))
->from($this->db->quoteName('#__weblinks'))
->where([
$this->db->quoteName('alias') . ' = :alias',
$this->db->quoteName('catid') . ' = :catid',
])
->bind(':alias', $segment)
->bind(':catid', $query['id'], ParameterType::INTEGER);
$this->db->setQuery($dbquery);
return (int) $this->db->loadResult();
}
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategoriesSegment($id, $query)
{
return $this->getCategorySegment($id, $query);
}
return (int) $segment;
}
/**
* Method to get the segment(s) for a weblink
*
* @param string $id ID of the weblink to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getWeblinkSegment($id, $query)
{
if (!strpos($id, ':'))
{
$id = (int) $id;
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('alias'))
->from($this->db->quoteName('#__weblinks'))
->where($this->db->quoteName('id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$this->db->setQuery($dbquery);
/**
* Method to get categories from cache
*
* @param array $options The options for retrieving categories
*
* @return CategoryInterface The object containing categories
*
* @since 4.0.0
*/
private function getCategories(array $options = []): CategoryInterface
{
$key = serialize($options);
if (!isset($this->categoryCache[$key])) {
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
}
$id .= ':' . $this->db->loadResult();
}
if ($this->noIDs)
{
list($void, $segment) = explode(':', $id, 2);
return array($void => $segment);
}
return array((int) $id => $id);
}
/**
* Method to get the segment(s) for a form
*
* @param string $id ID of the weblink form to retrieve the segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*
* @since 4.0.0
*/
public function getFormSegment($id, $query)
{
return $this->getWeblinkSegment($id, $query);
}
/**
* Method to get the id for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoryId($segment, $query)
{
if (isset($query['id']))
{
$category = $this->getCategories(['access' => false])->get($query['id']);
if ($category)
{
foreach ($category->getChildren() as $child)
{
if ($this->noIDs)
{
if ($child->alias == $segment)
{
return $child->id;
}
}
else
{
if ($child->id == (int) $segment)
{
return $child->id;
}
}
}
}
}
return false;
}
/**
* Method to get the segment(s) for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoriesId($segment, $query)
{
return $this->getCategoryId($segment, $query);
}
/**
* Method to get the segment(s) for a weblink
*
* @param string $segment Segment of the weblink to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getWeblinkId($segment, $query)
{
if ($this->noIDs)
{
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('id'))
->from($this->db->quoteName('#__weblinks'))
->where(
[
$this->db->quoteName('alias') . ' = :alias',
$this->db->quoteName('catid') . ' = :catid',
]
)
->bind(':alias', $segment)
->bind(':catid', $query['id'], ParameterType::INTEGER);
$this->db->setQuery($dbquery);
return (int) $this->db->loadResult();
}
return (int) $segment;
}
/**
* Method to get categories from cache
*
* @param array $options The options for retrieving categories
*
* @return CategoryInterface The object containing categories
*
* @since 4.0.0
*/
private function getCategories(array $options = []): CategoryInterface
{
$key = serialize($options);
if (!isset($this->categoryCache[$key]))
{
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
}
return $this->categoryCache[$key];
}
return $this->categoryCache[$key];
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -11,8 +12,9 @@ namespace Joomla\Component\Weblinks\Site\View\Categories;
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.
*
@ -20,15 +22,14 @@ defined('_JEXEC') or die;
*/
class HtmlView extends CategoriesView
{
/**
* @var string Default title to use for page title
* @since 3.2
*/
protected $pageHeading = 'COM_WEBLINKS_DEFAULT_PAGE_TITLE';
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_weblinks';
/**
* @var string Default title to use for page title
* @since 3.2
*/
protected $pageHeading = 'COM_WEBLINKS_DEFAULT_PAGE_TITLE';
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_weblinks';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -11,8 +12,9 @@ namespace Joomla\Component\Weblinks\Site\View\Category;
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
*
@ -20,9 +22,9 @@ defined('_JEXEC') or die;
*/
class FeedView extends CategoryFeedView
{
/**
* @var string The name of the view to link individual items to
* @since 3.2
*/
protected $viewName = 'weblink';
/**
* @var string The name of the view to link individual items to
* @since 3.2
*/
protected $viewName = 'weblink';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -13,8 +14,9 @@ use Joomla\CMS\MVC\View\CategoryView;
use Joomla\CMS\Router\Route;
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
*
@ -22,89 +24,74 @@ defined('_JEXEC') or die;
*/
class HtmlView extends CategoryView
{
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_weblinks';
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_weblinks';
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise a Error object.
*/
public function display($tpl = null)
{
parent::commonCategoryDisplay();
// Prepare the data.
// Compute the weblink slug & link url.
foreach ($this->items as $item) {
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $this->params;
$item->params->merge($temp);
if ($item->params->get('count_clicks', 1) == 1) {
$item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id);
} else {
$item->link = $item->url;
}
}
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise a Error object.
*/
public function display($tpl = null)
{
parent::commonCategoryDisplay();
return parent::display($tpl);
}
// Prepare the data.
// Compute the weblink slug & link url.
foreach ($this->items as $item)
{
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $this->params;
$item->params->merge($temp);
/**
* Prepares the document
*
* @return void
*/
protected function prepareDocument()
{
parent::prepareDocument();
parent::addFeed();
if ($this->menuItemMatchCategory) {
// If the active menu item is linked directly to the category being displayed, no further process is needed
return;
}
if ($item->params->get('count_clicks', 1) == 1)
{
$item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id);
}
else
{
$item->link = $item->url;
}
}
// Get ID of the category from active menu item
$menu = $this->menu;
return parent::display($tpl);
}
if (
$menu && $menu->component == 'com_weblinks' && isset($menu->query['view'])
&& in_array($menu->query['view'], ['categories', 'category'])
) {
$id = $menu->query['id'];
} else {
$id = 0;
}
/**
* Prepares the document
*
* @return void
*/
protected function prepareDocument()
{
parent::prepareDocument();
$path = [['title' => $this->category->title, 'link' => '']];
$category = $this->category->getParent();
while ($category !== null && $category->id != $id && $category->id !== 'root') {
$path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)];
$category = $category->getParent();
}
parent::addFeed();
if ($this->menuItemMatchCategory)
{
// If the active menu item is linked directly to the category being displayed, no further process is needed
return;
}
// Get ID of the category from active menu item
$menu = $this->menu;
if ($menu && $menu->component == 'com_weblinks' && isset($menu->query['view'])
&& in_array($menu->query['view'], ['categories', 'category']))
{
$id = $menu->query['id'];
}
else
{
$id = 0;
}
$path = [['title' => $this->category->title, 'link' => '']];
$category = $this->category->getParent();
while ($category !== null && $category->id != $id && $category->id !== 'root')
{
$path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)];
$category = $category->getParent();
}
$path = array_reverse($path);
foreach ($path as $item)
{
$this->pathway->addItem($item['title'], $item['link']);
}
}
$path = array_reverse($path);
foreach ($path as $item) {
$this->pathway->addItem($item['title'], $item['link']);
}
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -9,7 +10,9 @@
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\Language\Text;
@ -23,154 +26,138 @@ use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
*/
class HtmlView extends BaseHtmlView
{
/**
* @var \Joomla\CMS\Form\Form
* @since 4.0.0
*/
protected $form;
/**
* @var \Joomla\CMS\Form\Form
* @since 4.0.0
*/
protected $form;
/**
* @var object
* @since 4.0.0
*/
protected $item;
/**
* @var object
* @since 4.0.0
*/
protected $item;
/**
* @var string
* @since 4.0.0
*/
protected $return_page;
/**
* @var string
* @since 4.0.0
*/
protected $return_page;
/**
* @var string
* @since 4.0.0
*/
protected $pageclass_sfx;
/**
* @var string
* @since 4.0.0
*/
protected $pageclass_sfx;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $state;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $state;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $params;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $params;
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
// Get model data.
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage');
// Get model data.
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage');
if (empty($this->item->id))
{
$authorised = $user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create'));
}
else
{
$authorised = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
}
if (empty($this->item->id)) {
$authorised = $user->authorise('core.create', 'com_weblinks') || count($user->getAuthorisedCategories('com_weblinks', 'core.create'));
} else {
$authorised = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
}
if ($authorised !== true)
{
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
if ($authorised !== true) {
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
if (!empty($this->item))
{
// Override the base weblink data with any data in the session.
$temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
if (!empty($this->item)) {
// Override the base weblink data with any data in the session.
$temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', []);
foreach ($temp as $k => $v)
{
$this->item->$k = $v;
}
foreach ($temp as $k => $v) {
$this->item->$k = $v;
}
$this->form->bind($this->item);
}
$this->form->bind($this->item);
}
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// Create a shortcut to the parameters.
$params = &$this->state->params;
// Create a shortcut to the parameters.
$params = &$this->state->params;
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
$this->params = $params;
$this->user = $user;
$this->params = $params;
$this->user = $user;
$this->_prepareDocument();
$this->prepareDocument();
parent::display($tpl);
}
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*/
protected function _prepareDocument()
{
$app = Factory::getApplication();
/**
* Prepares the document
*
* @return void
*/
protected function prepareDocument()
{
$app = Factory::getApplication();
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $app->getMenu()->getActive();
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $app->getMenu()->getActive();
if (empty($this->item->id))
{
$head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK');
}
else
{
$head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK');
}
if (empty($this->item->id)) {
$head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK');
} else {
$head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK');
}
if ($menu)
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
}
else
{
$this->params->def('page_heading', $head);
}
if ($menu) {
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
} else {
$this->params->def('page_heading', $head);
}
$title = $this->params->def('page_title', $head);
$title = $this->params->def('page_title', $head);
$this->setDocumentTitle($title);
$this->setDocumentTitle($title);
if ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_description')) {
$this->document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_keywords'))
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}
if ($this->params->get('menu-meta_keywords')) {
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}
if ($this->params->get('robots'))
{
$this->document->setMetadata('robots', $this->params->get('robots'));
}
}
if ($this->params->get('robots')) {
$this->document->setMetadata('robots', $this->params->get('robots'));
}
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -12,8 +13,9 @@ namespace Joomla\Component\Weblinks\Site\View\Weblink;
use Joomla\CMS\Factory;
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
*
@ -21,69 +23,55 @@ defined('_JEXEC') or die;
*/
class HtmlView extends BaseHtmlView
{
/**
* The weblink object
*
* @var \JObject
*/
protected $item;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*/
protected $params;
/**
* The item model state
*
* @var \Joomla\Registry\Registry
* @since 1.6
*/
protected $state;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*
* @since __DEPLOY_VERSION__
*/
public function display($tpl = null)
{
$app = Factory::getApplication();
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->params = $this->state->get('params');
// Create a shortcut for $item.
$item = $this->item;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $app->getParams();
$item->params->merge($temp);
$offset = $this->state->get('list.offset');
$app->triggerEvent('onContentPrepare', array('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));
$results = $app->triggerEvent('onContentBeforeDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $app->triggerEvent('onContentAfterDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));
parent::display($tpl);
}
/**
* The weblink object
*
* @var \JObject
*/
protected $item;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*/
protected $params;
/**
* The item model state
*
* @var \Joomla\Registry\Registry
* @since 1.6
*/
protected $state;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*
* @since __DEPLOY_VERSION__
*/
public function display($tpl = null)
{
$app = Factory::getApplication();
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->params = $this->state->get('params');
// Create a shortcut for $item.
$item = $this->item;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $app->getParams();
$item->params->merge($temp);
$offset = $this->state->get('list.offset');
$app->triggerEvent('onContentPrepare', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$item->event = new \stdClass();
$results = $app->triggerEvent('onContentAfterTitle', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $app->triggerEvent('onContentBeforeDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $app->triggerEvent('onContentAfterDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]);
$item->event->afterDisplayContent = trim(implode("\n", $results));
parent::display($tpl);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,15 +8,14 @@
* @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\Layout\LayoutHelper;
// Add strings for translations in Javascript.
Text::script('JGLOBAL_EXPAND_CATEGORIES');
Text::script('JGLOBAL_COLLAPSE_CATEGORIES');
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->getRegistry()->addExtensionRegistryFile('com_categories');
@ -23,8 +23,8 @@ $wa->usePreset('com_categories.shared-categories-accordion');
?>
<div class="com-weblinks-categories categories-list">
<?php
echo LayoutHelper::render('joomla.content.categories_default', $this);
echo $this->loadTemplate('items');
?>
<?php
echo LayoutHelper::render('joomla.content.categories_default', $this);
echo $this->loadTemplate('items');
?>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,77 +8,93 @@
* @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\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
?>
<div class="com-content-categories__items">
<?php foreach ($this->items[$this->parent->id] as $id => $item) : ?>
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : ?>
<div class="com-content-categories__item">
<div class="w-100">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id, $item->language)); ?>">
<?php echo $this->escape($item->title); ?></a>
<?php if ($this->params->get('show_cat_num_links_cat') == 1) :?>
<span class="badge bg-info ">
<?php echo Text::_('COM_WEBLINKS_NUM_ITEMS'); ?>&nbsp;
<?php echo $item->numitems; ?>
</span>
<?php endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?>
<button
type="button"
id="category-btn-<?php echo $item->id; ?>"
data-category-id="<?php echo $item->id; ?>"
class="btn btn-secondary btn-sm float-end"
aria-expanded="false"
aria-label="<?php echo Text::_('JGLOBAL_EXPAND_CATEGORIES'); ?>"
>
<span class="icon-plus" aria-hidden="true"></span>
</button>
<?php endif; ?>
</div>
?>
<div class="com-content-categories__items">
<?php foreach ($this->items[$this->parent->id] as $id => $item) :
?>
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) :
?>
<div class="com-content-categories__item">
<div class="w-100">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id, $item->language)); ?>">
<?php echo $this->escape($item->title); ?></a>
<?php if ($this->params->get('show_cat_num_links_cat') == 1) :
?>
<span class="badge bg-info ">
<?php echo Text::_('COM_WEBLINKS_NUM_ITEMS'); ?>&nbsp;
<?php echo $item->numitems; ?>
</span>
<?php
endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) :
?>
<button
type="button"
id="category-btn-<?php echo $item->id; ?>"
data-category-id="<?php echo $item->id; ?>"
class="btn btn-secondary btn-sm float-end"
aria-expanded="false"
aria-label="<?php echo Text::_('JGLOBAL_EXPAND_CATEGORIES'); ?>"
>
<span class="icon-plus" aria-hidden="true"></span>
</button>
<?php
endif; ?>
</div>
<?php if ($this->params->get('show_subcat_desc_cat') == 1 && !empty($item->description)) : ?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_subcat_desc_cat') == 1 && !empty($item->description)) :
?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?>
</div>
<?php
endif; ?>
<?php if ($this->params->get('show_description_image') && !empty($item->getParams()->get('image'))) : ?>
<?php
$params = $item->getParams();
$img = HTMLHelper::cleanImageURL($params->get('image'));
$alt = '';
if (!empty($params->get('image_alt'))) :
$alt = 'alt="' . htmlspecialchars($params->get('image_alt'), ENT_COMPAT, 'UTF-8') . '"';
elseif (!empty($params->get('image_alt_empty'))) :
$alt = 'alt=""';
endif;
?>
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"<?php echo $alt; ?>>
<?php endif; ?>
<?php if ($this->params->get('show_description_image') && !empty($item->getParams()->get('image'))) :
?>
<?php
$params = $item->getParams();
$img = HTMLHelper::cleanImageURL($params->get('image'));
$alt = '';
if (!empty($params->get('image_alt'))) :
$alt = 'alt="' . htmlspecialchars($params->get('image_alt'), ENT_COMPAT, 'UTF-8') . '"';
elseif (!empty($params->get('image_alt_empty'))) :
$alt = 'alt=""';
endif;
?>
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"<?php echo $alt; ?>>
<?php
endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?>
<div class="com-content-categories__children" id="category-<?php echo $item->id; ?>" hidden>
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) :
?>
<div class="com-content-categories__children" id="category-<?php echo $item->id; ?>" hidden>
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php
endif; ?>
</div>
<?php
endif; ?>
<?php
endforeach; ?>
</div>
<?php
endif; ?>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,14 +8,15 @@
* @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;
?>
<div class="com-weblinks-category">
<?php
$this->subtemplatename = 'items';
echo LayoutHelper::render('joomla.content.category_default', $this);
?>
</div>
<?php
$this->subtemplatename = 'items';
echo LayoutHelper::render('joomla.content.category_default', $this);
?>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,47 +8,59 @@
* @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\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) :
?>
<ul class="com-weblinks-category__children list-group list-unstyled">
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : ?>
<li class="list-group-item">
<div class="item-title">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?>
</a>
?>
<ul class="com-weblinks-category__children list-group list-unstyled">
<?php foreach ($this->children[$this->category->id] as $id => $child) :
?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) :
?>
<li class="list-group-item">
<div class="item-title">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?>
</a>
<?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>
<?php endif; ?>
</div>
<?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>
<?php
endif; ?>
</div>
<?php if ($this->params->get('show_subcat_desc') == 1) : ?>
<?php if ($child->description) : ?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $child->description, '', 'com_weblinks.category'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($this->params->get('show_subcat_desc') == 1) :
?>
<?php if ($child->description) :
?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $child->description, '', 'com_weblinks.category'); ?>
</div>
<?php
endif; ?>
<?php
endif; ?>
<?php if (count($child->getChildren()) > 0 ) :
$this->children[$child->id] = $child->getChildren();
$this->category = $child;
$this->maxLevel--;
echo $this->loadTemplate('children');
$this->category = $child->getParent();
$this->maxLevel++;
endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (count($child->getChildren()) > 0) :
$this->children[$child->id] = $child->getChildren();
$this->category = $child;
$this->maxLevel--;
echo $this->loadTemplate('children');
$this->category = $child->getParent();
$this->maxLevel++;
endif; ?>
</li>
<?php
endif; ?>
<?php
endforeach; ?>
</ul>
<?php
endif; ?>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,215 +8,264 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Uri\Uri;
HTMLHelper::_('behavior.core');
// Get the user object.
$user = Factory::getApplication()->getIdentity();
// Check if user is allowed to add/edit based on weblinks permission.
$canEdit = $user->authorise('core.edit', '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);
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<div class="com-weblinks-category__items">
<form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
<?php if ($this->params->get('filter_field')) : ?>
<div class="com-weblinks-category__filter btn-group">
<label class="filter-search-lbl visually-hidden" for="filter-search">
<?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?>
</label>
<input
type="text"
name="filter-search"
id="filter-search"
value="<?php echo $this->escape($this->state->get('list.filter')); ?>"
onchange="document.adminForm.submit();"
placeholder="<?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?>"
>
<button type="submit" name="filter_submit" class="btn btn-primary"><?php echo Text::_('JGLOBAL_FILTER_BUTTON'); ?></button>
<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>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_pagination_limit')) : ?>
<div class="com-weblinks-category__pagination btn-group float-end">
<label for="limit" class="visually-hidden">
<?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<?php endif; ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<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'); ?>
</div>
<?php else : ?>
<ul class="category list-unstyled">
<?php foreach ($this->items as $i => $item) : ?>
<?php
// Shouldn't this be only for users with admin rights?
// @ToDo: what is the difference -class system-unbublished?
if ($item->state == 0) : ?>
<li class="system-unpublished list-group mt-3">
<?php else : ?>
<li class="list-group mt-3">
<?php endif; ?>
<form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
<?php if ($this->params->get('filter_field')) :
?>
<div class="com-weblinks-category__filter btn-group">
<label class="filter-search-lbl visually-hidden" for="filter-search">
<?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?>
</label>
<input
type="text"
name="filter-search"
id="filter-search"
value="<?php echo $this->escape($this->state->get('list.filter')); ?>"
onchange="document.adminForm.submit();"
placeholder="<?php echo Text::_('COM_WEBLINKS_FILTER_SEARCH_DESC'); ?>"
>
<button type="submit" name="filter_submit" class="btn btn-primary"><?php echo Text::_('JGLOBAL_FILTER_BUTTON'); ?></button>
<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>
</div>
<?php
endif; ?>
<?php if ($this->params->get('show_pagination_limit')) :
?>
<div class="com-weblinks-category__pagination btn-group float-end">
<label for="limit" class="visually-hidden">
<?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<?php
endif; ?>
<?php if (empty($this->items)) :
?>
<div class="alert alert-info">
<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'); ?>
</div>
<?php
else :
?>
<ul class="category list-unstyled">
<?php foreach ($this->items as $i => $item) :
?>
<?php
// Shouldn't this be only for users with admin rights?
// @ToDo: what is the difference -class system-unbublished?
if ($item->state == 0) :
?>
<li class="system-unpublished list-group mt-3">
<?php
else :
?>
<li class="list-group mt-3">
<?php
endif; ?>
<?php if ($canEdit || ($canEditOwn && $item->created_by == $userId)) : ?>
<div class="icons list-group-item">
<?php echo HTMLHelper::_('weblinkicon.edit', $item, $item->params); ?>
</div>
<?php endif; ?>
<?php if ($canEdit || ($canEditOwn && $item->created_by == $userId)) :
?>
<div class="icons list-group-item">
<?php echo HTMLHelper::_('weblinkicon.edit', $item, $item->params); ?>
</div>
<?php
endif; ?>
<div class="list-title list-group-item ">
<?php if ($this->params->get('icons', 1) == 0) : ?>
<?php echo Text::_('COM_WEBLINKS_LINK'); ?>
<?php elseif ($this->params->get('icons', 1) == 1) : ?>
<?php // ToDo css icons as variables ?>
<?php if (!$this->params->get('link_icons')) : ?>
<span class="icon-globe" aria-hidden="true"></span>
<?php else: ?>
<?php echo '<img src="' . $this->params->get('link_icons') . '" alt="' . Text::_('COM_WEBLINKS_LINK') . '" />'; ?>
<?php endif; ?>
<?php endif; ?>
<div class="list-title list-group-item ">
<?php if ($this->params->get('icons', 1) == 0) :
?>
<?php echo Text::_('COM_WEBLINKS_LINK'); ?>
<?php
elseif ($this->params->get('icons', 1) == 1) :
?>
<?php // ToDo css icons as variables ?>
<?php if (!$this->params->get('link_icons')) :
?>
<span class="icon-globe" aria-hidden="true"></span>
<?php
else :
?>
<?php echo '<img src="' . $this->params->get('link_icons') . '" alt="' . Text::_('COM_WEBLINKS_LINK') . '" />'; ?>
<?php
endif; ?>
<?php
endif; ?>
<?php // Compute the correct link ?>
<?php $menuclass = 'category' . $this->pageclass_sfx; ?>
<?php $link = $item->link; ?>
<?php $width = $item->params->get('width', 600); ?>
<?php $height = $item->params->get('height', 500); ?>
<?php if ($item->state == 0) : ?>
<span class="badge bg-warning"><?php echo Text::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
<?php // Compute the correct link ?>
<?php $menuclass = 'category' . $this->pageclass_sfx; ?>
<?php $link = $item->link; ?>
<?php $width = $item->params->get('width', 600); ?>
<?php $height = $item->params->get('height', 500); ?>
<?php
switch ($item->params->get('target', $this->params->get('target')))
{
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . '</a>';
break;
<?php if ($item->state == 0) :
?>
<span class="badge bg-warning"><?php echo Text::_('JUNPUBLISHED'); ?></span>
<?php
endif; ?>
case 2:
// 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) . '';
echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" .
$this->escape($item->title) . '</a>';
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = $this->escape($item->title);
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
<?php
switch ($item->params->get('target', $this->params->get('target'))) {
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . '</a>';
break;
case 2:
// 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) . '';
echo "<a href=\"$link\" onclick=\"window.open(this.href, 'targetWindow', '" . $attribs . "'); return false;\">" .
$this->escape($item->title) . '</a>';
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = $this->escape($item->title);
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . '
</button>';
break;
default:
// Open in parent window
echo '<a href="' . $link . '" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . ' </a>';
break;
}
?>
<?php if ($this->params->get('show_link_hits', 1)) : ?>
<div class="list-hits badge bg-info float-end">
<?php echo Text::sprintf('JGLOBAL_HITS_COUNT', $item->hits); ?>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_tags', 1) && !empty($item->tags->itemTags)) : ?>
<div class="mt-2 mb-2">
<?php echo LayoutHelper::render('joomla.content.tags', $item->tags->itemTags); ?>
</div>
<?php endif; ?>
break;
default:
// Open in parent window
echo '<a href="' . $link . '" class="' . $menuclass . '" rel="nofollow">' .
$this->escape($item->title) . ' </a>';
<?php if ($this->params->get('show_link_description') && ($item->description != '')) : ?>
<div class="mt-2 mb-2">
<?php $images = json_decode($item->images); ?>
<?php if (!empty($images->image_first)) : ?>
<?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) : ?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_first_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) : ?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
break;
}
?>
<?php if ($this->params->get('show_link_hits', 1)) :
?>
<div class="list-hits badge bg-info float-end">
<?php echo Text::sprintf('JGLOBAL_HITS_COUNT', $item->hits); ?>
</div>
<?php
endif; ?>
<?php if (!empty($images->image_second)) : ?>
<?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) : ?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_second_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) : ?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<?php if ($this->params->get('show_tags', 1) && !empty($item->tags->itemTags)) :
?>
<div class="mt-2 mb-2">
<?php echo LayoutHelper::render('joomla.content.tags', $item->tags->itemTags); ?>
</div>
<?php
endif; ?>
<?php echo $item->description; ?>
<?php if ($this->params->get('show_link_description') && ($item->description != '')) :
?>
<div class="mt-2 mb-2">
<?php $images = json_decode($item->images); ?>
<?php if (!empty($images->image_first)) :
?>
<?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) :
?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_first_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php
endif; ?>
</figure>
<?php
endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($images->image_second)) :
?>
<?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) :
?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_second_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php
endif; ?>
</figure>
<?php
endif; ?>
</div>
<?php echo $item->description; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
endif; ?>
<?php if ($this->params->get('show_pagination')) : ?>
<div class="com-weblinks-category__counter w-100">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="com-weblinks-category__counter counter float-end pt-3 pe-2">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
</div>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php endif; ?>
</li>
<?php
endforeach; ?>
</ul>
<?php endif; ?>
<?php if ($this->params->get('show_pagination')) :
?>
<div class="com-weblinks-category__counter w-100">
<?php if ($this->params->def('show_pagination_results', 1)) :
?>
<p class="com-weblinks-category__counter counter float-end pt-3 pe-2">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php
endif; ?>
<?php if ($canCreate) : ?>
<?php echo HTMLHelper::_('weblinkicon.create', $this->category, $this->category->params); ?>
<?php endif; ?>
</form>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php
endif; ?>
<?php
endif; ?>
<?php if ($canCreate) :
?>
<?php echo HTMLHelper::_('weblinkicon.create', $this->category, $this->category->params); ?>
<?php
endif; ?>
</form>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,93 +8,99 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
HTMLHelper::_('behavior.keepalive');
HTMLHelper::_('behavior.formvalidator');
$captchaEnabled = false;
$captchaSet = $this->params->get('captcha', Factory::getApplication()->get('captcha', '0'));
foreach (PluginHelper::getPlugin('captcha') as $plugin)
{
if ($captchaSet === $plugin->name)
{
$captchaEnabled = true;
break;
}
foreach (PluginHelper::getPlugin('captcha') as $plugin) {
if ($captchaSet === $plugin->name) {
$captchaEnabled = true;
break;
}
}
// Create shortcut to parameters.
$params = $this->state->get('params');
?>
<div class="edit item-page<?php echo $this->pageclass_sfx; ?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<div class="page-header">
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
</div>
<?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">
<?php if ($this->params->get('show_page_heading')) :
?>
<div class="page-header">
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
</div>
<?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">
<?php echo $this->form->renderField('title'); ?>
<?php echo $this->form->renderField('alias'); ?>
<?php echo $this->form->renderField('catid'); ?>
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('tags'); ?>
<?php echo $this->form->renderField('title'); ?>
<?php echo $this->form->renderField('alias'); ?>
<?php echo $this->form->renderField('catid'); ?>
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('tags'); ?>
<?php if ($params->get('save_history', 0)) : ?>
<?php echo $this->form->renderField('version_note'); ?>
<?php endif; ?>
<?php if ($params->get('save_history', 0)) :
?>
<?php echo $this->form->renderField('version_note'); ?>
<?php
endif; ?>
<?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) : ?>
<?php echo $this->form->renderField('state'); ?>
<?php endif; ?>
<?php echo $this->form->renderField('language'); ?>
<?php echo $this->form->renderField('description'); ?>
<?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) :
?>
<?php echo $this->form->renderField('state'); ?>
<?php
endif; ?>
<?php echo $this->form->renderField('language'); ?>
<?php echo $this->form->renderField('description'); ?>
<?php echo $this->form->renderField('image_first', 'images'); ?>
<?php echo $this->form->renderField('image_first_alt', 'images'); ?>
<?php echo $this->form->renderField('image_first_alt_empty', 'images'); ?>
<?php echo $this->form->renderField('float_first', 'images'); ?>
<?php echo $this->form->renderField('image_first_caption', 'images'); ?>
<?php echo $this->form->renderField('image_first', 'images'); ?>
<?php echo $this->form->renderField('image_first_alt', 'images'); ?>
<?php echo $this->form->renderField('image_first_alt_empty', 'images'); ?>
<?php echo $this->form->renderField('float_first', 'images'); ?>
<?php echo $this->form->renderField('image_first_caption', 'images'); ?>
<?php echo $this->form->renderField('image_second', 'images'); ?>
<?php echo $this->form->renderField('image_second_alt', 'images'); ?>
<?php echo $this->form->renderField('image_second_alt_empty', 'images'); ?>
<?php echo $this->form->renderField('float_second', 'images'); ?>
<?php echo $this->form->renderField('image_second_caption', 'images'); ?>
<?php echo $this->form->renderField('image_second', 'images'); ?>
<?php echo $this->form->renderField('image_second_alt', 'images'); ?>
<?php echo $this->form->renderField('image_second_alt_empty', 'images'); ?>
<?php echo $this->form->renderField('float_second', 'images'); ?>
<?php echo $this->form->renderField('image_second_caption', 'images'); ?>
<?php if ($captchaEnabled) : ?>
<div class="btn-group">
<?php echo $this->form->renderField('captcha'); ?>
</div>
<?php endif; ?>
<?php if ($captchaEnabled) :
?>
<div class="btn-group">
<?php echo $this->form->renderField('captcha'); ?>
</div>
<?php
endif; ?>
<div class="mb-2">
<button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('weblink.save')">
<span class="icon-check" aria-hidden="true"></span>
<?php echo Text::_('JSAVE'); ?>
</button>
<button type="button" class="btn btn-danger" onclick="Joomla.submitbutton('weblink.cancel')">
<span class="icon-times" aria-hidden="true"></span>
<?php echo Text::_('JCANCEL'); ?>
</button>
<?php if ($this->params->get('save_history', 0) && $this->item->id) : ?>
<?php echo $this->form->getInput('contenthistory'); ?>
<?php endif; ?>
</div>
<div class="mb-2">
<button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('weblink.save')">
<span class="icon-check" aria-hidden="true"></span>
<?php echo Text::_('JSAVE'); ?>
</button>
<button type="button" class="btn btn-danger" onclick="Joomla.submitbutton('weblink.cancel')">
<span class="icon-times" aria-hidden="true"></span>
<?php echo Text::_('JCANCEL'); ?>
</button>
<?php if ($this->params->get('save_history', 0) && $this->item->id) :
?>
<?php echo $this->form->getInput('contenthistory'); ?>
<?php
endif; ?>
</div>
<input type="hidden" name="return" value="<?php echo $this->return_page;?>" />
<input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>
<input type="hidden" name="return" value="<?php echo $this->return_page;?>" />
<input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>
</div>

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
@ -7,105 +8,120 @@
* @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\HTML\HTMLHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\String\PunycodeHelper;
$weblinkUrl = PunycodeHelper::urlToUTF8($this->item->url);
$user = Factory::getApplication()->getIdentity();
$canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
if (!$canEdit)
{
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->item->catid);
$canEdit = $canEditOwn && $this->item->created_by == $user->id;
if (!$canEdit) {
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->item->catid);
$canEdit = $canEditOwn && $this->item->created_by == $user->id;
}
?>
<div class="item-page">
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" />
<div class="page-header">
<h2 itemprop="headline">
<?php echo $this->escape($this->item->title); ?>
</h2>
</div>
<?php if ($canEdit) : ?>
<div class="icons">
<div class="float-end">
<div>
<?php echo HTMLHelper::_('weblinkicon.edit', $this->item, $this->item->params); ?>
</div>
</div>
</div>
<?php endif; ?>
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" />
<div class="page-header">
<h2 itemprop="headline">
<?php echo $this->escape($this->item->title); ?>
</h2>
</div>
<?php if ($canEdit) :
?>
<div class="icons">
<div class="float-end">
<div>
<?php echo HTMLHelper::_('weblinkicon.edit', $this->item, $this->item->params); ?>
</div>
</div>
</div>
<?php
endif; ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $this->item->event->afterDisplayTitle; ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $this->item->event->afterDisplayTitle; ?>
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
<div itemprop="articleBody">
<div class="p-3">
<a href="<?php echo $weblinkUrl; ?>" target="_blank" itemprop="url">
<?php echo $weblinkUrl; ?>
</a>
</div>
<div itemprop="articleBody">
<div class="p-3">
<a href="<?php echo $weblinkUrl; ?>" target="_blank" itemprop="url">
<?php echo $weblinkUrl; ?>
</a>
</div>
<?php if ($this->params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) : ?>
<div class="p-2">
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) :
?>
<div class="p-2">
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
</div>
<?php
endif; ?>
<div class="p-3">
<?php $images = json_decode($this->item->images); ?>
<?php if (!empty($images->image_first)) : ?>
<?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) : ?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_first_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) : ?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<div class="p-3">
<?php $images = json_decode($this->item->images); ?>
<?php if (!empty($images->image_first)) :
?>
<?php $imgFloat = '';?>
<?php if (!empty($images->float_first)) :
?>
<?php $imgFloat = $images->float_first == 'right' ? 'float-end' : 'float-start'; ?>
<?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_first); ?>
<?php $alt = empty($images->image_first_alt) && empty($images->image_first_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_first_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_first_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_first_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php
endif; ?>
</figure>
<?php
endif; ?>
<?php if (!empty($images->image_second)) : ?>
<?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) : ?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_second_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) : ?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<?php if (!empty($images->image_second)) :
?>
<?php $imgFloat = ''; ?>
<?php if (!empty($images->float_second)) :
?>
<?php $imgFloat = $images->float_second == 'right' ? 'float-end' : 'float-start'; ?>
<?php
endif; ?>
<?php $img = HTMLHelper::cleanImageURL($images->image_second); ?>
<?php $alt = empty($images->image_second_alt) && empty($images->image_second_alt_empty)
? ''
: 'alt="' . htmlspecialchars($images->image_second_alt, ENT_COMPAT, 'UTF-8') . '"'; ?>
<figure class="item-image <?php echo $imgFloat; ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?> itemprop="thumbnail" />
<?php if (!empty($images->image_second_caption)) :
?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_second_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php
endif; ?>
</figure>
<?php
endif; ?>
<?php if (!empty($this->item->description)) : ?>
<?php echo $this->item->description; ?>
<?php endif; ?>
<?php if (!empty($this->item->description)) :
?>
<?php echo $this->item->description; ?>
<?php
endif; ?>
</div>
</div>
</div>
<?php // Content is generated by content plugin event "onContentAfterDisplay" ?>
<?php echo $this->item->event->afterDisplayContent; ?>
</div>
<?php // Content is generated by content plugin event "onContentAfterDisplay" ?>
<?php echo $this->item->event->afterDisplayContent; ?>
</div>

View File

@ -8,7 +8,9 @@
* @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\Module;
@ -22,20 +24,20 @@ use Joomla\DI\ServiceProviderInterface;
* @since __DEPLOY_VERSION__
*/
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Weblinks'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Weblinks\\Site\\Helper'));
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Weblinks'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Weblinks\\Site\\Helper'));
$container->registerServiceProvider(new Module());
}
$container->registerServiceProvider(new Module());
}
};

View File

@ -14,9 +14,11 @@ use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
// phpcs:disable PSR1.Files.SideEffects
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
// phpcs:enable PSR1.Files.SideEffects
/**
* Dispatcher class for mod_weblinks
@ -25,26 +27,26 @@ use Joomla\CMS\Helper\HelperFactoryAwareTrait;
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;
use HelperFactoryAwareTrait;
/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
$data['list'] = $this->getHelperFactory()->getHelper('WeblinksHelper')->getWeblinks(
$data['params'],
$this->getApplication()
);
$data['list'] = $this->getHelperFactory()->getHelper('WeblinksHelper')->getWeblinks(
$data['params'],
$this->getApplication()
);
$data['moduleclass_sfx'] = htmlspecialchars($data['params']->get('moduleclass_sfx', ''));
$data['moduleclass_sfx'] = htmlspecialchars($data['params']->get('moduleclass_sfx', ''));
return $data;
}
return $data;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Component\ComponentHelper;
@ -23,117 +26,112 @@ use Joomla\Registry\Registry;
*/
class WeblinksHelper
{
/**
* Retrieve list of weblinks
*
* @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application
*
* @return array Array containing all the weblinks.
*
* @since __DEPLOY_VERSION__
**/
public function getWeblinks($params, $app)
{
// @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model
$model = $app->bootComponent('com_weblinks')->getMVCFactory()
->createModel('Category', 'Site', ['ignore_request' => true]);
/**
* Retrieve list of weblinks
*
* @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application
*
* @return array Array containing all the weblinks.
*
* @since __DEPLOY_VERSION__
**/
public function getWeblinks($params, $app)
{
// @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model
$model = $app->bootComponent('com_weblinks')->getMVCFactory()
->createModel('Category', 'Site', ['ignore_request' => true]);
// Set application parameters in model
$cParams = ComponentHelper::getParams('com_weblinks');
$model->setState('params', $cParams);
// Set application parameters in model
$cParams = ComponentHelper::getParams('com_weblinks');
$model->setState('params', $cParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $params->get('count', 5));
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $params->get('count', 5));
$model->setState('filter.state', 1);
$model->setState('filter.publish_date', true);
$model->setState('filter.state', 1);
$model->setState('filter.publish_date', true);
// Access filter
$access = !ComponentHelper::getParams('com_weblinks')->get('show_noauth');
$model->setState('filter.access', $access);
// Access filter
$access = !ComponentHelper::getParams('com_weblinks')->get('show_noauth');
$model->setState('filter.access', $access);
$ordering = $params->get('ordering', 'ordering');
$model->setState('list.ordering', $ordering == 'order' ? 'ordering' : $ordering);
$model->setState('list.direction', $params->get('direction', 'asc'));
$ordering = $params->get('ordering', 'ordering');
$model->setState('list.ordering', $ordering == 'order' ? 'ordering' : $ordering);
$model->setState('list.direction', $params->get('direction', 'asc'));
$catid = (int) $params->get('catid', 0);
$model->setState('category.id', $catid);
$model->setState('category.group', $params->get('groupby', 0));
$model->setState('category.ordering', $params->get('groupby_ordering', 'c.lft'));
$model->setState('category.direction', $params->get('groupby_direction', 'ASC'));
$catid = (int) $params->get('catid', 0);
$model->setState('category.id', $catid);
$model->setState('category.group', $params->get('groupby', 0));
$model->setState('category.ordering', $params->get('groupby_ordering', 'c.lft'));
$model->setState('category.direction', $params->get('groupby_direction', 'ASC'));
// Create query object
$db = $model->getDbo();
$query = $db->getQuery(true);
// Create query object
$db = $model->getDbo();
$query = $db->getQuery(true);
$case_when1 = ' CASE WHEN ';
$case_when1 .= $query->charLength('a.alias', '!=', '0');
$case_when1 .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$case_when1 .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when1 .= ' ELSE ';
$case_when1 .= $a_id . ' END as slug';
$case_when1 = ' CASE WHEN ';
$case_when1 .= $query->charLength('a.alias', '!=', '0');
$case_when1 .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$case_when1 .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when1 .= ' ELSE ';
$case_when1 .= $a_id . ' END as slug';
$case_when2 = ' CASE WHEN ';
$case_when2 .= $query->charLength('c.alias', '!=', '0');
$case_when2 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$case_when2 .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when2 .= ' ELSE ';
$case_when2 .= $c_id . ' END as catslug';
$case_when2 = ' CASE WHEN ';
$case_when2 .= $query->charLength('c.alias', '!=', '0');
$case_when2 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$case_when2 .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when2 .= ' ELSE ';
$case_when2 .= $c_id . ' END as catslug';
$model->setState(
'list.select',
'a.*, c.description AS c_description, c.published AS c_published,' . $case_when1 . ',' . $case_when2
);
$model->setState(
'list.select',
'a.*, c.description AS c_description, c.published AS c_published,' . $case_when1 . ',' . $case_when2
);
$model->setState('filter.c.published', 1);
$model->setState('filter.c.published', 1);
// Filter by language
$model->setState('filter.language', $app->getLanguageFilter());
// Filter by language
$model->setState('filter.language', $app->getLanguageFilter());
$items = $model->getItems();
$items = $model->getItems();
if ($items)
{
foreach ($items as $item)
{
$temp = $item->params;
$item->params = clone $cParams;
$item->params->merge($temp);
if ($items) {
foreach ($items as $item) {
$temp = $item->params;
$item->params = clone $cParams;
$item->params->merge($temp);
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);
}
else
{
$item->link = $item->url;
}
}
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);
} else {
$item->link = $item->url;
}
}
return $items;
}
return $items;
}
return [];
}
return [];
}
/**
* Retrieve list of weblinks
*
* @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application
*
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
*
* @since 1.5
*
* @deprecated 5.0 Use the none static function getWeblinks
**/
public static function getList($params, $app)
{
return (new self())->getWeblinks($params, $app);
}
/**
* Retrieve list of weblinks
*
* @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application
*
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
*
* @since 1.5
*
* @deprecated 5.0 Use the none static function getWeblinks
**/
public static function getList($params, $app)
{
return (new self())->getWeblinks($params, $app);
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -7,148 +8,181 @@
* @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\Language\Text;
?>
<?php if ($params->get('groupby', 0)) : ?>
<?php $cats = [] ?>
<?php $cols = $params->get('groupby_columns', 3); ?>
<?php foreach ($list as $l) : ?>
<?php $cats[] = array('catid' => $l->catid, 'title' => $l->category_title); ?>
<?php endforeach; ?>
<?php $cats = array_values(array_map('unserialize', array_unique(array_map('serialize', $cats)))); ?>
<?php foreach ($cats as $k => $cat) : ?>
<?php $items = []; ?>
<?php foreach ($list as $item) : ?>
<?php if ($item->catid == $cat['catid']) : ?>
<?php $items[] = $item; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($cols > 1) :?>
<?php if ($k % $cols == 0) : ?>
<div class="row row-fluid">
<?php endif; ?>
<div class="col-' . 12 / $cols . '">
<?php endif; ?>
<?php if ($params->get('groupby_showtitle', 1)) :?>
<strong> <?php echo htmlspecialchars($cat['title'], ENT_COMPAT, 'UTF-8'); ?></strong>
<?php endif; ?>;
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($items as $item) : ?>
<li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1">
<?php
$link = $item->link;
$width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500);
<?php if ($params->get('groupby', 0)) :
?>
<?php $cats = [] ?>
<?php $cols = $params->get('groupby_columns', 3); ?>
<?php foreach ($list as $l) :
?>
<?php $cats[] = array('catid' => $l->catid, 'title' => $l->category_title); ?>
<?php
endforeach; ?>
<?php $cats = array_values(array_map('unserialize', array_unique(array_map('serialize', $cats)))); ?>
<?php foreach ($cats as $k => $cat) :
?>
<?php $items = []; ?>
<?php foreach ($list as $item) :
?>
<?php if ($item->catid == $cat['catid']) :
?>
<?php $items[] = $item; ?>
<?php
endif; ?>
<?php
endforeach; ?>
<?php if ($cols > 1) :
?>
<?php if ($k % $cols == 0) :
?>
<div class="row row-fluid">
<?php
endif; ?>
<div class="col-' . 12 / $cols . '">
<?php
endif; ?>
<?php if ($params->get('groupby_showtitle', 1)) :
?>
<strong> <?php echo htmlspecialchars($cat['title'], ENT_COMPAT, 'UTF-8'); ?></strong>
<?php
endif; ?>;
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($items as $item) :
?>
<li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1">
<?php
$link = $item->link;
$width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500);
switch ($item->params->get('target')) {
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 2:
// Open in a popup window
$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;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
switch ($item->params->get('target'))
{
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 2:
// Open in a popup window
$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;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . '
</button>';
break;
default:
// Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
}
?>
</div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) : ?>
<div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"> <?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php if ($cols > 1) :?>
</div>
<?php if (($k + 1) % $cols == 0 || $k == count($cats) - 1) : ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else : ?>
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :?>
<li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1">
<?php
$link = $item->link;
$width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500);
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . '</button>';
switch ($item->params->get('target'))
{
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 2:
// Open in a popup window
$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;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
break;
default:
// Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
}
?>
</div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) :
?>
<div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"> <?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div>
<?php
endif; ?>
</li>
<?php
endforeach; ?>
</ul>
<?php if ($cols > 1) :
?>
</div>
<?php if (($k + 1) % $cols == 0 || $k == count($cats) - 1) :
?>
</div>
<?php
endif; ?>
<?php
endif; ?>
<?php
endforeach; ?>
<?php
else :
?>
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :
?>
<li><div class="d-flex flex-wrap">
<div class="col flex-sm-grow-1">
<?php
$link = $item->link;
$width = (int) $item->params->get('width', 600);
$height = (int) $item->params->get('height', 500);
switch ($item->params->get('target')) {
case 1:
// Open in a new window
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 2:
// Open in a popup window
$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;\">" .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
case 3:
// Open in a modal window
$modalId = 'weblink-item-modal-' . $item->id;
$modalParams['title'] = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');
$modalParams['url'] = $link;
$modalParams['height'] = '100%';
$modalParams['width'] = '100%';
$modalParams['bodyHeight'] = 70;
$modalParams['modalWidth'] = 80;
echo HTMLHelper::_('bootstrap.renderModal', $modalId, $modalParams);
echo '<button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#' . $modalId . '">
' . $item->title . '
</button>';
break;
default:
// Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
}
?>
</div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) : ?>
<div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"><?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
break;
default:
// Open in parent window
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
break;
}
?>
</div>
<?php echo $params->get('description', 0) ? '<div class="col flex-sm-grow-1">' . $item->description . '</div>' : ''; ?>
<?php if ($params->get('hits', 0)) :
?>
<div class="col flex-sm-grow-1">
<span class="badge bg-info float-md-end"><?php echo $item->hits . ' ' . Text::_('MOD_WEBLINKS_HITS'); ?></span>
</div>
<?php
endif; ?>
</li>
<?php
endforeach; ?>
</ul>
<?php
endif; ?>

View File

@ -8,7 +8,9 @@
* @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\Factory;
@ -19,29 +21,29 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\EditorsXtd\Weblink\Extension\Weblink;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$app = Factory::getApplication();
$dispatcher = $container->get(DispatcherInterface::class);
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$app = Factory::getApplication();
$dispatcher = $container->get(DispatcherInterface::class);
return new Weblink(
$dispatcher,
(array) PluginHelper::getPlugin('editors-xtd', 'weblink'),
$app
);
}
);
}
return new Weblink(
$dispatcher,
(array) PluginHelper::getPlugin('editors-xtd', 'weblink'),
$app
);
}
);
}
};

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors-xtd.weblink
@ -9,7 +10,9 @@
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\Language\Text;
@ -27,67 +30,69 @@ use Joomla\Event\DispatcherInterface;
*/
final class Weblink extends CMSPlugin
{
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application)
{
parent::__construct($dispatcher, $config);
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application)
{
parent::__construct($dispatcher, $config);
$this->setApplication($application);
}
$this->setApplication($application);
}
/**
* Display the button
*
* @param string $name The name of the button to add
*
* @return CMSObject The button options as JObject
*
* @since __DEPLOY_VERSION__
*/
public function onDisplay($name)
{
$user = $this->getApplication()->getIdentity();
/**
* Display the button
*
* @param string $name The name of the button to add
*
* @return CMSObject The button options as JObject
*
* @since __DEPLOY_VERSION__
*/
public function onDisplay($name)
{
$user = $this->getApplication()->getIdentity();
if ($user->authorise('core.create', 'com_weblinks')
|| $user->authorise('core.edit', 'com_weblinks')
|| $user->authorise('core.edit.own', 'com_weblinks'))
{
// The URL for the weblinks list
$link = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;'
. Session::getFormToken() . '=1&amp;editor=' . $name;
if (
$user->authorise('core.create', 'com_weblinks')
|| $user->authorise('core.edit', 'com_weblinks')
|| $user->authorise('core.edit.own', 'com_weblinks')
) {
// The URL for the weblinks list
$link = 'index.php?option=com_weblinks&amp;view=weblinks&amp;layout=modal&amp;tmpl=component&amp;'
. Session::getFormToken() . '=1&amp;editor=' . $name;
$button = new CMSObject;
$button->modal = true;
$button->link = $link;
$button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK');
$button->name = $this->_type . '_' . $this->_name;
$button->icon = 'globe';
$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 = new CMSObject();
$button->modal = true;
$button->link = $link;
$button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK');
$button->name = $this->_type . '_' . $this->_name;
$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">
<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>';
// phpcs:enable Generic.Files.LineLength
$button->options = [
'height' => '300px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
];
$button->options = [
'height' => '300px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
];
return $button;
}
}
return $button;
}
}
}

View File

@ -8,7 +8,9 @@
* @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\Plugin\PluginHelper;
@ -19,29 +21,29 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Finder\Weblinks\Extension\Weblinks;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('finder', 'weblinks'),
$database
);
}
);
}
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('finder', 'weblinks'),
$database
);
}
);
}
};

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -9,7 +10,9 @@
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\Component\ComponentHelper;
@ -32,377 +35,359 @@ use Joomla\Registry\Registry;
*/
final class Weblinks extends Adapter
{
use DatabaseAwareTrait;
use DatabaseAwareTrait;
/**
* The plugin identifier.
*
* @var string
* @since 2.5
*/
protected $context = 'Weblinks';
/**
* The plugin identifier.
*
* @var string
* @since 2.5
*/
protected $context = 'Weblinks';
/**
* The extension name.
*
* @var string
* @since 2.5
*/
protected $extension = 'com_weblinks';
/**
* The extension name.
*
* @var string
* @since 2.5
*/
protected $extension = 'com_weblinks';
/**
* The sublayout to use when rendering the results.
*
* @var string
* @since 2.5
*/
protected $layout = 'weblink';
/**
* The sublayout to use when rendering the results.
*
* @var string
* @since 2.5
*/
protected $layout = 'weblink';
/**
* The type of content that the adapter indexes.
*
* @var string
* @since 2.5
*/
protected $type_title = 'Web Link';
/**
* The type of content that the adapter indexes.
*
* @var string
* @since 2.5
*/
protected $type_title = 'Web Link';
/**
* The table name.
*
* @var string
* @since 2.5
*/
protected $table = '#__weblinks';
/**
* The table name.
*
* @var string
* @since 2.5
*/
protected $table = '#__weblinks';
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = true;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
$this->setDatabase($database);
}
$this->setDatabase($database);
}
/**
* Method to update the item link information when the item category is
* changed. This is fired when the item category is published or unpublished
* from the list view.
*
* @param string $extension The extension whose category has been updated.
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
*
* @return void
*
* @since 2.5
*/
public function onFinderCategoryChangeState($extension, $pks, $value)
{
// Make sure we're handling com_weblinks categories.
if ($extension == 'com_weblinks')
{
$this->categoryStateChange($pks, $value);
}
}
/**
* Method to update the item link information when the item category is
* changed. This is fired when the item category is published or unpublished
* from the list view.
*
* @param string $extension The extension whose category has been updated.
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
*
* @return void
*
* @since 2.5
*/
public function onFinderCategoryChangeState($extension, $pks, $value)
{
// Make sure we're handling com_weblinks categories.
if ($extension == 'com_weblinks') {
$this->categoryStateChange($pks, $value);
}
}
/**
* Method to remove the link information for items that have been deleted.
*
* @param string $context The context of the action being performed.
* @param Table $table A JTable object containing the record to be deleted.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderAfterDelete($context, $table)
{
if ($context == 'com_weblinks.weblink')
{
$id = $table->id;
}
elseif ($context == 'com_finder.index')
{
$id = $table->link_id;
}
else
{
return true;
}
/**
* Method to remove the link information for items that have been deleted.
*
* @param string $context The context of the action being performed.
* @param Table $table A JTable object containing the record to be deleted.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderAfterDelete($context, $table)
{
if ($context == 'com_weblinks.weblink') {
$id = $table->id;
} elseif ($context == 'com_finder.index') {
$id = $table->link_id;
} else {
return true;
}
// Remove the item from the index.
return $this->remove($id);
}
// Remove the item from the index.
return $this->remove($id);
}
/**
* Smart Search after content save method.
* Reindexes the link information for a weblink that has been saved.
* It also makes adjustments if the access level of a weblink item or
* the category to which it belongs has been changed.
*
* @param string $context The context of the content passed to the plugin.
* @param Table $row A JTable object.
* @param boolean $isNew True if the content has just been created.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderAfterSave($context, $row, $isNew)
{
// 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')
{
// Check if the access levels are different.
if (!$isNew && $this->old_access != $row->access)
{
// Process the change.
$this->itemAccessChange($row);
}
/**
* Smart Search after content save method.
* Reindexes the link information for a weblink that has been saved.
* It also makes adjustments if the access level of a weblink item or
* the category to which it belongs has been changed.
*
* @param string $context The context of the content passed to the plugin.
* @param Table $row A JTable object.
* @param boolean $isNew True if the content has just been created.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderAfterSave($context, $row, $isNew)
{
// 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') {
// Check if the access levels are different.
if (!$isNew && $this->old_access != $row->access) {
// Process the change.
$this->itemAccessChange($row);
}
// Reindex the item.
$this->reindex($row->id);
}
// Reindex the item.
$this->reindex($row->id);
}
// Check for access changes in the category.
if ($context == 'com_categories.category')
{
// Check if the access levels are different.
if (!$isNew && $this->old_cataccess != $row->access)
{
$this->categoryAccessChange($row);
}
}
// Check for access changes in the category.
if ($context == 'com_categories.category') {
// Check if the access levels are different.
if (!$isNew && $this->old_cataccess != $row->access) {
$this->categoryAccessChange($row);
}
}
return true;
}
return true;
}
/**
* Smart Search before content save method.
* This event is fired before the data is actually saved.
*
* @param string $context The context of the content passed to the plugin.
* @param Table $row A JTable object.
* @param boolean $isNew True if the content is just about to be created.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderBeforeSave($context, $row, $isNew)
{
// We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form')
{
// Query the database for the old access level if the item isn't new.
if (!$isNew)
{
$this->checkItemAccess($row);
}
}
/**
* Smart Search before content save method.
* This event is fired before the data is actually saved.
*
* @param string $context The context of the content passed to the plugin.
* @param Table $row A JTable object.
* @param boolean $isNew True if the content is just about to be created.
*
* @return boolean True on success.
*
* @throws \Exception on database error.
* @since 2.5
*/
public function onFinderBeforeSave($context, $row, $isNew)
{
// We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') {
// Query the database for the old access level if the item isn't new.
if (!$isNew) {
$this->checkItemAccess($row);
}
}
// Check for access levels from the category.
if ($context == 'com_categories.category')
{
// Query the database for the old access level if the item isn't new.
if (!$isNew)
{
$this->checkCategoryAccess($row);
}
}
// Check for access levels from the category.
if ($context == 'com_categories.category') {
// Query the database for the old access level if the item isn't new.
if (!$isNew) {
$this->checkCategoryAccess($row);
}
}
return true;
}
return true;
}
/**
* Method to update the link information for items that have been changed
* from outside the edit screen. This is fired when the item is published,
* unpublished, archived, or unarchived from the list view.
*
* @param string $context The context for the content passed to the plugin.
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
*
* @return void
*
* @since 2.5
*/
public function onFinderChangeState($context, $pks, $value)
{
// We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form')
{
$this->itemStateChange($pks, $value);
}
/**
* Method to update the link information for items that have been changed
* from outside the edit screen. This is fired when the item is published,
* unpublished, archived, or unarchived from the list view.
*
* @param string $context The context for the content passed to the plugin.
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
*
* @return void
*
* @since 2.5
*/
public function onFinderChangeState($context, $pks, $value)
{
// We only want to handle web links here.
if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') {
$this->itemStateChange($pks, $value);
}
// Handle when the plugin is disabled.
if ($context == 'com_plugins.plugin' && $value === 0)
{
$this->pluginDisable($pks);
}
}
// Handle when the plugin is disabled.
if ($context == 'com_plugins.plugin' && $value === 0) {
$this->pluginDisable($pks);
}
}
/**
* Method to index an item. The item must be a FinderIndexerResult object.
*
* @param Result $item The item to index as an FinderIndexerResult object.
*
* @return void
*
* @throws \Exception on database error.
* @since 2.5
*/
protected function index(Result $item)
{
// Check if the extension is enabled
if (ComponentHelper::isEnabled($this->extension) == false)
{
return;
}
/**
* Method to index an item. The item must be a FinderIndexerResult object.
*
* @param Result $item The item to index as an FinderIndexerResult object.
*
* @return void
*
* @throws \Exception on database error.
* @since 2.5
*/
protected function index(Result $item)
{
// Check if the extension is enabled
if (ComponentHelper::isEnabled($this->extension) == false) {
return;
}
$item->setLanguage();
$item->setLanguage();
// Initialise the item parameters.
$item->params = new Registry($item->params);
$item->metadata = new Registry($item->metadata);
// Initialise the item parameters.
$item->params = new Registry($item->params);
$item->metadata = new Registry($item->metadata);
// Build the necessary route and path information.
$item->url = $this->getURL($item->id, $this->extension, $this->layout);
$item->route = RouteHelper::getWeblinkRoute($item->slug, $item->catslug, $item->language);
// Build the necessary route and path information.
$item->url = $this->getURL($item->id, $this->extension, $this->layout);
$item->route = RouteHelper::getWeblinkRoute($item->slug, $item->catslug, $item->language);
/*
* Add the meta-data processing instructions based on the newsfeeds
* configuration parameters.
*/
// Add the meta-author.
$item->metaauthor = $item->metadata->get('author');
/*
* Add the meta-data processing instructions based on the newsfeeds
* configuration parameters.
*/
// Add the meta-author.
$item->metaauthor = $item->metadata->get('author');
// Handle the link to the meta-data.
$item->addInstruction(Indexer::META_CONTEXT, 'link');
$item->addInstruction(Indexer::META_CONTEXT, 'metakey');
$item->addInstruction(Indexer::META_CONTEXT, 'metadesc');
$item->addInstruction(Indexer::META_CONTEXT, 'metaauthor');
$item->addInstruction(Indexer::META_CONTEXT, 'author');
$item->addInstruction(Indexer::META_CONTEXT, 'created_by_alias');
// Handle the link to the meta-data.
$item->addInstruction(Indexer::META_CONTEXT, 'link');
$item->addInstruction(Indexer::META_CONTEXT, 'metakey');
$item->addInstruction(Indexer::META_CONTEXT, 'metadesc');
$item->addInstruction(Indexer::META_CONTEXT, 'metaauthor');
$item->addInstruction(Indexer::META_CONTEXT, 'author');
$item->addInstruction(Indexer::META_CONTEXT, 'created_by_alias');
// Translate the state. Weblinks should only be published if the category is published and also ensure that 'state' for trashed items is set to zero
$item->state = $this->translateState($item->state, $item->cat_state);
// Translate the state. Weblinks should only be published if the category is published and also ensure that 'state' for trashed items is set to zero
$item->state = $this->translateState($item->state, $item->cat_state);
// Add the type taxonomy data.
$item->addTaxonomy('Type', 'Web Link');
// Add the type taxonomy data.
$item->addTaxonomy('Type', 'Web Link');
// Add the category taxonomy data.
$categories = Categories::getInstance('com_weblinks', ['published' => false, 'access' => false]);
$category = $categories->get($item->catid);
// Add the category taxonomy data.
$categories = Categories::getInstance('com_weblinks', ['published' => false, 'access' => false]);
$category = $categories->get($item->catid);
// Category does not exist, stop here
if (!$category)
{
return;
}
// Category does not exist, stop here
if (!$category) {
return;
}
$item->addNestedTaxonomy('Category', $category, $this->translateState($category->published), $category->access, $category->language);
$item->addNestedTaxonomy('Category', $category, $this->translateState($category->published), $category->access, $category->language);
// Add the language taxonomy data.
$item->addTaxonomy('Language', $item->language);
// Add the language taxonomy data.
$item->addTaxonomy('Language', $item->language);
// Get content extras.
Helper::getContentExtras($item);
// Get content extras.
Helper::getContentExtras($item);
// Index the item.
$this->indexer->index($item);
}
// Index the item.
$this->indexer->index($item);
}
/**
* Method to setup the indexer to be run.
*
* @return boolean True on success.
*
* @since 2.5
*/
protected function setup()
{
return true;
}
/**
* Method to setup the indexer to be run.
*
* @return boolean True on success.
*
* @since 2.5
*/
protected function setup()
{
return true;
}
/**
* Method to get the SQL query used to retrieve the list of content items.
*
* @param mixed $query A JDatabaseQuery object or null.
*
* @return DatabaseQuery A database object.
*
* @since 2.5
*/
protected function getListQuery($query = null)
{
$db = $this->getDatabase();
/**
* Method to get the SQL query used to retrieve the list of content items.
*
* @param mixed $query A JDatabaseQuery object or null.
*
* @return DatabaseQuery A database object.
*
* @since 2.5
*/
protected function getListQuery($query = null)
{
$db = $this->getDatabase();
// Check if we can use the supplied SQL query.
$query = $query instanceof DatabaseQuery ? $query : $db->getQuery(true)
->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary')
->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering')
->select('a.created_by_alias, a.modified, a.modified_by')
->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
->select('a.state AS state, a.created AS start_date, a.params')
->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');
// Check if we can use the supplied SQL query.
$query = $query instanceof DatabaseQuery ? $query : $db->getQuery(true)
->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary')
->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering')
->select('a.created_by_alias, a.modified, a.modified_by')
->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
->select('a.state AS state, a.created AS start_date, a.params')
->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');
// Handle the alias CASE WHEN portion of the query.
$case_when_item_alias = ' CASE WHEN ';
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
$case_when_item_alias .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$case_when_item_alias .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when_item_alias .= ' ELSE ';
$case_when_item_alias .= $a_id . ' END as slug';
$query->select($case_when_item_alias);
// Handle the alias CASE WHEN portion of the query.
$case_when_item_alias = ' CASE WHEN ';
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
$case_when_item_alias .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$case_when_item_alias .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when_item_alias .= ' ELSE ';
$case_when_item_alias .= $a_id . ' END as slug';
$query->select($case_when_item_alias);
$case_when_category_alias = ' CASE WHEN ';
$case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
$case_when_category_alias .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$case_when_category_alias .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when_category_alias .= ' ELSE ';
$case_when_category_alias .= $c_id . ' END as catslug';
$query->select($case_when_category_alias)
->from('#__weblinks AS a')
->join('LEFT', '#__categories AS c ON c.id = a.catid');
$case_when_category_alias = ' CASE WHEN ';
$case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
$case_when_category_alias .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$case_when_category_alias .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when_category_alias .= ' ELSE ';
$case_when_category_alias .= $c_id . ' END as catslug';
$query->select($case_when_category_alias)
->from('#__weblinks AS a')
->join('LEFT', '#__categories AS c ON c.id = a.catid');
return $query;
}
return $query;
}
/**
* Method to get the query clause for getting items to update by time.
*
* @param string $time The modified timestamp.
*
* @return DatabaseQuery A database object.
*
* @since 2.5
*/
protected function getUpdateQueryByTime($time)
{
// Build an SQL query based on the modified time.
$db = $this->getDatabase();
$query = $db->getQuery(true)
->where('a.date >= ' . $db->quote($time));
/**
* Method to get the query clause for getting items to update by time.
*
* @param string $time The modified timestamp.
*
* @return DatabaseQuery A database object.
*
* @since 2.5
*/
protected function getUpdateQueryByTime($time)
{
// Build an SQL query based on the modified time.
$db = $this->getDatabase();
$query = $db->getQuery(true)
->where('a.date >= ' . $db->quote($time));
return $query;
}
return $query;
}
}

View File

@ -8,7 +8,9 @@
* @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\Factory;
@ -20,31 +22,31 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Search\Weblinks\Extension\Weblinks;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$app = Factory::getApplication();
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$app = Factory::getApplication();
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('finder', 'weblinks'),
$app,
$database
);
}
);
}
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('finder', 'weblinks'),
$app,
$database
);
}
);
}
};

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -19,7 +20,9 @@ use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
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.
@ -28,220 +31,209 @@ defined('_JEXEC') or die;
*/
final class Weblinks extends CMSPlugin
{
use DatabaseAwareTrait;
use DatabaseAwareTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = true;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param CMSApplicationInterface $application
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param CMSApplicationInterface $application
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
$this->setApplication($application);
$this->setDatabase($database);
}
$this->setApplication($application);
$this->setDatabase($database);
}
/**
* Determine areas searchable by this plugin.
*
* @return array An array of search areas.
*
* @since 1.6
*/
public function onContentSearchAreas()
{
static $areas = [
'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS',
];
/**
* Determine areas searchable by this plugin.
*
* @return array An array of search areas.
*
* @since 1.6
*/
public function onContentSearchAreas()
{
static $areas = [
'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS',
];
return $areas;
}
return $areas;
}
/**
* Search content (weblinks).
*
* The SQL must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
*
* @param string $text Target search string.
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
* @param mixed $areas An array if the search it to be restricted to areas or null to search all areas.
*
* @return array Search results.
*
* @since 1.6
*/
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
{
$app = $this->getApplication();
$db = $this->getDatabase();
$groups = $app->getIdentity()->getAuthorisedViewLevels();
/**
* Search content (weblinks).
*
* The SQL must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
*
* @param string $text Target search string.
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
* @param mixed $areas An array if the search it to be restricted to areas or null to search all areas.
*
* @return array Search results.
*
* @since 1.6
*/
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
{
$app = $this->getApplication();
$db = $this->getDatabase();
$groups = $app->getIdentity()->getAuthorisedViewLevels();
$searchText = $text;
$searchText = $text;
if (is_array($areas)
&& !array_intersect($areas, array_keys($this->onContentSearchAreas())))
{
return [];
}
if (
is_array($areas)
&& !array_intersect($areas, array_keys($this->onContentSearchAreas()))
) {
return [];
}
$sContent = $this->params->get('search_content', 1);
$sArchived = $this->params->get('search_archived', 1);
$limit = $this->params->def('search_limit', 50);
$state = [];
$sContent = $this->params->get('search_content', 1);
$sArchived = $this->params->get('search_archived', 1);
$limit = $this->params->def('search_limit', 50);
$state = [];
if ($sContent)
{
$state[] = 1;
}
if ($sContent) {
$state[] = 1;
}
if ($sArchived)
{
$state[] = 2;
}
if ($sArchived) {
$state[] = 2;
}
if (empty($state))
{
return [];
}
if (empty($state)) {
return [];
}
$text = trim($text);
$text = trim($text);
if ($text == '')
{
return [];
}
if ($text == '') {
return [];
}
$searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS');
$searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS');
switch ($phrase)
{
case 'exact':
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
$wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $text;
$wheres2[] = 'a.description LIKE ' . $text;
$wheres2[] = 'a.title LIKE ' . $text;
$where = '(' . implode(') OR (', $wheres2) . ')';
break;
switch ($phrase) {
case 'exact':
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
$wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $text;
$wheres2[] = 'a.description LIKE ' . $text;
$wheres2[] = 'a.title LIKE ' . $text;
$where = '(' . implode(') OR (', $wheres2) . ')';
break;
case 'all':
case 'any':
default:
$words = explode(' ', $text);
$wheres = [];
case 'all':
case 'any':
default:
$words = explode(' ', $text);
$wheres = [];
foreach ($words as $word)
{
$word = $db->quote('%' . $db->escape($word, true) . '%', false);
$wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $word;
$wheres2[] = 'a.description LIKE ' . $word;
$wheres2[] = 'a.title LIKE ' . $word;
$wheres[] = implode(' OR ', $wheres2);
}
foreach ($words as $word) {
$word = $db->quote('%' . $db->escape($word, true) . '%', false);
$wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $word;
$wheres2[] = 'a.description LIKE ' . $word;
$wheres2[] = 'a.title LIKE ' . $word;
$wheres[] = implode(' OR ', $wheres2);
}
$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
break;
}
$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
break;
}
switch ($ordering)
{
case 'oldest':
$order = 'a.created ASC';
break;
switch ($ordering) {
case 'oldest':
$order = 'a.created ASC';
break;
case 'popular':
$order = 'a.hits DESC';
break;
case 'popular':
$order = 'a.hits DESC';
break;
case 'alpha':
$order = 'a.title ASC';
break;
case 'alpha':
$order = 'a.title ASC';
break;
case 'category':
$order = 'c.title ASC, a.title ASC';
break;
case 'category':
$order = 'c.title ASC, a.title ASC';
break;
case 'newest':
default:
$order = 'a.created DESC';
}
case 'newest':
default:
$order = 'a.created DESC';
}
$query = $db->getQuery(true);
$query = $db->getQuery(true);
// SQLSRV changes.
$caseWhen = ' CASE WHEN ';
$caseWhen .= $query->charLength('a.alias', '!=', '0');
$caseWhen .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$caseWhen .= $query->concatenate([$a_id, 'a.alias'], ':');
$caseWhen .= ' ELSE ';
$caseWhen .= $a_id . ' END as slug';
// SQLSRV changes.
$caseWhen = ' CASE WHEN ';
$caseWhen .= $query->charLength('a.alias', '!=', '0');
$caseWhen .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id');
$caseWhen .= $query->concatenate([$a_id, 'a.alias'], ':');
$caseWhen .= ' ELSE ';
$caseWhen .= $a_id . ' END as slug';
$caseWhen1 = ' CASE WHEN ';
$caseWhen1 .= $query->charLength('c.alias', '!=', '0');
$caseWhen1 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$caseWhen1 .= $query->concatenate([$c_id, 'c.alias'], ':');
$caseWhen1 .= ' ELSE ';
$caseWhen1 .= $c_id . ' END as catslug';
$caseWhen1 = ' CASE WHEN ';
$caseWhen1 .= $query->charLength('c.alias', '!=', '0');
$caseWhen1 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id');
$caseWhen1 .= $query->concatenate([$c_id, 'c.alias'], ':');
$caseWhen1 .= ' ELSE ';
$caseWhen1 .= $c_id . ' END as catslug';
$query->select('a.title AS title, a.created AS created, a.url, a.description AS text, ' . $caseWhen . "," . $caseWhen1)
->select($query->concatenate([$db->quote($searchWeblinks), 'c.title'], " / ") . ' AS section')
->select('\'1\' AS browsernav')
->from('#__weblinks AS a')
->join('INNER', '#__categories as c ON c.id = a.catid')
->where('(' . $where . ')')
->whereIn($db->quoteName('a.state'), $state)
->where($db->quoteName('c.published') . ' = 1')
->whereIn($db->quoteName('c.access'), $groups)
->order($order);
$query->select('a.title AS title, a.created AS created, a.url, a.description AS text, ' . $caseWhen . "," . $caseWhen1)
->select($query->concatenate([$db->quote($searchWeblinks), 'c.title'], " / ") . ' AS section')
->select('\'1\' AS browsernav')
->from('#__weblinks AS a')
->join('INNER', '#__categories as c ON c.id = a.catid')
->where('(' . $where . ')')
->whereIn($db->quoteName('a.state'), $state)
->where($db->quoteName('c.published') . ' = 1')
->whereIn($db->quoteName('c.access'), $groups)
->order($order);
// Filter by language.
// Filter by language.
if ($app->isClient('site') && Multilanguage::isEnabled())
{
$languages = [$app->getLanguage()->getTag(), '*'];
$query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING)
->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING);
}
if ($app->isClient('site') && Multilanguage::isEnabled()) {
$languages = [$app->getLanguage()->getTag(), '*'];
$query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING)
->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING);
}
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$return = [];
$return = [];
if ($rows)
{
foreach ($rows as $key => $row)
{
$rows[$key]->href = RouteHelper::getWeblinkRoute($row->slug, $row->catslug);
}
if ($rows) {
foreach ($rows as $key => $row) {
$rows[$key]->href = RouteHelper::getWeblinkRoute($row->slug, $row->catslug);
}
foreach ($rows as $weblink)
{
if (\searchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title']))
{
$return[] = $weblink;
}
}
}
foreach ($rows as $weblink) {
if (\searchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title'])) {
$return[] = $weblink;
}
}
}
return $return;
}
return $return;
}
}

View File

@ -8,7 +8,9 @@
* @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\Plugin\PluginHelper;
@ -19,29 +21,29 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\System\Weblinks\Extension\Weblinks;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'weblinks'),
$database
);
}
);
}
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('system', 'weblinks'),
$database
);
}
);
}
};

View File

@ -1,4 +1,5 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
@ -18,7 +19,9 @@ use Joomla\Event\DispatcherInterface;
use Joomla\Event\Event;
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.
@ -27,99 +30,96 @@ defined('_JEXEC') or die;
*/
final class Weblinks extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use DatabaseAwareTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;
/**
* Supported Extensions
*
* @var array
* @since __DEPLOY_VERSION__
*/
private $supportedExtensions = [
'mod_stats',
'mod_stats_admin',
];
/**
* Supported Extensions
*
* @var array
* @since __DEPLOY_VERSION__
*/
private $supportedExtensions = [
'mod_stats',
'mod_stats_admin',
];
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
$this->setDatabase($database);
}
$this->setDatabase($database);
}
/**
* Returns an array of CMS events this plugin will listen to and the respective handlers.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onGetStats' => 'onGetStats',
];
}
/**
* Returns an array of CMS events this plugin will listen to and the respective handlers.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onGetStats' => 'onGetStats',
];
}
/**
* Method to add statistics information to Administrator control panel.
*
* @param string $extension The extension requesting information.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onGetStats(Event $event)
{
if (!ComponentHelper::isEnabled('com_weblinks'))
{
return;
}
/**
* Method to add statistics information to Administrator control panel.
*
* @param string $extension The extension requesting information.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onGetStats(Event $event)
{
if (!ComponentHelper::isEnabled('com_weblinks')) {
return;
}
[$extension] = $event->getArguments();
[$extension] = $event->getArguments();
if (!in_array($extension, $this->supportedExtensions))
{
return;
}
if (!in_array($extension, $this->supportedExtensions)) {
return;
}
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('COUNT(id) AS count_links')
->from('#__weblinks')
->where('state = 1');
$webLinks = $db->setQuery($query)->loadResult();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('COUNT(id) AS count_links')
->from('#__weblinks')
->where('state = 1');
$webLinks = $db->setQuery($query)->loadResult();
if (!$webLinks)
{
return;
}
if (!$webLinks) {
return;
}
$result = $event->getArgument('result', []);
$result[] = [
[
'title' => Text::_('PLG_SYSTEM_WEBLINKS_STATISTICS'),
'icon' => 'out-2',
'data' => $webLinks,
],
];
$result = $event->getArgument('result', []);
$result[] = [
[
'title' => Text::_('PLG_SYSTEM_WEBLINKS_STATISTICS'),
'icon' => 'out-2',
'data' => $webLinks,
],
];
$event->setArgument('result', $result);
}
$event->setArgument('result', $result);
}
}