Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
836 lines (687 sloc) 30 KB
<?php
/*
* Author: Greg London
* http://greglondon.info
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
private $cal = array();
private $role = null;
private $adminEmail = 'gregdlondon@gmail.com';
public function __construct()
{
parent::__construct();
$this->load->model('Subscribers', 'sub', TRUE);
$this->load->model('Leads', 'lead', TRUE);
$this->load->helper('custom');
session_start();
if (isset($_SESSION['role']))
$this->role = $_SESSION['role'];
}
public function index()
{
$headData['title'] = "Greg's web development services!";
$headData['description'] = 'Information about getting to know Greg London the web application developer, programmer.';
$headData['keywords'] = 'Greg London, web application developer, programmer';
$headData['canonical'] = base_url();
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$data['ad'] = self::googleAd();
$sidebar = sidebar();
$this->header($headData);
$this->load->view('home', array_merge($data, $sidebar));
$this->footer();
}
public function contact()
{
$headData['title'] = "Contact Greg London!";
$headData['description'] = 'Contact Greg London to get more information about getting a website built.';
$headData['keywords'] = 'Greg London, contact, website built';
$headData['canonical'] = base_url().'contact';
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$data['attributes'] = array(
'class' => 'contact'
);
$data['firstName'] = array(
'name' => 'firstName',
'maxlength' => '50',
'id' => 'firstName',
'value' => 'First Name',
'onfocus' => "if (this.value == 'First Name') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'First Name';}"
);
$data['lastName'] = array(
'name' => 'lastName',
'maxlength' => '50',
'id' => 'lastName',
'value' => 'Last Name',
'onfocus' => "if (this.value == 'Last Name') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Last Name';}"
);
$data['phone'] = array(
'name' => 'phone',
'maxlength' => '15',
'id' => 'phone',
'value' => 'Phone',
'onfocus' => "if (this.value == 'Phone') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Phone';}"
);
$data['email'] = array(
'name' => 'email',
'maxlength' => '75',
'id' => 'email',
'value' => 'Email',
'onfocus' => "if (this.value == 'Email') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Email';}"
);
$data['dateOption'] = array(
'name' => 'dateOption',
'checked' => false,
'value' => 'No',
'id' => 'dateOption'
);
$today = date('m/d/Y');
$coupleDays = date('m/d/Y', strtotime($today . ' + 2 days'));
$data['date'] = array(
'name' => 'date',
'id' => 'datepicker',
'value' => html_escape($coupleDays)
);
$data['question'] = array(
'name' => 'question',
'maxlength' => '500',
'id' => 'question',
'placeholder' => 'Comments/Questions',
'onfocus' => "if (this.value == 'Comments/Questions') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Comments/Questions';}"
);
$data['tzSelected'] = 'central';
$data['tiZone'] = 'id="timeZone"';
$data['tzOptions'] = array(
'central' => 'Central Time',
'pacific' => 'Pacific Time',
'eastern' => 'Eastern Time'
);
$data['tiTime'] = 'id="time"';
$data['tiSelected'] = 'am';
$data['tiOptions'] = array(
'am' => 'AM',
'pm' => 'PM'
);
$data['amSelected'] = 7;
$data['pmSelected'] = 4;
$data['amHour'] = 'id="amHour"';
$data['pmHour'] = 'id="pmHour"';
$data['amOptions'] = array(
7 => '7:00',
8 => '8:00',
9 => '9:00',
10 => '10:00',
11 => '11:00'
);
$data['pmOptions'] = array(
12 => '12:00',
1 => '1:00',
2 => '2:00',
3 => '3:00',
4 => '4:00',
5 => '5:00',
6 => '6:00',
7 => '7:00',
8 => '8:00'
);
$data['subscribe'] = array(
'name' => 'subscribe',
'checked' => true,
'value' => 'Yes',
'id' => 'subscribe'
);
$data['image'] = $this->createCaptcha();
$data['captchaInput'] = array(
'name' => 'captcha',
'color' => 'white',
'class' => 'captchaPadding',
'placeholder' => '',
'id' => 'captcha',
'value' => 'Captcha',
'onfocus' => "if (this.value == 'Captcha') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Captcha';}"
);
$data['submit'] = array(
'name' => 'submit',
'value' => 'Send',
'class' => 'btn btn-large btn-success',
'id' => 'send'
);
$this->load->helper('form');
$this->header($headData);
$sidebar = sidebar();
$this->load->view('contact', array_merge($data, $sidebar));
$this->footer();
}
public function submitContact()
{
if (!$this->input->is_ajax_request()) {
redirect('notAjax');
exit();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('firstName','First Name','trim|required|max_length[50]|xss_clean|callback_firstCheck');
$this->form_validation->set_rules('lastName','Last Name','trim|required|max_length[50]|xss_clean|callback_lastCheck');
$this->form_validation->set_rules('phone','Phone','callback_phoneCheck|trim|required|max_length[15]|xxs_clean');
$this->form_validation->set_rules('email','Email','trim|required|max_length[75]|valid_email|xss_clean');
$this->form_validation->set_rules('question','Question','trim|xss_clean');
$this->form_validation->set_rules('captcha', 'Captcha', 'callback_captchaCheck|required');
$this->form_validation->set_rules('date','Date','callback_dateCheck|trim|required|xss_clean|max_length[25]|regex_match[/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/]');
if ($this->form_validation->run() == false) {
$errors = array();
foreach ($this->input->post() as $key => $value) {
$errors[$key] = form_error($key);
}
$response['date'] = false;
if ($errors['date'] !== '') $response['date'] = true;
$response['errors'] = array_filter($errors);
$response['success'] = false;
exit(json_encode($response));
} else {
$response['success'] = true;
$this->load->helper('custom');
$question = $this->input->post('question');
if ($question == '') $question = 'None';
if ($question == 'Comments/Questions') $question = 'None';
$sub = $this->input->post('subscribe') == 'Yes' ? true : false;
$datepicker = $this->input->post('date');
$datepicker = date('Y-m-d', strtotime($datepicker));
if ($this->input->post('time') == 'am')
$postHour = $this->input->post('amHour');
else
$postHour = $this->input->post('pmHour');
if ($this->input->post('dateOption') == true) {
$data = array(
'firstName' => self::formatFirstName($this->input->post('firstName')),
'lastName' => self::formatLastName($this->input->post('lastName')),
'phone' => html_escape($this->input->post('phone')),
'email' => $this->input->post('email'),
'question' => html_escape($question),
'date' => $datepicker,
'timeZone' => html_escape($this->input->post('timeZone')),
'hour' => html_escape($postHour),
'time' => html_escape($this->input->post('time')),
'subscribe' => $sub,
'appointment' => true
);
$date = $data['date'];
$hour = (int)$data['hour'];
$time = strtoupper($data['time']);
$timeZone = $data['timeZone'];
$end = 0;
$s = ($hour < 10 ? ' 0' : ' ');
$end = ($hour == 12 ? 1 : $hour + 1);
$es = ($end < 10 ? ' 0' : ' ');
$this->cal['calendarStart'] = $date . $s . $hour . ':00 ' . $time;
if ($hour == 11) $time = 'PM';
$this->cal['calendarEnd'] = $date . $es . $end . ':00 ' . $time;
switch ($timeZone) {
case 'central':
$this->cal['calendarZone'] = 'America/Chicago';
break;
case 'eastern':
$this->cal['calendarZone'] = 'America/New_York';
break;
default:
$this->cal['calendarZone'] = 'America/Los_Angeles';
}
$this->cal['calendarTitle'] = 'Appointment with Greg London on Web Project.';
$this->cal['calendarDesc'] = 'Appointment with Greg London for your Web Project';
$successMessage = 'Thank you for getting in touch '.$data['firstName'].'.<br />'
. 'Your appointment is scheduled for '.formatDate($date).' at '.$hour.''.$data['time'].' '.$timeZone.' time.';
$response['message'] = '<div class="success">'.$successMessage.'</div><script>$(".contactFormIndent").hide(2000);</script>';
$response['calendar'] = $this->calendar();
} else {
$data = array(
'firstName' => self::formatFirstName($this->input->post('firstName')),
'lastName' => self::formatLastName($this->input->post('lastName')),
'phone' => html_escape($this->input->post('phone')),
'email' => $this->input->post('email'),
'question' => html_escape($question),
'date' => 'N/a',
'timeZone' => 'N/a',
'hour' => 'N/a',
'time' => 'N/a',
'subscribe' => $sub,
'appointment' => false
);
$successMessage = 'Thank you for getting in touch '.$data['firstName'].'! Greg will be calling you soon!';
$response['message'] = '<div class="success">'.$successMessage.'</div><script>$(".contactFormIndent").hide(2000);</script>';
}
$this->processContactForm($data);
$this->lead->insertLead($data);
exit(json_encode($response));
}
}
private function calendar()
{
$calendar = '<script type="text/javascript" src="https://addthisevent.com/libs/1.6.0/ate.min.js"></script>
<div class="calendar">
<div title="Add to Calendar" class="addthisevent">
Add to Calendar
<span class="start">'.html_escape($this->cal['calendarStart']).'</span>
<span class="end">'.html_escape($this->cal['calendarEnd']).'</span>
<span class="timezone">'.html_escape($this->cal['calendarZone']).'</span>
<span class="title">'.html_escape($this->cal['calendarTitle']).'</span>
<span class="description">'.html_escape($this->cal['calendarDesc']).'</span>
<span class="all_day_event">false</span>
<span class="date_format">MM/DD/YYYY</span>
</div>
</div>';
return $calendar;
}
private function processContactForm($data)
{
$emailExists = $this->sub->checkEmailExists($data['email']);
if($data['date'] != 'N/a')
$dateFormat = array('dateFormat' => formatDate($data['date']));
else
$dateFormat = array('dateFormat' => date('Y-m-d'));
$data['adminEmail'] = $this->adminEmail;
if ($data['subscribe'] && !$emailExists) {
$this->sub->addSubscriber($data);
$subscribed = array('subscribed' => true);
}
elseif ($data['subscribe'] && $emailExists)
$subscribed = array('subscribed' => false, 'cannot_subscribe' => true);
else
$subscribed = array('subscribed' => false);
$this->load->library('email');
$adminSubject = 'A user has filled out the contact form at GregLondon.info';
$toAdmin = array_merge($data, $subscribed);
$adminMessage = $this->load->view('emails/adminContact', $toAdmin, TRUE);
$this->email->set_mailtype('html');
$this->email->from($this->adminEmail);
$this->email->to($this->adminEmail);
$this->email->subject($adminSubject);
$this->email->message($adminMessage);
$this->email->subject($adminSubject);
$this->email->send();
$id = $this->getIdByEmail($data['email']);
$dateSignedUp = $this->sub->getSignUpDate($id);
$dateSigned = array('dateSignedUp' => formatDate($dateSignedUp));
$dataAdd = array_merge($data, $subscribed, $dateFormat, $dateSigned, array('id' => $id));
$userSubject = 'Thank you for contacting Greg about your web project.';
$userMessage = $this->load->view('emails/userContact', $dataAdd, TRUE);
$this->email->set_mailtype('html');
$this->email->from($this->adminEmail);
$this->email->to($data['email']);
$this->email->subject($userSubject);
$this->email->message($userMessage);
$this->email->send();
}
public function subscribe()
{
$headData['title'] = 'Subscribe';
$headData['description'] = 'Join the newsletter and get more information about getting a website built.';
$headData['keywords'] = 'Greg London, subscribe, join newsletter';
$headData['canonical'] = base_url().'subscribe';
$headData['role'] = $this->role;
$data['attributes'] = array(
'class' => 'subscribe'
);
$data['firstName'] = array(
'name' => 'firstName',
'maxlength' => '50',
'id' => 'firstName',
'value' => 'First Name',
'onfocus' => "if (this.value == 'First Name') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'First Name';}"
);
$data['email'] = array(
'name' => 'email',
'maxlength' => '75',
'id' => 'email',
'value' => 'Email',
'onfocus' => "if (this.value == 'Email') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Email';}"
);
$data['image'] = $this->createCaptcha();
$data['captchaInput'] = array(
'name' => 'captcha',
'color' => 'white',
'class' => 'captchaPadding',
'placeholder' => '',
'id' => 'captcha',
'value' => 'Captcha',
'onfocus' => "if (this.value == 'Captcha') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Captcha';}"
);
$data['submit'] = array(
'name' => 'submit',
'value' => 'Subscribe',
'class' => 'btn btn-large btn-success',
'id' => 'subscribeSubmit'
);
$this->load->helper('form');
$this->header($headData);
$sidebar = sidebar();
$this->load->view('subscribe', array_merge($data, $sidebar));
$this->footer();
}
public function submitSubscribe()
{
if (!$this->input->is_ajax_request()) {
redirect('notAjax');
exit();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('firstName','First Name','trim|required|max_length[50]|xss_clean|callback_firstCheck');
$this->form_validation->set_rules('email','Email','trim|required|max_length[75]|valid_email|is_unique[subscribers.email]|xss_clean');
$this->form_validation->set_message('is_unique', 'The %s address cannot already be subscribed.');
$this->form_validation->set_rules('captcha', 'Captcha', 'callback_captchaCheck|required');
if ($this->form_validation->run() == false) {
$errors = array();
foreach ($this->input->post() as $key => $value) {
$errors[$key] = form_error($key);
}
$response['errors'] = array_filter($errors); // Some will be empty...
$response['success'] = false;
header('Content-type: application/json');
exit(json_encode($response));
} else {
$response['success'] = true;
$data = array(
'firstName' => self::formatFirstName($this->input->post('firstName')),
'email' => $this->input->post('email'),
'date' => date('Y-m-d')
);
$successMessage = 'Thanks for joining the newsletter '.$data['firstName'].'!';
$response['message'] = '<div class="success">'.$successMessage.'</div><script>$(".subscribeFormIndent").hide(2000);</script>';
$this->processSubscribeForm($data);
header('Content-type: application/json');
exit(json_encode($response));
}
}
private function processSubscribeForm($data)
{
$this->sub->addSubscriber($data);
$this->load->library('email');
$data['adminEmail'] = $this->adminEmail;
$adminSubject = 'A user subscribed to GregLondon.info on ' . date('Y-m-d');
$adminMessage = $this->load->view('emails/adminSubscribe', $data, TRUE);
$this->email->set_mailtype('html');
$this->email->from($this->adminEmail);
$this->email->to($this->adminEmail);
$this->email->subject($adminSubject);
$this->email->message($adminMessage);
$this->email->send();
$id = $this->getIdByEmail($data['email']);
$dataAdd = array_merge($data, array('id' => $id));
$userRecipient = $data['email'];
$userSubject = 'Thank you for subscribing to GregLondon.info.';
$userMessage = $this->load->view('emails/userSubscribe', $dataAdd, TRUE);
$this->email->set_mailtype('html');
$this->email->from($this->adminEmail);
$this->email->to($userRecipient);
$this->email->subject($userSubject);
$this->email->message($userMessage);
$this->email->send();
}
public function unsubscribe($email = NULL, $firstName = NULL, $id = NULL)
{
$headData['title'] = "Unsubscribe";
$headData['description'] = 'Unsubscribe from the GregLondon.info newsletter.';
$headData['keywords'] = 'Greg London, unsubscribe, newsletter';
$headData['canonical'] = base_url().'unsubscribe';
$headData['role'] = $this->role;
//clean up the name string...
$filteredName = filter_var($firstName, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$data['email'] = str_replace('%40', '@', $email); // convert @ symbol back to normal from url..
$data['firstName'] = $filteredName;
$data['id'] = (int)$id; //make sure we are dealing with an integer...
//just manually make the form to get access to needed url variables
$data['form'] = '<form action="'.base_url().'unsubscribe/'.$data['email'].'/'.$data['firstName'].'/'.$data['id'].'" method="post" accept-charset="utf-8" class="unsubscribe">
<fieldset><legend>Are you sure?</legend><input type="submit" name="submit" value="Unsubscribe" class="btn btn-large btn-success" />
</fieldset></form>';
//getting email from url, need to make sure it's clean
if (filter_var($data['email'], FILTER_VALIDATE_EMAIL) === false && $data['email'] === NULL)
$data['email'] = 'none@none.com'; // set a fake default for now (so at least it's safe)
//getting id from url, need to make sure it is an integer...
if (filter_var($data['id'], FILTER_VALIDATE_INT) === false)
$data['message'] = 'There is no (integer) ID for an email to unsubscribe in the url.';
else {
$checkId = $this->sub->checkIdExists($data['id']); // make sure id is available in db
$checkSub = $this->sub->checkSub($data['id'], $data['firstName'], $data['email']);
if ($checkId && $checkSub) {
if (!empty($_POST)) {
// there will be no errors because it's just a button...
$deleteSub = $this->sub->deleteSubscriber($data['id']);
if ($deleteSub) {
$data['message'] = 'You have been unsubscribed from the newsletter. Sorry to see you go.';
$this->load->library('email');
$adminRecipient = $this->adminEmail;
$adminSubject = 'A user Unsubscribed to GregLondon.info on ' . date('Y-m-d');
$adminEmail['firstName'] = $data['firstName'];
$adminEmail['email'] == $data['email'];
$adminMessage = $this->load->view('emails/adminUnsubscribe', $adminEmail, TRUE);
$this->email->set_mailtype('html');
$this->email->from($adminRecipient);
$this->email->to($adminRecipient);
$this->email->subject($adminSubject);
$this->email->message($adminMessage);
$this->email->send();
}
else
$data['message'] = 'There was a problem deleting the email address. Please contact Greg for further assistance.';
}
}
else
$data['message'] = 'The ID and email combined did not match our records.';
}
$this->load->helper('form');
$this->header($headData);
$this->load->view('unsubscribe', $data);
$this->footer();
}
private function createCaptcha()
{
$this->load->helper('captcha');
$captchaValues = array(
'word' => '',
'word_length' => 8,
'img_path' => './img/captcha/',
'img_url' => base_url() . 'img/captcha/',
'font_path' => base_url() . 'system/fonts/texb.ttf',
'img_width' => '125',
'img_height' => 50,
'expiration' => 3600
);
$cap = create_captcha($captchaValues);
$_SESSION['captchaWord'] = $cap['word'];
return $cap['image'];
}
private function getIdByEmail($email)
{
$id = $this->sub->getIdByEmail($email);
if ($id == false)
$id = 0;
return $id;
}
private static function formatFirstName($str)
{
$str = html_escape($str);
$str = strtolower($str);
$str = ucfirst($str);
return $str;
}
private static function formatLastName($str)
{
$str = html_escape($str);
$str = strtolower($str);
$str = ucfirst($str);
return $str;
}
public function dateCheck($str)
{
$today = date('m/d/Y');
$dateEntered = date('m/d/Y',strtotime($str));
if($dateEntered <= $today){
$this->form_validation->set_message('dateCheck', 'The %s field can not be today or in the past.');
return false;
}
else
return true;
}
public function captchaCheck($str)
{
if (strcasecmp($_SESSION['captchaWord'], $str) == 0)
return true;
else {
$this->form_validation->set_message('captchaCheck', 'The %s field was not correct.');
return false;
}
}
public function firstCheck($str)
{
$value = trim($str);
if ($value == 'First Name') {
$this->form_validation->set_message('firstCheck', 'The %s field is required.');
return false;
}
else
return true;
}
public function lastCheck($str)
{
$value = trim($str);
if ($value == 'Last Name') {
$this->form_validation->set_message('lastCheck', 'The %s field is required.');
return false;
}
else
return true;
}
public function phoneCheck($str)
{
$value = trim($str);
if (!preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $value)){
$this->form_validation->set_message('phoneCheck', 'The %s field should be in this format: (555-555-5555).');
return false;
}
else
return true;
}
public function header($headData)
{
$this->load->view('partials/header',$headData);
}
public function footer()
{
$this->load->view('partials/footer');
}
public function webDesign()
{
$headData['title'] = "Hire Greg for a Web Project";
$headData['description'] = 'Greg London charges an affordable price to get your custom website done today.';
$headData['keywords'] = 'website application, Greg London';
$headData['canonical'] = base_url().'web-design';
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$this->header($headData);
$data = sidebar();
$this->load->view('webDesign', $data);
$this->footer();
}
public function portfolio()
{
$headData['title'] = "Web Development Portfolio";
$headData['description'] = 'View some of the websites Greg London has built and updated.';
$headData['keywords'] = 'website portfolio, Greg London';
$headData['canonical'] = base_url().'portfolio';
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$this->header($headData);
$data = sidebar();
$this->load->view('portfolio', $data);
$this->footer();
}
public function seo()
{
$headData['title'] = "Search Engine Optimization";
$headData['description'] = 'Greg can help you get your website indexed in search engines';
$headData['keywords'] = 'search engine optimization, seo';
$headData['canonical'] = base_url().'seo';
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$data['ad'] = self::googleAd();
$sidebar = sidebar();
$this->header($headData);
$this->load->view('seo', array_merge($data, $sidebar));
$this->footer();
}
public function bio()
{
$headData['title'] = "Biography";
$headData['description'] = 'See Greg London\'s Biography.';
$headData['keywords'] = 'biography, Greg London';
$headData['canonical'] = base_url().'bio';
$headData['active'] = 'class="active"';
$headData['role'] = $this->role;
$data['ad'] = self::googleAd();
$sidebar = sidebar();
$this->header($headData);
$this->load->view('bio', array_merge($data, $sidebar));
$this->footer();
}
public function privacy()
{
$headData['title'] = "Privacy Policy";
$headData['description'] = 'Privacy policy for greglondon.info.';
$headData['keywords'] = 'privacy policy';
$headData['canonical'] = base_url().'privacy';
$headData['role'] = $this->role;
$this->header($headData);
$this->load->view('privacy');
$this->footer();
}
public function disclosures()
{
$headData['title'] = "Disclosures";
$headData['description'] = 'Disclosures for greglondon.info.';
$headData['keywords'] = 'disclosures';
$headData['canonical'] = base_url().'disclosures';
$headData['role'] = $this->role;
$this->header($headData);
$this->load->view('disclosures');
$this->footer();
}
private static function googleAd()
{
$googleAdsense = '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- larger ad unit -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:280px"
data-ad-client="ca-pub-0372492470050030"
data-ad-slot="3565604629"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
return $googleAdsense;
}
public function notAjax()
{
$headData['title'] = "Invalid Ajax Request...";
$headData['description'] = 'Not a valid Ajax Request. Please try again.';
$headData['keywords'] = 'invalid ajax';
$headData['canonical'] = base_url().'notAjax';
$headData['role'] = $this->role;
$this->header($headData);
$this->load->view('notAjax');
$this->footer();
}
function sitemap()
{
$data['pages'] = array('web-design','portfolio','seo','contact','subscribe','privacy','disclosures','admin');
header("Content-Type: text/xml;charset=iso-8859-1");
$this->load->view('sitemap',$data);
}
}