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>
<div class="col-lg-6"> <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> </div>
</div> </div>

View File

@ -1,77 +1,31 @@
<!-- Section -->
<section class="content"> <section class="content">
<?php foreach ($content as $page): ?> <?php foreach ($content as $page): ?>
<article class="page"> <article class="page">
<header> <header>
<?php if ( $page->title() ): ?> <?php if ( $page->title() ): ?>
<h2> <h2>
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>"> <a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<?php <?php
echo htmlentities( $page->title() ); echo htmlentities( $page->title() );
?> ?>
</a> </a>
</h2> </h2>
<?php endif; ?> <?php endif; ?>
</header> </header>
<?php if ($page->coverImage()): ?> <?php if ($page->coverImage()): ?>
<img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug() ?>"> <img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug(); ?>"/>
<?php endif ?> <?php endif ?>
<?php echo $page->content() ?> <?php echo $page->content() ?>
<footer>
<footer> <a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>">
<a href="<?php echo htmlentities($page->permalink(), ENT_QUOTES | ENT_HTML401)?>"> <?php echo htmlentities( $L->get('Read this article.') ); ?>
<?php echo htmlentities( $L->get('Read this article.') ); ?> </a>
</a> <br/>
<br/> <?php echo htmlentities($page->date()); ?>
<?php echo $page->date() ?> </footer>
</footer> </article>
</article> <?php endforeach ?>
<?php endforeach ?>
</section> </section>
<!-- Pagination --> <?php include(THEME_DIR_PHP.'pagination.php'); ?>
<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>

View File

@ -1,18 +1,26 @@
<!-- Section -->
<section class="content"> <section class="content">
<article class="page"> <article class="page">
<header> <header>
<a href="<?php echo $page->permalink() ?>"> <?php if ( $page->title() ): ?>
<h2><?php echo $page->title() ?></h2> <h2>
</a> <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()): ?> <?php echo $page->content() ?>
<img src="<?php echo $page->coverImage() ?>" alt="<?php echo $page->slug() ?>">
<?php endif ?> <footer>
</header> <?php echo $page->date() ?>
<?php echo $page->content() ?> </footer>
<footer> </article>
<div class="date"><?php echo $page->date() ?></div>
</footer>
</article>
</section> </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>