public function index() { //$feed = \Feeds::make('http://www.swellinfo.com/rss/surf/long-beach-island-new-jersey.xml'); $feed = \Feeds::make('http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=39.6398N&lon=74.1816W&radius=50'); $items = []; foreach ($feed->get_items() as $id => $item) { $items[$id]['permalink'] = $item->get_permalink(); $items[$id]['title'] = $item->get_title(); $items[$id]['description'] = htmlspecialchars($item->get_description()); $items[$id]['posted'] = $item->get_date('j F Y | g:i a'); } $data = array('title' => $feed->get_title(), 'permalink' => $feed->get_permalink(), 'items' => $items); return $this->response->ok($data); //return \Response::make(); }
<?php /* |-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { $feedA = Feeds::make('http://globalnews.ca/bc/feed', 5); $global = array('title' => $feedA->get_title(), 'permalink' => $feedA->get_permalink(), 'items' => $feedA->get_items(0, 5)); $feedB = Feeds::make('http://business.financialpost.com/feed', 5); $financial = array('title' => $feedB->get_title(), 'permalink' => $feedB->get_permalink(), 'items' => $feedB->get_items(0, 5)); return view('welcome')->withFinancial($financial)->withGlobal($global); }); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route | it contains. The "web" middleware group is defined in your HTTP | kernel and includes session state, CSRF protection, and more. | */ Route::group(['middleware' => 'web'], function () { Route::auth();
| Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { $user = new App\User(); return view('welcome'); }); Route::get('parsefeed/{feed}', ['as' => 'parsefeed', 'uses' => 'Ads@parsefeed']); Route::get('/parsefeed-test', function () { if (Cache::has('myfeed')) { $feed = Cache::get('myfeed'); echo "cached<br>"; } else { $feed = Feeds::make('http://www.kijiji.ca/rss-srp-bikes/kitchener-waterloo/c644l1700212'); Cache::put('myfeed', $feed, 9); echo "NOT cached<br>"; } $data = array('title' => $feed->get_title(), 'permalink' => $feed->get_permalink(), 'items' => $feed->get_items()); $parser = new HtmlDomParser(); foreach ($data['items'] as $item) { $tokens = explode('/', $item->get_link()); $id = end($tokens); if (!App\Ad::find($id)) { $price = ''; $title = $item->get_title(); $description = $item->get_description() . "<br/>=================<br/>"; $link = $item->get_link(); $html = $parser->file_get_html($link); foreach ($html->find('span[itemprop=price]') as $span) {
public function make($url) { return $this->feeds->make($url); }