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

Source for file Standard.php

Documentation is available at Standard.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Alan Knowles <alan@akbkhome.com>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Standard.php,v 1.28 2004/04/24 02:05:48 alan_k Exp $
  20. //
  21. //  Base Compiler Class
  22. //  Standard 'Original Flavour' Flexy compiler
  23.  
  24.  
  25.  
  26.  
  27. require_once 'HTML/Template/Flexy/Tokenizer.php';
  28.  
  29. // cache for po files..
  30. $GLOBALS['_html_template_flexy_compiler_standard']['PO'= array();
  31.  
  32. class HTML_Template_Flexy_Compiler_Standard extends HTML_Template_Flexy_Compiler {
  33.     
  34.     
  35.     
  36.     /**
  37.     * The compile method.
  38.     * 
  39.     * @params   object HTML_Template_Flexy
  40.     * @params   string|false string to compile of false to use a file.
  41.     * @return   string   filename of template
  42.     * @access   public
  43.     */
  44.     function compile(&$flexy,$string=false
  45.     {
  46.         // read the entire file into one variable
  47.         
  48.         // note this should be moved to new HTML_Template_Flexy_Token
  49.         // and that can then manage all the tokens in one place..
  50.         global $_HTML_TEMPLATE_FLEXY_COMPILER;
  51.         
  52.         $gettextStrings &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
  53.         $gettextStrings = array()// reset it.
  54.         
  55.         if (@$this->options['debug']{
  56.             echo "compiling template $flexy->currentTemplate<BR>";
  57.             
  58.         }
  59.          
  60.         // reset the elements.
  61.         $flexy->_elements = array();
  62.         
  63.         // replace this with a singleton??
  64.         
  65.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'$this->options;
  66.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'= array();
  67.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'$flexy->currentTemplate;
  68.         
  69.         
  70.         if (is_array($this->options['Translation2'])) {
  71.             require_once 'Translation2.php';
  72.             $this->options['Translation2'= new Translation2(
  73.                 $this->options['Translation2']['driver'],
  74.                 @$this->options['Translation2']['options']
  75.             );
  76.         }
  77.         
  78.         
  79.         if (is_a($this->options['Translation2'],'Translation2')) {
  80.             $this->options['Translation2']->setLang($this->options['locale']);
  81.             // fixme - needs to be more specific to which template to use..
  82.             $this->options['Translation2']->setPageID(basename($flexy->currentTemplate));
  83.         else {
  84.             setlocale(LC_ALL$this->options['locale']);
  85.         }
  86.         
  87.         
  88.         
  89.         
  90.         
  91.         
  92.         
  93.         $data $string;
  94.         if ($string === false{
  95.             $data file_get_contents($flexy->currentTemplate);
  96.         }
  97.         
  98.         
  99.         
  100.         // PRE PROCESS {_(.....)} translation markers.
  101.         $got_gettext_markup = false;
  102.         
  103.         
  104.         
  105.         if (strpos($data,'{_('!== false{
  106.             $matches = array();
  107.             $lmatches explode ('{_('$data);
  108.             array_shift($lmatches);
  109.             // shift the first..
  110.             foreach ($lmatches as $k{
  111.                 if (false === strpos($k,')_}')) {
  112.                     continue;
  113.                 }
  114.                 $x explode(')_}',$k);
  115.                 $matches[$x[0];
  116.             }
  117.         
  118.         
  119.            //echo '<PRE>';print_r($matches);
  120.             // we may need to do some house cleaning here...
  121.             $gettextStrings $matches;
  122.             $got_gettext_markup = true;
  123.             
  124.             
  125.             // replace them now..  
  126.             // ** leaving in the tag (which should be ignored by the parser..
  127.             // we then get rid of the tags during the toString method in this class.
  128.             foreach($matches as $v{
  129.                 $data str_replace('{_('.$v.')_}''{_('.$this->translateString($v).')_}',$data);
  130.             }
  131.             
  132.         }
  133.             
  134.         
  135.         
  136.         
  137.         
  138.         
  139.         
  140.         $tokenizer = new HTML_Template_Flexy_Tokenizer($data);
  141.         $tokenizer->fileName = $flexy->currentTemplate;
  142.         
  143.         
  144.         //$tokenizer->debug=1;
  145.         if ($this->options['nonHTML']{
  146.             $tokenizer->ignoreHTML = true;
  147.         }
  148.         if ($this->options['allowPHP']{
  149.             $tokenizer->ignorePHP = false;
  150.         }
  151.         
  152.         $res = HTML_Template_Flexy_Token::buildTokens($tokenizer);
  153.          
  154.         
  155.         if (is_a($res,'PEAR_Error')) {
  156.             return $res;
  157.         }   
  158.         // turn tokens into Template..
  159.         
  160.         $data $res->compile($this);
  161.         
  162.         if (is_a($data,'PEAR_Error')) {
  163.             return $data;
  164.         }
  165.         
  166.         
  167.         if (   @$this->options['debug']{
  168.             echo "<B>Result: </B><PRE>".htmlspecialchars($data)."</PRE><BR>";
  169.             
  170.         }
  171.  
  172.         if ($this->options['nonHTML']{
  173.            $data =  str_replace("?>\n","?>\n\n",$data);
  174.         }
  175.         
  176.          
  177.         
  178.         
  179.         // at this point we are into writing stuff...
  180.         if ($this->options['compileToString']{
  181.             $flexy->elements =  $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'];
  182.             return $data;
  183.         }
  184.         
  185.         
  186.         
  187.         
  188.         // error checking?
  189.         if( ($cfp fopen$flexy->compiledTemplate 'w' )) ) {
  190.             if (@$this->options['debug']{
  191.                 echo "<B>Writing: </B>".htmlspecialchars($data)."<BR>";
  192.                 
  193.             }
  194.             fwrite($cfp,$data);
  195.             fclose($cfp);
  196.              chmod($flexy->compiledTemplate,0775);
  197.             // make the timestamp of the two items match.
  198.             clearstatcache();
  199.             touch($flexy->compiledTemplatefilemtime($flexy->currentTemplate));
  200.             
  201.         else {
  202.             return PEAR::raiseError('HTML_Template_Flexy::failed to write to '.$flexy->compiledTemplate,
  203.                 HTML_TEMPLATE_FLEXY_ERROR_FILE ,PEAR_ERROR_RETURN);
  204.         }
  205.         // gettext strings
  206.         if (file_exists($flexy->getTextStringsFile)) {
  207.             unlink($flexy->getTextStringsFile);
  208.         }
  209.         
  210.         if($gettextStrings && ($cfp fopen$flexy->getTextStringsFile'w') ) ) {
  211.             
  212.             fwrite($cfp,serialize(array_unique($gettextStrings)));
  213.             fclose($cfp);
  214.         }
  215.         
  216.         // elements
  217.         if (file_exists($flexy->elementsFile)) {
  218.             unlink($flexy->elementsFile);
  219.         }
  220.         
  221.         if$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'&&
  222.             ($cfp fopen$flexy->elementsFile'w') ) ) {
  223.             fwrite($cfp,serialize$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']));
  224.             fclose($cfp);
  225.             // now clear it.
  226.         
  227.         }
  228.         
  229.         return true;
  230.     }
  231.     
  232.     /**
  233.     * Flag indicating compiler is inside {_( .... )_} block, and should not
  234.     * add to the gettextstrings array.
  235.     *
  236.     * @var boolean 
  237.     * @access public
  238.     */
  239.     var $inGetTextBlock = false;
  240.     
  241.     /**
  242.     * This is the base toString Method, it relays into toString{TokenName}
  243.     *
  244.     * @param    object    HTML_Template_Flexy_Token_* 
  245.     * 
  246.     * @return   string     string to build a template
  247.     * @access   public
  248.     * @see      toString*
  249.     */
  250.   
  251.  
  252.     function toString($element
  253.     {
  254.         static $len = 26; // strlen('HTML_Template_Flexy_Token_');
  255.         if ($this->options['debug']{
  256.             $x $element;
  257.             unset($x->children);
  258.             echo htmlspecialchars(print_r($x,true))."<BR>\n";
  259.         }
  260.         if ($element->token == 'GetTextStart'{
  261.             $this->inGetTextBlock = true;
  262.             return '';
  263.         }
  264.         if ($element->token == 'GetTextEnd'{
  265.             $this->inGetTextBlock = false;
  266.             return '';
  267.         }
  268.         
  269.             
  270.         $class get_class($element);
  271.         if (strlen($class>= $len{
  272.             $type substr($class,$len);
  273.             return $this->{'toString'.$type}($element);
  274.         }
  275.         
  276.         $ret $element->value;
  277.         $add $element->compileChildren($this);
  278.         if (is_a($add,'PEAR_Error')) {
  279.             return $add;
  280.         }
  281.         $ret .= $add;
  282.         
  283.         if ($element->close{
  284.             $add $element->close->compile($this);
  285.             if (is_a($add,'PEAR_Error')) {
  286.                 return $add;
  287.             }
  288.             $ret .= $add;
  289.         }
  290.         
  291.         return $ret;
  292.     }
  293.  
  294.  
  295.     /**
  296.     *   HTML_Template_Flexy_Token_Else toString
  297.     *
  298.     * @param    object    HTML_Template_Flexy_Token_Else 
  299.     * 
  300.     * @return   string     string to build a template
  301.     * @access   public
  302.     * @see      toString*
  303.     */
  304.   
  305.  
  306.     function toStringElse($element
  307.      {
  308.         // pushpull states to make sure we are in an area.. - should really check to see 
  309.         // if the state it is pulling is a if...
  310.         if ($element->pullState(=== false{
  311.             return $this->appendHTML(
  312.                 "<font color=\"red\">Unmatched {else:} on line: {$element->line}</font>"
  313.                 );
  314.         }
  315.         $element->pushState();
  316.         return $this->appendPhp("} else {");
  317.     }
  318.     
  319.     /**
  320.     *   HTML_Template_Flexy_Token_End toString
  321.     *
  322.     * @param    object    HTML_Template_Flexy_Token_Else 
  323.     * 
  324.     * @return   string     string to build a template
  325.     * @access   public
  326.     * @see      toString*
  327.     */
  328.   
  329.     function toStringEnd($element
  330.     {
  331.         // pushpull states to make sure we are in an area.. - should really check to see 
  332.         // if the state it is pulling is a if...
  333.         if ($element->pullState(=== false{
  334.             return $this->appendHTML(
  335.                 "<font color=\"red\">Unmatched {end:} on line: {$element->line}</font>"
  336.                 );
  337.         }
  338.          
  339.         return $this->appendPhp("}");
  340.     }
  341.  
  342.     /**
  343.     *   HTML_Template_Flexy_Token_EndTag toString
  344.     *
  345.     * @param    object    HTML_Template_Flexy_Token_EndTag 
  346.     * 
  347.     * @return   string     string to build a template
  348.     * @access   public
  349.     * @see      toString*
  350.     */
  351.   
  352.  
  353.  
  354.     function toStringEndTag($element
  355.     {
  356.         return $this->toStringTag($element);
  357.     }
  358.         
  359.     
  360.     
  361.     /**
  362.     *   HTML_Template_Flexy_Token_Foreach toString
  363.     *
  364.     * @param    object    HTML_Template_Flexy_Token_Foreach 
  365.     * 
  366.     * @return   string     string to build a template
  367.     * @access   public
  368.     * @see      toString*
  369.     */
  370.   
  371.     
  372.     function toStringForeach($element
  373.     {
  374.     
  375.         $loopon $element->toVar($element->loopOn);
  376.         if (is_a($loopon,'PEAR_Error')) {
  377.             return $loopon;
  378.         }
  379.         
  380.         $ret 'if (is_array('$loopon")  || " .
  381.             'is_object(' $loopon  ')) ' .
  382.             'foreach(' $loopon  " ";
  383.             
  384.         $ret .= "as \${$element->key}";
  385.         
  386.         if ($element->value{
  387.             $ret .=  " => \${$element->value}";
  388.         }
  389.         $ret .= ") {";
  390.         
  391.         $element->pushState();
  392.         $element->pushVar($element->key);
  393.         $element->pushVar($element->value);
  394.         return $this->appendPhp($ret);
  395.     }
  396.     /**
  397.     *   HTML_Template_Flexy_Token_If toString
  398.     *
  399.     * @param    object    HTML_Template_Flexy_Token_If 
  400.     * 
  401.     * @return   string     string to build a template
  402.     * @access   public
  403.     * @see      toString*
  404.     */
  405.   
  406.     function toStringIf($element
  407.     {
  408.         
  409.         $var $element->toVar($element->condition);
  410.         if (is_a($var,'PEAR_Error')) {
  411.             return $var;
  412.         }
  413.         
  414.         $ret "if (".$element->isNegative . $var .")  {";
  415.         $element->pushState();
  416.         return $this->appendPhp($ret);
  417.     }
  418.  
  419.    /**
  420.     *  get Modifier Wrapper
  421.     *
  422.     * converts :h, :u, :r , .....
  423.     * @param    object    HTML_Template_Flexy_Token_Method|Var
  424.     * 
  425.     * @return   array prefix,suffix
  426.     * @access   public
  427.     * @see      toString*
  428.     */
  429.  
  430.     function getModifierWrapper($element
  431.     {
  432.         $prefix 'echo ';
  433.         
  434.         $suffix '';
  435.         $modifier $element->modifier . ' ';
  436.         switch ($modifier{0}{
  437.             case 'h':
  438.                 break;
  439.             case 'u':
  440.                 $prefix 'echo urlencode(';
  441.                 $suffix ')';
  442.                 break;
  443.             case 'r':
  444.                 $prefix 'echo \'<pre>\'; echo htmlspecialchars(print_r(';
  445.                 $suffix ',true)); echo \'</pre>\';';
  446.                 break;                
  447.             case 'n'
  448.                 // blank or value..
  449.                 $numberformat @$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'];
  450.                 $prefix 'echo number_format(';
  451.                 $suffix $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'')';
  452.                 break;
  453.             case 'b'// nl2br + htmlspecialchars
  454.                 $prefix 'echo nl2br(htmlspecialchars(';
  455.                 
  456.                 // add language ?
  457.                 $suffix '))';
  458.                 break;
  459.             default:
  460.                 $prefix 'echo htmlspecialchars(';
  461.                 // add language ?
  462.                 $suffix ')';
  463.         }
  464.         
  465.         return array($prefix,$suffix);
  466.     }
  467.  
  468.  
  469.  
  470.   /**
  471.     *   HTML_Template_Flexy_Token_Var toString
  472.     *
  473.     * @param    object    HTML_Template_Flexy_Token_Method 
  474.     * 
  475.     * @return   string     string to build a template
  476.     * @access   public
  477.     * @see      toString*
  478.     */
  479.   
  480.     function toStringVar($element
  481.     {
  482.         // ignore modifier at present!!
  483.         
  484.         $var $element->toVar($element->value);
  485.         if (is_a($var,'PEAR_Error')) {
  486.             return $var;
  487.         }
  488.         list($prefix,$suffix$this->getModifierWrapper($element);
  489.         return $this->appendPhp$prefix $var $suffix .';');
  490.     }
  491.    /**
  492.     *   HTML_Template_Flexy_Token_Method toString
  493.     *
  494.     * @param    object    HTML_Template_Flexy_Token_Method 
  495.     * 
  496.     * @return   string     string to build a template
  497.     * @access   public
  498.     * @see      toString*
  499.     */
  500.   
  501.     function toStringMethod($element
  502.     {
  503.  
  504.               
  505.         // set up the modifier at present!!
  506.         list($prefix,$suffix$this->getModifierWrapper($element);
  507.         
  508.         // add the '!' to if
  509.         
  510.         if ($element->isConditional{
  511.             $prefix 'if ('.$element->isNegative;
  512.             $element->pushState();
  513.             $suffix ')';
  514.         }  
  515.         
  516.         
  517.         // check that method exists..
  518.         // if (method_exists($object,'method');
  519.         $bits explode('.',$element->method);
  520.         $method array_pop($bits);
  521.         
  522.         $object implode('.',$bits);
  523.         
  524.         $var $element->toVar($object);
  525.         if (is_a($var,'PEAR_Error')) {
  526.             return $var;
  527.         }
  528.         
  529.         if (($object == 'GLOBALS'&& 
  530.             $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globalfunctions']{
  531.             // we should check if they something weird like: GLOBALS.xxxx[sdf](....)
  532.             $var $method;
  533.         else {
  534.             $prefix 'if (isset('.$var.
  535.                 ') && method_exists('.$var .",'{$method}')) " . $prefix;
  536.             $var $element->toVar($element->method);
  537.         }
  538.         
  539.  
  540.         if (is_a($var,'PEAR_Error')) {
  541.             return $var;
  542.         }
  543.         
  544.         $ret  =  $prefix;
  545.         $ret .=  $var "(";
  546.         $s =0;
  547.          
  548.        
  549.          
  550.         foreach($element->args as $a{
  551.              
  552.             if ($s{
  553.                 $ret .= ",";
  554.             }
  555.             $s =1;
  556.             if ($a{0== '#'{
  557.                 $ret .= '"'addslashes(substr($a,1,-1)) '"';
  558.                 continue;
  559.             }
  560.             
  561.             $var $element->toVar($a);
  562.             if (is_a($var,'PEAR_Error')) {
  563.                 return $var;
  564.             }
  565.             $ret .= $var;
  566.             
  567.         }
  568.         $ret .= ")" $suffix;
  569.         
  570.         if ($element->isConditional{
  571.             $ret .= ' { ';
  572.         else {
  573.             $ret .= ";";
  574.         }
  575.         
  576.         
  577.         
  578.         return $this->appendPhp($ret)
  579.         
  580.          
  581.  
  582.    }
  583.    /**
  584.     *   HTML_Template_Flexy_Token_Processing toString
  585.     *
  586.     * @param    object    HTML_Template_Flexy_Token_Processing 
  587.     * 
  588.     * @return   string     string to build a template
  589.     * @access   public
  590.     * @see      toString*
  591.     */
  592.  
  593.  
  594.     function toStringProcessing($element
  595.     {
  596.         // if it's XML then quote it..
  597.         if (strtoupper(substr($element->value,2,3)) == 'XML'
  598.             return $this->appendPhp("echo '" str_replace("'","\\"."'"$element->value"';");
  599.         }
  600.         // otherwise it's PHP code - so echo it..
  601.         return $element->value;
  602.     }
  603.     
  604.     /**
  605.     *   HTML_Template_Flexy_Token_Text toString
  606.     *
  607.     * @param    object    HTML_Template_Flexy_Token_Text 
  608.     * 
  609.     * @return   string     string to build a template
  610.     * @access   public
  611.     * @see      toString*
  612.     */
  613.  
  614.  
  615.  
  616.     function toStringText($element
  617.     {
  618.         // if it's XML then quote it..
  619.         
  620.         /**
  621.         * Global variable for gettext replacement
  622.         * static object vars will be nice in PHP5 :)
  623.         *
  624.         * @var array
  625.         * @access private
  626.         */
  627.         global $_HTML_TEMPLATE_FLEXY_COMPILER;
  628.         
  629.         $gettextStrings &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
  630.         
  631.         static $cleanArray = array(
  632.             '$' => '\$',
  633.             '"' => '\"',
  634.             "'" => '\\\'',
  635.             '\\' => '\\\\',
  636.             "\n" => '\n',
  637.             "\t" => '\t',
  638.             "\r" => '\r'
  639.         );
  640.         static $uncleanArray = false;
  641.         if (!$uncleanArray {
  642.             $uncleanArray = array_flip($cleanArray);
  643.         }
  644.  
  645.          
  646.         if (!strlen(trim($element->value) )) {
  647.             return $this->appendHtml($element->value);
  648.         }
  649.         // dont add comments to translation lists.
  650.          
  651.         if (substr($element->value,0,4== '<!--'{
  652.             return $this->appendHtml($element->value);
  653.         }
  654.         if (!count($element->argTokens&& !$element->isWord()) {
  655.             return $this->appendHtml($element->value);
  656.         }
  657.         
  658.         // ignore anything wrapped with {_( .... )_}
  659.         if ($this->inGetTextBlock{
  660.             return $this->appendHtml($element->value);
  661.         }
  662.         
  663.         $front '';
  664.         $rear '';
  665.         // trim whitespace front
  666.         for ($i=0;$i<strlen($element->value)$i++{
  667.             if (strpos(" \n\t\r\0\x0B"$element->value{$i}!== false{
  668.                 $front .= $element->value{$i};
  669.                 continue;
  670.             }
  671.             break;
  672.         }
  673.         // trim whitespace rear 
  674.         for ($i=strlen($element->value)-1;$i>-1; $i--{
  675.             if (strpos(" \n\t\r\0\x0B"$element->value{$i}!== false{
  676.                 $rear $element->value{$i$rear;
  677.                 continue;
  678.             }
  679.             break;            
  680.         }
  681.         
  682.         $value trim($element->value);
  683.         
  684.         
  685.         // convert to escaped chars.. (limited..)
  686.         $value strtr($value,$cleanArray);
  687.         
  688.         
  689.         // its a simple word!
  690.         if (!count($element->argTokens)) {
  691.             $gettextStrings[$value;
  692.             $value $this->translateString($value);
  693.             $value strtr($value,$uncleanArray);
  694.         
  695.             return $this->appendHtml($front .  $value  $rear);
  696.         }
  697.         
  698.         
  699.         // there are subtokens..
  700.         // print_r($element->argTokens );
  701.         $args = array();
  702.         $argsMake '';
  703.         // these should only be text or vars..
  704.         foreach($element->argTokens as $i=>$token{
  705.             $args[$token->compile($this);
  706.         }
  707.         
  708.         $gettextStrings[$value;
  709.         $value $this->translateString($value);
  710.         $value strtr($value,$uncleanArray);
  711.         
  712.         $bits explode('%s',$value);
  713.         $ret $front;
  714.         foreach($bits as $i=>$v{
  715.             $ret.=$v.@$args[$i];
  716.         }
  717.         
  718.         return  $ret $rear;
  719.         
  720.     }
  721.     
  722.     /**
  723.     * translateString - a gettextWrapper
  724.     *
  725.     * tries to do gettext or falls back on File_Gettext
  726.     * This has !!!NO!!! error handling - if it fails you just get english..
  727.     * no questions asked!!!
  728.     * 
  729.     * @param   string       string to translate
  730.     *
  731.     * @return   string      translated string..
  732.     * @access   public
  733.     */
  734.   
  735.     function translateString($string)
  736.     {
  737.          
  738.         
  739.         
  740.         if (is_a($this->options['Translation2'],'Translation2')) {
  741.             $result $this->options['Translation2']->get($string);
  742.             if (!empty($result)) {
  743.                 return $result;
  744.             }
  745.             return $string;
  746.         }
  747.         
  748.         
  749.         
  750.         $prefix basename($GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']).':';
  751.         if (@$this->options['debug']{
  752.             echo __CLASS__.":TRANSLATING $string<BR>";
  753.         }
  754.         if (function_exists('gettext'&& !$this->options['textdomain']{
  755.             if (@$this->options['debug']{
  756.                 echo __CLASS__.":USING GETTEXT?<BR>";
  757.             }
  758.             $t gettext($string);
  759.             if ($t != $string{
  760.                 return $t;
  761.             }
  762.             $tt gettext($prefix.$string);
  763.             if ($tt != $prefix.$string{
  764.                 return $tt;
  765.             }
  766.             // give up it's not translated anywhere...
  767.             return $t;
  768.              
  769.         }
  770.         if (!$this->options['textdomain'|| !$this->options['textdomainDir']{
  771.             // text domain is not set..
  772.             if (@$this->options['debug']{
  773.                 echo __CLASS__.":MISSING textdomain settings<BR>";
  774.             }
  775.             return $string;
  776.         }
  777.         $pofile $this->options['textdomainDir'
  778.                 '/' $this->options['locale'
  779.                 '/LC_MESSAGES/' $this->options['textdomain''.po';
  780.         
  781.         
  782.         // did we try to load it already..
  783.         if (@$GLOBALS['_'.__CLASS__]['PO'][$pofile=== false{
  784.             if (@$this->options['debug']{
  785.                 echo __CLASS__.":LOAD failed (Cached):<BR>";
  786.             }
  787.             return $string;
  788.         }
  789.         if (!@$GLOBALS['_'.__CLASS__]['PO'][$pofile]{
  790.             // default - cant load it..
  791.             $GLOBALS['_'.__CLASS__]['PO'][$pofile= false;
  792.             if (!file_exists($pofile)) {
  793.                  if (@$this->options['debug']{
  794.                 echo __CLASS__.":LOAD failed: {$pofile}<BR>";
  795.             }
  796.                 return $string;
  797.             }
  798.             
  799.             if (!@include_once 'File/Gettext.php'{
  800.                 if (@$this->options['debug']{
  801.                     echo __CLASS__.":LOAD no File_gettext:<BR>";
  802.                 }
  803.                 return $string;
  804.             }
  805.             
  806.             $GLOBALS['_'.__CLASS__]['PO'][$pofile= File_Gettext::factory('PO',$pofile);
  807.             $GLOBALS['_'.__CLASS__]['PO'][$pofile]->load();
  808.             //echo '<PRE>'.htmlspecialchars(print_r($GLOBALS['_'.__CLASS__]['PO'][$pofile]->strings,true));
  809.             
  810.         }
  811.         $po &$GLOBALS['_'.__CLASS__]['PO'][$pofile];
  812.         // we should have it loaded now...
  813.         // this is odd - data is a bit messed up with CR's
  814.         $string str_replace('\n',"\n",$string);
  815.         
  816.         if (isset($po->strings[$prefix.$string])) {
  817.             return $po->strings[$prefix.$string];
  818.         }
  819.         
  820.         if (!isset($po->strings[$string])) {
  821.             if (@$this->options['debug']{
  822.                     echo __CLASS__.":no match:<BR>";
  823.             }
  824.             return $string;
  825.         }
  826.         if (@$this->options['debug']{
  827.             echo __CLASS__.":MATCHED: {$po->strings[$string]}<BR>";
  828.         }
  829.         
  830.         // finally we have a match!!!
  831.         return $po->strings[$string];
  832.         
  833.     
  834.      /**
  835.     *   HTML_Template_Flexy_Token_Tag toString
  836.     *
  837.     * @param    object    HTML_Template_Flexy_Token_Tag 
  838.     * 
  839.     * @return   string     string to build a template
  840.     * @access   public
  841.     * @see      toString*
  842.     */
  843.   
  844.     function toStringTag($element{
  845.         if (strpos($element->tag,':'=== false{
  846.             $namespace 'Tag';
  847.         else {
  848.             $bits =  explode(':',$element->tag);
  849.             $namespace $bits[0];
  850.         }
  851.         if ($namespace{0== '/'{
  852.             return '';
  853.         }
  854.         if (empty($this->tagHandlers[$namespace])) {
  855.             
  856.             require_once 'HTML/Template/Flexy/Compiler/Standard/Tag.php';
  857.             $this->tagHandlers[$namespace&HTML_Template_Flexy_Compiler_Standard_Tag::factory($namespace,$this);
  858.             if (!$this->tagHandlers[$namespace{
  859.                 return PEAR::raiseError('HTML_Template_Flexy::failed to create Namespace Handler '.$namespace 
  860.                     ' in file ' $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'],
  861.                     HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,PEAR_ERROR_RETURN);
  862.             }
  863.                 
  864.         }
  865.         return $this->tagHandlers[$namespace]->toString($element);
  866.         
  867.         
  868.     }
  869.     
  870.  
  871. }

Documentation generated on Mon, 11 Mar 2019 10:15:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.