commit
e1ce64b68f
2 changed files with 30 additions and 2 deletions
|
@ -30,6 +30,16 @@ class Sanitize {
|
||||||
return htmlspecialchars_decode($text, $flags);
|
return htmlspecialchars_decode($text, $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove javascript from links
|
||||||
|
public static function noJSLink($text)
|
||||||
|
{
|
||||||
|
$text = preg_replace("/\s+/", "", $text);
|
||||||
|
while(strpos($text, 'javascript:')===0){
|
||||||
|
$text = preg_replace("/javascript\s*:\s*/", "", $text);
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
public static function pathFile($path, $file=false)
|
public static function pathFile($path, $file=false)
|
||||||
{
|
{
|
||||||
if ($file!==false){
|
if ($file!==false){
|
||||||
|
|
|
@ -49,6 +49,18 @@ class Site extends dbJSON {
|
||||||
'markdownParser'=> true,
|
'markdownParser'=> true,
|
||||||
'customFields'=> '{}'
|
'customFields'=> '{}'
|
||||||
);
|
);
|
||||||
|
private $linkKeys = array(
|
||||||
|
'twitter',
|
||||||
|
'facebook',
|
||||||
|
'codepen',
|
||||||
|
'instagram',
|
||||||
|
'github',
|
||||||
|
'gitlab',
|
||||||
|
'linkedin',
|
||||||
|
'mastodon',
|
||||||
|
'dribbble',
|
||||||
|
'vk'
|
||||||
|
);
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
|
@ -73,6 +85,12 @@ class Site extends dbJSON {
|
||||||
foreach ($this->dbFields as $field=>$value) {
|
foreach ($this->dbFields as $field=>$value) {
|
||||||
if (isset($args[$field])) {
|
if (isset($args[$field])) {
|
||||||
$finalValue = Sanitize::html($args[$field]);
|
$finalValue = Sanitize::html($args[$field]);
|
||||||
|
$finalValue = Sanitize::noJSLink($finalValue);
|
||||||
|
if (in_array($field,$this->linkKeys)){
|
||||||
|
if (!filter_var($finalValue, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED)) {
|
||||||
|
$finalValue = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($finalValue==='false') { $finalValue = false; }
|
if ($finalValue==='false') { $finalValue = false; }
|
||||||
elseif ($finalValue==='true') { $finalValue = true; }
|
elseif ($finalValue==='true') { $finalValue = true; }
|
||||||
settype($finalValue, gettype($value));
|
settype($finalValue, gettype($value));
|
||||||
|
|
Loading…
Add table
Reference in a new issue