-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
93 lines (72 loc) · 3 KB
/
plugin.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
<?php
/**
This is the AuthorWidget plugin.
This file contains the AuthorWidget plugin. It provides a widget that lists
all available authors.
@package urlaube\authorwidget
@version 0.1a3
@author Yahe <[email protected]>
@since 0.1a0
*/
// ===== DO NOT EDIT HERE =====
// prevent script from getting called directly
if (!defined("URLAUBE")) { die(""); }
class AuthorWidget extends BaseSingleton implements Plugin {
// RUNTIME FUNCTIONS
public static function plugin() {
$result = null;
$authors = [];
if (!getcache(null, $authors, static::class)) {
callcontent(null, true, true,
function ($content) use (&$authors) {
$result = null;
// check that $content is not hidden
if (!istrue(value($content, HidePlugin::HIDDEN))) {
// check that $content is not hidden from author
if (!istrue(value($content, HidePlugin::HIDDENFROMAUTHOR))) {
// check that $content is not a relocation
if (null === value($content, RelocatePlugin::RELOCATE)) {
// read the author
$authorvalue = value($content, AUTHOR);
if (null !== $authorvalue) {
// make sure that only valid characters are contained
if (1 === preg_match("~^[0-9A-Za-z\_\-]+$~", $authorvalue)) {
$authorvalue = strtolower($authorvalue);
if (isset($authors[$authorvalue])) {
$authors[$authorvalue]++;
} else {
$authors[$authorvalue] = 1;
}
}
}
}
}
}
return null;
});
setcache(null, $authors, static::class);
}
if (0 < count($authors)) {
// sort the authors
ksort($authors);
$content = fhtml("<div>".NL);
foreach ($authors as $key => $value) {
$metadata = new Content();
$metadata->set(AUTHOR, $key);
$content .= fhtml(" <span class=\"glyphicon glyphicon-user\"></span> <a href=\"%s\">%s</a> (%d)".BR.NL,
AuthorHandler::getUri($metadata),
str_replace("_", SP, $key),
$value);
}
$content .= fhtml("</div>");
$result = new Content();
$result->set(CONTENT, $content);
$result->set(TITLE, t("Autoren", static::class));
}
return $result;
}
}
// register plugin
Plugins::register(AuthorWidget::class, "plugin", ON_WIDGETS);
// register translation
Translate::register(__DIR__.DS."lang".DS, AuthorWidget::class);