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); }
/** * 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 function getStory($storyId) { $story = Stories::find($storyId); $excerptExtract = $story->feed->excerpt; $dom = new \Htmldom(htmlspecialchars_decode(urldecode($story->url))); $body = $dom->find($excerptExtract, 0); return response()->json(array('body' => $body->innertext)); }
public function index() { $data['stories'] = Stories::approved(); return view('site.homepage', $data); }
public function index() { $data['categories'] = FeedCategory::all(); $data['stories'] = Stories::unapproved(); return view('admin.dashboard', $data); }
public static function approved() { return Stories::where('approved', '=', 1)->limit(15)->orderBy('updated_at', 'desc')->get(); }