-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new bbcodeparser that uses pear
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41274 467b73ca-7a2a-4603-9d3b-597d59a354a9
- Loading branch information
Jeremy Shipman
committed
Sep 5, 2007
1 parent
e808b3a
commit 896e7bf
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
|
||
require_once('HTML/BBCodeParser.php'); | ||
/*Seting up the PEAR bbcode parser*/ | ||
$config = parse_ini_file('BBCodeParser.ini', true); | ||
$options = &PEAR::getStaticProperty('HTML_BBCodeParser', '_options'); | ||
$options = $config['HTML_BBCodeParser']; | ||
//Debug::show($options); | ||
unset($options); | ||
|
||
/** | ||
* TODO Investigate whether SSViewer will be fast enough to handle hundreds of little template files. | ||
* | ||
* A better (more SS) way of doing the HTML code in here is to place them all in small template files | ||
* (eg. BBCodeParser_Code.ss contains the HTML for BBCodeParser::parseCode()), but the overhead this | ||
* would cause is likely to make this very unusable, as nice as it would be. | ||
*/ | ||
class BBCodeParser extends TextParser { | ||
static function usable_tags() { | ||
return new DataObjectSet( | ||
new ArrayData(array( | ||
"Title" => "Bold Text", | ||
"Example" => "[b]<b>Bold</b>[/b]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Italic Text", | ||
"Example" => "[i]<i>Italics</i>[/i]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Underlined Text", | ||
"Example" => "[u]<u>Underlined</u>[/u]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Struck-out Text", | ||
"Example" => "[s]<s>Struck-out</s>[/s]" | ||
)), | ||
|
||
new ArrayData(array( | ||
"Title" => "Website link", | ||
"Description" => "Link to another website or URL", | ||
"Example" => "[url]http://www.website.com/[/url]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Website link", | ||
"Description" => "Link to another website or URL", | ||
"Example" => "[url=http://www.website.com/]Some website[/url]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Email link", | ||
"Description" => "Create link to an email address", | ||
"Example" => "[email]you@yoursite.com[/email]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "Email link", | ||
"Description" => "Create link to an email address", | ||
"Example" => "[email=you@yoursite.com]email me[/email]" | ||
)), | ||
|
||
new ArrayData(array( | ||
"Title" => "Image", | ||
"Description" => "Show an image in your post", | ||
"Example" => "[img]http://www.website.com/image.jpg[/img]" | ||
)), | ||
|
||
new ArrayData(array( | ||
"Title" => "Code Block", | ||
"Description" => "Unformatted code block", | ||
"Example" => "[code]Code block[/code]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "HTML Code Block", | ||
"Description" => "HTML-formatted code block", | ||
"Example" => "[html]HTML code block[/html]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "HTML Code Block", | ||
"Description" => "HTML-formatted code block", | ||
"Example" => "[code html]HTML code block[/code]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "PHP Code Block", | ||
"Description" => "PHP-formatted code block", | ||
"Example" => "[php]PHP code block[/php]" | ||
)), | ||
new ArrayData(array( | ||
"Title" => "PHP Code Block", | ||
"Description" => "PHP-formatted code block", | ||
"Example" => "[code php]PHP code block[/code]" | ||
)) | ||
|
||
); | ||
} | ||
|
||
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); | ||
return HTML_BBCodeParser::staticQparse($this->content); | ||
} | ||
|
||
|
||
} | ||
?> |