/**
  * insert comment with commnet type is class property $this->comment_type
  # @use wp_insert_comment
  # $args same with wp_insert_comment args
  * @return Object wp_error | comment object
 */
 public function insert($args)
 {
     global $current_user, $user_ID;
     // current user can not review for himself
     if (is_wp_error($post = get_post($args['comment_post_ID']))) {
         return $post;
     }
     if ($this->limit_time) {
         $time = $this->limit_time;
         // review comment not too fast, should after 3 or 5 minute to post next review
         $comments = get_comments(array('type' => '', 'author_email' => $current_user->user_email, 'number' => 1));
         if (!empty($comments)) {
             // check latest comment
             $comment = $comments[0];
             $date = $comment->comment_date_gmt;
             $ago = time() - strtotime($date);
             //return error if comment to fast
             if ($ago < (int) $time) {
                 return new WP_Error('fast_review', __("Please wait 2 minutes after each action submission.", 'aecore-class-ae-comments-backend'));
             }
         }
     }
     // set comment type
     $args['type'] = $this->comment_type;
     // donot allow duplication comment on a post
     if (!$this->duplicate) {
         $comments = get_comments(array('post_id' => $post->ID, 'type' => $args['type'], 'author_email' => $current_user->user_email, 'number' => 1));
         if (!empty($comments)) {
             if (isset($args['type'])) {
                 return new WP_Error('duplication', __("Already added.", 'aecore-class-ae-comments-backend'));
             } else {
                 return new WP_Error('duplicationde', __("You have already comment on this.", 'aecore-class-ae-comments-backend'));
             }
         }
     }
     unset($args['comment_author']);
     // try add review
     try {
         $browser = ae_getBrowser();
         $commentdata = wp_parse_args($args, array('comment_post_ID' => $post->ID, 'comment_author' => $current_user->user_login, 'comment_author_email' => $current_user->user_email, 'comment_author_url' => 'http://', 'comment_content' => $args['comment_content'], 'comment_type' => $args['type'], 'comment_parent' => 0, 'user_id' => $user_ID, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => $browser['userAgent'], 'comment_approved' => isset($args['comment_approved']) ? $args['comment_approved'] : 0, 'attitude' => 'pos'));
         $commentdata = apply_filters('ae_filter_data_' . $args['type'], $commentdata);
         /**
          * insert review to database
          */
         $comment = wp_insert_comment($commentdata);
         if (!is_wp_error($comment)) {
             // update comment meta
             if (!empty($this->meta)) {
                 foreach ($this->meta as $key => $value) {
                     if (isset($commentdata[$key])) {
                         update_comment_meta($comment, $key, $commentdata[$key]);
                     }
                 }
             }
             // do action after insert a comment with type args
             do_action('ae_after_insert_' . $args['type'], $comment);
             // return comment data
             return $comment;
         } else {
             throw new Exception($comment->get_error_message());
         }
     } catch (Exception $e) {
         return new WP_Error('add_review_error', $e->getMessage());
     }
 }
Beispiel #2
0
function ae_block_ie($version, $page)
{
    $info = ae_getBrowser();
    //if ( $info['name'] == 'Internet Explorer' && version_compare($version, $info['version'], '>=') && file_exists(TEMPLATEPATH . '/' . $page)){
    if (!is_page_template('page-unsupported.php')) {
        // find a template "unsupported"
        // If template doesn't existed, create it
        ?>
            <script type="text/javascript">
                var detectBrowser = function () {

                    var isOpera = this.check(/opera/);
                    var isIE = !isOpera && check(/msie/);
                    var isIE8 = isIE && check(/msie 8/);
                    var isIE7 = isIE && check(/msie 7/);
                    var isIE6 = isIE && check(/msie 6/);

                    if( ( isIE6 || isIE7 || isIE8 )  ) window.location   =   '<?php 
        echo et_get_page_link("unsupported");
        ?>
';
                }

                var check  = function (r) {
                    var ua = navigator.userAgent.toLowerCase();
                    return r.test(ua);
                }
                detectBrowser();

            </script>

            <?php 
    }
}