Alpha Framework alpha--util
[ class tree: alpha--util ] [ index: alpha--util ] [ all elements ]

Source for file InputFilter.inc

Documentation is available at InputFilter.inc

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * A filter class for filtering user input from text fields
  6.  * 
  7.  * @package alpha::util
  8.  * @since 1.0
  9.  * @author John Collins <dev@alphaframework.org>
  10.  * @version $Id: InputFilter.inc 1454 2011-12-04 15:14:05Z johnc $
  11.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  12.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  13.  *  All rights reserved.
  14.  * 
  15.  *  <pre>
  16.  *  Redistribution and use in source and binary forms, with or
  17.  *  without modification, are permitted provided that the
  18.  *  following conditions are met:
  19.  * 
  20.  *  * Redistributions of source code must retain the above
  21.  *    copyright notice, this list of conditions and the
  22.  *    following disclaimer.
  23.  *  * Redistributions in binary form must reproduce the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer in the documentation and/or other
  26.  *    materials provided with the distribution.
  27.  *  * Neither the name of the Alpha Framework nor the names
  28.  *    of its contributors may be used to endorse or promote
  29.  *    products derived from this software without specific
  30.  *    prior written permission.
  31.  *   
  32.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  35.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  36.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  37.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  43.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45.  *  </pre>
  46.  *  
  47.  */
  48. class InputFilter {
  49.     /**
  50.      * The encoding method which applies the filters
  51.      * 
  52.      * @param string $text 
  53.      * @param boolean $allowHTML 
  54.      * @return string 
  55.      * @since 1.0
  56.      */
  57.     public static function encode($text$allowHTML=false{
  58.         if(!get_magic_quotes_gpc()) {
  59.             if($allowHTML)
  60.                 return $text;
  61.             else
  62.                 return htmlentities($text);
  63.         }else{
  64.             if($allowHTML)
  65.                 return $text;
  66.             else
  67.                 return htmlentities($text);
  68.         }
  69.     }
  70.     
  71.     /**
  72.      * The decoding method which reverses the filters
  73.      * 
  74.      * @param string $text 
  75.      * @param boolean $allowHTML 
  76.      * @return string 
  77.      * @since 1.0
  78.      */
  79.     public static function decode($text$allowHTML=false{
  80.         if(!get_magic_quotes_gpc())
  81.             if($allowHTML)        
  82.                 return $text;
  83.             else
  84.                 return html_entity_decode($text);
  85.         else
  86.             if($allowHTML)
  87.                 return $text;
  88.             else
  89.                 return html_entity_decode($text);
  90.     }
  91. }
  92.  
  93. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:02 +0000 by phpDocumentor 1.4.3