/**
  * Implements FormatterInterface->format().
  *
  * @param \Zend\Feed\Reader\Entry\EntryInterface $item
  * @return string
  */
 public function format(EntryInterface $item)
 {
     $created = $item->getDateCreated();
     if ($created instanceof \DateTime) {
         $created = $created->format($this->datePattern);
     }
     $modified = $item->getDateModified();
     if ($modified instanceof \DateTime) {
         $modified = $modified->format($this->datePattern);
     }
     $author = $item->getAuthor();
     if (is_array($author)) {
         $authorname = $author['name'];
         $authoremail = isset($author['email']) ? $author['email'] : null;
         $authoruri = isset($author['uri']) ? $author['uri'] : null;
     } else {
         $authorname = '';
         $authoremail = '';
         $authoruri = '';
     }
     $replacements = array('%authorname%' => $authorname, '%authoremail%' => $authoremail, '%authoruri%' => $authoruri, '%content%' => $item->getContent(), '%datecreated%' => $created, '%datemodified%' => $modified, '%description%' => $item->getDescription(), '%id%' => $item->getId(), '%link%' => $item->getLink(), '%links%' => implode(' ', $item->getLinks()), '%permalink%' => $item->getPermalink(), '%title%' => $item->getTitle(), '%commentcount%' => $item->getCommentCount(), '%commentlink%' => $item->getCommentLink(), '%commentfeedlink%' => $item->getCommentFeedLink());
     $formatted = str_replace(array_keys($replacements), array_values($replacements), $this->pattern);
     return $formatted;
 }
Beispiel #2
0
 /**
  * Create post from entry
  *
  * @param EntryInterface $entry
  *
  * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
  */
 protected function createPostFromEntry(EntryInterface $entry)
 {
     $date = !empty($entry->getDateModified()) ? $entry->getDateModified()->format('Y-m-d H:i:s') : null;
     // Create post object
     $postData = ['post_author' => $this->entryParams['authorId'], 'post_content' => wp_kses_post($entry->getContent()), 'post_date' => $date, 'post_status' => $this->entryParams['status'], 'post_title' => wp_strip_all_tags($entry->getTitle()), 'post_type' => $this->postType];
     // Insert the post into the database
     $postId = wp_insert_post($postData);
     // Add meta.
     if (is_int($postId)) {
         add_post_meta($postId, 'feed_importer_feed_entry_id', wp_strip_all_tags($entry->getId()));
         if ($entry->getLink()) {
             add_post_meta($postId, 'feed_importer_feed_entry_link', wp_strip_all_tags($entry->getLink()));
         }
         if ($entry->getAuthors()) {
             add_post_meta($postId, 'feed_importer_feed_entry_authors', $entry->getAuthors()->getValues());
         }
         if (is_callable($this->entryParams['afterInsertPost'])) {
             call_user_func($this->entryParams['afterInsertPost'], $postId);
         }
     }
     return $postId;
 }