Code Duplication    Length = 15-15 lines in 2 locations

admin/sxd/index.php 1 location

@@ 1540-1554 (lines=15) @@
1537
function sxd_check($n, $obj, $filt){
1538
	return isset($obj[$n]) || ($filt && preg_match($filt, $n));
1539
}
1540
function sxd_php2json($obj){
1541
	if(count($obj) == 0) return '[]';
1542
	$is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true;
1543
	$str = $is_obj ? '{' : '[';
1544
    foreach ($obj AS $key  => $value) {
1545
    	$str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; 
1546
        if     (is_array($value))   $str .= sxd_php2json($value);
1547
        elseif (is_null($value))    $str .= 'null';
1548
        elseif (is_bool($value))    $str .= $value ? 'true' : 'false';
1549
		elseif (is_numeric($value)) $str .= $value;
1550
		else                        $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'";
1551
		$str .= ',';
1552
    }
1553
	return  substr_replace($str, $is_obj ? '}' : ']', -1);
1554
}
1555
function sxd_ver2int($ver){
1556
	return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0;
1557
}

admin/sxd/load.php 1 location

@@ 29-43 (lines=15) @@
26
		readfile($file);exit;
27
	}
28
}
29
function sxd_php2json($obj){
30
	if(count($obj) == 0) return '[]';
31
	$is_obj = isset($obj[count($obj) - 1]) ? false : true;
32
	$str = $is_obj ? '{' : '[';
33
    foreach ($obj AS $key  => $value) {
34
    	$str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; 
35
        if     (is_array($value))   $str .= sxd_php2json($value);
36
        elseif (is_null($value))    $str .= 'null';
37
        elseif (is_bool($value))    $str .= $value ? 'true' : 'false';
38
		elseif (is_numeric($value)) $str .= $value;
39
		else                        $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'";
40
		$str .= ',';
41
    }
42
	return  substr_replace($str, $is_obj ? '}' : ']', -1);
43
}
44