Esempio n. 1
0
function statusnet_fetchtimeline($a, $uid)
{
    $ckey = get_pconfig($uid, 'statusnet', 'consumerkey');
    $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
    $api = get_pconfig($uid, 'statusnet', 'baseapi');
    $otoken = get_pconfig($uid, 'statusnet', 'oauthtoken');
    $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
    $lastid = get_pconfig($uid, 'statusnet', 'lastid');
    //  get the application name for the SN app
    //  1st try personal config, then system config and fallback to the
    //  hostname of the node if neither one is set.
    $application_name = get_pconfig($uid, 'statusnet', 'application_name');
    if ($application_name == "") {
        $application_name = get_config('statusnet', 'application_name');
    }
    if ($application_name == "") {
        $application_name = App::get_hostname();
    }
    $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
    $parameters = array("exclude_replies" => true, "trim_user" => true, "contributor_details" => false, "include_rts" => false);
    $first_time = $lastid == "";
    if ($lastid != "") {
        $parameters["since_id"] = $lastid;
    }
    $items = $connection->get('statuses/user_timeline', $parameters);
    if (!is_array($items)) {
        return;
    }
    $posts = array_reverse($items);
    if (count($posts)) {
        foreach ($posts as $post) {
            if ($post->id > $lastid) {
                $lastid = $post->id;
            }
            if ($first_time) {
                continue;
            }
            if (is_object($post->retweeted_status)) {
                continue;
            }
            if ($post->in_reply_to_status_id != "") {
                continue;
            }
            if (!strpos($post->source, $application_name)) {
                $_REQUEST["type"] = "wall";
                $_REQUEST["api_source"] = true;
                $_REQUEST["profile_uid"] = $uid;
                $_REQUEST["source"] = "StatusNet";
                //$_REQUEST["date"] = $post->created_at;
                $_REQUEST["body"] = $post->text;
                if (is_string($post->place->name)) {
                    $_REQUEST["location"] = $post->place->name;
                }
                if (is_string($post->place->full_name)) {
                    $_REQUEST["location"] = $post->place->full_name;
                }
                if (is_array($post->geo->coordinates)) {
                    $_REQUEST["coord"] = $post->geo->coordinates[0] . " " . $post->geo->coordinates[1];
                }
                if (is_array($post->coordinates->coordinates)) {
                    $_REQUEST["coord"] = $post->coordinates->coordinates[1] . " " . $post->coordinates->coordinates[0];
                }
                //print_r($_REQUEST);
                if ($_REQUEST["body"] != "") {
                    logger('statusnet: posting for user ' . $uid);
                    $mod = new Zotlabs\Module\Item();
                    $mod->post();
                }
            }
        }
    }
    set_pconfig($uid, 'statusnet', 'lastid', $lastid);
}
Esempio n. 2
0
/**
 * 
 */
function api_statuses_repeat($a, $type)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // params
    $id = intval(argv(3));
    logger('API: api_statuses_repeat: ' . $id);
    //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
    $observer = App::get_observer();
    $item_normal = item_normal();
    $r = q("SELECT * from item where and id = %d {$item_normal} limit 1", intval($id));
    if (perm_is_allowed($r[0]['uid'], $observer['xchan_hash'], 'view_stream')) {
        if ($r[0]['body'] != "") {
            $_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . "[zrl=" . $r[0]['reply_url'] . "]" . $r[0]['reply_author'] . "[/zrl] \n" . $r[0]['body'];
            $_REQUEST['profile_uid'] = api_user();
            $_REQUEST['type'] = 'wall';
            $_REQUEST['api_source'] = true;
            $mod = new Zotlabs\Module\Item();
            $mod->post();
        }
    } else {
        return false;
    }
    if ($type == 'xml') {
        $ok = "true";
    } else {
        $ok = "ok";
    }
    return api_apply_template('test', $type, array('$ok' => $ok));
}