当前位置: 首页>>代码示例>>PHP>>正文


PHP Akismet::init方法代码示例

本文整理汇总了PHP中Akismet::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Akismet::init方法的具体用法?PHP Akismet::init怎么用?PHP Akismet::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Akismet的用法示例。


在下文中一共展示了Akismet::init方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: view

 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = false)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports_view');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     if (!$id) {
         url::redirect('main');
     } else {
         $incident = ORM::factory('incident', $id);
         if ($incident->id == 0) {
             url::redirect('main');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('comment_author', 'required', 'length[3,100]');
             $post->add_rules('comment_description', 'required');
             $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // comment data
                     $comment = array('author' => $post->comment_author, 'email' => $post->comment_email, 'website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         // If the server is down, we have to post
                         // the comment :(
                         // $this->_post_comment($comment);
                         $comment_spam = 0;
                     } else {
                         if ($akismet->is_spam()) {
                             $comment_spam = 1;
                         } else {
                             $comment_spam = 0;
                         }
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = $id;
                 $comment->comment_author = strip_tags($post->comment_author);
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_email = strip_tags($post->comment_email);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = 1;
                 }
                 $comment->save();
                 // Notify Admin Of New Comment
                 $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $id);
                 // Redirect
                 url::redirect('reports/view/' . $id);
             } else {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('comments'));
                 $form_error = TRUE;
             }
         }
         $this->template->content->incident_id = $incident->id;
         $this->template->content->incident_title = $incident->incident_title;
         $this->template->content->incident_description = nl2br($incident->incident_description);
         $this->template->content->incident_location = $incident->location->location_name;
//.........这里部分代码省略.........
开发者ID:kiirti,项目名称:Ushahidi_MHI,代码行数:101,代码来源:reports.php

示例2: _add_comment

 /**
  * Submit comments
  *
  * @return int
  */
 private function _add_comment()
 {
     $api_akismet = Kohana::config('settings.api_akismet');
     // Comment Post?
     // Setup and initialize form field names
     $form = array('incident_id' => '', 'comment_author' => '', 'comment_description' => '', 'comment_email' => '');
     $captcha = Captcha::factory();
     $errors = $form;
     $form_error = FALSE;
     $ret_value = 0;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST and Kohana::config('settings.allow_comments')) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('incident_id', 'required');
         $post->add_rules('comment_author', 'required', 'length[3,100]');
         $post->add_rules('comment_description', 'required');
         $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $incident = ORM::factory('incident')->where('id', $post->incident_id)->where('incident_active', 1)->find();
             if ($incident->id == 0) {
                 return $this->response(1, "No incidents with that ID");
             }
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // Comment data
                 $comment = array('author' => $post->comment_author, 'email' => $post->comment_email, 'website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $comment_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $comment_spam = 1;
                     } else {
                         $comment_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $comment_spam = 0;
             }
             $comment = new Comment_Model();
             $comment->incident_id = strip_tags($post->incident_id);
             $comment->comment_author = strip_tags($post->comment_author);
             $comment->comment_description = strip_tags($post->comment_description);
             $comment->comment_email = strip_tags($post->comment_email);
             $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
             $comment->comment_date = date("Y-m-d H:i:s", time());
             // Activate comment for now
             if ($comment_spam == 1) {
                 $comment->comment_spam = 1;
                 $comment->comment_active = 0;
             } else {
                 $comment->comment_spam = 0;
                 if (Kohana::config('settings.allow_comments') == 1) {
                     // Auto Approve
                     $comment->comment_active = 1;
                 } else {
                     // Manually Approve
                     $comment->comment_active = 0;
                 }
             }
             $comment->save();
             // Notify Admin Of New Comment
             $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $post->incident_id);
         } else {
             // No! We have validation errors, we need to show the form again, with the errors
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('comments'));
             foreach ($errors as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($errors)) {
                         $this->error_messages .= " - ";
                     }
                 }
//.........这里部分代码省略.........
开发者ID:kh411d,项目名称:Ushahidi_Web,代码行数:101,代码来源:MY_Comments_Api_Object.php

