Permalink
Browse files

Added bytesToHuman in Utils

Removed Posts class
Refactored PostFinder to use arrays vs. arrays of objects for posts
Removed obsolete data for each post
Reworked the execution time to be a bit better
Changed view variables and calls to PostFinder to now use the array notation for data
  • Loading branch information...
niden committed Oct 3, 2015
1 parent bd3dd8f commit e907099e716aea7589f4572ff592d5d446b8ccd9
@@ -53,10 +53,10 @@ public function rssAction()
$posts = $this->finder->getLatest(1);
foreach ($posts as $post) {
$feedItem = new Item();
- $feedItem->setTitle($post->getTitle());
- $feedItem->setLink($this->getFullUrl('/post/' . $post->getSlug()));
- $feedItem->setDescription($post->getContent());
- $feedItem->setDate($post->getDate());
+ $feedItem->setTitle($post['title']);
+ $feedItem->setLink($this->getFullUrl('/post/' . $post['slug']));
+ $feedItem->setDescription($post['content']);
+ $feedItem->setDate($post['date']);
$feed->addItem($feedItem);
}
@@ -87,8 +87,8 @@ public function sitemapAction()
$data = [];
foreach ($posts as $post) {
$data[] = [
- 'location' => sprintf($template, $post->getSlug()),
- 'lastModified' => $post->getDate(),
+ 'location' => sprintf($template, $post['slug']),
+ 'lastModified' => $post['date'],
'changeFrequency' => 'monthly',
'priority' => 0.5
];
@@ -130,7 +130,7 @@ public function viewAction($slug)
$this->view->setVar('showDisqus', true);
$this->view->setVar('post', $post);
- $this->view->setVar('title', $post ? $post->getTitle() : '');
+ $this->view->setVar('title', $post ? $post['title'] : '');
$viewFile = 'posts/view';
if (true === boolval($this->config->blog->customLayout)) {
$viewFile = 'posts/custom.view';
@@ -2,19 +2,19 @@
<div class="media-body">
<div class="media-heading">
<small class="pull-right text-muted">
- <a href="/post/{{ post.getSlug() }}">
+ <a href="/post/{{ post['slug'] }}">
<span class="icon icon-link"></span>
</a>
- {{ post.getDate() }}
+ {{ post['date'] }}
</small>
- <h3>{{ post.getTitle() }}</h3>
+ <h3>{{ post['title'] }}</h3>
</div>
<p>
- {{ post.getContent() }}
+ {{ post['content'] }}
</p>
</div>
<div class="media-body-actions">
- {% for tag in post.getTags() %}
+ {% for tag in post['tags'] %}
<button class="btn btn-primary-outline btn-sm">
{{ tag }}
</button>
@@ -26,8 +26,8 @@
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '{{ config.blog.disqus.shortName }}';
- var disqus_identifier = "{{ post.getDisqusId() }}";
- var disqus_url = '{{ post.getDisqusUrl() }}';
+ var disqus_identifier = "{{ post['disqusId'] }}";
+ var disqus_url = '{{ post['disqusUrl'] }}';
(function () {
var dsq = document.createElement('script');
@@ -181,19 +181,16 @@ function (\Exception $exception) use ($logger) {
);
register_shutdown_function(
- function () use ($logger, $memoryUsage, $currentTime) {
- $memoryUsed = number_format(
- (memory_get_usage() - $memoryUsage) / 1024,
- 3
- );
- $executionTime = number_format(
- (microtime(true) - $currentTime),
- 4
- );
+ function () use ($logger, $utils, $memoryUsage, $currentTime) {
+ $memoryUsed = memory_get_usage() - $memoryUsage;
+ $executionTime = microtime(true) - $currentTime;
if (K_DEBUG) {
$logger->info(
- 'Shutdown completed [Memory: ' . $memoryUsed . 'Kb] ' .
- '[Execution: ' . $executionTime .']'
+ sprintf(
+ 'Shutdown completed [%s]s - [%s]',
+ round($executionTime, 3),
+ $utils->bytesToHuman($memoryUsed)
+ )
);
}
}
View
@@ -1,178 +0,0 @@
-<?php
-/*
- +------------------------------------------------------------------------+
- | Kitsune |
- +------------------------------------------------------------------------+
- | Copyright (c) 2015-2015 Phalcon Team and contributors |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file docs/LICENSE.txt. |
- | |
- | If you did not receive a copy of the license and are unable to |
- | obtain it through the world-wide-web, please send an email |
- | to license@phalconphp.com so we can send you a copy immediately. |
- +------------------------------------------------------------------------+
-*/
-
-/**
- * Post.php
- * \Kitsune\PostFinder
- *
- * Represents a post
- */
-namespace Kitsune;
-
-use Kitsune\Markdown as KMarkdown;
-
-class Post
-{
- private $data = [];
-
- public function getTitle()
- {
- return $this->data['title'];
- }
-
- public function getSlug()
- {
- return $this->data['slug'];
- }
-
- public function getDate()
- {
- return $this->data['date'];
- }
-
- public function getYear()
- {
- return $this->data['year'];
- }
-
- public function getMonth()
- {
- return $this->data['month'];
- }
-
- public function getContent()
- {
- return $this->data['content'];
- }
-
- public function getRaw()
- {
- return $this->data['raw'];
- }
-
- public function getLink()
- {
- return $this->data['link'];
- }
-
- public function getTags()
- {
- return $this->data['tags'];
- }
-
- public function getFile()
- {
- return $this->data['file'];
- }
-
- public function getDisqusId()
- {
- return $this->data['disqusId'];
- }
-
- public function getDisqusUrl()
- {
- return $this->data['disqusUrl'];
- }
-
- public function __construct($config, $markdown)
- {
- $this->config = $config;
- $this->markdown = $markdown;
- $this->url = $config->blog->disqus->url;
-
- $this->init();
- }
-
- public function load($post)
- {
- /**
- * Initialize the internal array
- */
- $this->init();
-
- $dateParts = explode("-", $post['date']);
- $this->data['year'] = $dateParts[0];
- $this->data['month'] = $dateParts[1];
- $this->data['date'] = $post['date'];
- $this->data['slug'] = $post['slug'];
- $this->data['title'] = $post['title'];
- $this->data['link'] = $post['link'];
-
- if ($this->getLink()) {
- $this->data['disqusUrl'] = $this->getLink();
- $this->data['disqusId'] = sprintf(
- $this->config->blog->disqus->idTemplate,
- $this->getTitle()
- );
- } else {
- $this->data['disqusUrl'] = $this->config->blog->disqus->url
- . '/post/'
- . $this->getSlug();
- $this->data['disqusId'] = sprintf(
- $this->config->blog->disqus->idTemplate,
- str_replace(['"', "''"], ['', ''], $this->getTitle())
- );
- }
-
- $this->data['file'] = sprintf(
- '%s/%s/%s-%s.md',
- $dateParts[0],
- $dateParts[1],
- $this->getDate(),
- $this->getSlug()
- );
-
- $tags = explode(',', $post['tags']);
- foreach ($tags as $tag) {
- $this->data['tags'][] = trim($tag);
- }
-
- /**
- * Get the cdnUrl
- */
- $cdnUrl = $this->config->cdnUrl;
-
- /**
- * Get the post itself
- */
- $fileName = K_PATH . '/data/posts/' . $this->getFile();
- if (file_exists($fileName)) {
- $markdown = new KMarkdown();
- $this->data['raw'] = file_get_contents($fileName);
- $this->data['raw'] = str_replace('{{ cdnUrl }}', $cdnUrl, $this->getRaw());
- $this->data['content'] = $markdown->render($this->getRaw());
- }
- }
-
- private function init()
- {
- $this->data = [
- 'title' => '',
- 'slug' => '',
- 'date' => '',
- 'year' => '',
- 'month' => '',
- 'content' => '',
- 'raw' => '',
- 'link' => '',
- 'tags' => [],
- 'disqusId' => '',
- 'disqusUrl' => '',
- 'file' => '',
- ];
- }
-}
Oops, something went wrong.

0 comments on commit e907099

Please sign in to comment.