32
1
mirror of https://github.com/joomla-extensions/weblinks.git synced 2025-01-12 07:55:53 +00:00

Make weblinks 4.0-compatible

This commit is contained in:
Tuan Pham Ngoc 2021-06-19 21:17:09 +07:00
parent c1cff7a7ed
commit b318b68d07
55 changed files with 1463 additions and 1412 deletions

View File

@ -14,153 +14,7 @@ defined('_JEXEC') or die;
* *
* @since 1.6 * @since 1.6
*/ */
class WeblinksHelper extends JHelperContent class WeblinksHelper extends \Joomla\Component\Weblinks\Administrator\Controller\WeblinksHelper
{ {
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*
* @since 1.6
*/
public static function addSubmenu($vName = 'weblinks')
{
JHtmlSidebar::addEntry(
JText::_('COM_WEBLINKS_SUBMENU_WEBLINKS'),
'index.php?option=com_weblinks&view=weblinks',
$vName == 'weblinks'
);
JHtmlSidebar::addEntry(
JText::_('COM_WEBLINKS_SUBMENU_CATEGORIES'),
'index.php?option=com_categories&extension=com_weblinks',
$vName == 'categories'
);
if (JComponentHelper::isEnabled('com_fields') && JComponentHelper::getParams('com_weblinks')->get('custom_fields_enable', '1'))
{
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELDS'),
'index.php?option=com_fields&context=com_weblinks.weblink',
$vName == 'fields.fields'
);
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELD_GROUPS'),
'index.php?option=com_fields&view=groups&context=com_weblinks.weblink',
$vName == 'fields.groups'
);
}
}
/**
* Adds Count Items for WebLinks Category Manager.
*
* @param stdClass[] &$items The weblinks category objects.
*
* @return stdClass[] The weblinks category objects.
*
* @since 3.6.0
*/
public static function countItems(&$items)
{
$db = JFactory::getDbo();
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true)
->select('state, COUNT(*) AS count')
->from($db->qn('#__weblinks'))
->where($db->qn('catid') . ' = ' . (int) $item->id)
->group('state');
$db->setQuery($query);
$weblinks = $db->loadObjectList();
foreach ($weblinks as $weblink)
{
if ($weblink->state == 1)
{
$item->count_published = $weblink->count;
}
elseif ($weblink->state == 0)
{
$item->count_unpublished = $weblink->count;
}
elseif ($weblink->state == 2)
{
$item->count_archived = $weblink->count;
}
elseif ($weblink->state == -2)
{
$item->count_trashed = $weblink->count;
}
}
}
return $items;
}
/**
* Adds Count Items for Tag Manager.
*
* @param stdClass[] &$items The weblink tag objects
* @param string $extension The name of the active view.
*
* @return stdClass[]
*
* @since 3.7.0
*/
public static function countTagItems(&$items, $extension)
{
$db = JFactory::getDbo();
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select('published as state, count(*) AS count')
->from($db->qn('#__contentitem_tag_map') . 'AS ct ')
->where('ct.tag_id = ' . (int) $item->id)
->where('ct.type_alias =' . $db->q($extension))
->join('LEFT', $db->qn('#__categories') . ' AS c ON ct.content_item_id=c.id')
->group('state');
$db->setQuery($query);
$weblinks = $db->loadObjectList();
foreach ($weblinks as $weblink)
{
if ($weblink->state == 1)
{
$item->count_published = $weblink->count;
}
if ($weblink->state == 0)
{
$item->count_unpublished = $weblink->count;
}
if ($weblink->state == 2)
{
$item->count_archived = $weblink->count;
}
if ($weblink->state == -2)
{
$item->count_trashed = $weblink->count;
}
}
}
return $items;
}
} }

View File

@ -9,11 +9,13 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Categories\CategoryFactoryInterface; use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Component\Router\RouterFactoryInterface;
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface; use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface; use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\Service\Provider\CategoryFactory; use Joomla\CMS\Extension\Service\Provider\CategoryFactory;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory; use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory; use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\Extension\Service\Provider\RouterFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Component\Weblinks\Administrator\Extension\WeblinksComponent; use Joomla\Component\Weblinks\Administrator\Extension\WeblinksComponent;
use Joomla\DI\Container; use Joomla\DI\Container;
@ -26,30 +28,31 @@ use Joomla\DI\ServiceProviderInterface;
*/ */
return new class implements ServiceProviderInterface return new class implements ServiceProviderInterface
{ {
/** /**
* Registers the service provider with a DI container. * Registers the service provider with a DI container.
* *
* @param Container $container The DI container. * @param Container $container The DI container.
* *
* @return void * @return void
* *
* @since 4.0.0 * @since 4.0.0
*/ */
public function register(Container $container) public function register(Container $container)
{ {
$container->registerServiceProvider(new CategoryFactory('\\Joomla\\Component\\Weblinks')); $container->registerServiceProvider(new CategoryFactory('\\Joomla\\Component\\Weblinks'));
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Weblinks')); $container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Weblinks'));
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Weblinks')); $container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Weblinks'));
$container->set( $container->registerServiceProvider(new RouterFactory('\\Joomla\\Component\\Weblinks'));
ComponentInterface::class, $container->set(
function (Container $container) ComponentInterface::class,
{ function (Container $container) {
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class)); $component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class)); $component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class)); $component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
return $component; return $component;
} }
); );
} }
}; };

View File

