Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_textile
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2227/serendipity_event_textile
Added Files:
serendipity_event_textile.php textile.php
Log Message:
Added markup plugins
--- NEW FILE: serendipity_event_textile.php ---
<?php # $Id: serendipity_event_textile.php,v 1.1 2004/02/26 11:29:11 garvinhicking Exp $
require_once dirname(__FILE__) . '/textile.php';
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_EVENT_TEXTILE_NAME', 'Textformatierung: Textile');
@define('PLUGIN_EVENT_TEXTILE_DESC', 'Textile-Formatierung durchführen');
@define('PLUGIN_EVENT_TEXTILE_TRANSFORM', '<a href="http://www.textism.com/tools/textile/">Textile</a>-Formatierung erlaubt');
break;
case 'en':
default:
@define('PLUGIN_EVENT_TEXTILE_NAME', 'Markup: Textile');
@define('PLUGIN_EVENT_TEXTILE_DESC', 'Parse all output through the Textile converter');
@define('PLUGIN_EVENT_TEXTILE_TRANSFORM', '<a href="http://www.textism.com/tools/textile/">Textile</a>-formatting allowed');
break;
}
class serendipity_event_textile extends serendipity_event
{
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_TEXTILE_NAME);
$propbag->add('description', PLUGIN_EVENT_TEXTILE_DESC);
$propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
$propbag->add('preserve_tags',
array(
'php',
'output',
'name'
)
);
$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 generate_content(&$title) {
$title = PLUGIN_EVENT_TEXTILE_NAME;
}
function introspect_config_item($name, &$propbag)
{
$propbag->add('type', 'boolean');
$propbag->add('name', $name);
$propbag->add('description', sprintf(APPLY_MARKUP_TO, $name));
return true;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
$preserve_tags = &$bag->get('preserve_tags');
foreach ($this->markup_elements as $temp) {
if ($this->get_config($temp['name']) == 'true') {
$element = $temp['element'];
/* find all the tags and store them in $blocks */
$blocks = array();
foreach($preserve_tags as $tag) {
if (preg_match_all('/(<'.$tag.'[^>]?>.*<\/'.$tag.'>)/msU', $eventData[$element], $matches )) {
foreach($matches[1] as $match) {
$blocks[] = $match;
}
}
}
/* replace all the blocks with some code */
foreach($blocks as $id=>$block) {
$eventData[$element] = str_replace($block, '@BLOCK::'.$id.'@', $eventData[$element]);
}
/* textile it */
$eventData[$element] = textile($eventData[$element]);
/* each block will now be "<code>BLOCK::2</code>"
* so look for those place holders and replace
* them with the original blocks */
if (preg_match_all('/<code>BLOCK::(\d+)<\/code>/', $eventData[$element], $matches )) {
foreach($matches[1] as $key=>$match) {
$eventData[$element] = str_replace($matches[0][$key], $blocks[$match], $eventData[$element]);
}
}
/* post-process each block */
foreach($preserve_tags as $tag) {
$method = '_process_tag_' . $tag;
if (method_exists($this,$method)) {
if (preg_match_all('/<'.$tag.'[^>]?>(.*)<\/'.$tag.'>/msU', $eventData[$element], $matches )) {
foreach($matches[1] as $key=>$match) {
$eventData[$element] = str_replace($matches[0][$key], $this->$method($match), $eventData[$element]);
}
}
}
}
/* end textile processing */
}
}
return true;
case 'frontend_comment':
if ($this->get_config(COMMENT) != 'false') {
echo PLUGIN_EVENT_TEXTILE_TRANSFORM . '<br />';
}
return true;
break;
default:
return false;
}
} else {
return false;
}
}
function _process_tag_php($text) {
$code = "<?php\n" . trim($text) . "\n?>";
# Using OB, as highlight_string() only supports
# returning the result from 4.2.0
ob_start();
highlight_string($code);
$highlighted = ob_get_contents();
ob_end_clean();
# Fix output to use CSS classes and wrap well
$highlighted = '<p><div class="phpcode">' . str_replace(
array(
' ',
'<br />',
'<font color="',
'</font>',
"\n ",
'Ê '
),
array(
' ',
"<br />\n",
'<span class="',
'</span>',
"\n ",
' '
),
$highlighted
) . '</div></p>';
return $highlighted;
}
function _process_tag_output($text) {
return '<p><pre class="output">' . $text . '</pre></p>';
}
function _process_tag_name($text) {
return '<a name="'. $text . '"></a>';
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: textile.php ---
<?php
/*
This is Textile
A Humane Web Text Generator
Version 2.0 beta
8 July, 2003
Copyright (c) 2003, Dean Allen, www.textism.com
All rights reserved.
_______
LICENSE
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
[...1058 lines suppressed...]
$arr[]=
array('name'=>$atnm,'whole'=>$atnm.'="'.$match[1].'"',
'att'=>$match[1]);
$ok = 1; $mode = 0;
$attr = preg_replace("/^\w+(\s+|$)/", '', $attr);
}
break;
}
if ($ok == 0){
$attr = preg_replace('/^\S*\s*/', '', $attr);
$mode = 0;
}
}
if ($mode == 1) $arr[] =
array ('name'=>$atnm,'whole'=>$atnm.'="'.$atnm.'"','att'=>$atnm);
return $arr;
}
?>
|