Add Custom Pages feature

- Add config/pages directory
- Add new custom pages controller and route
- Add generated links in the footer
pull/22/head
Hypolite Petovan 4 years ago
parent 8c1d4404c7
commit e36805c206
  1. 4
      config/.gitignore
  2. 4
      config/pages/.gitignore
  3. 28
      src/classes/Controllers/Web/Page.php
  4. 1
      src/classes/Routes/Web/BaseRoute.php
  5. 18
      src/classes/Routes/Web/Pages.php
  6. 9
      src/routes.php
  7. 5
      src/templates/layout.phtml

4
config/.gitignore vendored

@ -1,4 +1,6 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
!.gitignore
# And the pages subdirectory
!pages

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

@ -0,0 +1,28 @@
<?php
namespace Friendica\Directory\Controllers\Web;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Page extends BaseController
{
/**
* @var string
*/
private $pageFile;
public function __construct(
string $pageFile
)
{
$this->pageFile = $pageFile;
}
public function render(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): array
{
$content = file_get_contents($this->pageFile);
return ['content' => $content];
}
}

@ -27,6 +27,7 @@ abstract class BaseRoute
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
{
$defaults = [
'pages' => glob(__DIR__ . '/../../../../config/pages/*.html'),
'version' => file_get_contents(__DIR__ . '/../../../../VERSION'),
'languages' => $this->container->settings['i18n']['locales'],
'lang' => $request->getAttribute('locale'),

@ -0,0 +1,18 @@
<?php
namespace Friendica\Directory\Routes\Web;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Pages extends BaseRoute
{
public function __construct(\Slim\Container $container, $pageFile)
{
parent::__construct($container);
$this->controller = new \Friendica\Directory\Controllers\Web\Page(
$pageFile
);
}
}

@ -36,4 +36,13 @@ $app->get('/VERSION', function (Request $request, Response $response) {
return $response;
});
foreach(glob(__DIR__ . '/../config/pages/*.html') as $page) {
$app->get('/' . strtolower(basename($page, '.html')), function (Request $request, Response $response, $args) use ($page) {
$route = new \Friendica\Directory\Routes\Web\Pages($this, $page);
return $route($request, $response, $args);
});
}
$app->get('/[{account_type}]', \Friendica\Directory\Routes\Web\Directory::class)->setName('directory');

@ -96,6 +96,11 @@
<li class="nav-item">
<a class="nav-link" href="stats"><i class="fa fa-clipboard-list"></i> <?php echo $this->__('Stats')?></a>
</li>
<?php foreach ($pages as $page):?>
<li class="nav-item">
<a class="nav-link" href="<?php echo strtolower(basename($page, '.html'))?>"><?php echo basename($page, '.html')?></a>
</li>
<?php endforeach;?>
</ul>
</div>
</nav>

Loading…
Cancel
Save