/** * 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); }