/**
  * Main BBCode parser method. This takes plain jane content and
  * runs it through so many filters
  *
  * @return DBField
  */
 public function parse()
 {
     // Convert content to plain text
     $this->content = DBField::create_field('HTMLFragment', $this->content)->Plain();
     $p = new SSHTMLBBCodeParser();
     $this->content = $p->qparse($this->content);
     unset($p);
     if ($this->config()->allow_smilies) {
         $smilies = array('#(?<!\\w):D(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/grin.gif'> ", '#(?<!\\w):\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/smile.gif'> ", '#(?<!\\w):-\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/smile.gif'> ", '#(?<!\\w):\\((?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/sad.gif'> ", '#(?<!\\w):-\\((?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/sad.gif'> ", '#(?<!\\w):p(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/tongue.gif'> ", '#(?<!\\w)8-\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/cool.gif'> ", '#(?<!\\w):\\^\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/confused.gif'> ");
         $this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
     }
     // Ensure to return cast value
     return DBField::create_field('HTMLFragment', $this->content);
 }
Example #2
0
 /**
  * Main BBCode parser method. This takes plain jane content and
  * runs it through so many filters 
  *
  * @return Text
  */
 public function parse()
 {
     $this->content = str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $this->content);
     $p = new SSHTMLBBCodeParser();
     $this->content = $p->qparse($this->content);
     unset($p);
     $this->content = "<p>" . $this->content . "</p>";
     $this->content = preg_replace('/(<p[^>]*>)\\s+/i', '\\1', $this->content);
     $this->content = preg_replace('/\\s+(<\\/p[^>]*>)/i', '\\1', $this->content);
     $this->content = preg_replace("/\n\\s*\n/", "</p><p>", $this->content);
     $this->content = str_replace("\n", "<br />", $this->content);
     if (BBCodeParser::smiliesAllowed()) {
         $smilies = array('#(?<!\\w):D(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/grin.gif'> ", '#(?<!\\w):\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/smile.gif'> ", '#(?<!\\w):-\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/smile.gif'> ", '#(?<!\\w):\\((?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/sad.gif'> ", '#(?<!\\w):-\\((?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/sad.gif'> ", '#(?<!\\w):p(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/tongue.gif'> ", '#(?<!\\w)8-\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/cool.gif'> ", '#(?<!\\w):\\^\\)(?!\\w)#i' => " <img src='" . BBCodeParser::smilies_location() . "/confused.gif'> ");
         $this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
     }
     return $this->content;
 }
Example #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  <*****@*****.**>
  */
 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);
 }
Example #4
0
 function parse()
 {
     $this->content = str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $this->content);
     $this->content = SSHTMLBBCodeParser::staticQparse($this->content);
     //Debug::message($this->content);
     $this->content = "<p>" . $this->content . "</p>";
     $this->content = preg_replace("/([^>\\s]\\s*)\n\n/", '$1</p><p>', $this->content);
     //$this->content = preg_replace("/([^>\s]\s*)\n/", '$1<br />', $this->content);
     return $this->content;
 }
Example #5
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);
 }
Example #6
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);
 }
 /**
  * Quick static method to do setText(), parse() and getParsed at once
  *
  * @return   none
  * @access   public
  * @see      parse()
  * @see      $_text
  * @author   Stijn de Reede  <*****@*****.**>
  */
 function staticQparse($str)
 {
     $p = new SSHTMLBBCodeParser();
     $str = $p->qparse($str);
     unset($p);
     return $str;
 }
Example #8
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];
 }
Example #9
0
	/**
	 * Main BBCode parser method. This takes plain jane content and
	 * runs it through so many filters 
	 *
	 * @return Text
	 */
	function parse() {
		$this->content = str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $this->content);
		$this->content = SSHTMLBBCodeParser::staticQparse($this->content);
		$this->content = "<p>".$this->content."</p>";

		$this->content = preg_replace('/(<p[^>]*>)\s+/i', '\\1', $this->content);
		$this->content = preg_replace('/\s+(<\/p[^>]*>)/i', '\\1', $this->content);

		$this->content = preg_replace("/\n\s*\n/", "</p><p>", $this->content);
		$this->content = str_replace("\n", "<br />", $this->content);
				
		if(BBCodeParser::smiliesAllowed()) {
			$smilies = array(
				'#(?<!\w):D(?!\w)#i'         => " <img src='".BBCodeParser::smilies_location(). "/grin.gif'> ", // :D
				'#(?<!\w):\)(?!\w)#i'        => " <img src='".BBCodeParser::smilies_location(). "/smile.gif'> ", // :)
				'#(?<!\w):-\)(?!\w)#i'        => " <img src='".BBCodeParser::smilies_location(). "/smile.gif'> ", // :-)
				'#(?<!\w):\((?!\w)#i'        => " <img src='".BBCodeParser::smilies_location(). "/sad.gif'> ", // :(
				'#(?<!\w):-\((?!\w)#i'        => " <img src='".BBCodeParser::smilies_location(). "/sad.gif'> ", // :-(
				'#(?<!\w):p(?!\w)#i'         => " <img src='".BBCodeParser::smilies_location(). "/tongue.gif'> ", // :p
			 	'#(?<!\w)8-\)(?!\w)#i'     => " <img src='".BBCodeParser::smilies_location(). "/cool.gif'> ", // 8-)
				'#(?<!\w):\^\)(?!\w)#i' => " <img src='".BBCodeParser::smilies_location(). "/confused.gif'> " // :^)
			);
			$this->content = preg_replace(array_keys($smilies), array_values($smilies), $this->content);
		}
		return $this->content;
	}