Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/administrator/components/com_weblinks/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,20 @@ public function install($parent)
// Set the location in the tree
$category->setLocation(1, 'last-child');

// Check to make sure our data is valid
if (!$category->check()) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
try {
// Check to make sure our data is valid
$category->check();
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $e->getMessage()), 'error');

return;
}

// Now store the category
if (!$category->store(true)) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
try {
// Now store the category
$category->store(true);
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $e->getMessage()), 'error');

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;

Expand Down Expand Up @@ -115,7 +116,8 @@ public function edit($weblink, $params, $attribs = [], $legacy = false)
&& $weblink->checked_out
&& $weblink->checked_out !== $user->get('id')
) {
$checkoutUser = Factory::getUser($weblink->checked_out);
$userFactory = Factory::getContainer()->get(UserFactoryInterface::class);
$checkoutUser = $userFactory->loadUserById($weblink->checked_out);
$date = HTMLHelper::_('date', $weblink->checked_out_time);
$tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name)
. ' <br> ' . $date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public function store($updateNulls = true)
$table->load(['language' => $this->language, 'alias' => $this->alias, 'catid' => (int) $this->catid])
&& ($table->id != $this->id || $this->id == 0)
) {
$this->setError(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
return false;
throw new \Exception(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
}

// Convert IDN urls to punycode
Expand All @@ -145,14 +144,12 @@ public function store($updateNulls = true)
public function check()
{
if (InputFilter::checkAttribute(['href', $this->url])) {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
return false;
throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
}

// Check for valid name
if (trim($this->title) === '') {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
return false;
throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
}

// Check for existing name
Expand All @@ -169,8 +166,7 @@ public function check()
$db->setQuery($query);
$xid = (int) $db->loadResult();
if ($xid && $xid != (int) $this->id) {
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME'));
return false;
throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_NAME'));
}

if (empty($this->alias)) {
Expand All @@ -184,8 +180,7 @@ public function check()

// Check the publish down date is not earlier than publish up.
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
throw new \Exception(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Weblinks\Administrator\Model\WeblinkModel;
use Joomla\Registry\Registry;

/**
* View to edit a weblink.
Expand All @@ -48,7 +48,7 @@ class HtmlView extends BaseHtmlView
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
* @var Registry
*/
protected $state;

Expand All @@ -67,11 +67,6 @@ public function display($tpl = null)
$this->item = $model->getItem();
$this->form = $model->getForm();

// Check for errors.
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

// If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
Expand All @@ -90,6 +85,18 @@ public function display($tpl = null)
parent::display($tpl);
}

/**
* Get the item ID.
*
* @return int
*
* @since __DEPLOY_VERSION__
*/
public function getItemId(): int
{
return (int) $this->item->id;
}

/**
* Add the page title and toolbar.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
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\Pagination\Pagination;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Weblinks\Administrator\Model\WeblinksModel;
use Joomla\Registry\Registry;

/**
* View class for a list of weblinks.
Expand All @@ -47,7 +48,7 @@ class HtmlView extends BaseHtmlView
/**
* The model state
*
* @var \Joomla\CMS\Object\CMSObject
* @var Registry
*/
protected $state;

Expand Down Expand Up @@ -91,12 +92,7 @@ public function display($tpl = null)
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

// Check for errors.
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
}

Expand All @@ -122,6 +118,42 @@ public function display($tpl = null)
parent::display($tpl);
}

/**
* Get the items.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function getItems(): array
{
return $this->items;
}

/**
* Get the pagination object.
*
* @return Pagination
*
* @since __DEPLOY_VERSION__
*/
public function getPagination(): Pagination
{
return $this->pagination;
}

/**
* Get the model state.
*
* @return Registry
*
* @since __DEPLOY_VERSION__
*/
public function getState(): Registry
{
return $this->state;
}

/**
* Add the page title and toolbar.
*
Expand Down
14 changes: 9 additions & 5 deletions src/administrator/components/com_weblinks/tmpl/weblink/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

/** @var \Joomla\Component\Weblinks\Administrator\View\Weblink\HtmlView $this */

HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', ['placement' => 'bottom']);

// @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since 3.7.0.
$function = Factory::getApplication()->getInput()->getCmd('function', 'jEditWeblink_' . (int) $this->item->id);
$function = Factory::getApplication()->getInput()->getCmd('function', 'jEditWeblink_' . $this->getItemId());

// Function to update input title when changed
$this->getDocument()->addScriptDeclaration('
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$script = <<<JS
function jEditWeblinkModal() {
if (window.parent && document.formvalidator.isValid(document.getElementById("weblink-form"))) {
return window.parent.' . $this->escape($function) . '(document.getElementById("jform_title").value);
return window.parent.{$this->escape($function)}(document.getElementById("jform_title").value);
}
}
');
JS;
$wa->addInlineScript($script);
?>
<button id="applyBtn" type="button" class="hidden" onclick="Joomla.submitbutton('weblink.apply'); jEditWeblinkModal();"></button>
<button id="saveBtn" type="button" class="hidden" onclick="Joomla.submitbutton('weblink.save'); jEditWeblinkModal();"></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
HTMLHelper::_('behavior.multiselect');
$user = Factory::getApplication()->getIdentity();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$listOrder = $this->escape($this->getState()->get('list.ordering'));
$listDirn = $this->escape($this->getState()->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';
$assoc = Associations::isEnabled();
if ($saveOrder && !empty($this->items)) {
if ($saveOrder && !empty($this->getItems())) {
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
}
Expand All @@ -41,7 +41,7 @@
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
?>
<?php if (empty($this->items)) :
<?php if (empty($this->getItems())) :
?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
Expand Down Expand Up @@ -98,7 +98,7 @@
<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 foreach ($this->getItems() as $i => $item) :
?>
<?php $item->cat_link = Route::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]=' . $item->catid); ?>
<?php $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); ?>
Expand Down Expand Up @@ -191,7 +191,7 @@
</table>

<?php // Load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>
<?php echo $this->getPagination()->getListFooter(); ?>

<?php // Load the batch processing form. ?>
<?php if (
Expand Down
3 changes: 2 additions & 1 deletion src/components/com_weblinks/src/Model/CategoriesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function getItems()
$options['access'] = $this->getState('filter.access');
$options['published'] = $this->getState('filter.published');
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = Categories::getInstance('Weblinks', $options);
$component = Factory::getApplication()->bootComponent('com_weblinks');
$categories = $component->getCategory($options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (\is_object($this->_parent)) {
$this->_items = $this->_parent->getChildren();
Expand Down
5 changes: 3 additions & 2 deletions src/components/com_weblinks/src/Model/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function getListQuery()

// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
$query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
}

// Filter by search in title
Expand Down Expand Up @@ -308,7 +308,8 @@ public function getCategory()
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0);

$categories = Categories::getInstance('Weblinks', $options);
$component = Factory::getApplication()->bootComponent('com_weblinks');
$categories = $component->getCategory($options);
$this->_item = $categories->get($this->getState('category.id', 'root'));

if (\is_object($this->_item)) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/com_weblinks/src/Model/WeblinkModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getItem($pk = null)

// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
$query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
}

// Join over the categories to get parent category titles
Expand Down Expand Up @@ -174,6 +174,7 @@ public function getItem($pk = null)

$this->_item[$pk] = $data;
} catch (\Exception $e) {
// @phpstan-ignore-next-line ItemModel::setError is designed to handle caught exceptions
$this->setError($e);
$this->_item[$pk] = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/com_weblinks/src/Service/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Router extends RouterView
* Weblinks Component router constructor
*
* @param SiteApplication $app The application object
* @param AbstractMenu $menu The menu object to work with
* @param AbstractMenu $menu The menu object to work witha
* @param CategoryFactoryInterface $categoryFactory The category object
* @param DatabaseInterface $db The database object
*/
Expand Down
11 changes: 7 additions & 4 deletions src/components/com_weblinks/src/View/Category/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\Component\Weblinks\Site\View\Category;

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\CategoryView;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function display($tpl = null)
}
}

return parent::display($tpl);
parent::display($tpl);
}

/**
Expand All @@ -71,10 +72,12 @@ protected function prepareDocument()
}

// Get ID of the category from active menu item
$menu = $this->menu;
$app = Factory::getApplication();
$menu = $app->getMenu()->getActive();
$pathway = $app->getPathway();

if (
$menu && $menu->component == 'com_weblinks' && isset($menu->query['view'])
$menu && $menu->component === 'com_weblinks' && isset($menu->query['view'])
&& \in_array($menu->query['view'], ['categories', 'category'])
) {
$id = $menu->query['id'];
Expand All @@ -91,7 +94,7 @@ protected function prepareDocument()

$path = array_reverse($path);
foreach ($path as $item) {
$this->pathway->addItem($item['title'], $item['link']);
$pathway->addItem($item['title'], $item['link']);
}
}
}
Loading