32
1
mirror of https://github.com/joomla-extensions/weblinks.git synced 2024-12-25 01:45:59 +00:00

Move to namespaces (#384)

* Make it joomla 4 compatible

* Joomla 4 compatibility

* Move to dispatcher

* Move controller.php to DisplayController

* Define default view for DisplayController

* Move the model weblinks.php to WeblinksModel

* Move the view weblinks list view view.html.php to HtmlView.php

* Move the view templates like default.php to the right position

* Move the weblinks controller weblins.php to WeblinksController.php

* Move the weblink model weblink.php to WeblinkModel.php

* Remove the get table function in the WeblinkModel

* Moved the table weblink.php to WeblinkTable.php

* Moved the controller weblink.php to WeblinkController.php

* Moved the web link form view view.html.php to HtmlView.php

* Move the weblink layouts to the right folder

* Convert list template to Bootstrap 4

* Convert form layout to Bootstrap 4

* Move forms to root folder

* Namespace field

* Calling the parent check function in the table

* Adapt travis file

* Pass factory to parent class
This commit is contained in:
Allon Moritz 2018-02-19 10:44:55 +01:00 committed by Yves Hoppe
parent 8574a4f3cf
commit 2247d9ba4d
24 changed files with 227 additions and 191 deletions

View File

@ -8,14 +8,13 @@ env:
matrix:
fast_finish: true
include:
- php: 5.5
- php: 5.6
env: RUN_PHPCS="yes"
- php: 7.0
env: RUN_PHPCS="yes"
sudo: true
addons:
firefox: "47.0.1"
- php: 7.1
- php: 7.2
- php: hhvm
sudo: true
dist: trusty
@ -66,5 +65,5 @@ script:
# System tests (Codeception)
- mv tests/acceptance.suite.dist.yml tests/acceptance.suite.yml
- vendor/bin/robo run:tests --use-htaccess
# Run phpcs on PHP 5.6 against weblinks source
# Run phpcs on PHP 7.0 against weblinks source
- if [[ $RUN_PHPCS == "yes" ]]; then vendor/bin/phpcs --report=full --extensions=php -p --standard=tests/joomla/build/phpcs/Joomla ./src; fi

View File

@ -7,15 +7,29 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
/**
* Weblinks Main Controller
*
* @since 1.5
*/
class WeblinksController extends JControllerLegacy
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'weblinks';
/**
* Method to display a view.
*
@ -39,9 +53,9 @@ class WeblinksController extends JControllerLegacy
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.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks', false));
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false));
return false;
}

View File

@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
@ -16,7 +18,7 @@ use Joomla\Utilities\ArrayHelper;
*
* @since 1.6
*/
class WeblinksControllerWeblink extends JControllerForm
class WeblinkController extends \JControllerForm
{
/**
* Method override to check if you can add a new record.
@ -35,7 +37,7 @@ class WeblinksControllerWeblink extends JControllerForm
if ($categoryId)
{
// If the category has been passed in the URL check it.
$allow = JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId);
$allow = \JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
if ($allow !== null)
@ -76,7 +78,7 @@ class WeblinksControllerWeblink extends JControllerForm
return false;
}
$user = JFactory::getUser();
$user = \JFactory::getUser();
// 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;
@ -96,13 +98,13 @@ class WeblinksControllerWeblink extends JControllerForm
*/
public function batch($model = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
// Set the model
$model = $this->getModel('Weblink', '', array());
// Preset the redirect
$this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
$this->setRedirect(\JRoute::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
return parent::batch($model);
}
@ -117,13 +119,13 @@ class WeblinksControllerWeblink extends JControllerForm
*
* @since 1.6
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
protected function postSaveHook(\JModelLegacy $model, $validData = array())
{
$task = $this->getTask();
if ($task == 'save')
{
$this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks', false));
$this->setRedirect(\JRoute::_('index.php?option=com_weblinks&view=weblinks', false));
}
}
}

View File

@ -7,14 +7,18 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\AdminController;
/**
* Weblinks list controller class.
*
* @since 1.6
*/
class WeblinksControllerWeblinks extends JControllerAdmin
class WeblinksController extends AdminController
{
/**
* Proxy for getModel
@ -27,7 +31,7 @@ class WeblinksControllerWeblinks extends JControllerAdmin
*
* @since 1.6
*/
public function getModel($name = 'Weblink', $prefix = 'WeblinksModel', $config = array('ignore_request' => true))
public function getModel($name = 'Weblink', $prefix = 'Administrator', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}

View File

@ -6,13 +6,17 @@
* @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\Field\Modal;
defined('JPATH_BASE') or die;
/**
* Supports a modal weblink picker.
*
* @since __DEPLOY_VERSION__
*/
class JFormFieldModal_Weblink extends JFormField
class WeblinkField extends \JFormField
{
/**
* The form field type.
@ -37,7 +41,7 @@ class JFormFieldModal_Weblink extends JFormField
$allowSelect = ((string) $this->element['select'] != 'false');
// Load language
JFactory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
\JFactory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
// The active weblink id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';
@ -46,8 +50,8 @@ class JFormFieldModal_Weblink extends JFormField
$modalId = 'Weblink_' . $this->id;
// Add the modal field script to the document head.
JHtml::_('jquery.framework');
JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true));
\JHtml::_('jquery.framework');
\JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true));
// Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect)
@ -61,7 +65,7 @@ class JFormFieldModal_Weblink extends JFormField
if (!isset($scriptSelect[$this->id]))
{
JFactory::getDocument()->addScriptDeclaration("
\JFactory::getDocument()->addScriptDeclaration("
function jSelectWeblink_" . $this->id . "(id, title, catid, object, url, language) {
window.processModalSelect('Weblink', '" . $this->id . "', id, title, catid, object, url, language);
}
@ -71,9 +75,9 @@ class JFormFieldModal_Weblink extends JFormField
}
// Setup variables for display.
$linkWeblinks = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$linkWeblink = 'index.php?option=com_weblinks&view=weblink&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$modalTitle = JText::_('COM_WEBLINKS_CHANGE_WEBLINK');
$linkWeblinks = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&' . \JSession::getFormToken() . '=1';
$linkWeblink = 'index.php?option=com_weblinks&view=weblink&layout=modal&tmpl=component&' . \JSession::getFormToken() . '=1';
$modalTitle = \JText::_('COM_WEBLINKS_CHANGE_WEBLINK');
if (isset($this->element['language']))
{
@ -88,7 +92,7 @@ class JFormFieldModal_Weblink extends JFormField
if ($value)
{
$db = JFactory::getDbo();
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__weblinks'))
@ -98,12 +102,12 @@ class JFormFieldModal_Weblink extends JFormField
{
$title = $db->loadResult();
}
catch (RuntimeException $e)
catch (\RuntimeException $e)
{
JError::raiseWarning(500, $e->getMessage());
\JError::raiseWarning(500, $e->getMessage());
}
}
$title = empty($title) ? JText::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
$title = empty($title) ? \JText::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The current weblink display field.
$html = '<span class="input-append">';
@ -118,8 +122,8 @@ class JFormFieldModal_Weblink extends JFormField
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalSelect' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_WEBLINKS_CHANGE_WEBLINK') . '">'
. '<span class="icon-file" aria-hidden="true"></span> ' . JText::_('JSELECT')
. ' title="' . \JHtml::tooltipText('COM_WEBLINKS_CHANGE_WEBLINK') . '">'
. '<span class="icon-file" aria-hidden="true"></span> ' . \JText::_('JSELECT')
. '</a>';
}
// New weblink button
@ -131,8 +135,8 @@ class JFormFieldModal_Weblink extends JFormField
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalNew' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_WEBLINKS_NEW_WEBLINK') . '">'
. '<span class="icon-new" aria-hidden="true"></span> ' . JText::_('JACTION_CREATE')
. ' title="' . \JHtml::tooltipText('COM_WEBLINKS_NEW_WEBLINK') . '">'
. '<span class="icon-new" aria-hidden="true"></span> ' . \JText::_('JACTION_CREATE')
. '</a>';
}
// Edit weblink button
@ -144,8 +148,8 @@ class JFormFieldModal_Weblink extends JFormField
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalEdit' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_WEBLINKS_EDIT_WEBLINK') . '">'
. '<span class="icon-edit" aria-hidden="true"></span> ' . JText::_('JACTION_EDIT')
. ' title="' . \JHtml::tooltipText('COM_WEBLINKS_EDIT_WEBLINK') . '">'
. '<span class="icon-edit" aria-hidden="true"></span> ' . \JText::_('JACTION_EDIT')
. '</a>';
}
// Clear weblink button
@ -156,7 +160,7 @@ class JFormFieldModal_Weblink extends JFormField
. ' id="' . $this->id . '_clear"'
. ' href="#"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-remove" aria-hidden="true"></span>' . JText::_('JCLEAR')
. '<span class="icon-remove" aria-hidden="true"></span>' . \JText::_('JCLEAR')
. '</a>';
}
$html .= '</span>';
@ -164,7 +168,7 @@ class JFormFieldModal_Weblink extends JFormField
// Select weblink modal
if ($allowSelect)
{
$html .= JHtml::_(
$html .= \JHtml::_(
'bootstrap.renderModal',
'ModalSelect' . $modalId,
array(
@ -174,7 +178,7 @@ class JFormFieldModal_Weblink extends JFormField
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" data-dismiss="modal" aria-hidden="true">' . JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>',
'footer' => '<a role="button" class="btn" data-dismiss="modal" aria-hidden="true">' . \JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>',
)
);
}
@ -182,7 +186,7 @@ class JFormFieldModal_Weblink extends JFormField
// New weblink modal
if ($allowNew)
{
$html .= JHtml::_(
$html .= \JHtml::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
@ -197,13 +201,13 @@ class JFormFieldModal_Weblink extends JFormField
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'weblink\', \'cancel\', \'weblink-form\'); return false;">'
. JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. \JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'weblink\', \'save\', \'weblink-form\'); return false;">'
. JText::_('JSAVE') . '</a>'
. \JText::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'weblink\', \'apply\', \'weblink-form\'); return false;">'
. JText::_('JAPPLY') . '</a>',
. \JText::_('JAPPLY') . '</a>',
)
);
}
@ -211,11 +215,11 @@ class JFormFieldModal_Weblink extends JFormField
// Edit weblink modal
if ($allowEdit)
{
$html .= JHtml::_(
$html .= \JHtml::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => JText::_('COM_WEBLINKS_EDIT_WEBLINK'),
'title' => \JText::_('COM_WEBLINKS_EDIT_WEBLINK'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
@ -226,20 +230,20 @@ class JFormFieldModal_Weblink extends JFormField
'modalWidth' => '80',
'footer' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'weblink\', \'cancel\', \'weblink-form\'); return false;">'
. JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. \JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'weblink\', \'save\', \'weblink-form\'); return false;">'
. JText::_('JSAVE') . '</a>'
. \JText::_('JSAVE') . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'weblink\', \'apply\', \'weblink-form\'); return false;">'
. JText::_('JAPPLY') . '</a>',
. \JText::_('JAPPLY') . '</a>',
)
);
}
// Note: class='required' for client side validation.
$class = $this->required ? ' class="required modal-value"' : '';
$html .= '<input type="hidden" id="' . $this->id . '_id" ' . $class . ' data-required="' . (int) $this->required . '" name="' . $this->name
. '" data-text="' . htmlspecialchars(JText::_('COM_WEBLINKS_SELECT_A_WEBLINK', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';
. '" data-text="' . htmlspecialchars(\JText::_('COM_WEBLINKS_SELECT_A_WEBLINK', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';
return $html;
}

View File

@ -7,18 +7,20 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
JLoader::register('WeblinksHelper', JPATH_ADMINISTRATOR . '/components/com_weblinks/helpers/weblinks.php');
\JLoader::register('WeblinksHelper', JPATH_ADMINISTRATOR . '/components/com_weblinks/helpers/weblinks.php');
/**
* Weblinks model.
*
* @since 1.5
*/
class WeblinksModelWeblink extends JModelAdmin
class WeblinkModel extends \JModelAdmin
{
/**
* The type alias for this content type.
@ -64,7 +66,7 @@ class WeblinksModelWeblink extends JModelAdmin
if ($record->catid)
{
return JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
return \JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canDelete($record);
@ -84,28 +86,12 @@ class WeblinksModelWeblink extends JModelAdmin
{
if (!empty($record->catid))
{
return JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
return \JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canEditState($record);
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $type The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return JTable A JTable object
*
* @since 1.6
*/
public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Abstract method for getting the form from the model.
*
@ -168,7 +154,7 @@ class WeblinksModelWeblink extends JModelAdmin
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
$data = \JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
if (empty($data))
{
@ -177,7 +163,7 @@ class WeblinksModelWeblink extends JModelAdmin
// Prime some default values.
if ($this->getState('weblink.id') == 0)
{
$app = JFactory::getApplication();
$app = \JFactory::getApplication();
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
}
}
@ -211,7 +197,7 @@ class WeblinksModelWeblink extends JModelAdmin
$item->images = $registry->toArray();
// Load associated web links items
$assoc = JLanguageAssociations::isEnabled();
$assoc = \JLanguageAssociations::isEnabled();
if ($assoc)
{
@ -219,7 +205,7 @@ class WeblinksModelWeblink extends JModelAdmin
if ($item->id != null)
{
$associations = JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
$associations = \JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id);
foreach ($associations as $tag => $association)
{
@ -230,7 +216,7 @@ class WeblinksModelWeblink extends JModelAdmin
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags = new \JHelperTags;
$item->tags->getTagIds($item->id, 'com_weblinks.weblink');
$item->metadata['tags'] = $item->tags;
}
@ -250,15 +236,15 @@ class WeblinksModelWeblink extends JModelAdmin
*/
protected function prepareTable($table)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$date = \JFactory::getDate();
$user = \JFactory::getUser();
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = JApplicationHelper::stringURLSafe($table->alias);
$table->alias = \JApplicationHelper::stringURLSafe($table->alias);
if (empty($table->alias))
{
$table->alias = JApplicationHelper::stringURLSafe($table->title);
$table->alias = \JApplicationHelper::stringURLSafe($table->title);
}
if (empty($table->id))
@ -318,9 +304,9 @@ class WeblinksModelWeblink extends JModelAdmin
*/
public function save($data)
{
$app = JFactory::getApplication();
$app = \JFactory::getApplication();
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
\JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
@ -328,7 +314,7 @@ class WeblinksModelWeblink extends JModelAdmin
// Check if New Category exists
if ($catid > 0)
{
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
$catid = \CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
}
// Save New Category
@ -342,7 +328,7 @@ class WeblinksModelWeblink extends JModelAdmin
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
$data['catid'] = \CategoriesHelper::createCategory($table);
}
// Alter the title for save as copy
@ -377,10 +363,10 @@ class WeblinksModelWeblink extends JModelAdmin
{
if ($name == $table->title)
{
$name = JString::increment($name);
$name = \JString::increment($name);
}
$alias = JString::increment($alias, 'dash');
$alias = \JString::increment($alias, 'dash');
}
return array($name, $alias);
@ -397,7 +383,7 @@ class WeblinksModelWeblink extends JModelAdmin
*
* @since 3.6.0
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
protected function preprocessForm(\JForm $form, $data, $group = 'content')
{
if ($this->canCreateCategory())
{
@ -405,13 +391,13 @@ class WeblinksModelWeblink extends JModelAdmin
}
// Association weblinks items
if (JLanguageAssociations::isEnabled())
if (\JLanguageAssociations::isEnabled())
{
$languages = JLanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc');
$languages = \JLanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc');
if (count($languages) > 1)
{
$addform = new SimpleXMLElement('<form />');
$addform = new \SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
@ -429,6 +415,7 @@ class WeblinksModelWeblink extends JModelAdmin
$field->addAttribute('new', 'true');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
$field->addAttribute('addfieldprefix', 'Joomla\\Component\\Weblinks\\Administrator\\Field');
}
$form->load($addform, false);
@ -447,6 +434,6 @@ class WeblinksModelWeblink extends JModelAdmin
*/
private function canCreateCategory()
{
return JFactory::getUser()->authorise('core.create', 'com_weblinks');
return \JFactory::getUser()->authorise('core.create', 'com_weblinks');
}
}

View File

@ -7,24 +7,30 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
/**
* Methods supporting a list of weblink records.
*
* @since 1.6
*/
class WeblinksModelWeblinks extends JModelList
class WeblinksModel extends ListModel
{
/**
* 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.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
@ -53,7 +59,7 @@ class WeblinksModelWeblinks extends JModelList
'level', 'c.level',
);
$assoc = JLanguageAssociations::isEnabled();
$assoc = \JLanguageAssociations::isEnabled();
if ($assoc)
{
@ -61,7 +67,7 @@ class WeblinksModelWeblinks extends JModelList
}
}
parent::__construct($config);
parent::__construct($config, $factory);
}
/**
@ -77,7 +83,7 @@ class WeblinksModelWeblinks extends JModelList
*/
protected function populateState($ordering = 'a.title', $direction = 'asc')
{
$app = JFactory::getApplication();
$app = \JFactory::getApplication();
$forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd');
@ -103,7 +109,7 @@ class WeblinksModelWeblinks extends JModelList
$this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd'));
// Load the parameters.
$params = JComponentHelper::getParams('com_weblinks');
$params = \JComponentHelper::getParams('com_weblinks');
$this->setState('params', $params);
// Force a language.
@ -155,7 +161,7 @@ class WeblinksModelWeblinks extends JModelList
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser();
$user = \JFactory::getUser();
// Select the required fields from the table.
$query->select(
@ -185,7 +191,7 @@ class WeblinksModelWeblinks extends JModelList
->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON ' . $db->qn('c.id') . ' = ' . $db->qn('a.catid'));
// Join over the associations.
$assoc = JLanguageAssociations::isEnabled();
$assoc = \JLanguageAssociations::isEnabled();
if ($assoc)
{

View File

@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\Table;
defined('_JEXEC') or die;
/**
@ -14,7 +16,7 @@ defined('_JEXEC') or die;
*
* @since 1.5
*/
class WeblinksTableWeblink extends JTable
class WeblinkTable extends \JTable
{
/**
* Ensure the params and metadata in json encoded in the bind method
@ -38,8 +40,11 @@ class WeblinksTableWeblink extends JTable
// Set the published column alias
$this->setColumnAlias('published', 'state');
JTableObserverTags::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
if (version_compare(JVERSION, '4.0', '<' ) == 1)
{
\JTableObserverTags::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
\JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_weblinks.weblink'));
}
}
/**
@ -53,8 +58,8 @@ class WeblinksTableWeblink extends JTable
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$date = \JFactory::getDate();
$user = \JFactory::getUser();
$this->modified = $date->toSql();
@ -91,17 +96,17 @@ class WeblinksTableWeblink extends JTable
}
// Verify that the alias is unique
$table = JTable::getInstance('Weblink', 'WeblinksTable');
$table = new WeblinkTable($this->getDbo());
if ($table->load(array('language' => $this->language, 'alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
$this->setError(\JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
return false;
}
// Convert IDN urls to punycode
$this->url = JStringPunycode::urlToPunycode($this->url);
$this->url = \JStringPunycode::urlToPunycode($this->url);
return parent::store($updateNulls);
}
@ -115,9 +120,9 @@ class WeblinksTableWeblink extends JTable
*/
public function check()
{
if (JFilterInput::checkAttribute(array('href', $this->url)))
if (\JFilterInput::checkAttribute(array('href', $this->url)))
{
$this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
$this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
return false;
}
@ -125,7 +130,7 @@ class WeblinksTableWeblink extends JTable
// Check for valid name
if (trim($this->title) == '')
{
$this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
$this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
return false;
}
@ -144,7 +149,7 @@ class WeblinksTableWeblink extends JTable
if ($xid && $xid != (int) $this->id)
{
$this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_NAME'));
$this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_NAME'));
return false;
}
@ -154,17 +159,17 @@ class WeblinksTableWeblink extends JTable
$this->alias = $this->title;
}
$this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
$this->alias = \JApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
$this->alias = \JFactory::getDate()->format("Y-m-d-H-i-s");
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $db->getNullDate() && $this->publish_down < $this->publish_up)
{
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
$this->setError(\JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
@ -177,7 +182,7 @@ class WeblinksTableWeblink extends JTable
{
// Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">");
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
$after_clean = \JString::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean);
$clean_keys = array();
@ -194,6 +199,6 @@ class WeblinksTableWeblink extends JTable
$this->metakey = implode(", ", $clean_keys);
}
return true;
return parent::check();
}
}

View File

@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\View\Weblink;
defined('_JEXEC') or die;
/**
@ -14,7 +16,7 @@ defined('_JEXEC') or die;
*
* @since 1.5
*/
class WeblinksViewWeblink extends JViewLegacy
class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
{
protected $state;
@ -38,13 +40,13 @@ class WeblinksViewWeblink extends JViewLegacy
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode("\n", $errors));
\JError::raiseError(500, implode("\n", $errors));
return false;
}
// 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 = \JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd'))
{
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
@ -71,47 +73,47 @@ class WeblinksViewWeblink extends JViewLegacy
*/
protected function addToolbar()
{
JFactory::getApplication()->input->set('hidemainmenu', true);
\JFactory::getApplication()->input->set('hidemainmenu', true);
$user = JFactory::getUser();
$user = \JFactory::getUser();
$isNew = ($this->item->id == 0);
$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.
$canDo = JHelperContent::getActions('com_weblinks', 'category', $this->item->catid);
$canDo = \JHelperContent::getActions('com_weblinks', 'category', $this->item->catid);
JToolbarHelper::title($isNew ? JText::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : JText::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
\JToolbarHelper::title($isNew ? \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
// If not checked out, can save the item.
if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create')))))
{
JToolbarHelper::apply('weblink.apply');
JToolbarHelper::save('weblink.save');
\JToolbarHelper::apply('weblink.apply');
\JToolbarHelper::save('weblink.save');
}
if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))
{
JToolbarHelper::save2new('weblink.save2new');
\JToolbarHelper::save2new('weblink.save2new');
}
// If an existing item, can save to a copy.
if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0))
{
JToolbarHelper::save2copy('weblink.save2copy');
\JToolbarHelper::save2copy('weblink.save2copy');
}
if (empty($this->item->id))
{
JToolbarHelper::cancel('weblink.cancel');
\JToolbarHelper::cancel('weblink.cancel');
}
else
{
if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit'))
{
JToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
\JToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
}
JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
\JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
}
JToolbarHelper::divider();
JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT');
\JToolbarHelper::divider();
\JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT');
}
}

View File

@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\View\Weblinks;
defined('_JEXEC') or die;
/**
@ -14,7 +16,7 @@ defined('_JEXEC') or die;
*
* @since 1.5
*/
class WeblinksViewWeblinks extends JViewLegacy
class HtmlView extends \Joomla\CMS\MVC\View\HtmlView
{
protected $items;
@ -40,13 +42,13 @@ class WeblinksViewWeblinks extends JViewLegacy
// Modal layout doesn't need the submenu.
if ($this->getLayout() !== 'modal')
{
WeblinksHelper::addSubmenu('weblinks');
\WeblinksHelper::addSubmenu('weblinks');
}
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode("\n", $errors));
\JError::raiseError(500, implode("\n", $errors));
return false;
}
@ -54,16 +56,16 @@ class WeblinksViewWeblinks extends JViewLegacy
if ($this->getLayout() !== 'modal')
{
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
$this->sidebar = \JHtmlSidebar::render();
}
else
{
// In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD'))
if ($forcedLanguage = \JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD'))
{
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
@ -89,51 +91,50 @@ class WeblinksViewWeblinks extends JViewLegacy
require_once JPATH_COMPONENT . '/helpers/weblinks.php';
$state = $this->get('State');
$canDo = JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
$user = JFactory::getUser();
$canDo = \JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
$user = \JFactory::getUser();
// Get the toolbar object instance
$bar = JToolBar::getInstance('toolbar');
$bar = \JToolbar::getInstance('toolbar');
JToolbarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
\JToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{
JToolbarHelper::addNew('weblink.add');
\JToolbarHelper::addNew('weblink.add');
}
if ($canDo->get('core.edit') || $canDo->get('core.edit.own'))
{
JToolbarHelper::editList('weblink.edit');
\JToolbarHelper::editList('weblink.edit');
}
if ($canDo->get('core.edit.state'))
{
JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
\JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
\JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
JToolbarHelper::archiveList('weblinks.archive');
JToolbarHelper::checkin('weblinks.checkin');
\JToolbarHelper::archiveList('weblinks.archive');
\JToolbarHelper::checkin('weblinks.checkin');
}
if ($state->get('filter.published') == -2 && $canDo->get('core.delete'))
{
JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
\JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
}
elseif ($canDo->get('core.edit.state'))
{
JToolbarHelper::trash('weblinks.trash');
\JToolbarHelper::trash('weblinks.trash');
}
// Add a batch button
if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks'))
{
JHtml::_('bootstrap.modal', 'collapseModal');
$title = JText::_('JTOOLBAR_BATCH');
$title = \JText::_('JTOOLBAR_BATCH');
// Instantiate a new JLayoutFile instance and render the batch button
$layout = new JLayoutFile('joomla.toolbar.batch');
$layout = new \JLayoutFile('joomla.toolbar.batch');
$dhtml = $layout->render(array('title' => $title));
$bar->appendButton('Custom', $dhtml, 'batch');
@ -141,10 +142,10 @@ class WeblinksViewWeblinks extends JViewLegacy
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
{
JToolbarHelper::preferences('com_weblinks');
\JToolbarHelper::preferences('com_weblinks');
}
JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
\JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
}
/**
@ -157,13 +158,13 @@ class WeblinksViewWeblinks extends JViewLegacy
protected function getSortFields()
{
return array(
'a.ordering' => JText::_('JGRID_HEADING_ORDERING'),
'a.state' => JText::_('JSTATUS'),
'a.title' => JText::_('JGLOBAL_TITLE'),
'a.access' => JText::_('JGRID_HEADING_ACCESS'),
'a.hits' => JText::_('JGLOBAL_HITS'),
'a.language' => JText::_('JGRID_HEADING_LANGUAGE'),
'a.id' => JText::_('JGRID_HEADING_ID')
'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'),
'a.state' => \JText::_('JSTATUS'),
'a.title' => \JText::_('JGLOBAL_TITLE'),
'a.access' => \JText::_('JGRID_HEADING_ACCESS'),
'a.hits' => \JText::_('JGLOBAL_HITS'),
'a.language' => \JText::_('JGRID_HEADING_LANGUAGE'),
'a.id' => \JText::_('JGRID_HEADING_ID')
);
}
}

View File

@ -0,0 +1,29 @@
<?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
*/
defined('_JEXEC') or die;
use Joomla\CMS\Dispatcher\Dispatcher;
/**
* Dispatcher class for com_weblinks
*
* @since __DEPLOY_VERSION__
*/
class WeblinksDispatcher extends Dispatcher
{
/**
* The extension namespace
*
* @var string
*
* @since __DEPLOY_VERSION__
*/
protected $namespace = 'Joomla\\Component\\Weblinks';
}

View File

@ -38,6 +38,7 @@
label="JCATEGORY"
description="COM_WEBLINKS_FIELD_CATEGORY_DESC"
extension="com_weblinks"
addfieldprefix="Joomla\Component\Categories\Administrator\Field"
required="true"
default=""
/>

View File

@ -46,22 +46,22 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo JHtml::_('bootstrap.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)); ?>
<div class="row-fluid">
<div class="span9">
<div class="row">
<div class="col-md-9">
<div class="form-vertical">
<?php echo $this->form->getControlGroup('url'); ?>
<?php echo $this->form->getControlGroup('description'); ?>
</div>
</div>
<div class="span3">
<div class="col-md-3">
<?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'images', JText::_('JGLOBAL_FIELDSET_IMAGE_OPTIONS', true)); ?>
<div class="row-fluid">
<div class="span6">
<div class="row">
<div class="col-md-6">
<?php echo $this->form->getControlGroup('images'); ?>
<?php foreach ($this->form->getGroup('images') as $field) : ?>
<?php echo $field->getControlGroup(); ?>
@ -72,18 +72,18 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>
<div class="row-fluid form-horizontal-desktop">
<div class="span6">
<div class="row form-horizontal-desktop">
<div class="col-md-6">
<?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
</div>
<div class="span6">
<div class="col-md-6">
<?php echo JLayoutHelper::render('joomla.edit.metadata', $this); ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JLayoutHelper::render('joomla.edit.params', $this); ?>
<?php if (!$isModal && $assoc) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'associations', JText::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<?php echo $this->loadTemplate('associations'); ?>

View File

@ -30,11 +30,12 @@ if ($saveOrder)
}
?>
<form action="<?php echo JRoute::_('index.php?option=com_weblinks&view=weblinks'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<?php if (!empty($this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<div id="j-sidebar-container" class="col-md-2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<div id="j-main-container" class="col-md-10">
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
@ -184,4 +185,5 @@ if ($saveOrder)
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</div>
</div>
</form>

View File

@ -1,20 +0,0 @@
<?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
*/
defined('_JEXEC') or die;
JHtml::_('behavior.tabstate');
if (!JFactory::getUser()->authorise('core.manage', 'com_weblinks'))
{
throw new JAccessExceptionNotallowed(JText::_('JERROR_ALERTNOAUTHOR'), 403);
}
$controller = JControllerLegacy::getInstance('Weblinks');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();