bbcode
[ class tree: bbcode ] [ index: bbcode ] [ all elements ]

Source for file bbcode.inc.php

Documentation is available at bbcode.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2009-08-26 19:19:41 +0200 (Mi, 26 Aug 2009) $
  5.      * @package            bbcode
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/bbcode.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_bbcode extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.         }
  23.         /**
  24.          * @desc            converts BBCode to HTML using IPB's native parser.
  25.          * @param    string    $input bbcode-formatted string
  26.          * @param    bool    $smilies set to true to parse smilies, otherwise false
  27.          * @return    string    HTML version of input
  28.          * @author            Matthias Reuter
  29.          * @sample
  30.          *  <code>
  31.          *  $ipbwi->bbcode->bbcode2html('[b]test[/b]',true);
  32.          *  </code>
  33.          * @since            2.0
  34.          */
  35.         public function bbcode2html($input$smilies true){
  36.             $this->ipbwi->ips_wrapper->parser->parse_smilies $smilies;
  37.             $this->ipbwi->ips_wrapper->parser->parse_html 0;
  38.             $this->ipbwi->ips_wrapper->parser->parse_bbcode 1;
  39.             $this->ipbwi->ips_wrapper->parser->strip_quotes 1;
  40.             $this->ipbwi->ips_wrapper->parser->parse_nl2br 1;
  41.             $input @$this->ipbwi->ips_wrapper->parser->preDbParse($input);
  42.             // Leave this here in case things go pear-shaped...
  43.             $input $this->ipbwi->ips_wrapper->parser->preDisplayParse($input);
  44.             if($smilies){
  45.                 $input    $this->ipbwi->properXHTML($input);
  46.             }
  47.             return $input;
  48.         }
  49.         /**
  50.          * @desc            converts HTML to BBCode using IPB's native parser.
  51.          * @param    string    $input html-formatted string
  52.          * @return    string    BBCode version of input
  53.          * @author            Matthias Reuter
  54.          * @sample
  55.          *  <code>
  56.          *  $ipbwi->bbcode->html2bbcode('<b>test</b>');
  57.          *  </code>
  58.          * @since            2.0
  59.          */
  60.         public function html2bbcode($input){
  61.             $this->ipbwi->ips_wrapper->parser->parse_html        0;
  62.             $this->ipbwi->ips_wrapper->parser->parse_nl2br        0;
  63.             $this->ipbwi->ips_wrapper->parser->parse_smilies    1;
  64.             $this->ipbwi->ips_wrapper->parser->parse_bbcode        1;
  65.             $this->ipbwi->ips_wrapper->parser->parsing_section    'myapp_comment';
  66.             $input $this->ipbwi->ips_wrapper->parser->preEditParse($input);
  67.             return $input;
  68.         }
  69.         /**
  70.          * @desc            List emoticons, optional limit the result to clickable emoticons only.
  71.          * @param    bool    $clickable set to true to list clickable emoticons only, otherwise set to false
  72.          * @return    array    Assoc array with Emoticons, keys 'typed', 'image'
  73.          * @author            Matthias Reuter
  74.          * @sample
  75.          *  <code>
  76.          *  $ipbwi->bbcode->listEmoticons(true);
  77.          *  </code>
  78.          * @since            2.0
  79.          */
  80.         public function listEmoticons($clickable false){
  81.             if($clickable){
  82.                 $this->ipbwi->ips_wrapper->DB->query('SELECT typed, image FROM '.$this->ipbwi->board['sql_tbl_prefix'].'emoticons WHERE clickable="1"');
  83.             }else{
  84.                 $this->ipbwi->ips_wrapper->DB->query('SELECT typed, image FROM '.$this->ipbwi->board['sql_tbl_prefix'].'emoticons');
  85.             }
  86.             $emos array();
  87.             while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  88.                 $emos[$row['typed']] $row['image'];
  89.             }
  90.             return $emos;
  91.         }
  92.         /**
  93.          * @desc            Print IP.board's built in RichTextEditor (RTE). notice: if your form isn't formatted correctly, please check in your css declaration of tags, e.g. "ul", wether they conflict with IP.board's editor.
  94.          * @param    string    $post a string of content going to be displayed in editor. If empty, a blank editor will be loaded.
  95.          * @param    string    $field a string which defines the name of textarea form field
  96.          * @param    int        $output optional, if 1: output of css & javascript, if 2: output of form, if false: output of both all together
  97.          * @param    bool    $rte optional, if true: force use of rich text editor
  98.          * @return    string    HTML Code of IP.board's RTE
  99.          * @author            Matthias Reuter
  100.          * @sample
  101.          *  <code>
  102.          *  $ipbwi->bbcode->printTextEditor('post content');
  103.          *  </code>
  104.          * @since            2.0
  105.          */
  106.         public function printTextEditor($post='',$field='post',$output=false,$rte=false){
  107.             $boardURL str_replace('?','',$this->ipbwi->board['url']);
  108.         
  109.             $style '
  110.                 <link rel="stylesheet" type="text/css" media="screen" href="'.$boardURL.'public/min/index.php?ipbv=31005&amp;f=public/style_css/css_1/ipb_editor.css" />
  111.                 <style type="text/css">
  112.                     <!--
  113.                         #ipboard_body ul, ol{
  114.                             list-style:none outside none;
  115.                             margin:0px;
  116.                             padding:0px;
  117.                         }
  118.                     -->
  119.                 </style>
  120.             ';
  121.             
  122.             $jscript = <<<EOF_SCRIPT
  123. <script type='text/javascript'>
  124.     jsDebug = 0; /* Must come before JS includes */
  125.     USE_RTE = 1;
  126.     inACP   = false;
  127. </script>
  128. <script type='text/javascript'>
  129. //<![CDATA[
  130.     /* ---- URLs ---- */
  131.     ipb.vars['base_url']             = '{$boardURL}index.php?&';
  132.     ipb.vars['board_url']            = '{$boardURL}';
  133.     ipb.vars['loading_img']         = '{$boardURL}public/style_images/master/loading.gif';
  134.     ipb.vars['active_app']            = 'forums';
  135.     ipb.vars['upload_url']            = '{$boardURL}uploads';
  136.     
  137.     /* Templates/Language */
  138.     ipb.templates['ajax_loading']     = "<div id='ajax_loading'>" + ipb.lang['loading'] + "</div>";
  139. //]]>
  140. </script>
  141. <script type='text/javascript'>
  142.     Loader.boot();
  143. </script>
  144. <script type='text/javascript' src='http://root.pc-intern.com/development/projects.pc-intern.com/public/min/index.php?g=js'></script>
  145. <script type='text/javascript' src='http://root.pc-intern.com/development/projects.pc-intern.com/public/min/index.php?charset=UTF-8&amp;f=public/js/ipb.js,public/js/ips.editor.js' charset='UTF-8'></script>
  146. EOF_SCRIPT;
  147.  
  148.         
  149.             IPSText::getTextClass('bbcode')->parse_html            0;
  150.             IPSText::getTextClass('bbcode')->parse_wordwrap        0;
  151.             IPSText::getTextClass('bbcode')->bypass_badwords    true;
  152.             IPSText::getTextClass('bbcode')->rte_width            200;
  153.             
  154.             $rte_post IPSText::getTextClass('bbcode')->convertForRTE($post);
  155.             
  156.             $form '<div id="ipboard_body">'.
  157.                 str_replace(
  158.                     array('<#EMO_DIR#>','undefined&amp;app=forums'),
  159.                     array('default',$this->ipbwi->getBoardVar('url').'/index.php?app=forums'),
  160.                     @IPSText::getTextClass('editor')->showEditor($rte_post$field))
  161.             .'</div>';
  162.             
  163.             // if user has set rich text editor
  164.             if($this->ipbwi->member->myInfo['members_editor_choice'== 'rte' || $rte == true){
  165.                 if($output == 1){
  166.                     return $style.$jscript;
  167.                 }elseif($output == 2){
  168.                     return $form;
  169.                 }else{
  170.                     return $style.$jscript.$form;
  171.                 }
  172.             // if user has set standard text editor
  173.             }else{
  174.             IPSText::getTextClass('bbcode')->parse_html            0;
  175.             IPSText::getTextClass('bbcode')->parse_nl2br        1;
  176.             IPSText::getTextClass('bbcode')->parse_smilies        1;
  177.             IPSText::getTextClass('bbcode')->parse_bbcode        1;
  178.             IPSText::getTextClass('bbcode')->parsing_section    'global';
  179.             
  180.             $std '<div class="std_emo">';
  181.                     foreach($this->listEmoticons(1as $emoticon => $emoFile){
  182.                         $std .= '<img onclick="insert(\' '.htmlentities($emoticon).' \',\' \')" src="'.$this->ipbwi->getBoardVar('emo_url').$emoFile.'" alt="'.htmlentities($emoticon).'" style="cursor:pointer;" /> ';
  183.                     }
  184.             $std .= '</div><textarea name="post" class="std_text" cols="40" rows="10">'.IPSText::getTextClass('bbcode')->preEditParse($post).'</textarea>';
  185.             
  186.             return $std;
  187.             }
  188.         }
  189.     }
  190. ?>

Documentation generated on Sat, 23 Oct 2010 23:35:46 +0200 by phpDocumentor 1.4.3