Exemplo n.º 1
0
 protected function prepare(array $args = array())
 {
     // If we die, show short error messages.
     GNUsocial::setApi(true);
     parent::prepare($args);
     $this->groups = array();
     $this->profiles = array();
     $term = $this->arg('term');
     $limit = $this->arg('limit');
     if ($limit > 200) {
         $limit = 200;
     }
     //prevent DOS attacks
     if (substr($term, 0, 1) == '@') {
         //profile search
         $term = substr($term, 1);
         $profile = new Profile();
         $profile->limit($limit);
         $profile->whereAdd('nickname like \'' . trim($profile->escape($term), '\'') . '%\'');
         $profile->whereAdd(sprintf('id in (SELECT id FROM user) OR ' . 'id in (SELECT subscribed from subscription' . ' where subscriber = %d)', $this->scoped->id));
         if ($profile->find()) {
             while ($profile->fetch()) {
                 $this->profiles[] = clone $profile;
             }
         }
     }
     if (substr($term, 0, 1) == '!') {
         //group search
         $term = substr($term, 1);
         $group = new User_group();
         $group->limit($limit);
         $group->whereAdd('nickname like \'' . trim($group->escape($term), '\'') . '%\'');
         //Can't post to groups we're not subscribed to...:
         $group->whereAdd(sprintf('id in (SELECT group_id FROM group_member' . ' WHERE profile_id = %d)', $this->scoped->id));
         if ($group->find()) {
             while ($group->fetch()) {
                 $this->groups[] = clone $group;
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
function common_relative_profile($sender, $nickname, $dt = null)
{
    // Try to find profiles this profile is subscribed to that have this nickname
    $recipient = new Profile();
    // XXX: use a join instead of a subquery
    $recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = ' . $sender->id . ' and subscribed = id)', 'AND');
    $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND');
    if ($recipient->find(true)) {
        // XXX: should probably differentiate between profiles with
        // the same name by date of most recent update
        return $recipient;
    }
    // Try to find profiles that listen to this profile and that have this nickname
    $recipient = new Profile();
    // XXX: use a join instead of a subquery
    $recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = ' . $sender->id . ' and subscriber = id)', 'AND');
    $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND');
    if ($recipient->find(true)) {
        // XXX: should probably differentiate between profiles with
        // the same name by date of most recent update
        return $recipient;
    }
    // If this is a local user, try to find a local user with that nickname.
    $sender = User::staticGet($sender->id);
    if ($sender) {
        $recipient_user = User::staticGet('nickname', $nickname);
        if ($recipient_user) {
            return $recipient_user->getProfile();
        }
    }
    // Otherwise, no links. @messages from local users to remote users,
    // or from remote users to other remote users, are just
    // outside our ability to make intelligent guesses about
    return null;
}
Exemplo n.º 3
0
 /**
  * Get profiles tagged with this people tag,
  * include modified timestamp as a "cursor" field
  * order by descending order of modified time
  *
  * @param integer $offset   offset
  * @param integer $limit    maximum no of results
  * @param integer $since_id=null    since unix timestamp
  * @param integer $upto=null  maximum unix timestamp when subscription was made
  *
  * @return Profile results
  */
 function getTagged($offset = 0, $limit = null, $since = 0, $upto = 0)
 {
     $tagged = new Profile();
     $tagged->joinAdd(array('id', 'profile_tag:tagged'));
     #@fixme: postgres
     $tagged->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
     $tagged->whereAdd('profile_tag.tagger = ' . $this->tagger);
     $tagged->whereAdd("profile_tag.tag = '{$this->tag}'");
     if ($since != 0) {
         $tagged->whereAdd('cursor > ' . $since);
     }
     if ($upto != 0) {
         $tagged->whereAdd('cursor <= ' . $upto);
     }
     if ($limit != null) {
         $tagged->limit($offset, $limit);
     }
     $tagged->orderBy('profile_tag.modified DESC');
     $tagged->find();
     return $tagged;
 }
Exemplo n.º 4
0
 function showContent()
 {
     // XXX: Note I'm doing it this two-stage way because a raw query
     // with a JOIN was *not* working. --Zach
     $featured_nicks = common_config('nickname', 'featured');
     if (count($featured_nicks) > 0) {
         $quoted = array();
         foreach ($featured_nicks as $nick) {
             $quoted[] = "'{$nick}'";
         }
         $user = new User();
         $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
         $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
         $user->orderBy(common_database_tablename('user') . '.nickname ASC');
         $user->find();
         $profile_ids = array();
         while ($user->fetch()) {
             $profile_ids[] = $user->id;
         }
         $profile = new Profile();
         $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
         $profile->orderBy('nickname ASC');
         $cnt = $profile->find();
         if ($cnt > 0) {
             $featured = new ProfileList($profile, $this);
             $featured->show();
         }
         $profile->free();
         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'featured');
     }
 }
Exemplo n.º 5
0
 function getUsers()
 {
     $profile = new Profile();
     // Comment this out or disable to get global profile searches
     $profile->joinAdd(array('id', 'user:id'));
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     if (!empty($this->q)) {
         // User is searching via query
         $search_engine = $profile->getSearchEngine('profile');
         $mode = 'reverse_chron';
         if ($this->sort == 'nickname') {
             if ($this->reverse) {
                 $mode = 'nickname_desc';
             } else {
                 $mode = 'nickname_asc';
             }
         } else {
             if ($this->reverse) {
                 $mode = 'chron';
             }
         }
         $search_engine->set_sort_mode($mode);
         $search_engine->limit($offset, $limit);
         $search_engine->query($this->q);
         $profile->find();
     } else {
         // User is browsing via AlphaNav
         switch ($this->filter) {
             case 'all':
                 // NOOP
                 break;
             case '0-9':
                 $profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s', $profile->escapedTableName(), 'nickname', $profile->_quote("0"), $profile->_quote("9")));
                 break;
             default:
                 $profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s', $profile->escapedTableName(), 'nickname', $profile->_quote($this->filter)));
         }
         $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC', $profile->escapedTableName(), $this->getSortKey('nickname'), $this->reverse ? 'DESC' : 'ASC', 'nickname');
         $profile->orderBy($order);
         $profile->limit($offset, $limit);
         $profile->find();
     }
     return $profile;
 }
Exemplo n.º 6
0
 /**
  * Get pending subscribers, who have not yet been approved.
  *
  * @param int $offset
  * @param int $limit
  * @return Profile
  */
 function getRequests($offset = 0, $limit = null)
 {
     // FIXME: mysql only
     $subqueue = new Profile();
     $subqueue->joinAdd(array('id', 'subscription_queue:subscriber'));
     $subqueue->whereAdd(sprintf('subscription_queue.subscribed = %d', $this->getID()));
     $subqueue->limit($offset, $limit);
     $subqueue->orderBy('subscription_queue.created', 'DESC');
     if (!$subqueue->find()) {
         throw new NoResultException($subqueue);
     }
     return $subqueue;
 }
Exemplo n.º 7
0
 function getBlocked($offset = null, $limit = null)
 {
     $blocked = new Profile();
     $blocked->joinAdd(array('id', 'group_block:blocked'));
     $blocked->whereAdd(sprintf('group_block.group_id = %u', $this->id));
     $blocked->orderBy('group_block.modified DESC');
     $blocked->limit($offset, $limit);
     $blocked->find();
     return $blocked;
 }