function getSubscribers()
 {
     $subs = array();
     $sub = new Subscription();
     $sub->subscribed = $this->user->id;
     if ($sub->find()) {
         while ($sub->fetch()) {
             if ($sub->subscriber != $this->user->id) {
                 $subs[] = clone $sub;
             }
         }
     }
     return $subs;
 }
 function getSubscribers()
 {
     $subs = array();
     $sub = new Subscription();
     $sub->subscribed = $this->user->id;
     if (!empty($this->after)) {
         $sub->whereAdd("created > '" . common_sql_date($this->after) . "'");
     }
     if ($sub->find()) {
         while ($sub->fetch()) {
             if ($sub->subscriber != $this->user->id) {
                 $subs[] = clone $sub;
             }
         }
     }
     return $subs;
 }
Beispiel #3
0
 /**
  * Output FOAF <account> bit for the given profile.
  *
  * @param Profile $profile
  * @param mixed $service Root URL of this StatusNet instance for a local
  *                       user, otherwise null.
  * @param mixed $useruri URI string for the referenced profile..
  * @param boolean $fetchSubscriptions Should we load and list all their subscriptions?
  * @param boolean $isSubscriber if not fetching subs, we can still mark the user as following the current page.
  *
  * @return array if $fetchSubscribers is set, return a list of info on those
  *               subscriptions.
  */
 function showMicrobloggingAccount($profile, $service = null, $useruri = null, $fetchSubscriptions = false, $isSubscriber = false)
 {
     $attr = array();
     if ($useruri) {
         $attr['rdf:about'] = $useruri . '#acct';
     }
     // Their account
     $this->elementStart('account');
     $this->elementStart('OnlineAccount', $attr);
     if ($service) {
         $this->element('accountServiceHomepage', array('rdf:resource' => $service));
     }
     $this->element('accountName', null, $profile->nickname);
     $this->element('accountProfilePage', array('rdf:resource' => $profile->profileurl));
     if ($useruri) {
         $this->element('sioc:account_of', array('rdf:resource' => $useruri));
     }
     $person = array();
     if ($fetchSubscriptions) {
         // Get people user is subscribed to
         $sub = new Subscription();
         $sub->subscriber = $profile->id;
         $sub->whereAdd('subscriber != subscribed');
         if ($sub->find()) {
             while ($sub->fetch()) {
                 $profile = Profile::staticGet('id', $sub->subscribed);
                 if (empty($profile)) {
                     common_debug('Got a bad subscription: ' . print_r($sub, true));
                     continue;
                 }
                 $user = $profile->getUser();
                 $other_uri = $profile->getUri();
                 $this->element('sioc:follows', array('rdf:resource' => $other_uri . '#acct'));
                 $person[$other_uri] = array(LISTENEE, $profile->id, $profile->nickname, $user ? 'local' : 'remote');
                 unset($profile);
             }
         }
         unset($sub);
     } else {
         if ($isSubscriber) {
             // Just declare that they follow the user whose FOAF we're showing.
             $this->element('sioc:follows', array('rdf:resource' => $this->user->uri . '#acct'));
         }
     }
     $this->elementEnd('OnlineAccount');
     $this->elementEnd('account');
     return $person;
 }
 private static function realBySubscribed($subscribedId, $offset, $limit)
 {
     $sub = new Subscription();
     $sub->subscribed = $subscribedId;
     $sub->whereAdd('subscriber != ' . $subscribedId);
     $sub->orderBy('created DESC');
     $sub->limit($offset, $limit);
     $sub->find();
     $subs = array();
     while ($sub->fetch()) {
         $subs[] = clone $sub;
     }
     return $subs;
 }
Beispiel #5
0
 function _deleteSubscriptions()
 {
     $sub = new Subscription();
     $sub->subscriber = $this->id;
     $sub->find();
     while ($sub->fetch()) {
         $other = Profile::staticGet('id', $sub->subscribed);
         if (empty($other)) {
             continue;
         }
         if ($other->id == $this->id) {
             continue;
         }
         Subscription::cancel($this, $other);
     }
     $subd = new Subscription();
     $subd->subscribed = $this->id;
     $subd->find();
     while ($subd->fetch()) {
         $other = Profile::staticGet('id', $subd->subscriber);
         if (empty($other)) {
             continue;
         }
         if ($other->id == $this->id) {
             continue;
         }
         Subscription::cancel($other, $this);
     }
     $self = new Subscription();
     $self->subscriber = $this->id;
     $self->subscribed = $this->id;
     $self->delete();
 }
