Permalink
Browse files

Updated Compiler to consume AuthorEntity objects

- Checks that a post is valid before using it
- If an AuthorEntity is present, pulls the ID from it when creating the
  "byAuthor" list
- If an AuthorEntity is in a post, those details will be used when
  creating the feed
  • Loading branch information...
1 parent 4d5429d commit 490e0e94bc3b69df12067b609bf4e212888f999e @weierophinney weierophinney committed Mar 28, 2012
Showing with 37 additions and 4 deletions.
  1. +3 −0 README.md
  2. +3 −0 autoload_classmap.php
  3. +10 −2 misc/sample-post.php
  4. +21 −2 src/PhlyBlog/Compiler.php
View
@@ -118,6 +118,9 @@ You will want to setup local configuration; I recommend putting it in
'entries_template' => 'phly-blog/list',
'entry_template' => 'phly-blog/entry',
+ // The feed author information is default information to use when
+ // the author of a post is unknown, or is not an AuthorEntity
+ // object (and hence does not contain this information).
'feed_author_email' => 'you@your.tld',
'feed_author_name' => "Your Name Here",
'feed_author_uri' => 'http://your.tld',
View
@@ -2,7 +2,9 @@
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'PhlyBlog\Filter\EntryFilter' => __DIR__ . '/src/PhlyBlog/Filter/EntryFilter.php',
+ 'PhlyBlog\Filter\AuthorFilter' => __DIR__ . '/src/PhlyBlog/Filter/AuthorFilter.php',
'PhlyBlog\Filter\Tags' => __DIR__ . '/src/PhlyBlog/Filter/Tags.php',
+ 'PhlyBlog\Filter\Url' => __DIR__ . '/src/PhlyBlog/Filter/Url.php',
'PhlyBlog\Filter\Permalink' => __DIR__ . '/src/PhlyBlog/Filter/Permalink.php',
'PhlyBlog\Compiler\WriterInterface' => __DIR__ . '/src/PhlyBlog/Compiler/WriterInterface.php',
'PhlyBlog\Compiler\FileWriter' => __DIR__ . '/src/PhlyBlog/Compiler/FileWriter.php',
@@ -11,4 +13,5 @@
'PhlyBlog\Compiler' => __DIR__ . '/src/PhlyBlog/Compiler.php',
'PhlyBlog\CompilerOptions' => __DIR__ . '/src/PhlyBlog/CompilerOptions.php',
'PhlyBlog\EntryEntity' => __DIR__ . '/src/PhlyBlog/EntryEntity.php',
+ 'PhlyBlog\AuthorEntity' => __DIR__ . '/src/PhlyBlog/AuthorEntity.php',
);
View
@@ -1,11 +1,19 @@
<?php
+use PhlyBlog\AuthorEntity;
use PhlyBlog\EntryEntity;
-$entry = new EntryEntity();
+$entry = new EntryEntity();
+$author = new AuthorEntity();
+$author->fromArray(array(
+ 'id' => 'yourusername',
+ 'name' => 'Your Full Name',
+ 'email' => 'you@your.tld',
+ 'url' => 'http://your.tld/',
+));
$entry->setId('this-is-the-stub-used-in-the-uri-and-should-be-unique');
$entry->setTitle('New site!');
-$entry->setAuthor('matthew');
+$entry->setAuthor($author);
$entry->setDraft(false);
$entry->setPublic(true);
$entry->setCreated(1300744335);
View
@@ -333,6 +333,11 @@ protected function prepareEntries()
continue;
}
+ if (!$entry->isValid()) {
+ // if we have an invalid entry, we should not continue
+ continue;
+ }
+
if ($entry->isDraft()) {
continue;
}
@@ -383,6 +388,9 @@ protected function prepareEntries()
// Finally, by author
$author = $entry->getAuthor();
+ if ($author instanceof AuthorEntity) {
+ $author = $author->getId();
+ }
if (!isset($this->byAuthor[$author])) {
$this->byAuthor[$author] = new Compiler\SortedEntries();
}
@@ -529,7 +537,7 @@ protected function iterateAndGenerateFeed(
if (empty($authorUri)) {
$authorUri = $blogLink;
}
- $author = array(
+ $defaultAuthor = array(
'name' => $this->options->getFeedAuthorName(),
'email' => $this->options->getFeedAuthorEmail(),
'uri' => $authorUri,
@@ -540,11 +548,22 @@ protected function iterateAndGenerateFeed(
if (!$latest) {
$latest = $post;
}
+
+ $authorDetails = $defaultAuthor;
+ $author = $post->getAuthor();
+ if ($author instanceof AuthorEntity && $author->isValid()) {
+ $authorDetails = array(
+ 'name' => $author->getName(),
+ 'email' => $author->getEmail(),
+ 'uri' => $author->getUri(),
+ );
+ }
+
$entry = $feed->createEntry();
$entry->setTitle($post->getTitle());
$entry->setLink(sprintf($linkTemplate, $post->getId()));
- $entry->addAuthor($author);
+ $entry->addAuthor($authorDetails);
$entry->setDateModified($post->getUpdated());
$entry->setDateCreated($post->getCreated());
$entry->setContent($post->getBody());

0 comments on commit 490e0e9

Please sign in to comment.