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

Source for file Text.php

Documentation is available at Text.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>                               |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Text.php,v 1.9 2004/02/26 14:20:45 alan_k Exp $
  20. //
  21.  
  22.  
  23. /**
  24. * Class to Text - implements gettext support.
  25. *
  26. */
  27.  
  28. class HTML_Template_Flexy_Token_Text extends HTML_Template_Flexy_Token {
  29.      
  30.       
  31.     
  32.       
  33.       
  34.     /**
  35.     * List of argument tokens.
  36.     *
  37.     * @var array 
  38.     * @access public
  39.     */
  40.     var $argTokens = array();
  41.     
  42.     /**
  43.     * Search backwards for whitespace and flexy tags to add to string.
  44.     *
  45.     * @return   none 
  46.     * @access   public
  47.     */
  48.   
  49.     function backSearch(&$tokens{
  50.         // if this is an empty string ignore it?
  51.         if (!strlen(trim($this->value))) {
  52.             return;
  53.         }
  54.         
  55.         
  56.         $i $this->id -1;
  57.         while ($i > 0{
  58.             if (empty($tokens[$i])) {
  59.                 return;
  60.             }
  61.             $token $tokens[$i];
  62.             
  63.             switch (strtolower(get_class($token))) {
  64.                 case 'html_template_flexy_token_text';
  65.                     if ($tokens[$i]->value == ''{
  66.                         break;
  67.                     }
  68.                     $this->value $token->value . $this->value;
  69.                     $tokens[$i]->value = ''// blank it..
  70.                     break;
  71.                     
  72.                 //case 'html_template_flexy_token_method';
  73.                 case 'html_template_flexy_token_var';
  74.                     $this->value '%s'$this->value;
  75.                     // copy token into argTokens
  76.                     array_unshift($this->argTokens,$token);
  77.                     // make the old token blank..
  78.                     $tokens[$i= HTML_Template_Flexy_Token::factory('Text','',$tokens[$i]->line);
  79.                     break;
  80.                
  81.                 default:
  82.                     // found a stop point.
  83.                     return;
  84.             }
  85.             $i--;
  86.         }
  87.     
  88.     }
  89.     /**
  90.     * Search forwards for whitespace and flexy tags to add to string.
  91.     *
  92.     * @param   int - id of last tag
  93.     * @return   int - id of next tag.
  94.     * @access   public
  95.     */
  96.     
  97.     function forwardSearch(&$tokens{
  98.         $max count($tokens);
  99.         
  100.         $i $this->id +1;
  101.         while ($i $max{
  102.         
  103.             $token $tokens[$i];
  104.             
  105.             switch (strtolower(get_class($token))) {
  106.                 case 'html_template_flexy_token_text';
  107.                     if ($tokens[$i]->value == ''{
  108.                         break;
  109.                     }
  110.                     $this->value .= $token->value;
  111.                     $tokens[$i]->value = '';
  112.                     break;
  113.                     
  114.                 //case 'html_template_flexy_token_method';
  115.                 case 'html_template_flexy_token_var';
  116.                     $this->value .= '%s';
  117.                     $this->argTokens[$token;
  118.                     $tokens[$i= HTML_Template_Flexy_Token::factory('Text','',$tokens[$i]->line);
  119.                     break;
  120.                 default:
  121.                     return $i - 1;
  122.             }
  123.             $i++;
  124.         }
  125.         return $i - 1;
  126.     }
  127.      /**
  128.     * Simple check to see if this piece of text is a word
  129.     * so that gettext and the merging tricks dont try
  130.     * - merge white space with a flexy tag
  131.     * - gettext doesnt translate &nbsp; etc.
  132.     *
  133.     * @return   boolean  true if this is a word
  134.     * @access   public
  135.     */
  136.     function isWord({
  137.         if (!strlen(trim($this->value))) {
  138.             return false;
  139.         }
  140.         if (preg_match('/^\&[a-z0-9]+;$/i',trim($this->value))) {
  141.             return false;
  142.         }
  143.         return  preg_match('/[a-z]/i',$this->value);
  144.     }
  145.      
  146. }

Documentation generated on Mon, 11 Mar 2019 13:54:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.