@ -37,14 +37,12 @@ class DisplayController extends BaseController
* @param array $urlparams An array of safe url parameters and their variable types, * @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}. * for valid values see {@link JFilterInput::clean()}.
* *
* @return JControllerLegacy This object to support chaining. * @return BaseController|boolean This object to support chaining.
* *
* @since 1.5 * @since 1.5
*/ */
public function display($cacheable = false, $urlparams = false) public function display($cacheable = false, $urlparams = false)
{ {
require_once JPATH_COMPONENT . '/helpers/weblinks.php';
$view = $this->input->get('view', 'weblinks'); $view = $this->input->get('view', 'weblinks');
$layout = $this->input->get('layout', 'default'); $layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('id'); $id = $this->input->getInt('id');
@ -53,8 +51,11 @@ class DisplayController extends BaseController
if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{ {
// Somehow the person just went to the form - we don't allow that. // Somehow the person just went to the form - we don't allow that.
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); if (!\count($this->app->getMessageQueue()))
$this->setMessage($this->getError(), 'error'); {
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
}
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false)); $this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
return false; return false;

View File

@ -11,6 +11,7 @@ namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\Utilities\ArrayHelper; use Joomla\Utilities\ArrayHelper;
/** /**
@ -18,7 +19,7 @@ use Joomla\Utilities\ArrayHelper;
* *
* @since 1.6 * @since 1.6
*/ */
class WeblinkController extends \JControllerForm class WeblinkController extends FormController
{ {
/** /**
* Method override to check if you can add a new record. * Method override to check if you can add a new record.
@ -32,20 +33,15 @@ class WeblinkController extends \JControllerForm
protected function allowAdd($data = array()) protected function allowAdd($data = array())
{ {
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int'); $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
$allow = null; $allow = null;
if ($categoryId) if ($categoryId)
{ {
// If the category has been passed in the URL check it. // If the category has been passed in the URL check it.
$allow = \JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId); return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
} }
if ($allow !== null) // In the absence of better information, revert to the component permissions.
{
return $allow;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data); return parent::allowAdd($data);
} }
@ -78,7 +74,7 @@ class WeblinkController extends \JControllerForm
return false; return false;
} }
$user = \JFactory::getUser(); $user = $this->app->getIdentity();
// Check if can edit own core.edit.own. // 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; $canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id;
@ -112,8 +108,8 @@ class WeblinkController extends \JControllerForm
/** /**
* Function that allows child controller access to model data after the data has been saved. * Function that allows child controller access to model data after the data has been saved.
* *
* @param JModelLegacy $model The data model object. * @param \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The data model object.
* @param array $validData The validated data. * @param array $validData The validated data.
* *
* @return void * @return void
* *

View File

@ -15,17 +15,28 @@ use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Association\AssociationServiceTrait; use Joomla\CMS\Association\AssociationServiceTrait;
use Joomla\CMS\Categories\CategoryServiceInterface; use Joomla\CMS\Categories\CategoryServiceInterface;
use Joomla\CMS\Categories\CategoryServiceTrait; use Joomla\CMS\Categories\CategoryServiceTrait;
use Joomla\CMS\Component\Router\RouterServiceInterface;
use Joomla\CMS\Component\Router\RouterServiceTrait;
use Joomla\CMS\Extension\MVCComponent; use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Tag\TagServiceInterface;
use Joomla\CMS\Tag\TagServiceTrait;
/** /**
* Component class for com_contact * Component class for com_contact
* *
* @since 4.0.0 * @since 4.0.0
*/ */
class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface,
TagServiceInterface, RouterServiceInterface
{ {
use CategoryServiceTrait; use CategoryServiceTrait;
use AssociationServiceTrait; use AssociationServiceTrait;
use RouterServiceTrait;
use CategoryServiceTrait, TagServiceTrait
{
CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
}
/** /**
* Returns the table for the count items functions for the given section. * Returns the table for the count items functions for the given section.
@ -52,6 +63,6 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface
*/ */
protected function getStateColumnForSection(string $section = null) protected function getStateColumnForSection(string $section = null)
{ {
return 'published'; return 'state';
} }
} }

View File

@ -0,0 +1,210 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Association\AssociationExtensionHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Table\Table;
use Joomla\Component\Weblinks\Site\Helper\AssociationHelper;
/**
* Content associations helper.
*
* @since __DEPLOY_VERSION__
*/
class WeblinksAssociationsHelper extends AssociationExtensionHelper
{
/**
* 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');
/**
* 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);
}
/**
* 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 = '';
}
// Get the associations.
$associations = Associations::getAssociations(
$this->extension,
$type['tables']['a'],
$context,
$id,
'id',
'alias',
$catidField
);
return $associations;
}
/**
* 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;
}
$table = null;
switch ($typeName)
{
case 'weblink':
$table = Table::getInstance('Weblink', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\');
break;
case 'category':
$table = Table::getInstance('Category');
break;
}
if (empty($table))
{
return null;
}
$table->load($id);
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,
);
}
}

View File

@ -0,0 +1,24 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Helper\ContentHelper;
/**
* Weblinks helper.
*
* @since 1.6
*/
class WeblinksHelper extends ContentHelper
{
}

View File

@ -11,16 +11,21 @@ namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
\JLoader::register('WeblinksHelper', JPATH_ADMINISTRATOR . '/components/com_weblinks/helpers/weblinks.php');
/** /**
* Weblinks model. * Weblinks model.
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinkModel extends \JModelAdmin class WeblinkModel extends AdminModel
{ {
/** /**
* The type alias for this content type. * The type alias for this content type.
@ -57,20 +62,12 @@ class WeblinkModel extends \JModelAdmin
*/ */
protected function canDelete($record) protected function canDelete($record)
{ {
if (!empty($record->id)) if (empty($record->id) || $record->published != -2)
{ {
if ($record->state != -2) return false;
{
return;
}
if ($record->catid)
{
return \JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canDelete($record);
} }
return Factory::getUser()->authorise('core.delete', 'com_contact.category.' . (int) $record->catid);
} }
/** /**
@ -86,7 +83,7 @@ class WeblinkModel extends \JModelAdmin
{ {
if (!empty($record->catid)) if (!empty($record->catid))
{ {
return \JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid); return Factory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
} }
return parent::canEditState($record); return parent::canEditState($record);
@ -154,7 +151,7 @@ class WeblinkModel extends \JModelAdmin
protected function loadFormData() protected function loadFormData()
{ {
// Check the session for previously entered form data. // Check the session for previously entered form data.
$data = \JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); $data = Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
if (empty($data)) if (empty($data))
{ {
@ -163,7 +160,7 @@ class WeblinkModel extends \JModelAdmin
// Prime some default values. // Prime some default values.
if ($this->getState('weblink.id') == 0) if ($this->getState('weblink.id') == 0)
{ {
$app = \JFactory::getApplication(); $app = Factory::getApplication();
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int')); $data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
} }
} }
@ -197,7 +194,7 @@ class WeblinkModel extends \JModelAdmin
$item->images = $registry->toArray(); $item->images = $registry->toArray();
// Load associated web links items // Load associated web links items
$assoc = \JLanguageAssociations::isEnabled(); $assoc = Associations::isEnabled();
if ($assoc) if ($assoc)
{ {
@ -205,7 +202,7 @@ class WeblinkModel extends \JModelAdmin
if ($item->id != null) if ($item->id != null)
{ {
$associations = \JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id); $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
foreach ($associations as $tag => $association) foreach ($associations as $tag => $association)
{ {
@ -228,7 +225,7 @@ class WeblinkModel extends \JModelAdmin
/** /**
* Prepare and sanitise the table data prior to saving. * Prepare and sanitise the table data prior to saving.
* *
* @param JTable $table A reference to a JTable object. * @param \Joomla\CMS\Table\Table $table A reference to a JTable object.
* *
* @return void * @return void
* *
@ -236,15 +233,15 @@ class WeblinkModel extends \JModelAdmin
*/ */
protected function prepareTable($table) protected function prepareTable($table)
{ {
$date = \JFactory::getDate(); $date = Factory::getDate();
$user = \JFactory::getUser(); $user = Factory::getUser();
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES); $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = \JApplicationHelper::stringURLSafe($table->alias); $table->alias = ApplicationHelper::stringURLSafe($table->alias);
if (empty($table->alias)) if (empty($table->alias))
{ {
$table->alias = \JApplicationHelper::stringURLSafe($table->title); $table->alias = ApplicationHelper::stringURLSafe($table->title);
} }
if (empty($table->id)) if (empty($table->id))
@ -254,7 +251,7 @@ class WeblinkModel extends \JModelAdmin
// Set ordering to the last item if not set // Set ordering to the last item if not set
if (empty($table->ordering)) if (empty($table->ordering))
{ {
$db = $this->getDbo(); $db = $this->getDbo();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select('MAX(ordering)') ->select('MAX(ordering)')
->from($db->quoteName('#__weblinks')); ->from($db->quoteName('#__weblinks'));
@ -279,7 +276,7 @@ class WeblinkModel extends \JModelAdmin
/** /**
* A protected method to get a set of ordering conditions. * A protected method to get a set of ordering conditions.
* *
* @param JTable $table A JTable object. * @param \Joomla\CMS\Table\Table $table A JTable object.
* *
* @return array An array of conditions to add to ordering queries. * @return array An array of conditions to add to ordering queries.
* *
@ -287,7 +284,7 @@ class WeblinkModel extends \JModelAdmin
*/ */
protected function getReorderConditions($table) protected function getReorderConditions($table)
{ {
$condition = array(); $condition = array();
$condition[] = 'catid = ' . (int) $table->catid; $condition[] = 'catid = ' . (int) $table->catid;
return $condition; return $condition;
@ -300,13 +297,11 @@ class WeblinkModel extends \JModelAdmin
* *
* @return boolean True on success. * @return boolean True on success.
* *
* @since 3.1 * @since 3.1
*/ */
public function save($data) public function save($data)
{ {
$app = \JFactory::getApplication(); $app = Factory::getApplication();
\JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison // Cast catid to integer for comparison
$catid = (int) $data['catid']; $catid = (int) $data['catid'];
@ -314,30 +309,30 @@ class WeblinkModel extends \JModelAdmin
// Check if New Category exists // Check if New Category exists
if ($catid > 0) if ($catid > 0)
{ {
$catid = \CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks'); $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
} }
// Save New Category // Save New Category
if ($catid == 0 && $this->canCreateCategory()) if ($catid == 0 && $this->canCreateCategory())
{ {
$table = array(); $table = array();
$table['title'] = $data['catid']; $table['title'] = $data['catid'];
$table['parent_id'] = 1; $table['parent_id'] = 1;
$table['extension'] = 'com_weblinks'; $table['extension'] = 'com_weblinks';
$table['language'] = $data['language']; $table['language'] = $data['language'];
$table['published'] = 1; $table['published'] = 1;
// Create new category and get catid back // Create new category and get catid back
$data['catid'] = \CategoriesHelper::createCategory($table); $data['catid'] = CategoriesHelper::createCategory($table);
} }
// Alter the title for save as copy // Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') if ($app->input->get('task') == 'save2copy')
{ {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name; $data['title'] = $name;
$data['alias'] = $alias; $data['alias'] = $alias;
$data['state'] = 0; $data['state'] = 0;
} }
return parent::save($data); return parent::save($data);
@ -363,10 +358,10 @@ class WeblinkModel extends \JModelAdmin
{ {
if ($name == $table->title) if ($name == $table->title)
{ {
$name = \JString::increment($name); $name = StringHelper::increment($name);
} }
$alias = \JString::increment($alias, 'dash'); $alias = StringHelper::increment($alias, 'dash');
} }
return array($name, $alias); return array($name, $alias);
@ -375,7 +370,7 @@ class WeblinkModel extends \JModelAdmin
/** /**
* Allows preprocessing of the JForm object. * Allows preprocessing of the JForm object.
* *
* @param JForm $form The form object * @param \JForm $form The form object
* @param array $data The data to be merged into the form object * @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed * @param string $group The plugin group to be executed
* *
@ -391,14 +386,14 @@ class WeblinkModel extends \JModelAdmin
} }
// Association weblinks items // Association weblinks items
if (\JLanguageAssociations::isEnabled()) if (Associations::isEnabled())
{ {
$languages = \JLanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc'); $languages = LanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc');
if (count($languages) > 1) if (count($languages) > 1)
{ {
$addform = new \SimpleXMLElement('<form />'); $addform = new \SimpleXMLElement('<form />');
$fields = $addform->addChild('fields'); $fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations'); $fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset'); $fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('name', 'item_associations');
@ -434,6 +429,6 @@ class WeblinkModel extends \JModelAdmin
*/ */
private function canCreateCategory() private function canCreateCategory()
{ {
return \JFactory::getUser()->authorise('core.create', 'com_weblinks'); return Factory::getUser()->authorise('core.create', 'com_weblinks');
} }
} }

View File

@ -11,8 +11,10 @@ namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
/** /**
* Methods supporting a list of weblink records. * Methods supporting a list of weblink records.
@ -24,7 +26,7 @@ class WeblinksModel extends ListModel
/** /**
* Constructor. * Constructor.
* *
* @param array $config An optional associative array of configuration settings. * @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory. * @param MVCFactoryInterface $factory The factory.
* *
* @see JControllerLegacy * @see JControllerLegacy
@ -83,7 +85,7 @@ class WeblinksModel extends ListModel
*/ */
protected function populateState($ordering = 'a.title', $direction = 'asc') protected function populateState($ordering = 'a.title', $direction = 'asc')
{ {
$app = \JFactory::getApplication(); $app = Factory::getApplication();
$forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd');
@ -109,7 +111,7 @@ class WeblinksModel extends ListModel
$this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd')); $this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd'));
// Load the parameters. // Load the parameters.
$params = \JComponentHelper::getParams('com_weblinks'); $params = ComponentHelper::getParams('com_weblinks');
$this->setState('params', $params); $this->setState('params', $params);
// Force a language. // Force a language.
@ -152,16 +154,16 @@ class WeblinksModel extends ListModel
/** /**
* Build an SQL query to load the list data. * Build an SQL query to load the list data.
* *
* @return JDatabaseQuery * @return \JDatabaseQuery
* *
* @since 1.6 * @since 1.6
*/ */
protected function getListQuery() protected function getListQuery()
{ {
// Create a new query object. // Create a new query object.
$db = $this->getDbo(); $db = $this->getDbo();
$query = $db->getQuery(true); $query = $db->getQuery(true);
$user = \JFactory::getUser(); $user = Factory::getUser();
// Select the required fields from the table. // Select the required fields from the table.
$query->select( $query->select(

View File

@ -9,6 +9,15 @@
namespace Joomla\Component\Weblinks\Administrator\Table; namespace Joomla\Component\Weblinks\Administrator\Table;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Tag\TaggableTableInterface;
use Joomla\CMS\Tag\TaggableTableTrait;
use Joomla\CMS\Versioning\VersionableTableInterface;
use Joomla\String\StringHelper;
defined('_JEXEC') or die; defined('_JEXEC') or die;
/** /**
@ -16,8 +25,9 @@ defined('_JEXEC') or die;
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinkTable extends \JTable class WeblinkTable extends Table implements VersionableTableInterface, TaggableTableInterface
{ {
use TaggableTableTrait;
/** /**
* Ensure the params and metadata in json encoded in the bind method * Ensure the params and metadata in json encoded in the bind method
* *
@ -29,22 +39,18 @@ class WeblinkTable extends \JTable
/** /**
* Constructor * Constructor
* *
* @param JDatabaseDriver &$db A database connector object * @param \JDatabaseDriver &$db A database connector object
* *
* @since 1.5 * @since 1.5
*/ */
public function __construct(&$db) public function __construct(&$db)
{ {
$this->typeAlias = 'com_weblinks.weblink';
parent::__construct('#__weblinks', 'id', $db); parent::__construct('#__weblinks', 'id', $db);
// Set the published column alias // Set the published column alias
$this->setColumnAlias('published', 'state'); $this->setColumnAlias('published', 'state');
if (version_compare(JVERSION, '4.0', '<' ) == 1)
{
\JTableObserverTags::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
\JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
}
} }
/** /**
@ -58,8 +64,8 @@ class WeblinkTable extends \JTable
*/ */
public function store($updateNulls = false) public function store($updateNulls = false)
{ {
$date = \JFactory::getDate(); $date = Factory::getDate();
$user = \JFactory::getUser(); $user = Factory::getUser();
$this->modified = $date->toSql(); $this->modified = $date->toSql();
@ -107,7 +113,13 @@ class WeblinkTable extends \JTable
} }
// Convert IDN urls to punycode // Convert IDN urls to punycode
$this->url = \JStringPunycode::urlToPunycode($this->url); $this->url = PunycodeHelper::urlToPunycode($this->url);
// Set default value for xreference
if ($this->xreference === null)
{
$this->xreference = '';
}
return parent::store($updateNulls); return parent::store($updateNulls);
} }
@ -132,6 +144,7 @@ class WeblinkTable extends \JTable
if (trim($this->title) == '') if (trim($this->title) == '')
{ {
$this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_TITLE')); $this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
return false; return false;
} }
@ -160,11 +173,11 @@ class WeblinkTable extends \JTable
$this->alias = $this->title; $this->alias = $this->title;
} }
$this->alias = \JApplicationHelper::stringURLSafe($this->alias, $this->language); $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '') if (trim(str_replace('-', '', $this->alias)) == '')
{ {
$this->alias = \JFactory::getDate()->format("Y-m-d-H-i-s"); $this->alias = Factory::getDate()->format("Y-m-d-H-i-s");
} }
// Check the publish down date is not earlier than publish up. // Check the publish down date is not earlier than publish up.
@ -183,9 +196,9 @@ class WeblinkTable extends \JTable
{ {
// Array of characters to remove // Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">"); $bad_characters = array("\n", "\r", "\"", "<", ">");
$after_clean = \JString::str_ireplace($bad_characters, "", $this->metakey); $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean); $keys = explode(',', $after_clean);
$clean_keys = array(); $clean_keys = array();
foreach ($keys as $key) foreach ($keys as $key)
{ {
@ -202,4 +215,16 @@ class WeblinkTable extends \JTable
return parent::check(); 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;
}
} }

View File

@ -11,18 +11,40 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblink;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
/** /**
* View to edit a weblink. * View to edit a weblink.
* *
* @since 1.5 * @since 1.5
*/ */
class HtmlView extends \Joomla\CMS\MVC\View\HtmlView class HtmlView extends BaseHtmlView
{ {
protected $state; /**
* The \JForm object
*
* @var \JForm
*/
protected $form;
/**
* The active item
*
* @var object
*/
protected $item; protected $item;
protected $form; /**
* The model state
*
* @var \JObject
*/
protected $state;
/** /**
* Display the view. * Display the view.
@ -40,13 +62,11 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors')))
{ {
\JError::raiseError(500, implode("\n", $errors)); throw new GenericDataException(implode("\n", $errors), 500);
return false;
} }
// If we are forcing a language in modal (used for associations). // If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage = \JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd'))
{ {
// Set the language field to the forcedLanguage and disable changing it. // Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage); $this->form->setValue('language', null, $forcedLanguage);
@ -73,47 +93,47 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
*/ */
protected function addToolbar() protected function addToolbar()
{ {
\JFactory::getApplication()->input->set('hidemainmenu', true); Factory::getApplication()->input->set('hidemainmenu', true);
$user = \JFactory::getUser(); $user = Factory::getUser();
$isNew = ($this->item->id == 0); $isNew = ($this->item->id == 0);
$checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
// Since we don't track these assets at the item level, use the category id. // Since we don't track these assets at the item level, use the category id.
$canDo = \JHelperContent::getActions('com_weblinks', 'category', $this->item->catid); $canDo = ContentHelper::getActions('com_weblinks', 'category', $this->item->catid);
\JToolbarHelper::title($isNew ? \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks'); ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
// If not checked out, can save the item. // If not checked out, can save the item.
if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))) if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create')))))
{ {
\JToolbarHelper::apply('weblink.apply'); ToolbarHelper::apply('weblink.apply');
\JToolbarHelper::save('weblink.save'); ToolbarHelper::save('weblink.save');
} }
if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))) if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))
{ {
\JToolbarHelper::save2new('weblink.save2new'); ToolbarHelper::save2new('weblink.save2new');
} }
// If an existing item, can save to a copy. // If an existing item, can save to a copy.
if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)) if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0))
{ {
\JToolbarHelper::save2copy('weblink.save2copy'); ToolbarHelper::save2copy('weblink.save2copy');
} }
if (empty($this->item->id)) if (empty($this->item->id))
{ {
\JToolbarHelper::cancel('weblink.cancel'); ToolbarHelper::cancel('weblink.cancel');
} }
else else
{ {
if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit')) if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit'))
{ {
\JToolbarHelper::versions('com_weblinks.weblink', $this->item->id); ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
} }
\JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
} }
\JToolbarHelper::divider(); ToolbarHelper::divider();
\JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT'); ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT');
} }
} }

