Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_bbcode
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27495/plugins/serendipity_event_bbcode
Modified Files:
serendipity_event_bbcode.php
Log Message:
Patch from Jez Hancock to make bbcode plugin reformat code/php block items.
Index: serendipity_event_bbcode.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- serendipity_event_bbcode.php 10 Jul 2004 08:24:10 -0000 1.6
+++ serendipity_event_bbcode.php 2 Sep 2004 12:44:37 -0000 1.7
@@ -24,7 +24,7 @@
$propbag->add('name', PLUGIN_EVENT_BBCODE_NAME);
$propbag->add('description', PLUGIN_EVENT_BBCODE_DESC);
- $propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
+ $propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true, 'css' => true));
$this->markup_elements = array(
array(
@@ -61,10 +61,6 @@
'/(?<!\\\\)\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si' => "<span style=\"text-decoration:underline\">\\1</span>",
'/(?<!\\\\)\[center(?::\w+)?\](.*?)\[\/center(?::\w+)?\]/si' => "<div style=\"text-align:center\">\\1</div>",
- // [code] & [php]
- '/(?<!\\\\)\[code(?::\w+)?\](.*?)\[\/code(?::\w+)?\]/si' => "<div class=\"bb-code\">\\1</div>",
- '/(?<!\\\\)\[php(?::\w+)?\](.*?)\[\/php(?::\w+)?\]/si' => "<div class=\"bb-php\">\\1</div>",
-
// [email]
'/(?<!\\\\)\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"bb-email\">\\1</a>",
'/(?<!\\\\)\[email(?::\w+)?=(.*?)\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"bb-email\">\\2</a>",
@@ -79,8 +75,8 @@
'/(?<!\\\\)\[img(?::\w+)?=(.*?)x(.*?)\](.*?)\[\/img(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" alt=\"\\3\" class=\"bb-image\" />",
// [quote]
- '/(?<!\\\\)\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si' => "<div>Quote:<div class=\"bb-quote\">\\1</div></div>",
- '/(?<!\\\\)\[quote(?::\w+)?=(?:"|"|\')?(.*?)["\']?(?:"|"|\')?\](.*?)\[\/quote\]/si' => "<div>Quote \\1:<div class=\"bb-quote\">\\2</div></div>",
+ '/(?<!\\\\)\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si' => "<div class=\"bb-code-title\">QUOTE:<div class=\"bb-code\">\\1</div></div>",
+ '/(?<!\\\\)\[quote(?::\w+)?=(?:"|"|\')?(.*?)["\']?(?:"|"|\')?\](.*?)\[\/quote\]/si' => "<div class=\"bb-code-title\">QUOTE \\1:<div class=\"bb-code\">\\2</div></div>",
// [list]
'/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*<br\s*\/?>\s*)?\[\*|(?:\s*<br\s*\/?>\s*)?\[\/?list)/si' => "\n<li class=\"bb-listitem\">\\1</li>",
@@ -102,6 +98,56 @@
}
+ 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 = "<?php\n\n$input\n\n?>";
+ }
+
+ ob_start();
+ highlight_string($input);
+ $input = ob_get_contents();
+ ob_end_clean();
+
+ $input = str_replace('<br />', "\n", $input);
+ break;
+
+ default:
+ return false;
+ }
+
+ $input = "<div class=\"bb-$type-title\">" . strtoupper($type) . ":</div>"
+ . "<div class=\"bb-$type\">$input</div>";
+ return($input);
+ }
+
function generate_content(&$title) {
$title = PLUGIN_EVENT_BBCODE_NAME;
}
@@ -113,14 +159,18 @@
$propbag->add('name', $name);
$propbag->add('description', sprintf(APPLY_MARKUP_TO, $name));
$propbag->add('default', 'true');
-
return true;
}
function bbcode($input) {
/* Regular expressions taken from http://smarty.incutio.com/?page=BBCodePlugin Wiki (Andre Rabold) */
- return preg_replace(array_keys($this->bbcodes), array_values($this->bbcodes), $input);
-}
+ $input = preg_replace(array_keys($this->bbcodes), array_values($this->bbcodes), $input);
+
+ // [code] & [php]
+ $input = preg_replace_callback('/(?<!\\\\)\[(code|php)(?::\w+)?\](.*?)\[\/\\1(?::\w+)?\]/si', array($this, 'bbcode_callback'), $input);
+ return $input;
+
+ }
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
@@ -147,6 +197,28 @@
return true;
break;
+ case 'css':
+ if (stristr('.bb-code', $addData)) {
+ // class exists in CSS, so a user has customized it and we don't need default
+ return true;
+ }
+?>
+ .bb-code, .bb-php, .bb-code-title, .bb-php-title {
+ margin-left: 20px;
+ margin-right: 20px;
+ color: black;
+}
+
+.bb-code-title, .bb-php-title {
+ margin-bottom: 2px;
+ background-color:#CCCCCC;
+ font-weight: bold;
+ padding-left: 5px;
+}
+<?php
+ return true;
+ break;
+
default:
return false;
}
@@ -157,4 +229,4 @@
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
|