/** * Execute the console command. * * @return mixed */ public function handle() { $this->info(''); $this->info('------------------------------------------'); $this->info(''); $feeds = Feeds::all(); foreach ($feeds as $f) { $feed = SimpleFeeds::make($f->url); $count = 0; $story['source'] = $feed->get_title(); $story['source_url'] = $feed->get_permalink(); foreach ($feed->get_items() as $item) { $date = strtotime($item->get_date()); // $dom = new \Htmldom($item->get_permalink()); // echo $response->getBody(); $story['headline'] = $item->get_title(); $story['url'] = $item->get_permalink(); $story['feed_id'] = $f->id; // $story['image'] = (isset($item->get_thumbnail())) ? $item->get_thumbnail() : ''; // $story['excerpt'] = (isset($dom->find($f->excerpt)[0]->find('p')[0])) ? $dom->find($f->excerpt)[0]->find('p')[0]->plaintext : 'empty'; $story['pub_date'] = Carbon::createFromTimeStamp($date)->format('Y-m-d G:i'); if ($item->get_description() && $f->use_description) { $story['excerpt'] = $item->get_description(); $story['approved'] = true; } if (!Stories::where('headline', '=', $story['headline'])->first()) { Stories::create($story); $count++; } } $this->info('Added ' . $count . ' stories from ' . $f->name); } }
public static function index() { $feeds = Feeds::all(); $stories = []; foreach ($feeds as $f) { $feed = SimpleFeeds::make($f->url); $count = 0; $story['source'] = $feed->get_title(); $story['source_url'] = $feed->get_permalink(); foreach ($feed->get_items() as $item) { $date = strtotime($item->get_date()); // $dom = new \Htmldom($item->get_permalink()); // echo $response->getBody(); $story['headline'] = $item->get_title(); $story['url'] = $item->get_permalink(); $story['feed_id'] = $f->id; // $story['image'] = (isset($item->get_thumbnail())) ? $item->get_thumbnail() : ''; // $story['excerpt'] = (isset($dom->find($f->excerpt)[0]->find('p')[0])) ? $dom->find($f->excerpt)[0]->find('p')[0]->plaintext : 'empty'; $story['pub_date'] = Carbon::createFromTimeStamp($date)->format('Y-m-d G:i'); if (!Stories::where('headline', '=', $story['headline'])->first()) { $stories[] = $story; Stories::create($story); $count++; } } } usort($stories, function ($a, $b) { $t1 = strtotime($a['pub_date']); $t2 = strtotime($b['pub_date']); return $t2 - $t1; }); return response()->json($stories); }
public static function approved() { return Stories::where('approved', '=', 1)->limit(15)->orderBy('updated_at', 'desc')->get(); }