예제 #1
0
파일: api.php 프로젝트: msooon/hubzilla
function api_favorites(&$a, $type)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // params
    $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 20;
    $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
    if ($page < 0) {
        $page = 0;
    }
    $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0;
    $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0;
    $exclude_replies = x($_REQUEST, 'exclude_replies') ? 1 : 0;
    $start = $page * $count;
    //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
    $sql_extra = '';
    if ($max_id > 0) {
        $sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
    }
    if ($exclude_replies > 0) {
        $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
    }
    if (api_user() != $user_info['uid']) {
        $observer = get_app()->get_observer();
        require_once 'include/permissions.php';
        if (!perm_is_allowed($user_info['uid'], $observer ? $observer['xchan_hash'] : '', 'view_stream')) {
            return '';
        }
        $sql_extra .= " and item_private = 0 ";
    }
    $item_normal = item_normal();
    $r = q("SELECT * from item WHERE uid = %d {$item_normal}\n\t\t\tand item_starred = 1 {$sql_extra}\n\t\t\tAND id > %d\n\t\t\tORDER BY received DESC LIMIT %d ,%d ", intval($user_info['uid']), intval($since_id), intval($start), intval($count));
    xchan_query($r, true);
    $ret = api_format_items($r, $user_info);
    $data = array('$statuses' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
            break;
        case "as":
            $as = api_format_as($a, $ret, $user_info);
            $as['title'] = $a->config['sitename'] . " Home Timeline";
            $as['link']['url'] = $a->get_baseurl() . "/" . $user_info["screen_name"] . "/all";
            return $as;
            break;
    }
    return api_apply_template("timeline", $type, $data);
}
예제 #2
0
function api_favorites(&$a, $type)
{
    global $called_api;
    if (api_user() === false) {
        return false;
    }
    $called_api = array();
    $user_info = api_get_user($a);
    // in friendica starred item are private
    // return favorites only for self
    logger('api_favorites: self:' . $user_info['self']);
    if ($user_info['self'] == 0) {
        $ret = array();
    } else {
        $sql_extra = "";
        // params
        $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0;
        $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0;
        $count = x($_GET, 'count') ? $_GET['count'] : 20;
        $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
        if ($page < 0) {
            $page = 0;
        }
        $start = $page * $count;
        if ($max_id > 0) {
            $sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
        }
        $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,\n\t\t\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,\n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\t\tFROM `item`, `contact`\n\t\t\t\tWHERE `item`.`uid` = %d\n\t\t\t\tAND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0\n\t\t\t\tAND `item`.`starred` = 1\n\t\t\t\tAND `contact`.`id` = `item`.`contact-id`\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\t{$sql_extra}\n\t\t\t\tAND `item`.`id`>%d\n\t\t\t\tORDER BY `item`.`id` DESC LIMIT %d ,%d ", intval(api_user()), intval($since_id), intval($start), intval($count));
        $ret = api_format_items($r, $user_info);
    }
    $data = array('$statuses' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
    }
    return api_apply_template("timeline", $type, $data);
}