Add Custom Pages feature

- Add config/pages directory
- Add new custom pages controller and route
- Add generated links in the footer
This commit is contained in:
Hypolite Petovan 2018-11-19 22:12:09 -05:00
parent 8c1d4404c7
commit e36805c206
7 changed files with 68 additions and 1 deletions

2
config/.gitignore vendored
View file

@ -2,3 +2,5 @@
* *
# Except this file # Except this file
!.gitignore !.gitignore
# And the pages subdirectory
!pages

4
config/pages/.gitignore vendored Normal file
View file

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

View file

@ -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];
}
}

View file

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

View file

@ -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
);
}
}

View file

@ -36,4 +36,13 @@ $app->get('/VERSION', function (Request $request, Response $response) {
return $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'); $app->get('/[{account_type}]', \Friendica\Directory\Routes\Web\Directory::class)->setName('directory');

View file

@ -96,6 +96,11 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="stats"><i class="fa fa-clipboard-list"></i> <?php echo $this->__('Stats')?></a> <a class="nav-link" href="stats"><i class="fa fa-clipboard-list"></i> <?php echo $this->__('Stats')?></a>
</li> </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> </ul>
</div> </div>
</nav> </nav>