<commit_before><?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
	header("location: index.php");
	exit;
}

/**
 * Smarty escape modifier plugin
 *
 * Type:     modifier<br>
 * Name:     escape<br>
 * Purpose:  Escape the string according to escapement type
 * @link http://smarty.php.net/manual/en/language.modifier.escape.php
 *          escape (Smarty online manual)
 * @author   <NAME> <monte at ohrt dot com>
 * @param string
 * @param html|htmlall|url|quotes|hex|hexentity|javascript
 * @return string
 */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'UTF-8')
{
	switch ($esc_type) {
		case 'html':
			$return = htmlspecialchars($string, ENT_QUOTES, $char_set);
			// Convert back sanitization tags into real tags to avoid them to be displayed
			$return = str_replace('&lt;x&gt;', '<x>', $return);
			// Convert back sanitization tags into real tags for no wrap space
			$return = str_replace('&amp;nbsp;', '&nbsp;', $return);
			return $return;

		case 'htmlall':
			$return = htmlentities($string, ENT_QUOTES, $char_set);
			if (!strlen($return) && strlen($string)) // Bug php when there is non utf8 characters in the string(http://bugs.php.net/bug.php?id=43549, http://bugs.php.net/bug.php?id=43294)
				$return = htmlentities($string, ENT_QUOTES);
			// Convert back sanitization tags into real tags to avoid them to be displayed
			$return = str_replace('&lt;x&gt;', '<x>', $return);
			return $return;

		case 'url':
			return rawurlencode($string);

		case 'urlpathinfo':
			return str_replace('%2F', '/', rawurlencode($string));

		case 'quotes':
			// escape unescaped single quotes
			return preg_replace("%(?<!\\\\)'%", "\\'", $string);<commit_msg>[FIX] strict: Don't pass arrays to htmlspecialchars (merci Trebly)<commit_after><?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
	header("location: index.php");
	exit;
}

/**
 * Smarty escape modifier plugin
 *
 * Type:     modifier<br>
 * Name:     escape<br>
 * Purpose:  Escape the string according to escapement type
 * @link http://smarty.php.net/manual/en/language.modifier.escape.php
 *          escape (Smarty online manual)
 * @author   <NAME> <monte at ohrt dot com>
 * @param string
 * @param html|htmlall|url|quotes|hex|hexentity|javascript
 * @return string
 */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'UTF-8')
{
	switch ($esc_type) {
		case 'html':
			if (is_array($string)) {
				$string = implode(',', $string);
			}
			$return = htmlspecialchars($string, ENT_QUOTES, $char_set);
			// Convert back sanitization tags into real tags to avoid them to be displayed
			$return = str_replace('&lt;x&gt;', '<x>', $return);
			// Convert back sanitization tags into real tags for no wrap space
			$return = str_replace('&amp;nbsp;', '&nbsp;', $return);
			return $return;

		case 'htmlall':
			$return = htmlentities($string, ENT_QUOTES, $char_set);
			if (!strlen($return) && strlen($string)) // Bug php when there is non utf8 characters in the string(http://bugs.php.net/bug.php?id=43549, http://bugs.php.net/bug.php?id=43294)
				$return = htmlentities($string, ENT_QUOTES);
			// Convert back sanitization tags into real tags to avoid them to be displayed
			$return = str_replace('&lt;x&gt;', '<x>', $return);
			return $return;

		case 'url':
			return rawurlencode($string);

		case 'urlpathinfo':
			return str_replace('%2F', '/', rawurlencode($string));

		case 'quotes':
			// escape unescaped single quotes
			return preg_replace("%(?<!\\\\)'%", "\\'", $string);
{'fraction_non_alphanumeric': 0.15024010976446375, 'fraction_numerical': 0.009604390578550195, 'mean_word_length': 3.9874572405929305, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991000', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1393, 'n_words': 432}