Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NBBC tweaks.

  • Loading branch information...
commit 556effeaaae25195a8397ec92bb0348938af1ce6 1 parent 5f9538f
@tburry tburry authored
Showing with 65 additions and 30 deletions.
  1. +65 −30 plugins/NBBC/class.nbbc.plugin.php
View
95 plugins/NBBC/class.nbbc.plugin.php
@@ -10,7 +10,7 @@
$PluginInfo['NBBC'] = array(
'Description' => 'Adapts The New BBCode Parser to work with Vanilla.',
- 'Version' => '1.0.5b',
+ 'Version' => '1.0.6b',
'RequiredApplications' => array('Vanilla' => '2.0.2a'),
'RequiredTheme' => FALSE,
'RequiredPlugins' => FALSE,
@@ -23,20 +23,62 @@
Gdn::FactoryInstall('BBCodeFormatter', 'NBBCPlugin', __FILE__, Gdn::FactorySingleton);
class NBBCPlugin extends Gdn_Plugin {
+
+ public $Class = 'BBCode';
/// CONSTRUCTOR ///
- public function __construct() {
+ public function __construct($Class = 'BBCode') {
parent::__construct();
+ $this->Class = $Class;
}
/// PROPERTIES ///
-
/// METHODS ///
- function DoQuote($bbcode, $action, $name, $default, $params, $content) {
+ function DoImage($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK)
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)) {
$defaultParts = explode(';', $default); // support vbulletin style quoting.
$Url = array_pop($defaultParts);
@@ -53,14 +95,14 @@ function DoQuote($bbcode, $action, $name, $default, $params, $content) {
if (isset($params['name'])) {
$username = trim($params['name']);
$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']))
$title = ConcatSep(' ', $title, T('Quote on', 'on'), htmlspecialchars(trim($params['date'])));
if ($title)
- $title = $title.':';
+ $title = $title . ':';
if (isset($params['url'])) {
$url = trim($params['url']);
@@ -76,7 +118,7 @@ function DoQuote($bbcode, $action, $name, $default, $params, $content) {
if ($title)
$title = "<div class=\"QuoteAuthor\">$title</div>";
-
+
return "\n<blockquote class=\"UserQuote\">\n"
. $title . "\n<div class=\"QuoteText\">"
. $content . "</div>\n</blockquote>\n";
@@ -86,22 +128,18 @@ public function Format($String) {
$Result = $this->NBBC()->Parse($String);
return $Result;
}
-
+
protected $_NBBC = NULL;
- /**
- *
- * @return BBCode
- */
+
public function NBBC() {
if ($this->_NBBC === NULL) {
require_once(dirname(__FILE__) . '/nbbc/nbbc.php');
- $BBCode = new BBCode();
+ $BBCode = new $this->Class();
$BBCode->smiley_url = Url('/plugins/NBBC/design/smileys');
$BBCode->SetAllowAmpersand(TRUE);
- $BBCode->AddRule('code',
- Array(
+ $BBCode->AddRule('code', Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => "\n<pre>{\$_content/v}\n</pre>\n",
'class' => 'code',
@@ -115,8 +153,7 @@ public function NBBC() {
'plain_end' => "\n",
));
- $BBCode->AddRule('quote',
- array('mode' => BBCODE_MODE_CALLBACK,
+ $BBCode->AddRule('quote', array('mode' => BBCODE_MODE_CALLBACK,
'method' => array($this, "DoQuote"),
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
@@ -127,20 +164,19 @@ public function NBBC() {
'plain_end' => "\n",
));
- $BBCode->AddRule('spoiler',
- Array(
- 'simple_start' => "\n".'<div class="UserSpoiler">
- <div class="SpoilerTitle">'.T('Spoiler').': </div>
+ $BBCode->AddRule('spoiler', Array(
+ 'simple_start' => "\n" . '<div class="UserSpoiler">
+ <div class="SpoilerTitle">' . T('Spoiler') . ': </div>
<div class="SpoilerReveal"></div>
<div class="SpoilerText" style="display: none;">',
- 'simple_end' => "</div></div>\n",
- 'allow_in' => Array('listitem', 'block', 'columns'),
- 'before_tag' => "sns",
- 'after_tag' => "sns",
- 'before_endtag' => "sns",
- 'after_endtag' => "sns",
- 'plain_start' => "\n",
- 'plain_end' => "\n"));
+ 'simple_end' => "</div></div>\n",
+ 'allow_in' => Array('listitem', 'block', 'columns'),
+ 'before_tag' => "sns",
+ 'after_tag' => "sns",
+ 'before_endtag' => "sns",
+ 'after_endtag' => "sns",
+ 'plain_start' => "\n",
+ 'plain_end' => "\n"));
$BBCode->AddRule('img', array(
'mode' => BBCODE_MODE_CALLBACK,
@@ -182,7 +218,6 @@ public function NBBC() {
$this->EventArguments['BBCode'] = $BBCode;
$this->FireEvent('AfterNBBCSetup');
$this->_NBBC = $BBCode;
-
}
return $this->_NBBC;
}
Please sign in to comment.
Something went wrong with that request. Please try again.