Navigation Menu

Skip to content

Commit

Permalink
NBBC tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
tburry committed Apr 18, 2012
1 parent 5f9538f commit 556effe
Showing 1 changed file with 65 additions and 30 deletions.
95 changes: 65 additions & 30 deletions plugins/NBBC/class.nbbc.plugin.php
Expand Up @@ -10,7 +10,7 @@


$PluginInfo['NBBC'] = array( $PluginInfo['NBBC'] = array(
'Description' => 'Adapts The New BBCode Parser to work with Vanilla.', 'Description' => 'Adapts The New BBCode Parser to work with Vanilla.',
'Version' => '1.0.5b', 'Version' => '1.0.6b',
'RequiredApplications' => array('Vanilla' => '2.0.2a'), 'RequiredApplications' => array('Vanilla' => '2.0.2a'),
'RequiredTheme' => FALSE, 'RequiredTheme' => FALSE,
'RequiredPlugins' => FALSE, 'RequiredPlugins' => FALSE,
Expand All @@ -23,20 +23,62 @@
Gdn::FactoryInstall('BBCodeFormatter', 'NBBCPlugin', __FILE__, Gdn::FactorySingleton); Gdn::FactoryInstall('BBCodeFormatter', 'NBBCPlugin', __FILE__, Gdn::FactorySingleton);


class NBBCPlugin extends Gdn_Plugin { class NBBCPlugin extends Gdn_Plugin {

public $Class = 'BBCode';


/// CONSTRUCTOR /// /// CONSTRUCTOR ///
public function __construct() { public function __construct($Class = 'BBCode') {
parent::__construct(); parent::__construct();
$this->Class = $Class;
} }


/// PROPERTIES /// /// PROPERTIES ///

/// METHODS /// /// METHODS ///


function DoQuote($bbcode, $action, $name, $default, $params, $content) { function DoImage($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) if ($action == BBCODE_CHECK)
return true; return true;
$content = trim($bbcode->UnHTMLEncode(strip_tags($content)));
if ($bbcode->IsValidUrl($content, false))
return "<img src=\"" . htmlspecialchars($content) . "\" alt=\""
. htmlspecialchars(basename($content)) . "\" class=\"bbcode_img\" />";



// if (preg_match("/\\.(?:gif|jpeg|jpg|jpe|png)$/i", $content)) {
// if (preg_match("/^[a-zA-Z0-9_][^:]+$/", $content)) {
// if (!preg_match("/(?:\\/\\.\\.\\/)|(?:^\\.\\.\\/)|(?:^\\/)/", $content)) {
// $info = @getimagesize("{$bbcode->local_img_dir}/{$content}");
// if ($info[2] == IMAGETYPE_GIF || $info[2] == IMAGETYPE_JPEG || $info[2] == IMAGETYPE_PNG) {
// return "<img src=\""
// . htmlspecialchars("{$bbcode->local_img_url}/{$content}") . "\" alt=\""
// . htmlspecialchars(basename($content)) . "\" width=\""
// . htmlspecialchars($info[0]) . "\" height=\""
// . htmlspecialchars($info[1]) . "\" class=\"bbcode_img\" />";
// }
// }
// } else if ($bbcode->IsValidURL($content, false)) {
// return "<img src=\"" . htmlspecialchars($content) . "\" alt=\""
// . htmlspecialchars(basename($content)) . "\" class=\"bbcode_img\" />";
// }
// }
return htmlspecialchars($params['_tag']) . htmlspecialchars($content) . htmlspecialchars($params['_endtag']);
}

function DoVideo($bbcode, $action, $name, $default, $params, $content) {
list($Width, $Height) = Gdn_Format::GetEmbedSize();
list($Type, $Code) = explode(';', $default);
switch ($Type) {
case 'youtube':
return '<div class="Video P"><iframe width="'.$Width.'" height="'.$Height.'" src="http://www.youtube.com/embed/' . $Code . '" frameborder="0" allowfullscreen></iframe></div>';
default:
return $content;
}
}

function DoQuote($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK)
return true;

if (is_string($default)) { if (is_string($default)) {
$defaultParts = explode(';', $default); // support vbulletin style quoting. $defaultParts = explode(';', $default); // support vbulletin style quoting.
$Url = array_pop($defaultParts); $Url = array_pop($defaultParts);
Expand All @@ -53,14 +95,14 @@ function DoQuote($bbcode, $action, $name, $default, $params, $content) {
if (isset($params['name'])) { if (isset($params['name'])) {
$username = trim($params['name']); $username = trim($params['name']);
$username = html_entity_decode($username, ENT_QUOTES, 'UTF-8'); $username = html_entity_decode($username, ENT_QUOTES, 'UTF-8');
$title = ConcatSep(' ', $title, Anchor(htmlspecialchars($username, NULL, 'UTF-8'), '/profile/'.rawurlencode($username)), T('Quote wrote', 'wrote')); $title = ConcatSep(' ', $title, Anchor(htmlspecialchars($username, NULL, 'UTF-8'), '/profile/' . rawurlencode($username)), T('Quote wrote', 'wrote'));
} }


if (isset($params['date'])) if (isset($params['date']))
$title = ConcatSep(' ', $title, T('Quote on', 'on'), htmlspecialchars(trim($params['date']))); $title = ConcatSep(' ', $title, T('Quote on', 'on'), htmlspecialchars(trim($params['date'])));


if ($title) if ($title)
$title = $title.':'; $title = $title . ':';


if (isset($params['url'])) { if (isset($params['url'])) {
$url = trim($params['url']); $url = trim($params['url']);
Expand All @@ -76,7 +118,7 @@ function DoQuote($bbcode, $action, $name, $default, $params, $content) {


if ($title) if ($title)
$title = "<div class=\"QuoteAuthor\">$title</div>"; $title = "<div class=\"QuoteAuthor\">$title</div>";

return "\n<blockquote class=\"UserQuote\">\n" return "\n<blockquote class=\"UserQuote\">\n"
. $title . "\n<div class=\"QuoteText\">" . $title . "\n<div class=\"QuoteText\">"
. $content . "</div>\n</blockquote>\n"; . $content . "</div>\n</blockquote>\n";
Expand All @@ -86,22 +128,18 @@ public function Format($String) {
$Result = $this->NBBC()->Parse($String); $Result = $this->NBBC()->Parse($String);
return $Result; return $Result;
} }

protected $_NBBC = NULL; protected $_NBBC = NULL;
/**
*
* @return BBCode
*/
public function NBBC() { public function NBBC() {
if ($this->_NBBC === NULL) { if ($this->_NBBC === NULL) {
require_once(dirname(__FILE__) . '/nbbc/nbbc.php'); require_once(dirname(__FILE__) . '/nbbc/nbbc.php');
$BBCode = new BBCode(); $BBCode = new $this->Class();
$BBCode->smiley_url = Url('/plugins/NBBC/design/smileys'); $BBCode->smiley_url = Url('/plugins/NBBC/design/smileys');
$BBCode->SetAllowAmpersand(TRUE); $BBCode->SetAllowAmpersand(TRUE);




$BBCode->AddRule('code', $BBCode->AddRule('code', Array(
Array(
'mode' => BBCODE_MODE_ENHANCED, 'mode' => BBCODE_MODE_ENHANCED,
'template' => "\n<pre>{\$_content/v}\n</pre>\n", 'template' => "\n<pre>{\$_content/v}\n</pre>\n",
'class' => 'code', 'class' => 'code',
Expand All @@ -115,8 +153,7 @@ public function NBBC() {
'plain_end' => "\n", 'plain_end' => "\n",
)); ));


$BBCode->AddRule('quote', $BBCode->AddRule('quote', array('mode' => BBCODE_MODE_CALLBACK,
array('mode' => BBCODE_MODE_CALLBACK,
'method' => array($this, "DoQuote"), 'method' => array($this, "DoQuote"),
'allow_in' => Array('listitem', 'block', 'columns'), 'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns", 'before_tag' => "sns",
Expand All @@ -127,20 +164,19 @@ public function NBBC() {
'plain_end' => "\n", 'plain_end' => "\n",
)); ));


$BBCode->AddRule('spoiler', $BBCode->AddRule('spoiler', Array(
Array( 'simple_start' => "\n" . '<div class="UserSpoiler">
'simple_start' => "\n".'<div class="UserSpoiler"> <div class="SpoilerTitle">' . T('Spoiler') . ': </div>
<div class="SpoilerTitle">'.T('Spoiler').': </div>
<div class="SpoilerReveal"></div> <div class="SpoilerReveal"></div>
<div class="SpoilerText" style="display: none;">', <div class="SpoilerText" style="display: none;">',
'simple_end' => "</div></div>\n", 'simple_end' => "</div></div>\n",
'allow_in' => Array('listitem', 'block', 'columns'), 'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns", 'before_tag' => "sns",
'after_tag' => "sns", 'after_tag' => "sns",
'before_endtag' => "sns", 'before_endtag' => "sns",
'after_endtag' => "sns", 'after_endtag' => "sns",
'plain_start' => "\n", 'plain_start' => "\n",
'plain_end' => "\n")); 'plain_end' => "\n"));


$BBCode->AddRule('img', array( $BBCode->AddRule('img', array(
'mode' => BBCODE_MODE_CALLBACK, 'mode' => BBCODE_MODE_CALLBACK,
Expand Down Expand Up @@ -182,7 +218,6 @@ public function NBBC() {
$this->EventArguments['BBCode'] = $BBCode; $this->EventArguments['BBCode'] = $BBCode;
$this->FireEvent('AfterNBBCSetup'); $this->FireEvent('AfterNBBCSetup');
$this->_NBBC = $BBCode; $this->_NBBC = $BBCode;

} }
return $this->_NBBC; return $this->_NBBC;
} }
Expand Down

0 comments on commit 556effe

Please sign in to comment.