IP/libs/plugins/modifiercompiler.unescape.php

51 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2014-04-01 18:38:34 +00:00
<?php
/**
* Smarty plugin
*
2014-10-13 09:24:53 +00:00
* @package Smarty
2014-04-01 18:38:34 +00:00
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty unescape modifier plugin
* Type: modifier<br>
* Name: unescape<br>
* Purpose: unescape html entities
*
* @author Rodney Rehm
2014-10-13 09:24:53 +00:00
*
2014-04-01 18:38:34 +00:00
* @param array $params parameters
2014-10-13 09:24:53 +00:00
*
2014-04-01 18:38:34 +00:00
* @return string with compiled code
*/
2014-10-13 09:24:53 +00:00
function smarty_modifiercompiler_unescape($params)
2014-04-01 18:38:34 +00:00
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = 'html';
2014-04-01 18:38:34 +00:00
}
if (!isset($params[ 2 ])) {
$params[ 2 ] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
2014-04-01 18:38:34 +00:00
} else {
$params[ 2 ] = "'" . $params[ 2 ] . "'";
2014-04-01 18:38:34 +00:00
}
switch (trim($params[ 1 ], '"\'')) {
2014-04-01 18:38:34 +00:00
case 'entity':
case 'htmlall':
if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
2014-04-01 18:38:34 +00:00
}
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
2014-04-01 18:38:34 +00:00
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
2014-04-01 18:38:34 +00:00
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
2014-04-01 18:38:34 +00:00
default:
return $params[ 0 ];
2014-04-01 18:38:34 +00:00
}
}