-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
103 lines (80 loc) · 3.55 KB
/
plugin.php
File metadata and controls
103 lines (80 loc) · 3.55 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
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
<?php
/**
This is the CategoryWidget plugin.
This file contains the CategoryWidget plugin. It provides a widget that
lists all available categories.
@package urlaube\categorywidget
@version 0.1a10
@author Yahe <hello@yahe.sh>
@since 0.1a0
*/
// ===== DO NOT EDIT HERE =====
// prevent script from getting called directly
if (!defined("URLAUBE")) { die(""); }
class CategoryWidget extends BaseSingleton implements Plugin {
// RUNTIME FUNCTIONS
public static function plugin() {
$result = null;
$categories = [];
if (!getcache(null, $categories, static::class)) {
callcontent(null, true, true,
function ($content) use (&$categories) {
$result = null;
// check that $content is not hidden
if (!istrue(value($content, HidePlugin::HIDDEN))) {
// check that $content is not hidden from category
if (!istrue(value($content, HidePlugin::HIDDENFROMCATEGORY))) {
// check that $content is not a relocation
if (null === value($content, RelocatePlugin::RELOCATE)) {
// read the category
$catvalue = value($content, CATEGORY);
if (null !== $catvalue) {
$seen = [];
$catvalue = explode(SP, $catvalue);
foreach ($catvalue as $catvalue_item) {
// make sure that only valid characters are contained
if (1 === preg_match("~^[0-9A-Za-z\_\-]+$~", $catvalue_item)) {
$catvalue_item = strtolower($catvalue_item);
// only count each category once per content
if (!isset($seen[$catvalue_item])) {
$seen[$catvalue_item] = null;
if (isset($categories[$catvalue_item])) {
$categories[$catvalue_item]++;
} else {
$categories[$catvalue_item] = 1;
}
}
}
}
}
}
}
}
return null;
});
setcache(null, $categories, static::class);
}
if (0 < count($categories)) {
// sort the categories
ksort($categories);
$content = fhtml("<div>".NL);
foreach ($categories as $key => $value) {
$metadata = new Content();
$metadata->set(CATEGORY, $key);
$content .= fhtml(" <span class=\"glyphicon glyphicon-tag\"></span> <a href=\"%s\">%s</a> (%d)".BR.NL,
CategoryHandler::getUri($metadata),
str_replace("_", SP, $key),
$value);
}
$content .= fhtml("</div>");
$result = new Content();
$result->set(CONTENT, $content);
$result->set(TITLE, t("Kategorien", static::class));
}
return $result;
}
}
// register plugin
Plugins::register(CategoryWidget::class, "plugin", ON_WIDGETS);
// register translation
Translate::register(__DIR__.DS."lang".DS, CategoryWidget::class);