X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ftoselector.php;h=7a959ff8b518e9e48ba23d997fbc651a3294803f;hb=349e842078c5d69901df6ec9205cf7edcb4c4636;hp=6dd4b5c9f4bfaa174f4d7db8ac18fe5d78428b12;hpb=e862dcdb8a9cfc21cf00513d76f40d20dd3b1b7a;p=quix0rs-gnu-social.git diff --git a/lib/toselector.php b/lib/toselector.php index 6dd4b5c9f4..7a959ff8b5 100644 --- a/lib/toselector.php +++ b/lib/toselector.php @@ -4,7 +4,7 @@ * Copyright (C) 2011, StatusNet, Inc. * * Widget showing a drop-down of potential addressees - * + * * PHP version 5 * * This program is free software: you can redistribute it and/or modify @@ -44,7 +44,6 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - class ToSelector extends Widget { protected $user; @@ -81,50 +80,106 @@ class ToSelector extends Widget function show() { $choices = array(); - $default = 'public:site'; + $default = common_config('site', 'private') ? 'public:site' : 'public:everyone'; - if (!common_config('site', 'private')) { - $choices['public:everyone'] = _('Everyone'); - $default = 'public:everyone'; - } - // XXX: better name...? - $choices['public:site'] = sprintf(_('My colleagues at %s'), common_config('site', 'name')); - $groups = $this->user->getGroups(); - while ($groups->fetch()) { - $value = 'group:'.$groups->id; + while ($groups instanceof User_group && $groups->fetch()) { + $value = 'group:'.$groups->getID(); if (($this->to instanceof User_group) && $this->to->id == $groups->id) { $default = $value; } - $choices[$value] = $groups->getBestName(); + $choices[$value] = "!{$groups->getNickname()} [{$groups->getBestName()}]"; } - // XXX: add users...? + // Add subscribed users to dropdown menu + $users = $this->user->getSubscribed(); + while ($users->fetch()) { + $value = 'profile:'.$users->getID(); + try { + $choices[$value] = substr($users->getAcctUri(), 5) . " [{$users->getBestName()}]"; + } catch (ProfileNoAcctUriException $e) { + $choices[$value] = "[?@?] " . $e->profile->getBestName(); + } + } if ($this->to instanceof Profile) { - $value = 'profile:'.$this->to->id; + $value = 'profile:'.$this->to->getID(); $default = $value; - $choices[$value] = $this->to->getBestName(); + try { + $choices[$value] = substr($this->to->getAcctUri(), 5) . " [{$this->to->getBestName()}]"; + } catch (ProfileNoAcctUriException $e) { + $choices[$value] = "[?@?] " . $e->profile->getBestName(); + } + } + + // alphabetical order + asort($choices); + + // Reverse so we can add entries at the end (can't unshift with a key) + $choices = array_reverse($choices); + + if (common_config('notice', 'allowprivate')) { + // TRANS: Option in drop-down of potential addressees. + // TRANS: %s is a StatusNet sitename. + $choices['public:site'] = sprintf(_('Everyone at %s'), common_config('site', 'name')); + } + + if (!common_config('site', 'private')) { + // TRANS: Option in drop-down of potential addressees. + $choices['public:everyone'] = _m('SENDTO','Everyone'); } + // Return the order + $choices = array_reverse($choices); + $this->out->dropdown($this->id, - _('To:'), + // TRANS: Label for drop-down of potential addressees. + _m('LABEL','To:'), $choices, null, false, $default); - $this->out->checkbox('notice_private', - _('Private'), - $this->private); + $this->out->elementStart('span', 'checkbox-wrapper'); + if (common_config('notice', 'allowprivate')) { + $this->out->checkbox('notice_private', + // TRANS: Checkbox label in widget for selecting potential addressees to mark the notice private. + _('Private?'), + $this->private); + } + $this->out->elementEnd('span'); + } + + static function fillActivity(Action $action, Activity $act, array &$options) + { + if (!$act->context instanceof ActivityContext) { + $act->context = new ActivityContext(); + } + self::fillOptions($action, $options); + if (isset($options['groups'])) { + foreach ($options['groups'] as $group_id) { + $group = User_group::getByID($group_id); + $act->context->attention[$group->getUri()] = $group->getObjectType(); + } + } + if (isset($options['replies'])) { + foreach ($options['replies'] as $profile_uri) { + $profile = Profile::fromUri($profile_uri); + $act->context->attention[$profile->getUri()] = $profile->getObjectType(); + } + } } static function fillOptions($action, &$options) { // XXX: make arg name selectable $toArg = $action->trimmed('notice_to'); - $private = $action->boolean('notice_private'); + $private = common_config('notice', 'allowprivate') ? $action->boolean('notice_private') : false; + + if (empty($toArg)) { + return; + } list($prefix, $value) = explode(':', $toArg); switch ($prefix) { @@ -135,8 +190,8 @@ class ToSelector extends Widget } break; case 'profile': - $profile = Profile::staticGet('id', $value); - $options['replies'] = $profile->getUri(); + $profile = Profile::getKV('id', $value); + $options['replies'] = array($profile->getUri()); if ($private) { $options['scope'] = Notice::ADDRESSEE_SCOPE; } @@ -149,7 +204,8 @@ class ToSelector extends Widget } break; default: - throw new ClientException('Unknown to value: ' . toArg); + // TRANS: Client exception thrown in widget for selecting potential addressees when an invalid fill option was received. + throw new ClientException(sprintf(_('Unknown to value: "%s".'),$toArg)); break; } }