/**
  * 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'> ", '#(?<!\\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;
 }