Beispiel #6
0
function initSubscriptionURI()
{
    printfnq("Ensuring all subscriptions have a URI...");
    $sub = new Subscription();
    $sub->whereAdd('uri IS NULL');
    if ($sub->find()) {
        while ($sub->fetch()) {
            try {
                $sub->decache();
                $sub->query(sprintf('update subscription ' . 'set uri = "%s" ' . 'where subscriber = %d ' . 'and subscribed = %d', Subscription::newURI($sub->subscriber, $sub->subscribed, $sub->created), $sub->subscriber, $sub->subscribed));
            } catch (Exception $e) {
                common_log(LOG_ERR, "Error updated subscription URI: " . $e->getMessage());
            }
        }
    }
    printfnq("DONE.\n");
}
Beispiel #7
0
 function _deleteSubscriptions()
 {
     $sub = new Subscription();
     $sub->subscriber = $this->getID();
     $sub->find();
     while ($sub->fetch()) {
         try {
             $other = $sub->getSubscribed();
             if (!$other->sameAs($this)) {
                 Subscription::cancel($this, $other);
             }
         } catch (NoResultException $e) {
             // Profile not found
             common_log(LOG_INFO, 'Subscribed profile id==' . $sub->subscribed . ' not found when deleting profile id==' . $this->getID() . ', ignoring...');
         } catch (ServerException $e) {
             // Subscription cancel failed
             common_log(LOG_INFO, 'Subscribed profile id==' . $other->getID() . ' could not be reached for unsubscription notice when deleting profile id==' . $this->getID() . ', ignoring...');
         }
     }
     $sub = new Subscription();
     $sub->subscribed = $this->getID();
     $sub->find();
     while ($sub->fetch()) {
         try {
             $other = $sub->getSubscriber();
             common_log(LOG_INFO, 'Subscriber profile id==' . $sub->subscribed . ' not found when deleting profile id==' . $this->getID() . ', ignoring...');
             if (!$other->sameAs($this)) {
                 Subscription::cancel($other, $this);
             }
         } catch (NoResultException $e) {
             // Profile not found
             common_log(LOG_INFO, 'Subscribed profile id==' . $sub->subscribed . ' not found when deleting profile id==' . $this->getID() . ', ignoring...');
         } catch (ServerException $e) {
             // Subscription cancel failed
             common_log(LOG_INFO, 'Subscriber profile id==' . $other->getID() . ' could not be reached for unsubscription notice when deleting profile id==' . $this->getID() . ', ignoring...');
         }
     }
     // Finally delete self-subscription
     $self = new Subscription();
     $self->subscriber = $this->getID();
     $self->subscribed = $this->getID();
     $self->delete();
 }
Beispiel #8
0
function omb_broadcast_profile($profile)
{
    # First, get remote users subscribed to this profile
    # XXX: use a join here rather than looping through results
    $sub = new Subscription();
    $sub->subscribed = $profile->id;
    if ($sub->find()) {
        $updated = array();
        while ($sub->fetch()) {
            $rp = Remote_profile::staticGet('id', $sub->subscriber);
            if ($rp) {
                if (!array_key_exists($rp->updateprofileurl, $updated)) {
                    if (omb_update_profile($profile, $rp, $sub)) {
                        $updated[$rp->updateprofileurl] = true;
                    }
                }
            }
        }
    }
}
Beispiel #9
0
 function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs = false)
 {
     $this->auth_user = $apidata['user'];
     $user = $this->get_user($apidata['api_arg'], $apidata);
     if (!$user) {
         $this->clientError('Not Found', 404, $apidata['content-type']);
         return;
     }
     $page = $this->trimmed('page');
     if (!$page || !is_numeric($page)) {
         $page = 1;
     }
     $profile = $user->getProfile();
     if (!$profile) {
         $this->serverError(_('User has no profile.'));
         return;
     }
     $sub = new Subscription();
     $sub->{$user_attr} = $profile->id;
     $since = strtotime($this->trimmed('since'));
     if ($since) {
         $d = date('Y-m-d H:i:s', $since);
         $sub->whereAdd("created > '{$d}'");
     }
     $sub->orderBy('created DESC');
     if (!$onlyIDs) {
         $sub->limit(($page - 1) * 100, 100);
     }
     $others = array();
     if ($sub->find()) {
         while ($sub->fetch()) {
             $others[] = Profile::staticGet($sub->{$other_attr});
         }
     } else {
         // user has no followers
     }
     $type = $apidata['content-type'];
     $this->init_document($type);
     if ($onlyIDs) {
         $this->showIDs($others, $type);
     } else {
         $this->show_profiles($others, $type);
     }
     $this->end_document($type);
 }