View File

@ -11,19 +11,58 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblinks;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
/** /**
* View class for a list of weblinks. * View class for a list of weblinks.
* *
* @since 1.5 * @since 1.5
*/ */
class HtmlView extends \Joomla\CMS\MVC\View\HtmlView class HtmlView extends BaseHtmlView
{ {
/**
* An array of items
*
* @var array
*/
protected $items; protected $items;
/**
* The pagination object
*
* @var \JPagination
*/
protected $pagination; protected $pagination;
/**
* The model state
*
* @var \JObject
*/
protected $state; protected $state;
/**
* Form object for search filters
*
* @var \JForm
*/
public $filterForm;
/**
* The active search filters
*
* @var array
*/
public $activeFilters;
/** /**
* Display the view. * Display the view.
* *
@ -39,16 +78,11 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
$this->filterForm = $this->get('FilterForm'); $this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters'); $this->activeFilters = $this->get('ActiveFilters');
// Modal layout doesn't need the submenu.
if ($this->getLayout() !== 'modal')
{
\WeblinksHelper::addSubmenu('weblinks');
}
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors')))
{ {
\JError::raiseError(500, implode("\n", $errors)); throw new GenericDataException(implode("\n", $errors), 500);
return false; return false;
} }
@ -56,13 +90,12 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
if ($this->getLayout() !== 'modal') if ($this->getLayout() !== 'modal')
{ {
$this->addToolbar(); $this->addToolbar();
$this->sidebar = \JHtmlSidebar::render();
} }
else else
{ {
// In article associations modal we need to remove language filter if forcing a language. // In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language. // We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = \JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD'))
{ {
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field. // If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />'); $languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
@ -88,54 +121,52 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
*/ */
protected function addToolbar() protected function addToolbar()
{ {
require_once JPATH_COMPONENT . '/helpers/weblinks.php';
$state = $this->get('State'); $state = $this->get('State');
$canDo = \JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id')); $canDo = ContentHelper::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
$user = \JFactory::getUser(); $user = Factory::getUser();
// Get the toolbar object instance // Get the toolbar object instance
$bar = \JToolbar::getInstance('toolbar'); $bar = Toolbar::getInstance('toolbar');
\JToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{ {
\JToolbarHelper::addNew('weblink.add'); ToolbarHelper::addNew('weblink.add');
} }
if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) if ($canDo->get('core.edit') || $canDo->get('core.edit.own'))
{ {
\JToolbarHelper::editList('weblink.edit'); ToolbarHelper::editList('weblink.edit');
} }
if ($canDo->get('core.edit.state')) if ($canDo->get('core.edit.state'))
{ {
\JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true); ToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
\JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true); ToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
\JToolbarHelper::archiveList('weblinks.archive'); ToolbarHelper::archiveList('weblinks.archive');
\JToolbarHelper::checkin('weblinks.checkin'); ToolbarHelper::checkin('weblinks.checkin');
} }
if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) if ($state->get('filter.published') == -2 && $canDo->get('core.delete'))
{ {
\JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH'); ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
} }
elseif ($canDo->get('core.edit.state')) elseif ($canDo->get('core.edit.state'))
{ {
\JToolbarHelper::trash('weblinks.trash'); ToolbarHelper::trash('weblinks.trash');
} }
// Add a batch button // Add a batch button
if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks') if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks')) && $user->authorise('core.edit.state', 'com_weblinks'))
{ {
\JHtml::_('bootstrap.renderModal', 'collapseModal'); HTMLHelper::_('bootstrap.renderModal', 'collapseModal');
$title = \JText::_('JTOOLBAR_BATCH'); $title = Text::_('JTOOLBAR_BATCH');
// Instantiate a new JLayoutFile instance and render the batch button // Instantiate a new JLayoutFile instance and render the batch button
$layout = new \JLayoutFile('joomla.toolbar.batch'); $layout = new FileLayout('joomla.toolbar.batch');
$dhtml = $layout->render(array('title' => $title)); $dhtml = $layout->render(array('title' => $title));
$bar->appendButton('Custom', $dhtml, 'batch'); $bar->appendButton('Custom', $dhtml, 'batch');
@ -143,10 +174,10 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks')) if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
{ {
\JToolbarHelper::preferences('com_weblinks'); ToolbarHelper::preferences('com_weblinks');
} }
\JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS'); ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
} }
/** /**
@ -160,12 +191,12 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
{ {
return array( return array(
'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'), 'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'),
'a.state' => \JText::_('JSTATUS'), 'a.state' => \JText::_('JSTATUS'),
'a.title' => \JText::_('JGLOBAL_TITLE'), 'a.title' => \JText::_('JGLOBAL_TITLE'),
'a.access' => \JText::_('JGRID_HEADING_ACCESS'), 'a.access' => \JText::_('JGRID_HEADING_ACCESS'),
'a.hits' => \JText::_('JGLOBAL_HITS'), 'a.hits' => \JText::_('JGLOBAL_HITS'),
'a.language' => \JText::_('JGRID_HEADING_LANGUAGE'), 'a.language' => \JText::_('JGRID_HEADING_LANGUAGE'),
'a.id' => \JText::_('JGRID_HEADING_ID') 'a.id' => \JText::_('JGRID_HEADING_ID'),
); );
} }
} }

View File

@ -9,10 +9,8 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.formvalidator'); JHtml::_('behavior.formvalidator');
JHtml::_('formbehavior.chosen', 'select', null, array('disable_search_threshold' => 0 ));
$app = JFactory::getApplication(); $app = JFactory::getApplication();
$input = $app->input; $input = $app->input;
@ -21,6 +19,7 @@ $assoc = JLanguageAssociations::isEnabled();
// Fieldsets to not automatically render by /layouts/joomla/edit/params.php // Fieldsets to not automatically render by /layouts/joomla/edit/params.php
$this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata'); $this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata');
$this->useCoreUI = true;
// In case of modal // In case of modal
$isModal = $input->get('layout') == 'modal' ? true : false; $isModal = $input->get('layout') == 'modal' ? true : false;
@ -33,9 +32,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?> <?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>
<div class="form-horizontal"> <div class="form-horizontal">
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?> <?php echo JHtml::_('uitab.startTabSet', 'myTab', array('active' => 'details')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', empty($this->item->id) ? JText::_('COM_WEBLINKS_NEW_WEBLINK', true) : JText::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?> <?php echo JHtml::_('uitab.addTab', 'myTab', 'details', empty($this->item->id) ? JText::_('COM_WEBLINKS_NEW_WEBLINK', true) : JText::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?>
<div class="row"> <div class="row">
<div class="col-md-9"> <div class="col-md-9">
<div class="form-vertical"> <div class="form-vertical">
@ -47,9 +46,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo JLayoutHelper::render('joomla.edit.global', $this); ?> <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
</div> </div>
</div> </div>
<?php echo JHtml::_('bootstrap.endTab'); ?> <?php echo JHtml::_('uitab.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'images', JText::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS', true)); ?> <?php echo JHtml::_('uitab.addTab', 'myTab', 'images', JText::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS', true)); ?>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php echo $this->form->renderField('images'); ?> <?php echo $this->form->renderField('images'); ?>
@ -59,9 +58,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
</div> </div>
</div> </div>
<?php echo JHtml::_('bootstrap.endTab'); ?> <?php echo JHtml::_('uitab.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?> <?php echo JHtml::_('uitab.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>
<div class="row form-horizontal-desktop"> <div class="row form-horizontal-desktop">
<div class="col-md-6"> <div class="col-md-6">
<?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?> <?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
@ -70,19 +69,19 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo JLayoutHelper::render('joomla.edit.metadata', $this); ?> <?php echo JLayoutHelper::render('joomla.edit.metadata', $this); ?>
</div> </div>
</div> </div>
<?php echo JHtml::_('bootstrap.endTab'); ?> <?php echo JHtml::_('uitab.endTab'); ?>
<?php echo JLayoutHelper::render('joomla.edit.params', $this); ?> <?php echo JLayoutHelper::render('joomla.edit.params', $this); ?>
<?php if (!$isModal && $assoc) : ?> <?php if (!$isModal && $assoc) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'associations', JText::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?> <?php echo JHtml::_('uitab.addTab', 'myTab', 'associations', JText::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<?php echo $this->loadTemplate('associations'); ?> <?php echo $this->loadTemplate('associations'); ?>
<?php echo JHtml::_('bootstrap.endTab'); ?> <?php echo JHtml::_('uitab.endTab'); ?>
<?php elseif ($isModal && $assoc) : ?> <?php elseif ($isModal && $assoc) : ?>
<div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div> <div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
<?php endif; ?> <?php endif; ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?> <?php echo JHtml::_('uitab.endTabSet'); ?>
</div> </div>

View File

@ -9,11 +9,16 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\Weblinks\Administrator\View\Weblinks\HtmlView $this */
JHtml::_('bootstrap.tooltip'); JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect'); JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select'); //JHtml::_('formbehavior.chosen', 'select');
$user = JFactory::getUser(); $user = JFactory::getUser();
$userId = $user->get('id'); $userId = $user->get('id');
@ -26,164 +31,164 @@ $assoc = JLanguageAssociations::isEnabled();
if ($saveOrder) if ($saveOrder)
{ {
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component'; $saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
JHtml::_('sortablelist.sortable', 'weblinkList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); HTMLHelper::_('draggablelist.draggable');
} }
?> ?>
<form action="<?php echo JRoute::_('index.php?option=com_weblinks&view=weblinks'); ?>" method="post" name="adminForm" id="adminForm"> <form action="<?php echo Route::_('index.php?option=com_weblinks&view=weblinks'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row"> <div class="row">
<?php if (!empty($this->sidebar)) : ?> <div class="col-md-12">
<div id="j-sidebar-container" class="col-md-2"> <div id="j-main-container" class="j-main-container">
<?php echo $this->sidebar; ?> <?php
</div> // Search tools bar
<div id="j-main-container" class="col-md-10"> echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
<?php else : ?> ?>
<div id="j-main-container"> <?php if (empty($this->items)) : ?>
<?php endif;?> <div class="alert alert-info">
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> <span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<div class="clearfix"> </div> <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
<?php if (empty($this->items)) : ?> </div>
<div class="alert alert-no-items"> <?php else : ?>
<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?> <table class="table" id="articleList">
</div> <caption class="visually-hidden">
<?php else : ?> <?php echo Text::_('COM_WEBLINKS_WEBLINKS_TABLE_CAPTION'); ?>,
<table class="table table-striped" id="weblinkList"> <span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<thead> <span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
<tr> </caption>
<th width="1%" class="nowrap center hidden-phone"> <thead>
<?php echo JHtml::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?> <tr>
</th> <th width="1%" class="nowrap center hidden-phone">
<th width="1%" class="nowrap center"> <?php echo JHtml::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?>
<?php echo JHtml::_('grid.checkall'); ?> </th>
</th> <th width="1%" class="nowrap center">
<th width="1%" class="nowrap center"> <?php echo JHtml::_('grid.checkall'); ?>
<?php echo JHtml::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?> </th>
</th> <th width="1%" class="nowrap center">
<th class="title"> <?php echo JHtml::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?> </th>
</th> <th class="title">
<th width="10%" class="nowrap hidden-phone"> <?php echo JHtml::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?> </th>
</th> <th width="10%" class="nowrap hidden-phone">
<th width="5%" class="nowrap center hidden-phone"> <?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?> </th>
</th> <th width="5%" class="nowrap center hidden-phone">
<?php if ($assoc) : ?> <?php echo JHtml::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?>
<th width="5%" class="nowrap hidden-phone hidden-tablet"> </th>
<?php echo JHtml::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?> <?php if ($assoc) : ?>
</th> <th width="5%" class="nowrap hidden-phone hidden-tablet">
<?php endif; ?> <?php echo JHtml::_('searchtools.sort', 'COM_WEBLINKS_HEADING_ASSOCIATION', 'association', $listDirn, $listOrder); ?>
<th width="10%" class="nowrap hidden-phone"> </th>
<?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?>
</th>
<th width="1%" class="nowrap center hidden-phone">
<?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="8">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item) : ?>
<?php $ordering = ($listOrder == 'a.ordering'); ?>
<?php $item->cat_link = JRoute::_('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 == 0; ?>
<?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; ?>" sortable-group-id="<?php echo $item->catid; ?>">
<td class="order nowrap center hidden-phone">
<?php $iconClass = ''; ?>
<?php if (!$canChange) : ?>
<?php $iconClass = ' inactive'; ?>
<?php elseif (!$saveOrder) : ?>
<?php $iconClass = ' inactive tip-top hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); ?>
<?php endif; ?> <?php endif; ?>
<span class="sortable-handler<?php echo $iconClass ?>"> <th width="10%" class="nowrap hidden-phone">
<?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_LANGUAGE', 'language_title', $listDirn, $listOrder); ?>
</th>
<th width="1%" class="nowrap center hidden-phone">
<?php echo JHtml::_('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 $ordering = ($listOrder == 'a.ordering'); ?>
<?php $item->cat_link = JRoute::_('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 == 0; ?>
<?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; ?>" sortable-group-id="<?php echo $item->catid; ?>">
<td class="order nowrap center hidden-phone">
<?php $iconClass = ''; ?>
<?php if (!$canChange) : ?>
<?php $iconClass = ' inactive'; ?>
<?php elseif (!$saveOrder) : ?>
<?php $iconClass = ' inactive tip-top hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); ?>
<?php endif; ?>
<span class="sortable-handler<?php echo $iconClass ?>">
<i class="icon-menu" aria-hidden="true"></i> <i class="icon-menu" aria-hidden="true"></i>
</span> </span>
<?php if ($canChange && $saveOrder) : ?> <?php if ($canChange && $saveOrder) : ?>
<input type="text" style="display:none" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order " /> <input type="text" style="display:none" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order " />
<?php endif; ?> <?php endif; ?>
</td> </td>
<td class="center"> <td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?> <?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td> </td>
<td class="center"> <td class="center">
<div class="btn-group"> <div class="btn-group">
<?php echo JHtml::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?> <?php echo JHtml::_('jgrid.published', $item->state, $i, 'weblinks.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
<?php // Create dropdown items and render the dropdown list. ?> <?php // Create dropdown items and render the dropdown list. ?>
<?php if ($canChange) : ?> <?php if ($canChange) : ?>
<?php JHtml::_('actionsdropdown.' . ((int) $item->state === 2 ? 'un' : '') . 'archive', 'cb' . $i, 'weblinks'); ?> <?php JHtml::_('actionsdropdown.' . ((int) $item->state === 2 ? 'un' : '') . 'archive', 'cb' . $i, 'weblinks'); ?>
<?php JHtml::_('actionsdropdown.' . ((int) $item->state === -2 ? 'un' : '') . 'trash', 'cb' . $i, 'weblinks'); ?> <?php JHtml::_('actionsdropdown.' . ((int) $item->state === -2 ? 'un' : '') . 'trash', 'cb' . $i, 'weblinks'); ?>
<?php echo JHtml::_('actionsdropdown.render', $this->escape($item->title)); ?> <?php echo JHtml::_('actionsdropdown.render', $this->escape($item->title)); ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
</td> </td>
<td class="nowrap has-context"> <td class="nowrap has-context">
<?php if ($item->checked_out) : ?> <?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?> <?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?>
<?php endif; ?> <?php endif; ?>
<?php if ($canEdit || $canEditOwn) : ?> <?php if ($canEdit || $canEditOwn) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id); ?>"> <a href="<?php echo JRoute::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id); ?>">
<?php echo $this->escape($item->title); ?></a> <?php echo $this->escape($item->title); ?></a>
<?php else : ?> <?php else : ?>
<?php echo $this->escape($item->title); ?> <?php echo $this->escape($item->title); ?>
<?php endif; ?> <?php endif; ?>
<span class="small"> <span class="small">
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?> <?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?>
</span> </span>
<div class="small"> <div class="small">
<?php echo JText::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?> <?php echo JText::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div> </div>
</td> </td>
<td class="small hidden-phone"> <td class="small hidden-phone">
<?php echo $this->escape($item->access_level); ?> <?php echo $this->escape($item->access_level); ?>
</td> </td>
<td class="center hidden-phone"> <td class="center hidden-phone">
<?php echo $item->hits; ?> <?php echo $item->hits; ?>
</td> </td>
<?php if ($assoc) : ?> <?php if ($assoc) : ?>
<td class="hidden-phone hidden-tablet"> <td class="hidden-phone hidden-tablet">
<?php if ($item->association) : ?> <?php if ($item->association) : ?>
<?php echo JHtml::_('weblink.association', $item->id); ?> <?php echo JHtml::_('weblink.association', $item->id); ?>
<?php endif; ?>
</td>
<?php endif; ?> <?php endif; ?>
</td> <td class="small hidden-phone">
<?php endif; ?> <?php echo JLayoutHelper::render('joomla.content.language', $item); ?>
<td class="small hidden-phone"> </td>
<?php echo JLayoutHelper::render('joomla.content.language', $item); ?> <td class="center hidden-phone">
</td> <?php echo (int) $item->id; ?>
<td class="center hidden-phone"> </td>
<?php echo (int) $item->id; ?> </tr>
</td> <?php endforeach; ?>
</tr> </tbody>
<?php endforeach; ?> </table>
</tbody>
</table>
<?php // Load the batch processing form. ?>
<?php if ($user->authorise('core.create', 'com_content')
&& $user->authorise('core.edit', 'com_content')
&& $user->authorise('core.edit.state', 'com_content')) : ?>
<?php echo JHtml::_(
'bootstrap.renderModal',
'collapseModal',
array(
'title' => JText::_('COM_WEBLINKS_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
),
$this->loadTemplate('batch_body')
); ?>
<?php endif; ?>
<?php endif; ?>
<input type="hidden" name="task" value="" /> <?php // Load the pagination. ?>
<input type="hidden" name="boxchecked" value="0" /> <?php echo $this->pagination->getListFooter(); ?>
<?php echo JHtml::_('form.token'); ?>
</div> <?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> </div>
</form> </form>

View File

@ -7,6 +7,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Layout\LayoutHelper;
$published = $this->state->get('filter.published'); $published = $this->state->get('filter.published');
?> ?>
@ -14,12 +17,12 @@ $published = $this->state->get('filter.published');
<div class="row-fluid"> <div class="row-fluid">
<div class="control-group span6"> <div class="control-group span6">
<div class="controls"> <div class="controls">
<?php echo JHtml::_('batch.language'); ?> <?php echo LayoutHelper::render('joomla.html.batch.language', []); ?>
</div> </div>
</div> </div>
<div class="control-group span6"> <div class="control-group span6">
<div class="controls"> <div class="controls">
<?php echo JHtml::_('batch.access'); ?> <?php echo LayoutHelper::render('joomla.html.batch.access', []); ?>
</div> </div>
</div> </div>
</div> </div>
@ -27,13 +30,13 @@ $published = $this->state->get('filter.published');
<?php if ($published >= 0) : ?> <?php if ($published >= 0) : ?>
<div class="control-group span6"> <div class="control-group span6">
<div class="controls"> <div class="controls">
<?php echo JHtml::_('batch.item', 'com_weblinks'); ?> <?php echo LayoutHelper::render('joomla.html.batch.item', ['extension' => 'com_contact']); ?>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="control-group span6"> <div class="control-group span6">
<div class="controls"> <div class="controls">
<?php echo JHtml::_('batch.tag'); ?> <?php echo LayoutHelper::render('joomla.html.batch.tag', []); ?>
</div> </div>
</div> </div>
</div> </div>

View File

@ -10,7 +10,7 @@
<version>##VERSION##</version> <version>##VERSION##</version>
<description>COM_WEBLINKS_XML_DESCRIPTION</description> <description>COM_WEBLINKS_XML_DESCRIPTION</description>
<scriptfile>script.php</scriptfile> <scriptfile>script.php</scriptfile>
<namespace>Joomla\Component\Weblinks</namespace> <namespace path="src">Joomla\Component\Weblinks</namespace>
<install> <install>
<sql> <sql>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<form> <form>
<fieldset addfieldpath="/administrator/components/com_categories/models/fields"> <fieldset addfieldprefix="Joomla\Component\Categories\Administrator\Field">
<field <field
name="id" name="id"
type="hidden" type="hidden"

View File

@ -1,33 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
/**
* Weblinks Component Category Tree.
*
* @since 1.6
*/
class WeblinksCategories extends JCategories
{
/**
* Constructor
*
* @param array $options Array of options
*
* @since 1.6
*/
public function __construct($options = array())
{
$options['table'] = '#__weblinks';
$options['extension'] = 'com_weblinks';
parent::__construct($options);
}
}

View File

@ -1,271 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
/**
* Weblinks Component Route Helper.
*
* @since 1.5
*/
abstract class WeblinksHelperRoute
{
protected static $lookup;
protected static $lang_lookup = array();
/**
* 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)
{
$needles = array('weblink' => array((int) $id));
// Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id=' . $id;
if ($catid > 1)
{
$categories = JCategories::getInstance('Weblinks');
$category = $categories->get($catid);
if ($category)
{
$needles['category'] = array_reverse($category->getPath());
$needles['categories'] = $needles['category'];
$link .= '&catid=' . $catid;
}
}
if ($language && $language != "*" && JLanguageMultilang::isEnabled())
{
self::buildLanguageLookup();
if (isset(self::$lang_lookup[$language]))
{
$link .= '&lang=' . self::$lang_lookup[$language];
$needles['language'] = $language;
}
}
if ($item = self::_findItem($needles))
{
$link .= '&Itemid=' . $item;
}
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';
}
if ($return)
{
$link .= '&return=' . $return;
}
return $link;
}
/**
* Get the Category Route
*
* @param JCategoryNode|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 JCategoryNode)
{
$id = $catid->id;
$category = $catid;
}
else
{
$id = (int) $catid;
$category = JCategories::getInstance('Weblinks')->get($id);
}
if ($id < 1 || !($category instanceof JCategoryNode))
{
$link = '';
}
else
{
$needles = array();
// Create the link
$link = 'index.php?option=com_weblinks&view=category&id=' . $id;
$catids = array_reverse($category->getPath());
$needles['category'] = $catids;
$needles['categories'] = $catids;
if ($language && $language != "*" && JLanguageMultilang::isEnabled())
{
self::buildLanguageLookup();
if (isset(self::$lang_lookup[$language]))
{
$link .= '&lang=' . self::$lang_lookup[$language];
$needles['language'] = $language;
}
}
if ($item = self::_findItem($needles))
{
$link .= '&Itemid=' . $item;
}
}
return $link;
}
/**
* Do a language lookup
*
* @return void
*/
protected static function buildLanguageLookup()
{
if (count(self::$lang_lookup) == 0)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.sef AS sef')
->select('a.lang_code AS lang_code')
->from('#__languages AS a');
$db->setQuery($query);
$langs = $db->loadObjectList();
foreach ($langs as $lang)
{
self::$lang_lookup[$lang->lang_code] = $lang->sef;
}
}
}
/**
* Find items per given $needles
*
* @param array $needles A given array of needles to find
*
* @return void
*/
protected static function _findItem($needles = null)
{
$app = JFactory::getApplication();
$menus = $app->getMenu('site');
$language = isset($needles['language']) ? $needles['language'] : '*';
// Prepare the reverse lookup array.
if (!isset(self::$lookup[$language]))
{
self::$lookup[$language] = array();
$component = JComponentHelper::getComponent('com_weblinks');
$attributes = array('component_id');
$values = array($component->id);
if ($language != '*')
{
$attributes[] = 'language';
$values[] = array($needles['language'], '*');
}
$items = $menus->getItems($attributes, $values);
if ($items)
{
foreach ($items as $item)
{
if (isset($item->query) && isset($item->query['view']))
{
$view = $item->query['view'];
if (!isset(self::$lookup[$language][$view]))
{
self::$lookup[$language][$view] = array();
}
if (isset($item->query['id']))
{
/**
* Here it will become a bit tricky
* language != * can override existing entries
* language == * cannot override existing entries
*/
if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
{
self::$lookup[$language][$view][$item->query['id']] = $item->id;
}
}
}
}
}
}
if ($needles)
{
foreach ($needles as $view => $ids)
{
if (isset(self::$lookup[$language][$view]))
{
foreach ($ids as $id)
{
if (isset(self::$lookup[$language][$view][(int) $id]))
{
return self::$lookup[$language][$view][(int) $id];
}
}
}
}
}
// Check if the active menuitem matches the requested language
$active = $menus->getActive();
if ($active && ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled()))
{
return $active->id;
}
// If not found, return language specific home link
$default = $menus->getDefault($language);
return !empty($default->id) ? $default->id : null;
}
}

View File

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
</metadata>

View File

@ -1,295 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
/**
* Routing class from com_weblinks
*
* @since 3.3
*/
class WeblinksRouter extends JComponentRouterBase
{
/**
* Build the route for the com_weblinks component
*
* @param array &$query An array of URL arguments
*
* @return array The URL arguments to use to assemble the subsequent URL.
*
* @since 3.3
*/
public function build(&$query)
{
$segments = array();
// Get a menu item based on Itemid or currently active
$app = JFactory::getApplication();
$menu = $app->getMenu();
$params = JComponentHelper::getParams('com_weblinks');
$advanced = $params->get('sef_advanced_link', 0);
// We need a menu item. Either the one specified in the query, or the current active one if none specified
if (empty($query['Itemid']))
{
$menuItem = $menu->getActive();
}
else
{
$menuItem = $menu->getItem($query['Itemid']);
}
$mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view'];
$mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id'];
if (isset($query['view']))
{
$view = $query['view'];
if (empty($query['Itemid']) || empty($menuItem) || $menuItem->component != 'com_weblinks')
{
$segments[] = $query['view'];
}
// We need to keep the view for forms since they never have their own menu item
if ($view != 'form')
{
unset($query['view']);
}
}
// Are we dealing with an weblink that is attached to a menu item?
if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == (int) $query['id']))
{
unset($query['view']);
unset($query['catid']);
unset($query['id']);
return $segments;
}
if (isset($view) and ($view == 'category' or $view == 'weblink'))
{
if ($mId != (int) $query['id'] || $mView != $view)
{
if ($view == 'weblink' && isset($query['catid']))
{
$catid = $query['catid'];
}
elseif (isset($query['id']))
{
$catid = $query['id'];
}
$menuCatid = $mId;
$categories = JCategories::getInstance('Weblinks');
$category = $categories->get($catid);
if ($category)
{
// TODO Throw error that the category either not exists or is unpublished
$path = $category->getPath();
$path = array_reverse($path);
$array = array();
foreach ($path as $id)
{
if ((int) $id == (int) $menuCatid)
{
break;
}
if ($advanced)
{
list($tmp, $id) = explode(':', $id, 2);
}
$array[] = $id;
}
$segments = array_merge($segments, array_reverse($array));
}
if ($view == 'weblink')
{
if ($advanced)
{
list($tmp, $id) = explode(':', $query['id'], 2);
}
else
{
$id = $query['id'];
}
$segments[] = $id;
}
}
unset($query['id']);
unset($query['catid']);
}
if (isset($query['layout']))
{
if (!empty($query['Itemid']) && isset($menuItem->query['layout']))
{
if ($query['layout'] == $menuItem->query['layout'])
{
unset($query['layout']);
}
}
else
{
if ($query['layout'] == 'default')
{
unset($query['layout']);
}
}
}
$total = count($segments);
for ($i = 0; $i < $total; $i++)
{
$segments[$i] = str_replace(':', '-', $segments[$i]);
}
return $segments;
}
/**
* Parse the segments of a URL.
*
* @param array &$segments The segments of the URL to parse.
*
* @return array The URL attributes to be used by the application.
*
* @since 3.3
*/
public function parse(&$segments)
{
$total = count($segments);
$vars = array();
for ($i = 0; $i < $total; $i++)
{
$segments[$i] = preg_replace('/-/', ':', $segments[$i], 1);
}
// Get the active menu item.
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item = $menu->getActive();
$params = JComponentHelper::getParams('com_weblinks');
$advanced = $params->get('sef_advanced_link', 0);
// Count route segments
$count = count($segments);
// Standard routing for weblinks.
if (!isset($item))
{
$vars['view'] = $segments[0];
$vars['id'] = $segments[$count - 1];
return $vars;
}
// From the categories view, we can only jump to a category.
$id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root';
$category = JCategories::getInstance('Weblinks')->get($id);
$categories = $category->getChildren();
$found = 0;
foreach ($segments as $segment)
{
foreach ($categories as $category)
{
if (($category->slug == $segment) || ($advanced && $category->alias == str_replace(':', '-', $segment)))
{
$vars['id'] = $category->id;
$vars['view'] = 'category';
$categories = $category->getChildren();
$found = 1;
break;
}
}
if ($found == 0)
{
if ($advanced)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from('#__weblinks')
->where($db->quoteName('catid') . ' = ' . (int) $vars['catid'])
->where($db->quoteName('alias') . ' = ' . $db->quote(str_replace(':', '-', $segment)));
$db->setQuery($query);
$id = $db->loadResult();
}
else
{
$id = $segment;
}
$vars['id'] = $id;
$vars['view'] = 'weblink';
break;
}
$found = 0;
}
return $vars;
}
}
/**
* Weblinks router functions
*
* @param array &$query An array of URL arguments
*
* @return array The URL arguments to use to assemble the subsequent URL.
*
* Note. These functions are proxies for the new router interface
* for old SEF extensions.
*
* @deprecated 4.0 Use Class based routers instead
*/
function WeblinksBuildRoute(&$query)
{
$router = new WeblinksRouter;
return $router->build($query);
}
/**
* Weblinks router functions
*
* @param array $segments The segments of the URL to parse.
*
* @return array The URL attributes to be used by the application.
*
* Note. These functions are proxies for the new router interface
* for old SEF extensions.
*
* @deprecated 4.0 Use Class based routers instead
*/
function WeblinksParseRoute($segments)
{
$router = new WeblinksRouter;
return $router->parse($segments);
}

