Example #1
0
        // Object ID for replies to replies
        if (!$objectId) {
            $objectId = isset($replyObjectIds[$tweet->in_reply_to_status_id]) ? $replyObjectIds[$tweet->in_reply_to_status_id] : 0;
        }
        $q = $db->buildQuery("SELECT id FROM connections WHERE external_id=%d", $twUser->externalId());
        $tweetConnectionId = $db->getSingleValue($q);
        // Find comment
        $q = $db->buildQuery("SELECT id FROM comments WHERE user_connection_id=%d AND external_id='%s'", $tweetConnectionId, $tweet->id);
        $commentId = $db->getSingleValue($q);
        if ($commentId) {
            continue;
        }
        // Store comment
        $comment = new Comment();
        $comment->setInReplyToId($objectId);
        $comment->setUserId($localUser->id());
        $comment->setConnectionId($tweetConnectionId);
        $comment->setExternalId($tweet->id);
        $comment->setBody($tweet->text);
        $comment->setCtime($ctime);
        $comment->save();
        // TODO: also store object_id, not doing so flattens all comments and all nesting/threading information is lost
        $replyObjectIds[$tweet->id] = $objectId ? $objectId : $comment->objectId();
        printf("%s commented on %d:%s%s%s", $twUser->name(), $objectId, PHP_EOL, $tweet->text, PHP_EOL . PHP_EOL);
    } else {
        if (isset($tweet->retweeted_status) && $tweet->user->id != $connectionId) {
            // TODO: store quoted retweet
            // echo "==== retweet ====". print_r($tweet,true). "==== end retweet ====". PHP_EOL;
        }
    }
}
Example #2
0
     $objectId = isset($objectIds[$postId]) ? $objectIds[$postId] : 0;
     $q = $db->buildQuery("SELECT id FROM connections WHERE external_id=%d", $fbUser->externalId());
     $connectionId = $db->getSingleValue($q);
     // Find comment
     $q = $db->buildQuery("SELECT id FROM comments WHERE user_connection_id=%d AND external_id='%s'", $connectionId, $externalId);
     $commentId = $db->getSingleValue($q);
     if ($commentId) {
         continue;
     }
     // Store comment
     $comment = new Comment();
     // TODO: support nested comments using $reply['parent_id']
     // (Facebook UI does not support that yet, but their post-July 2013 data model does.)
     $comment->setInReplyToId($objectId);
     $comment->setUserId($localUser->id());
     $comment->setConnectionId($connectionId);
     $comment->setExternalId($externalId);
     $comment->setBody($reply['text']);
     $comment->setCtime($ctime);
     $comment->save();
     $object = ObjectCache::get($objectId);
     $label = method_exists($object, 'title') ? $object->title() : null;
     printf("%s commented on %s %d (%s):%s%s%s", $fbUser->name(), $object->type(), $objectId, $label, PHP_EOL, $reply['text'], PHP_EOL . PHP_EOL);
 }
 // Get likes
 $q = "select post_id, user_id, object_id, object_type from like where post_id in ({$qPostIds})";
 $rs = $apiUser->api()->api('fql', 'get', array('q' => $q));
 if (!$rs || !isset($rs['data'])) {
     continue;
 }
 foreach ($rs['data'] as $like) {