first commit

This commit is contained in:
2025-06-17 11:53:18 +02:00
commit 9f0f7ba12b
8804 changed files with 1369176 additions and 0 deletions

View File

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="module" client="site" method="upgrade">
<name>mod_articles_popular</name>
<author>Joomla! Project</author>
<creationDate>2006-07</creationDate>
<copyright>(C) 2006 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>MOD_POPULAR_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\ArticlesPopular</namespace>
<files>
<folder module="mod_articles_popular">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/mod_articles_popular.ini</language>
<language tag="en-GB">language/en-GB/mod_articles_popular.sys.ini</language>
</languages>
<help key="Site_Modules:_Articles_-_Most_Read" />
<config>
<fields name="params">
<fieldset name="basic">
<field
name="catid"
type="category"
label="JCATEGORY"
extension="com_content"
multiple="true"
filter="intarray"
layout="joomla.form.field.list-fancy-select"
/>
<field
name="count"
type="number"
label="MOD_POPULAR_FIELD_COUNT_LABEL"
default="5"
filter="integer"
/>
<field
name="show_front"
type="radio"
layout="joomla.form.field.radio.switcher"
label="MOD_POPULAR_FIELD_FEATURED_LABEL"
default="1"
filter="integer"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field
name="basicspacer1"
type="spacer"
hr="true"
/>
<field
name="date_filtering"
type="list"
label="MOD_POPULAR_FIELD_DATEFILTERING_LABEL"
default="off"
validate="options"
>
<option value="off">MOD_POPULAR_OPTION_OFF_VALUE</option>
<option value="range">MOD_POPULAR_OPTION_DATERANGE_VALUE</option>
<option value="relative">MOD_POPULAR_OPTION_RELATIVEDAY_VALUE</option>
</field>
<field
name="date_field"
type="list"
label="MOD_POPULAR_FIELD_DATEFIELD_LABEL"
default="a.created"
showon="date_filtering:range,relative"
validate="options"
>
<option value="a.created">MOD_POPULAR_OPTION_CREATED_VALUE</option>
<option value="a.modified">MOD_POPULAR_OPTION_MODIFIED_VALUE</option>
<option value="a.publish_up">MOD_POPULAR_OPTION_STARTPUBLISHING_VALUE</option>
</field>
<field
name="start_date_range"
type="calendar"
label="MOD_POPULAR_FIELD_STARTDATE_LABEL"
translateformat="true"
showtime="true"
filter="user_utc"
showon="date_filtering:range"
/>
<field
name="end_date_range"
type="calendar"
label="MOD_POPULAR_FIELD_ENDDATE_LABEL"
translateformat="true"
showtime="true"
filter="user_utc"
showon="date_filtering:range"
/>
<field
name="relative_date"
type="number"
label="MOD_POPULAR_FIELD_RELATIVEDATE_LABEL"
default="30"
filter="integer"
showon="date_filtering:relative"
/>
</fieldset>
<fieldset name="advanced">
<field
name="layout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
class="form-select"
validate="moduleLayout"
/>
<field
name="moduleclass_sfx"
type="textarea"
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
rows="3"
validate="CssIdentifier"
/>
<field
name="cache"
type="list"
label="COM_MODULES_FIELD_CACHING_LABEL"
default="1"
filter="integer"
validate="options"
>
<option value="1">JGLOBAL_USE_GLOBAL</option>
<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
</field>
<field
name="cache_time"
type="number"
label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
default="900"
filter="integer"
/>
<field
name="cachemode"
type="hidden"
default="static"
>
<option value="static"></option>
</field>
</fieldset>
</fields>
</config>
</extension>

View File

@ -0,0 +1,41 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_popular
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
\defined('_JEXEC') or die;
use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
/**
* The popular articles module service provider.
*
* @since 4.3.0
*/
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.3.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\ArticlesPopular'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\ArticlesPopular\\Site\\Helper'));
$container->registerServiceProvider(new Module());
}
};

View File

