Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
- class Commentaires extends CI_Controller
- {
- public function __construct()
- {
- parent::__construct();
- $this->load->database();
- $this->load->helper(array(
- 'url',
- 'security'
- ));
- $this->load->model('tutoriel_model');
- $this->load->model('commentaire_model');
- }
- public function ecrire()
- {
- $this->load->library('form_validation');
- $this->form_validation->set_rules('g-recaptcha-response', 'recaptcha validation', 'required|callback_validate_captcha');
- $this->form_validation->set_message('validate_captcha', 'Please check the the captcha form');
- $this->form_validation->set_error_delimiters('<p class="form_erreur">', '</p>');
- $this->form_validation->set_rules('pseudo', '"Pseudo"', 'trim|required|min_length[3]|max_length[25]|alpha_dash|xss_clean');
- $this->form_validation->set_rules('contenu', '"Contenu"', 'trim|required|min_length[3]|max_length[3000]|xss_clean');
- $this->form_validation->set_rules('id_tuto', '"id_tuto"', 'trim|required|xss_clean');
- if ($this->form_validation->run()) {
- $data['title'] = "Ecrire commentaire";
- $this->commentaire_model->ajouter_commentaire($this->input->post('pseudo'), $this->input->post('contenu'), $this->input->post('id_tuto'));
- redirect('home/index');
- } else {
- $data ['title'] = 'Ecrire commentaire ';
- $this->load->view('common/header', $data);
- $this->load->view('common/nav');
- $this->load->view('commentaires/ecrire', $data);
- echo 'erreur';
- }
- }
- function validate_captcha()
- {
- $recaptcha = trim($this->input->post('g-recaptcha-response'));
- $userIp = $this->input->ip_address();
- $secret = '6LeOoSMUAAAAAFkaazrhAVMdoCLGx1Ne6Q5awFQa';
- $data = array(
- 'secret' => "$secret",
- 'response' => "$recaptcha",
- 'remoteip' => "$userIp"
- );
- $verify = curl_init();
- curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
- curl_setopt($verify, CURLOPT_POST, true);
- curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
- curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($verify);
- $status = json_decode($response, true);
- if (empty($status['success'])) {
- return FALSE;
- } else {
- return TRUE;
- }
- }
- // public function suppression($id_commentaire = NULL)
- // {
- // if (!$this->auth_user->is_connected) {
- // redirect('home/index');
- // }
- // if (!is_numeric($id_commentaire)) {
- // redirect('home/index');
- // }
- // if ($this->input->post('confirm') === NULL) {
- // $data['action'] = "confirm";
- // } else {
- // $this->commentaire_model->delete_comment($id_commentaire);
- // $data['action'] = "result";
- // }
- // $data['title'] = "Suppression commentaire";
- // $this->load->helper('form');
- // $this->load->view('dashboard/header_admin', $data);
- // $this->load->view('blog/delete_comment', $data);
- // }
- // public function validate_comment($id_commentaire)
- // {
- // $this->load->model('commentaire_model');
- // $this->commentaire_model->validate_comment($id_commentaire);
- // $this->load->view('common/header', $data);
- // $this->load->view('commentaires/validate_comment', $data);
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement