2008-09-26 04:22:51 +02:00
|
|
|
<?php
|
|
|
|
require_once('HTML/HTMLBBCodeParser.php');
|
2014-08-15 08:53:05 +02:00
|
|
|
/*Seting up the PEAR bbcode parser*/
|
2008-09-26 04:22:51 +02:00
|
|
|
$config = parse_ini_file('BBCodeParser.ini', true);
|
|
|
|
$options = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
|
|
|
|
$options = $config['SSHTMLBBCodeParser'];
|
|
|
|
//Debug::show($options);
|
|
|
|
unset($options);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BBCode parser object.
|
|
|
|
* Use on a text field in a template with $Content.Parse(BBCodeParser).
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-09-26 04:22:51 +02:00
|
|
|
* @subpackage misc
|
|
|
|
*/
|
|
|
|
class BBCodeParser extends TextParser {
|
|
|
|
|
2009-01-08 00:00:54 +01:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
|
|
|
* @var Boolean Set whether phrases starting with http:// or www. are automatically linked
|
2009-01-08 00:00:54 +01:00
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $autolink_urls = true;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-01-08 00:00:54 +01:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
|
|
|
* @var Boolean Set whether similies :), :(, :P are converted to images
|
2009-01-08 00:00:54 +01:00
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $allow_similies = false;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-01-08 00:00:54 +01:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
|
|
|
* @var string Set the location of the smiles folder. By default use the ones in framework
|
2009-01-08 00:00:54 +01:00
|
|
|
* but this can be overridden by setting BBCodeParser::set_icon_folder('themes/yourtheme/images/');
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $smilies_location = null;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.smilies_location" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function smilies_location() {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.smilies_location" config setting instead');
|
2012-03-24 04:38:57 +01:00
|
|
|
if(!BBCodeParser::$smilies_location) {
|
|
|
|
return FRAMEWORK_DIR . '/images/smilies';
|
|
|
|
}
|
2013-03-26 10:15:17 +01:00
|
|
|
return static::config()->smilies_location;
|
2009-01-08 00:00:54 +01:00
|
|
|
}
|
2013-03-21 19:48:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.smilies_location" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function set_icon_folder($path) {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.smilies_location" config setting instead');
|
2013-03-26 10:15:17 +01:00
|
|
|
static::config()->smilies_location = $path;
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.autolink_urls" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function autolinkUrls() {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.autolink_urls" config setting instead');
|
2013-03-26 10:15:17 +01:00
|
|
|
return static::config()->autolink_urls;
|
2008-09-26 04:22:51 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.autolink_urls" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function disable_autolink_urls($autolink = false) {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.autolink_urls" config setting instead');
|
2013-03-26 10:15:17 +01:00
|
|
|
static::config()->autolink_urls = $autolink;
|
2008-09-26 04:22:51 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.allow_smilies" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function smiliesAllowed() {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.allow_smilies" config setting instead');
|
2013-03-26 10:15:17 +01:00
|
|
|
return static::config()->allow_smilies;
|
2009-01-08 00:00:54 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.2 Use the "BBCodeParser.allow_smilies" config setting instead
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function enable_smilies() {
|
2013-03-21 19:48:54 +01:00
|
|
|
Deprecation::notice('3.2', 'Use the "BBCodeParser.allow_smilies" config setting instead');
|
2013-03-26 10:15:17 +01:00
|
|
|
static::config()->allow_similies = true;
|
2009-01-08 00:00:54 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function usable_tags() {
|
2011-05-05 12:40:24 +02:00
|
|
|
return new ArrayList(
|
2012-07-18 07:02:31 +02:00
|
|
|
array(
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.BOLD', 'Bold Text'),
|
|
|
|
"Example" => '[b]<b>'._t('BBCodeParser.BOLDEXAMPLE', 'Bold').'</b>[/b]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.ITALIC', 'Italic Text'),
|
|
|
|
"Example" => '[i]<i>'._t('BBCodeParser.ITALICEXAMPLE', 'Italics').'</i>[/i]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.UNDERLINE', 'Underlined Text'),
|
|
|
|
"Example" => '[u]<u>'._t('BBCodeParser.UNDERLINEEXAMPLE', 'Underlined').'</u>[/u]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.STRUCK', 'Struck-out Text'),
|
|
|
|
"Example" => '[s]<s>'._t('BBCodeParser.STRUCKEXAMPLE', 'Struck-out').'</s>[/s]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.COLORED', 'Colored text'),
|
|
|
|
"Example" => '[color=blue]'._t('BBCodeParser.COLOREDEXAMPLE', 'blue text').'[/color]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.ALIGNEMENT', 'Alignment'),
|
|
|
|
"Example" => '[align=right]'._t('BBCodeParser.ALIGNEMENTEXAMPLE', 'right aligned').'[/align]'
|
2014-08-15 08:53:05 +02:00
|
|
|
)),
|
2012-07-18 07:02:31 +02:00
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.CODE', 'Code Block'),
|
|
|
|
"Description" => _t('BBCodeParser.CODEDESCRIPTION', 'Unformatted code block'),
|
|
|
|
"Example" => '[code]'._t('BBCodeParser.CODEEXAMPLE', 'Code block').'[/code]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
|
|
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
|
|
|
"Example" => "[email]you@yoursite.com[/email]"
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
|
|
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
|
|
|
"Example" => "[email=you@yoursite.com]Email[/email]"
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.UNORDERED', 'Unordered list'),
|
|
|
|
"Description" => _t('BBCodeParser.UNORDEREDDESCRIPTION', 'Unordered list'),
|
|
|
|
"Example" => '[ulist][*]'._t('BBCodeParser.UNORDEREDEXAMPLE1', 'unordered item 1').'[/ulist]'
|
2014-08-15 08:53:05 +02:00
|
|
|
)),
|
2012-07-18 07:02:31 +02:00
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.IMAGE', 'Image'),
|
|
|
|
"Description" => _t('BBCodeParser.IMAGEDESCRIPTION', 'Show an image in your post'),
|
|
|
|
"Example" => "[img]http://www.website.com/image.jpg[/img]"
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
|
|
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
|
|
|
"Example" => '[url]http://www.website.com/[/url]'
|
|
|
|
)),
|
|
|
|
new ArrayData(array(
|
|
|
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
|
|
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
|
|
|
"Example" => "[url=http://www.website.com/]Website[/url]"
|
2014-08-15 08:53:05 +02:00
|
|
|
))
|
2012-07-18 07:02:31 +02:00
|
|
|
)
|
2008-09-26 04:22:51 +02:00
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function useable_tagsHTML(){
|
2008-09-26 04:22:51 +02:00
|
|
|
$useabletags = "<ul class='bbcodeExamples'>";
|
|
|
|
foreach($this->usable_tags()->toArray() as $tag){
|
|
|
|
$useabletags = $useabletags."<li><span>".$tag->Example."</span></li>";
|
|
|
|
}
|
|
|
|
return $useabletags."</ul>";
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-01-08 00:00:54 +01:00
|
|
|
/**
|
|
|
|
* Main BBCode parser method. This takes plain jane content and
|
2014-08-15 08:53:05 +02:00
|
|
|
* runs it through so many filters
|
2009-01-08 00:00:54 +01:00
|
|
|
*
|
|
|
|
* @return Text
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function parse() {
|
2008-09-26 04:22:51 +02:00
|
|
|
$this->content = str_replace(array('&', '<', '>'), array('&', '<', '>'), $this->content);
|
2012-07-31 05:43:01 +02:00
|
|
|
|
|
|
|
$p = new SSHTMLBBCodeParser();
|
|
|
|
$this->content = $p->qparse($this->content);
|
|
|
|
unset($p);
|
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
$this->content = "<p>".$this->content."</p>";
|
2009-01-05 07:19:48 +01:00
|
|
|
|
|
|
|
$this->content = preg_replace('/(<p[^>]*>)\s+/i', '\\1', $this->content);
|
|
|
|
$this->content = preg_replace('/\s+(<\/p[^>]*>)/i', '\\1', $this->content);
|
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
$this->content = preg_replace("/\n\s*\n/", "</p><p>", $this->content);
|
|
|
|
$this->content = str_replace("\n", "<br />", $this->content);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-29 23:31:23 +02:00
|
|
|
if($this->config()->allow_smilies) {
|
2009-01-08 00:00:54 +01:00
|
|
|
$smilies = array(
|
|
|
|
'#(?<!\w):D(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/grin.gif'> ", // :D
|
|
|
|
'#(?<!\w):\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/smile.gif'> ", // :)
|
|
|
|
'#(?<!\w):-\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/smile.gif'> ", // :-)
|
|
|
|
'#(?<!\w):\((?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/sad.gif'> ", // :(
|
|
|
|
'#(?<!\w):-\((?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/sad.gif'> ", // :-(
|
|
|
|
'#(?<!\w):p(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/tongue.gif'> ", // :p
|
2012-12-08 12:20:20 +01:00
|
|
|
'#(?<!\w)8-\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/cool.gif'> ", // 8-)
|
2009-01-08 00:00:54 +01:00
|
|
|
'#(?<!\w):\^\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/confused.gif'> " // :^)
|
|
|
|
);
|
|
|
|
$this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
|
|
|
|
}
|
2008-09-26 04:22:51 +02:00
|
|
|
return $this->content;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
}
|