add('name', PLUGIN_EVENT_BBCODE_NAME);
$propbag->add('description', PLUGIN_EVENT_BBCODE_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Jez Hancock, Garvin Hicking');
$propbag->add('version', '2.09');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'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, 'css' => 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();
$conf_array[] = 'info';
$conf_array[] = 'target';
foreach($this->markup_elements as $element) {
$conf_array[] = $element['name'];
}
$propbag->add('configuration', $conf_array);
}
function bbcode_callback($matches) {
$type = $matches[1];
$input = trim($matches[2], "\r\n");
switch ($type) {
case 'code':
$search_replace = array(
'&' => '&',
' ' => ' ',
'<' => '<',
'<' => '<',
'>' => '>',
'>' => '>',
'"' => '"',
':' => ':',
'[' => '[',
']' => ']',
')' => ')',
'(' => '(',
'*' => '*',
'\t' => ' ',
'\\"' => '"',
"\\'" => "'"
);
$input = strtr($input, $search_replace);
break;
case 'php':
if (substr($input, 0, 2) != '') {
$input = "";
}
ob_start();
highlight_string($input);
$input = ob_get_contents();
ob_end_clean();
$input = str_replace('
', "\n", $input);
break;
default:
return false;
}
$input = "
" . strtoupper($type) . ":
"
. "$input
";
return($input);
}
function generate_content(&$title) {
$title = $this->title;
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'target':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_BBCODE_TARGET);
$propbag->add('default', 'false');
break;
case 'info':
$propbag->add('type', 'info');
$propbag->add('description', PLUGIN_EVENT_BBCODE_TRANSFORM);
break;
default:
$propbag->add('type', 'boolean');
$propbag->add('name', constant($name));
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
$propbag->add('default', 'true');
break;
}
return true;
}
function install() {
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function uninstall() {
serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function bbcode($input) {
static $bbcodes = null;
// Only allow numbers and characters for CSS: "red", "#FF0000", ...
static $pattern_css = '([ 0-9a-z#-]+?)';
// Only allow strings occuring in emails: .-_@, 0-9, a-z
static $pattern_mail = '([\.\-\+~@_0-9a-z]+?)';
// Only allow strings occuring in URLs: &;?:.-_@/, 0-9, a-z
static $pattern_url = '([@!=~\?:&;0-9a-z#\.\-_\/,%\+]+?)';
// Disallow possibly evil HTML characters which may lead to Javascript XSS: '"();
static $pattern_query = '([^"\'\(\);]+?)';
static $target = null;
if ($target === null) {
$target = serendipity_db_bool($this->get_config('target'));
}
// Note:
// * Anything between ... tags will be caught by htmlspecialchars() and disallows custom HTML tags.
// * (?::\w+)? means "non capturing" match on any word character.
// * (? "\\2",
'/(? "\\2",
'/(? "\\2",
'/(? "\\2
",
'/(? "\\1",
'/(? "\\1",
'/(? "\\1",
'/(? "\\1
",
'/(? "\\1",
// [email]
'/(? "\\1",
'/(? "\\2",
// [url]
'/(? "\\2",
'/(? "\\1",
'/(? "\\1",
'/(? "\\2",
// [img]
'/(? "
",
'/(? "
",
// [quote]
'/(? "QUOTE:
\\1
",
'/(? "QUOTE \\1:
\\2
",
// [list]
'/(?\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*
\s*)?\[\*|(?:\s*
\s*)?\[\/?list)/si' => "\n\\1",
'/(?\s*)?\[\/list(:(?!u|o)\w+)?\](?:
)?/si' => "\n",
'/(?\s*)?\[\/list:u(:\w+)?\](?:
)?/si' => "\n",
'/(?\s*)?\[\/list:o(:\w+)?\](?:
)?/si' => "\n",
'/(?\s*)?\[list(:(?!u|o)\w+)?\]\s*(?:
)?/si' => "\n",
'/(?\s*)?\[list:u(:\w+)?\]\s*(?:
)?/si' => "\n",
'/(?\s*)?\[list:o(:\w+)?\]\s*(?:
)?/si' => "\n",
'/(?\s*)?\[list(?::o)?(:\w+)?=1\]\s*(?:
)?/si' => "\n",
'/(?\s*)?\[list(?::o)?(:\w+)?=i\]\s*(?:
)?/s' => "\n",
'/(?\s*)?\[list(?::o)?(:\w+)?=I\]\s*(?:
)?/s' => "\n",
'/(?\s*)?\[list(?::o)?(:\w+)?=a\]\s*(?:
)?/s' => "\n",
'/(?\s*)?\[list(?::o)?(:\w+)?=A\]\s*(?:
)?/s' => "\n",
// escaped tags like \[b], \[color], \[url], ...
'/\\\\(\[\/?\w+(?::\w+)*\])/' => "\\1"
);
}
/* Regular expressions taken from http://smarty.incutio.com/?page=BBCodePlugin Wiki (Andre Rabold) */
$input = preg_replace(array_keys($bbcodes), array_values($bbcodes), $input);
// [code] & [php]
$input = preg_replace_callback('/(?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] &&
!isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
$element = $temp['element'];
$eventData[$element] = $this->bbcode($eventData[$element]);
}
}
return true;
break;
case 'frontend_comment':
if (serendipity_db_bool($this->get_config('COMMENT', true))) {
echo '';
}
return true;
break;
case 'css':
if (strpos($eventData, '.bb-code') !== false) {
// class exists in CSS, so a user has customized it and we don't need default
return true;
}
?>
.bb-quote, .bb-code, .bb-php, .bb-code-title, .bb-php-title {
margin-left: 20px;
margin-right: 20px;
color: black;
direction: ltr;
}
.bb-code-title, .bb-php-title {
margin-bottom: 2px;
background-color:#CCCCCC;
font-weight: bold;
padding-left: 5px;
}
.bb-code, .bb-php {
font-family: courier, "courier new";
background-color: #DDDDDD;
padding: 10px;
white-space: pre;
overflow: auto;
max-height: 24em;
}
.bb-quote {
background-color: #DDDDDD;
padding: 10px;
}
.bb-list-ordered-d {
list-style-type: decimal;
}
.bb-list-ordered-la {
list-style-type: lower-alpha;
}
.bb-list-ordered-ua {
list-style-type: upper-alpha;
}