public function testSetsImageDescription() { $writer = new Zend_Feed_Writer_Feed(); $writer->setImage(array('uri' => 'http://www.example.com/logo.gif', 'description' => 'Image description')); $this->assertEquals(array('uri' => 'http://www.example.com/logo.gif', 'description' => 'Image description'), $writer->getImage()); }
public function feedAction() { $data = $this->_request->getParams(); $this->prefix = "Default_"; $config = $this->config; $this->setupCache('default'); //$this->totpl('theInclude','list'); if ($data['lib']) { $feedtype = $data['type']; if (!($out = $this->loadCache('feed_' . $data['lib'] . "_" . $feedtype))) { //we have a lib... now get the content for this lib $type = $this->getContentTypeByLib($data['lib']); //some admins think it is a good thing to add more than one content type for each lib ;S if ($type['title']) { $content = $this->getRecent($type['title'], 10); } else { foreach ($type as $o => $s) { $content[] = $this->getRecent($s['title'], 5); } } //get recent items if (count($content) > 0) { $feed = new Zend_Feed_Writer_Feed(); $feed->setTitle($config->site->frontend_title . " " . $data['lib'] . " feed"); $feed->setLink($this->http_location); $feed->setCopyright($this->t($config->site->feed_copyright)); $feed->setGenerator($config->site->feed_generator); $feed->setFeedLink($this->http_location . "/" . $data['lib'], 'atom'); $feed->setFeedLink($this->http_location . "/" . $data['lib'] . "?type=rss", 'rss'); $feed->addAuthor(array('name' => $config->site->feed_author_name, 'email' => $config->site->feed_author_email, 'uri' => $this->http_location)); $feed->setImage(array('uri' => $config->site->feed_logo_image)); $feed->setDateModified(time()); $feed->addHub('http://pubsubhubbub.appspot.com/'); //now we need to loop foreach ($content as $k => $v) { if ($v['title']) { $entry = $feed->createEntry(); $entry->setTitle($v['title']); $entry->setLink($this->http_location . "/" . $data['lib'] . "/" . $v['slug']); $entry->setDateCreated($v['datestr']); $entry->setDateModified(time()); if ($v['content']) { $entry->setDescription(strip_tags(stripslashes(substr($v['content'], 0, 160)))); } $feed->addEntry($entry); } else { foreach ($v as $r) { $entry = $feed->createEntry(); $entry->setTitle($r['title']); $entry->setLink($this->http_location . "/" . $data['lib'] . "/" . $r['slug']); $entry->setDateCreated($r['datestr']); $entry->setDateModified(time()); if ($r['content']) { $entry->setDescription(strip_tags(stripslashes(substr($r['content'], 0, 160)))); } $feed->addEntry($entry); } } } $out = $feed->export($feedtype); } $this->cacheData($out, 'feed_' . $data['lib'] . "_" . $feedtype); } header("Content-type: text/xml"); echo $out; die; } }
/** * Generate a feed (ATOM 1.0 or RSS 2.0 using Zend_Feed_Writer_Feed * * @param string $section Tiki feature the feed is related to * @param string $uniqueid * @param string $feed_version DEPRECATED * @param array $changes the content that will be used to generate the feed * @param string $itemurl base url for items (e.g. "tiki-view_blog_post.php?postId=%s") * @param string $urlparam * @param string $id name of the id field used to identify each feed item (e.g. "postId") * @param string $title title for the feed * @param string $titleId name of the key in the $changes array with the title of each item * @param string $desc description for the feed * @param string $descId name of the key in the $changes array with the description of each item * @param string $dateId name of the key in the $changes array with the date of each item * @param string $authorId name of the key in the $changes array with the author of each item * @param bool $fromcache if true recover the feed from cache * * @return array the generated feed */ function generate_feed($section, $uniqueid, $feed_version, $changes, $itemurl, $urlparam, $id, $title, $titleId, $desc, $descId, $dateId, $authorId, $fromcache = false) { global $tikilib, $tiki_p_admin, $prefs, $userlib, $prefs, $smarty; // both title and description fields cannot be null if (empty($title) || empty($desc)) { $msg = tra('The fields title and description are mandatory to generate a feed.'); if ($tiki_p_admin) { $msg .= ' ' . tra('To fix this error go to Admin -> Feeds.'); } else { $msg .= ' ' . tra('Please contact the site administrator and ask him to fix this error'); } $smarty->assign('msg', $msg); $smarty->display('error.tpl'); die; } $feed_format = $this->get_current_feed_format(); $feed_format_name = $this->get_current_feed_format_name(); if ($prefs['feed_cache_time'] < 1) { $fromcache = false; } // only get cache data if rss cache is enabled if ($fromcache) { $output = $this->get_from_cache($uniqueid, $feed_format); if ($output['data'] != 'EMPTY') { return $output; } } $urlarray = parse_url($_SERVER["REQUEST_URI"]); $rawPath = str_replace('\\', '/', dirname($urlarray["path"])); $URLPrefix = $tikilib->httpPrefix() . $rawPath; if ($rawPath != "/") { $URLPrefix .= "/"; // Append a slash unless Tiki is in the document root. dirname() removes a slash except in that case. } if (isset($prefs['feed_' . $section . '_index']) && $prefs['feed_' . $section . '_index'] != '') { $feedLink = $prefs['feed_' . $section . '_index']; } else { $feedLink = htmlspecialchars($tikilib->httpPrefix() . $_SERVER["REQUEST_URI"]); } $img = htmlspecialchars($URLPrefix . $prefs['feed_img']); $title = htmlspecialchars($title); $desc = htmlspecialchars($desc); $read = $URLPrefix . $itemurl; $feed = new Zend_Feed_Writer_Feed(); $feed->setTitle($title); $feed->setDescription($desc); if (!empty($prefs['feed_language'])) { $feed->setLanguage($prefs['feed_language']); } $feed->setLink($tikilib->tikiUrl('')); $feed->setFeedLink($feedLink, $feed_format_name); $feed->setDateModified($tikilib->now); if ($feed_format_name == 'atom') { $author = array(); if (!empty($prefs['feed_atom_author_name'])) { $author['name'] = $prefs['feed_atom_author_name']; } if (!empty($prefs['feed_atom_author_email'])) { $author['email'] = $prefs['feed_atom_author_email']; } if (!empty($prefs['feed_atom_author_url'])) { $author['url'] = $prefs['feed_atom_author_url']; } if (!empty($author)) { if (empty($author['name'])) { $msg = tra('If you set feed author email or URL, you must set feed author name.'); $smarty->assign('msg', $msg); $smarty->display('error.tpl'); die; } $feed->addAuthor($author); } } else { $authors = array(); if (!empty($prefs['feed_rss_editor_email'])) { $authors['name'] = $prefs['feed_rss_editor_email']; } if (!empty($prefs['feed_rss_webmaster_email'])) { $authors['name'] = $prefs['feed_rss_webmaster_email']; } if (!empty($authors)) { $feed->addAuthors($authors); } } if (!empty($prefs['feed_img'])) { $image = array(); $image['uri'] = $tikilib->tikiUrl($prefs['feed_img']); $image['title'] = tra('Feed logo'); $image['link'] = $tikilib->tikiUrl(''); $feed->setImage($image); } foreach ($changes["data"] as $data) { $item = $feed->createEntry(); $item->setTitle($data[$titleId]); if (isset($data['sefurl'])) { $item->setLink($URLPrefix . $data['sefurl']); } elseif ($urlparam != '') { // 2 parameters to replace $item->setlink(sprintf($read, urlencode($data["{$id}"]), urlencode($data["{$urlparam}"]))); } else { $item->setLink(sprintf($read, urlencode($data["{$id}"]))); } if (isset($data[$descId]) && $data[$descId] != '') { $item->setDescription($data[$descId]); } $item->setDateCreated($data[$dateId]); $item->setDateModified($data[$dateId]); if ($authorId != '' && $prefs['feed_' . $section . '_showAuthor'] == 'y') { $author = $this->process_item_author($data[$authorId]); $item->addAuthor($author); } $feed->addEntry($item); } $data = $feed->export($feed_format_name); $this->put_to_cache($uniqueid, $feed_format, $data); $output = array(); $output["data"] = $data; $output["content-type"] = 'application/xml'; return $output; }