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
|
<?php
/**
* This file implements the BBcode plugin for b2evolution
*
* BB style formatting, like [b]bold[/b]
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package plugins
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* Includes:
*/
require_once dirname(__FILE__).'/../renderer.class.php';
/**
* @package plugins
*/
class bbcode_Rendererplugin extends RendererPlugin
{
var $code = 'b2evBBco';
var $name = 'BB code';
var $priority = 50;
var $apply_when = 'opt-in';
var $apply_to_html = true;
var $apply_to_xml = true; // strip the BBcode
var $short_desc;
var $long_desc;
/**
* BBcode formatting search array
*
* @access private
*/
var $search = array(
'#\[b](.+?)\[/b]#is', // Formatting tags
'#\[i](.+?)\[/i]#is',
'#\[u](.+?)\[/u]#is',
'#\[s](.+?)\[/s]#is',
'!\[color=(#?[A-Za-z0-9]+?)](.+?)\[/color]!is',
'#\[size=([0-9]+?)](.+?)\[/size]#is',
'#\[font=([A-Za-z0-9 ;\-]+?)](.+?)\[/font]#is',
// The following are dangerous, until we security check resulting code.
// '#\[img](.+?)\[/img]#is', // Image
// '#\[url](.+?)\[/url]#is', // URL
// '#\[url=(.+?)](.+?)\[/url]#is',
// '#\[email](.+?)\[/email]#eis', // E-mail
// '#\[email=(.+?)](.+?)\[/email]#eis'
);
/**
* HTML replace array
*
* @access private
*/
var $replace = array(
'<strong>$1</strong>', // Formatting tags
'<em>$1</em>',
'<span style="text-decoration:underline">$1</span>',
'<span style="text-decoration:line-through">$1</span>',
'<span style="color:$1">$2</span>',
'<span style="font-size:$1px">$2</span>',
'<span style="font-family:$1">$2</span>',
// '<img src="$1" alt="" />', // Image
// '<a href="$1">$1</a>', // URL
// '<a href="$1" title="$2">$2</a>',
// '<a href=\"mailto:$1\">$1</a>', // E-mail
// '<a href="mailto:$1">$2</a>'
);
/**
* Constructor
*
* {@internal bbcode_Rendererplugin::bbcode_Rendererplugin(-)}}
*/
function bbcode_Rendererplugin()
{
$this->short_desc = T_('BB formatting e-g [b]bold[/b]');
$this->long_desc = T_('No description available');
}
/**
* Perform rendering
*
* {@internal BBcode::render(-)}}
*
* @param string content to render (by reference) / rendered content
* @param string Output format, see {@link format_to_output()}
* @return boolean true if we can render something for the required output format
*/
function render( & $content, $format )
{
if( ! parent::render( $content, $format ) )
{ // We cannot render the required format
return false;
}
$content = preg_replace( $this->search, $this->replace, $content );
return true;
}
}
// Register the plugin:
$this->register( new bbcode_Rendererplugin() );
?>
|