Advertisement
InerciaCreativa

Soporte de Akistmet en cforms

Oct 17th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.70 KB | None | 0 0
  1. <?php
  2. /* Incluir en functions.php */
  3.  
  4. function my_cforms_filter($params)
  5. {
  6.     if (!function_exists('akismet_get_key') || !akismet_get_key()) {
  7.         return $params;
  8.     }
  9.  
  10.     /* $params es la variable global $_POST. */
  11.     /* Modifica la llamada a my_cforms_akismet() si es necesario con los campos adecuados. */
  12.     if (my_cforms_akismet($params['cf_field_1'], $params['cf_field_2'], $params['cf_field_3'], $params['cf_field_4'])) {
  13.         /* Esto causa que la página no se termine de componer, pero no hay otra manera. */
  14.         /* Agradéceselo a Oliver Seidel, autor del plugin. */
  15.         exit('Spam detectado...');
  16.     }
  17.  
  18.     return $params;
  19. }
  20.  
  21. function my_cforms_ajax_filter($params)
  22. {
  23.     if (!function_exists('akismet_get_key') || !akismet_get_key()) {
  24.         return $params;
  25.     }
  26.  
  27.     /* $params contiene los campos del formulario en el orden establecido durante su creación. */
  28.     /* Modifica la llamada a my_cforms_akismet() si es necesario con los campos adecuados. */
  29.     if (my_cforms_akismet($params['field_1'], $params['field_2'], $params['field_3'], $params['field_4'])) {
  30.         header ('Content-Type: text/javascript');
  31.         header ('X-Content-Type-Options: nosniff');
  32.         header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  33.         header ('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
  34.         header ('Cache-Control: no-cache, must-revalidate');
  35.         header ('Pragma: no-cache');
  36.  
  37.         exit('+:var res = ' . (trim(sajax_get_js_repr('1*$#nSpam detectado...'))) . '; res;');
  38.     }
  39.  
  40.     return $params;
  41. }
  42.  
  43. function my_cforms_akismet($author, $email, $url, $content)
  44. {
  45.     global $akismet_api_host, $akismet_api_port;
  46.  
  47.     $comment = array(
  48.         'blog'                 => get_option('home'),
  49.         'blog_lang'            => get_locale(),
  50.         'blog_charset'         => get_option('blog_charset'),
  51.         'user_ip'              => $_SERVER['REMOTE_ADDR'],
  52.         'user_agent'           => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null,
  53.         'referrer'             => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null,
  54.         'comment_type'         => 'contact-form',
  55.         'comment_author'       => $author,
  56.         'comment_author_email' => $email,
  57.         'comment_author_url'   => $url,
  58.         'comment_content'      => $content
  59.     );
  60.  
  61.     $query_string = '';
  62.  
  63.     foreach ($comment as $key => $data) {
  64.         $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
  65.     }
  66.  
  67.     $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
  68.     if ('true' == $response[1]) {
  69.         return true;
  70.     }
  71.  
  72.     return false;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement