Example #1
0
/**
 * @brief
 *
 * @param array $channel
 * @param string $observer_hash
 * @param array $params
 * @return string
 */
function get_feed_for($channel, $observer_hash, $params)
{
    if (!channel) {
        http_status_exit(401);
    }
    if ($params['pages']) {
        if (!perm_is_allowed($channel['channel_id'], $observer_hash, 'view_pages')) {
            http_status_exit(403);
        }
    } else {
        if (!perm_is_allowed($channel['channel_id'], $observer_hash, 'view_stream')) {
            http_status_exit(403);
        }
    }
    $items = items_fetch(array('wall' => '1', 'datequery' => $params['end'], 'datequery2' => $params['begin'], 'start' => $params['start'], 'records' => $params['records'], 'direction' => $params['direction'], 'pages' => $params['pages'], 'order' => 'post', 'top' => $params['top'], 'cat' => $params['cat']), $channel, $observer_hash, CLIENT_MODE_NORMAL, App::$module);
    $feed_template = get_markup_template('atom_feed.tpl');
    $atom = '';
    $atom .= replace_macros($feed_template, array('$version' => xmlify(Zotlabs\Lib\System::get_project_version()), '$red' => xmlify(Zotlabs\Lib\System::get_platform_name()), '$feed_id' => xmlify($channel['xchan_url']), '$feed_title' => xmlify($channel['channel_name']), '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ATOM_TIME)), '$hub' => '', '$salmon' => '', '$name' => xmlify($channel['channel_name']), '$profile_page' => xmlify($channel['xchan_url']), '$mimephoto' => xmlify($channel['xchan_photo_mimetype']), '$photo' => xmlify($channel['xchan_photo_l']), '$thumb' => xmlify($channel['xchan_photo_m']), '$picdate' => '', '$uridate' => '', '$namdate' => '', '$birthday' => '', '$community' => ''));
    call_hooks('atom_feed', $atom);
    if ($items) {
        $type = 'html';
        foreach ($items as $item) {
            if ($item['item_private']) {
                continue;
            }
            /** @BUG $owner is undefined in this call */
            $atom .= atom_entry($item, $type, null, $owner, true);
        }
    }
    call_hooks('atom_feed_end', $atom);
    $atom .= '</feed>' . "\r\n";
    return $atom;
}
Example #2
0
function api_statuses_user_timeline(&$a, $type)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // get last network messages
    logger("api_statuses_user_timeline: api_user: "******"\nuser_info: " . print_r($user_info, true) . "\n_REQUEST:  " . print_r($_REQUEST, true), LOGGER_DEBUG);
    // 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;
    $exclude_replies = x($_REQUEST, 'exclude_replies') ? 1 : 0;
    //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
    $start = $page * $count;
    $sql_extra = '';
    if ($user_info['self'] == 1) {
        $sql_extra .= " AND `item`.`wall` = 1 ";
    }
    //FIXME - this isn't yet implemented
    if ($exclude_replies > 0) {
        $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
    }
    // 	$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
    // 			`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
    // 			`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
    // 			`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
    // 			FROM `item`, `contact`
    // 			WHERE `item`.`uid` = %d
    // 			AND `item`.`contact-id` = %d
    // 			AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
    // 			AND `contact`.`id` = `item`.`contact-id`
    // 			AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
    // 			$sql_extra
    // 			AND `item`.`id`>%d
    // 			ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
    // 			intval(api_user()),
    // 			intval($user_info['id']),
    // 			intval($since_id),
    // 			intval($start),	intval($count)
    // 		);
    $arr = array('uid' => api_user(), 'since_id' => $since_id, 'start' => $start, 'records' => $count);
    if ($user_info['self'] == 1) {
        $arr['wall'] = 1;
    } else {
        $arr['cid'] = $user_info['id'];
    }
    $r = items_fetch($arr, get_app()->get_channel(), get_observer_hash());
    $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);
}