public function parseDocBookRequest() { $server_pathtrans = isset($_SERVER['PATH_TRANSLATED']) ? $_SERVER['PATH_TRANSLATED'] : null; $server_uri = $_SERVER['REQUEST_URI']; $server_query = $_SERVER['QUERY_STRING']; $server_argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : null; $docbook = FrontController::getInstance(); $locator = new Locator(); $file = $path = $action = null; $args = array(); /*/ echo '<br />server_pathtrans: '.var_export($server_pathtrans,1); echo '<br />server_uri: '.var_export($server_uri,1); echo '<br />server_query: '.var_export($server_query,1); echo '<br />server_argv: '.var_export($server_argv,1); //*/ // first: request path from URL if (!empty($server_query)) { $req = $server_query; if ($req === FrontController::DOCBOOK_INTERFACE) { $req = $server_uri; } // if '/action' if ($ctrl = $locator->findController(trim($req, '/'))) { $action = trim($req, '/'); } else { $parts = explode('/', $req); $parts = array_filter($parts); $int_index = array_search(FrontController::DOCBOOK_INTERFACE, $parts); if (!empty($int_index)) { unset($parts[$int_index]); } $original_parts = $parts; // classic case : XXX/YYY/...(/action) $test_file = $locator->locateDocument(implode('/', $parts)); while (empty($test_file) && count($parts) > 0) { array_pop($parts); $test_file = $locator->locateDocument(implode('/', $parts)); } if (count($parts) > 0) { $file = $test_file; $diff = array_diff($original_parts, $parts); if (!empty($diff) && count($diff) === 1) { $action = array_shift($diff); } } else { // case of a non-existing file : XXX/YYY/.../ZZZ.md(/action) $parts = $original_parts; $isMd = '.md' === substr(end($parts), -3); while (true !== $isMd && count($parts) > 0) { array_pop($parts); $isMd = '.md' === substr(end($parts), -3); } if ($isMd && count($parts) > 0) { $file = implode('/', $parts); $diff = array_diff($original_parts, $parts); if (!empty($diff) && count($diff) === 1) { $action = array_shift($diff); } } } } } /* // second: request from CLI if (empty($action)) { if (!empty($server_argv)) { $tmp_action = end($server_argv); } elseif (!empty($server_pathtrans)) { $tmp_action = $server_pathtrans; } if (!empty($tmp_action)) { if (!empty($file) && ($tmp_action===$file || trim($tmp_action, '/')===$file)) { $tmp_action = null; } if (!empty($tmp_action) && false!==strpos($tmp_action, $docbook->getPath('base_dir_http'))) { $tmp_action = str_replace($docbook->getPath('base_dir_http'), '', $tmp_action); } if (!empty($file) && ($tmp_action===$file || trim($tmp_action, '/')===$file)) { $tmp_action = null; } if (!empty($tmp_action)) { $action_parts = explode('/', $tmp_action); $action_parts = array_filter($action_parts); $action = array_shift($action_parts); } } } */ if (!empty($file)) { $docbook->setInputFile($file); if (file_exists($file)) { $docbook->setInputPath(is_dir($file) ? $file : dirname($file)); } } else { $docbook->setInputPath('/'); } //echo '<br />intermediate action: '.var_export($action,1); // if GET args in action if (!empty($action) && strpos($action, '?') !== false) { $action_new = substr($action, 0, strpos($action, '?')); $action_args = substr($action, strpos($action, '?') + 1); parse_str($action_args, $action_str_args); if (!empty($action_str_args)) { $args = array_merge($args, $action_str_args); } $action = $action_new; } // if PHP GET args if (!empty($_GET)) { $args = array_merge($args, $_GET); } // if GET args from diff( uri-query ) if (0 < substr_count($server_uri, $server_query)) { $uri_diff = trim(str_replace($server_query, '', $server_uri), '/'); if (!empty($uri_diff)) { if (substr($uri_diff, 0, 1) === '?') { $uri_diff = substr($uri_diff, 1); } parse_str($uri_diff, $uri_diff_args); if (!empty($uri_diff_args)) { $args = array_merge($args, $uri_diff_args); } } } if (!empty($args)) { $docbook->setQuery($args); } $docbook->setAction(!empty($action) ? $action : 'default'); /* echo '<br />file: '.var_export($docbook->getInputFile(),1); echo '<br />path: '.var_export($docbook->getInputPath(),1); echo '<br />action: '.var_export($docbook->getAction(),1); echo '<br />arguments: '.var_export($docbook->getQuery(),1); var_dump($this); exit('yo'); */ return $this; }
/** * Get a template file path (relative to `option['templates_dir']`) * * @param string $name The view filename * @return misc FALSE if nothing had been find, the filename otherwise */ public function getTemplate($name) { $locator = new Locator(); return $locator->fallbackFinder($name); }