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; }
/** * * 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; }
public function getFavIcon(SimplePie_Item $item) { $shortname = ''; $categories = $item->get_categories(); foreach ($categories as $category) { $matches = array(); $matched = preg_match('/short=([a-z-]+)/', $category->get_term(), $matches); if ($matched === 1) { $shortname = $matches[1]; break; } } if (array_key_exists($shortname, self::$map)) { $favIcon = self::$map[$shortname]; } else { $favIcon = $item->get_feed()->get_favicon(); } return $favIcon; }
/** * 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()); } }
/** * 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; }
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; }
/** * Populate an item from a feed item * * @param $item \Planetflow3\Domain\Model\Item * @param $feedItem \SimplePie_Item * @return void */ protected function populateItemProperties(Item $item, \SimplePie_Item $feedItem) { $item->setLink($feedItem->get_link()); $item->setTitle($feedItem->get_title()); $item->setDescription($feedItem->get_description()); $item->setContent($feedItem->get_content(TRUE)); $item->setPublicationDate(new \DateTime($feedItem->get_date())); $item->setAuthor($feedItem->get_author()); }
/** * @param \SimplePie_Item $tweet * @return \Swiftriver\Core\ObjectModel\DuplicationIdentificationFieldCollection */ private function ParseTweetToSanitizedTweetDiffCollection($tweet) { //Get the original text $tweetText = $tweet->get_title(); //Break the text down into words $tweetTextParts = explode(" ", $tweetText); //Set up the sanitized return string $sanitizedText = ""; //loop through all the words foreach ($tweetTextParts as $part) { //to lowwer the word $part = strtolower($part); //If the word contains none standard chars, continue if (preg_match("/[^\\w\\d\\.\\(\\)\\!']/si", $part)) { continue; } //if the owrd is just rt then continue if ($part == "rt") { continue; } //Add the word to the sanitized $sanitizedText .= $part . " "; } //Create a new Diff $dif = new \Swiftriver\Core\ObjectModel\DuplicationIdentificationField("Sanitized Tweet", utf8_encode($sanitizedText)); //Create the new diff collection $difCollection = new \Swiftriver\Core\ObjectModel\DuplicationIdentificationFieldCollection("Sanitized Tweet", array($dif)); //Return the diff collection return $difCollection; }
/** * 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; }
/** * Constructor */ function WP_SimplePieAtomPub_Item($feed, $data) { parent::SimplePie_Item($feed, $data); }
/** * @return string twitterified content */ function get_content($content_only = false) { $content = $this->twitterify(parent::get_content($content_only)); return $content; }
protected function getLinkFromItem(SimplePie_Item $i) { /* @var $e SimplePie_Enclosure */ $e = $i->get_enclosure(0); if (empty($e)) { return ''; } return $e->get_link(); }
/** * @param SimplePie_Item $item * @return string */ function socialbookmarks_get_tags($item) { global $serendipity; $return = ''; $taglink = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/tag/'; switch ($this->get_config('socialbookmarksService')) { case 'del.icio.us': // quite easy $return .= '<br/><p style="font-size:.7em;margin:0;padding:0" class="serendipity_socialbookmarks_tags">[Tags:'; $tags = $item->get_categories(); /** @var SimplePie_Category $tag */ foreach ($tags as $tag) { $return .= ' <a href="' . $taglink . socialbookmarks_freetag_compat(strtolower($tag->get_term())) . '" rel="tag">' . strtolower($tag->get_term()) . '</a>'; } $return .= ']</p>'; break; case 'ma.gnolia': // they've changed this recently $return .= '<br/><p style="font-size:.7em;margin:0;padding:0" class="serendipity_socialbookmarks_tags">[Tags:'; $tags = $item->get_categories(); //$tags = explode(' ', $tags[0]); foreach ($tags as $tag) { $return .= ' <a href="' . $taglink . socialbookmarks_freetag_compat(strtolower($tag)) . '" rel="tag">' . strtolower($tag) . '</a>'; } $return .= ']</p>'; break; case 'furl': $return .= '<br/><p style="font-size:.7em;margin:0;padding:0" class="serendipity_socialbookmarks_tags">[Tags:'; $tags = $item->get_category(); foreach ($tags as $tag) { $return .= ' <a href="' . $taglink . socialbookmarks_freetag_compat(strtolower($tag)) . '" rel="tag">' . strtolower($tag) . '</a>'; } $return .= ']</p>'; break; case 'misterwong': case 'linkroll': // services don't provide tags in their RSS feeds (yet)!? // services don't provide tags in their RSS feeds (yet)!? default: break; } return $return; }
function get_categories() { $cats = parent::get_categories(); $mycats = array(); if (!is_null($cats)) { foreach ($cats as $cat) { $mycats[] = $cat->term; } } return $mycats; }
function get_source() { return apply_filters('feedwordpie_item_get_source', parent::get_source(), $this); }
/** * 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; }
/** * MagpieFromSimplePie::normalize_author_inheritance * * @param SimplePie_Item $original * * @uses SimplePie_Item::get_authors * @uses SimplePie_Author::get_name * @uses SimplePie_Author::get_link * @uses SimplePie_Author::get_email * @uses MagpieFromSimplePie::increment_element */ function normalize_author_inheritance(&$item, $original) { // "If an atom:entry element does not contain // atom:author elements, then the atom:author elements // of the contained atom:source element are considered // to apply. In an Atom Feed Document, the atom:author // elements of the containing atom:feed element are // considered to apply to the entry if there are no // atom:author elements in the locations described // above." <http://atompub.org/2005/08/17/draft-ietf-atompub-format-11.html#rfc.section.4.2.1> if (!isset($item["author#"])) { $authors = $original->get_authors(); foreach ($authors as $author) { $tag = $this->increment_element($item, 'author', 'atom', array()); $item[$tag] = $item["{$tag}_name"] = $author->get_name(); if ($author->get_link()) { $item["{$tag}_uri"] = $item["{$tag}_url"] = $author->get_link(); } if ($author->get_email()) { $item["{$tag}_email"] = $author->get_email(); } } } }
/** * Implements CollectionAbstract::buildDocument(). * * @param IndexDocument $document * @param \SimplePie_Item $data */ public function buildDocument(IndexDocument $document, $data) { $document->source = $this->_feed->get_title(); $document->subject = $this->_feed->get_description(); $document->title = $data->get_title(); $document->link = $data->get_link(); $document->description = $data->get_description(); $document->creator = (array) $data->get_author(); $document->date = $data->get_date(); // PHP properties cannot have dashes (-), and the fields below have // dashes in the field name. $document->source_link = $this->_feed->get_link(); $document->getField('source_link')->setName('source-link'); $document->item_subject = $this->_feed->get_link(); $document->getField('item_subject')->setName('item-subject'); }
/** * Pieces together the title attribute without using inline ternary conditional statements * * @access public * @param SimplePie_Item $item The item to generate the title attribute for. * @param integer $length The number of characters to return in the description. * @param string $date_format The format to use when displaying dates on items. Uses values from http://php.net/strftime, NOT http://php.net/date. * @return string The string for the title attribute. */ function get_title_attr($item, $length, $date_format) { // Get a handle for the item's parent feed object for PHP 4.x. $parent = $item->get_feed(); $title_attr = ''; $title_attr .= $item->get_title(); // The title of the post $title_attr .= ' :: '; // The separator between the title and the description (required by MooTools) $title_attr .= newsblocks::cleanup($item->get_description(), $length); // The cleaned-up and shortened version of the description $title_attr .= '<span>'; // This marks the beginning of the date/domain line (and is CSS styleable) // Does the item have a timestamp? if ($item->get_local_date($date_format)) { $title_attr .= $item->get_local_date($date_format); // Use the locale-friendly version for non-English languages. $title_attr .= ' // '; // Visual separator. } $title_attr .= newsblocks::name($parent->subscribe_url()); // The domain name that the item is coming from. $title_attr .= '</span>'; // Mark the end of the date/domain line. return $title_attr; }