/** * Default component view * * @return void */ public function displayTask() { if (User::isGuest()) { $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option . '&task=' . $this->_task), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('COM_FEEDAGGREGATOR_LOGIN_NOTICE'), 'warning'); } $authlevel = User::getAuthorisedViewLevels(); $access_level = 3; //author_level if (!in_array($access_level, $authlevel)) { App::redirect(Route::url('index.php?option=com_feedaggregator'), Lang::txt('COM_FEEDAGGREGATOR_NOT_AUTH'), 'warning'); } $feeds = Feed::all()->rows(); $this->view->set('title', Lang::txt('COM_FEEDAGGREGATOR'))->set('feeds', $feeds)->display(); }
/** * Saves posts from enabled Source Feeds * * @return void */ public function RetrieveNewPostsTask() { $feeds = Feed::all()->rows(); $savedURLS = array(); $urls = Post::all()->select('url')->rows(); foreach ($urls as $url) { $savedURLS[] = $url->url; } foreach ($feeds as $feed) { if ($feed->enabled == 1 && filter_var($feed->url, FILTER_VALIDATE_URL) == TRUE) { try { $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $feed->url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); if (!$data) { $this->setError(Lang::txt('COM_FEEDAGGREGATOR_ERROR_READING_FEED', $feed->url)); continue; } $page = simplexml_load_string(utf8_encode($data)); if (isset($page->entry) == TRUE) { $items = $page->entry; $feedType = 'ATOM'; } else { $items = $page->channel->item; //gets the items of the channel $feedType = 'RSS'; } foreach ($items as $item) { if ($feedType == 'ATOM') { // get the href attribute of the orignal content link foreach ($item->link->attributes() as $link) { $link = $link; } if (in_array($link, $savedURLS) == FALSE) { $post = new Post(); //create post object $post->set('title', html_entity_decode(strip_tags($item->title))); $post->set('feed_id', (int) $feed->id); $post->set('status', 0); //force new status //ATOM original content link $post->set('url', (string) $link); if (isset($item->published) == TRUE) { $post->set('created', Date::of($item->published)->toSql()); } else { $post->set('created', Date::of($item->updated)->toSql()); } $post->set('description', (string) html_entity_decode(strip_tags($item->content, '<img>'))); $post->save(); //save the post } // end check for prior existance } else { if ($feedType == 'RSS') { if (in_array($item->link, $savedURLS) == FALSE) { $post = new Post(); //create post object $post->set('title', (string) html_entity_decode(strip_tags($item->title))); $post->set('feed_id', (int) $feed->id); $post->set('status', 0); //force new status $post->set('created', Date::of($item->pubDate)->toSql()); $post->set('description', (string) html_entity_decode(strip_tags($item->description, '<img>'))); $post->set('url', (string) $item->link); $post->save(); //save the post } } } } //end foreach } catch (Exception $e) { $this->setError(Lang::txt('COM_FEEDAGGREGATOR_ERROR_READING_FEED', $feed->url)); continue; } } //end if } if ($this->getError()) { Notify::warning(implode('<br />', $this->getErrors()), $this->_option); } // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=posts&filterby=all', false), Lang::txt('COM_FEEDAGGREGATOR_GOT_NEW_POSTS')); }