Exemplo n.º 1
0
 /**
  * Inits the route for page rendering, registers a layout renderer and 
  * provides fancy error pages
  *
  * @return void
  */
 function init()
 {
     $routes = $this->import("Routes");
     $app = $this->import("App");
     $config = $this->import("Config");
     $routes->addRoute(new PageRoute(array($this, "render")));
     Page::setSearchPath(array($this->getPath() . "/default", \Core\APPROOT . "/pages"));
     // An object which holds the layout variables
     $layout = new StdClass();
     $this->export("Layout", $layout);
     $layout->title = "Willkommen zu SimpleCMS!";
     $layoutRenderer = new Mustache();
     $layoutRenderer->setTemplatePath($this->getPath() . "/default")->setTemplatePath(\Core\APPROOT . "/layouts");
     $layoutName = isset($config["Pages"]["layout_name"]) ? $config["Pages"]["layout_name"] : "layout";
     // Render the layout after the dispatching process
     $app->after(function ($request, $response) use($layoutName, $layout, $layoutRenderer) {
         $body = $response->getBody();
         $layout->content = $body;
         $response->setBody($layoutRenderer->render($layoutName, $layout));
     });
     // Checks if the response has errors and renders appropiate error pages
     $app->error(new ErrorHandler());
 }
 /**
  * @group issue-25
  */
 public function testSubLayoutsCanAlterContentOfParent()
 {
     $mustache = new Mustache();
     $mustache->setTemplatePath(__DIR__ . '/templates/no-layout-dups');
     $view = new stdClass();
     $view->name = 'Stan';
     $layout = $mustache->render('layout', $view);
     $this->assertContains('Hello Stan', $layout);
     $this->assertContains('Default content of the page', $layout);
     $subLayout = $mustache->render('sub-layout', $view);
     $this->assertContains('Salutations Stan', $subLayout);
     $this->assertContains('Lorem ipsum, yada yada yada...', $subLayout);
 }
Exemplo n.º 3
0
 /**
  * Send the directory listing.
  */
 public function sendListing()
 {
     $app = Application::getInstance();
     $request = $app->getRequest();
     // Build up data:
     $data = (object) ['resource' => ['dir' => $request->getResourcesDir(), 'uri' => $request->getResourcesUri()], 'request' => ['dir' => $request->getRequestDir(), 'uri' => $request->getRequestUri()], 'features' => ['archive' => $this->archiveDownload], 'breadcrumb' => $app->getBreadcrumb(), 'readme' => [], 'results' => []];
     foreach ($app->getReadme() as $item) {
         $document = new DOMDocument('1.0', 'utf-8');
         $document->loadHTML('<?xml encoding="UTF-8">' . $item->html);
         $xpath = new DOMXPath($document);
         // Find any 'neatindex-action' links:
         foreach ($xpath->query('//link[@rel = "neatindex-action"]') as $node) {
             // Remove the node from the document:
             $node->parentNode->removeChild($node);
             if (isset($item->actions) === false) {
                 $item->actions = [];
             }
             $item->actions[] = (object) ['name' => $node->getAttribute('title'), 'url' => $node->getAttribute('href')];
         }
         // Rebuild the HTML:
         $item->html = null;
         foreach ($xpath->query('//body/node()') as $node) {
             $item->html .= $document->saveHTML($node);
         }
         $data->readme[] = $item;
     }
     foreach ($app->getResults() as $item) {
         // Set locale timestamp:
         $item->date->value = strftime($this->dateFormat, $item->date->timestamp);
         // Give files a class based on their extension:
         if ($item->type->file) {
             $classes = [];
             // Give files a class based on their mime:
             if (isset($item->type->mime)) {
                 $classes = explode('/', $item->type->mime);
             }
             if (preg_match('%.[.].%', $item->name)) {
                 $classes[] = preg_replace('%(^.+?)([.]([^.]+$))%', 'extension-\\3', strtolower($item->name));
             }
             $item->type->class = implode(' ', $classes);
         }
         $data->results[] = $item;
     }
     // Render output:
     $mustache = new Mustache();
     $mustache->setSuffix('html');
     $mustache->setTemplatePath($request->getResourcesDir() . '/themes/adwaita/templates');
     header('content-type: text/html;charset=utf-8');
     echo $mustache->render('main', $data);
 }