コード例 #1
0
ファイル: FeedTest.php プロジェクト: jsnshrmn/Suma
 public function testAddsManyCategories()
 {
     $writer = new Zend_Feed_Writer_Feed();
     $writer->addCategories(array(array('term' => 'cat_dog'), array('term' => 'cat_mouse')));
     $this->assertEquals(array(array('term' => 'cat_dog'), array('term' => 'cat_mouse')), $writer->getCategories());
 }
コード例 #2
0
ファイル: FeedController.php プロジェクト: balupton/balcms
 /**
  * Generate our Feed
  */
 protected function getFeed($type = null)
 {
     # Prepare
     $App = $this->getHelper('App');
     $Identity = $App->getUser();
     # --------------------------
     # Fetch Content
     # Search
     $search = $App->fetchSearch();
     $searchQuery = delve($search, 'query');
     # Prepare Criteria
     $criteria = array('recent' => true, 'fetch' => 'list', 'status' => 'published', 'Identity' => $Identity, 'hydrationMode' => Doctrine::HYDRATE_ARRAY);
     # Criteria: SearchQuery
     if ($searchQuery) {
         $criteria['search'] = $searchQuery;
     }
     # Fetch
     $Contents = $App->fetchRecords('Content', $criteria);
     # --------------------------
     # Generate Feed
     # Pepare Feed
     $feed = array('title' => $App->getConfig('site.title'), 'link' => $App->getBaseUrl(true), 'author' => $App->getConfig('site.author'), 'dateModified' => empty($Content[0]) ? time() : strtotime($Content->updated_at), 'description' => $App->getConfig('site.description', 'News Feed for ' . $App->getConfig('site.title')), 'categories' => prepare_csv_array($App->getConfig('site.keywords')));
     # Create Feed
     $Feed = new Zend_Feed_Writer_Feed();
     $Feed->setTitle($feed['title']);
     $Feed->setLink($feed['link']);
     $Feed->setDateModified($feed['dateModified']);
     $Feed->setDescription($feed['description']);
     $Feed->addAuthor($feed['author']['title'], $feed['author']['email'], $feed['author']['url']);
     $Feed->addHub('http://pubsubhubbub.appspot.com/');
     # Apply Categories
     $categories = array();
     foreach ($feed['categories'] as $tag) {
         $categories[] = array('term' => str_replace(' ', '-', $tag), 'label' => $tag);
     }
     $Feed->addCategories($categories);
     # Content Map
     $contentMap = array('title' => 'title', 'url' => 'link', 'updated_at' => 'dateModified', 'created_at' => 'dateCreated', 'description_rendered' => 'description', 'content_rendered' => 'content');
     # Apply Content
     foreach ($Contents as $Content) {
         # Create Entry
         $Entry = $Feed->createEntry();
         # Prepare Content
         $Content['url'] = $App->getUrl()->content($Content)->full()->toString();
         $Content['updated_at'] = strtotime($Content['updated_at']);
         $Content['created_at'] = strtotime($Content['created_at']);
         # Apply Content
         foreach ($contentMap as $from => $to) {
             $method = 'set' . ucfirst($to);
             $value = delve($Content, $from);
             $Entry->{$method}($value);
         }
         # Apply Author
         if (empty($Content['Author']['website'])) {
             $Content['Author']['website'] = $App->getUrl()->user($Content['Author'])->full()->toString();
         }
         $Entry->addAuthor($Content['Author']['displayname'], $Content['Author']['email'], $Content['Author']['website']);
         # Apply Categories
         $categories = array();
         foreach ($Content['ContentTags'] as $Tag) {
             $categories[] = array('term' => str_replace(' ', '-', $Tag['name']), 'label' => $Tag['name']);
         }
         $Entry->addCategories($categories);
         # Add Entry
         $Feed->addEntry($Entry);
     }
     # --------------------------
     # Done
     # Return Feed
     return $Feed;
 }