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; }
/** * Look up a Profile by profileurl field. Profile::staticGet() was * not working consistently. * * @param string $nickname local nickname of the Twitter user * @param string $profileurl the profile url * * @return mixed value the first Profile with that url, or null */ function getProfileByUrl($nickname, $profileurl) { $profile = new Profile(); $profile->nickname = $nickname; $profile->profileurl = $profileurl; $profile->limit(1); if ($profile->find()) { $profile->fetch(); return $profile; } return null; }
/** * 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; }
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; }
/** * Look up a Profile by profileurl field. Profile::getKV() was * not working consistently. * * @param string $nickname local nickname of the Twitter user * @param string $profileurl the profile url * * @return mixed value the first Profile with that url, or null */ protected function getProfileByUrl($nickname, $profileurl) { $profile = new Profile(); $profile->nickname = $nickname; $profile->profileurl = $profileurl; $profile->limit(1); if (!$profile->find(true)) { $profile->profileurl = str_replace('https://', 'http://', $profileurl); if (!$profile->find(true)) { throw new NoResultException($profile); } } return $profile; }
/** * 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; }
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; }