Ejemplo n.º 1
0
/**
 * Fetch a list of files recursively
 *
 * @param string $path Base directory
 * @param string $ext File extension
 * @return stdClass
 */
function getFilesRecursive($path, $ext)
{
    $files = array();
    foreach (glob($path) as $file) {
        $name = basename($file);
        if (strpos($name, ".") === 0) {
            continue;
        }
        if (is_dir($file)) {
            $files[$name] = getFilesRecursive("{$file}/*", $ext);
        } else {
            if (strrpos($name, $ext) === strlen($name) - strlen($ext)) {
                $files[substr($name, 0, strrpos($name, "."))] = $file;
            }
        }
    }
    return (object) $files;
}
Ejemplo n.º 2
0
require_once "{$paths->lib}Functions.php";
require_once "{$paths->lib}Hooks.php";
// set PHP include path
$include_paths = array($paths->views);
if (count($config->mvc['include_paths'])) {
    $include_paths = array_merge($include_paths, $config->mvc['include_paths']);
}
if (strpos(get_include_path(), $include_paths[0]) === false) {
    set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $include_paths));
}
// initialise the View
$view = new TemplateFile();
$this->wire('view', $view);
$view->layout = $page->layout() === null ? 'default' : $page->layout();
$view->script = $page->view() === null ? null : $page->view();
$view->partials = getFilesRecursive("{$paths->partials}*", $ext);
$view->placeholders = new ViewPlaceholders($page, $paths->scripts, $ext);
// include a file containing custom front controller logic; the contents of
// this file are executed right before dispatching the template controller,
// which means that this file already has access to the View component etc.
if (is_file("{$config->paths->templates}{$front_controller}.custom.php")) {
    include "{$config->paths->templates}{$front_controller}.custom.php";
    if ($this->halt) {
        return $this->halt();
    }
}
// initialise the Controller; since this template-specific component isn't
// required, we'll first have to check if it exists at all
if (is_file("{$paths->controllers}{$page->template}{$ext}")) {
    include "{$paths->controllers}{$page->template}{$ext}";
    if ($this->halt) {