1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * @return array
16 */
17function module_most_commented_info()
18{
19	return [
20		'name' => tra('Most Commented'),
21		'description' => tra('Display the most commented objects of a certain type.'),
22		'prefs' => [],
23		'params' => [
24			'objectType' => [
25				'name' => tra('Object Type'),
26				'description' => tra('Type of objects to consider.') . ' ' . tra('Possible values: wiki (Wiki pages), blog (blog posts), article (articles).') . ' ' . tra('Default:') . ' wiki'
27			],
28			'objectLanguageFilter' => [
29				'name' => tra('Language Filter'),
30				'description' => tra('If set to a RFC1766 language tag, restricts the objects considered to those in the specified language.')
31			]
32		],
33		'common_params' => ['nonums', 'rows']
34	];
35}
36
37/**
38 * @param $mod_reference
39 * @param $module_params
40 */
41function module_most_commented($mod_reference, $module_params)
42{
43	$smarty = TikiLib::lib('smarty');
44
45	$type = 'wiki';
46	if (isset($module_params['objectType'])) {
47		$type = $module_params['objectType'];
48		if ($type != 'article' && $type != 'blog' && $type != 'wiki') {
49			//If parameter is not properly set then default to wiki
50			$type = 'wiki';
51		}
52	}
53
54	$result = TikiLib::lib('comments')->order_comments_by_count($type, isset($module_params['objectLanguageFilter']) ? $module_params['objectLanguageFilter'] : '', $mod_reference['rows']);
55	if ($result === false) {
56		$smarty->assign('module_error', tra('Feature disabled'));
57		return;
58	}
59	$smarty->assign('modMostCommented', $result['data']);
60	$smarty->assign('modContentType', $type);
61}
62