Example #1
0
function updateGroupUrls()
{
    printfnq("Updating group URLs...\n");
    $group = new User_group();
    if ($group->find()) {
        while ($group->fetch()) {
            try {
                printfv("Updating group {$group->nickname}...");
                $orig = User_group::getKV('id', $group->id);
                if (!empty($group->original_logo)) {
                    $group->original_logo = Avatar::url(basename($group->original_logo));
                    $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
                    $group->stream_logo = Avatar::url(basename($group->stream_logo));
                    $group->mini_logo = Avatar::url(basename($group->mini_logo));
                }
                // XXX: this is a hack to see if a group is local or not
                $localUri = common_local_url('groupbyid', array('id' => $group->id));
                if ($group->getUri() != $localUri) {
                    $group->mainpage = common_local_url('showgroup', array('nickname' => $group->nickname));
                }
                $group->update($orig);
                printfv("DONE.");
            } catch (Exception $e) {
                echo "Can't update avatars for group " . $group->nickname . ": " . $e->getMessage();
            }
        }
    }
}
 /**
  * constructor
  *
  * @param User_group $user User_group that's missing a profile
  */
 public function __construct(User_group $group)
 {
     $this->group = $group;
     // TRANS: Exception text shown when no profile can be found for a group.
     // TRANS: %1$s is a group nickname, $2$d is a group profile_id (number).
     $message = sprintf(_('Group "%1$s" (%2$d) has no profile record.'), $group->nickname, $group->getID());
     parent::__construct($group->profile_id, $message);
 }
Example #3
0
 public function getGroup()
 {
     $group = new User_group();
     $group->id = $this->group_id;
     $group->find(true);
     if (!$group instanceof User_group) {
         common_log(LOG_ERR, 'User_group does not exist for Local_group: ' . $this->group_id);
         throw new NoResultException($group);
     }
     return $group;
 }
