/** * List pages and children * * @param $pages Array of Page * @param $options Array of options (options available: ul, li, level, liCallback) * @return string Html list of pages */ function listPagesAndChildren(array $pages, array $options, $level = 9) { $ul = isset($options['ul']) ? $options['ul'] : ''; $li = isset($options['li']) ? $options['li'] : ''; $liCallback = isset($options['liCallback']) ? $options['liCallback'] : null; $level = isset($options['level']) ? $options['level'] : 9; if ($level > 0) { $str = '<ul ' . $ul . '>' . PHP_EOL; foreach ($pages as $page) { $anch = $page->title; if ($liCallback !== null) { $anch = $liCallback($page); } $str .= '<li ' . $li . '>' . $anch; if ($page->getChildren()) { --$options['level']; $str .= listPagesAndChildren($page->getChildren(), $options); ++$options['level']; } $str .= '</li>' . PHP_EOL; } return $str . '</ul>' . PHP_EOL; } return ''; }
if ($c['themes']->has($themeName = $c['config']->get('theme'))) { return $c['themes']->read($themeName); } else { throw new Exception('Theme `' . $themeName . '` does not exists'); } }; $app['view'] = function (Container $c) { $theme = $c['theme']; $config = $c['config']; // Create new Plates instance to render theme files $path = $theme->getPath(); $view = new League\Plates\Engine($path, $theme->getExtension()); // Helper function // List pages $view->registerFunction('listPages', function ($pages, $options) { return listPagesAndChildren(listPagesRoot($pages), $options); }); // System date format $view->registerFunction('dateFormat', function (DateTime $date) use($config) { return $date->format($config->get('dateFormat')); }); // System date format $view->registerFunction('pageDateFormat', function (Parvula\Models\Page $page) use($config) { return $page->getDateTime()->format($config->get('dateFormat')); }); // Excerpt strings $view->registerFunction('excerpt', function ($text, $length = 275) { $text = strip_tags($text); $excerpt = substr($text, 0, $length); if ($excerpt !== $text) { $lastDot = strrpos($excerpt, '. ');