- md5
- f901a3da23e4343110a756f748302446
- sha1
- ab1ef371c16d3c775d527a89e4330ddb11aba0d0
- sha256
- 70ea745cd34fca28fa34df28d981769f47fa13d1f62333caf89b8762ae9e4fb3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Filter;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Language;
use Joomla\Filter\OutputFilter as BaseOutputFilter;
use Joomla\String\StringHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* OutputFilter
*
* @since 1.7.0
*/
class OutputFilter extends BaseOutputFilter
{
/**
* This method processes a string and replaces all instances of & with & in links only.
*
* @param string $input String to process
*
* @return string Processed string
*
* @since 1.7.0
*/
public static function linkXHTMLSafe($input)
{
$regex = 'href="([^"]*(&(amp;){0})[^"]*)*?"';
return preg_replace_callback("#$regex#i", array('\\Joomla\\CMS\\Filter\\OutputFilter', 'ampReplaceCallback'), $input);
}
/**
* This method processes a string and escapes it for use in JavaScript
*
* @param string $string String to process
*
* @return string Processed text
*/
public static function stringJSSafe($string)
{
$chars = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
$new_str = '';
foreach ($chars as $chr) {
$code = str_pad(dechex(StringHelper::ord($chr)), 4, '0', STR_PAD_LEFT);
if (strlen($code) < 5) {
$new_str .= '\\u' . $code;
} else {
$new_str .= '\\u{' . $code . '}';
}
}
return $new_str;
}
/**
* 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 lowercase.
*
* @param string $string String to process
* @param string $language Language to transliterate to
*
* @return string Processed string
*
* @since 1.7.0
*/
public static function stringURLSafe($string, $language = '')
{
// Remove any '-' from the string since they will be used as concatenaters
$str = str_replace('-', ' ', $string);
// Transliterate on the language requested (fallback to current language if not specified)
$lang = $language == '' || $language == '*' ? Factory::getLanguage() : Language::getInstance($language);
$str = $lang->transliterate($str);
// Trim white spaces at beginning and end of alias and make lowercase
$str = trim(StringHelper::strtolower($str));
// Remove any apostrophe. We do it here to ensure it is not replaced by a '-'
$str = str_replace("'", '', $str);
// Remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);
// Trim dashes at beginning and end of alias
$str = trim($str, '-');
return $str;
}
/**
* Callback method for replacing & with & in a string
*
* @param string $m String to process
*
* @return string Replaced string
*
* @since 3.5
*/
public static function ampReplaceCallback($m)
{
$rx = '&(?!amp;)';
return preg_replace('#' . $rx . '#', '&', $m[0]);
}
}
The same content is in 11 releases, Joomla 4.2.1 to 4.3.0-alpha2. See them all, or every version of this file.