Actually display blog posts from the database

develop
Sven Slootweg 12 years ago
parent 8683fc6d20
commit 70d81e1b78

@ -23,7 +23,8 @@ class BlogPost extends CPHPDatabaseRecordClass
'string' => array(
'Title' => "Title",
'Body' => "Body",
'Slug' => "Slug"
'Slug' => "Slug",
'Thumbnail' => "Thumbnail"
),
'numeric' => array(
'Views' => "Views",

@ -13,5 +13,63 @@
if(!isset($_APP)) { die("Unauthorized."); }
$current_page = empty($router->uParameters[1]) ? 1 : (int) $router->uParameters[1];
$current_page = ($current_page < 1) ? 1 : $current_page;
$per_page = 5;
$start = ($current_page - 1) * $per_page;
$result = $database->CachedQuery("SELECT COUNT(*) FROM blog_posts WHERE `Visible` = 1");
$total_posts = $result->data[0]["COUNT(*)"];
$total_pages = ceil($total_posts / $per_page);
$sPosts = array();
try
{
$result = BlogPost::CreateFromQuery("SELECT * FROM blog_posts WHERE `Visible` = 1 ORDER BY `Posted` DESC LIMIT {$start},{$per_page}");
}
catch (NotFoundException $e)
{
$result = array();
}
foreach($result as $sBlogPost)
{
$sPosts[] = array(
"title" => $sBlogPost->sTitle,
"author" => $sBlogPost->sAuthor->sUsername,
"relative-date" => time_ago($sBlogPost->sPostedDate, $locale),
"teaser" => Markdown(cut_text($sBlogPost->sBody, 1000)),
"thumbnail" => $sBlogPost->sThumbnail,
"tags" => "test1, test2, test3",
"url" => "/blog/{$sBlogPost->sSlug}"
);
}
$sPages = array();
foreach(generate_pagination(1, $total_pages, $current_page, 2, 3, 3) as $page)
{
if($page === null)
{
$sPages[] = array('value' => false);
}
else
{
$sPages[] = array(
'value' => $page,
'current' => ($page == $current_page)
);
}
}
$sPageTitle = "Latest posts";
$sPageContents = NewTemplater::Render("blog/home", $locale->strings, array());
$sPageContents = NewTemplater::Render("blog/home", $locale->strings, array(
"entries" => $sPosts,
"pagination-first" => ($current_page == 1),
"pagination-last" => ($current_page == $total_pages),
"previous-page" => ($current_page - 1),
"next-page" => ($current_page + 1),
"pages" => $sPages
));

@ -32,6 +32,10 @@ $router->routes = array(
"target" => "modules/blog/home.php",
"_section" => "Blog"
),
"^/blog/p([0-9]+)$" => array(
"target" => "modules/blog/home.php",
"_section" => "Blog"
),
"^/login$" => array(
"target" => "modules/account/login.php",
"_section" => "Account"

@ -1,38 +1,27 @@
<div class="entry">
<h1><a href="#">SimpleNode $3.50 256MB OpenVZ in Dallas, Texas & Phoenix, Arizona</a></h1>
<img src="/static/images/simplenode.jpg">
{%foreach entry in entries}
<div class="entry">
<h1><a href="{%?entry[url]}">{%?entry[title]}</a></h1>
<img src="{%?entry[thumbnail]}">
<div class="metadata">
<span class="date">Yesterday</span>, by
<span class="author">joepie91</span>
<span class="tags">Tags: dallas, phoenix, openvz</span>
<span class="date">{%?entry[relative-date]}</span>, by
<span class="author">{%?entry[author]}</span>
<span class="tags">Tags: {%?entry[tags]}</span>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam gravida nisi ut sapien dignissim ornare. Ut nisl eros, pharetra molestie malesuada vitae, elementum sit amet dui. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur elementum leo et erat malesuada id convallis nibh faucibus. Etiam tempor faucibus urna ut blandit. Pellentesque laoreet est vel risus lobortis vehicula. Vestibulum interdum lectus et metus hendrerit ullamcorper.</p>
<p>Suspendisse libero massa, mattis at laoreet vel, tincidunt id arcu. Curabitur ac suscipit tellus. In hac habitasse platea dictumst. Donec sed leo arcu. Maecenas tempor nunc et nisi ullamcorper nec interdum lorem porttitor. In suscipit semper justo, ut pellentesque sapien ultrices a. Nam ut viverra erat. Nulla facilisi. Mauris auctor eleifend dui id vestibulum. Ut varius, odio tempus pellentesque imperdiet, tortor sapien faucibus justo, ut iaculis velit velit at leo.</p>
<a href="#" class="readmore">Read more...</a>
</div>
<div class="entry">
<h1><a href="#">CrownCloud $7/Month 1024MB KVM VPS in Frankfurt, Germany</a></h1>
<img src="/static/images/crowncloud.jpg">
<div class="metadata">
<span class="date">2 days ago</span>, by
<span class="author">joepie91</span>
<span class="tags">Tags: germany, kvm</span>
{%?entry[teaser]}
<a href="{%?entry[url]}" class="readmore">Read more...</a>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam gravida nisi ut sapien dignissim ornare. Ut nisl eros, pharetra molestie malesuada vitae, elementum sit amet dui. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur elementum leo et erat malesuada id convallis nibh faucibus. Etiam tempor faucibus urna ut blandit. Pellentesque laoreet est vel risus lobortis vehicula. Vestibulum interdum lectus et metus hendrerit ullamcorper.</p>
<p>Suspendisse libero massa, mattis at laoreet vel, tincidunt id arcu. Curabitur ac suscipit tellus. In hac habitasse platea dictumst. Donec sed leo arcu. Maecenas tempor nunc et nisi ullamcorper nec interdum lorem porttitor. In suscipit semper justo, ut pellentesque sapien ultrices a. Nam ut viverra erat. Nulla facilisi. Mauris auctor eleifend dui id vestibulum. Ut varius, odio tempus pellentesque imperdiet, tortor sapien faucibus justo, ut iaculis velit velit at leo.</p>
<a href="#" class="readmore">Read more...</a>
</div>
{%/foreach}
<div class="entry">
<h1><a href="#">InfinityHosts $4.99 256MB OpenVZ VPS in the Netherlands</a></h1>
<img src="/static/images/infinityhosts.jpg">
<div class="metadata">
<span class="date">4 days ago</span>, by
<span class="author">joepie91</span>
<span class="tags">Tags: netherlands, openvz</span>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam gravida nisi ut sapien dignissim ornare. Ut nisl eros, pharetra molestie malesuada vitae, elementum sit amet dui. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur elementum leo et erat malesuada id convallis nibh faucibus. Etiam tempor faucibus urna ut blandit. Pellentesque laoreet est vel risus lobortis vehicula. Vestibulum interdum lectus et metus hendrerit ullamcorper.</p>
<p>Suspendisse libero massa, mattis at laoreet vel, tincidunt id arcu. Curabitur ac suscipit tellus. In hac habitasse platea dictumst. Donec sed leo arcu. Maecenas tempor nunc et nisi ullamcorper nec interdum lorem porttitor. In suscipit semper justo, ut pellentesque sapien ultrices a. Nam ut viverra erat. Nulla facilisi. Mauris auctor eleifend dui id vestibulum. Ut varius, odio tempus pellentesque imperdiet, tortor sapien faucibus justo, ut iaculis velit velit at leo.</p>
<a href="#" class="readmore">Read more...</a>
<div class="pagination">
{%if pagination-first == false}
<a href="/forums/p{%?previous-page}" class="previous">&lt;</a>
{%/if}
{%foreach page in pages}
<a href="/forums/p{%?page[value]}" {%if page[current] == true}class="current"{%/if}>{%?page[value]}</a>
{%/foreach}
{%if pagination-last == false}
<a href="/forums/p{%?next-page}" class="next">&gt;</a>
{%/if}
</div>

Loading…
Cancel
Save