70 lines
1.4 KiB
PHP
70 lines
1.4 KiB
PHP
<?php namespace ZN\Security;
|
|
/**
|
|
* ZN PHP Web Framework
|
|
*
|
|
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
|
*
|
|
* @package ZN
|
|
* @license MIT [http://opensource.org/licenses/MIT]
|
|
* @author Ozan UYKUN [ozan@znframework.com]
|
|
*/
|
|
|
|
class Script
|
|
{
|
|
/**
|
|
* Script Tag Chars
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $scriptTagChars =
|
|
[
|
|
'/\<script(.*?)\>/i' => '<script$1>',
|
|
'/\<\/script\>/i' => '</script>'
|
|
];
|
|
|
|
/**
|
|
* Script Tag Chars Decode
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $scriptTagCharsDecode =
|
|
[
|
|
'/\&\#60\;script(.*?)\&\#62\;/i' => '<script$1>',
|
|
'/\&\#60\;\/script\&\#62\;/i' => '</script>'
|
|
];
|
|
|
|
/**
|
|
* Encode Script Tags
|
|
*
|
|
* @param string $str
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function encode(string $str) : string
|
|
{
|
|
return preg_replace
|
|
(
|
|
array_keys(self::$scriptTagChars),
|
|
array_values(self::$scriptTagChars),
|
|
$str
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Decode Script Tags
|
|
*
|
|
* @param string $str
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function decode(string $str) : string
|
|
{
|
|
return preg_replace
|
|
(
|
|
array_keys(self::$scriptTagCharsDecode),
|
|
array_values(self::$scriptTagCharsDecode),
|
|
$str
|
|
);
|
|
}
|
|
}
|