protected function _generateModel(array $params) { # Check $Content = $this->getContentObjectFromParams($params); $ContentList = delve($params, 'ContentList', array()); if (empty($ContentList)) { # Prepare $content = delve($params, 'content'); $codes = prepare_csv_array($content); # Prepare Fetch $fetch = array_merge(array('status' => 'published', 'limit' => 20), $params); //$fetch = array_keys_unset($fetch, array('id','class','title','Content')); $fetch = array_keys_keep($fetch, array('featured', 'codes', 'limit', 'recent', 'Parent', 'status')); # Fetch: Parent if (!isset($fetch['Parent'])) { $fetch['Parent'] = $Content; } if (empty($fetch['Parent'])) { unset($fetch['Parent']); // don't fetch with a parent } # Fetch: Codes if (!empty($codes)) { $fetch['codes'] = $codes; } # Execute Fetch $ContentList = Content::fetch($fetch); } # Apply $model = compact('Content', 'ContentList'); $model = array_merge($params, $model); # Return model return $model; }
/** * 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; }