/** * /contact/ */ public function index($parameters) { if ($parameters) { $this->loadView('404'); } $page = new Page($this->db, $this->business['id']); $data = $page->getPageData('contact'); if (!$data) { $this->loadView('404'); } if (!$data['title']) { $data['title'] = 'Contact Us'; } $location = $page->getLocationAndHours(); $address = str_replace('<br>', ' ', $location['location']); $address = str_replace(' ', '+', $address); $url = 'http://maps.google.com/maps/api/geocode/json?address=' . $address . '&sensor=false'; try { $json = file_get_contents($url); $json = json_decode($json); if (isset($json->{'results'}[0]->{'geometry'}->{'location'})) { $coordinates = $json->results[0]->geometry->location; $data['coordinates'] = array('latitude' => $coordinates->lat, 'longitude' => $coordinates->lng); } } catch (Exception $e) { } $this->data = $data; $this->loadView('contact'); }
/** * Get the data that is loaded on every page. * * @return array */ private function _fetchPageData() { $page = new Page($this->db, $this->business['id']); $data = array(); $data['business'] = $this->business; $data['navigation_links'] = $page->getNavigationLinks(); $data['newsletter'] = $page->getNewsletterStatus(); $data['social_links'] = $page->getSocialLinks(); $location_and_hours = $page->getLocationAndHours(); $data['location'] = $location_and_hours['location']; $data['hours'] = $location_and_hours['hours']; return $data; }