Example #4
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         throw new ClientException(_('Only for logged-in users'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     if (!$cur->isMember($this->group)) {
         throw new ClientException(_('Only for members'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::staticGet('id', $id);
     if (empty($this->gm)) {
         throw new ClientException(_('No such message'), 404);
     }
     $this->group = User_group::staticGet('id', $this->gm->to_group);
     if (empty($this->group)) {
         throw new ServerException(_('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         throw new ClientException(_('Cannot read message.'), 403);
     }
     $this->sender = Profile::staticGet('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         throw new ServerException(_('No sender found.'));
     }
     return true;
 }
Example #6
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_config('inboxes', 'enabled')) {
         $this->serverError(_('Inboxes must be enabled for groups to work.'));
         return false;
     }
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to leave a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('leavegroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('nickname', $nickname);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isMember($this->group)) {
         $this->clientError(_('You are not a member of that group.'), 403);
         return false;
     }
     return true;
 }
Example #7
0
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupqueue', $args), 301);
     }
     if (!$nickname) {
         // TRANS: Client error displayed when trying to view group members without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
     }
     $local = Local_group::getKV('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when trying to view group members for a non-existing group.
         $this->clientError(_('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when trying to view group members for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
     }
     $cur = common_current_user();
     if (!$cur || !$cur->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to approve group applicants without being a group administrator.
         $this->clientError(_('Only the group admin may approve users.'));
     }
     return true;
 }
 /**
  * Constructor
  *
  * @param Group   $group   the group for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($group, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->group = $group;
     // TRANS: Title in atom group notice feed. %s is a group name.
     $title = sprintf(_("%s timeline"), $group->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $group->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $group->homepage_logo;
     $logo = $avatar ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $self = common_local_url('ApiTimelineGroup', array('id' => $group->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     // For groups, we generate an author _AND_ an <activity:subject>
     // Versions of StatusNet under 0.9.7 treat <author> as a person
     // XXX: remove this workaround in future versions
     $ao = ActivityObject::fromGroup($group);
     $this->addAuthorRaw($ao->asString('author'));
     $depMsg = 'Deprecation warning: activity:subject is present ' . 'only for backward compatibility. It will be ' . 'removed in the next version of StatusNet.';
     $this->addAuthorRaw("<!--{$depMsg}-->\n" . $ao->asString('activity:subject'));
     $this->addLink($group->homeUrl());
 }
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('blockedfromgroup', $args), 301);
     }
     if (!$nickname) {
         // TRANS: Client error displayed when requesting a list of blocked users for a group without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
     }
     $local = Local_group::getKV('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting a list of blocked users for a non-local group.
         $this->clientError(_('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting a list of blocked users for a non-existing group.
         $this->clientError(_('No such group.'), 404);
     }
     return true;
 }
Example #10
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         // TRANS: Client exception thrown when trying to view group inbox while not logged in.
         throw new ClientException(_m('Only for logged-in users.'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
     }
     $localGroup = Local_group::getKV('nickname', $nickname);
     if (empty($localGroup)) {
         // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
         throw new ClientException(_m('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $localGroup->group_id);
     if (empty($this->group)) {
         // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
         throw new ClientException(_m('No such group.'), 404);
     }
     if (!$cur->isMember($this->group)) {
         // TRANS: Client exception thrown when trying to view group inbox while not a member.
         throw new ClientException(_m('Only for members.'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Must be logged in.'), 403);
     }
     if (!$this->user->hasRight(Right::NEWMESSAGE)) {
         throw new Exception(sprintf(_('User %s not allowed to send private messages.'), $this->user->nickname));
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('newgroupmessage', array('nickname' => $nickname));
         common_redirect($url, 301);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     // This throws an exception on error
     Group_privacy_settings::ensurePost($this->user, $this->group);
     // If we're posted to, check session token and get text
     if ($this->isPost()) {
         $this->checkSessionToken();
         $this->text = $this->trimmed('content');
     }
     return true;
 }
function updateGroupUri($group)
{
    if (!have_option('q', 'quiet')) {
        print "Updating URI for group '" . $group->nickname . "' (" . $group->id . ")...";
    }
    if (empty($group->uri)) {
        // Using clone here was screwing up the group->find() iteration
        $orig = User_group::staticGet('id', $group->id);
        $group->uri = $group->getUri();
        if (have_option('dry_run')) {
            echo " would have set {$group->uri} ";
        } else {
            if (!$group->update($orig)) {
                throw new Exception("Can't update uri for group " . $group->nickname . ".");
            }
            echo " set {$group->uri} ";
        }
    } else {
        print " already set, keeping {$group->uri} ";
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
Example #13
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
Example #14
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
Example #15
0
 /**
  * Handle input, produce output
  *
  * Switches based on GET or POST method. On GET, shows a form
  * for posting a notice. On POST, saves the results of that form.
  *
  * Results may be a full page, or just a single notice list item,
  * depending on whether AJAX was requested.
  *
  * @param array $args $_REQUEST contents
  *
  * @return void
  */
 function handle($args)
 {
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             // check for this before token since all POST and FILES data
             // is losts when size is exceeded
             if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
                 // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
                 // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
                 $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
                 $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
             }
             parent::handle($args);
             $user = common_current_user();
             $group = User_group::staticGet('id', $this->trimmed('groupid'));
             $taskid = $this->trimmed('taskid');
             try {
                 $this->saveNewNotice();
                 Task::completeTask($user->id, $taskid);
             } catch (Exception $e) {
                 $this->ajaxErrorMsg($e->getMessage(), $taskid, $group);
                 return;
             }
         }
     }
 }
Example #16
0
 /**
  * Prepare the action
  *
  * Reads and validates arguments and instantiates the attributes.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('showgroup', $args), 301);
     }
     if (!$nickname) {
         // TRANS: Client error displayed when requesting a group RSS feed without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
     }
     $local = Local_group::getKV('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting a group RSS feed for group that does not exist.
         $this->clientError(_('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting a group RSS feed for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
     }
     $this->notices = $this->getNotices($this->limit);
     return true;
 }
Example #17
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
         $this->clientError(_('No such group.'), 404);
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::getKV('nickname', $this->nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
         $this->clientError(_('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
         $this->clientError(_('No such group.'), 404);
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
function updateGroupAvatars($group)
{
    if (!have_option('q', 'quiet')) {
        print "Updating avatars for group '" . $group->nickname . "' (" . $group->id . ")...";
    }
    if (empty($group->original_logo)) {
        print "(none found)...";
    } else {
        // Using clone here was screwing up the group->find() iteration
        $orig = User_group::staticGet('id', $group->id);
        $group->original_logo = Avatar::url(basename($group->original_logo));
        $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
        $group->stream_logo = Avatar::url(basename($group->stream_logo));
        $group->mini_logo = Avatar::url(basename($group->mini_logo));
        if (!$group->update($orig)) {
            throw new Exception("Can't update avatars for group " . $group->nickname . ".");
        }
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
Example #19
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed when trying to view group members without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when trying to view group members for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when trying to view group members for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying to view group private messages without being logged in.
         throw new ClientException(_m('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::getKV('id', $id);
     if (empty($this->gm)) {
         // TRANS: Client exception thrown when trying to view a non-existing group private message.
         throw new ClientException(_m('No such message.'), 404);
     }
     $this->group = User_group::getKV('id', $this->gm->to_group);
     if (empty($this->group)) {
         // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
         throw new ServerException(_m('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         // TRANS: Client exception thrown when trying to view a group private message without being a group member.
         throw new ClientException(_m('Cannot read message.'), 403);
     }
     $this->sender = Profile::getKV('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         // TRANS: Server exception thrown when trying to view a group private message without a sender.
         throw new ServerException(_m('No sender found.'));
     }
     return true;
 }
Example #21
0
 function showGroup()
 {
     $this->out->elementStart('li', array('class' => 'profile h-card', 'id' => 'group-' . $this->group->id));
     $user = common_current_user();
     $this->out->elementStart('div', 'entity_profile');
     $logo = $this->group->stream_logo ?: User_group::defaultLogo(AVATAR_STREAM_SIZE);
     $this->out->elementStart('a', array('href' => $this->group->homeUrl(), 'class' => 'u-url p-nickname', 'rel' => 'contact group'));
     $this->out->element('img', array('src' => $logo, 'class' => 'avatar u-photo', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, 'alt' => $this->group->getBestName()));
     $this->out->text($this->group->getNickname());
     $this->out->elementEnd('a');
     if ($this->group->fullname) {
         $this->out->text(' ');
         $this->out->elementStart('span', 'p-name');
         $this->out->raw($this->highlight($this->group->fullname));
         $this->out->elementEnd('span');
     }
     if ($this->group->location) {
         $this->out->text(' ');
         $this->out->elementStart('span', 'label');
         $this->out->raw($this->highlight($this->group->location));
         $this->out->elementEnd('span');
     }
     if ($this->group->homepage) {
         $this->out->text(' ');
         $this->out->elementStart('a', array('href' => $this->group->homepage, 'class' => 'u-url'));
         $this->out->raw($this->highlight($this->group->homepage));
         $this->out->elementEnd('a');
     }
     if ($this->group->description) {
         $this->out->elementStart('p', 'note');
         $this->out->raw($this->highlight($this->group->description));
         $this->out->elementEnd('p');
     }
     // If we're on a list with an owner (subscriptions or subscribers)...
     if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
         $this->showOwnerControls();
     }
     $this->out->elementEnd('div');
     if ($user) {
         $this->out->elementStart('div', 'entity_actions');
         $this->out->elementStart('ul');
         $this->out->elementStart('li', 'entity_subscribe');
         // XXX: special-case for user looking at own
         // subscriptions page
         if ($user->isMember($this->group)) {
             $lf = new LeaveForm($this->out, $this->group);
             $lf->show();
         } else {
             if (!Group_block::isBlocked($this->group, $user->getProfile())) {
                 $jf = new JoinForm($this->out, $this->group);
                 $jf->show();
             }
         }
         $this->out->elementEnd('li');
         $this->out->elementEnd('ul');
         $this->out->elementEnd('div');
     }
     $this->out->elementEnd('li');
 }
Example #22
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to leave a group while not logged in.
         $this->clientError(_('You must be logged in to leave a group.'));
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::getKV('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
             }
             $local = Local_group::getKV('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error displayed when trying to leave a non-local group.
                 $this->clientError(_('No such group.'), 404);
             }
             $this->group = User_group::getKV('id', $local->group_id);
         } else {
             // TRANS: Client error displayed when trying to leave a group without providing a group name or group ID.
             $this->clientError(_('No nickname or ID.'), 404);
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed when trying to leave a non-existing group.
         $this->clientError(_('No such group.'), 404);
     }
     $cur = common_current_user();
     if (empty($cur)) {
         // TRANS: Client error displayed when trying to leave a group while not logged in.
         $this->clientError(_('Must be logged in.'), 403);
     }
     if ($this->arg('profile_id')) {
         if ($cur->isAdmin($this->group)) {
             $this->profile = Profile::getKV('id', $this->arg('profile_id'));
         } else {
             // TRANS: Client error displayed when trying to approve or cancel a group join request without
             // TRANS: being a group administrator.
             $this->clientError(_('Only group admin can approve or cancel join requests.'), 403);
         }
     } else {
         $this->profile = $cur->getProfile();
     }
     $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, 'group_id' => $this->group->id));
     if (empty($this->request)) {
         // TRANS: Client error displayed when trying to approve a non-existing group join request.
         // TRANS: %s is a user nickname.
         $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
     }
     return true;
 }
Example #23
0
 function showResults($q, $page)
 {
     $user_group = new User_group();
     $user_group->limit(($page - 1) * GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1);
     $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
     foreach ($wheres as $where) {
         $where_q = "{$where} like '%" . trim($user_group->escape($q), '\'') . '%\'';
         $user_group->whereAdd($where_q, 'OR');
     }
     $cnt = $user_group->find();
     if ($cnt > 0) {
         $terms = preg_split('/[\\s,]+/', $q);
         $results = new GroupSearchResults($user_group, $terms, $this);
         $results->show();
         $user_group->free();
         $this->pagination($page > 1, $cnt > GROUPS_PER_PAGE, $page, 'groupsearch', array('q' => $q));
     } else {
         $this->element('p', 'error', _('No results.'));
         $this->searchSuggestions($q);
         if (common_logged_in()) {
             $message = _('If you can\'t find the group you\'re looking for, you can [create it](%%action.newgroup%%) yourself.');
         } else {
             $message = _('Why not [register an account](%%action.register%%) and [create the group](%%action.newgroup%%) yourself!');
         }
         $this->elementStart('div', 'guide');
         $this->raw(common_markup_to_html($message));
         $this->elementEnd('div');
         $user_group->free();
     }
 }
Example #24
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('blockto');
     if (empty($id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a to be blocked user profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing profile.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('blockgroup');
     if (empty($group_id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a group to block a profile from.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing group.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while not being an admin user.
         $this->clientError(_('Only an admin can block group members.'), 401);
         return false;
     }
     if (Group_block::isBlocked($this->group, $this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while user is already blocked from the given group.
         $this->clientError(_('User is already blocked from group.'));
         return false;
     }
     // XXX: could have proactive blocks, but we don't have UI for it.
     if (!$this->profile->isMember($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while user is not a member of given group.
         $this->clientError(_('User is not a member of group.'));
         return false;
     }
     return true;
 }
Example #25
0
 function showGroup()
 {
     $this->out->elementStart('li', 'h-card');
     $this->out->elementStart('a', array('title' => $this->group->getBestName(), 'href' => $this->group->homeUrl(), 'rel' => 'contact group', 'class' => 'p-name u-url org'));
     $logo = $this->group->mini_logo ? $this->group->mini_logo : User_group::defaultLogo(AVATAR_MINI_SIZE);
     $this->out->element('img', array('src' => $logo, 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', 'alt' => $this->group->getBestName()));
     $this->out->elementEnd('a');
     $this->out->elementEnd('li');
 }
Example #26
0
 public function getProfile()
 {
     $group = User_group::getKV('id', $this->group_id);
     if (!$group instanceof User_group) {
         return null;
         // TODO: Throw exception when other code is ready
     }
     return $group->getProfile();
 }
Example #27
0
 function showGroup()
 {
     $this->out->elementStart('li', 'vcard');
     $this->out->elementStart('a', array('title' => $this->group->fullname ? $this->group->fullname : $this->group->nickname, 'href' => $this->group->homeUrl(), 'rel' => 'contact group', 'class' => 'url'));
     $logo = $this->group->mini_logo ? $this->group->mini_logo : User_group::defaultLogo(AVATAR_MINI_SIZE);
     $this->out->element('img', array('src' => $logo, 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', 'alt' => $this->group->fullname ? $this->group->fullname : $this->group->nickname));
     $this->out->element('span', 'fn org nickname', $this->group->nickname);
     $this->out->elementEnd('a');
     $this->out->elementEnd('li');
 }
Example #28
0
 function getGroup()
 {
     $group = User_group::getKV('id', $this->group_id);
     if (empty($group)) {
         // TRANS: Exception thrown providing an invalid group ID.
         // TRANS: %s is the invalid group ID.
         throw new Exception(sprintf(_("Group ID %s is invalid."), $this->group_id));
     }
     return $group;
 }
Example #29
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to join a group while not logged in.
         $this->clientError(_('You must be logged in to join a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error displayed when trying to join a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error displayed when trying to join a group without providing a group name or group ID.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed when trying to join a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if ($cur->isMember($this->group)) {
         // TRANS: Client error displayed when trying to join a group while already a member.
         $this->clientError(_('You are already a member of that group.'), 403);
         return false;
     }
     if (Group_block::isBlocked($this->group, $cur->getProfile())) {
         // TRANS: Client error displayed when trying to join a group while being blocked form joining it.
         $this->clientError(_('You have been blocked from that group by the admin.'), 403);
         return false;
     }
     return true;
 }
Example #30
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('profileid');
     if (empty($id)) {
         // TRANS: Client error displayed when not providing a profile ID on the Make Admin page.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed when specifying an invalid profile ID on the Make Admin page.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('groupid');
     if (empty($group_id)) {
         // TRANS: Client error displayed when not providing a group ID on the Make Admin page.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed when providing an invalid group ID on the Make Admin page.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group) && !$user->hasRight(Right::MAKEGROUPADMIN)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page while not an admin.
         $this->clientError(_('Only an admin can make another user an admin.'), 401);
         return false;
     }
     if ($this->profile->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page who already is admin.
         // TRANS: %1$s is the user that is already admin, %2$s is the group user is already admin for.
         $this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401);
         return false;
     }
     return true;
 }