Advertisement
tonny16

controller commentaires

Jul 10th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.02 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3.  
  4. class Commentaires extends CI_Controller
  5. {
  6.    
  7.     public function __construct()
  8.     {
  9.         parent::__construct();
  10.         $this->load->database();
  11.         $this->load->helper(array(
  12.             'url',
  13.             'security'
  14.         ));
  15.         $this->load->model('tutoriel_model');
  16.        
  17.         $this->load->model('commentaire_model');
  18.        
  19.     }
  20.    
  21.  
  22.     public function ecrire()
  23.     {
  24.        
  25.         $this->load->library('form_validation');
  26.        
  27.         $this->form_validation->set_rules('g-recaptcha-response', 'recaptcha validation', 'required|callback_validate_captcha');
  28.         $this->form_validation->set_message('validate_captcha', 'Please check the the captcha form');
  29.        
  30.         $this->form_validation->set_error_delimiters('<p class="form_erreur">', '</p>');
  31.        
  32.         $this->form_validation->set_rules('pseudo', '"Pseudo"', 'trim|required|min_length[3]|max_length[25]|alpha_dash|xss_clean');
  33.         $this->form_validation->set_rules('contenu', '"Contenu"', 'trim|required|min_length[3]|max_length[3000]|xss_clean');
  34.         $this->form_validation->set_rules('id_tuto', '"id_tuto"', 'trim|required|xss_clean');
  35.        
  36.            
  37.             if ($this->form_validation->run()) {
  38.              $data['title'] = "Ecrire commentaire";
  39.                 $this->commentaire_model->ajouter_commentaire($this->input->post('pseudo'), $this->input->post('contenu'), $this->input->post('id_tuto'));
  40.                
  41.                 redirect('home/index');
  42.             } else {
  43.                 $data ['title'] = 'Ecrire commentaire ';
  44.                 $this->load->view('common/header', $data);
  45.                 $this->load->view('common/nav');
  46.                 $this->load->view('commentaires/ecrire', $data);
  47.                 echo 'erreur';
  48.                
  49.             }
  50.         }
  51.  
  52.    
  53.     function validate_captcha()
  54.     {
  55.         $recaptcha = trim($this->input->post('g-recaptcha-response'));
  56.         $userIp    = $this->input->ip_address();
  57.         $secret    = '6LeOoSMUAAAAAFkaazrhAVMdoCLGx1Ne6Q5awFQa';
  58.         $data      = array(
  59.             'secret' => "$secret",
  60.             'response' => "$recaptcha",
  61.             'remoteip' => "$userIp"
  62.         );
  63.        
  64.         $verify = curl_init();
  65.         curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
  66.         curl_setopt($verify, CURLOPT_POST, true);
  67.         curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
  68.         curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
  69.         curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
  70.         $response = curl_exec($verify);
  71.         $status   = json_decode($response, true);
  72.         if (empty($status['success'])) {
  73.             return FALSE;
  74.         } else {
  75.             return TRUE;
  76.         }
  77.     }
  78.    
  79.    //  public function suppression($id_commentaire = NULL)
  80.    //  {
  81.    //      if (!$this->auth_user->is_connected) {
  82.    //          redirect('home/index');
  83.    //      }
  84.    //      if (!is_numeric($id_commentaire)) {
  85.    //          redirect('home/index');
  86.    //      }
  87.        
  88.        
  89.      
  90.    //      if ($this->input->post('confirm') === NULL) {
  91.    //          $data['action'] = "confirm";
  92.    //      } else {
  93.    //          $this->commentaire_model->delete_comment($id_commentaire);
  94.    //          $data['action'] = "result";
  95.    //      }
  96.    //      $data['title'] = "Suppression commentaire";
  97.    //      $this->load->helper('form');
  98.        
  99.    //      $this->load->view('dashboard/header_admin', $data);
  100.    //      $this->load->view('blog/delete_comment', $data);
  101.    //  }
  102.    
  103.    // public function validate_comment($id_commentaire)
  104.    //  {
  105.    //      $this->load->model('commentaire_model');
  106.    //      $this->commentaire_model->validate_comment($id_commentaire);
  107.        
  108.  
  109.        
  110.    //      $this->load->view('common/header', $data);
  111.    //      $this->load->view('commentaires/validate_comment', $data);
  112.    //  }
  113.  
  114.    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement