2007-10-02 05:21:38 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage misc
|
|
|
|
*/
|
2007-10-02 05:21:38 +02:00
|
|
|
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2007-10-02 05:21:38 +02:00
|
|
|
require_once('HTML/HTMLBBCodeParser.php');
|
|
|
|
/*Seting up the PEAR bbcode parser*/
|
|
|
|
$config = parse_ini_file('BBCodeParser.ini', true);
|
|
|
|
$options = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
|
|
|
|
$options = $config['SSHTMLBBCodeParser'];
|
|
|
|
//Debug::show($options);
|
|
|
|
unset($options);
|
|
|
|
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* BBCode parser object.
|
|
|
|
* Use on a text field in a template with $Content.Parse(BBCodeParser).
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage misc
|
2008-01-08 07:37:50 +01:00
|
|
|
*/
|
2007-10-02 05:21:38 +02:00
|
|
|
class BBCodeParser extends TextParser {
|
|
|
|
|
|
|
|
protected static $autolinkUrls = true;
|
|
|
|
|
|
|
|
static function autolinkUrls() {
|
|
|
|
return (self::$autolinkUrls != null) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function disable_autolink_urls($autolink = false) {
|
|
|
|
BBCodeParser::$autolinkUrls = $autolink;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function usable_tags() {
|
|
|
|
return new DataObjectSet(
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.BOLD', 'Bold Text'),
|
|
|
|
"Example" => '[b]<b>'._t('BBCodeParser.BOLDEXAMPLE', 'Bold').'</b>[/b]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.ITALIC', 'Italic Text'),
|
|
|
|
"Example" => '[i]<i>'._t('BBCodeParser.ITALICEXAMPLE', 'Italics').'</i>[/i]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.UNDERLINE', 'Underlined Text'),
|
|
|
|
"Example" => '[u]<u>'._t('BBCodeParser.UNDERLINEEXAMPLE', 'Underlined').'</u>[/u]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.STRUCK', 'Struck-out Text'),
|
|
|
|
"Example" => '[s]<s>'._t('BBCodeParser.STRUCKEXAMPLE', 'Struck-out').'</s>[/s]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.COLORED', 'Colored text'),
|
|
|
|
"Example" => '[color=blue]'._t('BBCodeParser.COLOREDEXAMPLE', 'blue text').'[/color]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.ALIGNEMENT', 'Alignment'),
|
|
|
|
"Example" => '[align=right]'._t('BBCodeParser.ALIGNEMENTEXAMPLE', 'right aligned').'[/align]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
|
|
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
|
|
|
"Example" => '[url]http://www.website.com/[/url]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
|
|
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
2007-10-02 05:21:38 +02:00
|
|
|
"Example" => "[url=http://www.website.com/]Some website[/url]"
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
|
|
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
2007-10-02 05:21:38 +02:00
|
|
|
"Example" => "[email]you@yoursite.com[/email]"
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
|
|
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
2007-10-02 05:21:38 +02:00
|
|
|
"Example" => "[email=you@yoursite.com]email me[/email]"
|
|
|
|
)),
|
|
|
|
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.IMAGE', 'Image'),
|
|
|
|
"Description" => _t('BBCodeParser.IMAGEDESCRIPTION', 'Show an image in your post'),
|
2007-10-02 05:21:38 +02:00
|
|
|
"Example" => "[img]http://www.website.com/image.jpg[/img]"
|
|
|
|
)),
|
|
|
|
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.CODE', 'Code Block'),
|
|
|
|
"Description" => _t('BBCodeParser.CODEDESCRIPTION', 'Unformatted code block'),
|
|
|
|
"Example" => '[code]'._t('BBCodeParser.CODEEXAMPLE', 'Code block').'[/code]'
|
2007-10-02 05:21:38 +02:00
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
2008-01-10 04:28:13 +01:00
|
|
|
"Title" => _t('BBCodeParser.UNORDERED', 'Unordered list'),
|
|
|
|
"Description" => _t('BBCodeParser.UNORDEREDDESCRIPTION', 'Unordered list'),
|
|
|
|
"Example" => '[ulist][*]'._t('BBCodeParser.UNORDEREDEXAMPLE1', 'unordered item 1').'[*]'._t('BBCodeParser.UNORDEREDEXAMPLE2', 'unordered item 2').'[/ulist]'
|
2007-10-02 05:21:38 +02:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function useable_tagsHTML(){
|
|
|
|
$useabletags = "<ul class='bbcodeExamples'>";
|
|
|
|
foreach($this->usable_tags()->toArray() as $tag){
|
|
|
|
$useabletags = $useabletags."<li><span>".$tag->Example."</span></li>";
|
|
|
|
}
|
|
|
|
return $useabletags."</ul>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse() {
|
|
|
|
$this->content = str_replace(array('&', '<', '>'), array('&', '<', '>'), $this->content);
|
|
|
|
$this->content = SSHTMLBBCodeParser::staticQparse($this->content);
|
|
|
|
$this->content = "<p>".$this->content."</p>";
|
|
|
|
$this->content = str_replace("\n\n", "</p><p>", $this->content);
|
|
|
|
$this->content = str_replace("\n", "<br />", $this->content);
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|