Esempio n. 1
0
 public function build(\SimplePie_Item $feed)
 {
     $data = new ArrayCollection();
     $data->set('title', $feed->get_title());
     $data->set('url', $feed->get_permalink());
     $data->set('description', $feed->get_description());
     return $data;
 }
Esempio n. 2
0
 /**
  * Parses a since feed item.
  *
  * @param \Devour\Table\TableInterface $table
  *   A table obeject.
  * @param \SimplePie_Item $item
  *   A SimplePie item.
  */
 protected function parseItem(TableInterface $table, \SimplePie_Item $item)
 {
     // @todo Add more fields.
     $row = $table->getNewRow();
     $row->set('id', $item->get_id())->set('permalink', $item->get_permalink())->set('title', $item->get_title())->set('date', $item->get_gmdate('U'))->set('content', $item->get_content());
     if ($author = $item->get_author()) {
         $row->set('author_name', $author->get_name())->set('author_email', $author->get_email());
     }
 }
Esempio n. 3
0
 /**
  * The constructor stores feed item attributes as properties.
  * 
  * @param type $feed the feed the new item belongs to
  * @param SimplePie_Item $item SimplePie_Item that contains information
  * about the item
  */
 public function __construct($feed, $item)
 {
     $this->_feed = $feed;
     $this->_title = $item->get_title();
     $this->_link = $item->get_permalink();
     $this->_description = $item->get_content();
     $this->_date = $item->get_date('U');
     $author = $item->get_author();
     $author_name = $author ? $author->get_name() : NULL;
     $this->_author = $author && empty($author_name) ? $author->get_email() : $author_name;
 }
Esempio n. 4
0
 /**
  *
  * Check if a feed item is suitable for import into database
  *
  * @param \SimplePie_Item  $item
  * @param \Datetime        $itemUploadedToFeed
  * @param \Datetime        $lastImportDate
  * @return bool
  */
 protected function checkSuitableForImport(\SimplePie_Item $item, $itemUploadedToFeed, $lastImportDate)
 {
     // only check new import items (ie added since last import date)
     if ($itemUploadedToFeed < $lastImportDate) {
         return false;
     }
     // check db to see if item was:
     //   - manually added by a protalk team member
     //   - somehow re-added to the feed, at a later date, but with the same title
     //   - previously imported but a protalk team member edited the title (hence permalink check)
     $repository = $this->entityManager->getRepository('ProtalkMediaBundle:Media');
     $itemExists = $repository->itemExists($item->get_permalink());
     if ($itemExists) {
         return false;
     }
     return true;
 }
Esempio n. 5
0
function filter(SimplePie_Item $item, array $patterns)
{
    foreach ($patterns as $pattern) {
        switch ($pattern["field"]) {
            case "title":
                if (preg_match($pattern["regex"], $item->get_title())) {
                    return false;
                }
                break;
            case "summary":
                if (preg_match($pattern["regex"], $item->get_description())) {
                    return false;
                }
                break;
            case "content":
                if (preg_match($pattern["regex"], $item->get_content())) {
                    return false;
                }
                break;
            case "url":
                if (preg_match($pattern["regex"], $item->get_permalink())) {
                    return false;
                }
                break;
            case "category":
                foreach ($item->get_categories() as $category) {
                    if (preg_match($pattern["regex"], $category->get_term()) || preg_match($pattern["regex"], $category->get_label())) {
                        return false;
                    }
                }
                break;
            default:
                die("Filter not implemented for field " . $pattern["field"]);
        }
    }
    return true;
}
Esempio n. 6
0
 /**
  * Parses the simplepie item to a content item
  * @param \SimplePie_Item $tweet
  * @param \Swiftriver\Core\ObjectModel\Channel $channel
  */
 private function ParseTweetFromATOMItem($tweet, $channel)
 {
     //Extract all the relevant feedItem info
     $title = $tweet->get_title();
     //$description = $tweet->get_description();
     $contentLink = $tweet->get_permalink();
     $date = $tweet->get_date();
     //Create the source
     $author = $tweet->get_author();
     $source_name = $author != null ? $author->get_name() : $channel->name;
     $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted);
     $source->name = $source_name;
     $source->email = $author != null ? $tweet->get_author()->get_email() : null;
     $source->link = $author != null ? $tweet->get_author()->get_link() : null;
     $source->parent = $channel->id;
     $source->type = $channel->type;
     $source->subType = $channel->subType;
     //Add location data
     //Long and lat
     $location = $tweet->get_item_tags("http://www.georss.org/georss", "point");
     $long = 0;
     $lat = 0;
     $name = "";
     if (is_array($location)) {
         $lat_lon_array = split(" ", $location[0]["data"]);
         $long = $lat_lon_array[1];
         $lat = $lat_lon_array[0];
         //Name
         $location_name = $tweet->get_item_tags("http://api.twitter.com", "place");
         if (is_array($location_name)) {
             if (isset($location_name[0]["child"]["http://api.twitter.com"]["full_name"][0]["data"])) {
                 $name = $location_name[0]["child"]["http://api.twitter.com"]["full_name"][0]["data"];
             }
         }
         $source->gisData = array(new \Swiftriver\Core\ObjectModel\GisData($long, $lat, $name));
     }
     //Create a new Content item
     $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
     //Fill the Content Item
     $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $title, array());
     $item->link = $contentLink;
     $item->date = strtotime($date);
     //Sanitize the tweet text into a DIF collection
     $sanitizedTweetDiffCollection = $this->ParseTweetToSanitizedTweetDiffCollection($tweet);
     //Add the dif collection to the item
     $item->difs = array($sanitizedTweetDiffCollection);
     //return the item
     return $item;
 }
Esempio n. 7
0
 /**
  * Parses the simplepie item to a content item
  * @param \SimplePie_Item $tweet
  * @param \Swiftriver\Core\ObjectModel\Source
  * @return \Swiftriver\Core\ObjectModel\Content
  */
 private function ParseTweetFromATOMItem($tweet, $channel)
 {
     //Extract all the relevant feedItem info
     $title = $tweet->get_title();
     //$description = $tweet->get_description();
     $contentLink = $tweet->get_permalink();
     $date = $tweet->get_date();
     //Create the source
     $author = $tweet->get_author();
     $source_name = $author != null ? $author->get_name() : $channel->name;
     $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name);
     $source->name = $source_name;
     $source->email = $author != null ? $tweet->get_author()->get_email() : null;
     $source->link = $author != null ? $tweet->get_author()->get_link() : null;
     $source->parent = $channel->id;
     $source->type = $channel->type;
     $source->subType = $channel->subType;
     //Create a new Content item
     $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
     //Fill the Content Item
     $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $title, array());
     $item->link = $contentLink;
     $item->date = strtotime($date);
     return $item;
 }