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

Source for file SpecialChars.php

Documentation is available at SpecialChars.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Contains the Translation2_Decorator_SpecialChars class
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. The name of the author may not be used to endorse or promote products
  17.  *    derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  20.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * @category  Internationalization
  31.  * @package   Translation2
  32.  * @author    Lorenzo Alberton <l.alberton@quipo.it>
  33.  * @copyright 2004-2007 Lorenzo Alberton
  34.  * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
  35.  * @version   CVS: $Id: SpecialChars.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
  36.  * @link      http://pear.php.net/package/Translation2
  37.  */
  38.  
  39. /**
  40.  * Load Translation2 decorator base class
  41.  */
  42. require_once 'Translation2/Decorator.php';
  43.  
  44. /**
  45.  * Decorator to replace special chars with the matching html entities.
  46.  *
  47.  * You can set the charset to use (the default being 'ISO-8859-1'):
  48.  * <code>
  49.  * $tr->setOptions(array('charset' => 'UTF-8'));
  50.  * </code>
  51.  *
  52.  * @category  Internationalization
  53.  * @package   Translation2
  54.  * @author    Lorenzo Alberton <l.alberton@quipo.it>
  55.  * @copyright 2004-2007 Lorenzo Alberton
  56.  * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
  57.  * @version   CVS: $Id: SpecialChars.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
  58.  * @link      http://pear.php.net/package/Translation2
  59.  * @see       http://www.php.net/htmlentities for a list of available charsets.
  60.  */
  61. {
  62.     // {{{ class vars
  63.  
  64.     /**
  65.      * @var string 
  66.      * @access protected
  67.      */
  68.     var $charset = 'ISO-8859-1';
  69.  
  70.     // }}}
  71.     // {{{ get()
  72.  
  73.     /**
  74.      * Get translated string
  75.      *
  76.      * replace special chars with the matching html entities
  77.      *
  78.      * @param string $stringID    string ID
  79.      * @param string $pageID      page/group ID
  80.      * @param string $langID      language ID
  81.      * @param string $defaultText Text to display when the string is empty
  82.      *
  83.      * @return string 
  84.      */
  85.     function get($stringID$pageID=TRANSLATION2_DEFAULT_PAGEID$langID=null$defaultText=null)
  86.     {
  87.         $str $this->translation2->get($stringID$pageID$langID$defaultText);
  88.         if (PEAR::isError($str)) {
  89.             return $str;
  90.         }
  91.         if (!empty($str)) {
  92.             $str htmlentities($strENT_QUOTES$this->charset);
  93.         }
  94.         return $str;
  95.     }
  96.  
  97.     // }}}
  98.     // {{{ getPage()
  99.  
  100.     /**
  101.      * Same as getRawPage, but apply transformations when needed
  102.      *
  103.      * @param string $pageID page/group ID
  104.      * @param string $langID language ID
  105.      *
  106.      * @return array 
  107.      */
  108.     function getPage($pageID=TRANSLATION2_DEFAULT_PAGEID$langID=null)
  109.     {
  110.         $data $this->translation2->getPage($pageID$langID);
  111.         if (PEAR::isError($data)) {
  112.             return $data;
  113.         }
  114.         foreach ($data as $key => $val{
  115.             if (!empty($val)) {
  116.                 $data[$keyhtmlentities($valENT_QUOTES$this->charset);
  117.             }
  118.         }
  119.         return $data;
  120.     }
  121.  
  122.     // }}}
  123. }
  124. ?>

Documentation generated on Tue, 06 May 2008 06:00:39 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.