Sanitizing html output and using page.php

Issues #1 and #4
This commit is contained in:
sergiotarxz 2020-07-28 20:12:22 +02:00
parent cce82e5ae2
commit 9b824a0788
4 changed files with 100 additions and 90 deletions

View File

@ -16,7 +16,13 @@
</div>
<div class="col-lg-6">
<?php include(THEME_DIR_PHP.'home.php') ?>
<?php
if ( $WHERE_AM_I === 'home' ) {
include(THEME_DIR_PHP.'home.php');
} elseif ( $WHERE_AM_I === 'page' ) {
include(THEME_DIR_PHP.'page.php');
}
?>
</div>
</div>
</div>

View File

@ -1,77 +1,31 @@
<!-- Section -->
<section class="content">
<?php foreach ($content as $page): ?>
<article class="page">
<header>
<?php if ( $page->title() ): ?>
<h2>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php
echo htmlentities( $page->title() );
?>
</a>
</h2>
<?php endif; ?>
</header>
<?php if ($page->coverImage()): ?>
<img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug() ?>">
<?php endif ?>
<?php foreach ($content as $page): ?>
<article class="page">
<header>
<?php if ( $page->title() ): ?>
<h2>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php
echo htmlentities( $page->title() );
?>
</a>
</h2>
<?php endif; ?>
</header>
<?php if ($page->coverImage()): ?>
<img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug(); ?>"/>
<?php endif ?>
<?php echo $page->content() ?>
<footer>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php echo htmlentities( $L->get('Read this article.') ); ?>
</a>
<br/>
<?php echo $page->date() ?>
</footer>
</article>
<?php endforeach ?>
<?php echo $page->content() ?>
<footer>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php echo htmlentities( $L->get('Read this article.') ); ?>
</a>
<br/>
<?php echo htmlentities($page->date()); ?>
</footer>
</article>
<?php endforeach ?>
</section>
<!-- Pagination -->
<ul class="pagination">
<?php
$isPage = $WHERE_AM_I === 'page';
$isHome = $WHERE_AM_I === 'home';
$pageHandler = new Pages();
$previousLink = null;
$nextLink = null;
$areTherePages = !!count($content);
if ( $isPage && $areTherePages ) {
$currentPage = $content[0];
if( isset($currentPage) ) {
if ( $currentPage->previousKey() ) {
$previousLink = buildPage($currentPage->previousKey())->permalink();
}
if ( $currentPage->nextKey() ) {
$nextLink = buildPage($currentPage->nextKey())->permalink();
}
}
}
if ( $isHome ) {
if ( Paginator::showPrev() ) {
$previousLink = Paginator::previousPageUrl();
}
if ( Paginator::showNext() ) {
$nextLink = Paginator::nextPageUrl();
}
}
?>
<?php if ( isset($previousLink) ): ?>
<li class="float-left">
<a href="<?php echo htmlentities( $previousLink, ENT_QUOTES | ENT_HTML401 ); ?>">
<?php echo $L->get('Previous page') ?>
</a>
</li>
<?php endif; ?>
<?php if ( isset($nextLink) ): ?>
<li class="float-right">
<a href="<?php echo htmlentities( $nextLink, ENT_QUOTES | ENT_HTML401 ); ?>">
<?php echo $L->get('Next page') ?>
</a>
</li>
<?php endif; ?>
</ul>
<?php include(THEME_DIR_PHP.'pagination.php'); ?>

View File

@ -1,18 +1,26 @@
<!-- Section -->
<section class="content">
<article class="page">
<header>
<a href="<?php echo $page->permalink() ?>">
<h2><?php echo $page->title() ?></h2>
</a>
<article class="page">
<header>
<?php if ( $page->title() ): ?>
<h2>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php
echo htmlentities( $page->title() );
?>
</a>
</h2>
<?php endif; ?>
</header>
<?php if ($page->coverImage()): ?>
<img src="<?php echo htmlentities($page->coverImage(), ENT_QUOTES | ENT_HTML401); ?>" alt="<?php echo htmlentities($page->slug(), ENT_QUOTES | ENT_HTML401); ?>"/>
<?php endif ?>
<?php if($page->coverImage()): ?>
<img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug() ?>">
<?php endif ?>
</header>
<?php echo $page->content() ?>
<footer>
<div class="date"><?php echo $page->date() ?></div>
</footer>
</article>
</section>
<?php echo $page->content() ?>
<footer>
<?php echo $page->date() ?>
</footer>
</article>
</section>
<?php include(THEME_DIR_PHP.'pagination.php'); ?>

42
php/pagination.php Normal file
View File

@ -0,0 +1,42 @@
<!-- Pagination -->
<ul class="pagination">
<?php
$isPage = $WHERE_AM_I === 'page';
$isHome = $WHERE_AM_I === 'home';
$pageHandler = new Pages();
$previousLink = null;
$nextLink = null;
if ( $isPage && isset($page) ) {
if( isset($page) ) {
if ( $page->previousKey() ) {
$previousLink = buildPage($page->previousKey())->permalink();
}
if ( $page->nextKey() ) {
$nextLink = buildPage($page->nextKey())->permalink();
}
}
}
if ( $isHome ) {
if ( Paginator::showPrev() ) {
$previousLink = Paginator::previousPageUrl();
}
if ( Paginator::showNext() ) {
$nextLink = Paginator::nextPageUrl();
}
}
?>
<?php if ( isset($previousLink) ): ?>
<li class="float-left">
<a href="<?php echo htmlentities( $previousLink, ENT_QUOTES | ENT_HTML401 ); ?>">
<?php echo $L->get('Previous page') ?>
</a>
</li>
<?php endif; ?>
<?php if ( isset($nextLink) ): ?>
<li class="float-right">
<a href="<?php echo htmlentities( $nextLink, ENT_QUOTES | ENT_HTML401 ); ?>">
<?php echo $L->get('Next page') ?>
</a>
</li>
<?php endif; ?>
</ul>