null, 'tableheader' => null, 'showsize' => null, 'showdate' => null, 'listsep' => null, ]; } /** @inheritdoc */ protected function processPath(string $path): array { [$base, $pattern] = $this->separatePathAndPattern($path); return ['base' => $base, 'pattern' => $pattern]; } /** @inheritdoc */ protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool { $pathInfo = $this->getPathInfoSafe($pathData['base'], $renderer); if ($pathInfo === false) { return true; } $crawler = $this->createCrawler($params); $result = $crawler->crawl( $pathInfo['root'], $pathInfo['local'], $pathData['pattern'], $params['recursive'], $params['titlefile'] ); $items = $this->flattenResultTree($result); $items = $this->filterImages($items); if ($items == []) { $this->renderError($renderer, 'error_nomatch'); return true; } $output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items); if ($format == 'xhtml') { $output->renderAsGallery($params); return true; } // Fallback for non-XHTML formats: render as a list of links $params['style'] = 'list'; $params['showsize'] = 0; $params['showdate'] = 0; $params['listsep'] = ', '; $output->renderAsList($params); return true; } /** * Flattens the crawl result tree into a list of file items. * * @param array $items * @param string $prefix * @return array */ protected function flattenResultTree($items, $prefix = '') { $result = []; foreach ($items as $file) { if ($file['children'] !== false) { $result = array_merge( $result, $this->flattenResultTree($file['children'], $prefix . $file['name'] . '/') ); } else { $file['name'] = $prefix . $file['name']; $result[] = $file; } } return $result; } /** * Keep only image files. * * @param array $items * @return array */ protected function filterImages($items) { $images = []; foreach ($items as $item) { if (!isset($item['path']) || !is_string($item['path'])) continue; if (!is_file($item['path'])) continue; try { [, $mime,] = mimetype($item['path'], false); } catch (Throwable $e) { continue; } if (is_string($mime) && str_starts_with($mime, 'image/')) { $images[] = $item; } } return $images; } }