예제 #1
0
파일: facebook.php 프로젝트: TMBR/johnjohn
 public function get_posts()
 {
     $facebook_url = add_query_arg(array('access_token' => self::$appId . '|' . self::$appSecret), self::$endpoint . self::$username . '/feed/');
     $response = wp_remote_get($facebook_url);
     $r = json_decode(wp_remote_retrieve_body($response));
     if ($r) {
         foreach ($r->data as $_post) {
             $fbpost = new FBPost($_post);
             if (!$fbpost->is_valid()) {
                 error_log('The FB Social Post is not valid: ');
                 error_log(print_r($fbpost, 1));
                 continue;
             }
             $social_post = $fbpost->generate_socialpost();
             if (!$social_post->exists()) {
                 $social_post->save();
             } else {
             }
         }
     }
 }
$limit = $_GET["limit"];
$isClassifier = $_GET["isClassifier"];
if (!isset($_SESSION['client'])) {
    $_SESSION['client'] = new nusoap_client(getWsdlAddress(), true);
}
if (strlen($facebookquery) > 0) {
    $params = array('facebookquery' => $facebookquery, 'start_time' => $start_time, 'limit' => $limit, 'isClassifier' => $isClassifier);
    $test_xml_string = $_SESSION['client']->call("startSearchingFacebookPost", $params, const_namespace);
}
//file_put_contents("testfile.txt", $test_xml_string, FILE_APPEND | LOCK_EX);
$test_xml_string = cleanString($test_xml_string);
if (!simplexml_load_string($test_xml_string)) {
    $arrayPosts = array();
    array_push($arrayPosts, "error");
    echo json_encode($arrayPosts);
} else {
    //file_put_contents("testfile.txt", date("F j, Y, g:i a"), FILE_APPEND | LOCK_EX);
    //file_put_contents("testfile.txt", "\r\n", FILE_APPEND | LOCK_EX);
    $xml = simplexml_load_string($test_xml_string);
    $count = 0;
    $arrayPosts = array();
    foreach ($xml->children() as $tnum) {
        if ($tnum['postID'] != "") {
            $post = new FBPost();
            $post->initializeMembers($tnum);
            $arrayPosts[$count] = $post;
            $count++;
        }
    }
    echo json_encode($arrayPosts);
}