/** * 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 function delete($feedId) { $feed = Feeds::find($feedId); if ($feed->delete()) { return redirect('/admin'); } }
function getFeeds() { if (Auth::check()) { $mainString = Input::get('mstring'); $subString = Input::get('sstring'); $author = Input::get('author'); //$mainString = Input::get('mstring'); $filename = ""; $ext = ""; if ($subString == null) { $subString = ""; } if ($author == null) { $author = ""; } if ($mainString != null) { if (Input::hasFile('img')) { $imageFile = Input::file('img'); $filename = time() . '.' . $imageFile->getClientOriginalExtension(); $imageFile->move('feedimages', $filename); $ext = $imageFile->getClientOriginalExtension(); } else { } $feedModel = new Feeds(); $feedModel->mainstring = $mainString; $feedModel->substring = $subString; $feedModel->author = $author; $feedModel->image = $filename; $feedModel->imagepath = 'feedimages'; $feedModel->ext = $ext; $feedModel->save(); } return view('admin.Feeds'); } else { return redirect('login'); } }