git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

apiuserfriends.php 2.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Show a user's friends (subscriptions)
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  API
 * @package   StatusNet
Zach Copley's avatar
Zach Copley committed
24 25
 * @author    Dan Moore <dan@moore.cx>
 * @author    Evan Prodromou <evan@status.net>
26 27 28 29 30 31
 * @author    Zach Copley <zach@status.net>
 * @copyright 2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

32
if (!defined('GNUSOCIAL')) { exit(1); }
33 34 35 36 37 38 39 40

/**
 * Ouputs the authenticating user's friends (subscriptions), each with
 * current Twitter-style status inline.  They are ordered by the date
 * in which the user subscribed to them, 100 at a time.
 *
 * @category API
 * @package  StatusNet
Zach Copley's avatar
Zach Copley committed
41 42
 * @author   Dan Moore <dan@moore.cx>
 * @author   Evan Prodromou <evan@status.net>
43 44 45 46
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
47
class ApiUserFriendsAction extends ApiSubscriptionsAction
48 49 50 51 52 53
{
    /**
     * Get the user's subscriptions (friends) as an array of profiles
     *
     * @return array Profiles
     */
54
    protected function getProfiles()
55 56 57 58 59 60 61
    {
        $offset = ($this->page - 1) * $this->count;
        $limit =  $this->count + 1;

        $subs = null;

        if (isset($this->tag)) {
62
            $subs = $this->target->getTaggedSubscriptions(
63 64 65
                $this->tag, $offset, $limit
            );
        } else {
66
            $subs = $this->target->getSubscribed(
67 68 69 70 71 72 73
                $offset,
                $limit
            );
        }

        $profiles = array();

74 75
        while ($subs->fetch()) {
            $profiles[] = clone($subs);
76 77 78 79 80
        }

        return $profiles;
    }
}