예제 #1
0
 /**
  * Default component view
  *
  * @return  void
  */
 public function displayTask()
 {
     $authlevel = \JAccess::getAuthorisedViewLevels(User::get('id'));
     $access_level = 3;
     //author_level
     if (in_array($access_level, $authlevel) && User::get('id')) {
         $model = new Models\Feeds();
         $this->view->feeds = $model->loadAll();
         $this->view->title = Lang::txt('COM_FEEDAGGREGATOR');
         $this->view->display();
     } else {
         if (User::get('id')) {
             App::redirect(Route::url('index.php?option=com_feedaggregator'), Lang::txt('COM_FEEDAGGREGATOR_NOT_AUTH'), 'warning');
         } else {
             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');
             }
         }
     }
 }
예제 #2
0
 /**
  * Saves posts from enabled Source Feeds
  *
  * @return  void
  */
 public function RetrieveNewPostsTask()
 {
     $model = new Models\Feeds();
     $feeds = $model->loadAll();
     $model = new Models\Posts();
     $savedURLS = $model->loadURLs();
     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 Models\Posts();
                             //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', strtotime($item->published));
                             } else {
                                 $post->set('created', strtotime($item->updated));
                             }
                             $post->set('description', (string) html_entity_decode(strip_tags($item->content, '<img>')));
                             $post->store();
                             //save the post
                         }
                         // end check for prior existance
                     } else {
                         if ($feedType == 'RSS') {
                             if (in_array($item->link, $savedURLS) == FALSE) {
                                 $post = new Models\Posts();
                                 //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', strtotime($item->pubDate));
                                 $post->set('description', (string) html_entity_decode(strip_tags($item->description, '<img>')));
                                 $post->set('url', (string) $item->link);
                                 $post->store();
                                 //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'));
 }