- md5
- 7338852a5a9c03cc1d160a2867f03323
- sha1
- a785dd6104bafabbaa023dc1d1ebcec2b2632aff
- sha256
- 74daea3d2a9e961253f38ee976a556641e53befef6a60204889b6e6480d01fb5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
<?php
/**
* @package Joomla.Administrator
* @subpackage mod_popular
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/models', 'ContentModel');
/**
* Helper for mod_popular
*
* @since 1.6
*/
abstract class ModPopularHelper
{
/**
* Get a list of the most popular articles
*
* @param JObject &$params The module parameters.
*
* @return array
*/
public static function getList(&$params)
{
$user = JFactory::getuser();
// Get an instance of the generic articles model
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
// Set List SELECT
$model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
' a.created, a.hits');
// Set Ordering filter
$model->setState('list.ordering', 'a.hits');
$model->setState('list.direction', 'DESC');
// Set Category Filter
$categoryId = $params->get('catid', null);
if (is_numeric($categoryId))
{
$model->setState('filter.category_id', $categoryId);
}
// Set User Filter.
$userId = $user->get('id');
switch ($params->get('user_id', '0'))
{
case 'by_me':
$model->setState('filter.author_id', $userId);
break;
case 'not_me':
$model->setState('filter.author_id', $userId);
$model->setState('filter.author_id.include', false);
break;
}
// Set the Start and Limit
$model->setState('list.start', 0);
$model->setState('list.limit', $params->get('count', 5));
$items = $model->getItems();
if ($error = $model->getError())
{
JError::raiseError(500, $error);
return false;
}
// Set the links
foreach ($items as &$item)
{
if ($user->authorise('core.edit', 'com_content.article.' . $item->id))
{
$item->link = JRoute::_('index.php?option=com_content&task=article.edit&id=' . $item->id);
}
else
{
$item->link = '';
}
}
return $items;
}
/**
* Get the alternate title for the module
*
* @param JObject $params The module parameters.
*
* @return string The alternate title for the module.
*/
public static function getTitle($params)
{
$who = $params->get('user_id', '0');
$catid = (int) $params->get('catid', null);
if ($catid)
{
$category = JCategories::getInstance('Content')->get($catid);
if ($category)
{
$title = $category->title;
}
else
{
$title = JText::_('MOD_POPULAR_UNEXISTING');
}
}
else
{
$title = '';
}
return JText::plural(
'MOD_POPULAR_TITLE' . ($catid ? '_CATEGORY' : '') . ($who != '0' ? "_$who" : ''),
(int) $params->get('count', 5),
$title
);
}
}
The same content is in 30 releases, Joomla 3.9.15-rc to 3.10.0-alpha1. See them all, or every version of this file.