forked from XoopsModules25x/tag
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
105 lines (87 loc) · 4.17 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* XOOPS tag management module
*
* @copyright {@link https://xoops.org/ The XOOPS Project}
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
* @author Taiwen Jiang <phppp@users.sourceforge.net>
* @since 1.00
*/
use XoopsModules\Tag\Common;
use XoopsModules\Tag\Utility;
require_once __DIR__ . '/header.php';
$page_title = sprintf(_MD_TAG_TAGLIST, $GLOBALS['xoopsConfig']['sitename']);
$GLOBALS['xoopsOption']['template_main'] = 'tag_index.tpl';
$GLOBALS['xoopsOption']['xoops_pagetitle'] = strip_tags($page_title);
require_once $GLOBALS['xoops']->path('header.php');
$GLOBALS['xoTheme']->addStylesheet('browse.php?modules/' . $moduleDirName . '/assets/css/style.css');
/**
* @var \XoopsModules\Tag\Helper $helper
* @var \XoopsModules\Tag\TagHandler $tagHandler
*/
$tagHandler = $helper->getHandler('Tag');
$tag_config = Utility::tag_load_config();
Utility::tag_define_url_delimiter();
$limit = empty($tag_config['limit_tag_list']) ? 100 : $tag_config['limit_tag_list'];
$criteria = new \CriteriaCompo();
$criteria->setSort('count');
$criteria->order = 'DESC'; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method
/** @todo determine if the following call should use $limit as first param to reduce # of returned tags */
$tags_array = $tagHandler->getByLimit($limit, 0, $criteria, null, false);
$tags_term_array = [];
// set min and max tag count
$count_array = array_column($tags_array, 'count', 'id');
$count_min = count($count_array) > 0 ? min($count_array) : 0;
$count_min = max($count_min, 0);
$count_max = count($count_array) > 0 ? max($count_array) : 0;
$count_max = max($count_max, 0);
$term_array = array_column($tags_array, 'term', 'id');
$tags_term_array = array_map('\mb_strtolower', $term_array);
array_multisort($tags_term_array, SORT_ASC, $tags_array);
$count_interval = $count_max - $count_min;
$level_limit = 5;
$font_max = $tag_config['font_max'];
$font_min = $tag_config['font_min'];
$font_ratio = $count_interval ? ($font_max - $font_min) / $count_interval : 1;
$tags_data_array = [];
foreach ($tags_array as $tag) {
/*
* Font-size = ((tag.count - count.min) * (font.max - font.min) / (count.max - count.min) ) * 100%
*/
$tags_data_array[] = [
'id' => $tag['id'],
'font' => empty($count_interval) ? 100 : floor(($tag['count'] - $count_min) * $font_ratio) + $font_min,
'level' => empty($count_max) ? 0 : floor(($tag['count'] - $count_min) * $level_limit / $count_max),
'term' => urlencode($tag['term']),
'title' => htmlspecialchars($tag['term'], ENT_QUOTES | ENT_HTML5),
'count' => $tag['count'],
];
}
unset($tags_array, $count_array, $term_array, $tags_term_array);
// Breadcrumb
$breadcrumb = new Common\Breadcrumb();
$breadcrumb->addLink($helper->getModule()->getVar('name'));
$GLOBALS['xoopsTpl']->assign(
[
'module_name' => $GLOBALS['xoopsModule']->getVar('name'),
'lang_jumpto' => _MD_TAG_JUMPTO,
'pagenav' => '<a href="' . $helper->url('list.tag.php') . '">' . _MORE . "</a>\n",
'tag_page_title' => $page_title,
'tag_breadcrumb' => $breadcrumb->render(),
// Loading module meta data, NOT THE RIGHT WAY DOING IT
'xoops_pagetitle' => $GLOBALS['xoopsOption']['xoops_pagetitle'],
//'xoops_module_header' => $GLOBALS['xoopsOption']['xoops_module_header'],
'xoops_meta_description' => $GLOBALS['xoopsOption']['xoops_pagetitle'],
]
);
//@todo figure out why $tags_data_array is using assign_by_ref
$GLOBALS['xoopsTpl']->assign_by_ref('tags', $tags_data_array);
require_once __DIR__ . '/footer.php';