private function parseFeed($author, $feed)
 {
     $contenttype = $this->config['contenttype'];
     $reader = new Reader();
     $resource = $reader->download($feed['feed']);
     // Return the right parser instance according to the feed format
     $parser = $reader->getParser($resource->getUrl(), $resource->getContent(), $resource->getEncoding());
     // Return a Feed object
     $feeditems = $parser->execute();
     // Print the feed properties with the magic method __toString()
     // slice
     $items = array_slice($feeditems->items, 0, $this->config['itemAmount']);
     foreach ($items as $item) {
         //echo "<hr>\n";
         //echo " - " .$item->getTitle() . "<br>\n - " . \Bolt\Helpers\String::slug( $item->getTitle() ) . "\n";
         // try to get an existing record for this item
         $record = $this->app['storage']->getContent($contenttype, array('slug' => \Bolt\Helpers\String::slug($item->getTitle()), 'returnsingle' => true));
         if (!$record) {
             // New one.
             $record = $this->app['storage']->getContentObject($contenttype);
             echo "\n<b>[NEW]</b> ";
             $new = true;
         } else {
             echo "\n<b>[UPD]</b> : " . $record->values['id'];
             $new = false;
         }
         $date = new \DateTime("@" . $item->getDate());
         if ($item->getContent() != false) {
             $raw = $item->getContent();
         } else {
             $raw = $item->getIntro();
         }
         // Sanitize/clean the HTML.
         $maid = new \Maid\Maid(array('output-format' => 'html', 'allowed-tags' => array('p', 'br', 'hr', 's', 'u', 'strong', 'em', 'i', 'b', 'li', 'ul', 'ol', 'menu', 'blockquote', 'pre', 'code', 'tt', 'h2', 'h3', 'h4', 'h5', 'h6', 'dd', 'dl', 'dh', 'table', 'tbody', 'thead', 'tfoot', 'th', 'td', 'tr', 'a', 'img'), 'allowed-attribs' => array('id', 'class', 'name', 'value', 'href', 'src')));
         $content = $maid->clean($raw);
         // if ($item->getImage() != "") {
         //     $image = $item->getImage();
         // } else {
         $image = $this->findImage($content, $feed['url']);
         // }
         $values = array('itemid' => $item->getId(), 'title' => "" . $item->getTitle(), 'raw' => "" . $raw, 'body' => "" . $content, 'author' => $author, 'image' => $image, 'status' => 'published', 'sitetitle' => $feed['title'], 'sitesource' => $feed['url']);
         // echo "<img src='".$image['file']."' width='200'>";
         if ($new || $date instanceof \DateTime) {
             echo "[1]";
             $values['datecreated'] = $date instanceof \DateTime ? $date->format('Y-m-d H:i:s') : "";
             $values['datepublish'] = $date instanceof \DateTime ? $date->format('Y-m-d H:i:s') : "";
         } else {
             dump($date);
             echo "[2]";
         }
         // $record->setTaxonomy('tags', $item->getTags());
         // $record->setTaxonomy('authors', $author);
         $record->setValues($values);
         $id = $this->app['storage']->saveContent($record);
         echo " - " . $values['datecreated'] . " / " . $values['title'];
         flush();
     }
 }
Example #2
0
 /**
  * Add 'soft hyphens' &shy; to a string, so that it won't break layout in HTML when
  * using strings without spaces or dashes.
  *
  * @param string $str
  *
  * @return string
  */
 public function shy($str)
 {
     if (is_string($str)) {
         $str = String::shyphenate($str);
     }
     return $str;
 }