Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/filter/output.php

Documentation is available at output.php

  1. <?php
  2. /**
  3.  * @version        $Id: functions.php 4277 2006-07-19 20:35:35Z friesengeist $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Filter
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant to the
  9.  *  GNU General Public License, and as distributed it includes or is derivative
  10.  *  of works licensed under the GNU General Public License or other free or open
  11.  *  source software licenses. See COPYRIGHT.php for copyright notices and
  12.  *  details.
  13.  */
  14.  
  15. /**
  16.  * JOutputFilter
  17.  *
  18.  * @static
  19.  * @author        Louis Landry <[email protected]>
  20.  * @package     Joomla.Framework
  21.  * @subpackage    Filter
  22.  * @since        1.5
  23.  */
  24. {
  25.     /**
  26.     * Makes an object safe to display in forms
  27.     *
  28.     * Object parameters that are non-string, array, object or start with underscore
  29.     * will be converted
  30.     *
  31.     * @static
  32.     * @param object An object to be parsed
  33.     * @param int The optional quote style for the htmlspecialchars function
  34.     * @param string|arrayAn optional single field name or array of field names not
  35.     *                      to be parsed (eg, for a textarea)
  36.     * @since 1.5
  37.     */
  38.     function objectHTMLSafe&$mixed$quote_style=ENT_QUOTES$exclude_keys='' )
  39.     {
  40.         if (is_object$mixed ))
  41.         {
  42.             foreach (get_object_vars$mixed as $k => $v)
  43.             {
  44.                 if (is_array$v || is_object$v || $v == NULL || substr$k1== '_' {
  45.                     continue;
  46.                 }
  47.  
  48.                 if (is_string$exclude_keys && $k == $exclude_keys{
  49.                     continue;
  50.                 else if (is_array$exclude_keys && in_array$k$exclude_keys )) {
  51.                     continue;
  52.                 }
  53.  
  54.                 $mixed->$k htmlspecialchars$v$quote_style );
  55.             }
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * This method processes a string and replaces all instances of & with &amp; in links only
  61.      *
  62.      * @static
  63.      * @param    string    $input    String to process
  64.      * @return    string    Processed string
  65.      * @since    1.5
  66.      */
  67.     function linkXHTMLSafe($input)
  68.     {
  69.         $regex 'href="([^"]*(&(amp;){0})[^"]*)*?"';
  70.         return preg_replace_callback"#$regex#i"array('JOutputFilter''_ampReplaceCallback')$input );
  71.     }
  72.  
  73.     /**
  74.      * This method processes a string all replaces all accented UTF-8 characters by unaccented
  75.      * ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercased.
  76.      *
  77.      * @static
  78.      * @param    string    $input    String to process
  79.      * @return    string    Processed string
  80.      * @since    1.5
  81.      */
  82.     function stringURLSafe($string)
  83.     {
  84.         $str htmlentities(utf8_decode($string));
  85.         $str preg_replace(
  86.             array('/&szlig;/','/&(..)lig;/''/&([aouAOU])uml;/','/&(.)[^;]*;/'),
  87.             array('ss',"$1","$1".'e',"$1"),
  88.             $str);
  89.  
  90.         // remove any duplicate whitespace, and ensure all characters are alphanumeric
  91.         $str preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/')array('-','')$str);
  92.  
  93.         // lowercase and trim
  94.         $str trim(strtolower($str));
  95.         return $str;
  96.     }
  97.  
  98.     /**
  99.     * Replaces &amp; with & for xhtml compliance
  100.     *
  101.     * @todo There must be a better way???
  102.     *
  103.     * @static
  104.     * @since 1.5
  105.     */
  106.     function ampReplace$text )
  107.     {
  108.         $text str_replace'&&''*--*'$text );
  109.         $text str_replace'&#''*-*'$text );
  110.         $text str_replace'&amp;''&'$text );
  111.         $text preg_replace'|&(?![\w]+;)|''&amp;'$text );
  112.         $text str_replace'*-*''&#'$text );
  113.         $text str_replace'*--*''&&'$text );
  114.  
  115.         return $text;
  116.     }
  117.  
  118.  
  119.  
  120.     /**
  121.      * Callback method for replacing & with &amp; in a string
  122.      *
  123.      * @static
  124.      * @param    string    $m    String to process
  125.      * @return    string    Replaced string
  126.      * @since    1.5
  127.      */
  128.     function _ampReplaceCallback$m )
  129.     {
  130.          $rx '&(?!amp;)';
  131.          return preg_replace'#'.$rx.'#''&amp;'$m[0);
  132.     }
  133.  
  134.     /**
  135.     * Cleans text of all formating and scripting code
  136.     */
  137.     function cleanText &$text )
  138.     {
  139.         $text preg_replace"'<script[^>]*>.*?</script>'si"''$text );
  140.         $text preg_replace'/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is''\2 (\1)'$text );
  141.         $text preg_replace'/<!--.+?-->/'''$text );
  142.         $text preg_replace'/{.+?}/'''$text );
  143.         $text preg_replace'/&nbsp;/'' '$text );
  144.         $text preg_replace'/&amp;/'' '$text );
  145.         $text preg_replace'/&quot;/'' '$text );
  146.         $text strip_tags$text );
  147.         $text htmlspecialchars$text );
  148.         return $text;
  149.     }
  150. }
  151. ?>

Documentation generated on Mon, 05 Mar 2007 21:12:25 +0000 by phpDocumentor 1.3.1