/
serendipity_event_s9ymarkup.php
146 lines (121 loc) · 4.79 KB
/
serendipity_event_s9ymarkup.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
@serendipity_plugin_api::load_language(dirname(__FILE__));
class serendipity_event_s9ymarkup extends serendipity_event
{
var $title = PLUGIN_EVENT_S9YMARKUP_NAME;
var $markup_elements;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_S9YMARKUP_NAME);
$propbag->add('description', PLUGIN_EVENT_S9YMARKUP_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team');
$propbag->add('version', '1.4.2');
$propbag->add('requirements', array(
'serendipity' => '1.6',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('cachable_events', array('frontend_display' => true));
$propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
$propbag->add('groups', array('MARKUP'));
$this->markup_elements = array(
array(
'name' => 'ENTRY_BODY',
'element' => 'body',
),
array(
'name' => 'EXTENDED_BODY',
'element' => 'extended',
),
array(
'name' => 'COMMENT',
'element' => 'comment',
),
array(
'name' => 'HTML_NUGGET',
'element' => 'html_nugget',
)
);
$conf_array = array();
foreach($this->markup_elements as $element) {
$conf_array[] = $element['name'];
}
$propbag->add('configuration', $conf_array);
}
function install()
{
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function uninstall(&$propbag)
{
serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function generate_content(&$title)
{
$title = $this->title;
}
function introspect_config_item($name, &$propbag)
{
$propbag->add('type', 'boolean');
$propbag->add('name', constant($name));
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
$propbag->add('default', 'true');
return true;
}
function event_hook($event, &$bag, &$eventData, $addData = null)
{
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
foreach ($this->markup_elements as $temp) {
if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
! ($eventData['properties']['ep_disable_markup_' . $this->instance] ?? null) &&
!isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
$element = $temp['element'];
$eventData[$element] = $this->_s9y_markup($eventData[$element]);
}
}
break;
case 'frontend_comment':
if (serendipity_db_bool($this->get_config('COMMENT', true))) {
echo '<div class="serendipity_commentDirection serendipity_comment_s9ymarkup">' . PLUGIN_EVENT_S9YMARKUP_TRANSFORM . '</div>';
}
break;
default:
return false;
}
return true;
} else {
return false;
}
}
function _s9y_markup($text)
{
$text = str_replace('\_', chr(1), $text);
$text = preg_replace('/#([[:alnum:]]+?)#/','&\1;', $text);
$text = preg_replace('/\b\s_([\S ]+?)_\s\b/',' <u>\1</u> ', $text);
$text = str_replace(chr(1), '\_', $text);
// bold
$text = str_replace('\*',chr(1), $text);
$text = str_replace('**',chr(2), $text);
$text = preg_replace('/(\S)\*(\S)/','\1' . chr(1) . '\2', $text);
$text = preg_replace('/\B\*([^*]+)\*\B/','<strong>\1</strong>', $text);
$text = str_replace(chr(2),'**', $text);
$text = str_replace(chr(1),'\*', $text);
// $text = preg_replace('/\|([0-9a-fA-F]+?)\|([\S ]+?)\|/', '<font color="\1">\2</font>',$text);
$text = preg_replace('/\^([[:alnum:]]+?)\^/','<sup>\1</sup>', $text);
$text = preg_replace('/\@([[:alnum:]]+?)\@/','<sub>\1</sub>', $text);
$text = preg_replace('/([\\\])([*#_|^@%])/', '\2', $text);
return $text;
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>