. * * index.php * * The index file. * * @author Daniele Bonini * @copyrights (c) 2016, 2024, the Open Gallery's contributors * @license https://opensource.org/licenses/BSD-3-Clause */ require "../Private/core/init.inc"; use fivemode\fivemode\Cache; // FUNCTION AND VARIABLE DECLARATIONS //$scriptPath = APP_SCRIPT_PATH; $env = []; $methods = []; function eval_ex_handler(Throwable $exception) { global $methods; global $url; echo("

This is a bit of doc for $url:

"); echo("

"); echo($methods[$url]["doc"]); } // READING METHODS FROM THE API PATH // Reading from the cache first $cache = &Cache::getInstance(); $cacheKey = md5("CALL spGetMethods();"); $methods = false; //$cache->getJ($cacheKey); if (!$methods) { chdir(APP_API_PATH); $pattern = "*.inc"; $apiPaths = glob($pattern); //print_r($apiPaths); $eni=0; foreach($apiPaths as $apiPath) { $ipos = strripos($apiPath, PHP_SLASH); if ($ipos !== false) { $apiPath = substr($apiPath, $ipos); } $apiPath = APP_API_PATH . DIRECTORY_SEPARATOR . $apiPath; $apistr = file_get_contents($apiPath); // Parsing for the api namespace.. $matches = []; $regstr = '/namespace\s(?[\w\-\\\]+)\;/'; if (preg_match_all($regstr, $apistr, $matches, PREG_SET_ORDER) !== false) { $env[$eni]['namespace'] = (string)$matches[0]["namespace"]; } if (empty($env[$eni]['namespace'])) { $env[$eni]['namespace'] = "-"; } // Parsing for the api classname.. $matches = []; $regstr = '/class\s(?[\w\-]+)\s/'; if (preg_match_all($regstr, $apistr, $matches, PREG_SET_ORDER) !== false) { $env[$eni]['classname'] = (string)$matches[0]["classname"]; } if (empty($env[$eni]['classname'])) { $env[$eni]['classname'] = "-"; } //echo("namespace=".$env[$eni]['namespace']."
"); //echo("classname=".$env[$eni]['classname']."
"); $matches = []; $regstr = '/(?(?private|public)?\s?(?static)?\s?function\s(?\&?[\w\-]{2,25})\((?(?\s?(?\?)?(?[a-z]{3,8})?\s?(?[\&]{0,1})?(?\$[\w\-]{1,20})\s?(?\=\s?[\w\-\']{1,128})?\s?\,?\s?)?(?\s?(?\?)?(?[a-z]{3,8})?\s?(?\&)?(?\$[\w\-]{1,20})\s?(?\=\s?[\w\-\']{1,128})?\s?\,?\s?)?(?\s?(?\?)?(?[a-z]{3,8})?\s?(?\&)?(?\$[\w\-]{1,20})\s?(?\=\s?[\w\-\']{1,128})?\s?\,?\s?)?(?\s?(?\?)?(?[a-z]{3,8})?\s?(?\&)?(?\$[\w\-]{1,20})\s?(?\=\s?[\w\-\']{1,128})?\s?\,?\s?)?(?\s?(?\?)?(?[a-z]{3,8})?\s?(?\&)?(?\$[\w\-]{1,20})\s?(?\=\s?[\w\-\']{1,128})?\s?\,?\s?)?)?\)?\:?\s?(?[\w\-]{2,25})?)/'; if (preg_match_all($regstr, $apistr, $matches, PREG_SET_ORDER) !== false) { foreach($matches as $match) { $method1=[]; if ($match["visibility"] === "public" || $env[$eni]['namespace'] === "-") { //var_dump_ifdebug(true, $match); if ($match["param_defs"]!="") { $method1['name'] = $match["name"]; echo_ifdebug(true, "debug: ".$match["name"]."("); $method1['doc'] = $match["name"]."("; for($i=1;$i<=5;$i++) { if (!empty($match["param_name".$i])) { $param1 = []; $param1['name'] = $match["param_name".$i]; $param1['type'] = "variant"; $param1['optional'] = false; if ($i > 1) { echo_ifdebug(true, ", "); $method1['doc'].=", "; } echo_ifdebug(true, $match["param_name".$i]." ("); $method1['doc'].=$match["param_name".$i]." ("; if (empty($match["param_type".$i])) { echo_ifdebug(true, "variant"); $method1['doc'].="variant"; } else { $param1['type'] = $match["param_type".$i]; echo_ifdebug(true, $match["param_type".$i]); $method1['doc'].=$match["param_type".$i]; } if ($match["optional_flag".$i] === "?") { $param1['optional'] = true; echo_ifdebug(true, ", optional)"); $method1['doc'].=", optional)"; } else { echo_ifdebug(true, ")"); $method1['doc'].=")"; } $method1['params'][] = $param1; } else { continue; } } if (!isset($match["return_type"])) { $method1['return_type'] = "variant"; } else { $method1['return_type'] = $match["return_type"]; } $method1['doc'].="):".$method1['return_type']; $method1['namespace'] = $env[$eni]['namespace']; $method1['classname'] = $env[$eni]['classname']; $methods[ltrim($match["name"],'&')] = $method1; echo_ifdebug(true, "):".$method1['return_type']."
"); } else { $method1['name'] = $match["name"]; $param1 = []; $method1['params'] = $param1; if (!isset($match["return_type"])) { $method1['return_type'] = "variant"; } else { $method1['return_type'] = $match["return_type"]; } $method1['doc'] = $match["name"]."():".$method1['return_type']; $method1['namespace'] = $env[$eni]['namespace']; $method1['classname'] = $env[$eni]['classname']; $methods[ltrim($match["name"],'&')] = $method1; echo_ifdebug(true, "debug: ".$match["name"]."():".$method1['return_type'].""."
"); } } } //$methods[] = $method1; //var_dump_ifdebug(true, $methods); // LOADING METHODS //var_dump_ifdebug(true, $matches); //exit(-1); } $eni++; } } //exit(-1); if (empty($methods)) { $methods = []; } // Caching the array just loaded $cache->setJ($cacheKey, $methods, 0, CACHE_EXPIRE); // PARAMETERS VALIDATION $url = trim(substr(filter_input(INPUT_GET, "url", FILTER_SANITIZE_STRING), 0, 300), "/"); /* switch ($url) { case "action": $scriptPath = APP_AJAX_PATH; define("SCRIPT_NAME", "action"); define("SCRIPT_FILENAME", "action.php"); break; case "method": define("SCRIPT_NAME", "mymethod"); define("SCRIPT_FILENAME", "mymethod.php"); break; default: $scriptPath = APP_ERROR_PATH; define("SCRIPT_NAME", "err-404"); define("SCRIPT_FILENAME", "err-404.php"); } */ //print_r($methods); echo_ifdebug(true, "
"); if (isset($methods[$url])) { $userMethod = $url; if ($methods[$url]['namespace']==="-" || $methods[$url]['classname'] ==="-") { $cmd = 'return '.$url.'('; } else { $cmd = 'return '.$methods[$url]['namespace'].'\\'.$methods[$url]['classname'].'::'.$url.'('; } //print_r($methods[$url]["params"]); $i=0; foreach($methods[$url]["params"] as $param) { $userParams[$i] = filter_input(INPUT_GET, $param['name'], FILTER_SANITIZE_STRING); //print_r($userParams[$i]); if ($param['type']==="string" && !empty($userParams[$i])) { $cmd .= "'$userParams[$i]',"; } else { $cmd .= "$userParams[$i],"; } $i++; } $cmd=rtrim($cmd,","); $cmd .= ");"; //echo("cmd=$cmd"); set_exception_handler('eval_ex_handler'); $ret = eval($cmd); if ($methods[$url]["return_type"]==="bool") { echo(($ret?"true":"false")); } else { echo($ret); } } else if ($url === "XMLDOC") { if (!DEBUG) { header("Content-Type: text/xml"); //print_r($env); echo(''); echo(''); foreach($env as $e) { $curnamespace = $e['namespace']; $curclassname = $e['classname']; foreach($methods as $m) { //echo($m['namespace']."===".$curnamespace."
"); //echo($m['classname']."===".$curclassname."
"); if (($m['namespace'] === $curnamespace) && ($m['classname'] === $curclassname)) { echo(""); echo(''.$m['namespace'].''); echo(''.$m['classname'].''); echo(''.$m['name'].''); $pi=1; foreach($m['params'] as $p) { echo("".$p['name'].""); $pi++; } echo(''.$m['return_type'].''); echo('
'.$m['doc'].'
'); echo("
"); } } } echo('
'); } } else { $scriptPath = APP_ERROR_PATH; define("SCRIPT_NAME", "err-404"); define("SCRIPT_FILENAME", "err-404.php"); if (SCRIPT_NAME==="err-404") { header("HTTP/1.1 404 Not Found"); } require $scriptPath . "/" . SCRIPT_FILENAME; }