Пример #1
0
 function denglu_exportComment_ajax($start = 0)
 {
     @ini_set("max_execution_time", 300);
     if (function_exists('import_comments_to_denglu')) {
         $data = import_comments_to_denglu();
     } else {
         return var_dump("请先在评论设置勾选开启“社会化评论”功能。");
     }
     // $data = array_slice(range(1,605), $start, 50, true);
     // sleep(1);
     // return var_dump($data);
     if ($data) {
         $wptm_basic = get_option('wptm_basic');
         $data = json_encode($data);
         class_exists('Denglu') or (require dirname(__FILE__) . "/class/Denglu.php");
         $api = new Denglu($wptm_basic['appid'], $wptm_basic['appkey'], 'utf-8');
         try {
             $comments = $api->importComment($data);
         } catch (DengluException $e) {
             // 获取异常后的处理办法(请自定义)
             // wp_die($e -> geterrorDescription()); //返回错误信息
             echo $e->geterrorDescription();
             return;
         }
         // return var_dump($comments);
         if ($comments && is_array($comments)) {
             foreach ($comments as $comment) {
                 if ($comment['id']) {
                     wp_update_comment_agent($comment['comment_ID'], $comment['id']);
                 }
                 if (is_array($comment['children'])) {
                     foreach ($comment['children'] as $children) {
                         if ($children['id']) {
                             wp_update_comment_agent($children['comment_ID'], $children['id']);
                         }
                     }
                 }
             }
             echo count($comments) + $start;
             //继续
         }
     } else {
         echo 'success';
         //成功
     }
 }
Пример #2
0
 function denglu_importReplyComment($comment_id, $comment)
 {
     if ($comment->comment_approved != 1 || $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' || $comment->comment_parent == 0 || strpos($comment->comment_agent, 'Denglu_') !== false) {
         return $comment_id;
     }
     $get_dlCommentID = get_dengluCommentID($comment->comment_parent);
     if ($get_dlCommentID) {
         $comment = array('comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_author' => $comment->comment_author, 'comment_author_email' => $comment->comment_author_email, 'comment_author_url' => $comment->comment_author_url, 'comment_author_IP' => $comment->comment_author_IP, 'comment_date' => $comment->comment_date, 'comment_content' => $comment->comment_content, 'comment_parent' => $comment->comment_parent, 'user_id' => $comment->user_id);
         if ($comment['user_id']) {
             if ($tid = get_usertid($comment['comment_author_email'], $comment['user_id'])) {
                 $user = get_row_userinfo($comment['user_id'], $tid);
                 if (is_array($user)) {
                     $comment = array_merge($user, $comment);
                 }
             }
         }
         $data[] = array('cid' => $get_dlCommentID, 'children' => array($comment));
         $data = json_encode($data);
         class_exists('Denglu') or (require dirname(__FILE__) . "/class/Denglu.php");
         global $wptm_basic;
         $api = new Denglu($wptm_basic['appid'], $wptm_basic['appkey'], 'utf-8');
         try {
             $comments = $api->importComment($data);
         } catch (DengluException $e) {
             // 获取异常后的处理办法(请自定义)
         }
         // return var_dump($comments);
         if (is_array($comments)) {
             foreach ($comments as $comment) {
                 if (is_array($comment['children'])) {
                     foreach ($comment['children'] as $children) {
                         if ($children['id']) {
                             wp_update_comment_agent($children['comment_ID'], $children['id']);
                         }
                     }
                 }
             }
         }
     }
 }