Skip to content

Commit

Permalink
metaData method has moved to the model
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Dec 20, 2011
1 parent 78c6dd9 commit ca1cde0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
45 changes: 11 additions & 34 deletions View/Helper/PostHelper.php
Expand Up @@ -10,46 +10,23 @@ class PostHelper extends AppHelper {
'Text'
);

public function metaData($file) {
$year = substr($file, 0, 4);
$month = substr($file, 5, 2);
$day = substr($file, 8, 2);
$slug = substr($file, 11, -3);
$date = mktime(0, 0, 0, $month, $day, $year);

return array(
'file' => $file,
'title' => str_replace('-', ' ', $slug),
'year' => $year,
'month' => $month,
'day' => $day,
'date' => $date,
'slug' => $slug,
'url' => "/$year/$month/$day/$slug.html"
);
}

public function data($file, $type = 'Posts') {
if (!$file) {
return;
}
$return = $this->metaData($file);
public function data($post, $type = 'Posts') {
if ($type === 'Posts') {
$contents = file_get_contents(Configure::read('PhasePosts') . $file);
$contents = file_get_contents(Configure::read('PhasePosts') . $post['file']);
} else {
$contents = file_get_contents(Configure::read('PhaseViews') . $type . DS . $file);
$contents = file_get_contents(Configure::read('PhaseViews') . $type . DS . $post['file']);
}
$parsed = $this->YFM->parse($contents);
$return += $parsed;
if (empty($return['intro'])) {
$return['intro'] = substr($return['contents'], 0, strpos($return['contents'], "\n", 1));
if (strlen($return['intro']) < 200) {
$return['intro'] = $this->Text->truncate($return['contents'], 400);
$post += $parsed;
if (empty($post['intro'])) {
$post['intro'] = substr($post['contents'], 0, strpos($post['contents'], "\n", 1));
if (strlen($post['intro']) < 200) {
$post['intro'] = $this->Text->truncate($post['contents'], 400);
}
$return['intro'] = '<p>' . $return['intro'] . '</p>';
$post['intro'] = '<p>' . $post['intro'] . '</p>';
}
$return['contents'] = $this->Markdown->process($return['contents']);
$post['contents'] = $this->Markdown->process($post['contents']);

return $return;
return $post;
}
}
7 changes: 3 additions & 4 deletions View/Layouts/xml/atom.ctp
Expand Up @@ -2,10 +2,9 @@
<feed xmlns="http://www.w3.org/2005/Atom">

<title><?php echo Configure::read('Phase.feed.title') ?></title>
<link href="http://AD7six.com/atom.xml" rel="self"/>
<link href="http://AD7six.com/"/>
<?php $lastPost = $this->Post->data($posts[0]); ?>
<updated><?php echo strftime('%Y-%m-%dT%H:%M:%s+%z', $lastPost['date']) ?></updated>
<link href="<?php echo Configure::read('Phase.site.domain') ?>atom.xml" rel="self"/>
<link href="<?php echo Configure::read('Phase.site.domain') ?>"/>
<updated><?php echo strftime('%Y-%m-%dT%H:%M:%s+%z', $posts[0]['date']) ?></updated>
<id><?php echo Configure::read('Phase.feed.id') ?></id>
<author>
<name><?php echo Configure::read('Phase.feed.author') ?></name>
Expand Down
2 changes: 1 addition & 1 deletion View/Posts/archives.ctp
Expand Up @@ -5,7 +5,7 @@ title: All posts

<h1>All articles</h1>
<ul class="posts">
<?php foreach($posts as $file): $post = $this->Post->metaData($file); ?>
<?php foreach($posts as $post): ?>
<li><span><?php echo strftime('%d %b, %G', $post['date']) ?></span> » <a href="<?php echo $post['url']?>"><?php echo $post['title'] ?></a></li>
<?php endforeach; ?>
</ul>
4 changes: 2 additions & 2 deletions View/Posts/home.ctp
Expand Up @@ -6,13 +6,13 @@ description: Latest posts from Somebody

<h2>Title</h2>
<p>Tagline.</p>
<?php $latest = $this->Post->data($latest); ?><h2>Latest: <a href="<?php echo $latest['url'] ?>"><?php echo $latest['title'] ?></a></h2>
<h2>Latest: <a href="<?php echo $latest['url'] ?>"><?php echo $latest['title'] ?></a></h2>
<h3 class="date"><?php echo strftime('%e %b, %G', $latest['date']) ?></h3>
<?php echo $latest['intro'] ?>

<h2>Recent Writing</h2>
<ul class="posts">
<?php foreach($posts as $file): $post = $this->Post->metaData($file); ?>
<?php foreach($posts as $post): ?>
<li><span><?php echo strftime('%d %b, %G', $post['date']) ?></span> » <a href="<?php echo $post['url']?>"><?php echo $post['title'] ?></a></li>
<?php endforeach; ?>
<li><a href="/archives.html">All articles</a></li>
Expand Down
2 changes: 1 addition & 1 deletion View/Posts/xml/archives.ctp
Expand Up @@ -2,7 +2,7 @@
layout: xml/atom
---

<?php foreach($posts as $file): $post = $this->Post->data($file); ?>
<?php foreach($posts as $post): $post = $this->Post->data($file); ?>
<entry>
<title><?php echo $post['title'] ?></title>
<link href="<?php echo Configure::read('Phase.site.domain') . $post['url']?>"/>
Expand Down

0 comments on commit ca1cde0

Please sign in to comment.