Пример #1
0
 /**
  * Executes statements before the actual array building starts
  *
  * This method should be overwritten in a filter if you want to do
  * something before the parsing process starts. This can be useful to
  * allow certain short alternative tags which then can be converted into
  * proper tags with preg_replace() calls.
  * The main class walks through all the filters and and calls this
  * method if it exists. The filters should modify their private $_text
  * variable.
  *
  * @return   none
  * @access   private
  * @see      $_text
  * @author   Stijn de Reede  <*****@*****.**>
  */
 public function _preparse()
 {
     $options = SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
     $o = $options['open'];
     $c = $options['close'];
     $oe = $options['open_esc'];
     $ce = $options['close_esc'];
     $this->_preparsed = preg_replace("!" . $oe . "img(\\s?.*)" . $ce . "(.*)" . $oe . "/img" . $ce . "!Ui", $o . "img=\"\$2\"\$1" . $c . $o . "/img" . $c, $this->_text);
 }
Пример #2
0
 /**
  * Executes statements before the actual array building starts
  *
  * This method should be overwritten in a filter if you want to do
  * something before the parsing process starts. This can be useful to
  * allow certain short alternative tags which then can be converted into
  * proper tags with preg_replace() calls.
  * The main class walks through all the filters and and calls this
  * method if it exists. The filters should modify their private $_text
  * variable.
  *
  * @return   none
  * @access   private
  * @see      $_text
  * @author   Stijn de Reede  <*****@*****.**>
  */
 function _preparse()
 {
     $options = SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
     $o = $options['open'];
     $c = $options['close'];
     $oe = $options['open_esc'];
     $ce = $options['close_esc'];
     $pattern = array("!(^|\\s)([-a-z0-9_.]+@[-a-z0-9.]+\\.[a-z]{2,4})!i", "!" . $oe . "email(" . $ce . "|\\s.*" . $ce . ")(.*)" . $oe . "/email" . $ce . "!Ui");
     $replace = array("\\1" . $o . "email=\\2" . $c . "\\2" . $o . "/email" . $c, $o . "email=\\2\\1\\2" . $o . "/email" . $c);
     $this->_preparsed = preg_replace($pattern, $replace, $this->_text);
 }
Пример #3
0
 /**
  * Executes statements before the actual array building starts
  *
  * This method should be overwritten in a filter if you want to do
  * something before the parsing process starts. This can be useful to
  * allow certain short alternative tags which then can be converted into
  * proper tags with preg_replace() calls.
  * The main class walks through all the filters and and calls this
  * method if it exists. The filters should modify their private $_text
  * variable.
  *
  * @return   none
  * @access   private
  * @see      $_text
  * @author   Stijn de Reede <*****@*****.**>, Seth Price <*****@*****.**>
  */
 function _preparse()
 {
     $options = SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
     $o = $options['open'];
     $c = $options['close'];
     $oe = $options['open_esc'];
     $ce = $options['close_esc'];
     $pattern = array("!" . $oe . "\\*" . $ce . "!", "!" . $oe . "(u?)list=(?-i:A)(\\s*[^" . $ce . "]*)" . $ce . "!i", "!" . $oe . "(u?)list=(?-i:a)(\\s*[^" . $ce . "]*)" . $ce . "!i", "!" . $oe . "(u?)list=(?-i:I)(\\s*[^" . $ce . "]*)" . $ce . "!i", "!" . $oe . "(u?)list=(?-i:i)(\\s*[^" . $ce . "]*)" . $ce . "!i", "!" . $oe . "(u?)list=(?-i:1)(\\s*[^" . $ce . "]*)" . $ce . "!i", "!" . $oe . "(u?)list([^" . $ce . "]*)" . $ce . "!i");
     $replace = array($o . "li" . $c, $o . "\$1list=upper-alpha\$2" . $c, $o . "\$1list=lower-alpha\$2" . $c, $o . "\$1list=upper-roman\$2" . $c, $o . "\$1list=lower-roman\$2" . $c, $o . "\$1list=decimal\$2" . $c, $o . "\$1list\$2" . $c);
     $this->_preparsed = preg_replace($pattern, $replace, $this->_text);
 }
<?php

require_once 'HTML/HTMLBBCodeParser.php';
/*Seting up the PEAR bbcode parser*/
$config = parse_ini_file('BBCodeParser.ini', true);
$options =& SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
$options = $config['SSHTMLBBCodeParser'];
//Debug::show($options);
unset($options);
/**
 * BBCode parser object.
 * Use on a text field in a template with $Content.Parse(BBCodeParser).
 * @package sapphire
 * @subpackage misc
 */
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
Пример #5
0
 /**
  * Constructor, initialises the options and filters
  *
  * Sets the private variable _options with base options defined with
  * &PEAR::getStaticProperty(), overwriting them with (if present)
  * the argument to this method.
  * Then it sets the extra options to properly escape the tag
  * characters in preg_replace() etc. The set options are
  * then stored back with &PEAR::getStaticProperty(), so that the filter
  * classes can use them.
  * All the filters in the options are initialised and their defined tags
  * are copied into the private variable _definedTags.
  *
  * @param    array           options to use, can be left out
  * @return   none
  * @access   public
  * @author   Stijn de Reede  <*****@*****.**>
  */
 function SSHTMLBBCodeParser($options = array())
 {
     // set the already set options
     $baseoptions =& SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
     if (is_array($baseoptions)) {
         foreach ($baseoptions as $k => $v) {
             $this->_options[$k] = $v;
         }
     }
     // set the options passed as an argument
     foreach ($options as $k => $v) {
         $this->_options[$k] = $v;
     }
     // add escape open and close chars to the options for preg escaping
     $preg_escape = '\\^$.[]|()?*+{}';
     if ($this->_options['open'] != '' && strpos($preg_escape, $this->_options['open'])) {
         $this->_options['open_esc'] = "\\" . $this->_options['open'];
     } else {
         $this->_options['open_esc'] = $this->_options['open'];
     }
     if ($this->_options['close'] != '' && strpos($preg_escape, $this->_options['close'])) {
         $this->_options['close_esc'] = "\\" . $this->_options['close'];
     } else {
         $this->_options['close_esc'] = $this->_options['close'];
     }
     // set the options back so that child classes can use them */
     $baseoptions = $this->_options;
     unset($baseoptions);
     // return if this is a subclass
     if (is_subclass_of($this, 'SSHTMLBBCodeParser_Filter')) {
         return;
     }
     // extract the definedTags from subclasses */
     $this->addFilters($this->_options['filters']);
 }
Пример #6
0
 /**
  * Finish preparsing URL to clean it up
  *
  * @return  string
  * @access  private
  * @author  Seth Price <*****@*****.**>
  */
 public function smarterPPLink($matches)
 {
     $options = SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
     $o = $options['open'];
     $c = $options['close'];
     $urlServ = $matches[1];
     $path = $matches[5];
     $off = strpos($urlServ, ':');
     if ($off === false) {
         //Default to http
         $urlServ = $this->_defaultScheme . '://' . $urlServ;
         $off = strpos($urlServ, ':');
     }
     //Add trailing slash if missing (to create a valid URL)
     if (!$path) {
         $path = '/';
     }
     $protocol = substr($urlServ, 0, $off);
     if (in_array($protocol, $this->_allowedSchemes)) {
         //If protocol is in the approved list than allow it
         return $o . 'url=' . $urlServ . $path . $c . $matches[6] . $o . '/url' . $c;
     }
     //Else remove url tag
     return $matches[6];
 }