Home · Latest · Trends  /  PHP
4

esoTalk-BBCode plugin with Color Tag

rated 4 times [  4] [ 0]  / comments: 0 / hits: 1748  / 3 years ago, sat, jan 21, 2017, 05:41:42
esoTalk forum script / esoTalk-BBCode plugin with color tag [plugin.php] [resources/bbcode.js]
=======plugin.php=======

<?php
// Copyright 2011 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.
if(!defined("IN_ESOTALK"))
 exit;
ET::$pluginInfo["BBCode"] = array("name" => "BBCode","description" => "Formats BBCode within posts, allowing users to style their text.","version" => ESOTALK_VERSION,"author" => "esoTalk Team","authorEmail" => "support@esotalk.org","authorURL" => "http://esotalk.org","license" => "GPLv2");
/**
 * ETPlugin_BBCode
 * @package   
 * @author devcodepro.com
 * @version 2017
 * @access public
 */
class ETPlugin_BBCode extends ETPlugin {
 public function handler_conversationController_renderBefore($sender) {
  $sender->addJSFile($this->resource("bbcode.js"));
  $sender->addCSSFile($this->resource("bbcode.css"));
 }
 public function handler_conversationController_getEditControls($sender,&$controls,$id) {
  addToArrayString($controls,"fixed","<a href='javascript:BBCode.fixed(\"$id\");void(0)' title='".T("Code")."' class='control-fixed'><i class='icon-code'></i></a>",0);
  addToArrayString($controls,"image","<a href='javascript:BBCode.image(\"$id\");void(0)' title='".T("Image")."' class='control-img'><i class='icon-picture'></i></a>",0);
  addToArrayString($controls,"link","<a href='javascript:BBCode.link(\"$id\");void(0)' title='".T("Link")."' class='control-link'><i class='icon-link'></i></a>",0);
  addToArrayString($controls,"strike","<a href='javascript:BBCode.strikethrough(\"$id\");void(0)' title='".T("Strike")."' class='control-s'><i class='icon-strikethrough'></i></a>",0);
  addToArrayString($controls,"header","<a href='javascript:BBCode.header(\"$id\");void(0)' title='".T("Header")."' class='control-h'><i class='icon-h-sign'></i></a>",0);
  addToArrayString($controls,"italic","<a href='javascript:BBCode.italic(\"$id\");void(0)' title='".T("Italic")."' class='control-i'><i class='icon-italic'></i></a>",0);
  addToArrayString($controls,"bold","<a href='javascript:BBCode.bold(\"$id\");void(0)' title='".T("Bold")."' class='control-b'><i class='icon-bold'></i></a>",0);
  addToArrayString($controls,"color","<a href='javascript:BBCode.color(\"$id\");void(0)' title='".T("Color")."' class='control-b'>COLOR</a>",0);
 }
 public function handler_format_beforeFormat($sender) {
  $hideBlock = create_function('&$blockFixedContents, $contents','
		$blockFixedContents[] = $contents;
		return "</p><pre></pre><p>";');
  $hideInline = create_function('&$inlineFixedContents, $contents','
		$inlineFixedContents[] = $contents;
		return "<code></code>";');
  $this->blockFixedContents = array();
  $this->inlineFixedContents = array();
  $regexp = "/(.*)^\s*\[code\]\n?(.*?)\n?\[\/code]$/imse";
  while(preg_match($regexp,$sender->content)) {
   if($sender->inline)
    $sender->content = preg_replace($regexp,"'$1' . \$hideInline(\$this->inlineFixedContents, '$2')",$sender->content);
   else
    $sender->content = preg_replace($regexp,"'$1' . \$hideBlock(\$this->blockFixedContents, '$2')",$sender->content);
  }
  // Inline-level [fixed] tags will become <code>.
  $sender->content = preg_replace("/\[code\]\n?(.*?)\n?\[\/code]/ise","\$hideInline(\$this->inlineFixedContents, '$1')",$sender->content);
 }
 public function handler_format_format($sender) {
  $replacement = $sender->inline?"[image]":"<img src='$1' alt='-image-'/>";
  $sender->content = preg_replace("/\[img\](.*?)\[\/img\]/i",$replacement,$sender->content);
  $sender->content = preg_replace_callback("/\[url=(\w{2,6}:\/\/)?([^\]]*?)\](.*?)\[\/url\]/i",array($this,"linksCallback"),$sender->content);
  $sender->content = preg_replace("|\[b\](.*?)\[/b\]|si","<b>$1</b>",$sender->content);
  $sender->content = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*)\[\/color\]/Usi","<span style=\"color:\\1\">\\2</span>",$sender->content);
  $sender->content = preg_replace("/\[i\](.*?)\[\/i\]/si","<i>$1</i>",$sender->content);
  $sender->content = preg_replace("/\[s\](.*?)\[\/s\]/si","<del>$1</del>",$sender->content);
  $replacement = $sender->inline?"<b>$1</b>":"</p><h4>$1</h4><p>";
  $sender->content = preg_replace("/\[h\](.*?)\[\/h\]/",$replacement,$sender->content);
 }
 public function linksCallback($matches) {
  return ET::formatter()->formatLink($matches[1].$matches[2],$matches[3]);
 }
 public function handler_format_afterFormat($sender) {
  $sender->content = preg_replace("/<code><\/code>/ie","'<code>' . array_shift(\$this->inlineFixedContents) . '</code>'",$sender->content);
  if(!$sender->inline)
   $sender->content = preg_replace("/<pre><\/pre>/ie","'<pre>' . array_pop(\$this->blockFixedContents) . '</pre>'",$sender->content);
 }
}

=======resources/bbcode.js=======

var BBCode = {

    bold: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[b]", "[/b]");
    },
    italic: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[i]", "[/i]");
    },
    strikethrough: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[s]", "[/s]");
    },
    header: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[h]", "[/h]");
    },
    link: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[url=http://example.com]", "[/url]", "http://example.com", "link text");
    },
    image: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[img]", "[/img]", "", "http://example.com/image.jpg");
    },
    fixed: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[code]", "[/code]");
    },
    color: function(id) {
        ETConversation.wrapText($("#" + id + " textarea"), "[color=red]", "[/color]");
    },

};


More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Snippets
reCaptcha in smarty template file
3 years ago, mon, dec 5, 2016
reCAPTCHA v.2.0. Sample Form. You need to get API key for your site. https://www.google.com/recaptcha/admin#list
3 years ago, mon, jan 9, 2017
PHP stopforumspam integration example ans class
3 years ago, mon, jan 16, 2017
Smarty section start loop: First result, second result, first and second result
3 years ago, fri, feb 10, 2017
PHP replace bad words function / form
3 years ago, fri, feb 10, 2017
Get a domain name IP address with PHP
3 years ago, tue, feb 28, 2017
Get YouTube Video ID and clean URL with PHP
3 years ago, sun, mar 5, 2017
HTML Purifier posting arrays example
3 years ago, thu, mar 16, 2017
Thunderbird userchrome.css example C://Users/<USER>/AppData/Roaming/Thunderbird/Profiles/<PROFILE>/chrome/userChrome.css
3 years ago, sun, apr 16, 2017
Sponsor
Posted
jimmy

jimmy

Member since Dec 15, 2016
Total Code Snippets: 16
Total Comments: 2
Location: n/a
Following
User not following anyone yet.