/src/plugins/system/jhellosef.php
PHP | 196 lines | 106 code | 12 blank | 78 comment | 15 complexity | 202f4c9e504144b32bb92bfbf2d478a0 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
- <?php
- /**
- * @version $Id:jhellosef.php 6961 2009-01-12 19:13:20Z 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)
- {
- /** viet4777: overwriting the text function for alias replacing
- * Joomla! 1.5 checks if a class is already loaded so we can load the whole class and overwrite it :)
- */
- $plugin = & JPluginHelper::getPlugin('system', 'jhellosef');
- $params = new JParameter( $plugin->params );
- $trans2 = $params->get('transformtext','');
- $vi_trans = $params->get('vi_trans',1);
-
- //remove any '-' from the string they will be used as concatonater
- $str = str_replace('-', ' ', $string);
-
- if($vi_trans>0) {
- $trans = array(
- "?"=>"d","?"=>"a","â"=>"a","á"=>"a","ŕ"=>"a","?"=>"a","ă"=>"a","?"=>"a",
- "?"=>"a","?"=>"a","?"=>"a","?"=>"a","?"=>"a",
- "?"=>"a","?"=>"a","?"=>"a","?"=>"a","?"=>"a",
- "é"=>"e","č"=>"e","?"=>"e","?"=>"e","?"=>"e",
- "?"=>"e","?"=>"e","?"=>"e","?"=>"e","?"=>"e",
- "í"=>"i","ě"=>"i","?"=>"i","?"=>"i","?"=>"i",
- "?"=>"u","ô"=>"o","?"=>"o","ę"=>"e",
- "?"=>"u","Ô"=>"o","?"=>"o","Ę"=>"e",
- "ú"=>"u","ů"=>"u","?"=>"u","?"=>"u","?"=>"u",
- "?"=>"u","?"=>"u","?"=>"u","?"=>"u","?"=>"u",
- "ó"=>"o","ň"=>"o","?"=>"o","ő"=>"o","?"=>"o",
- "?"=>"o","?"=>"o","?"=>"o","?"=>"o","?"=>"o",
- "?"=>"o","?"=>"o","?"=>"o","?"=>"o","?"=>"o",
- "ú"=>"u","ů"=>"u","?"=>"u","?"=>"u","?"=>"u",
- "?"=>"u","?"=>"u","?"=>"u","?"=>"u","?"=>"u",'ý'=>'y','?'=>'y','?'=>'y','?'=>'y','?'=>'y', 'Ý'=>'Y','?'=>'Y','?'=>'Y','?'=>'Y','?'=>'Y',
- "?"=>"D","?"=>"A","Â"=>"A","Á"=>"A","Ŕ"=>"A","?"=>"A","Ă"=>"A","?"=>"A",
- "?"=>"A","?"=>"A","?"=>"A","?"=>"A","?"=>"A",
- "?"=>"A","?"=>"A","?"=>"A","?"=>"A","?"=>"A",
- "É"=>"E","Č"=>"E","?"=>"E","?"=>"E","?"=>"E",
- "?"=>"E","?"=>"E","?"=>"E","?"=>"E","?"=>"E",
- "Í"=>"I","Ě"=>"I","?"=>"I","?"=>"I","?"=>"I",
- "?"=>"U","Ô"=>"O","?"=>"O","Ę"=>"E",
- "?"=>"U","Ô"=>"O","?"=>"O","Ę"=>"E",
- "Ú"=>"U","Ů"=>"U","?"=>"U","?"=>"U","?"=>"U",
- "?"=>"U","?"=>"U","?"=>"U","?"=>"U","?"=>"U",
- "Ó"=>"O","Ň"=>"O","?"=>"O","Ő"=>"O","?"=>"O",
- "?"=>"O","?"=>"O","?"=>"O","?"=>"O","?"=>"O",
- "?"=>"O","?"=>"O","?"=>"O","?"=>"O","?"=>"O",
- "Ú"=>"U","Ů"=>"U","?"=>"U","?"=>"U","?"=>"U",
- "?"=>"U","?"=>"U","?"=>"U","?"=>"U","?"=>"U",);
- $str = strtr($str, $trans);
- }
- if($trans2 !='') {
- eval("\$trans2 = array(".$trans2.");");
- $str = strtr($str, $trans2);
- }
- //$str = strtr($str, $trans);
- $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);
- // $str = preg_replace(array('/\s+/', '/\./'), array('-', '_'), $str);
- //$str = utf8_accents_to_ascii($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;
- }
- }