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:
parent
8c1d4404c7
commit
e36805c206
7 changed files with 68 additions and 1 deletions
2
config/.gitignore
vendored
2
config/.gitignore
vendored
|
@ -2,3 +2,5 @@
|
|||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
# And the pages subdirectory
|
||||
!pages
|
||||
|
|
4
config/pages/.gitignore
vendored
Normal file
4
config/pages/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
28
src/classes/Controllers/Web/Page.php
Normal file
28
src/classes/Controllers/Web/Page.php
Normal 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];
|
||||
}
|
||||
}
|
|
@ -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'),
|
||||
|
|
18
src/classes/Routes/Web/Pages.php
Normal file
18
src/classes/Routes/Web/Pages.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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…
Reference in a new issue