Skip to content

Instantly share code, notes, and snippets.

@Laim
Created November 21, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Laim/c1491addb81c4f6c0260d0084b467fdc to your computer and use it in GitHub Desktop.
Save Laim/c1491addb81c4f6c0260d0084b467fdc to your computer and use it in GitHub Desktop.
How not to do it
<?php
//MAIN CONFIGURATION
require_once(dirname(__FILE__) . "/include/configuration.php");
//DATABASE
require_once(dirname(__FILE__) . "/include/db/conn.php");
require_once(dirname(__FILE__) . "/include/db/func.php");
$sb = new susboy($pdo);
if (isset($_GET['filter'])) {
$filter = htmlentities($_GET['filter']);
}
if (isset($_GET['posturl'])) {
$purl = htmlentities($_GET['posturl']);
}
if(!empty($purl)) {
$keywords = $sb->GetPost($purl)[0]['PostTags'];
$meta_intro = $sb->GetPost($purl)[0]['PostIntro'];
$meta_title = $sb->GetPost($purl)[0]['PostTitle'];
$meta_date = date("D s F Y H:m",$sb->GetPost($purl)[0]['PostDate']);
$meta_pid = $sb->GetPost($purl)[0]['PostID'];
$meta_featuredimage = $sb->GetPost($purl)[0]['PostFeaturedImage'];
}
if(!empty($purl))
{
if(empty($sb->GetPost($purl)[0]['PostBody']))
{
header("location: /posts/");
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php print(SITE_NAME);?> - <?php if(empty($purl)) { print "Posts"; } else { print ($sb->GetPost($purl)[0]['PostTitle']);} ?></title>
<?php require_once(dirname(__FILE__) . "/include/meta.php");?>
<?php require_once(dirname(__FILE__) . "/include/stylesheet.php");?>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<main>
<div class="container">
<div class="row mt-5">
<div class="col-md text-muted">
<?php
if(empty($purl)) {
print("<h3><a href='//laimmckenzie.com/'>Home</a> - <a href='//laimmckenzie.com/posts/'>Posts</a></h3><hr>");
$x = 1;
if(empty($filter)) {
foreach ($sb->AllPosts() as $posts) { ?>
<div class="card <?php if($x !== 5) { print("mb-3"); }?>">
<img class="card-img-top shadow-sm" src="//laimmckenzie.com/uploads/<?php print($posts['PostID']);?>/<?php print($posts['PostFeaturedImage']);?>" alt="<?php print($posts['PostTitle']);?>">
<div class="card-body">
<h5 class="card-title">
<a href="//laimmckenzie.com/posts/<?php print($posts['PostURL']);?>">
<?php print($posts['PostTitle']);?>
</a>
</h5>
<p class="card-text">
<?php print($posts['PostIntro']);?>
</p>
</div>
<div class="card-footer text-muted" style="background-color: inherit;">
<?php print(date("d M y H:m",$posts['PostDate'])); ?>
</div>
</div>
<?php
$x++;
}
} else {
foreach ($sb->FilterPosts($filter) as $posts) {
?>
<div class="card <?php if($x !== 5) { print("mb-3"); }?>">
<!--<div class="card-header" style="background-color: inherit;">
<a href="<?php print(DOMAIN);?>/posts/<?php print($posts['PostURL']);?>">
<?php print($posts['PostTitle']);?>
</a>
</div>-->
<img class="card-img-top shadow-sm" src="//laimmckenzie.com/uploads/<?php print($posts['PostID']);?>/<?php print($posts['PostFeaturedImage']);?>" alt="<?php print($posts['PostTitle']);?>">
<div class="card-body">
<h5 class="card-title">
<a href="//laimmckenzie.com/posts/<?php print($posts['PostURL']);?>">
<?php print($posts['PostTitle']);?>
</a>
</h5>
<p class="card-text">
<?php print($posts['PostIntro']);?>
</p>
</div>
<div class="card-footer text-muted" style="background-color: inherit;">
<?php print(date("d M y H:m",$posts['PostDate'])); ?>
</div>
</div>
<?php
$x++;
}
}
} else {
print("<h3><a href='//laimmckenzie.com/'>Home</a> - <a href='//laimmckenzie.com/posts/'>Posts</a></h3><hr>");
?>
<div class="card">
<div class="card-header" style="background-color: inherit; color: black;">
<?php print($sb->GetPost($purl)[0]['PostTitle']);?>
</div>
<div class="card-body">
<p class="card-text">
<?php print($sb->GetPost($purl)[0]['PostBody']);?>
</p>
</div>
<div class="card-footer text-muted" style="background-color: inherit;">
<?php print(date("D s F Y H:m",$sb->GetPost($purl)[0]['PostDate'])); ?>
</div>
</div>
<?php } ?>
</div>
<div class="col-md-3 text-muted d-none d-sm-block">
<h3>Widgets</h3><hr>
<ul class="list-group">
<?php foreach ($sb->AllPostCategories() as $APC) { ?>
<li class="list-group-item d-flex justify-content-between align-items-center">
<a href="<?php print('//laimmckenzie.com/posts/filter/' . strtolower($APC['PostCategories']));?>">
<?php print($APC['PostCategories']); ?>
</a>
<span class="badge badge-danger badge-pill">
<?php print($sb->CountPostCategories($APC['PostCategories']));?>
</span>
</li>
<?php } ?>
</ul>
</div>
</div>
<!-- footer area -->
<?php require_once(dirname(__FILE__) . "/include/footer.php");?>
</div>
</main>
<?php require_once(dirname(__FILE__) . "/include/javascript.php");?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment