123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class AccountProfileBlock extends ProfileBlock
- {
- protected $profile = null;
- protected $user = null;
- function __construct(Action $out, Profile $profile)
- {
- parent::__construct($out);
- $this->profile = $profile;
- try {
- $this->user = $this->profile->getUser();
- } catch (NoSuchUserException $e) {
-
- assert(!$this->profile->isLocal());
- }
- }
- function name()
- {
- return $this->profile->getBestName();
- }
- function url()
- {
- return $this->profile->profileurl;
- }
- function location()
- {
- return $this->profile->location;
- }
- function homepage()
- {
- return $this->profile->homepage;
- }
- function description()
- {
- return $this->profile->bio;
- }
- function otherProfiles()
- {
- $others = array();
- Event::handle('OtherAccountProfiles', array($this->profile, &$others));
-
- return $others;
- }
- function showTags()
- {
- $cur = common_current_user();
- $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
- $self_tags->show();
- if ($cur) {
-
- if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
- $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
- $tags->show();
- }
- }
- }
- function showActions()
- {
- if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
- if ($this->profile->hasRole(Profile_role::DELETED)) {
- $this->out->elementStart('div', 'entity_actions');
-
- $this->out->element('h2', null, _('User actions'));
- $this->out->elementStart('ul');
- $this->out->elementStart('p', array('class' => 'profile_deleted'));
-
- $this->out->text(_('User deletion in progress...'));
- $this->out->elementEnd('p');
- $this->out->elementEnd('ul');
- $this->out->elementEnd('div');
- return;
- }
- $cur = common_current_user();
- $this->out->elementStart('div', 'entity_actions');
-
- $this->out->element('h2', null, _('User actions'));
- $this->out->elementStart('ul');
- if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
- if (empty($cur)) {
- if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
- Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
- }
- } else {
- if ($cur->id == $this->profile->id) {
- $this->out->elementStart('li', 'entity_edit');
- $this->out->element('a', array('href' => common_local_url('profilesettings'),
-
- 'title' => _('Edit profile settings.')),
-
- _m('BUTTON','Edit'));
- $this->out->elementEnd('li');
- } else {
-
- $this->out->elementStart('li', 'entity_subscribe');
- if ($cur->isSubscribed($this->profile)) {
- $usf = new UnsubscribeForm($this->out, $this->profile);
- $usf->show();
- } else if ($cur->hasPendingSubscription($this->profile)) {
- $sf = new CancelSubscriptionForm($this->out, $this->profile);
- $sf->show();
- } else {
- $sf = new SubscribeForm($this->out, $this->profile);
- $sf->show();
- }
- $this->out->elementEnd('li');
- if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
-
- if ($this->user->email && $this->user->emailnotifynudge) {
- $this->out->elementStart('li', 'entity_nudge');
- $nf = new NudgeForm($this->out, $this->user);
- $nf->show();
- $this->out->elementEnd('li');
- }
- }
-
- list($action, $r2args) = $this->out->returnToArgs();
-
- $r2args['action'] = $action;
-
- $blocked = $cur->hasBlocked($this->profile);
- $this->out->elementStart('li', 'entity_block');
- if ($blocked) {
- $ubf = new UnblockForm($this->out, $this->profile, $r2args);
- $ubf->show();
- } else {
- $bf = new BlockForm($this->out, $this->profile, $r2args);
- $bf->show();
- }
- $this->out->elementEnd('li');
-
- $isLocal = !empty($this->user);
- if ($cur->hasRight(Right::SANDBOXUSER) ||
- $cur->hasRight(Right::SILENCEUSER) ||
- $cur->hasRight(Right::DELETEUSER)) {
- $this->out->elementStart('li', 'entity_moderation');
-
- $this->out->element('p', null, _('Moderate'));
- $this->out->elementStart('ul');
- if ($cur->hasRight(Right::SANDBOXUSER)) {
- $this->out->elementStart('li', 'entity_sandbox');
- if ($this->profile->isSandboxed()) {
- $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
- $usf->show();
- } else {
- $sf = new SandboxForm($this->out, $this->profile, $r2args);
- $sf->show();
- }
- $this->out->elementEnd('li');
- }
- if ($cur->hasRight(Right::SILENCEUSER)) {
- $this->out->elementStart('li', 'entity_silence');
- if ($this->profile->isSilenced()) {
- $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
- $usf->show();
- } else {
- $sf = new SilenceForm($this->out, $this->profile, $r2args);
- $sf->show();
- }
- $this->out->elementEnd('li');
- }
- if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
- $this->out->elementStart('li', 'entity_delete');
- $df = new DeleteUserForm($this->out, $this->profile, $r2args);
- $df->show();
- $this->out->elementEnd('li');
- }
- $this->out->elementEnd('ul');
- $this->out->elementEnd('li');
- }
- if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
- $this->out->elementStart('li', 'entity_role');
-
- $this->out->element('p', null, _('User role'));
- $this->out->elementStart('ul');
-
- $this->roleButton('administrator', _m('role', 'Administrator'));
-
- $this->roleButton('moderator', _m('role', 'Moderator'));
- $this->out->elementEnd('ul');
- $this->out->elementEnd('li');
- }
- }
- }
- Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
- }
- $this->out->elementEnd('ul');
- $this->out->elementEnd('div');
- Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
- }
- }
- function roleButton($role, $label)
- {
- list($action, $r2args) = $this->out->returnToArgs();
- $r2args['action'] = $action;
- $this->out->elementStart('li', "entity_role_$role");
- if ($this->profile->hasRole($role)) {
- $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
- $rf->show();
- } else {
- $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
- $rf->show();
- }
- $this->out->elementEnd('li');
- }
- function show()
- {
- $this->out->elementStart('div', 'profile_block account_profile_block section');
- if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
- parent::show();
- Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
- }
- $this->out->elementEnd('div');
- }
- }
|