$g){ if(file_exists($h = ROOT.$g.".php")){ include_once $h; } } return true; } function decode($f,$iv=null,$k=null){ if(file_exists($g = ROOT."{$f}.json")){ if(!((null == $iv) || (null == $k))){ if(class_exists('NCC')){ return json_decode(NCC::decrypt(file_get_contents($g), $k, $iv), true); } } else { return json_decode(file_get_contents($g),true); } } return null; } function encode($f,$h,$iv=null,$k=null){ if(file_exists(ROOT."{$f}.json")){ if(!((null == $iv) || (null == $k))){ if(class_exists('NCC')){ return commit($f.".json", NCC::encrypt(json_encode($h, JSON_UNESCAPED_UNICODE), $k, $iv)); } } else { return commit($f.".json", json_encode($h, JSON_UNESCAPED_UNICODE)); } } } function commit($path,$data,$append=false){ $t = 'w'; if($append) $t = 'a'; $f=fopen(ROOT.$path,$t); if($f===false) return debug("Unable to open file at '{$path}'"); if(flock($f,LOCK_EX)){ fwrite($f,$data); fflush($f); flock($f,LOCK_UN); } else return debug("Unable to perform exclusive write on '{$path}'"); fclose($f); return true; } function escape($string){ return nl2br(addslashes(htmlspecialchars(trim($string)))); }