Changyan_Synchronizer::sync2Wordpress PHP Method

sync2Wordpress() public method

public sync2Wordpress ( )
    public function sync2Wordpress()
    {
        global $zbp;
        @set_time_limit(0);
        if (function_exists('ini_set')) {
            ini_set('memory_limit', '256M');
        }
        $script = $this->getOption('changyan_script');
        $appID = explode("'", $script);
        //Now we get the appID from the script
        $appID = $appID[1];
        //not site_url: the folder of wp installed, see http://www.andelse.com/wordpress-url-strategy-url-function-list.html
        //echo "<br/>".home_url();//it is right
        //get post list from
        $nextID2CY = (int) $this->getOption('changyan_sync2CY');
        $nextID2WP = (int) $this->getOption('changyan_sync2WP');
        $cmt = $zbp->GetCommentByID($nextID2WP);
        date_default_timezone_set('Etc/GMT-8');
        if ($cmt->ID == 0) {
            $time = date("Y-m-d H:i:s", 0);
        } else {
            $time = date("Y-m-d H:i:s", $cmt->PostTime);
        }
        date_default_timezone_set($zbp->option['ZC_TIME_ZONE_NAME']);
        $params = array('appId' => $appID, 'date' => $time);
        $URL = "http://changyan.sohu.com/admin/api/recent-comment-topics";
        $URL = $this->buildURL($params, $URL);
        $data = $this->getContents_curl($URL);
        $data = json_decode($data);
        if (empty($data->success)) {
            die("同步失败:服务器返回空值");
        }
        if ('false' === $data->success) {
            die("同步失败:" . $data->success);
        }
        $postGroup = $data->topics;
        //die(var_dump($postGroup));
        $lastCommentID = $this->getOption('changyan_sync2WP');
        if (empty($lastCommentID)) {
            $lastCommentID = 0;
        }
        foreach ($postGroup as $aPost) {
            $cyanCommentList = $this->getCommentList_curl($appID, $aPost->topic_id);
            $commentID = $this->insertComments($cyanCommentList, $aPost->topic_source_id);
            if ($commentID > $lastCommentID) {
                $lastCommentID = $commentID;
            }
            //recode the latest synchronization time
            $this->setOption('changyan_lastSyncTime', time());
            $this->setOption('changyan_sync2WP', $lastCommentID);
        }
        die("同步成功");
    }