where('country', '=', COUNTRY_INT) ->where(function($query) { $query->where('status', '=', ''); $query->or_where('status', '=', 'active'); }) ->order_by('updated_at', 'desc') ->take(5) ->get(); $review = Review::where('reviews.status', '=', 'approved') ->join('takeaways', 'reviews.takeaway_id', '=', 'takeaways.id') // ->where(CONTENT_TYPE, '=', 1) ->where('country', '=', COUNTRY_INT) ->order_by('reviews.created_at', 'desc') ->first(); $view = View::make(ENV_VIEW_DIR.'.home')->with(array( 'latest' => $latest, 'review' => $review, 'review_takeaway' => $review ? Takeaway::find($review->takeaway_id) : null )); Turbo::save_cache('home', $view); return $view; } public function action_search() { // First, have we redirected here from a google query? if (Input::get('q')) { return View::make(ENV_VIEW_DIR.'.google_results')->with(array( 'search_string' => Input::get('q') )); } $string = Input::get('search'); if (!$string) return Redirect::to('/'); // For mobile, make a list of results $return = array(); // Break the string into words and normalize them $tmp_parts = explode(' ', $string); $parts = array(); foreach ($tmp_parts as $tp) { $str = preg_replace('/[^a-zA-Z]/', '', $tp); if (strlen($str) < 4) continue; $str = strtolower($str); $parts[] = $str; } // Find any matching towns $towns = array(); $town_ids = array(); foreach ($parts as $part) { $tmp_towns = Town::where('urlname', 'LIKE', '%'.$part.'%') ->where(CONTENT_TYPE.'_count', '>', 0) ->get(); foreach ($tmp_towns as $twn) { $towns[] = $twn; $town_ids[] = $twn->id; } } // Remove any matched towns from the parts we'll search for takeaways foreach ($towns as $twn) { if (($key = array_search(strtolower($twn->name), $parts)) !== false) { unset($parts[$key]); } } // Find any matching categories $categories = array(); foreach ($parts as $part) { $tmp_cats = Category::where('urlname', 'LIKE', '%'.$part.'%')->get(); foreach ($tmp_cats as $cat) { if (!in_array($cat, $categories)) $categories[] = $cat; } } // Start with no takeaways $takeaways = array(); if (count($towns)) { // Find a redirect if (count($towns) == 1 && count($categories) == 1) { // Matched a single town, one or more cats, just go with the first return Redirect::to( $categories[0]->url($towns[0]) ); } // Try to find an exact takeaway match in one of the towns $tmp_takes = Takeaway::select('takeaways.*') ->where(function($query) use($parts) { foreach ($parts as $part) { $query->where('search', 'LIKE', '%'.$part.'%'); } }) ->join('takeaway_town', 'takeaway_town.takeaway_id', '=', 'takeaways.id') ->where_in('takeaway_town.town_id', $town_ids) ->where('takeaways.'.CONTENT_TYPE, '=', 1) ->where('country', '=', COUNTRY_INT) ->where(function($query) { $query->where('status', '=', ''); $query->or_where('status', '=', 'active'); $query->or_where('status', '=', 'menu'); }) ->get(); if (count($tmp_takes) == 1) { return Redirect::to( $tmp_takes[0]->url ); } // Try and find a matching related takeaway foreach ($parts as $part) { $tmp_takes = Takeaway::select('takeaways.*') ->where('urlname', 'LIKE', '%'.$part.'%') ->join('takeaway_town', 'takeaway_town.takeaway_id', '=', 'takeaways.id') ->where_in('takeaway_town.town_id', $town_ids) ->where('takeaways.'.CONTENT_TYPE, '=', 1) ->where('country', '=', COUNTRY_INT) ->where(function($query) { $query->where('status', '=', ''); $query->or_where('status', '=', 'active'); $query->or_where('status', '=', 'menu'); }) ->get(); foreach ($tmp_takes as $take) { if (!in_array($take, $takeaways)) { $takeaways[] = $take; if (ENVIRONMENT == 'mobile') $return[] = $take; } } } // Should we look for an exact name match on multiple results? if (count($takeaways) > 1) { $string = strtolower($string); foreach ($takeaways as $take) { $match = str_replace(strtolower($take->name), '', $string); if (strpos($string, strtolower($take->name)) !== false ) { return Redirect::to( $take->get_url()); } } } } // Did we find any takeaways? if (count($takeaways) == 1) { // Redirect to this takeaway return Redirect::to( $takeaways[0]->get_url() ); } else if (count($takeaways) == 0 && count($towns) == 1) { // Matched one town? Send them there return Redirect::to( $towns[0]->url() ); } else if (count($takeaways)) { // More than one possible takeaway? return View::make(ENV_VIEW_DIR.'.search_results')->with(array( 'town' => $towns[0], 'categories' => $categories, 'takeaways' => $takeaways, 'search_string' => $string )); } else if (count($towns)) { // Matched more than one town, give the use the options return View::make(ENV_VIEW_DIR.'.search_results')->with(array( 'towns' => $towns, 'categories' => $categories, 'search_string' => $string )); } // Matched nothing?! Show google results $params = array( 'cx' => 'partner-pub-1155136436784288:4749669681', 'cof' => 'FORID:10', 'ie' => 'UTF-8', 'q' => $string, 'sa' => 'Search', 'siteurl' => url('browse/search'), // 'ref' => 'restaurant-locator.dev%2F&ss=284j21138j6' ); return Redirect::to( 'browse/search/?'.http_build_query($params) ); } public function action_near_me( $lat = false, $lng = false, $old_take_id = false ) { if ($lat !== false && $lng !== false) { $takeaways = Takeaway::nearby($lat, $lng); $view = View::make(ENV_VIEW_DIR.'.list_takeaways', array( 'title' => CONTENT_PLURAL.' near me', 'categories' => Takeaway::organise_by_category($takeaways), 'near_me' => true, 'lat' => $lat, 'lng' => $lng )); return $view; } else { if ($cached = Turbo::get_cache('near_me_locate')) return $cached; $view = View::make(ENV_VIEW_DIR.'.near_me_locate', array( 'title' => CONTENT_PLURAL.' near me', 'description' => 'Takeaways Near Me - Find Takeaways in near your current location, or browse by town.' )); Turbo::save_cache('near_me_locate', $view); return $view; } } public function action_town_link() { $ip = Request::ip(); $data = file_get_contents('http://ipinfo.io/'.$ip.'/geo'); $json = json_decode($data); $city = $json->city; $town = Town::where('name', 'LIKE', $city)->first(); if ($town) { $return = $town->to_array(); $return['url'] = $town->url(); return Response::json($return); } else { return Response::make('404', 404); } } public function action_regions( $url = false ) { if (COUNTRY == 'UK') { if ($url) { $url_slug = '-'.$url; $page_title = CONTENT_PLURAL.' in '.ucfirst($url); } else { // Default to england // $url = 'england'; // $url_slug = '-england'; // $page_title = CONTENT_PLURAL.' in England'; return Redirect::to(CONTENT_LINK.'/browse/england', 302); } if ($cached = Turbo::get_cache('regions'.$url_slug)) return $cached; $country_ids = array( 'england' => 1, 'wales' => 2, 'scotland' => 3, 'ireland' => 5 ); $regions = Region::where_country_id($country_ids[$url])->order_by('name', 'asc')->get(); $view = View::make(ENV_VIEW_DIR.'.regions')->with(array( 'regions' => $regions, 'country_name' => $url, 'title' => $page_title )); Turbo::save_cache('regions'.$url_slug, $view); } else if (COUNTRY == 'US') { if ($cached = Turbo::get_cache('states')) return $cached; $view = View::make(ENV_VIEW_DIR.'.states')->with(array( 'states' => State::order_by('name', 'asc')->where('counties', '>', 0)->get() )); Turbo::save_cache('states', $view); } return $view; } public function action_state($urlname) { if ($cached = Turbo::get_cache('states/'.$urlname)) return $cached; $state = State::where_urlname($urlname)->first(); if (!$state) return Event::first('404'); $_counties = $state->counties()->order_by('name', 'asc')->get(); $counties = array(); foreach ($_counties as $county) { $county->towns()->order_by('name', 'asc') // ->where(CONTENT_TYPE.'_count', '>', 0) ->get(); // if (count($county->towns) == 0) continue; $counties[] = $county; } $view = View::make(ENV_VIEW_DIR.'.state')->with(array( 'state' => $state, 'counties' => $counties )); Turbo::save_cache($urlname, $view, 'states'); return $view; } // Just used for mobile public function action_towns() { if ($cached = Turbo::get_cache('towns')) return $cached; $view = View::make(ENV_VIEW_DIR.'.towns'); Turbo::save_cache('towns', $view); return $view; } // Just used for mobile public function action_recents() { return View::make(ENV_VIEW_DIR.'.recents'); } // Just used for mobile public function action_write_review() { return View::make(ENV_VIEW_DIR.'.write_review'); } // Just used for mobile public function action_more_apps() { if (stristr($_SERVER['HTTP_USER_AGENT'],'android')) { return View::make(ENV_VIEW_DIR.'.more_apps_android'); } else { return View::make(ENV_VIEW_DIR.'.more_apps_iphone'); } } // Reroute to the normal town function public function action_state_town($state_urlname, $urlname) { return $this->action_town($urlname, $state_urlname); } public function action_town($urlname, $state_urlname = false) { if ($state_urlname) { // Get by county and town $state = State::where('urlname', '=', $state_urlname)->first(); if (!$state) return Event::first('404'); $town = Town::where('state_id', '=', $state->id) ->where('urlname', '=', $urlname) ->get(); // Notify about duplicate towns if (count($town) > 1) { mail('malcolm@christiesmedia.co.uk', 'DUPLICATE TOWN ERROR', 'There are '.count($town).' called '.$urlname); return Event::first('404'); } if (!$town) return Event::first('404'); $town = $town[0]; } else { // Just get by town $town = Town::where('urlname', '=', $urlname)->first(); if (!$town) return Event::first('404'); $state = false; } if ($cached = Turbo::get_cache($urlname, 'towns')) return $cached; // $the_categories = DB::query('SELECT DISTINCT(categories.id), categories.* FROM categories JOIN category_takeaway ON categories.id = category_takeaway.category_id JOIN takeaway_town ON category_takeaway.takeaway_id = takeaway_town.takeaway_id WHERE takeaway_town.town_id = '.$town->id.' ORDER BY name ASC'); $the_categories = Category::select('categories.*') ->join('category_takeaway', 'categories.id', '=', 'category_takeaway.category_id') ->join('takeaway_town', 'category_takeaway.takeaway_id', '=', 'takeaway_town.takeaway_id') ->where('takeaway_town.town_id', '=', $town->id) ->order_by('name', 'asc') ->group_by('categories.id') ->get(); $categories = array(); // Find any promoted takeaways $promoted = Takeaway::select('takeaways.*') ->join('takeaway_town', 'takeaways.id', '=', 'takeaway_town.takeaway_id') ->where('promoted', '=', 1) ->where('takeaway_town.town_id', '=', $town->id) ->where('takeaways.'.CONTENT_TYPE, '=', 1) // ->where('country', '=', COUNTRY_INT) No need when using town ->group_by('takeaways.id') ->order_by('priority', 'desc') ->order_by('name', 'asc') ->get(); if ($promoted) { $categories[] = array( 'category' => Category::promoted(), 'takeaways' => $promoted ); } foreach ($the_categories as $cat) { $categories[] = array( 'category' => $cat, 'takeaways' => Takeaway::by_town_and_category($town->id, $cat->id) ); } $view = View::make(ENV_VIEW_DIR.'.list_takeaways')->with(array( 'title' => CONTENT_PLURAL." in {$town->name}", 'town' => $town, 'categories' => $categories, 'lat' => $town->lat, 'lng' => $town->lng )); if ($state) $urlname = $state->urlname.'_'.$urlname; Turbo::save_cache($urlname, $view, 'towns'); return $view; } public function action_takeaway($url) { // Get the ID from the URL and the takeaway object $segments = explode('-', $url); $id = end($segments); if ($cached = Turbo::get_cache($id, 'takeaways')) return $cached; $takeaway = Takeaway::find($id); // 404 if it doesnt exist if (!$takeaway) return Event::first('404'); // Check we're on the right site /* No, don't check that, not any more! if ($takeaway->{CONTENT_TYPE} != 1) { if ($takeaway->takeaway == 1) return Redirect::to("http://takeaway-finder.co.uk/takeaway/{$takeaway->urlname}-{$takeaway->id}"); if ($takeaway->restaurant == 1) return Redirect::to("http://restaurant-locator.co.uk/restaurant/{$takeaway->urlname}-{$takeaway->id}"); if ($takeaway->coffee == 1) return Redirect::to("http://coffee-breaks.co.uk/coffee/{$takeaway->urlname}-{$takeaway->id}"); if ($takeaway->takeout == 1) return Redirect::to("http://takeouts-near-me.com/takeout/{$takeaway->urlname}-{$takeaway->id}"); } */ // Check if we're using the new URL including the town if ($url != str_replace('/'.URI::segment(1).'/', '', $takeaway->url)) { return Redirect::to($takeaway->url, 301); } // Include the number formatter include path('app').'libraries/number_formatter.php'; // Include some related stuff $town = $takeaway->Towns()->first(); $county = false; $country = false; if ($town) { $county = $town->county; if ($county) { $country_id = $town->county->country_id; $country_ids = array( 1 => 'england', 2 => 'wales', 3 => 'scotland', 4 => false, 5 => 'ireland' ); $country = array_key_exists($country_id, $country_ids) ? $country_ids[$country_id] : false; } } $town_name = $town ? $town->name : ''; // if (!$town) return Event::first('500'); $categories = $takeaway->categories()->order_by('name', 'asc')->get(); $similar = false; $similar_title = false; $recommended = false; $best_count = 0; if ($town) { foreach ($categories as $cat) { $similar_title = "More ".CONTENT_PLURAL." in {$town->link()} which specialise in ".$cat->link($town).' cuisine.'; $tmp = Takeaway::by_town_and_category($town->id, $cat->id, $id, 50); if (count($tmp) > $best_count) { $similar = $tmp; break; } } if (!$similar) { $similar_title = "More ".CONTENT_PLURAL." in {$town->name}."; $similar = $town->Takeaways() // ->where(CONTENT_TYPE, '=', 1) ->order_by('views', 'desc') ->take(50) ->get(); } // Get recommended takeaways in the town $recommended = $town->Takeaways()->where('promoted', '=', 1)->get(); } // Does this takeaway have a hungry house link? $hungryhouse = false; if ($takeaway->hungryhouse_id) { $hh = Hungryhouse::find($takeaway->hungryhouse_id); if ($hh) $hungryhouse = $hh->{'home page'}; } // Get menu categories, leave the dishes for the view, naughty $menu_categories = $takeaway->MenuCategories()->order_by('id', 'asc')->get(); $page_title = $takeaway->name; if (strlen($page_title) + strlen(' '.$town_name) <= 70) $page_title .= ' '.$town_name; if ((strlen($page_title) + strlen(' menu') <= 70) && $menu_categories) $page_title = $page_title.' menu'; $street_name = preg_replace('/^[\s0-9]+/', '', $takeaway->address1); if (strlen($page_title) + strlen(', '.$street_name) <= 70) $page_title .= ', '.$street_name; // Pass stuff to the view and return it $view = View::make(ENV_VIEW_DIR.'.takeaway')->with(array( 'title' => $page_title, 'description' => $takeaway->safe_description(), 'takeaway' => $takeaway, 'reviews' => $takeaway->published_reviews(), 'phone_numbers' => $takeaway->numbers(), 'urls' => $takeaway->Urls()->where('deleted', '!=', 1)->get(), 'categories' => $categories, 'town' => $town, 'county' => $county, 'country' => $country, 'menu_categories' => $menu_categories, 'similar_title' => $similar_title, 'similar' => $similar, 'recommended' => $recommended, 'hungryhouse' => $hungryhouse, // For mobile 'ajax' => (Request::ajax() || URI::segment(1) == 'm') )); // File::put(path('public')."cache/".CONTENT_TYPE."/takeaways/$id.html", $view); Turbo::save_cache($id, $view, 'takeaways'); $takeaway->cached_at = date('Y-m-d H:i:s'); $takeaway->save(); return $view; } public function action_track_view($id) { DB::query("UPDATE LOW_PRIORITY `takeaways` SET `views` = `views` + 1 WHERE `id` = {$id} LIMIT 1;"); } public function action_url($id) { $url = TakeawayUrl::find($id); if (!$url) return Redirect::to('/'); $url->clicks++; $url->save(); $actual_url = strpos($url->url, 'http') !== 0 ? 'http://'.$url->url : $url->url; return Redirect::to($actual_url); } /* Ajax methods */ public function action_reviews($id) { $takeaway = Takeaway::find($id); // Check that they're not making bad requests if (!$takeaway) return Event::first('404'); return View::make(ENV_VIEW_DIR.'.reviews')->with(array( 'takeaway' => $takeaway, 'reviews' => $takeaway->published_reviews() )); } public function action_rate_takeaway($id, $user_rating) { $takeaway = Takeaway::find($id); // Check that they're not making bad requests if (!$takeaway) return Event::first('404'); if (!is_numeric($user_rating) || $user_rating > 5 || $user_rating < 1) return Response::error('400'); // See if we should be updating an existing rating $rating = Rating::where('takeaway_id', '=', $id)->where('ip_address', '=', Request::ip())->first(); if (!$rating) $rating = new Rating; // Reset everything incase it's new $rating->takeaway_id = $id; $rating->ip_address = Request::ip(); $rating->rating = $user_rating; $rating->save(); $takeaway->refresh_rating(); $takeaway->flush_cache(); $takeaway->action('rating'); } public function action_save_review() { $id = Input::get('id'); $new_review = Input::get('review'); // Apps with send takeaway_id if (!$id) $id = Input::get('takeaway_id'); if (Block::check(Request::ip())) return 'BLOCKED'; // Response::error('403'); if (!$id || !$new_review) return Response::error('400'); $takeaway = Takeaway::find($id); if (!$takeaway) return Event::first('404'); $akismet = IoC::Resolve('Akismet'); $comment = array('body' => $new_review); $config = array( 'comment' => $comment, 'api_key' => '00d49d443555', 'blog_url' => 'http://www.takeaway-finder.co.uk' ); $spam = false; $akismet->init($config); if ( $akismet->errors_exist() ) { return Event::first('500'); } elseif ($akismet->is_spam()) { $spam = true;; } $review = new Review; $review->review = $new_review; $review->status = $spam ? 'blocked' : 'new'; $review->ip_address = Request::ip(); $review->created_at = date('c'); $review->email_address = ''; // $review->save(); $review = $takeaway->Reviews()->insert($review); $takeaway->flush_cache(); $takeaway->action('review', $review); if ($takeaway->user_id && $takeaway->email_review == 1) { $user = User::find($takeaway->user_id); if ($user) $user->email('review', array('takeaway' => $takeaway, 'review' => $review)); } if (ENVIRONMENT == 'desktop') { if ($spam) { return 'SPAM'; } else { return View::make(ENV_VIEW_DIR.'.review') ->with(array( 'review' => $review, 'takeaway' => $takeaway, 'new' => true )); } } else { return $spam ? 'SPAM' : 'saved'; } } public function action_report_review() { $id = Input::get('review_id'); if (Block::check(Request::ip())) return 'BLOCKED'; // Response::error('403'); if (!$id) return Response::error('400'); $review = Review::find($id); if (!$review) return Event::first('404'); $review->status = 'reported'; $review->save(); $takeaway = Takeaway::find($review->takeaway_id); $takeaway->action('review_reported', $review); return "Thanks, we'll review this review."; } public function action_migrate_old($old_id, $captcha = 'invalid captcha') { $old_takeaway = Oldtakeaway::find($old_id); if (!$old_takeaway) return Response::json( array('alert' => "Sorry, we couldn't find that ".CONTENT_NAME.", something went wrong.")); if (!function_exists('crawlerDetect')) include path('app').'libraries/crawler_detect.php'; if (crawlerDetect() && !Captcha::check($captcha)) { mail('malcolm@christiesmedia.co.uk', 'Failed Captcha migration', "Failed for ID: {$old_id}\n\nUser agent: ".$_SERVER['HTTP_USER_AGENT']); return Response::json( array('alert' => "Sorry, please check you entered the right text from the image.")); } mail('malcolm@christiesmedia.co.uk', 'Migration!', "Migrated ID: {$old_id}\n\nUser agent: ".$_SERVER['HTTP_USER_AGENT']); $new_takeaway = $old_takeaway->migrate(); $new_takeaway->action('migrated'); return Response::json( array('url' => $new_takeaway->url) ); } }

Unhandled Exception

Message:

Class 'Browse_Controller' not found

Location:

/home/forge/takeaway-finder.co.uk/laravel/routing/controller.php on line 226

Stack Trace:

#0 /home/forge/takeaway-finder.co.uk/laravel/routing/controller.php(145): Laravel\Routing\Controller::resolve('application', 'Browse_Controll...')
#1 /home/forge/takeaway-finder.co.uk/laravel/routing/route.php(153): Laravel\Routing\Controller::call('browse@state_to...', Array)
#2 /home/forge/takeaway-finder.co.uk/laravel/routing/route.php(124): Laravel\Routing\Route->response()
#3 /home/forge/takeaway-finder.co.uk/laravel/laravel.php(125): Laravel\Routing\Route->call()
#4 /home/forge/takeaway-finder.co.uk/public_html/index.php(34): require('/home/forge/tak...')
#5 {main}