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_freetags_most_popular_info()
18{
19	return [
20		'name' => tra('Most Popular Tags'),
21		'description' => tra('Shows the most popular tags. More popularity is indicated by a larger font.'),
22		'prefs' => ['feature_freetags'],
23		'params' => [
24			'type' => [
25				'name' => tra('Display type'),
26				'description' => tra('If set to "cloud", links are displayed as a cloud.') . " " . tr('Default: "list".'),
27				'filter' => 'word'
28			],
29			'max' => [
30				'name' => tra('Maximum elements'),
31				'description' => tra('If set to a number, limits the number of tags displayed.') . " " . tr('Default: 10.'),
32				'filter' => 'int'
33			],
34			'where' => [
35				'required' => false,
36				'name' => tra('Object type'),
37				'description' => tra('Type of objects to extract. Set to All to find all types.'),
38				'filter' => 'text',
39				'default' => null,
40				'options' => [
41					['text' => tra('All'), 'value' => ''],
42					['text' => tra('Same'), 'value' => 'all'],
43					['text' => tra('Wiki Pages'), 'value' => 'wiki page'],
44					['text' => tra('Blog Posts'), 'value' => 'blog post'],
45					['text' => tra('Article'), 'value' => 'article'],
46					['text' => tra('Directory'), 'value' => 'directory'],
47					['text' => tra('Faqs'), 'value' => 'faq'],
48					['text' => tra('File Galleries'), 'value' => 'file gallery'],
49					['text' => tra('Files'), 'value' => 'file'],
50					['text' => tra('Polls'), 'value' => 'poll'],
51					['text' => tra('Quizzes'), 'value' => 'quiz'],
52					['text' => tra('Surveys'), 'value' => 'survey'],
53					['text' => tra('Trackers'), 'value' => 'tracker'],
54				],
55			],
56			'objectId' => [
57				'required' => false,
58				'name' => tra('BlogId'),
59				'description' => tra('Blog Id if only blog posts selected. More than one blog can be provided, separated by colon. Example: 1:5'),
60				'default' => null,
61				'profile_reference' => 'blog',
62			],
63		],
64		'common_params' => ['rows'] // This is not clean. We should use just max instead of max and rows as fallback,
65	];
66}
67
68/**
69 * @param $mod_reference
70 * @param $module_params
71 */
72function module_freetags_most_popular($mod_reference, $module_params)
73{
74	$smarty = TikiLib::lib('smarty');
75	$globalperms = Perms::get();
76	if ($globalperms->view_freetags) {
77		$freetaglib = TikiLib::lib('freetag');
78		$most_popular_tags = $freetaglib->get_most_popular_tags('', 0, empty($module_params['max']) ? $mod_reference["rows"] : $module_params['max'], empty($module_params['where']) ? '' : $module_params['where'], empty($module_params['objectId']) ? '' : $module_params['objectId']);
79		$smarty->assign_by_ref('most_popular_tags', $most_popular_tags);
80		$smarty->assign('type', (isset($module_params['type']) && $module_params['type'] == 'cloud') ? 'cloud' : 'list');
81	}
82}
83