/** * Method to add a user to a group. * In most cases, you should call Profile->joinGroup() instead. * * @param integer $group_id Group to add to * @param integer $profile_id Profile being added * * @return Group_member new membership object */ static function join($group_id, $profile_id) { $member = new Group_member(); $member->group_id = $group_id; $member->profile_id = $profile_id; $member->created = common_sql_now(); $member->uri = self::newUri(Profile::getByID($profile_id), User_group::getByID($group_id), $member->created); $result = $member->insert(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); // TRANS: Exception thrown when joining a group fails. throw new Exception(_("Group join failed.")); } return $member; }
protected function doPreparation() { // accessing by ID just requires an ID, not a nickname $this->target = Profile::getByID($this->trimmed('id')); // For local users when accessed by id number, redirect with // the nickname as argument instead of id. if ($this->target->isLocal()) { // Support redirecting to FOAF rdf/xml if the agent prefers it... // Internet Explorer doesn't specify "text/html" and does list "*/*" // at least through version 8. We need to list text/html up front to // ensure that only user-agents who specifically ask for RDF get it. $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2'; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $type = common_negotiate_type(common_accept_to_prefs($httpaccept), common_accept_to_prefs($page_prefs)); $page = $type === 'application/rdf+xml' ? 'foaf' : 'showstream'; $url = common_local_url($page, array('nickname' => $this->target->getNickname())); common_redirect($url, 303); } }
/** * Find @-mentions in the given text, using the given notice object as context. * References will be resolved with common_relative_profile() against the user * who posted the notice. * * Note the return data format is internal, to be used for building links and * such. Should not be used directly; rather, call common_linkify_mentions(). * * @param string $text * @param Profile $sender the Profile that is sending the current text * @param Notice $parent the Notice this text is in reply to, if any * * @return array * * @access private */ function common_find_mentions($text, Profile $sender, Notice $parent = null) { $mentions = array(); if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { // Get the context of the original notice, if any $origMentions = array(); // Does it have a parent notice for context? if ($parent instanceof Notice) { $ids = $parent->getReplies(); // replied-to _profile ids_ foreach ($ids as $id) { try { $repliedTo = Profile::getByID($id); $origMentions[$repliedTo->getNickname()] = $repliedTo; } catch (NoResultException $e) { // continue foreach } } } $matches = common_find_mentions_raw($text); foreach ($matches as $match) { try { $nickname = Nickname::normalize($match[0]); } catch (NicknameException $e) { // Bogus match? Drop it. continue; } // Try to get a profile for this nickname. // Start with conversation context, then go to // sender context. if ($parent instanceof Notice && $parent->getProfile()->getNickname() === $nickname) { $mentioned = $parent->getProfile(); } else { if (!empty($origMentions) && array_key_exists($nickname, $origMentions)) { $mentioned = $origMentions[$nickname]; } else { // sets to null if no match $mentioned = common_relative_profile($sender, $nickname); } } if ($mentioned instanceof Profile) { $user = User::getKV('id', $mentioned->id); try { $url = $mentioned->getUrl(); } catch (InvalidUrlException $e) { $url = common_local_url('userbyid', array('id' => $mentioned->getID())); } $mention = array('mentioned' => array($mentioned), 'type' => 'mention', 'text' => $match[0], 'position' => $match[1], 'length' => mb_strlen($match[0]), 'title' => $mentioned->getFullname(), 'url' => $url); $mentions[] = $mention; } } // @#tag => mention of all subscriptions tagged 'tag' preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $tag = common_canonical_tag($hmatch[0]); $plist = Profile_list::getByTaggerAndTag($sender->getID(), $tag); if (!$plist instanceof Profile_list || $plist->private) { continue; } $tagged = $sender->getTaggedSubscribers($tag); $url = common_local_url('showprofiletag', array('nickname' => $sender->getNickname(), 'tag' => $tag)); $mentions[] = array('mentioned' => $tagged, 'type' => 'list', 'text' => $hmatch[0], 'position' => $hmatch[1], 'length' => mb_strlen($hmatch[0]), 'url' => $url); } preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)!(' . Nickname::DISPLAY_FMT . ')/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $nickname = Nickname::normalize($hmatch[0]); $group = User_group::getForNickname($nickname, $sender); if (!$group instanceof User_group || !$sender->isMember($group)) { continue; } $profile = $group->getProfile(); $mentions[] = array('mentioned' => array($profile), 'type' => 'group', 'text' => $hmatch[0], 'position' => $hmatch[1], 'length' => mb_strlen($hmatch[0]), 'url' => $group->permalink(), 'title' => $group->getFancyName()); } Event::handle('EndFindMentions', array($sender, $text, &$mentions)); } return $mentions; }
/** * get the tagger of this profile_list object * * @return Profile the tagger */ function getTagger() { return Profile::getByID($this->tagger); }
function getProfile() { return Profile::getByID($this->user_id); }
function showFeedForm(SubMirror $mirror) { $profile = Profile::getByID($mirror->subscribed); $form = new EditMirrorForm($this, $profile); $form->show(); }
function onEndShowSections(Action $action) { if (!$action instanceof ShowstreamAction) { // early return for actions we're not interested in return true; } $scoped = $action->getScoped(); if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) { // only continue if we are allowed to VIEWMODLOG return true; } $profile = $action->getTarget(); $ml = new ModLog(); $ml->profile_id = $profile->getID(); $ml->orderBy("created"); $cnt = $ml->find(); if ($cnt > 0) { $action->elementStart('div', array('id' => 'entity_mod_log', 'class' => 'section')); $action->element('h2', null, _('Moderation')); $action->elementStart('table'); while ($ml->fetch()) { $action->elementStart('tr'); $action->element('td', null, strftime('%y-%m-%d', strtotime($ml->created))); $action->element('td', null, sprintf($ml->is_grant ? _('+%s') : _('-%s'), $ml->role)); $action->elementStart('td'); if ($ml->moderator_id) { $mod = Profile::getByID($ml->moderator_id); if (empty($mod)) { $action->text(_('[unknown]')); } else { $action->element('a', array('href' => $mod->getUrl(), 'title' => $mod->getFullname()), $mod->getNickname()); } } else { $action->text(_('[unknown]')); } $action->elementEnd('td'); $action->elementEnd('tr'); } $action->elementEnd('table'); $action->elementEnd('div'); } }
function initGroupMemberURI() { printfnq("Ensuring all group memberships have a URI..."); $mem = new Group_member(); $mem->whereAdd('uri IS NULL'); if ($mem->find()) { while ($mem->fetch()) { try { $mem->decache(); $mem->query(sprintf('update group_member set uri = "%s" ' . 'where profile_id = %d ' . 'and group_id = %d ', Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created), $mem->profile_id, $mem->group_id)); } catch (Exception $e) { common_log(LOG_ERR, "Error updated membership URI: " . $e->getMessage()); } } } printfnq("DONE.\n"); }
static function setTag($tagger, $tagged, $tag, $desc = null, $private = false) { $ptag = Profile_tag::pkeyGet(array('tagger' => $tagger, 'tagged' => $tagged, 'tag' => $tag)); # if tag already exists, return it if ($ptag instanceof Profile_tag) { return $ptag; } $tagger_profile = Profile::getByID($tagger); $tagged_profile = Profile::getByID($tagged); if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) { if (!$tagger_profile->canTag($tagged_profile)) { // TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged. throw new ClientException(_('You cannot tag this user.')); } $tags = new Profile_list(); $tags->tagger = $tagger; $count = (int) $tags->count('distinct tag'); if ($count >= common_config('peopletag', 'maxtags')) { // TRANS: Client exception thrown trying to set more tags than allowed. throw new ClientException(sprintf(_('You already have created %d or more tags ' . 'which is the maximum allowed number of tags. ' . 'Try using or deleting some existing tags.'), common_config('peopletag', 'maxtags'))); } $plist = new Profile_list(); $plist->query('BEGIN'); $profile_list = Profile_list::ensureTag($tagger, $tag, $desc, $private); if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) { // TRANS: Client exception thrown when trying to add more people than allowed to a list. throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' . 'which is the maximum allowed number. ' . 'Try unlisting others first.'), common_config('peopletag', 'maxpeople'), $tag)); } $newtag = new Profile_tag(); $newtag->tagger = $tagger; $newtag->tagged = $tagged; $newtag->tag = $tag; $result = $newtag->insert(); if (!$result) { common_log_db_error($newtag, 'INSERT', __FILE__); $plist->query('ROLLBACK'); return false; } try { $plist->query('COMMIT'); Event::handle('EndTagProfile', array($newtag)); } catch (Exception $e) { $newtag->delete(); $profile_list->delete(); throw $e; } $profile_list->taggedCount(true); self::blowCaches($tagger, $tagged); } return $newtag; }
public function getSubscribed() { return Profile::getByID($this->subscribed); }
public function getActor() { return Profile::getByID($this->profile_id); }