$avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename;
$avatar->original = true;
- $avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now();
// XXX: start a transaction here
*
* @return mixed Notice or null
*/
- function getCurrentNotice()
+ function getCurrentNotice(Profile $scoped=null)
{
- $notice = $this->getNotices(0, 1);
+ try {
+ $notice = $this->getNotices(0, 1, 0, 0, $scoped);
- if ($notice->fetch()) {
- if ($notice instanceof ArrayWrapper) {
- // hack for things trying to work with single notices
- return $notice->_items[0];
+ if ($notice->fetch()) {
+ if ($notice instanceof ArrayWrapper) {
+ // hack for things trying to work with single notices
+ // ...but this shouldn't happen anymore I think. Keeping it for safety...
+ return $notice->_items[0];
+ }
+ return $notice;
}
- return $notice;
+ } catch (PrivateStreamException $e) {
+ // Maybe we should let this through if it's handled well upstream
+ return null;
}
return null;
return false;
}
- function getLists($auth_user, $offset=0, $limit=null, $since_id=0, $max_id=0)
+ function getLists(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
{
$ids = array();
self::cacheSet($keypart, implode(',', $ids));
}
- $showPrivate = (($auth_user instanceof User ||
- $auth_user instanceof Profile) &&
- $auth_user->id === $this->id);
+ $showPrivate = $this->sameAs($scoped);
$lists = array();
/**
* Get tags that other people put on this profile, in reverse-chron order
*
- * @param (Profile|User) $auth_user Authorized user (used for privacy)
+ * @param Profile $scoped User we are requesting as
* @param int $offset Offset from latest
* @param int $limit Max number to get
* @param datetime $since_id max date
* @return Profile_list resulting lists
*/
- function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
+ function getOtherTags(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
{
$list = new Profile_list();
$this->id);
- if ($auth_user instanceof User || $auth_user instanceof Profile) {
+ if (!is_null($scoped)) {
$qry .= sprintf('AND ( ( profile_list.private = false ) ' .
'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = true ) )',
- $auth_user->id);
+ $scoped->getID());
} else {
$qry .= 'AND profile_list.private = 0 ';
}
$notices = new Notice();
$notices->profile_id = $this->id;
+ $notices->verb = ActivityVerb::POST;
$cnt = (int) $notices->count('distinct id');
if (!empty($c)) {
*/
public function getUrl()
{
- if (empty($this->profileurl) ||
- !filter_var($this->profileurl, FILTER_VALIDATE_URL)) {
- throw new InvalidUrlException($this->profileurl);
+ $url = null;
+ if ($this->isGroup()) {
+ // FIXME: Get rid of this event, it fills no real purpose, data should be in Profile->profileurl (replaces User_group->mainpage)
+ if (Event::handle('StartUserGroupHomeUrl', array($this->getGroup(), &$url))) {
+ $url = $this->getGroup()->isLocal()
+ ? common_local_url('showgroup', array('nickname' => $this->getNickname()))
+ : $this->profileurl;
+ }
+ Event::handle('EndUserGroupHomeUrl', array($this->getGroup(), $url));
+ } elseif ($this->isLocal()) {
+ $url = common_local_url('showstream', array('nickname' => $this->getNickname()));
+ } else {
+ $url = $this->profileurl;
+ }
+ if (empty($url) ||
+ !filter_var($url, FILTER_VALIDATE_URL)) {
+ throw new InvalidUrlException($url);
}
- return $this->profileurl;
+ return $url;
}
public function getNickname()
$user = User::getKV('uri', $uri);
if ($user instanceof User) {
$profile = $user->getProfile();
+ } else {
+ $group = User_group::getKV('uri', $uri);
+ if ($group instanceof User_group) {
+ $profile = $group->getProfile();
+ }
}
Event::handle('EndGetProfileFromURI', array($uri, $profile));
}