@ -0,0 +1,51 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_popular
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\ArticlesPopular\Site\Dispatcher;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Dispatcher class for mod_articles_popular
*
* @since 4.3.0
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;
/**
* Returns the layout data.
*
* @return array
*
* @since 4.3.0
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
if (!ComponentHelper::getParams('com_content')->get('record_hits', 1)) {
$data['hitsDisabledMessage'] = Text::_('JGLOBAL_RECORD_HITS_DISABLED');
} else {
$data['list'] = $this->getHelperFactory()->getHelper('ArticlesPopularHelper', $data)->getArticles($data['params'], $data['app']);
}
return $data;
}
}

View File

@ -0,0 +1,184 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_popular
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\ArticlesPopular\Site\Helper;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Cache\Controller\OutputController;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Component\Content\Site\Model\ArticlesModel;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Helper for mod_articles_popular
*
* @since 4.3.0
*/
class ArticlesPopularHelper
{
/**
* The module instance
*
* @var \stdClass
*
* @since 4.3.0
*/
protected $module;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @since 4.3.0
*/
public function __construct($config = [])
{
$this->module = $config['module'];
}
/**
* Retrieve a list of months with archived articles
*
* @param Registry $params The module parameters.
* @param SiteApplication $app The current application.
*
* @return object[]
*
* @since 4.3.0
*/
public function getArticles(Registry $moduleParams, SiteApplication $app)
{
$cacheKey = md5(serialize([$moduleParams->toString(), $this->module->module, $this->module->id]));
/** @var OutputController $cache */
$cache = Factory::getContainer()->get(CacheControllerFactoryInterface::class)
->createCacheController('output', ['defaultgroup' => 'mod_articles_popular']);
if (!$cache->contains($cacheKey)) {
$mvcContentFactory = $app->bootComponent('com_content')->getMVCFactory();
/** @var ArticlesModel $articlesModel */
$articlesModel = $mvcContentFactory->createModel('Articles', 'Site', ['ignore_request' => true]);
// Set application parameters in model
$appParams = $app->getParams();
$articlesModel->setState('params', $appParams);
$articlesModel->setState('list.start', 0);
$articlesModel->setState('filter.published', ContentComponent::CONDITION_PUBLISHED);
// Set the filters based on the module params
$articlesModel->setState('list.limit', (int) $moduleParams->get('count', 5));
$articlesModel->setState('filter.featured', $moduleParams->get('show_front', 1) == 1 ? 'show' : 'hide');
// This module does not use tags data
$articlesModel->setState('load_tags', false);
// Access filter
$access = !ComponentHelper::getParams('com_content')->get('show_noauth');
$articlesModel->setState('filter.access', $access);
// Category filter
$articlesModel->setState('filter.category_id', $moduleParams->get('catid', []));
// Date filter
$date_filtering = $moduleParams->get('date_filtering', 'off');
if ($date_filtering !== 'off') {
$articlesModel->setState('filter.date_filtering', $date_filtering);
$articlesModel->setState('filter.date_field', $moduleParams->get('date_field', 'a.created'));
$articlesModel->setState('filter.start_date_range', $moduleParams->get('start_date_range', '1000-01-01 00:00:00'));
$articlesModel->setState('filter.end_date_range', $moduleParams->get('end_date_range', '9999-12-31 23:59:59'));
$articlesModel->setState('filter.relative_date', $moduleParams->get('relative_date', 30));
}
// Filter by language
$articlesModel->setState('filter.language', $app->getLanguageFilter());
// Ordering
$articlesModel->setState('list.ordering', 'a.hits');
$articlesModel->setState('list.direction', 'DESC');
// Prepare the module output
$items = [];
$itemParams = new \stdClass();
$itemParams->authorised = Access::getAuthorisedViewLevels($app->getIdentity()->get('id'));
$itemParams->access = $access;
foreach ($articlesModel->getItems() as $item) {
$items[] = $this->prepareItem($item, $itemParams);
}
// Cache the output and return
$cache->store($items, $cacheKey);
return $items;
}
// Return the cached output
return $cache->get($cacheKey);
}
/**
* Prepare the article before render.
*
* @param object $item The article to prepare
* @param \stdClass $params The model item
*
* @return object
*
* @since 4.3.0
*/
private function prepareItem($item, $params): object
{
$item->slug = $item->id . ':' . $item->alias;
if ($params->access || \in_array($item->access, $params->authorised)) {
// We know that user has the privilege to view the article
$item->link = Route::_(RouteHelper::getArticleRoute($item->slug, $item->catid, $item->language));
} else {
$item->link = Route::_('index.php?option=com_users&view=login');
}
return $item;
}
/**
* Get a list of popular articles from the articles model
*
* @param \Joomla\Registry\Registry &$params object holding the models parameters
*
* @return mixed
*
* @since 4.3.0
*
* @deprecated 4.3 will be removed in 6.0
* Use the non-static method getArticles
* Example: Factory::getApplication()->bootModule('mod_articles_popular', 'site')
* ->getHelper('ArticlesPopularHelper')
* ->getArticles($params, Factory::getApplication())
*/
public static function getList(&$params)
{
return (new self())->getArticles($params, Factory::getApplication());
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_popular
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
if (!isset($list)) {
if (isset($hitsDisabledMessage)) {
echo $hitsDisabledMessage;
}
return;
}
?>
<ul class="mostread mod-list">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>