[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/tags/html/ -> bbcode.tag.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2003 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TAG
   8  * @version $Id: bbcode.tag.php,v 1.5 2004/11/18 04:22:49 jeffmoore Exp $
   9  */
  10  
  11  /**
  12  * Register the tag
  13  */
  14  $taginfo =& new TagInfo('html:BBCODE', 'HtmlBBCodeTag');
  15  $taginfo->setEndTag(ENDTAG_FORBIDDEN);
  16  TagDictionary::registerTag($taginfo, __FILE__);
  17  
  18  /**
  19  * Parse the 
  20  * @todo Provide mechanism for automatically pulling text from runtime DataSources
  21  * @todo Attributes controlling htmlentity use and nl2br use
  22  * @see http://wact.sourceforge.net/index.php/HtmlBBCodeTag
  23  * @access protected
  24  * @package WACT_TAG
  25  */
  26  class HtmlBBCodeTag extends ServerComponentTag {
  27      /**
  28      * File to include at runtime
  29      * @var string path to runtime component relative to WACT_ROOT
  30      * @access private
  31      */
  32      var $runtimeIncludeFile = '/template/components/html/bbcode.inc.php';
  33      /**
  34      * Name of runtime component class
  35      * @var string
  36      * @access private
  37      */
  38      var $runtimeComponentName = 'HtmlBBCodeComponent';
  39      
  40      /**
  41      * Tag options - partly defined by PEAR::HTML_BBCodeParser plus
  42      * addition output control options. See wiki.
  43      * @var array
  44      * @access private
  45      */
  46      var $options = array();
  47  
  48      /**
  49      * @param CodeWriter
  50      * @return void
  51      * @access protected
  52      */
  53  	function preGenerate(&$code) {
  54          parent::preGenerate($code);
  55          if ( $quotestyle = $this->getAttribute('quotestyle') ) {
  56              $quotestyles = array('single','double');
  57              if ( in_array($quotestyle,$quotestyles) ) {
  58                  $this->options['quotestyle']=$quotestyle;
  59              } else {
  60                  $this->options['quotestyle'] = 'single';
  61              }
  62          } else {
  63              $this->options['quotestyle'] = 'single';
  64          }
  65          if ( $quotewhat = $this->getAttribute('quotewhat') ) {
  66              $quotewhats = array('all','none','strings');
  67              if ( in_array($quotewhat,$quotewhats) ) {
  68                  $this->options['quotewhat']=$quotewhat;
  69              } else {
  70                  $this->options['quotewhat'] = 'all';
  71              }
  72          } else {
  73              $this->options['quotewhat'] = 'all';
  74          }        
  75          $open = $this->getAttribute('open');
  76          if ( isset($open) && $open != '<' ) {
  77              $this->options['open']=$open;
  78          } else {
  79              $this->options['open']='[';
  80          }
  81          $close = $this->getAttribute('close');
  82          if ( isset($open) && $open != '>' ) {
  83              $this->options['close']=$close;
  84          } else {
  85              $this->options['close']=']';
  86          }
  87          if ( $this->getAttribute('xmlclose') ) {
  88              $this->options['xmlclose'] = $this->getBoolAttribute('xmlclose');
  89          } else {
  90              $this->options['xmlclose'] = TRUE;
  91          }
  92          if ( $filters = $this->getAttribute('filters') ) {
  93              $filters = explode(',',$filters);
  94              $filters = array_map('strtolower',$filters);
  95              $knownfilters = array('basic','extended','links',
  96                                    'images','lists','email');
  97              $sep = '';
  98              foreach ( $filters as $filter ) {
  99                  if (in_array($filter,$knownfilters)) {
 100                      $this->options['filters'].=$sep.ucfirst($filter);
 101                      $sep = ',';
 102                  }
 103              }
 104          } else {
 105              $this->options['filters'] = 'Basic,Extended,Links,Images,Lists,Email';
 106          }
 107          if ( NULL !== ($wordwrap = $this->getAttribute('wordwrap')) ) {
 108              if ( $wordwrap == (int)$wordwrap && $wordwrap > 0 ) {
 109                  $this->options['wordwrap'] = $wordwrap;
 110              } else {
 111                  $this->options['wordwrap'] = FALSE;
 112              }
 113          } else {
 114              $this->options['wordwrap'] = FALSE;
 115          }        
 116          if ( $this->getAttribute('nl2br') ) {
 117              $this->options['nl2br'] = $this->getBoolAttribute('nl2br');
 118          } else {
 119              $this->options['nl2br'] = TRUE;
 120          }
 121          if ( $this->getAttribute('htmlentities') ) {
 122              $this->options['htmlentities'] = $this->getBoolAttribute('htmlentities');
 123          } else {
 124              $this->options['htmlentities'] = TRUE;
 125          }
 126      }
 127      /**
 128      * @param CodeWriter
 129      * @return void
 130      * @access protected
 131      */
 132  	function generateContents(&$code) {
 133          parent::generateContents($code);
 134          $code->writePHP($this->getComponentRefCode().
 135              '->options=unserialize(\''.serialize($this->options).'\');');
 136          $code->writePHP('echo '.$this->getComponentRefCode().'->display();');
 137      }
 138  }
 139  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5