View File

@ -7,14 +7,19 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Controller;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
/** /**
* Weblinks Component Controller * Weblinks Component Controller
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinksController extends JControllerLegacy class DisplayController extends BaseController
{ {
/** /**
* Method to display a view. * Method to display a view.
@ -23,7 +28,7 @@ class WeblinksController extends JControllerLegacy
* @param array $urlparams An array of safe url parameters and their variable types, * @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}. * for valid values see {@link JFilterInput::clean()}.
* *
* @return WeblinksController This object to support chaining. * @return BaseController This object to support chaining.
* *
* @since 1.5 * @since 1.5
*/ */
@ -41,7 +46,7 @@ class WeblinksController extends JControllerLegacy
$vName = $this->input->get('view', 'categories'); $vName = $this->input->get('view', 'categories');
$this->input->set('view', $vName); $this->input->set('view', $vName);
if (JFactory::getUser()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories')) if ($this->app->getIdentity()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories'))
{ {
$cacheable = false; $cacheable = false;
} }
@ -59,7 +64,7 @@ class WeblinksController extends JControllerLegacy
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{ {
// Somehow the person just went to the form - we don't allow that. // Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403);
} }
return parent::display($cacheable, $safeurlparams); return parent::display($cacheable, $safeurlparams);

View File

