Optimization and cleanup

This commit is contained in:
Michael Babker 2015-02-17 20:20:59 -05:00
parent 5ceb760b54
commit 58ec6fef01
21 changed files with 270 additions and 221 deletions

View File

@ -10,7 +10,7 @@
defined('_JEXEC') or die;
/**
* Weblinks Weblink Controller
* Weblinks Main Controller
*
* @since 1.5
*/
@ -22,7 +22,7 @@ class WeblinksController extends JControllerLegacy
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @return JControllerLegacy This object to support chaining.
*
* @since 1.5
*/
@ -45,8 +45,6 @@ class WeblinksController extends JControllerLegacy
return false;
}
parent::display();
return $this;
return parent::display();
}
}

View File

@ -37,15 +37,13 @@ class WeblinksControllerWeblink extends JControllerForm
$allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
}
if ($allow === null)
{
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
else
if ($allow !== null)
{
return $allow;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
/**
@ -73,11 +71,9 @@ class WeblinksControllerWeblink extends JControllerForm
// The category has been set. Check the category permissions.
return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId);
}
else
{
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
/**

View File

@ -29,22 +29,6 @@ class WeblinksControllerWeblinks extends JControllerAdmin
*/
public function getModel($name = 'Weblink', $prefix = 'WeblinksModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
/**
* Method to provide child classes the opportunity to process after the delete task.
*
* @param JModelLegacy $model The model for the component
* @param mixed $ids array of ids deleted.
*
* @return void
*
* @since 3.1
*/
protected function postDeleteHook(JModelLegacy $model, $ids = null)
{
return parent::getModel($name, $prefix, $config);
}
}

View File

@ -10,6 +10,7 @@
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
use Joomla\String\String;
/**
* Weblinks model.
@ -18,12 +19,11 @@ use Joomla\Registry\Registry;
*/
class WeblinksModelWeblink extends JModelAdmin
{
/**
* The type alias for this content type.
*
* @var string
* @since 3.2
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
@ -52,16 +52,13 @@ class WeblinksModelWeblink extends JModelAdmin
{
return;
}
$user = JFactory::getUser();
if ($record->catid)
{
return $user->authorise('core.delete', 'com_weblinks.category.'.(int) $record->catid);
}
else
{
return parent::canDelete($record);
return JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canDelete($record);
}
}
@ -76,16 +73,12 @@ class WeblinksModelWeblink extends JModelAdmin
*/
protected function canEditState($record)
{
$user = JFactory::getUser();
if (!empty($record->catid))
{
return $user->authorise('core.edit.state', 'com_weblinks.category.'.(int) $record->catid);
}
else
{
return parent::canEditState($record);
return JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canEditState($record);
}
/**
@ -234,11 +227,11 @@ class WeblinksModelWeblink extends JModelAdmin
$user = JFactory::getUser();
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = JApplication::stringURLSafe($table->alias);
$table->alias = JApplicationHelper::stringURLSafe($table->alias);
if (empty($table->alias))
{
$table->alias = JApplication::stringURLSafe($table->title);
$table->alias = JApplicationHelper::stringURLSafe($table->title);
}
if (empty($table->id))
@ -262,7 +255,7 @@ class WeblinksModelWeblink extends JModelAdmin
{
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->get('id');
$table->modified_by = $user->id;
}
}
@ -332,10 +325,10 @@ class WeblinksModelWeblink extends JModelAdmin
{
if ($name == $table->title)
{
$name = JString::increment($name);
$name = String::increment($name);
}
$alias = JString::increment($alias, 'dash');
$alias = String::increment($alias, 'dash');
}
return array($name, $alias);

View File

@ -20,7 +20,8 @@ class WeblinksModelWeblinks extends JModelList
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
@ -54,8 +55,9 @@ class WeblinksModelWeblinks extends JModelList
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
@ -94,8 +96,10 @@ class WeblinksModelWeblinks extends JModelList
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
@ -114,6 +118,7 @@ class WeblinksModelWeblinks extends JModelList
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
@ -128,9 +133,7 @@ class WeblinksModelWeblinks extends JModelList
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
'a.hits,' .
'a.state, a.access, a.ordering,' .
'a.language, a.publish_up, a.publish_down'
'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
)
);
$query->from($db->quoteName('#__weblinks') . ' AS a');
@ -166,6 +169,7 @@ class WeblinksModelWeblinks extends JModelList
// Filter by published state
$published = $this->getState('filter.state');
if (is_numeric($published))
{
$query->where('a.state = ' . (int) $published);
@ -177,6 +181,7 @@ class WeblinksModelWeblinks extends JModelList
// Filter by category.
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId))
{
$query->where('a.catid = ' . (int) $categoryId);
@ -184,6 +189,7 @@ class WeblinksModelWeblinks extends JModelList
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
@ -204,6 +210,7 @@ class WeblinksModelWeblinks extends JModelList
}
$tagId = $this->getState('filter.tag');
// Filter by a single tag.
if (is_numeric($tagId))
{
@ -218,13 +225,14 @@ class WeblinksModelWeblinks extends JModelList
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}
$query->order($db->escape($orderCol . ' ' . $orderDirn));
//echo nl2br(str_replace('#__','jos_',$query));
return $query;
}
}

View File

@ -21,7 +21,7 @@ class Com_WeblinksInstallerScript
/**
* Function to perform changes during install
*
* @param JInstallerComponent $parent The class calling this method
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*

View File

@ -9,6 +9,8 @@
defined('_JEXEC') or die;
use Joomla\String\String;
/**
* Weblink Table class
*
@ -28,6 +30,8 @@ class WeblinksTableWeblink extends JTable
* Constructor
*
* @param JDatabaseDriver &$db A database connector object
*
* @since 1.5
*/
public function __construct(&$db)
{
@ -44,20 +48,22 @@ class WeblinksTableWeblink extends JTable
* Overload the store method for the Weblinks table.
*
* @param boolean Toggle whether null values should be updated.
*
* @return boolean True on success, false on failure.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$date = JFactory::getDate();
$user = JFactory::getUser();
$this->modified = $date->toSql();
$this->modified = $date->toSql();
if ($this->id)
{
// Existing item
$this->modified_by = $user->get('id');
$this->modified_by = $user->id;
}
else
{
@ -67,22 +73,23 @@ class WeblinksTableWeblink extends JTable
{
$this->created = $date->toSql();
}
if (empty($this->created_by))
{
$this->created_by = $user->get('id');
$this->created_by = $user->id;
}
}
// Set publish_up to null date if not set
if (!$this->publish_up)
{
$this->publish_up = $this->_db->getNullDate();
$this->publish_up = $this->getDbo()->getNullDate();
}
// Set publish_down to null date if not set
if (!$this->publish_down)
{
$this->publish_down = $this->_db->getNullDate();
$this->publish_down = $this->getDbo()->getNullDate();
}
// Verify that the alias is unique
@ -91,6 +98,7 @@ class WeblinksTableWeblink extends JTable
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
return false;
}
@ -104,12 +112,15 @@ class WeblinksTableWeblink extends JTable
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
*
* @since 1.5
*/
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'));
return false;
}
@ -121,17 +132,21 @@ class WeblinksTableWeblink extends JTable
}
// Check for existing name
$query = $this->_db->getQuery(true)
->select($this->_db->quoteName('id'))
->from($this->_db->quoteName('#__weblinks'))
->where($this->_db->quoteName('title') . ' = ' . $this->_db->quote($this->title))
->where($this->_db->quoteName('catid') . ' = ' . (int) $this->catid);
$this->_db->setQuery($query);
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__weblinks'))
->where($db->quoteName('title') . ' = ' . $db->quote($this->title))
->where($db->quoteName('catid') . ' = ' . (int) $this->catid);
$db->setQuery($query);
$xid = (int) $db->loadResult();
$xid = (int) $this->_db->loadResult();
if ($xid && $xid != (int) $this->id)
{
$this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_NAME'));
return false;
}
@ -139,36 +154,45 @@ class WeblinksTableWeblink extends JTable
{
$this->alias = $this->title;
}
$this->alias = JApplication::stringURLSafe($this->alias);
$this->alias = JApplicationHelper::stringURLSafe($this->alias);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$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 > $this->_db->getNullDate() && $this->publish_down < $this->publish_up)
if ($this->publish_down > $db->getNullDate() && $this->publish_down < $this->publish_up)
{
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
// clean up keywords -- eliminate extra spaces between phrases
// and cr (\r) and lf (\n) characters from string
/*
* Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string
*/
if (!empty($this->metakey))
{
// only process if not empty
$bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
$keys = explode(',', $after_clean); // create array using commas as delimiter
// Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">");
$after_clean = String::str_ireplace($bad_characters, "", $this->metakey);
$keys = explode(',', $after_clean);
$clean_keys = array();
foreach ($keys as $key)
{
if (trim($key)) { // ignore blank keywords
// Ignore blank keywords
if (trim($key))
{
$clean_keys[] = trim($key);
}
}
$this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
// Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys);
}
return true;

View File

@ -29,9 +29,9 @@ class WeblinksViewWeblinks extends JViewLegacy
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
WeblinksHelper::addSubmenu('weblinks');
@ -56,39 +56,46 @@ 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();
$state = $this->get('State');
$canDo = JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
$user = JFactory::getUser();
// Get the toolbar object instance
$bar = JToolBar::getInstance('toolbar');
JToolbarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{
JToolbarHelper::addNew('weblink.add');
}
if ($canDo->get('core.edit'))
{
JToolbarHelper::editList('weblink.edit');
}
if ($canDo->get('core.edit.state')) {
if ($canDo->get('core.edit.state'))
{
JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
JToolbarHelper::archiveList('weblinks.archive');
JToolbarHelper::checkin('weblinks.checkin');
}
if ($state->get('filter.state') == -2 && $canDo->get('core.delete'))
{
JToolbarHelper::deleteList('', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
} elseif ($canDo->get('core.edit.state'))
}
elseif ($canDo->get('core.edit.state'))
{
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'))
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');
@ -99,6 +106,7 @@ class WeblinksViewWeblinks extends JViewLegacy
$dhtml = $layout->render(array('title' => $title));
$bar->appendButton('Custom', $dhtml, 'batch');
}
if ($user->authorise('core.admin', 'com_weblinks'))
{
JToolbarHelper::preferences('com_weblinks');
@ -133,9 +141,9 @@ class WeblinksViewWeblinks extends JViewLegacy
);
JHtmlSidebar::addFilter(
JText::_('JOPTION_SELECT_TAG'),
'filter_tag',
JHtml::_('select.options', JHtml::_('tag.options', true, true), 'value', 'text', $this->state->get('filter.tag'))
JText::_('JOPTION_SELECT_TAG'),
'filter_tag',
JHtml::_('select.options', JHtml::_('tag.options', true, true), 'value', 'text', $this->state->get('filter.tag'))
);
}

View File

@ -19,10 +19,12 @@ class WeblinksController extends JControllerLegacy
/**
* Method to display a view.
*
* @param boolean If true, the view output will be cached
* @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return WeblinksController This object to support chaining.
*
* @return JController This object to support chaining.
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
@ -37,7 +39,7 @@ class WeblinksController extends JControllerLegacy
$vName = $this->input->get('view', 'categories');
$this->input->set('view', $vName);
if ($user->get('id') ||($this->input->getMethod() == 'POST' && $vName = 'categories'))
if (JFactory::getUser()->id ||($this->input->getMethod() == 'POST' && $vName = 'categories'))
{
$cachable = false;
}

View File

@ -9,6 +9,8 @@
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
/**
* Weblinks class.
*
@ -17,12 +19,18 @@ defined('_JEXEC') or die;
class WeblinksControllerWeblink extends JControllerForm
{
/**
* @since 1.6
* The URL view item variable.
*
* @var string
* @since 1.6
*/
protected $view_item = 'form';
/**
* @since 1.6
* The URL view list variable.
*
* @var string
* @since 1.6
*/
protected $view_list = 'categories';
@ -38,6 +46,7 @@ class WeblinksControllerWeblink extends JControllerForm
* Method to add a new record.
*
* @return boolean True if the article can be added, false if not.
*
* @since 1.6
*/
public function add()
@ -60,25 +69,22 @@ class WeblinksControllerWeblink extends JControllerForm
*/
protected function allowAdd($data = array())
{
$user = JFactory::getUser();
$categoryId = JArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int');
$allow = null;
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int');
$allow = null;
if ($categoryId)
{
// If the category has been passed in the URL check it.
$allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
$allow = JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId);
}
if ($allow === null)
{
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
else
if ($allow !== null)
{
return $allow;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
/**
@ -106,11 +112,9 @@ class WeblinksControllerWeblink extends JControllerForm
// The category has been set. Check the category permissions.
return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId);
}
else
{
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
/**
@ -124,10 +128,12 @@ class WeblinksControllerWeblink extends JControllerForm
*/
public function cancel($key = 'w_id')
{
parent::cancel($key);
$return = parent::cancel($key);
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
return $return;
}
/**
@ -142,9 +148,7 @@ class WeblinksControllerWeblink extends JControllerForm
*/
public function edit($key = null, $urlVar = 'w_id')
{
$result = parent::edit($key, $urlVar);
return $result;
return parent::edit($key, $urlVar);
}
/**
@ -160,9 +164,7 @@ class WeblinksControllerWeblink extends JControllerForm
*/
public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
return parent::getModel($name, $prefix, $config);
}
/**
@ -195,9 +197,7 @@ class WeblinksControllerWeblink extends JControllerForm
}
/**
* Get the return URL.
*
* If a "return" variable has been passed in the request
* Get the return URL if a "return" variable has been passed in the request
*
* @return string The return URL.
*
@ -211,24 +211,8 @@ class WeblinksControllerWeblink extends JControllerForm
{
return JUri::base();
}
else
{
return base64_decode($return);
}
}
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
* @since 1.6
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
return;
return base64_decode($return);
}
/**
@ -267,11 +251,11 @@ class WeblinksControllerWeblink extends JControllerForm
$id = $this->input->getInt('id');
// Get the model, requiring published items
$modelLink = $this->getModel('Weblink', '', array('ignore_request' => true));
$modelLink = $this->getModel('Weblink', '', array('ignore_request' => true));
$modelLink->setState('filter.published', 1);
// Get the item
$link = $modelLink->getItem($id);
$link = $modelLink->getItem($id);
// Make sure the item was found.
if (empty($link))
@ -280,8 +264,7 @@ class WeblinksControllerWeblink extends JControllerForm
}
// Check whether item access level allows access.
$user = JFactory::getUser();
$groups = $user->getAuthorisedViewLevels();
$groups = JFactory::getUser()->getAuthorisedViewLevels();
if (!in_array($link->access, $groups))
{
@ -314,9 +297,7 @@ class WeblinksControllerWeblink extends JControllerForm
$modelLink->hit($id);
JFactory::getApplication()->redirect($link->url);
}
else
{
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'));
}
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'));
}
}

View File

@ -27,15 +27,13 @@ abstract class WeblinksHelperAssociation extends CategoryHelperAssociation
*
* @return array Array of associations for the item
*
* @since 3.0
* @since 3.0
*/
public static function getAssociations($id = 0, $view = null)
{
jimport('helper.route', JPATH_COMPONENT_SITE);
$app = JFactory::getApplication();
$jinput = $app->input;
$jinput = JFactory::getApplication()->input;
$view = is_null($view) ? $jinput->get('view') : $view;
$id = empty($id) ? $jinput->getInt('id') : $id;
@ -45,6 +43,5 @@ abstract class WeblinksHelperAssociation extends CategoryHelperAssociation
}
return array();
}
}

View File

@ -16,10 +16,18 @@ defined('_JEXEC') or die;
*/
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

@ -16,6 +16,14 @@ defined('_JEXEC') or die;
*/
class JHtmlIcon
{
/**
* Create a link to create a new weblink
*
* @param mixed $weblink Unused
* @param mixed $params Unused
*
* @return string
*/
public static function create($weblink, $params)
{
JHtml::_('bootstrap.tooltip');
@ -24,10 +32,19 @@ class JHtmlIcon
$url = JRoute::_(WeblinksHelperRoute::getFormRoute(0, base64_encode($uri)));
$text = JHtml::_('image', 'system/new.png', JText::_('JNEW'), null, true);
$button = JHtml::_('link', $url, $text);
$output = '<span class="hasTooltip" title="' . JHtml::tooltipText('COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>';
return $output;
return '<span class="hasTooltip" title="' . JHtml::tooltipText('COM_WEBLINKS_FORM_CREATE_WEBLINK') . '">' . $button . '</span>';
}
/**
* Create a link to edit an existing weblink
*
* @param object $weblink Weblink data
* @param \Joomla\Registry\Registry $params Item params
* @param array $attribs Unused
*
* @return string
*/
public static function edit($weblink, $params, $attribs = array())
{
$uri = JUri::getInstance();
@ -67,8 +84,6 @@ class JHtmlIcon
$button = JHtml::_('link', JRoute::_($url), $text);
$output = '<span class="hasTooltip" title="' . JHtml::tooltipText('COM_WEBLINKS_EDIT') . ' :: ' . $overlib . '">' . $button . '</span>';
return $output;
return '<span class="hasTooltip" title="' . JHtml::tooltipText('COM_WEBLINKS_EDIT') . ' :: ' . $overlib . '">' . $button . '</span>';
}
}

View File

@ -22,6 +22,8 @@ abstract class WeblinksHelperRoute
/**
* @param integer The route of the weblink
*
* @return string
*/
public static function getWeblinkRoute($id, $catid, $language = 0)
{
@ -29,7 +31,7 @@ abstract class WeblinksHelperRoute
'weblink' => array((int) $id)
);
//Create the link
// Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id='. $id;
if ($catid > 1)
@ -65,8 +67,10 @@ abstract class WeblinksHelperRoute
}
/**
* @param integer $id The id of the weblink.
* @param string $return The return page variable.
* @param integer $id The id of the weblink.
* @param string $return The return page variable.
*
* @return string
*/
public static function getFormRoute($id, $return = null)
{
@ -88,6 +92,12 @@ abstract class WeblinksHelperRoute
return $link;
}
/**
* @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)
@ -136,6 +146,9 @@ abstract class WeblinksHelperRoute
return $link;
}
/**
* @return void
*/
protected static function buildLanguageLookup()
{
if (count(self::$lang_lookup) == 0)
@ -158,9 +171,9 @@ abstract class WeblinksHelperRoute
protected static function _findItem($needles = null)
{
$app = JFactory::getApplication();
$menus = $app->getMenu('site');
$language = isset($needles['language']) ? $needles['language'] : '*';
$app = JFactory::getApplication();
$menus = $app->getMenu('site');
$language = isset($needles['language']) ? $needles['language'] : '*';
// Prepare the reverse lookup array.
if (!isset(self::$lookup[$language]))
@ -187,13 +200,14 @@ abstract class WeblinksHelperRoute
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
@ -226,6 +240,7 @@ abstract class WeblinksHelperRoute
// 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;
@ -233,6 +248,7 @@ abstract class WeblinksHelperRoute
// If not found, return language specific home link
$default = $menus->getDefault($language);
return !empty($default->id) ? $default->id : null;
}
}

View File

@ -17,16 +17,17 @@ defined('_JEXEC') or die;
class WeblinksModelCategories extends JModelList
{
/**
* Model context string.
* Context string for the model type. This is used to handle uniqueness
* when dealing with the getStoreId() method and caching data structures.
*
* @var string
* @var string
*/
public $_context = 'com_weblinks.categories';
protected $context = 'com_weblinks.categories';
/**
* The category context (allows other extensions to derived from this model).
*
* @var string
* @var string
*/
protected $_extension = 'com_weblinks';

View File

@ -9,6 +9,8 @@
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
/**
* Weblinks Component Weblink Model
*
@ -35,7 +37,8 @@ class WeblinksModelCategory extends JModelList
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
@ -56,16 +59,14 @@ class WeblinksModelCategory extends JModelList
/**
* The category that applies.
*
* @access protected
* @var object
* @var object
*/
protected $_category = null;
/**
* The list of other weblink categories.
*
* @access protected
* @var array
* @var array
*/
protected $_categories = null;
@ -84,10 +85,11 @@ class WeblinksModelCategory extends JModelList
{
if (!isset($this->_params))
{
$params = new JRegistry;
$params = new Registry;
$params->loadString($item->params);
$item->params = $params;
}
// Get the tags
$item->tags = new JHelperTags;
$item->tags->getItemTags('com_weblinks.weblink', $item->id);
@ -97,15 +99,15 @@ class WeblinksModelCategory extends JModelList
}
/**
* Method to build an SQL query to load the list data.
* 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 string An SQL query
* @since 1.6
*/
protected function getListQuery()
{
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
// Create a new query object.
$db = $this->getDbo();
@ -123,8 +125,9 @@ class WeblinksModelCategory extends JModelList
->join('LEFT', '#__categories AS c ON c.id = a.catid')
->where('c.access IN (' . $groups . ')');
//Filter by published category
// Filter by published category
$cpublished = $this->getState('filter.c.published');
if (is_numeric($cpublished))
{
$query->where('c.published = ' . (int) $cpublished);
@ -134,24 +137,24 @@ class WeblinksModelCategory extends JModelList
// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")
->select("ua.email AS author_email")
->join('LEFT', '#__users AS ua ON ua.id = a.created_by')
->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');
// Filter by state
$state = $this->getState('filter.state');
if (is_numeric($state))
{
$query->where('a.state = ' . (int) $state);
}
// do not show trashed links on the front-end
$query->where('a.state != -2');
// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$date = JFactory::getDate();
$nowDate = $db->quote($date->toSql());
$nowDate = $db->quote(JFactory::getDate()->toSql());
if ($this->getState('filter.publish_date'))
{
@ -167,6 +170,7 @@ class WeblinksModelCategory extends JModelList
// Filter by search in title
$search = $this->getState('list.filter');
if (!empty($search))
{
$search = $db->quote('%' . $db->escape($search, true) . '%');
@ -174,7 +178,12 @@ class WeblinksModelCategory extends JModelList
}
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
$query->order(
$db->escape(
$this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')
)
);
return $query;
}
@ -201,23 +210,28 @@ class WeblinksModelCategory extends JModelList
$this->setState('list.filter', $app->input->getString('filter-search'));
$orderCol = $app->input->get('filter_order', 'ordering');
if (!in_array($orderCol, $this->filter_fields))
{
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $app->input->get('filter_order_Dir', 'ASC');
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', '')))
{
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id);
$user = JFactory::getUser();
if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks')))
{
// limit to published for people who can't edit or edit.state.
@ -236,9 +250,8 @@ class WeblinksModelCategory extends JModelList
/**
* Method to get category data for the current category
*
* @param integer An optional ID
*
* @return object
*
* @since 1.5
*/
public function getCategory()
@ -248,7 +261,7 @@ class WeblinksModelCategory extends JModelList
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new JRegistry;
$params = new Registry;
if ($active)
{
@ -256,17 +269,22 @@ class WeblinksModelCategory extends JModelList
}
$options = array();
$options['countItems'] = $params->get('show_cat_num_links_cat', 1) || $params->get('show_empty_categories', 0);
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0);
$categories = JCategories::getInstance('Weblinks', $options);
$this->_item = $categories->get($this->getState('category.id', 'root'));
if (is_object($this->_item))
{
$this->_children = $this->_item->getChildren();
$this->_parent = false;
if ($this->_item->getParent())
{
$this->_parent = $this->_item->getParent();
}
$this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling = $this->_item->getSibling(false);
}
@ -339,20 +357,19 @@ class WeblinksModelCategory extends JModelList
/**
* Increment the hit counter for the category.
*
* @param int $pk Optional primary key of the category to increment.
* @param integer $pk Optional primary key of the category to increment.
*
* @return boolean True if successful; false otherwise and internal error set.
* @return boolean True if successful; false otherwise and internal error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$input = JFactory::getApplication()->input;
$hitcount = $input->getInt('hitcount', 1);
$hitcount = JFactory::getApplication()->input->getInt('hitcount', 1);
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->load($pk);
$table->hit($pk);

View File

@ -9,7 +9,7 @@
defined('_JEXEC') or die;
require_once JPATH_COMPONENT_ADMINISTRATOR.'/models/weblink.php';
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/weblink.php';
/**
* Weblinks model.
@ -21,14 +21,16 @@ class WeblinksModelForm extends WeblinksModelWeblink
/**
* Model typeAlias string. Used for version history.
*
* @var string
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';
/**
* Get the return URL.
*
* @return string The return URL.
* @return string The return URL.
*
* @since 1.6
*/
public function getReturnPage()
@ -50,10 +52,11 @@ class WeblinksModelForm extends WeblinksModelWeblink
// Load state from the request.
$pk = $app->input->getInt('w_id');
$this->setState('weblink.id', $pk);
// Add compatibility variable for default naming conventions.
$this->setState('form.id', $pk);
$categoryId = $app->input->getInt('catid');
$categoryId = $app->input->getInt('catid');
$this->setState('weblink.catid', $categoryId);
$return = $app->input->get('return', null, 'base64');
@ -66,7 +69,7 @@ class WeblinksModelForm extends WeblinksModelWeblink
$this->setState('return_page', base64_decode($return));
// Load the parameters.
$params = $app->getParams();
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout', $app->input->getString('layout'));

View File

@ -21,8 +21,7 @@ class WeblinksModelWeblink extends JModelItem
/**
* Model context string.
*
* @access protected
* @var string
* @var string
*/
protected $_context = 'com_weblinks.weblink';
@ -98,7 +97,9 @@ class WeblinksModelWeblink extends JModelItem
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
*
* @return JTable A database object
*
* @since 1.6
*/
public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array())
@ -121,6 +122,7 @@ class WeblinksModelWeblink extends JModelItem
}
$weblink = $this->getTable('Weblink', 'WeblinksTable');
return $weblink->hit($id);
}
}

View File

@ -17,9 +17,7 @@ JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_weblinks/models', 'We
/**
* Helper for mod_weblinks
*
* @package Joomla.Site
* @subpackage mod_weblinks
* @since 1.5.0
* @since 1.5
*/
class ModWeblinksHelper
{
@ -30,7 +28,7 @@ class ModWeblinksHelper
*
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
*
* @since 1.5.0
* @since 1.5
**/
public static function getList(&$params)
{
@ -108,9 +106,7 @@ class ModWeblinksHelper
return $items;
}
else
{
return;
}
return;
}
}

View File

@ -9,6 +9,8 @@
defined('JPATH_BASE') or die;
use Joomla\Registry\Registry;
// Load the base adapter.
require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php';
@ -251,11 +253,11 @@ class PlgFinderWeblinks extends FinderIndexerAdapter
$item->setLanguage();
// Initialise the item parameters.
$registry = new JRegistry;
$registry = new Registry;
$registry->loadString($item->params);
$item->params = $registry;
$registry = new JRegistry;
$registry = new Registry;
$registry->loadString($item->metadata);
$item->metadata = $registry;

View File

@ -60,9 +60,7 @@ class PlgSearchWeblinks extends JPlugin
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
{
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
$searchText = $text;
@ -185,7 +183,7 @@ class PlgSearchWeblinks extends JPlugin
->order($order);
// Filter by language.
if ($app->isSite() && JLanguageMultilang::isEnabled())
if (JFactory::getApplication()->isSite() && JLanguageMultilang::isEnabled())
{
$tag = JFactory::getLanguage()->getTag();
$query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')