ToSelector widget to send private notices
A new widget, ToSelector (Sorry, couldn't think of anything better) that lets you select an addressee for a notice and whether it's private.
This commit is contained in:
parent
133def8370
commit
5147404ea2
@ -209,6 +209,10 @@ class NewnoticeAction extends Action
|
|||||||
$author_id = $user->id;
|
$author_id = $user->id;
|
||||||
$text = $content_shortened;
|
$text = $content_shortened;
|
||||||
|
|
||||||
|
// Does the heavy-lifting for getting "To:" information
|
||||||
|
|
||||||
|
ToSelector::fillOptions($this, $options);
|
||||||
|
|
||||||
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
|
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
|
||||||
|
|
||||||
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
|
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
|
||||||
|
@ -79,6 +79,15 @@ class NoticeForm extends Form
|
|||||||
var $location_id;
|
var $location_id;
|
||||||
var $location_ns;
|
var $location_ns;
|
||||||
|
|
||||||
|
/** select this group from the drop-down by default. */
|
||||||
|
var $to_group;
|
||||||
|
|
||||||
|
/** select this user from the drop-down by default. */
|
||||||
|
var $to_user;
|
||||||
|
|
||||||
|
/** Pre-click the private checkbox. */
|
||||||
|
var $private;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -109,7 +118,8 @@ class NoticeForm extends Form
|
|||||||
$this->actionName = $action->trimmed('action');
|
$this->actionName = $action->trimmed('action');
|
||||||
|
|
||||||
$prefill = array('content', 'inreplyto', 'lat',
|
$prefill = array('content', 'inreplyto', 'lat',
|
||||||
'lon', 'location_id', 'location_ns');
|
'lon', 'location_id', 'location_ns',
|
||||||
|
'to_group', 'to_profile', 'private');
|
||||||
|
|
||||||
foreach ($prefill as $fieldName) {
|
foreach ($prefill as $fieldName) {
|
||||||
if (array_key_exists($fieldName, $options)) {
|
if (array_key_exists($fieldName, $options)) {
|
||||||
@ -117,6 +127,16 @@ class NoticeForm extends Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefill the profile if we're replying
|
||||||
|
|
||||||
|
if (empty($this->to_profile) &&
|
||||||
|
!empty($this->inreplyto)) {
|
||||||
|
$notice = Notice::staticGet('id', $this->inreplyto);
|
||||||
|
if (!empty($notice)) {
|
||||||
|
$this->to_profile = $notice->getProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists('user', $options)) {
|
if (array_key_exists('user', $options)) {
|
||||||
$this->user = $options['user'];
|
$this->user = $options['user'];
|
||||||
} else {
|
} else {
|
||||||
@ -218,6 +238,14 @@ class NoticeForm extends Form
|
|||||||
}
|
}
|
||||||
$this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
|
$this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
|
||||||
|
|
||||||
|
$this->out->elementStart('div');
|
||||||
|
$toWidget = new ToSelector($this->out,
|
||||||
|
$this->user,
|
||||||
|
(!empty($this->to_group) ? $this->to_group : $this->to_user));
|
||||||
|
|
||||||
|
$toWidget->show();
|
||||||
|
$this->out->elementEnd('div');
|
||||||
|
|
||||||
if ($this->user->shareLocation()) {
|
if ($this->user->shareLocation()) {
|
||||||
$this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
|
$this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
|
||||||
$this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
|
$this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
|
||||||
|
156
lib/toselector.php
Normal file
156
lib/toselector.php
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* StatusNet - the distributed open-source microblogging tool
|
||||||
|
* 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
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @category Widget
|
||||||
|
* @package StatusNet
|
||||||
|
* @author Evan Prodromou <evan@status.net>
|
||||||
|
* @copyright 2011 StatusNet, Inc.
|
||||||
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
|
* @link http://status.net/
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('STATUSNET')) {
|
||||||
|
// This check helps protect against security problems;
|
||||||
|
// your code file can't be executed directly from the web.
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget showing a drop-down of potential addressees
|
||||||
|
*
|
||||||
|
* @category Widget
|
||||||
|
* @package StatusNet
|
||||||
|
* @author Evan Prodromou <evan@status.net>
|
||||||
|
* @copyright 2011 StatusNet, Inc.
|
||||||
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
|
* @link http://status.net/
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ToSelector extends Widget
|
||||||
|
{
|
||||||
|
protected $user;
|
||||||
|
protected $to;
|
||||||
|
protected $id;
|
||||||
|
protected $name;
|
||||||
|
protected $private;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param HTMLOutputter $out output context
|
||||||
|
* @param User $user Current user
|
||||||
|
* @param mixed $to Default selection for addressee
|
||||||
|
*/
|
||||||
|
function __construct($out, $user, $to, $private=false, $id='notice_to', $name='notice_to')
|
||||||
|
{
|
||||||
|
parent::__construct($out);
|
||||||
|
|
||||||
|
$this->user = $user;
|
||||||
|
$this->to = $to;
|
||||||
|
$this->private = $private;
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param HTMLOutputter $out output context
|
||||||
|
* @param User $user Current user
|
||||||
|
* @param mixed $to Default selection for addressee
|
||||||
|
*/
|
||||||
|
function show()
|
||||||
|
{
|
||||||
|
$choices = array();
|
||||||
|
$default = 'public:site';
|
||||||
|
|
||||||
|
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;
|
||||||
|
if (($this->to instanceof User_group) && $this->to->id == $groups->id) {
|
||||||
|
$default = $value;
|
||||||
|
}
|
||||||
|
$choices[$value] = $groups->getBestName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX: add users...?
|
||||||
|
|
||||||
|
if ($this->to instanceof Profile) {
|
||||||
|
$value = 'profile:'.$this->to->id;
|
||||||
|
$default = $value;
|
||||||
|
$choices[$value] = $this->to->getBestName();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out->dropdown($this->id,
|
||||||
|
_('To:'),
|
||||||
|
$choices,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
$default);
|
||||||
|
|
||||||
|
$this->out->checkbox('notice_private',
|
||||||
|
_('Private'),
|
||||||
|
$this->private);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function fillOptions($action, &$options)
|
||||||
|
{
|
||||||
|
// XXX: make arg name selectable
|
||||||
|
$toArg = $action->trimmed('notice_to');
|
||||||
|
$private = $action->boolean('notice_private');
|
||||||
|
|
||||||
|
list($prefix, $value) = explode(':', $toArg);
|
||||||
|
switch ($prefix) {
|
||||||
|
case 'group':
|
||||||
|
$options['groups'] = array($value);
|
||||||
|
if ($private) {
|
||||||
|
$options['scope'] = Notice::GROUP_SCOPE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'profile':
|
||||||
|
$profile = Profile::staticGet('id', $value);
|
||||||
|
$options['replies'] = $profile->getUri();
|
||||||
|
if ($private) {
|
||||||
|
$options['scope'] = Notice::ADDRESSEE_SCOPE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'public':
|
||||||
|
if ($value == 'everyone' && !common_config('site', 'private')) {
|
||||||
|
$options['scope'] = 0;
|
||||||
|
} else if ($value == 'site') {
|
||||||
|
$options['scope'] = Notice::SITE_SCOPE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ClientException('Unknown to value: ' . toArg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user