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