forked from getkirby-v2/tagcloud-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagcloud.php
More file actions
62 lines (50 loc) · 1.36 KB
/
Copy pathtagcloud.php
File metadata and controls
62 lines (50 loc) · 1.36 KB
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
<?php
/**
* Tagcloud plugin
*
* @author Bastian Allgeier <bastian@getkirby.com>
* @version 2.0.0
*/
function tagcloud($parent, $options = array()) {
// default values
$defaults = array(
'limit' => false,
'field' => 'tags',
'children' => 'visible',
'baseurl' => $parent->url(),
'param' => 'tag',
'sort' => 'results',
'sortdir' => 'desc'
);
// merge defaults and options
$options = array_merge($defaults, $options);
switch($options['children']) {
case 'invisible':
$children = $parent->children()->invisible();
break;
case 'visible':
$children = $parent->children()->visible();
break;
default:
$children = $parent->children();
break;
}
$tags = $children->pluck($options['field'], ',');
$tags = array_count_values($tags);
$cloud = array();
$ds = DS == '/' ? ':' : ';';
foreach($tags as $tag => $count) {
$cloud[$tag] = new Obj(array(
'results' => $count,
'name' => $tag,
'url' => $options['baseurl'] . '/' . $options['param'] . $ds . urlencode($tag),
'isActive' => urldecode(param($options['param'])) == $tag
));
}
$cloud = new Collection($cloud);
$cloud = $cloud->sortBy($options['sort'], $options['sortdir']);
if($options['limit']) {
$cloud = $cloud->limit($options['limit']);
}
return $cloud;
}