Esempio n. 1
0
#!/usr/bin/php -q
<?php 
use Kiki\User;
use OAuthException;
$_SERVER['SERVER_NAME'] = isset($argv[1]) ? $argv[1] : die('SERVER_NAME argument missing' . PHP_EOL);
require_once preg_replace('~/bin/(.*)\\.php~', '/lib/init.php', __FILE__);
// TODO: make admin check, assume all admins have working connections capable of acting as apiUser in TwitterConnectionService->getApiUsers()
$q = $db->buildQuery("SELECT DISTINCT connection_id as id FROM publications p LEFT JOIN connections c ON c.external_id=p.connection_id WHERE c.service='%s' OR c.service='%s' OR c.service='%s' LIMIT 1", 'User_Twitter', 'Twitter', 'Kiki\\User\\Twitter');
$apiConnectionId = $db->getSingleValue($q);
$apiUser = User\Factory::getInstance('Twitter', $apiConnectionId);
$q = $db->buildQuery("SELECT DISTINCT external_id AS id FROM connections WHERE service='%s' OR service='%s' OR service='%s'", 'User_Twitter', 'Twitter', 'Kiki\\User\\Twitter');
$connectionIds = $db->getObjectIds($q);
$chunks = array_chunk($connectionIds, 100);
foreach ($chunks as $chunk) {
    $rs = $apiUser->api()->get("users/lookup", array("user_id" => implode(",", $chunk)));
    foreach ($rs as $rsUser) {
        // echo "$rsUser->id / $rsUser->name / $rsUser->screen_name / $rsUser->profile_image_url_https". PHP_EOL;
        $twUser = User\Factory::getInstance('Twitter', $rsUser->id);
        $twUser->setName($rsUser->name);
        $twUser->setScreenName($rsUser->screen_name);
        $twUser->setPicture($rsUser->profile_image_url_https);
        $twUser->link();
    }
}
Esempio n. 2
0
                    continue;
                }
                $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
Esempio n. 3
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);
            }
        }
    }
}