Beispiel #10
0
 function handle($args)
 {
     parent::handle($args);
     header('Content-Type: application/rdf+xml');
     $this->startXML();
     $this->elementStart('rdf:RDF', array('xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
     // This is the document about the user
     $this->showPpd('', $this->user->uri);
     // XXX: might not be a person
     $this->elementStart('Person', array('rdf:about' => $this->user->uri));
     $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email));
     if ($this->profile->fullname) {
         $this->element('name', null, $this->profile->fullname);
     }
     if ($this->profile->homepage) {
         $this->element('homepage', array('rdf:resource' => $this->profile->homepage));
     }
     if ($this->profile->bio) {
         $this->element('rdfs:comment', null, $this->profile->bio);
     }
     // XXX: more structured location data
     if ($this->profile->location) {
         $this->elementStart('based_near');
         $this->elementStart('geo:SpatialThing');
         $this->element('name', null, $this->profile->location);
         $this->elementEnd('geo:SpatialThing');
         $this->elementEnd('based_near');
     }
     $this->showMicrobloggingAccount($this->profile, common_root_url());
     $avatar = $this->profile->getOriginalAvatar();
     if ($avatar) {
         $this->elementStart('img');
         $this->elementStart('Image', array('rdf:about' => $avatar->url));
         foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
             $scaled = $this->profile->getAvatar($size);
             if (!$scaled->original) {
                 // sometimes the original has one of our scaled sizes
                 $this->elementStart('thumbnail');
                 $this->element('Image', array('rdf:about' => $scaled->url));
                 $this->elementEnd('thumbnail');
             }
         }
         $this->elementEnd('Image');
         $this->elementEnd('img');
     }
     // Get people user is subscribed to
     $person = array();
     $sub = new Subscription();
     $sub->subscriber = $this->profile->id;
     $sub->whereAdd('subscriber != subscribed');
     if ($sub->find()) {
         while ($sub->fetch()) {
             if ($sub->token) {
                 $other = Remote_profile::staticGet('id', $sub->subscribed);
             } else {
                 $other = User::staticGet('id', $sub->subscribed);
             }
             if (!$other) {
                 common_debug('Got a bad subscription: ' . print_r($sub, true));
                 continue;
             }
             $this->element('knows', array('rdf:resource' => $other->uri));
             $person[$other->uri] = array(LISTENEE, $other);
         }
     }
     // Get people who subscribe to user
     $sub = new Subscription();
     $sub->subscribed = $this->profile->id;
     $sub->whereAdd('subscriber != subscribed');
     if ($sub->find()) {
         while ($sub->fetch()) {
             if ($sub->token) {
                 $other = Remote_profile::staticGet('id', $sub->subscriber);
             } else {
                 $other = User::staticGet('id', $sub->subscriber);
             }
             if (!$other) {
                 common_debug('Got a bad subscription: ' . print_r($sub, true));
                 continue;
             }
             if (array_key_exists($other->uri, $person)) {
                 $person[$other->uri][0] = BOTH;
             } else {
                 $person[$other->uri] = array(LISTENER, $other);
             }
         }
     }
     $this->elementEnd('Person');
     foreach ($person as $uri => $p) {
         $foaf_url = null;
         if ($p[1] instanceof User) {
             $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
         }
         $this->profile = Profile::staticGet($p[1]->id);
         $this->elementStart('Person', array('rdf:about' => $uri));
         if ($p[0] == LISTENER || $p[0] == BOTH) {
             $this->element('knows', array('rdf:resource' => $this->user->uri));
         }
         $this->showMicrobloggingAccount($this->profile, $p[1] instanceof User ? common_root_url() : null);
         if ($foaf_url) {
             $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
         }
         $this->elementEnd('Person');
         if ($foaf_url) {
             $this->showPpd($foaf_url, $uri);
         }
     }
     $this->elementEnd('rdf:RDF');
     $this->endXML();
 }