/**
  * Show blor article page by article slug
  * @param string $slug Post slug
  */
 public function post($slug)
 {
     // Check if article exists
     $this->data['article'] = $this->blog_articles_model->get_article_by_slug($slug);
     if (!count($this->data['article'])) {
         custom_404();
     } else {
         // Redirect if /blog/post/slug
         if ($this->uri->segment(1) == 'blog') {
             $url = $this->uri->segment(2) . '/' . $this->uri->segment(3);
             redirect($url, 'location', '301');
         }
         // Page title and description
         $this->data['seo'] = $this->seo_model->get_by(array('name' => 'Post'), TRUE);
         $this->data['seo']->title .= ' ' . $this->data['article']->title;
         $this->data['seo']->description = $this->data['article']->title;
         // Load layout and content view
         $this->load_view('layouts/blog', 'blog_post');
     }
 }
 /**
  * Ajax feedback form method
  */
 public function email()
 {
     if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) or $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
         // No direct access allowed
         custom_404();
     } else {
         // Set up the form
         $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|xss_clean|htmlentities');
         $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
         $this->form_validation->set_rules('subject', 'Subject', 'trim|required|min_length[3]|xss_clean|htmlentities');
         $this->form_validation->set_rules('website', 'Website', 'trim|min_length[4]|xss_clean|htmlentities');
         $this->form_validation->set_rules('message', 'Message', 'trim|required|max_length[1000]|xss_clean|htmlentities');
         $this->form_validation->set_rules('captcha', 'Captcha', 'trim|required|integer|callback__captcha');
         // Process the form
         if ($this->form_validation->run() == TRUE) {
             // get user email
             $this->load->model('user_model');
             $user_email = $this->user_model->get(1)->email;
             // send email
             $this->load->library('email');
             $config['mailtype'] = 'html';
             $this->email->initialize($config);
             $this->email->from('*****@*****.**', 'Mypersonal feedback form');
             $this->email->reply_to($this->input->post('email'), $this->input->post('name'));
             $this->email->to($user_email);
             $this->email->subject($this->input->post('subject'));
             $data = array();
             $data['name'] = $this->input->post('name');
             $data['email'] = $this->input->post('email');
             $data['subject'] = $this->input->post('subject');
             $data['website'] = $this->input->post('website');
             $data['message'] = $this->input->post('message');
             $message = "<div style=\"width:100%;font-family:Arial;font-size:14px;color:#333;\">\n    <p>\n        <strong>From: </strong>{$data['name']}<br/>\n        <strong>Email: </strong><a href=\"mailto:{$data['email']}\">{$data['email']}</a><br/>\n        <strong>Subject: </strong>{$data['subject']}<br/>\n        <strong>Website: </strong><a href=\"{$data['website']}\">{$data['website']}</a><br/>\n        <strong>Message: </strong><br/>{$data['message']}\n    </p>\n</div>";
             $this->email->message($message);
             $this->email->send();
             $errors = FALSE;
             $mes = '<p>Mail has been sent</p>';
         } else {
             $errors = validation_errors();
             $mes = FALSE;
         }
         // Generate new captcha
         $a = mt_rand(1, 10);
         $b = mt_rand(1, 10);
         $captcha = array('captcha_string' => "{$a} + {$b} =", 'captcha_value' => $a + $b);
         $this->session->set_userdata($captcha);
         // return json data to client
         echo json_encode(array('errors' => $errors, 'mes' => $mes, 'captcha' => $this->session->userdata('captcha_string')));
     }
 }