public function get_feed(array $args) { // Read items from Content Repository $this->get_items($args); // Set up feed midgardmvc_core::get_instance()->component->load_library('Feed'); $feed = new ezcFeed(); $feed->title = $this->data['title']; $feed->description = ''; $now = new DateTime(); $feed->published = $now->format(DateTime::RSS); $link = $feed->add('link'); $link->href = midgardmvc_core::get_instance()->dispatcher->generate_url('index', array(), $this->request); array_walk($this->data['items'], function ($item) use($feed) { $feeditem = $feed->add('item'); $feeditem->title = $item->title; $feeditem->description = $item->content; $feeditem->published = $item->published->format(DateTime::RSS); $author = $feeditem->add('author'); $author->name = $item->firstname; $link = $feeditem->add('link'); $link->href = $item->url; }); $this->data['feed'] = $feed; }
public function testRunRegression($file) { $errors = array(); $outFile = $this->outFileName($file, '.in', '.out'); try { $parsed = ezcFeed::parseContent(file_get_contents($file)); $expected = (include_once $outFile); $this->cleanForCompare($expected, $parsed); } catch (ezcFeedException $e) { $parsed = $e->getMessage(); $expected = trim(file_get_contents($outFile)); } $this->assertEquals(var_export($expected, true), var_export($parsed, true), "The " . basename($outFile) . " is not the same as the parsed feed from " . basename($file) . "."); }
public static function fetch_feed(com_meego_planet_feed $feed, $index, $item_callback) { if (!is_callable($item_callback)) { throw InvalidArgumentException('Item processing callback must be a valid function'); } midgardmvc_core::get_instance()->component->load_library('Feed'); try { $fetched = ezcFeed::parse($feed->feed); } catch (Exception $e) { midgardmvc_core::get_instance()->log(__CLASS__, $e->getMessage(), 'info'); return false; } $items = $fetched->item; array_walk($items, $item_callback, $feed); self::remove_missing($items, $feed); }
/** * Returns a new instance of the $name module with data container level $level. * * @param string $name The name of the module to create * @param string $level The level of the data container ('feed' or 'item') * @return ezcFeedModule */ public static function create($name, $level = 'feed') { $supportedModules = ezcFeed::getSupportedModules(); if (!isset($supportedModules[$name])) { throw new ezcFeedUnsupportedModuleException($name); } return new $supportedModules[$name]($level); }
/** * Parses the provided XML element object and stores it as a feed textinput in * the provided ezcFeed object. * * @param ezcFeed $feed The feed object in which to store the parsed XML element as a feed textinput * @param DOMElement $xml The XML element object to parse */ private function parseTextInput(ezcFeed $feed, DOMElement $xml = null) { $textInput = $feed->add('textInput'); if ($xml !== null) { foreach ($xml->childNodes as $itemChild) { if ($itemChild->nodeType == XML_ELEMENT_NODE) { $tagName = $itemChild->tagName; switch ($tagName) { case 'title': case 'description': case 'name': case 'link': $textInput->{$tagName} = $itemChild->textContent; break; } } } if ($xml->hasAttributeNS(self::NAMESPACE_URI, 'about')) { $textInput->about = $xml->getAttributeNS(self::NAMESPACE_URI, 'about'); } } }
/** * Parses the provided XML document object and returns an ezcFeed object * from it. * * @throws ezcFeedParseErrorException * If an error was encountered during parsing. * * @param DOMDocument $xml The XML document object to parse * @return ezcFeed */ public function parse(DOMDocument $xml) { $feed = new ezcFeed(self::FEED_TYPE); $rssChildren = $xml->documentElement->childNodes; $channel = null; $this->usedPrefixes = $this->fetchUsedPrefixes($xml); foreach ($rssChildren as $rssChild) { if ($rssChild->nodeType === XML_ELEMENT_NODE && $rssChild->tagName === 'channel') { $channel = $rssChild; } } if ($channel === null) { throw new ezcFeedParseErrorException(null, "No channel tag"); } foreach ($channel->childNodes as $channelChild) { if ($channelChild->nodeType == XML_ELEMENT_NODE) { $tagName = $channelChild->tagName; switch ($tagName) { case 'title': case 'description': case 'copyright': $element = $feed->add($tagName); $element->text = $channelChild->textContent; break; case 'language': case 'ttl': case 'docs': case 'rating': $element = $feed->add($tagName); $element->text = $channelChild->textContent; break; case 'generator': $element = $feed->add($tagName); $element->name = $channelChild->textContent; break; case 'managingEditor': $element = $feed->add('author'); $element->name = $channelChild->textContent; // @todo parse $name to see if it has the structure // email@address (name) to fill the ->email field from it break; case 'webMaster': $element = $feed->add('webMaster'); $element->name = $channelChild->textContent; // @todo parse $name to see if it has the structure // email@address (name) to fill the ->email field from it break; case 'category': $element = $feed->add($tagName); $element->term = $channelChild->textContent; if ($channelChild->hasAttribute('domain')) { $element->scheme = $channelChild->getAttribute('domain'); } break; case 'link': $element = $feed->add($tagName); $element->href = $channelChild->textContent; break; case 'cloud': $element = $feed->add($tagName); $attributes = array('domain' => 'domain', 'port' => 'port', 'path' => 'path', 'registerProcedure' => 'registerProcedure', 'protocol' => 'protocol'); foreach ($attributes as $name => $alias) { if ($channelChild->hasAttribute($name)) { $element->{$alias} = $channelChild->getAttribute($name); } } break; case 'pubDate': $feed->published = $channelChild->textContent; break; case 'lastBuildDate': $feed->updated = $channelChild->textContent; break; case 'item': $element = $feed->add($tagName); $this->parseItem($element, $channelChild); break; case 'image': $image = $feed->add('image'); $this->parseImage($image, $channelChild); break; case 'skipHours': $element = $feed->add($tagName); $this->parseSkipHours($element, $channelChild); break; case 'skipDays': $element = $feed->add($tagName); $this->parseSkipDays($element, $channelChild); break; case 'textInput': $element = $feed->add($tagName); $this->parseTextInput($element, $channelChild); break; default: // check if it's part of a known module/namespace $this->parseModules($feed, $channelChild, $tagName); } } } return $feed; }
public function __construct($src) { $zeta = \ezcFeed::parse($src); $this->rawData = $zeta; }
function node2rss($nodeList, $meta) { $feed = new ezcFeed(); $feed->title = $meta['title']; $feed->description = $meta['description']; $feed->language = $meta['language']; $link = $feed->add('link'); $link->href = sprintf('http://%s/', $meta['siteURL']); // to add the <atom:link> element needed for RSS2 $feed->id = sprintf('http://%s%s/', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']); // required for ATOM $feed->updated = time(); $author = $feed->add('author'); $author->email = $meta['authorMail']; $author->name = $meta['authorName']; $descriptionFields = $this->feedIni->variable('FeedSettings', 'description'); $contentFields = $this->feedIni->variable('FeedSettings', 'content'); $catFields = $this->feedIni->variable('FeedSettings', 'category'); // convert objects to nodes, filter class types, and limit number foreach ($nodeList as $node) { $item = $feed->add('item'); $item->title = $node->attribute('name'); $item->published = date('r', $node->ContentObject->Published); $link = $item->add('link'); $link->href = sprintf('http://%s/%s', $meta['siteURL'], $node->attribute('url_alias')); $item->id = sprintf('http://%s/content/view/full/%d', $meta['siteURL'], $node->attribute('node_id')); $map = $node->attribute('data_map'); $description = $this->preferedField($descriptionFields, $map); $item->description = $description; $content = $this->preferedField($contentFields, $map); if (!empty($content)) { $module = $item->addModule('Content'); $module->encoded = $content; } $tagString = $this->preferedField($catFields, $map); $tags = explode('|#', $tagString); foreach ($tags as $tag) { $cat = $item->add('category'); $cat->term = $tag; } } $rss = $feed->generate('rss2'); // add host to local links $rss = preg_replace('#(src|href)=([\'"])/#i', sprintf("\$1=\$2http:/%s/", $meta['siteURL']), $rss); return $rss; }
/** * Generates an RSS feed document with type $type and returns it as a string. * * It uses the Feed component from eZ Components. * * Supported types: 'rss1', 'rss2', 'atom'. * * @since 4.2 * @param string $type One of 'rss1', 'rss2' and 'atom' * @return string XML document as a string */ function generateFeed( $type ) { $locale = eZLocale::instance(); // Get URL Translation settings. $config = eZINI::instance(); if ( $config->variable( 'URLTranslator', 'Translation' ) == 'enabled' ) { $useURLAlias = true; } else { $useURLAlias = false; } if ( $this->attribute( 'url' ) == '' ) { $baseItemURL = ''; eZURI::transformURI( $baseItemURL, false, 'full' ); $baseItemURL .= '/'; } else { $baseItemURL = $this->attribute( 'url' ) . '/'; //.$this->attribute( 'site_access' ).'/'; } $feed = new ezcFeed(); $feed->title = $this->attribute( 'title' ); $link = $feed->add( 'link' ); $link->href = $baseItemURL; $feed->description = $this->attribute( 'description' ); $feed->language = $locale->httpLocaleCode(); // to add the <atom:link> element needed for RSS2 $feed->id = $baseItemURL . 'rss/feed/' . $this->attribute( 'access_url' ); // required for ATOM $feed->updated = time(); $author = $feed->add( 'author' ); $author->email = $config->variable( 'MailSettings', 'AdminEmail' ); $creatorObject = eZContentObject::fetch( $this->attribute( 'creator_id' ) ); if ( $creatorObject instanceof eZContentObject ) { $author->name = $creatorObject->attribute('name'); } $imageURL = $this->fetchImageURL(); if ( $imageURL !== false ) { $image = $feed->add( 'image' ); // Required for RSS1 $image->about = $imageURL; $image->url = $imageURL; $image->title = $this->attribute( 'title' ); $image->link = $baseItemURL; } $cond = array( 'rssexport_id' => $this->ID, 'status' => $this->Status ); $rssSources = eZRSSExportItem::fetchFilteredList( $cond ); $nodeArray = eZRSSExportItem::fetchNodeList( $rssSources, $this->getObjectListFilter() ); if ( is_array( $nodeArray ) && count( $nodeArray ) ) { $attributeMappings = eZRSSExportItem::getAttributeMappings( $rssSources ); foreach ( $nodeArray as $node ) { if ( $node->attribute('is_hidden') && !eZContentObjectTreeNode::showInvisibleNodes() ) { // if the node is hidden skip past it and don't add it to the RSS export continue; } $object = $node->attribute( 'object' ); $dataMap = $object->dataMap(); if ( $useURLAlias === true ) { $nodeURL = $this->urlEncodePath( $baseItemURL . $node->urlAlias() ); } else { $nodeURL = $baseItemURL . 'content/view/full/' . $node->attribute( 'node_id' ); } // keep track if there's any match $doesMatch = false; // start mapping the class attribute to the respective RSS field foreach ( $attributeMappings as $attributeMapping ) { // search for correct mapping by path if ( $attributeMapping[0]->attribute( 'class_id' ) == $object->attribute( 'contentclass_id' ) and in_array( $attributeMapping[0]->attribute( 'source_node_id' ), $node->attribute( 'path_array' ) ) ) { // found it $doesMatch = true; // now fetch the attributes $title = $dataMap[$attributeMapping[0]->attribute( 'title' )]; // description is optional $descAttributeIdentifier = $attributeMapping[0]->attribute( 'description' ); $description = $descAttributeIdentifier ? $dataMap[$descAttributeIdentifier] : false; // category is optional $catAttributeIdentifier = $attributeMapping[0]->attribute( 'category' ); $category = $catAttributeIdentifier ? $dataMap[$catAttributeIdentifier] : false; // enclosure is optional $enclosureAttributeIdentifier = $attributeMapping[0]->attribute( 'enclosure' ); $enclosure = $enclosureAttributeIdentifier ? $dataMap[$enclosureAttributeIdentifier] : false; break; } } if( !$doesMatch ) { // no match eZDebug::writeError( 'Cannot find matching RSS attributes for datamap on node: ' . $node->attribute( 'node_id' ), __METHOD__ ); return null; } // title RSS element with respective class attribute content $titleContent = $title->attribute( 'content' ); if ( $titleContent instanceof eZXMLText ) { $outputHandler = $titleContent->attribute( 'output' ); $itemTitleText = $outputHandler->attribute( 'output_text' ); } else { $itemTitleText = $titleContent; } $item = $feed->add( 'item' ); $item->title = $itemTitleText; $link = $item->add( 'link' ); $link->href = $nodeURL; switch ( $type ) { case 'rss2': $item->id = $object->attribute( 'remote_id' ); $item->id->isPermaLink = false; break; default: $item->id = $nodeURL; } $itemCreatorObject = $node->attribute('creator'); if ( $itemCreatorObject instanceof eZContentObject ) { $author = $item->add( 'author' ); $author->name = $itemCreatorObject->attribute('name'); $author->email = $config->variable( 'MailSettings', 'AdminEmail' ); } // description RSS element with respective class attribute content if ( $description ) { $descContent = $description->attribute( 'content' ); if ( $descContent instanceof eZXMLText ) { $outputHandler = $descContent->attribute( 'output' ); $itemDescriptionText = str_replace( ' ', '&nbsp;', $outputHandler->attribute( 'output_text' ) ); } else if ( $descContent instanceof eZImageAliasHandler ) { $itemImage = $descContent->hasAttribute( 'rssitem' ) ? $descContent->attribute( 'rssitem' ) : $descContent->attribute( 'rss' ); $origImage = $descContent->attribute( 'original' ); eZURI::transformURI( $itemImage['full_path'], true, 'full' ); eZURI::transformURI( $origImage['full_path'], true, 'full' ); $itemDescriptionText = '<a href="' . htmlspecialchars( $origImage['full_path'] ) . '"><img alt="' . htmlspecialchars( $descContent->attribute( 'alternative_text' ) ) . '" src="' . htmlspecialchars( $itemImage['full_path'] ) . '" width="' . $itemImage['width'] . '" height="' . $itemImage['height'] . '" /></a>'; } else { $itemDescriptionText = $descContent; } $item->description = $itemDescriptionText; } // category RSS element with respective class attribute content if ( $category ) { $categoryContent = $category->attribute( 'content' ); if ( $categoryContent instanceof eZXMLText ) { $outputHandler = $categoryContent->attribute( 'output' ); $itemCategoryText = $outputHandler->attribute( 'output_text' ); } elseif ( $categoryContent instanceof eZKeyword ) { $itemCategoryText = $categoryContent->keywordString(); } else { $itemCategoryText = $categoryContent; } if ( $itemCategoryText ) { $cat = $item->add( 'category' ); $cat->term = $itemCategoryText; } } // enclosure RSS element with respective class attribute content if ( $enclosure ) { $encItemURL = false; $enclosureContent = $enclosure->attribute( 'content' ); if ( $enclosureContent instanceof eZMedia ) { $enc = $item->add( 'enclosure' ); $enc->length = $enclosureContent->attribute('filesize'); $enc->type = $enclosureContent->attribute('mime_type'); $encItemURL = 'content/download/' . $enclosure->attribute('contentobject_id') . '/' . $enclosureContent->attribute( 'contentobject_attribute_id' ) . '/' . urlencode( $enclosureContent->attribute( 'original_filename' ) ); eZURI::transformURI( $encItemURL, false, 'full' ); } else if ( $enclosureContent instanceof eZBinaryFile ) { $enc = $item->add( 'enclosure' ); $enc->length = $enclosureContent->attribute('filesize'); $enc->type = $enclosureContent->attribute('mime_type'); $encItemURL = 'content/download/' . $enclosure->attribute('contentobject_id') . '/' . $enclosureContent->attribute( 'contentobject_attribute_id' ) . '/version/' . $enclosureContent->attribute( 'version' ) . '/file/' . urlencode( $enclosureContent->attribute( 'original_filename' ) ); eZURI::transformURI( $encItemURL, false, 'full' ); } else if ( $enclosureContent instanceof eZImageAliasHandler ) { $enc = $item->add( 'enclosure' ); $origImage = $enclosureContent->attribute( 'original' ); $enc->length = $origImage['filesize']; $enc->type = $origImage['mime_type']; $encItemURL = $origImage['full_path']; eZURI::transformURI( $encItemURL, true, 'full' ); } if ( $encItemURL ) { $enc->url = $encItemURL; } } $item->published = $object->attribute( 'published' ); $item->updated = $object->attribute( 'published' ); } } return $feed->generate( $type ); }
/** * Returns if the property $name is set. * * @param string $name The property name * @return bool * @ignore */ public function __isset($name) { switch ($name) { case 'author': case 'category': case 'cloud': case 'contributor': case 'copyright': case 'description': case 'docs': case 'generator': case 'icon': case 'id': case 'image': case 'item': case 'language': case 'link': case 'published': case 'rating': case 'skipDays': case 'skipHours': case 'textInput': case 'title': case 'ttl': case 'updated': case 'webMaster': return isset($this->elements[$name]); default: $supportedModules = ezcFeed::getSupportedModules(); if (isset($supportedModules[$name])) { return $this->hasModule($name); } } return false; }
/** * Fetches the supported prefixes and namespaces from the XML document $xml. * * @param DOMDocument $xml The XML document object to parse * @return array(string=>string) * @ignore */ protected function fetchUsedPrefixes(DOMDocument $xml) { $usedPrefixes = array(); $xp = new DOMXpath($xml); $set = $xp->query('./namespace::*', $xml->documentElement); $usedNamespaces = array(); foreach ($set as $node) { foreach (ezcFeed::getSupportedModules() as $moduleName => $moduleClass) { $moduleNamespace = call_user_func(array($moduleClass, 'getNamespace')); // compare the namespace URIs from the XML source with the supported ones if ($moduleNamespace === $node->nodeValue) { // the nodeName looks like: xmlns:some_module list($xmlns, $prefix) = explode(':', $node->nodeName); // use the prefix from the XML source as a key in the array $usedPrefixes // eg. array( 'some_prefix' => 'DublinCore' ); // then, when calling later parseModules(), if encountering an element // like <some_prefix:creator>, it is checked if 'DublinCore' is supported $usedPrefixes[$prefix] = $moduleName; } } } return $usedPrefixes; }
/** * Test for issue #15625: RSS 0.90 feeds are parsed as RSS 1.0 feeds * It tests if when parsing an RSS 0.90 feed the parser throws an ezcFeedParseErrorException */ public function testParseRss090() { try { $xml = <<<EOT <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://channel.netscape.com/rdf/simple/0.9/"> <channel> <title>Mozilla Dot Org</title> <link>http://www.mozilla.org</link> <description>the Mozilla Organization web site</description> </channel> <image> <title>Mozilla</title> <url>http://www.mozilla.org/images/moz.gif</url> <link>http://www.mozilla.org</link> </image> <item> <title>New Status Updates</title> <link>http://www.mozilla.org/status/</link> </item> </rdf:RDF> EOT; $feed = ezcFeed::parseContent($xml); $this->fail("Expected exception was not thrown."); } catch (ezcFeedParseErrorException $e) { } }
/** * Test for issue #13963: ezcFeedEnclosureElement obsolete? */ public function testAssignEnclosure() { $feed = new ezcFeed('rss2'); $feed->title = 'Feed title'; $feed->description = 'Feed description'; $link = $feed->add('link'); $link->href = 'http://example.com/'; $item = $feed->add('item'); $item->title = 'Item title'; $item->description = 'Item description'; $link = $item->add('link'); $link->href = 'http://example.com/item/'; // assign the enclosure directly. Before the fix it would fail with error // as it tried to assign the property 'link' instead of 'url' $item->enclosure = 'http://example.com/enclosure.mp3'; $xml = $feed->generate('rss2'); // assert that the enclosure element is inside the generated XML feed $this->assertEquals(true, strpos($xml, '<enclosure url="http://example.com/enclosure.mp3"/>') !== false); }
/** * Fetches the supported prefixes and namespaces from the XML document $xml. * * @param DOMDocument $xml The XML document object to parse * @return array(string=>string) * @ignore */ protected function fetchUsedPrefixes(DOMDocument $xml) { $usedPrefixes = array(); $xp = new DOMXpath($xml); $set = $xp->query('./namespace::*', $xml->documentElement); $usedNamespaces = array(); foreach ($set as $node) { foreach (ezcFeed::getSupportedModules() as $moduleName => $moduleClass) { $moduleNamespace = call_user_func(array($moduleClass, 'getNamespace')); // compare the namespace URIs from the XML source with the supported ones if ($moduleNamespace === $node->nodeValue) { // the nodeName looks like: xmlns:some_module list($xmlns, $prefix) = explode(':', $node->nodeName); // use the prefix from the XML source as a key in the array $usedPrefixes // eg. array( 'some_prefix' => 'DublinCore' ); // then, when calling later parseModules(), if encountering an element // like <some_prefix:creator>, it is checked if 'DublinCore' is supported $usedPrefixes[$prefix] = $moduleName; } } // If the feed contains the ATOM namespace (xmlns:atom="http://www.w3.org/2005/Atom") // and the feed itself is not of type ATOM, then add the 'atom' prefix (or any alias) // to the $usedPrefixes array which is returned by the function if (ezcFeedAtom::NAMESPACE_URI === $node->nodeValue && $xml->documentElement->tagName !== 'feed') { // the nodeName looks like: xmlns:some_module list($xmlns, $prefix) = explode(':', $node->nodeName); $usedPrefixes[$prefix] = 'Atom'; } } return $usedPrefixes; }
<?php require 'ezc-setup.php'; try { $feed = ezcFeed::parse('http://components.ez.no/rss/rss2.xml'); } catch (Exception $e) { $feed = ezcFeed::parse(dirname(__FILE__) . '/rss2.xml'); } echo "<b>{$feed->title}</b><br/><br/>\n"; foreach ($feed->item as $item) { echo "<a href='{$item->link}'>{$item->title}</a><br/>"; echo $item->Content->encoded, "<br/>"; }
protected function createFeed($type, $data) { $feed = new ezcFeed($type); $supportedModules = ezcFeed::getSupportedModules(); if (is_array($data)) { foreach ($data as $property => $value) { if (is_array($value)) { foreach ($value as $val) { if (isset($supportedModules[$property])) { $element = $feed->addModule($property); } else { $element = $feed->add($property); } if (is_array($val)) { foreach ($val as $subKey => $subValue) { if ($subKey === '#') { $element->set($subValue); } else { if ($subKey === 'MULTI') { $values = array(); foreach ($subValue as $multi) { foreach ($multi as $subSubKey => $subSubValue) { if (isset($supportedModules[$subSubKey])) { $subElement = $element->addModule($subSubKey); } else { if ($property === 'skipDays') { $values[] = $subSubValue; $element->days = $values; } else { if ($property === 'skipHours') { $values[] = $subSubValue; $element->hours = $values; } else { $subElement = $element->add($subSubKey); } } } if ($property !== 'skipDays' && $property !== 'skipHours') { $subElement->set($subSubValue); } } } } else { if (is_array($subValue)) { if (count($subValue) === 0 || !isset($subValue[0])) { if (isset($supportedModules[$subKey])) { $subElement = $element->addModule($subKey); } else { $subElement = $element->add($subKey); } } foreach ($subValue as $subSubKey => $subSubValue) { if ($subSubKey === '#') { $subElement->set($subSubValue); } else { if (is_array($subSubValue)) { if (isset($supportedModules[$subKey])) { $subElement = $element->addModule($subKey); } else { $subElement = $element->add($subKey); } foreach ($subSubValue as $subSubSubKey => $subSubSubValue) { if ($subSubSubKey === '#') { $subElement->set($subSubSubValue); } else { if (is_array($subSubSubValue)) { foreach ($subSubSubValue as $subSubSubSubKey => $subSubSubSubValue) { $subSubElement = $subElement->add($subSubSubKey); foreach ($subSubSubSubValue as $subSubSubSubSubKey => $subSubSubSubSubValue) { if ($subSubSubSubSubKey === '#') { $subSubElement->set($subSubSubSubSubValue); } else { $subSubElement->{$subSubSubSubSubKey} = $subSubSubSubSubValue; } } } } else { $subElement->{$subSubSubKey} = $subSubSubValue; } } } } else { $subElement->{$subSubKey} = $subSubValue; } } } } else { $element->{$subKey} = $subValue; } } } } } else { $element->set($val); } } } else { $feed->{$property} = $value; } } } return $feed; }
/** * Uses the array $data to create a feed of type $feedType ('rss1', 'rss2' or * 'atom') and returns it as a string. * * The format of the $data array is: * <code> * array( 'title' => 'Feed title', * 'link' => 'Feed link', * 'published' => 'Feed published date', * 'authorName' => 'Feed author name', * 'authorEmail' => 'Feed author email', * 'description' => 'Feed description', * 'items' => array( * 0 => array( 'title' => 'Item 0 title', * 'link' => 'Item 0 link', * 'published' => 'Item 0 published date', * 'authorName' => 'Item 0 author name', * 'authorEmail' => 'Item 0 author email', * 'description' => 'Item 0 description', * ), * 1 => array( 'title' => 'Item 1 title', * 'link' => 'Item 1 link', * 'published' => 'Item 1 published date', * 'authorName' => 'Item 1 author name', * 'authorEmail' => 'Item 1 author email', * 'description' => 'Item 1 description', * ), * ) * ); * </code> * * @param string $feedType The type of the feed to create ('rss1', 'rss2' or 'atom') * @param array(mixed) $data Data for the elements of the feed * @return string */ function createFeed($feedType, $data) { $feed = new ezcFeed(); $feed->title = $data['title']; $feed->description = $data['description']; $feed->id = $data['link']; $link = $feed->add('link'); $link->href = $data['link']; $feed->updated = time(); $feed->published = $data['published']; $author = $feed->add('author'); $author->name = $data['authorName']; $author->email = $data['authorEmail']; foreach ($data['item'] as $dataItem) { $item = $feed->add('item'); $item->title = $dataItem['title']; $item->description = $dataItem['description']; $item->id = $dataItem['link']; $item->id->isPermaLink = true; // RSS2 only $link = $item->add('link'); $link->href = $dataItem['link']; $link->rel = 'alternate'; $item->updated = time(); $item->published = $dataItem['published']; $author = $item->add('author'); $author->name = $dataItem['authorName']; $author->email = $dataItem['authorEmail']; } return $feed->generate($feedType); }
/** * Returns if the property $name is set. * * @param string $name The property name * @return bool * @ignore */ public function __isset($name) { switch ($name) { case 'author': case 'category': case 'comments': case 'content': case 'contributor': case 'copyright': case 'description': case 'enclosure': case 'id': case 'link': case 'published': case 'title': case 'updated': case 'source': case 'language': return isset($this->properties[$name]); default: $supportedModules = ezcFeed::getSupportedModules(); if (isset($supportedModules[$name])) { return isset($this->modules[$name]); } } }
<?php date_default_timezone_set('UTC'); require '/home/derick/dev/zetacomponents/trunk/Base/src/ezc_bootstrap.php'; /* Find files */ $d = glob("news/*txt"); sort($d); $d = array_reverse($d); $latest = preg_replace('@^news/(.*).txt$@', '\\1', $d[0]); $feed = new ezcFeed(); $feed->title = 'Xdebug.org announcements'; $feed->description = 'This is a feed showing the latest announcements from xdebug.org.'; $feed->published = new DateTime("{$latest} 09:00"); $author = $feed->add('author'); $author->name = 'Derick Rethans'; $author->email = '*****@*****.**'; $link = $feed->add('link'); $link->href = 'http://xdebug.org'; foreach ($d as $item) { $date = preg_replace('@^news/(.*).txt$@', '\\1', $item); $file = file($item); $title = array_shift($file); $item = $feed->add('item'); $item->title = trim($title); $item->description = join('', $file); $item->published = new DateTime("{$date} 09:00"); } $xml = $feed->generate('rss2'); header('Content-Type: ' . $feed->getContentType() . '; charset=utf-8'); echo $xml;
/** * Executes the PHP function for the operator cleanup and modifies $operatorValue. * * @param eZTemplate $tpl * @param string $operatorName * @param array $operatorParameters * @param string $rootNamespace * @param string $currentNamespace * @param mixed $operatorValue * @param array $namedParameters */ public function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { switch ($operatorName) { case 'feedreader': $source = isset($namedParameters['source']) ? $namedParameters['source'] : ''; $limit = isset($namedParameters['limit']) ? $namedParameters['limit'] : 0; $offset = isset($namedParameters['offset']) ? $namedParameters['offset'] : 0; $res = array(); $sourceXML = eZHTTPTool::getDataByURL($namedParameters['source']); try { $feed = ezcFeed::parseContent($sourceXML); } catch (Exception $e) { $res['error'] = $e->getMessage(); $operatorValue = $res; return; } $res['title'] = isset($feed->title) ? $feed->title->__toString() : null; $res['links'] = self::buildLinksArray(isset($feed->link) ? $feed->link : array()); $items = isset($feed->item) ? $feed->item : array(); $counter = 0; foreach ($items as $item) { $counter++; if ($counter <= $offset) { continue; } $title = isset($item->title) ? $item->title->__toString() : null; $description = isset($item->description) ? $item->description->__toString() : null; $content = isset($item->content) ? $item->content->__toString() : null; $published = isset($item->published) ? $item->published->date->format('U') : null; $links = self::buildLinksArray(isset($item->link) ? $item->link : array()); $res['items'][] = array('title' => $title, 'links' => $links, 'description' => $description, 'content' => $content, 'published' => $published); if ($counter == $limit + $offset) { break; } } $operatorValue = $res; break; } }
public function testRegisterNewModuleType() { ezcFeed::registerModule('Slash', 'mySlashHandler', 'slash'); $types = ezcFeed::getSupportedModules(); $expected = array('Content' => 'ezcFeedContentModule', 'CreativeCommons' => 'ezcFeedCreativeCommonsModule', 'DublinCore' => 'ezcFeedDublinCoreModule', 'Geo' => 'ezcFeedGeoModule', 'iTunes' => 'ezcFeedITunesModule', 'Slash' => 'mySlashHandler'); $this->assertEquals($expected, $types); $types = ezcFeed::getSupportedModulesPrefixes(); $expected = array('content' => 'Content', 'creativeCommons' => 'CreativeCommons', 'dc' => 'DublinCore', 'geo' => 'Geo', 'itunes' => 'iTunes', 'slash' => 'Slash'); $this->assertEquals($expected, $types); ezcFeed::unregisterModule('Slash'); }
<pre style="font-size: 11px;"> <?php require 'ezc-setup.php'; // setup feed and content module $feed = new ezcFeed(); $feed->title = 'eZ components release feed'; $feed->link = 'http://components.ez.no/'; $feed->description = <<<ENDL This feed shows all the latest components releases. ENDL; $feed->copyright = "eZ systems A.S."; $feed->language = 'en-us'; // load data $stmt = (require 'feed-data.php'); foreach ($stmt as $release) { $item = $feed->add('item'); $item->title = "{$release['package']} {$release['version']}"; $item->link = "http://ez.no/doc/components/view/latest/(file)/changelog_{$release['package']}.html"; $item->description = $release['releasenotes']; $item->published = $release['releasedate']; $item->guid = md5($item->title); } echo htmlspecialchars($feed->generate('rss2'));