@ -7,8 +7,13 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Controller;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Uri\Uri;
use Joomla\Utilities\ArrayHelper; use Joomla\Utilities\ArrayHelper;
/** /**
@ -16,7 +21,7 @@ use Joomla\Utilities\ArrayHelper;
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinksControllerWeblink extends JControllerForm class WeblinkController extends FormController
{ {
/** /**
* The URL view item variable. * The URL view item variable.
@ -75,15 +80,10 @@ class WeblinksControllerWeblink extends JControllerForm
if ($categoryId) if ($categoryId)
{ {
// If the category has been passed in the URL check it. // If the category has been passed in the URL check it.
$allow = JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId); return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
} }
if ($allow !== null) // In the absence of better information, revert to the component permissions.
{
return $allow;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data); return parent::allowAdd($data);
} }
@ -110,7 +110,7 @@ class WeblinksControllerWeblink extends JControllerForm
if ($categoryId) if ($categoryId)
{ {
// The category has been set. Check the category permissions. // The category has been set. Check the category permissions.
return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId); return $this->app->getIdentity()->authorise('core.edit', $this->option . '.category.' . $categoryId);
} }
// Since there is no asset tracking, revert to the component permissions. // Since there is no asset tracking, revert to the component permissions.
@ -162,7 +162,7 @@ class WeblinksControllerWeblink extends JControllerForm
* *
* @since 1.5 * @since 1.5
*/ */
public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true)) public function getModel($name = 'form', $prefix = 'Site', $config = array('ignore_request' => true))
{ {
return parent::getModel($name, $prefix, $config); return parent::getModel($name, $prefix, $config);
} }
@ -207,9 +207,9 @@ class WeblinksControllerWeblink extends JControllerForm
{ {
$return = $this->input->get('return', null, 'base64'); $return = $this->input->get('return', null, 'base64');
if (empty($return) || !JUri::isInternal(base64_decode($return))) if (empty($return) || !Uri::isInternal(base64_decode($return)))
{ {
return JUri::base(); return Uri::base();
} }
return base64_decode($return); return base64_decode($return);
@ -228,7 +228,7 @@ class WeblinksControllerWeblink extends JControllerForm
public function save($key = null, $urlVar = 'w_id') public function save($key = null, $urlVar = 'w_id')
{ {
// Get the application // Get the application
$app = JFactory::getApplication(); $app = $this->app;
// Get the data from POST // Get the data from POST
$data = $this->input->post->get('jform', array(), 'array'); $data = $this->input->post->get('jform', array(), 'array');
@ -253,6 +253,8 @@ class WeblinksControllerWeblink extends JControllerForm
* *
* @return void * @return void
* *
* @throws \Exception
*
* @since 1.6 * @since 1.6
*/ */
public function go() public function go()
@ -261,7 +263,7 @@ class WeblinksControllerWeblink extends JControllerForm
$id = $this->input->getInt('id'); $id = $this->input->getInt('id');
// Get the model, requiring published items // Get the model, requiring published items
$modelLink = $this->getModel('Weblink', '', array('ignore_request' => true)); $modelLink = $this->getModel('Weblink');
$modelLink->setState('filter.published', 1); $modelLink->setState('filter.published', 1);
// Get the item // Get the item
@ -270,19 +272,19 @@ class WeblinksControllerWeblink extends JControllerForm
// Make sure the item was found. // Make sure the item was found.
if (empty($link)) if (empty($link))
{ {
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check whether item access level allows access. // Check whether item access level allows access.
$groups = JFactory::getUser()->getAuthorisedViewLevels(); $groups = $this->app->getIdentity()->getAuthorisedViewLevels();
if (!in_array($link->access, $groups)) if (!in_array($link->access, $groups))
{ {
return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
} }
// Check whether category access level allows access. // Check whether category access level allows access.
$modelCat = $this->getModel('Category', 'WeblinksModel', array('ignore_request' => true)); $modelCat = $this->getModel('Category', 'Site', array('ignore_request' => true));
$modelCat->setState('filter.published', 1); $modelCat->setState('filter.published', 1);
// Get the category // Get the category
@ -291,13 +293,13 @@ class WeblinksControllerWeblink extends JControllerForm
// Make sure the category was found. // Make sure the category was found.
if (empty($category)) if (empty($category))
{ {
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check whether item access level allows access. // Check whether item access level allows access.
if (!in_array($category->access, $groups)) if (!in_array($category->access, $groups))
{ {
return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
} }
// Redirect to the URL // Redirect to the URL
@ -305,9 +307,9 @@ class WeblinksControllerWeblink extends JControllerForm
if ($link->url) if ($link->url)
{ {
$modelLink->hit($id); $modelLink->hit($id);
JFactory::getApplication()->redirect($link->url, 301); $this->app->redirect($link->url, 301);
} }
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID')); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'), 404);
} }
} }

View File

@ -7,18 +7,20 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Helper;
defined('_JEXEC') or die; defined('_JEXEC') or die;
JLoader::register('WeblinksHelper', JPATH_ADMINISTRATOR . '/components/com_weblinks/helpers/weblinks.php'); use Joomla\CMS\Factory;
JLoader::register('WeblinksHelperRoute', JPATH_SITE . '/components/com_weblinks/helpers/route.php'); use Joomla\CMS\Language\Associations;
JLoader::register('CategoryHelperAssociation', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/association.php'); use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
/** /**
* Weblinks Component Association Helper * Weblinks Component Association Helper
* *
* @since 3.0 * @since 3.0
*/ */
abstract class WeblinksHelperAssociation extends CategoryHelperAssociation abstract class AssociationHelper extends CategoryAssociationHelper
{ {
/** /**
* Method to get the associations for a given item * Method to get the associations for a given item
@ -32,21 +34,21 @@ abstract class WeblinksHelperAssociation extends CategoryHelperAssociation
*/ */
public static function getAssociations($id = 0, $view = null) public static function getAssociations($id = 0, $view = null)
{ {
$jinput = JFactory::getApplication()->input; $input = Factory::getApplication()->input;
$view = is_null($view) ? $jinput->get('view') : $view; $view = is_null($view) ? $input->get('view') : $view;
$id = empty($id) ? $jinput->getInt('id') : $id; $id = empty($id) ? $input->getInt('id') : $id;
if ($view === 'weblink') if ($view === 'weblink')
{ {
if ($id) if ($id)
{ {
$associations = JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id); $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id);
$return = array(); $return = array();
foreach ($associations as $tag => $item) foreach ($associations as $tag => $item)
{ {
$return[$tag] = WeblinksHelperRoute::getWeblinkRoute($item->id, (int) $item->catid, $item->language); $return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language);
} }
return $return; return $return;

View File

@ -0,0 +1,115 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Site\Helper;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Language\Multilanguage;
defined('_JEXEC') or die;
/**
* Weblinks Component Route Helper.
*
* @since 1.5
*/
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;
if ($catid > 1)
{
$link .= '&catid=' . $catid;
}
if ($language && $language !== '*' && Multilanguage::isEnabled())
{
$link .= '&lang=' . $language;
}
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';
}
if ($return)
{
$link .= '&return=' . $return;
}
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;
}
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;
}
}

View File

@ -7,6 +7,13 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Model;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Registry\Registry;
defined('_JEXEC') or die; defined('_JEXEC') or die;
/** /**
@ -14,7 +21,7 @@ defined('_JEXEC') or die;
* *
* @since 1.6 * @since 1.6
*/ */
class WeblinksModelCategories extends JModelList class CategoriesModel extends ListModel
{ {
/** /**
* Context string for the model type. This is used to handle uniqueness * Context string for the model type. This is used to handle uniqueness
@ -49,7 +56,7 @@ class WeblinksModelCategories extends JModelList
*/ */
protected function populateState($ordering = null, $direction = null) protected function populateState($ordering = null, $direction = null)
{ {
$app = JFactory::getApplication(); $app = Factory::getApplication();
$this->setState('filter.extension', $this->_extension); $this->setState('filter.extension', $this->_extension);
// Get the parent id if defined. // Get the parent id if defined.
@ -92,21 +99,22 @@ class WeblinksModelCategories extends JModelList
*/ */
public function getItems() public function getItems()
{ {
if (!count($this->_items)) if ($this->_items === null)
{ {
$app = JFactory::getApplication(); $active = Factory::getApplication()->getMenu()->getActive();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new JRegistry;
if ($active) if ($active)
{ {
$params->loadString($active->params); $params = $active->getParams();
}
else
{
$params = new Registry;
} }
$options = array(); $options = array();
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0); $options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = JCategories::getInstance('Weblinks', $options); $categories = Categories::getInstance('Weblinks', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root')); $this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (is_object($this->_parent)) if (is_object($this->_parent))

View File

@ -7,8 +7,17 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
/** /**
@ -16,7 +25,7 @@ use Joomla\Registry\Registry;
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinksModelCategory extends JModelList class CategoryModel extends ListModel
{ {
/** /**
* Category items data * Category items data
@ -91,7 +100,7 @@ class WeblinksModelCategory extends JModelList
} }
// Get the tags // Get the tags
$item->tags = new JHelperTags; $item->tags = new TagsHelper();
$item->tags->getItemTags('com_weblinks.weblink', $item->id); $item->tags->getItemTags('com_weblinks.weblink', $item->id);
} }
@ -101,13 +110,13 @@ class WeblinksModelCategory extends JModelList
/** /**
* Method to get a JDatabaseQuery object for retrieving the data set from a database. * Method to get a JDatabaseQuery object for retrieving the data set from a database.
* *
* @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. * @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
* *
* @since 1.6 * @since 1.6
*/ */
protected function getListQuery() protected function getListQuery()
{ {
$groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels()); $groups = implode(',', Factory::getUser()->getAuthorisedViewLevels());
// Create a new query object. // Create a new query object.
$db = $this->getDbo(); $db = $this->getDbo();
@ -164,7 +173,7 @@ class WeblinksModelCategory extends JModelList
// Filter by start and end dates. // Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate()); $nullDate = $db->quote($db->getNullDate());
$nowDate = $db->quote(JFactory::getDate()->toSql()); $nowDate = $db->quote(Factory::getDate()->toSql());
if ($this->getState('filter.publish_date')) if ($this->getState('filter.publish_date'))
{ {
@ -175,7 +184,7 @@ class WeblinksModelCategory extends JModelList
// Filter by language // Filter by language
if ($this->getState('filter.language')) if ($this->getState('filter.language'))
{ {
$query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); $query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
} }
// Filter by search in title // Filter by search in title
@ -219,8 +228,8 @@ class WeblinksModelCategory extends JModelList
*/ */
protected function populateState($ordering = null, $direction = null) protected function populateState($ordering = null, $direction = null)
{ {
$app = JFactory::getApplication(); $app = Factory::getApplication();
$params = JComponentHelper::getParams('com_weblinks'); $params = ComponentHelper::getParams('com_weblinks');
// List state information // List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint'); $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
@ -253,7 +262,7 @@ class WeblinksModelCategory extends JModelList
$id = $app->input->get('id', 0, 'int'); $id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id); $this->setState('category.id', $id);
$user = JFactory::getUser(); $user = Factory::getUser();
if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))) if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks')))
{ {
@ -264,7 +273,7 @@ class WeblinksModelCategory extends JModelList
$this->setState('filter.publish_date', true); $this->setState('filter.publish_date', true);
} }
$this->setState('filter.language', JLanguageMultilang::isEnabled()); $this->setState('filter.language', Multilanguage::isEnabled());
// Load the parameters. // Load the parameters.
$this->setState('params', $params); $this->setState('params', $params);
@ -281,21 +290,22 @@ class WeblinksModelCategory extends JModelList
{ {
if (!is_object($this->_item)) if (!is_object($this->_item))
{ {
$app = JFactory::getApplication(); $active = Factory::getApplication()->getMenu()->getActive();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new Registry;
if ($active) if ($active)
{ {
$params->loadString($active->params); $params = $active->getParams();
}
else
{
$params = new Registry;
} }
$options = array(); $options = array();
$options['countItems'] = $params->get('show_cat_num_links_cat', 1) $options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0); || $params->get('show_empty_categories', 0);
$categories = JCategories::getInstance('Weblinks', $options); $categories = Categories::getInstance('Weblinks', $options);
$this->_item = $categories->get($this->getState('category.id', 'root')); $this->_item = $categories->get($this->getState('category.id', 'root'));
if (is_object($this->_item)) if (is_object($this->_item))
@ -392,12 +402,12 @@ class WeblinksModelCategory extends JModelList
*/ */
public function hit($pk = 0) public function hit($pk = 0)
{ {
$hitcount = JFactory::getApplication()->input->getInt('hitcount', 1); $hitcount = Factory::getApplication()->input->getInt('hitcount', 1);
if ($hitcount) if ($hitcount)
{ {
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id'); $pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
$table = JTable::getInstance('Category', 'JTable'); $table = Table::getInstance('Category', 'JTable');
$table->load($pk); $table->load($pk);
$table->hit($pk); $table->hit($pk);
} }

View File

@ -7,16 +7,21 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; defined('_JEXEC') or die;
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/weblink.php'; use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Weblinks\Administrator\Model\WeblinkModel;
/** /**
* Weblinks model. * Weblinks model.
* *
* @since 1.6 * @since 1.6
*/ */
class WeblinksModelForm extends WeblinksModelWeblink class FormModel extends WeblinkModel
{ {
/** /**
* Model typeAlias string. Used for version history. * Model typeAlias string. Used for version history.
@ -49,7 +54,7 @@ class WeblinksModelForm extends WeblinksModelWeblink
*/ */
protected function populateState() protected function populateState()
{ {
$app = JFactory::getApplication(); $app = Factory::getApplication();
// Load state from the request. // Load state from the request.
$pk = $app->input->getInt('w_id'); $pk = $app->input->getInt('w_id');
@ -63,7 +68,7 @@ class WeblinksModelForm extends WeblinksModelWeblink
$return = $app->input->get('return', null, 'base64'); $return = $app->input->get('return', null, 'base64');
if (!JUri::isInternal(base64_decode($return))) if (!Uri::isInternal(base64_decode($return)))
{ {
$return = null; $return = null;
} }
@ -92,7 +97,7 @@ class WeblinksModelForm extends WeblinksModelWeblink
$form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData)); $form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
// Disable the buttons and just allow editor none for not authenticated users // Disable the buttons and just allow editor none for not authenticated users
if (JFactory::getUser()->guest) if (Factory::getUser()->guest)
{ {
$form->setFieldAttribute('description', 'editor', 'none'); $form->setFieldAttribute('description', 'editor', 'none');
$form->setFieldAttribute('description', 'buttons', 'no'); $form->setFieldAttribute('description', 'buttons', 'no');
@ -100,4 +105,21 @@ class WeblinksModelForm extends WeblinksModelWeblink
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);
}
} }

View File

@ -7,19 +7,23 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\Model;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper; use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ItemModel;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
/** /**
* Weblinks Component Model for a Weblink record * Weblinks Component Model for a Weblink record
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinksModelWeblink extends JModelItem class WeblinkModel extends ItemModel
{ {
/** /**
* Model context string. * Model context string.
@ -39,7 +43,7 @@ class WeblinksModelWeblink extends JModelItem
*/ */
protected function populateState() protected function populateState()
{ {
$app = JFactory::getApplication('site'); $app = Factory::getApplication();
// Load the object state. // Load the object state.
$pk = $app->input->getInt('id'); $pk = $app->input->getInt('id');
@ -49,7 +53,7 @@ class WeblinksModelWeblink extends JModelItem
$params = $app->getParams(); $params = $app->getParams();
$this->setState('params', $params); $this->setState('params', $params);
$user = JFactory::getUser(); $user = $app->getIdentity();
if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))) if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks')))
{ {
@ -57,7 +61,7 @@ class WeblinksModelWeblink extends JModelItem
$this->setState('filter.archived', 2); $this->setState('filter.archived', 2);
} }
$this->setState('filter.language', JLanguageMultilang::isEnabled()); $this->setState('filter.language', Multilanguage::isEnabled());
} }
/** /**
@ -69,7 +73,7 @@ class WeblinksModelWeblink extends JModelItem
*/ */
public function getItem($pk = null) public function getItem($pk = null)
{ {
$user = JFactory::getUser(); $user = Factory::getUser();
$pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id'); $pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id');
@ -100,7 +104,7 @@ class WeblinksModelWeblink extends JModelItem
// Filter by language // Filter by language
if ($this->getState('filter.language')) if ($this->getState('filter.language'))
{ {
$query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); $query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
} }
// Join over the categories to get parent category titles // Join over the categories to get parent category titles
@ -111,9 +115,8 @@ class WeblinksModelWeblink extends JModelItem
{ {
// Filter by start and end dates. // Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate()); $nullDate = $db->quote($db->getNullDate());
$date = JFactory::getDate();
$nowDate = $db->quote($date->toSql()); $nowDate = $db->quote(Factory::getDate()->toSql());
$query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')')
->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')');
@ -134,13 +137,13 @@ class WeblinksModelWeblink extends JModelItem
if (empty($data)) if (empty($data))
{ {
JError::raiseError(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Check for published state if filter set. // Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived))) if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived)))
{ {
JError::raiseError(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404);
} }
// Convert parameter fields to objects. // Convert parameter fields to objects.
@ -162,7 +165,7 @@ class WeblinksModelWeblink extends JModelItem
$this->_item[$pk] = $data; $this->_item[$pk] = $data;
} }
catch (Exception $e) catch (\Exception $e)
{ {
$this->setError($e); $this->setError($e);
$this->_item[$pk] = false; $this->_item[$pk] = false;
@ -179,13 +182,13 @@ class WeblinksModelWeblink extends JModelItem
* @param string $prefix A prefix for the table class name. Optional. * @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional. * @param array $config Configuration array for model. Optional.
* *
* @return JTable A database object * @return Table A database object
* *
* @since 1.6 * @since 1.6
*/ */
public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array()) public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = array())
{ {
return JTable::getInstance($type, $prefix, $config); return parent::getTable($type, $prefix, $config);
} }
/** /**
@ -202,6 +205,6 @@ class WeblinksModelWeblink extends JModelItem
$pk = $this->getState('weblink.id'); $pk = $this->getState('weblink.id');
} }
return $this->getTable('Weblink', 'WeblinksTable')->hit($pk); return $this->getTable('Weblink')->hit($pk);
} }
} }

View File

@ -0,0 +1,37 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_content
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Site\Service;
\defined('_JEXEC') or die;
use Joomla\CMS\Categories\Categories;
/**
* Content Component Category Tree
*
* @since 1.6
*/
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);
}
}

View File

@ -0,0 +1,298 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Site\Service;
\defined('_JEXEC') or die;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Categories\CategoryInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Component\Router\RouterView;
use Joomla\CMS\Component\Router\RouterViewConfiguration;
use Joomla\CMS\Component\Router\Rules\MenuRules;
use Joomla\CMS\Component\Router\Rules\NomenuRules;
use Joomla\CMS\Component\Router\Rules\StandardRules;
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
/**
* Routing class from com_contact
*
* @since 3.3
*/
class Router extends RouterView
{
/**
* 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;
/**
* Content 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('id');
$this->registerView($form);
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
/**
* 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);
}
}
return $path;
}
return array();
}
/**
* 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);
}
/**
* Method to get the segment(s) for a weblink
*
* @param string $id ID of the contact 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();
}
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 contact 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 contact
*
* @param string $segment Segment of the contact 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];
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Site\View\Categories;
use Joomla\CMS\MVC\View\CategoriesView;
defined('_JEXEC') or die;
/**
* Weblinks categories view.
*
* @since 1.5
*/
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';
}

View File

@ -7,6 +7,10 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\View\Category;
use Joomla\CMS\MVC\View\CategoryFeedView;
defined('_JEXEC') or die; defined('_JEXEC') or die;
/** /**
@ -14,7 +18,7 @@ defined('_JEXEC') or die;
* *
* @since 1.0 * @since 1.0
*/ */
class WeblinksViewCategory extends JViewCategoryfeed class FeedView extends CategoryFeedView
{ {
/** /**
* @var string The name of the view to link individual items to * @var string The name of the view to link individual items to

View File

@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Site\View\Category;
use Joomla\CMS\MVC\View\CategoryView;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;
defined('_JEXEC') or die;
/**
* HTML View class for the WebLinks component
*
* @since 1.5
*/
class HtmlView extends CategoryView
{
/**
* @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;
if ($item->params->get('count_clicks', $this->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;
}
$temp = new Registry;
$temp->loadString($item->params);
$item->params = clone($this->params);
$item->params->merge($temp);
}
return parent::display($tpl);
}
/**
* 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;
}
// 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']);
}
}
}

View File

@ -7,23 +7,58 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\View\Form;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
/** /**
* HTML Article View class for the Weblinks component * HTML Article View class for the Weblinks component
* *
* @since 1.5 * @since 1.5
*/ */
class WeblinksViewForm extends JViewLegacy class HtmlView extends BaseHtmlView
{ {
/**
* @var \Joomla\CMS\Form\Form
* @since 4.0.0
*/
protected $form; protected $form;
/**
* @var object
* @since 4.0.0
*/
protected $item; protected $item;
/**
* @var string
* @since 4.0.0
*/
protected $return_page; protected $return_page;
/**
* @var string
* @since 4.0.0
*/
protected $pageclass_sfx;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $state; protected $state;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $params;
/** /**
* Display the view. * Display the view.
* *
@ -33,7 +68,7 @@ class WeblinksViewForm extends JViewLegacy
*/ */
public function display($tpl = null) public function display($tpl = null)
{ {
$user = JFactory::getUser(); $user = Factory::getUser();
// Get model data. // Get model data.
$this->state = $this->get('State'); $this->state = $this->get('State');
@ -52,15 +87,13 @@ class WeblinksViewForm extends JViewLegacy
if ($authorised !== true) if ($authorised !== true)
{ {
JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
return false;
} }
if (!empty($this->item)) if (!empty($this->item))
{ {
// Override the base weblink data with any data in the session. // Override the base weblink data with any data in the session.
$temp = (array) JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); $temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
foreach ($temp as $k => $v) foreach ($temp as $k => $v)
{ {
@ -73,9 +106,7 @@ class WeblinksViewForm extends JViewLegacy
// Check for errors. // Check for errors.
if (count($errors = $this->get('Errors'))) if (count($errors = $this->get('Errors')))
{ {
JError::raiseWarning(500, implode("\n", $errors)); throw new GenericDataException(implode("\n", $errors), 500);
return false;
} }
// Create a shortcut to the parameters. // Create a shortcut to the parameters.
@ -88,6 +119,7 @@ class WeblinksViewForm extends JViewLegacy
$this->user = $user; $this->user = $user;
$this->_prepareDocument(); $this->_prepareDocument();
parent::display($tpl); parent::display($tpl);
} }
@ -98,21 +130,19 @@ class WeblinksViewForm extends JViewLegacy
*/ */
protected function _prepareDocument() protected function _prepareDocument()
{ {
$app = JFactory::getApplication(); $app = Factory::getApplication();
$menus = $app->getMenu();
$title = null;
// Because the application sets a default page title, // Because the application sets a default page title,
// we need to get it from the menu item itself // we need to get it from the menu item itself
$menu = $menus->getActive(); $menu = $app->getMenu()->getActive();
if (empty($this->item->id)) if (empty($this->item->id))
{ {
$head = JText::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK'); $head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK');
} }
else else
{ {
$head = JText::_('COM_WEBLINKS_FORM_EDIT_WEBLINK'); $head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK');
} }
if ($menu) if ($menu)
@ -126,16 +156,7 @@ class WeblinksViewForm extends JViewLegacy
$title = $this->params->def('page_title', $head); $title = $this->params->def('page_title', $head);
if ($app->get('sitename_pagetitles', 0) == 1) $this->setDocumentTitle($title);
{
$title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
}
elseif ($app->get('sitename_pagetitles', 0) == 2)
{
$title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}
$this->document->setTitle($title);
if ($this->params->get('menu-meta_description')) if ($this->params->get('menu-meta_description'))
{ {

View File

@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Component\Weblinks\Site\View\Weblink;
defined('_JEXEC') or die; defined('_JEXEC') or die;
/** /**

View File

@ -10,7 +10,6 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
JHtml::_('behavior.caption');
JFactory::getDocument()->addScriptDeclaration(" JFactory::getDocument()->addScriptDeclaration("
jQuery(function($) { jQuery(function($) {

View File

@ -9,6 +9,8 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
JHtml::_('bootstrap.tooltip'); JHtml::_('bootstrap.tooltip');
$class = ' class="first"'; $class = ' class="first"';
@ -26,7 +28,7 @@ if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) :
<div <?php echo $class; ?> > <div <?php echo $class; ?> >
<?php $class = ''; ?> <?php $class = ''; ?>
<h3 class="page-header item-title"> <h3 class="page-header item-title">
<a href="<?php echo JRoute::_(WeblinksHelperRoute::getCategoryRoute($item->id));?>"> <a href="<?php echo JRoute::_(RouteHelper::getCategoryRoute($item->id));?>">
<?php echo $this->escape($item->title); ?></a> <?php echo $this->escape($item->title); ?></a>
<?php if ($this->params->get('show_cat_num_links_cat') == 1) :?> <?php if ($this->params->get('show_cat_num_links_cat') == 1) :?>
<span class="badge badge-info tip hasTooltip" title="<?php echo JHtml::tooltipText('COM_WEBLINKS_NUM_ITEMS'); ?>"> <span class="badge badge-info tip hasTooltip" title="<?php echo JHtml::tooltipText('COM_WEBLINKS_NUM_ITEMS'); ?>">

View File

@ -11,10 +11,10 @@ defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.framework'); // JHtml::_('behavior.framework');
// Create a shortcut for params. // Create a shortcut for params.
$params = &$this->item->params; $params = &$this->category->params;
// Get the user object. // Get the user object.
$user = JFactory::getUser(); $user = JFactory::getUser();
@ -128,8 +128,8 @@ $listDirn = $this->escape($this->state->get('list.direction'));
</div> </div>
<?php $tagsData = $item->tags->getItemTags('com_weblinks.weblink', $item->id); ?> <?php $tagsData = $item->tags->getItemTags('com_weblinks.weblink', $item->id); ?>
<?php if ($this->params->get('show_tags', 1)) : ?> <?php if ($this->params->get('show_tags', 1)) : ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> <?php $this->category->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($tagsData); ?> <?php echo $this->category->tagLayout->render($tagsData); ?>
<?php endif; ?> <?php endif; ?>
<?php if (($this->params->get('show_link_description')) and ($item->description != '')) : ?> <?php if (($this->params->get('show_link_description')) and ($item->description != '')) : ?>
<?php $images = json_decode($item->images); ?> <?php $images = json_decode($item->images); ?>

View File

@ -9,10 +9,11 @@
defined('_JEXEC') or die; defined('_JEXEC') or die;
JHtml::_('behavior.keepalive'); use Joomla\CMS\HTML\HTMLHelper;
JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select'); HTMLHelper::_('behavior.keepalive');
JHtml::_('behavior.modal', 'a.modal_jform_contenthistory'); HTMLHelper::_('behavior.formvalidator');
// JHtml::_('behavior.modal', 'a.modal_jform_contenthistory');
$captchaEnabled = false; $captchaEnabled = false;
$captchaSet = $this->params->get('captcha', JFactory::getApplication()->get('captcha', '0')); $captchaSet = $this->params->get('captcha', JFactory::getApplication()->get('captcha', '0'));
@ -35,7 +36,6 @@ $params = $this->state->get('params');
{ {
if (task == 'weblink.cancel' || document.formvalidator.isValid(document.getElementById('adminForm'))) if (task == 'weblink.cancel' || document.formvalidator.isValid(document.getElementById('adminForm')))
{ {
<?php echo $this->form->getField('description')->save(); ?>
Joomla.submitform(task); Joomla.submitform(task);
} }
} }

View File

@ -1,83 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
/**
* Content categories view.
*
* @since 1.5
*/
class WeblinksViewCategories extends JViewCategories
{
protected $item = null;
/**
* @var string Default title to use for page title
* @since 3.2
*/
protected $defaultPageTitle = 'COM_WEBLINKS_DEFAULT_PAGE_TITLE';
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_weblinks';
/**
* @var string The name of the view to link individual items to
* @since 3.2
*/
protected $viewName = 'weblink';
/**
* 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)
{
$state = $this->get('State');
$items = $this->get('Items');
$parent = $this->get('Parent');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseWarning(500, implode("\n", $errors));
return false;
}
if ($items === false)
{
return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}
if ($parent == false)
{
return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}
$params = &$state->params;
$items = array($parent->id => $items);
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
$this->maxLevelcat = $params->get('maxLevelcat', -1);
$this->params = &$params;
$this->parent = &$parent;
$this->items = &$items;
return parent::display($tpl);
}
}

View File

@ -1,105 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
/**
* HTML View class for the WebLinks component
*
* @since 1.5
*/
class WeblinksViewCategory extends JViewCategory
{
/**
* 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;
if ($item->params->get('count_clicks', $this->params->get('count_clicks', 1)) == 1)
{
$item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id);
}
else
{
$item->link = $item->url;
}
$temp = new JRegistry;
$temp->loadString($item->params);
$item->params = clone($this->params);
$item->params->merge($temp);
}
return parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*/
protected function prepareDocument()
{
parent::prepareDocument();
$app = JFactory::getApplication();
$menus = $app->getMenu();
$pathway = $app->getPathway();
$title = null;
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $menus->getActive();
if ($menu)
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
}
else
{
$this->params->def('page_heading', JText::_('COM_WEBLINKS_DEFAULT_PAGE_TITLE'));
}
$id = (int) @$menu->query['id'];
if ($menu && ($menu->query['option'] != 'com_weblinks' || $id != $this->category->id))
{
$this->params->set('page_subheading', $this->category->title);
$path = array(array('title' => $this->category->title, 'link' => ''));
$category = $this->category->getParent();
while (($menu->query['option'] != 'com_weblinks' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => WeblinksHelperRoute::getCategoryRoute($category->id));
$category = $category->getParent();
}
$path = array_reverse($path);
foreach ($path as $item)
{
$pathway->addItem($item['title'], $item['link']);
}
}
parent::addFeed();
}
}

View File

@ -1,16 +0,0 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @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;
require_once JPATH_COMPONENT . '/helpers/route.php';
$controller = JControllerLegacy::getInstance('Weblinks');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();