Example #1
0
 public static function getFeed($feed)
 {
     # Retreve the feed
     $feed_url = $feed->feed_url;
     $content = file_get_contents($feed_url);
     $xml = new \SimpleXmlElement($content);
     #dd($xml);
     foreach ($xml->channel->item as $entry) {
         $article = new \p4\Article();
         $article->feed_id = $feed->id;
         $article->article_guid = hash('sha1', $entry->guid . $entry->title . $entry->pubDate);
         $article->title = $entry->title;
         $article->article_text = $entry->description . strip_tags($entry->children("content", true), '<a><img><p>');
         $article->url = $entry->link;
         $article->publish_date = new \DateTime($entry->pubDate);
         #dd($article);
         if (!\p4\Article::where('article_guid', '=', $article->article_guid)->where('feed_id', '=', $article->feed_id)->exists()) {
             $article->save();
         }
     }
     # Update the Next Update / Last Updated Dates
     $feed->last_updated = date("Y-m-d H:i:s");
     # The period of time between feed retrieval is set in the FEED_UPDATE_INTERVAL environment variable
     $nextUpdate = time() + 60 * env('FEED_UPDATE_INTERVAL', 1440);
     $feed->next_update = date("Y-m-d H:i:s", $nextUpdate);
     $feed->save();
 }
Example #2
0
 public function getRemoveFeed(Request $request, $feed_id)
 {
     $user_id = \Auth::user()->id;
     #Remove this Feed from the User_Feed Table if it exists
     $userFeed = \p4\UserFeed::where('feed_id', '=', $feed_id)->where('user_id', '=', $user_id)->first();
     if ($userFeed) {
         $userFeed->delete();
     }
     # Remove any Articles Marked for Deletion
     $articles = \p4\Article::where('feed_id', $feed_id)->pluck('id');
     $userFeedArticles = \p4\UserArticle::wherein('article_id', $articles)->where('user_id', '=', $user_id);
     if ($userFeedArticles) {
         $userFeedArticles->delete();
     }
     #Remove this Feed from the Feeds table if nobody else is subscribed to it
     if (!\p4\UserFeed::where('feed_id', '=', $feed_id)->exists()) {
         #Remove Articles First
         \p4\Article::where('feed_id', '=', $feed_id)->delete();
         #Now Remove the Feed
         $feed = \p4\Feed::where('id', '=', $feed_id)->first();
         if ($feed) {
             $feed->delete();
         }
     }
     # Update the Session Feeds so the updated list will appear in the left nav
     \p4\User::setSessionFeeds($user_id);
     return \Redirect::to('/Manage');
 }
Example #3
0
 public function getDisplayFeed(Request $request, $FeedID)
 {
     $user_id = \Auth::user()->id;
     # Get any articles which have been marked as read
     $readArticles = \p4\UserArticle::where('user_id', $user_id)->where('marked_as_read', 1)->pluck('article_id');
     $article_count = \p4\Article::where('feed_id', $FeedID)->count();
     # Retrieve articles for this feed and leave out the items which have been marked as read by the user
     $articles = \p4\Article::where('feed_id', $FeedID)->whereNotIn('id', $readArticles)->orderby('publish_date', 'DESC')->paginate(env('PAGE_SIZE', 50));
     $feed_name = \p4\UserFeed::where('feed_id', $FeedID)->where('user_id', $user_id)->first()->feed_name;
     return view('articles', ['title' => "News Stories from " . $feed_name . " (" . $article_count . " articles)", 'articles' => $articles, 'user_id' => $user_id]);
 }
Example #4
0
File: Feed.php Project: ccushing/p4
 public function get_stats()
 {
     #$yesterday = time() - 86400;
     $yesterday = Carbon::now()->subDays(1);
     return \p4\Article::where('feed_id', $this->id)->where('created_at', '>', $yesterday)->count();
 }