FEATURE: added Smiliey support to BBCode / forum. Now BBCode supports :) :P :D :( 8-) and :^). Yays for icons. Should move from BBCodeParser to TextParser so its available in tinymce but this will do for the forum

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@69687 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Will Rossiter 2009-01-05 03:28:44 +00:00 committed by Sam Minnee
parent e5bafe0467
commit ad60ef40f8
7 changed files with 51 additions and 0 deletions

BIN
images/smilies/confused.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

BIN
images/smilies/cool.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

BIN
images/smilies/grin.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

BIN
images/smilies/sad.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

BIN
images/smilies/smile.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

BIN
images/smilies/tongue.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

View File

@ -16,8 +16,32 @@ unset($options);
*/
class BBCodeParser extends TextParser {
/**
* Set whether phrases starting with http:// or www. are automatically linked
* @var Boolean
*/
protected static $autolinkUrls = true;
/**
* Set whether similies :), :(, :P are converted to images
* @var Boolean
*/
protected static $allowSimilies = false;
/**
* Set the location of the smiles folder. By default use the ones in sapphire
* but this can be overridden by setting BBCodeParser::set_icon_folder('themes/yourtheme/images/');
* @var string
*/
protected static $smilies_location = 'sapphire/images/smilies';
static function smilies_location() {
return BBCodeParser::$smilies_location;
}
static function set_icon_folder($path) {
BBCodeParser::$smilies_location = $path;
}
static function autolinkUrls() {
return (self::$autolinkUrls != null) ? true : false;
}
@ -26,6 +50,15 @@ class BBCodeParser extends TextParser {
BBCodeParser::$autolinkUrls = $autolink;
}
static function smiliesAllowed() {
return (self::$allowSimilies != null) ? true : false;
}
static function enable_smilies() {
BBCodeParser::$allowSimilies = true;
}
static function usable_tags() {
return new DataObjectSet(
new ArrayData(array(
@ -98,6 +131,12 @@ class BBCodeParser extends TextParser {
return $useabletags."</ul>";
}
/**
* Main BBCode parser method. This takes plain jane content and
* runs it through so many filters
*
* @return Text
*/
function parse() {
$this->content = str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $this->content);
$this->content = SSHTMLBBCodeParser::staticQparse($this->content);
@ -108,6 +147,18 @@ class BBCodeParser extends TextParser {
$this->content = preg_replace("/\n\s*\n/", "</p><p>", $this->content);
$this->content = str_replace("\n", "<br />", $this->content);
if(BBCodeParser::smiliesAllowed()) {
$smilies = array(
'#(?<!\w):D(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/grin.gif'> ",
'#(?<!\w):\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/smile.gif'> ",
'#(?<!\w):\((?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/sad.gif'> ",
'#(?<!\w):p(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/tongue.gif'> ",
'#(?<!\w)8-\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/cool.gif'> ",
'#(?<!\w):\^\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/confused.gif'> "
);
$this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
}
return $this->content;
}