File: /home/awaldron/_buildinmotion/bim_ci/app/Controllers/ServiceArea.php
<?php namespace App\Controllers;
class ServiceArea extends BaseController
{
public function index()
{
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
}
public function states()
{
$url = 'https://hub.bimcatalyst.dev/api/v2/objects/data/State?size=100&i=0&q=&t=&sort=asc';
$authToken = 'Jy23Ns2zSEiOjuBipq+9Mw==';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Set the request URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $authToken", // Set the Authorization header
"Content-Type: application/json" // Optional: Specify content type if sending/receiving JSON
]);
$response = curl_exec($ch);
$states = json_decode( $response, true );
$states = $states['r'];
usort($states, function($a, $b) {
return strcmp($a['Name'], $b['Name']);
});
$data = [];
$data['title'] = 'Custom Software Development throughout the United States';
$data['description'] = 'Build in Motion offers Custom Software Development services to clients like you throughout the United States';
$data['canon'] = 'https://buildinmotion.com/local/states';
$data['nav'] = '';
$data['states'] = $states;
$html = view('_header', $data);
$html .= view('_header_ui', $data);
$html .= view('states', $data);
$html .= view('_footer');
$html .= view('_footer_ui');
echo $html;
}
public function state( $state )
{
$url = 'https://hub.bimcatalyst.dev/api/v2/objects/data/Metros?size=100&i=0&q='.urlencode('{"Payload.StateAbbr":{$eq:"'.strtoupper($state).'"}}').'&t=&sort=asc';
$authToken = 'Jy23Ns2zSEiOjuBipq+9Mw==';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Set the request URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $authToken", // Set the Authorization header
"Content-Type: application/json" // Optional: Specify content type if sending/receiving JSON
]);
$response = curl_exec($ch);
$cities = json_decode( $response, true );
$cities = $cities['r'];
usort($cities, function($a, $b) {
return strcmp($a['City'], $b['City']);
});
//echo '<pre>', print_r($cities), '</pre>';
$data = [];
$data['title'] = 'Custom Software Development in '.$cities[0]['State'];
$data['description'] = 'Build in Motion offers quality Custom Software Development for clients like you in '.$cities[0]['State'];
$data['canon'] = 'https://buildinmotion.com/local/state/'.strtolower($cities[0]['StateAbbr']);
$data['nav'] = '';
$data['cities'] = $cities;
$html = view('_header', $data);
$html .= view('_header_ui', $data);
$html .= view('state', $data);
$html .= view('_footer');
$html .= view('_footer_ui');
echo $html;
}
public function city( $state, $cityslug )
{
helper('content');
$citySearch = str_ireplace('-', ' ', $cityslug);
$q = '{"Payload.StateAbbr":{$regex:"^'.strtolower($state).'$",$options:"i"},"Payload.City":{$regex:"^'.strtolower($citySearch).'$",$options:"i"}}';
$url = 'https://hub.bimcatalyst.dev/api/v2/objects/data/Metros?size=100&i=0&q='.urlencode($q).'&t=&sort=asc';
$authToken = 'Jy23Ns2zSEiOjuBipq+9Mw==';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Set the request URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $authToken", // Set the Authorization header
"Content-Type: application/json" // Optional: Specify content type if sending/receiving JSON
]);
$response = curl_exec($ch);
$city = json_decode( $response, true );
$city = $city['r'];
if (count($city) === 0) {
$city['City'] = str_replace('-',' ',ucwords($cityslug));
$city['StateAbbr'] = strtoupper($state);
} else {
$city = $city[0];
}
// TEMP FIXES FOR 404's
if (count($city) === 0 && $state === 'nh') {
return redirect()->to("/local/nj/".$cityslug)->setStatusCode(301);
}
else if (count($city) === 0 && $state === 'hi') {
return redirect()->to("/local/ia/".$cityslug)->setStatusCode(301);
}
else {
$session = \Config\Services::session();
$session->set('locale', $city['City'].', '.$city['StateAbbr']);
$data = [];
$data['title'] = 'Your Custom Software Development Experts in ' . $city['City'] . ', ' . $city['StateAbbr'];
$data['description'] = 'Build in Motion is a custom software agency specializing in mobile apps, artificial intelligence, and e-commerce for businesses like yours in ' . $city['City'] . ', ' . $city['StateAbbr'];
$data['canon'] = 'https://buildinmotion.com/local/'.strtolower($state).'/'.$cityslug;
$data['nav'] = 'contact';
$data['city'] = $city['City'];
$data['state'] = $city['StateAbbr'];
$data['radius'] = !empty($city['Population']) ? $city['Population'] : 30000 ;
$data['intro'] = get_intro();
$data['features'] = shuffle_features();
$data['services'] = shuffle_services();
$data['testimonials'] = shuffle_testimonials();
$html = view('_header', $data);
$html .= view('_header_ui', $data);
$html .= view('localsplash', $data);
$html .= view('local', $data);
$html .= view('_footer');
$html .= view('_footer_ui');
echo $html;
}
}
}