示例3: _get_feedback_form

 /**
  * Get the feedback
  */
 private function _get_feedback_form()
 {
     //setup and initialize form fields
     $form = array('feedback_message' => '', 'person_email' => '', 'feedback_captcha' => '');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     $captcha = Captcha::factory();
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     //has form been submitted, if so setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //Trim whitespaces
         $post->pre_filter('trim', TRUE);
         //Add validation rules
         $post->add_rules('feedback_message', 'required');
         $post->add_rules('person_email', 'required', 'email');
         $post->add_rules('feedback_captcha', 'required', 'Captcha::valid');
         if ($post->validate()) {
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // comment data
                 $feedback = array('feedback_message' => $post->feedback_message, 'person_email' => $post->feedback_message);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'feedback' => $feedback);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $feedback_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $feedback_spam = 1;
                     } else {
                         $feedback_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $feedback_spam = 0;
             }
             $this->_dump_feedback($post);
             //send details to admin
             $frm = $post->person_email;
             $subject = Kohana::lang('feedback.feedback_details');
             $message = $post->feedback_message;
             $email = Kohana::config('settings.site_email');
             $this->_send_feedback($email, $message, $subject, $frm);
             //send details to ushahidi
             $frm = $post->person_email;
             $subject = Kohana::lang('feedback.feedback_details');
             $message = $post->feedback_message;
             $message .= "Instance: " . url::base();
             $email = "feedback@ushahidi.com";
             $this->_send_feedback($email, $message, $subject, $frm);
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feedback'));
             $form_error = TRUE;
         }
     }
     $this->template->footer->js = new View('footer_form_js');
     $this->template->footer->form = $form;
     $this->template->footer->captcha = $captcha;
     $this->template->footer->errors = $errors;
     $this->template->footer->form_error = $form_error;
 }
开发者ID:eyedol,项目名称:agbena,代码行数:81,代码来源:jobsmain.php

示例4: view

 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = FALSE)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports/detail');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     // Sanitize the report id before proceeding
     $id = intval($id);
     if ($id > 0) {
         $incident = ORM::factory('sharing_incident')->where('id', $id)->where('incident_active', 1)->find();
         // Not Found
         if (!$incident->loaded) {
             url::redirect('reports/');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST and Kohana::config('settings.allow_comments')) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             if (!$this->user) {
                 $post->add_rules('comment_author', 'required', 'length[3,100]');
                 $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             }
             $post->add_rules('comment_description', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // Comment data
                     $comment = array('website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     if ($this->user) {
                         $comment['author'] = $this->user->name;
                         $comment['email'] = $this->user->email;
                     } else {
                         $comment['author'] = $post->comment_author;
                         $comment['email'] = $post->comment_email;
                     }
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         $comment_spam = 0;
                     } else {
                         $comment_spam = $akismet->is_spam() ? 1 : 0;
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = 0;
                 if ($this->user) {
                     $comment->user_id = $this->user->id;
                     $comment->comment_author = $this->user->name;
                     $comment->comment_email = $this->user->email;
                 } else {
                     $comment->comment_author = strip_tags($post->comment_author);
                     $comment->comment_email = strip_tags($post->comment_email);
                 }
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = Kohana::config('settings.allow_comments') == 1 ? 1 : 0;
                 }
                 $comment->save();
                 // link comment to sharing_incident
                 $incident_comment = ORM::factory('sharing_incident_comment');
                 $incident_comment->comment_id = $comment->id;
                 $incident_comment->sharing_incident_id = $incident->id;
                 $incident_comment->save();
                 // Event::comment_add - Added a New Comment
                 Event::run('ushahidi_action.comment_add', $comment);
//.........这里部分代码省略.........
开发者ID:rjmackay,项目名称:Ushahidi-plugin-sharing_two,代码行数:101,代码来源:sharing.php

示例5: _get_job_app_form

 private function _get_job_app_form()
 {
     $form = array('captcha' => '', 'contact_name' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_subject' => '', 'contact_message' => '', 'comment' => 'Submit', 'apply' => 'Apply');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     $captcha = Captcha::factory();
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     //has form been submitted, if so setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //Trim whitespaces
         $post->pre_filter('trim', TRUE);
         //Add validation rules
         $post->add_rules('contact_name', 'required', 'length[3,100]');
         $post->add_rules('contact_email', 'required', 'email', 'length[4,100]');
         $post->add_rules('contact_subject', 'required', 'length[3,100]');
         $post->add_rules('contact_message', 'required');
         $post->add_rules('captcha', 'required', 'Captcha::valid');
         if ($post->validate()) {
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // comment data
                 $jobapply = array('contact_name' => $post->contact_name, 'contact_email' => $post->contact_email, 'contact_subject' => $post->contact_subject, 'contact_message' => $post->contact_message);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'jobapply' => $jobapply);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $jobapply_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $jobapply_spam = 1;
                     } else {
                         $jobapply_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $feedback_spam = 0;
             }
             $this->_dump_feedback($post);
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feedback'));
             $form_error = TRUE;
         }
     }
     $this->template->footer->js = new View('footer_form_js');
     $this->template->footer->form = $form;
     $this->template->footer->captcha = $captcha;
     $this->template->footer->errors = $errors;
     $this->template->footer->form_error = $form_error;
 }
开发者ID:eyedol,项目名称:agbena,代码行数:66,代码来源:jobs.php


注:本文中的Akismet::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。