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.26 2004/04/22 03:48:53 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.         if (is_a($res,'PEAR_Error')) {
  154.             return $res;
  155.         }   
  156.         // turn tokens into Template..
  157.         
  158.         $data $res->compile($this);
  159.         
  160.         if (is_a($data,'PEAR_Error')) {
  161.             return $data;
  162.         }
  163.         
  164.         
  165.         if (   @$this->options['debug']{
  166.             echo "<B>Result: </B><PRE>".htmlspecialchars($data)."</PRE><BR>";
  167.             
  168.         }
  169.  
  170.         if ($this->options['nonHTML']{
  171.            $data =  str_replace("?>\n","?>\n\n",$data);
  172.         }
  173.         
  174.          
  175.         
  176.         
  177.         // at this point we are into writing stuff...
  178.         if ($this->options['compileToString']{
  179.             $flexy->elements =  $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'];
  180.             return $data;
  181.         }
  182.         
  183.         
  184.         
  185.         
  186.         // error checking?
  187.         if( ($cfp fopen$flexy->compiledTemplate 'w' )) ) {
  188.             if (@$this->options['debug']{
  189.                 echo "<B>Writing: </B>".htmlspecialchars($data)."<BR>";
  190.                 
  191.             }
  192.             fwrite($cfp,$data);
  193.             fclose($cfp);
  194.              chmod($flexy->compiledTemplate,0775);
  195.             // make the timestamp of the two items match.
  196.             clearstatcache();
  197.             touch($flexy->compiledTemplatefilemtime($flexy->currentTemplate));
  198.             
  199.         else {
  200.             return PEAR::raiseError('HTML_Template_Flexy::failed to write to '.$flexy->compiledTemplate,
  201.                 HTML_TEMPLATE_FLEXY_ERROR_FILE ,PEAR_ERROR_RETURN);
  202.         }
  203.         // gettext strings
  204.         if (file_exists($flexy->getTextStringsFile)) {
  205.             unlink($flexy->getTextStringsFile);
  206.         }
  207.         
  208.         if($gettextStrings && ($cfp fopen$flexy->getTextStringsFile'w') ) ) {
  209.             
  210.             fwrite($cfp,serialize(array_unique($gettextStrings)));
  211.             fclose($cfp);
  212.         }
  213.         
  214.         // elements
  215.         if (file_exists($flexy->elementsFile)) {
  216.             unlink($flexy->elementsFile);
  217.         }
  218.         
  219.         if$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'&&
  220.             ($cfp fopen$flexy->elementsFile'w') ) ) {
  221.             fwrite($cfp,serialize$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']));
  222.             fclose($cfp);
  223.             // now clear it.
  224.         
  225.         }
  226.         
  227.         return true;
  228.     }
  229.     
  230.     /**
  231.     * Flag indicating compiler is inside {_( .... )_} block, and should not
  232.     * add to the gettextstrings array.
  233.     *
  234.     * @var boolean 
  235.     * @access public
  236.     */
  237.     var $inGetTextBlock = false;
  238.     
  239.     /**
  240.     * This is the base toString Method, it relays into toString{TokenName}
  241.     *
  242.     * @param    object    HTML_Template_Flexy_Token_* 
  243.     * 
  244.     * @return   string     string to build a template
  245.     * @access   public
  246.     * @see      toString*
  247.     */
  248.   
  249.  
  250.     function toString($element
  251.     {
  252.         static $len = 26; // strlen('HTML_Template_Flexy_Token_');
  253.         if ($this->options['debug']{
  254.             $x $element;
  255.             unset($x->children);
  256.             echo htmlspecialchars(print_r($x,true))."<BR>\n";
  257.         }
  258.         if ($element->token == 'GetTextStart'{
  259.             $this->inGetTextBlock = true;
  260.             return '';
  261.         }
  262.         if ($element->token == 'GetTextEnd'{
  263.             $this->inGetTextBlock = false;
  264.             return '';
  265.         }
  266.         
  267.             
  268.         $class get_class($element);
  269.         if (strlen($class>= $len{
  270.             $type substr($class,$len);
  271.             return $this->{'toString'.$type}($element);
  272.         }
  273.         
  274.         $ret $element->value;
  275.         $add $element->compileChildren($this);
  276.         if (is_a($add,'PEAR_Error')) {
  277.             return $add;
  278.         }
  279.         $ret .= $add;
  280.         
  281.         if ($element->close{
  282.             $add $element->close->compile($this);
  283.             if (is_a($add,'PEAR_Error')) {
  284.                 return $add;
  285.             }
  286.             $ret .= $add;
  287.         }
  288.         
  289.         return $ret;
  290.     }
  291.  
  292.  
  293.     /**
  294.     *   HTML_Template_Flexy_Token_Else toString
  295.     *
  296.     * @param    object    HTML_Template_Flexy_Token_Else 
  297.     * 
  298.     * @return   string     string to build a template
  299.     * @access   public
  300.     * @see      toString*
  301.     */
  302.   
  303.  
  304.     function toStringElse($element
  305.      {
  306.         // pushpull states to make sure we are in an area.. - should really check to see 
  307.         // if the state it is pulling is a if...
  308.         if ($element->pullState(=== false{
  309.             return $this->appendHTML(
  310.                 "<font color=\"red\">Unmatched {else:} on line: {$element->line}</font>"
  311.                 );
  312.         }
  313.         $element->pushState();
  314.         return $this->appendPhp("} else {");
  315.     }
  316.     
  317.     /**
  318.     *   HTML_Template_Flexy_Token_End toString
  319.     *
  320.     * @param    object    HTML_Template_Flexy_Token_Else 
  321.     * 
  322.     * @return   string     string to build a template
  323.     * @access   public
  324.     * @see      toString*
  325.     */
  326.   
  327.     function toStringEnd($element
  328.     {
  329.         // pushpull states to make sure we are in an area.. - should really check to see 
  330.         // if the state it is pulling is a if...
  331.         if ($element->pullState(=== false{
  332.             return $this->appendHTML(
  333.                 "<font color=\"red\">Unmatched {end:} on line: {$element->line}</font>"
  334.                 );
  335.         }
  336.          
  337.         return $this->appendPhp("}");
  338.     }
  339.  
  340.     /**
  341.     *   HTML_Template_Flexy_Token_EndTag toString
  342.     *
  343.     * @param    object    HTML_Template_Flexy_Token_EndTag 
  344.     * 
  345.     * @return   string     string to build a template
  346.     * @access   public
  347.     * @see      toString*
  348.     */
  349.   
  350.  
  351.  
  352.     function toStringEndTag($element
  353.     {
  354.         return $this->toStringTag($element);
  355.     }
  356.         
  357.     
  358.     
  359.     /**
  360.     *   HTML_Template_Flexy_Token_Foreach toString
  361.     *
  362.     * @param    object    HTML_Template_Flexy_Token_Foreach 
  363.     * 
  364.     * @return   string     string to build a template
  365.     * @access   public
  366.     * @see      toString*
  367.     */
  368.   
  369.     
  370.     function toStringForeach($element
  371.     {
  372.     
  373.         $loopon $element->toVar($element->loopOn);
  374.         if (is_a($loopon,'PEAR_Error')) {
  375.             return $loopon;
  376.         }
  377.         
  378.         $ret 'if (is_array('$loopon")  || " .
  379.             'is_object(' $loopon  ')) ' .
  380.             'foreach(' $loopon  " ";
  381.             
  382.         $ret .= "as \${$element->key}";
  383.         
  384.         if ($element->value{
  385.             $ret .=  " => \${$element->value}";
  386.         }
  387.         $ret .= ") {";
  388.         
  389.         $element->pushState();
  390.         $element->pushVar($element->key);
  391.         $element->pushVar($element->value);
  392.         return $this->appendPhp($ret);
  393.     }
  394.     /**
  395.     *   HTML_Template_Flexy_Token_If toString
  396.     *
  397.     * @param    object    HTML_Template_Flexy_Token_If 
  398.     * 
  399.     * @return   string     string to build a template
  400.     * @access   public
  401.     * @see      toString*
  402.     */
  403.   
  404.     function toStringIf($element
  405.     {
  406.         
  407.         $var $element->toVar($element->condition);
  408.         if (is_a($var,'PEAR_Error')) {
  409.             return $var;
  410.         }
  411.         
  412.         $ret "if (".$element->isNegative . $var .")  {";
  413.         $element->pushState();
  414.         return $this->appendPhp($ret);
  415.     }
  416.  
  417.    /**
  418.     *  get Modifier Wrapper
  419.     *
  420.     * converts :h, :u, :r , .....
  421.     * @param    object    HTML_Template_Flexy_Token_Method|Var
  422.     * 
  423.     * @return   array prefix,suffix
  424.     * @access   public
  425.     * @see      toString*
  426.     */
  427.  
  428.     function getModifierWrapper($element
  429.     {
  430.         $prefix 'echo ';
  431.         
  432.         $suffix '';
  433.         $modifier $element->modifier . ' ';
  434.         switch ($modifier{0}{
  435.             case 'h':
  436.                 break;
  437.             case 'u':
  438.                 $prefix 'echo urlencode(';
  439.                 $suffix ')';
  440.                 break;
  441.             case 'r':
  442.                 $prefix 'echo \'<pre>\'; echo htmlspecialchars(print_r(';
  443.                 $suffix ',true)); echo \'</pre>\';';
  444.                 break;                
  445.             case 'n'
  446.                 // blank or value..
  447.                 $numberformat @$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'];
  448.                 $prefix 'echo number_format(';
  449.                 $suffix $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'')';
  450.                 break;
  451.             case 'b'// nl2br + htmlspecialchars
  452.                 $prefix 'echo nl2br(htmlspecialchars(';
  453.                 
  454.                 // add language ?
  455.                 $suffix '))';
  456.                 break;
  457.             default:
  458.                 $prefix 'echo htmlspecialchars(';
  459.                 // add language ?
  460.                 $suffix ')';
  461.         }
  462.         
  463.         return array($prefix,$suffix);
  464.     }
  465.  
  466.  
  467.  
  468.   /**
  469.     *   HTML_Template_Flexy_Token_Var toString
  470.     *
  471.     * @param    object    HTML_Template_Flexy_Token_Method 
  472.     * 
  473.     * @return   string     string to build a template
  474.     * @access   public
  475.     * @see      toString*
  476.     */
  477.   
  478.     function toStringVar($element
  479.     {
  480.         // ignore modifier at present!!
  481.         
  482.         $var $element->toVar($element->value);
  483.         if (is_a($var,'PEAR_Error')) {
  484.             return $var;
  485.         }
  486.         list($prefix,$suffix$this->getModifierWrapper($element);
  487.         return $this->appendPhp$prefix $var $suffix .';');
  488.     }
  489.    /**
  490.     *   HTML_Template_Flexy_Token_Method toString
  491.     *
  492.     * @param    object    HTML_Template_Flexy_Token_Method 
  493.     * 
  494.     * @return   string     string to build a template
  495.     * @access   public
  496.     * @see      toString*
  497.     */
  498.   
  499.     function toStringMethod($element
  500.     {
  501.  
  502.               
  503.         // set up the modifier at present!!
  504.         list($prefix,$suffix$this->getModifierWrapper($element);
  505.         
  506.         // add the '!' to if
  507.         
  508.         if ($element->isConditional{
  509.             $prefix 'if ('.$element->isNegative;
  510.             $element->pushState();
  511.             $suffix ')';
  512.         }  
  513.         
  514.         
  515.         // check that method exists..
  516.         // if (method_exists($object,'method');
  517.         $bits explode('.',$element->method);
  518.         $method array_pop($bits);
  519.         
  520.         $object implode('.',$bits);
  521.         
  522.         $var $element->toVar($object);
  523.         if (is_a($var,'PEAR_Error')) {
  524.             return $var;
  525.         }
  526.         
  527.         if (($object == 'GLOBALS'&& 
  528.             $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globalfunctions']{
  529.             // we should check if they something weird like: GLOBALS.xxxx[sdf](....)
  530.             $var $method;
  531.         else {
  532.             $prefix 'if (isset('.$var.
  533.                 ') && method_exists('.$var .",'{$method}')) " . $prefix;
  534.             $var $element->toVar($element->method);
  535.         }
  536.         
  537.  
  538.         if (is_a($var,'PEAR_Error')) {
  539.             return $var;
  540.         }
  541.         
  542.         $ret  =  $prefix;
  543.         $ret .=  $var "(";
  544.         $s =0;
  545.          
  546.        
  547.          
  548.         foreach($element->args as $a{
  549.              
  550.             if ($s{
  551.                 $ret .= ",";
  552.             }
  553.             $s =1;
  554.             if ($a{0== '#'{
  555.                 $ret .= '"'addslashes(substr($a,1,-1)) '"';
  556.                 continue;
  557.             }
  558.             
  559.             $var $element->toVar($a);
  560.             if (is_a($var,'PEAR_Error')) {
  561.                 return $var;
  562.             }
  563.             $ret .= $var;
  564.             
  565.         }
  566.         $ret .= ")" $suffix;
  567.         
  568.         if ($element->isConditional{
  569.             $ret .= ' { ';
  570.         else {
  571.             $ret .= ";";
  572.         }
  573.         
  574.         
  575.         
  576.         return $this->appendPhp($ret)
  577.         
  578.          
  579.  
  580.    }
  581.    /**
  582.     *   HTML_Template_Flexy_Token_Processing toString
  583.     *
  584.     * @param    object    HTML_Template_Flexy_Token_Processing 
  585.     * 
  586.     * @return   string     string to build a template
  587.     * @access   public
  588.     * @see      toString*
  589.     */
  590.  
  591.  
  592.     function toStringProcessing($element
  593.     {
  594.         // if it's XML then quote it..
  595.         if (strtoupper(substr($element->value,2,3)) == 'XML'
  596.             return $this->appendPhp("echo '" str_replace("'","\\"."'"$element->value"';");
  597.         }
  598.         // otherwise it's PHP code - so echo it..
  599.         return $element->value;
  600.     }
  601.     
  602.     /**
  603.     *   HTML_Template_Flexy_Token_Text toString
  604.     *
  605.     * @param    object    HTML_Template_Flexy_Token_Text 
  606.     * 
  607.     * @return   string     string to build a template
  608.     * @access   public
  609.     * @see      toString*
  610.     */
  611.  
  612.  
  613.  
  614.     function toStringText($element
  615.     {
  616.         // if it's XML then quote it..
  617.         
  618.         /**
  619.         * Global variable for gettext replacement
  620.         * static object vars will be nice in PHP5 :)
  621.         *
  622.         * @var array
  623.         * @access private
  624.         */
  625.         global $_HTML_TEMPLATE_FLEXY_COMPILER;
  626.         
  627.         $gettextStrings &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
  628.         
  629.         static $cleanArray = array(
  630.             '$' => '\$',
  631.             '"' => '\"',
  632.             "'" => '\\\'',
  633.             '\\' => '\\\\',
  634.             "\n" => '\n',
  635.             "\t" => '\t',
  636.             "\r" => '\r'
  637.         );
  638.         static $uncleanArray = false;
  639.         if (!$uncleanArray {
  640.             $uncleanArray = array_flip($cleanArray);
  641.         }
  642.  
  643.          
  644.         if (!strlen(trim($element->value) )) {
  645.             return $this->appendHtml($element->value);
  646.         }
  647.         // dont add comments to translation lists.
  648.          
  649.         if (substr($element->value,0,4== '<!--'{
  650.             return $this->appendHtml($element->value);
  651.         }
  652.         if (!count($element->argTokens&& !$element->isWord()) {
  653.             return $this->appendHtml($element->value);
  654.         }
  655.         
  656.         // ignore anything wrapped with {_( .... )_}
  657.         if ($this->inGetTextBlock{
  658.             return $this->appendHtml($element->value);
  659.         }
  660.         
  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:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.