コード例 #1
0
ファイル: twitter-commentsync.php プロジェクト: robkaper/kiki
                }
                $tweets[$tweet->id] = $tweet;
                $maxId = $tweet->id - 1;
                // Tweet already known? No need to get more.
                if (isset($replyObjectIds[$tweet->id])) {
                    $getMore = false;
                }
            }
        }
    }
}
ksort($tweets, SORT_NUMERIC);
foreach ($tweets as $id => $tweet) {
    if ($storePublicationsAsComment && isset($objectIds[$tweet->id]) || isset($objectIds[$tweet->in_reply_to_status_id]) || isset($replyObjectIds[$tweet->in_reply_to_status_id])) {
        $twUser = User\Factory::getInstance('Twitter', $tweet->user->id);
        $localUser = ObjectCache::getByType('Kiki\\User', $twUser->kikiUserId());
        if (!$twUser->id()) {
            $twUser->setName($tweet->user->name);
            $twUser->setScreenName($tweet->user->screen_name);
            $twUser->setPicture($tweet->user->profile_image_url_https);
            $twUser->link($localUser->id());
        }
        $ctime = strtotime($tweet->created_at);
        // Object ID for publications
        $objectId = $storePublicationsAsComment && isset($objectIds[$tweet->id]) ? $objectIds[$tweet->id] : 0;
        // Object ID for replies to publications
        if (!$objectId) {
            $objectId = isset($objectIds[$tweet->in_reply_to_status_id]) ? $objectIds[$tweet->in_reply_to_status_id] : 0;
        }
        // Object ID for replies to replies
        if (!$objectId) {
コード例 #2
0
            $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) {
            list($uid, $postId) = explode("_", $like['post_id']);
            $objectId = isset($objectIds[$postId]) ? $objectIds[$postId] : 0;
            $fbUser = User\Factory::getInstance('User_Facebook', $like['user_id']);
            $localUser = ObjectCache::getByType('User', $fbUser->kikiUserId());
            if (!$fbUser->id()) {
                $fbUser->loadRemoteData($apiUser->api());
                $fbUser->link(0);
            }
            $q = "INSERT INTO likes (object_id, user_connection_id,ctime) VALUES({$objectId}, " . $fbUser->id() . ",now()) on duplicate key UPDATE user_connection_id=" . $fbUser->id();
            $rsLike = $db->query($q);
            if ($db->affectedRows($rs) == 1) {
                $object = ObjectCache::get($objectId);
                $label = method_exists($object, 'title') ? $object->title() : null;
                printf("%s likes %s %d (%s)" . PHP_EOL, $fbUser->name(), $object->type(), $objectId, $label);
            }
        }
    }
}