Vanilla 0.9.3+ versions of WhosOnline & PHPBBCode
Hi,
I tried to debug WhosOnline & PHPBBCode to make them available on Vanilla 0.9.3+. I don't know if anyone was on this project or did this already, but here they are :
WhosOnline version 1.1
PHPBBCode version 1.2
I tried to debug WhosOnline & PHPBBCode to make them available on Vanilla 0.9.3+. I don't know if anyone was on this project or did this already, but here they are :
WhosOnline version 1.1
PHPBBCode version 1.2
0
This discussion has been closed.
Comments
Now corrected, same address !
I checked it, and it's the right one. It's effectively based on the BBCode script, and modified with part of Garth Henson PHPMod for 0.9.2.
<?php /* Extension Name: BB Code (PHP Mod) Extension Url: http://lussumo.com/docs/ Description: A BBCode-to-HTML conversion tool for discussion comments Version: 1.2 Author: Mark O'Sullivan and Garth Henson, Vanilla 0.9.3+ version by Julien Cassignol. Author Url: http://markosullivan.ca/ */ /* [copyright stuff...] */ class BBCodeFormatter extends StringFormatter { var $AllowedProtocols = array('http', 'https', 'ftp', 'news', 'nntp', 'feed', 'gopher', 'mailto'); var $DefaultProtocol = 'http://'; function Parse($String, $Object, $FormatPurpose) { if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) { $String = $this->ProtectString($String); return $this->BBEncode($String); } else { return $String; } } function ProtectString ($String) { $String = str_replace("<", "<", $String); $String = str_replace("\r\n", "<br />", $String); return $String; } function Url($String) { $String = str_replace("\\\"", '"', $String); $SplitUrl = explode('://', $String); if(count($SplitUrl) < 2) return $this->DefaultProtocol.$String; else if(!in_array($SplitUrl[0], $this->AllowedProtocols)) return $this->DefaultProtocol.$String; else return $String; } function BBEncode($String) { $Patterns = array( "/\[img\](.+?)\[\/img\]/ei", "/\[url\=(.+?)\](.+?)\[\/url\]/ei", "/\[url\](.+?)\[\/url\]/ei", "/\[b\](.+?)\[\/b\]/is", "/\[i\](.+?)\[\/i\]/is", "/\[u\](.+?)\[\/u\]/is" ); $Replacements = array( '\'<img src="\'.$this->Url(\'$1\').\'" />\'', '\'<a href="\'.$this->Url(\'$1\').\'" target="_blank">$2</a>\'', '\'<a href="\'.$this->Url(\'$1\').\'">$1</a>\'', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>' ); return preg_replace($Patterns, $Replacements, $String); } } // Instantiate the bbcode object and add it to the string manipulation methods $BBCodeFormatter = $Context->ObjectFactory->NewObject($Context, "BBCodeFormatter"); $Context->StringManipulator->AddManipulator("BBCode", $BBCodeFormatter); ?><?php /* Extension Name: BB Code (PHP Mod) Extension Url: http://lussumo.com/docs/ Description: A BBCode-to-HTML conversion tool for discussion comments Version: 1.2 Author: Mark O'Sullivan and Garth Henson, Vanilla 0.9.3+ version by Julien Cassignol. Author Url: http://markosullivan.ca/ */ /* * Copyright 2003 - 2005 Mark O'Sullivan * This file is part of Vanilla. * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * The latest source code for Vanilla is available at www.lussumo.com * Contact Mark O'Sullivan at mark [at] lussumo [dot] com */ /* Snip : Too long... */ $Replacements = array( '\'<img src="\'.$this->Url(\'$1\').\'" />\'', '\'<a href="\'.$this->Url(\'$1\').\'" target="_blank">$2</a>\'', '\'<a href="\'.$this->Url(\'$1\').\'">$1</a>\'', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>' ); return $this->PHPCode(preg_replace($Patterns, $Replacements, $String)); } function PHPCode($String) { preg_match_all("|\[php\].+?\[/php\]|ims", $String, $matches); $phpOld = array(); $phpNew = array(); foreach ($matches[0] as $orig) { $phpOld[] = $orig; $new = str_replace(array('<','>','<br />','<br>'), array('<','>',"\n","\n"), $orig); $new = trim(preg_replace("|\[php\](.+?)\[/php\]|ims", "$1", $new)); $phpNew[] = "<div class='snippetTitle'>PHP Code:</div>\n<div class='codeSnippet'>" . highlight_string($new, true) . "</div>\n"; } $String = str_replace($phpOld, $phpNew, $String); preg_match_all("|\[code\].+?\[/code\]|ims", $String, $matches); $codeOld = array(); $codeNew = array(); foreach ($matches[0] as $orig) { $codeOld[] = $orig; $new = str_replace(array('<br />','<br>'), array("\n","\n"), $orig); $new = trim(preg_replace('|\[code\](.+?)\[/code\]|ims', "$1", $new)); $new = str_replace("\n", '<br />', $new); $codeNew[] = "<div class='snippetTitle'>Code:</div>\n<div class='codeSnippet'><code>$new< /code></div>\n"; } $String = str_replace($codeOld, $codeNew, $String); return $String; } } // Instantiate the bbcode object and add it to the string manipulation methods $BBCodeFormatter = $Context->ObjectFactory->NewObject($Context, "BBCodeFormatter"); $Context->StringManipulator->AddManipulator("BBCode", $BBCodeFormatter); ?>I had to add an extra space on </code> by the way :-)
It also looks like the html formatter dosn't seem to be properly replacing ampersands all of a sudden...