-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
84 lines (66 loc) · 2.3 KB
/
plugin.php
File metadata and controls
84 lines (66 loc) · 2.3 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
<?php
/**
This is the ReadMore plugin.
This file contains the ReadMore plugin. It generates a
read-more link on overview pages so that they are not
getting too long.
@package urlaube\readmore
@version 0.1a1
@author Yahe <hello@yahe.sh>
@since 0.1a0
*/
// ===== DO NOT EDIT HERE =====
// prevent script from getting called directly
if (!defined("URLAUBE")) { die(""); }
class ReadMore extends BaseSingleton implements Plugin {
// HELPER FUNCTIONS
protected static function getReadOnlyLink($content, $uri) {
$result = $content;
if (is_string($result)) {
if ((ErrorHandler::class !== Handlers::getActive()) &&
(FeedHandler::class !== Handlers::getActive()) &&
(PageHandler::class !== Handlers::getActive())) {
// generate form source code
$link = tfhtml(NL.
"<p><a href=\"%s\"><strong>%s</strong></a></p>".NL,
ReadMore::class,
$uri,
"Mehr lesen »");
$pos = stripos($result, "[readmore]");
if (false !== $pos) {
$result = substr($result, 0, $pos);
$result .= $link;
}
} else {
// replace shortcode with nothing
$result = str_ireplace("[readmore]", "", $result);
}
}
return $result;
}
// RUNTIME FUNCTIONS
public static function plugin($content) {
$result = $content;
if ($result instanceof Content) {
if ($result->isset(CONTENT)) {
$result->set(CONTENT, static::getReadOnlyLink(value($result, CONTENT), value($result, URI)));
}
} else {
if (is_array($result)) {
// iterate through all content items
foreach ($result as $result_item) {
if ($result_item instanceof Content) {
if ($result_item->isset(CONTENT)) {
$result_item->set(CONTENT, static::getReadOnlyLink(value($result_item, CONTENT), value($result_item, URI)));
}
}
}
}
}
return $result;
}
}
// register plugin
Plugins::register(ReadMore::class, "plugin", FILTER_CONTENT);
// register translation
Translate::register(__DIR__.DS."lang".DS, ReadMore::class);