PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/plugins/system/jhellosef.php

http://kak.googlecode.com/
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
  1. <?php
  2. /**
  3. * @version $Id:jhellosef.php 6961 2009-01-12 19:13:20Z tcp $
  4. * @package Joomla.Framework
  5. * @subpackage Filter
  6. * @copyright Copyright (C) 2005 - 2008 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. * JFilterOutput
  16. *
  17. * @static
  18. * @package Joomla.Framework
  19. * @subpackage Filter
  20. * @since 1.5
  21. */
  22. class JFilterOutput
  23. {
  24. /**
  25. * Makes an object safe to display in forms
  26. *
  27. * Object parameters that are non-string, array, object or start with underscore
  28. * will be converted
  29. *
  30. * @static
  31. * @param object An object to be parsed
  32. * @param int The optional quote style for the htmlspecialchars function
  33. * @param string|array An optional single field name or array of field names not
  34. * to be parsed (eg, for a textarea)
  35. * @since 1.5
  36. */
  37. function objectHTMLSafe( &$mixed, $quote_style=ENT_QUOTES, $exclude_keys='' )
  38. {
  39. if (is_object( $mixed ))
  40. {
  41. foreach (get_object_vars( $mixed ) as $k => $v)
  42. {
  43. if (is_array( $v ) || is_object( $v ) || $v == NULL || substr( $k, 1, 1 ) == '_' ) {
  44. continue;
  45. }
  46. if (is_string( $exclude_keys ) && $k == $exclude_keys) {
  47. continue;
  48. } else if (is_array( $exclude_keys ) && in_array( $k, $exclude_keys )) {
  49. continue;
  50. }
  51. $mixed->$k = htmlspecialchars( $v, $quote_style, 'UTF-8' );
  52. }
  53. }
  54. }
  55. /**
  56. * This method processes a string and replaces all instances of & with &amp; in links only
  57. *
  58. * @static
  59. * @param string $input String to process
  60. * @return string Processed string
  61. * @since 1.5
  62. */
  63. function linkXHTMLSafe($input)
  64. {
  65. $regex = 'href="([^"]*(&(amp;){0})[^"]*)*?"';
  66. return preg_replace_callback( "#$regex#i", array('JFilterOutput', '_ampReplaceCallback'), $input );
  67. }
  68. /**
  69. * This method processes a string and replaces all accented UTF-8 characters by unaccented
  70. * ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercased.
  71. *
  72. * @static
  73. * @param string $input String to process
  74. * @return string Processed string
  75. * @since 1.5
  76. */
  77. function stringURLSafe($string)
  78. {
  79. /** viet4777: overwriting the text function for alias replacing
  80. * Joomla! 1.5 checks if a class is already loaded so we can load the whole class and overwrite it :)
  81. */
  82. $plugin = & JPluginHelper::getPlugin('system', 'jhellosef');
  83. $params = new JParameter( $plugin->params );
  84. $trans2 = $params->get('transformtext','');
  85. $vi_trans = $params->get('vi_trans',1);
  86. //remove any '-' from the string they will be used as concatonater
  87. $str = str_replace('-', ' ', $string);
  88. if($vi_trans>0) {
  89. $trans = array(
  90. "?"=>"d","?"=>"a","â"=>"a","á"=>"a","ŕ"=>"a","?"=>"a","ă"=>"a","?"=>"a",
  91. "?"=>"a","?"=>"a","?"=>"a","?"=>"a","?"=>"a",
  92. "?"=>"a","?"=>"a","?"=>"a","?"=>"a","?"=>"a",
  93. "é"=>"e","č"=>"e","?"=>"e","?"=>"e","?"=>"e",
  94. "?"=>"e","?"=>"e","?"=>"e","?"=>"e","?"=>"e",
  95. "í"=>"i","ě"=>"i","?"=>"i","?"=>"i","?"=>"i",
  96. "?"=>"u","ô"=>"o","?"=>"o","ę"=>"e",
  97. "?"=>"u","Ô"=>"o","?"=>"o","Ę"=>"e",
  98. "ú"=>"u","ů"=>"u","?"=>"u","?"=>"u","?"=>"u",
  99. "?"=>"u","?"=>"u","?"=>"u","?"=>"u","?"=>"u",
  100. "ó"=>"o","ň"=>"o","?"=>"o","ő"=>"o","?"=>"o",
  101. "?"=>"o","?"=>"o","?"=>"o","?"=>"o","?"=>"o",
  102. "?"=>"o","?"=>"o","?"=>"o","?"=>"o","?"=>"o",
  103. "ú"=>"u","ů"=>"u","?"=>"u","?"=>"u","?"=>"u",
  104. "?"=>"u","?"=>"u","?"=>"u","?"=>"u","?"=>"u",'ý'=>'y','?'=>'y','?'=>'y','?'=>'y','?'=>'y', 'Ý'=>'Y','?'=>'Y','?'=>'Y','?'=>'Y','?'=>'Y',
  105. "?"=>"D","?"=>"A","Â"=>"A","Á"=>"A","Ŕ"=>"A","?"=>"A","Ă"=>"A","?"=>"A",
  106. "?"=>"A","?"=>"A","?"=>"A","?"=>"A","?"=>"A",
  107. "?"=>"A","?"=>"A","?"=>"A","?"=>"A","?"=>"A",
  108. "É"=>"E","Č"=>"E","?"=>"E","?"=>"E","?"=>"E",
  109. "?"=>"E","?"=>"E","?"=>"E","?"=>"E","?"=>"E",
  110. "Í"=>"I","Ě"=>"I","?"=>"I","?"=>"I","?"=>"I",
  111. "?"=>"U","Ô"=>"O","?"=>"O","Ę"=>"E",
  112. "?"=>"U","Ô"=>"O","?"=>"O","Ę"=>"E",
  113. "Ú"=>"U","Ů"=>"U","?"=>"U","?"=>"U","?"=>"U",
  114. "?"=>"U","?"=>"U","?"=>"U","?"=>"U","?"=>"U",
  115. "Ó"=>"O","Ň"=>"O","?"=>"O","Ő"=>"O","?"=>"O",
  116. "?"=>"O","?"=>"O","?"=>"O","?"=>"O","?"=>"O",
  117. "?"=>"O","?"=>"O","?"=>"O","?"=>"O","?"=>"O",
  118. "Ú"=>"U","Ů"=>"U","?"=>"U","?"=>"U","?"=>"U",
  119. "?"=>"U","?"=>"U","?"=>"U","?"=>"U","?"=>"U",);
  120. $str = strtr($str, $trans);
  121. }
  122. if($trans2 !='') {
  123. eval("\$trans2 = array(".$trans2.");");
  124. $str = strtr($str, $trans2);
  125. }
  126. //$str = strtr($str, $trans);
  127. $lang =& JFactory::getLanguage();
  128. $str = $lang->transliterate($str);
  129. // remove any duplicate whitespace, and ensure all characters are alphanumeric
  130. $str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'), array('-',''), $str);
  131. // $str = preg_replace(array('/\s+/', '/\./'), array('-', '_'), $str);
  132. //$str = utf8_accents_to_ascii($str);
  133. // lowercase and trim
  134. $str = trim(strtolower($str));
  135. return $str;
  136. }
  137. /**
  138. * Replaces &amp; with & for xhtml compliance
  139. *
  140. * @todo There must be a better way???
  141. *
  142. * @static
  143. * @since 1.5
  144. */
  145. function ampReplace( $text )
  146. {
  147. $text = str_replace( '&&', '*--*', $text );
  148. $text = str_replace( '&#', '*-*', $text );
  149. $text = str_replace( '&amp;', '&', $text );
  150. $text = preg_replace( '|&(?![\w]+;)|', '&amp;', $text );
  151. $text = str_replace( '*-*', '&#', $text );
  152. $text = str_replace( '*--*', '&&', $text );
  153. return $text;
  154. }
  155. /**
  156. * Callback method for replacing & with &amp; in a string
  157. *
  158. * @static
  159. * @param string $m String to process
  160. * @return string Replaced string
  161. * @since 1.5
  162. */
  163. function _ampReplaceCallback( $m )
  164. {
  165. $rx = '&(?!amp;)';
  166. return preg_replace( '#'.$rx.'#', '&amp;', $m[0] );
  167. }
  168. /**
  169. * Cleans text of all formating and scripting code
  170. */
  171. function cleanText ( &$text )
  172. {
  173. $text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text );
  174. $text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
  175. $text = preg_replace( '/<!--.+?-->/', '', $text );
  176. $text = preg_replace( '/{.+?}/', '', $text );
  177. $text = preg_replace( '/&nbsp;/', ' ', $text );
  178. $text = preg_replace( '/&amp;/', ' ', $text );
  179. $text = preg_replace( '/&quot;/', ' ', $text );
  180. $text = strip_tags( $text );
  181. $text = htmlspecialchars( $text );
  182. return $text;
  183. }
  184. }