forked from GNUsocial/gnu-social
A bunch of FormAction and ManagedAction synchronization
This commit is contained in:
parent
55894f02c7
commit
1ea876296d
@ -43,23 +43,17 @@ class CancelsubscriptionAction extends FormAction
|
|||||||
{
|
{
|
||||||
protected $needPost = true;
|
protected $needPost = true;
|
||||||
|
|
||||||
protected function prepare(array $args=array())
|
protected function doPreparation()
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
|
||||||
|
|
||||||
$profile_id = $this->int('unsubscribeto');
|
$profile_id = $this->int('unsubscribeto');
|
||||||
$this->target = Profile::getKV('id', $profile_id);
|
$this->target = Profile::getKV('id', $profile_id);
|
||||||
if (!$this->target instanceof Profile) {
|
if (!$this->target instanceof Profile) {
|
||||||
throw new NoProfileException($profile_id);
|
throw new NoProfileException($profile_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id,
|
$request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id,
|
||||||
'subscribed' => $this->target->id));
|
'subscribed' => $this->target->id));
|
||||||
@ -82,10 +76,7 @@ class CancelsubscriptionAction extends FormAction
|
|||||||
$this->elementEnd('body');
|
$this->elementEnd('body');
|
||||||
$this->endHTML();
|
$this->endHTML();
|
||||||
exit();
|
exit();
|
||||||
} else {
|
|
||||||
common_redirect(common_local_url('subscriptions',
|
|
||||||
array('nickname' => $this->scoped->nickname)),
|
|
||||||
303);
|
|
||||||
}
|
}
|
||||||
|
common_redirect(common_local_url('subscriptions', array('nickname' => $this->scoped->getNickname())), 303);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,10 +61,8 @@ class LoginAction extends FormAction
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
// XXX: login throttle
|
// XXX: login throttle
|
||||||
|
|
||||||
$nickname = $this->trimmed('nickname');
|
$nickname = $this->trimmed('nickname');
|
||||||
@ -104,22 +102,6 @@ class LoginAction extends FormAction
|
|||||||
common_redirect($url, 303);
|
common_redirect($url, 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Store an error and show the page
|
|
||||||
*
|
|
||||||
* This used to show the whole page; now, it's just a wrapper
|
|
||||||
* that stores the error in an attribute.
|
|
||||||
*
|
|
||||||
* @param string $error error, if any.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function showForm($msg=null, $success=false)
|
|
||||||
{
|
|
||||||
common_ensure_session();
|
|
||||||
return parent::showForm($msg, $success);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showScripts()
|
function showScripts()
|
||||||
{
|
{
|
||||||
parent::showScripts();
|
parent::showScripts();
|
||||||
|
@ -61,27 +61,15 @@ class NewApplicationAction extends FormAction
|
|||||||
$this->clientError(_('Unexpected form submission.'));
|
$this->clientError(_('Unexpected form submission.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function showForm($msg=null)
|
protected function getForm()
|
||||||
{
|
{
|
||||||
$this->msg = $msg;
|
return new ApplicationEditForm($this);
|
||||||
$this->showPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showContent()
|
public function getInstructions()
|
||||||
{
|
{
|
||||||
$form = new ApplicationEditForm($this);
|
// TRANS: Form instructions for registering a new application.
|
||||||
$form->show();
|
return _('Use this form to register a new application.');
|
||||||
}
|
|
||||||
|
|
||||||
function showPageNotice()
|
|
||||||
{
|
|
||||||
if ($this->msg) {
|
|
||||||
$this->element('p', 'error', $this->msg);
|
|
||||||
} else {
|
|
||||||
$this->element('p', 'instructions',
|
|
||||||
// TRANS: Form instructions for registering a new application.
|
|
||||||
_('Use this form to register a new application.'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function trySave()
|
private function trySave()
|
||||||
|
@ -29,9 +29,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new group
|
* Add a new group
|
||||||
@ -48,6 +46,8 @@ class NewgroupAction extends FormAction
|
|||||||
{
|
{
|
||||||
protected $group;
|
protected $group;
|
||||||
|
|
||||||
|
protected $form = 'GroupEdit';
|
||||||
|
|
||||||
function getGroup() {
|
function getGroup() {
|
||||||
return $this->group;
|
return $this->group;
|
||||||
}
|
}
|
||||||
@ -58,39 +58,23 @@ class NewgroupAction extends FormAction
|
|||||||
return _('New group');
|
return _('New group');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function doPreparation()
|
||||||
* Prepare to run
|
|
||||||
*/
|
|
||||||
protected function prepare(array $args=array())
|
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
|
||||||
|
|
||||||
// $this->scoped is the current user profile
|
// $this->scoped is the current user profile
|
||||||
if (!$this->scoped->hasRight(Right::CREATEGROUP)) {
|
if (!$this->scoped->hasRight(Right::CREATEGROUP)) {
|
||||||
// TRANS: Client exception thrown when a user tries to create a group while banned.
|
// TRANS: Client exception thrown when a user tries to create a group while banned.
|
||||||
$this->clientError(_('You are not allowed to create groups on this site.'), 403);
|
$this->clientError(_('You are not allowed to create groups on this site.'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showContent()
|
protected function getInstructions()
|
||||||
{
|
{
|
||||||
$form = new GroupEditForm($this);
|
// TRANS: Form instructions for group create form.
|
||||||
$form->show();
|
return _('Use this form to create a new group.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showInstructions()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
$this->element('p', 'instructions',
|
|
||||||
// TRANS: Form instructions for group create form.
|
|
||||||
_('Use this form to create a new group.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function handlePost()
|
|
||||||
{
|
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
if (Event::handle('StartGroupSaveForm', array($this))) {
|
if (Event::handle('StartGroupSaveForm', array($this))) {
|
||||||
$nickname = Nickname::normalize($this->trimmed('newnickname'), true);
|
$nickname = Nickname::normalize($this->trimmed('newnickname'), true);
|
||||||
|
|
||||||
@ -133,7 +117,6 @@ class NewgroupAction extends FormAction
|
|||||||
'Too many aliases! Maximum %d allowed.',
|
'Too many aliases! Maximum %d allowed.',
|
||||||
common_config('group', 'maxaliases')),
|
common_config('group', 'maxaliases')),
|
||||||
common_config('group', 'maxaliases')));
|
common_config('group', 'maxaliases')));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($private) {
|
if ($private) {
|
||||||
|
@ -30,9 +30,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for posting new notices
|
* Action for posting new notices
|
||||||
@ -83,7 +81,7 @@ class NewnoticeAction extends FormAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This handlePost saves a new notice, based on arguments
|
* This doPost saves a new notice, based on arguments
|
||||||
*
|
*
|
||||||
* If successful, will show the notice, or return an Ajax-y result.
|
* If successful, will show the notice, or return an Ajax-y result.
|
||||||
* If not, it will show an error message -- possibly Ajax-y.
|
* If not, it will show an error message -- possibly Ajax-y.
|
||||||
@ -93,17 +91,15 @@ class NewnoticeAction extends FormAction
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
||||||
|
|
||||||
assert($this->scoped); // XXX: maybe an error instead...
|
|
||||||
$user = $this->scoped->getUser();
|
$user = $this->scoped->getUser();
|
||||||
$content = $this->trimmed('status_textarea');
|
$content = $this->trimmed('status_textarea');
|
||||||
$options = array();
|
$options = array();
|
||||||
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
|
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
|
||||||
|
|
||||||
if (!$content) {
|
if (empty($content)) {
|
||||||
// TRANS: Client error displayed trying to send a notice without content.
|
// TRANS: Client error displayed trying to send a notice without content.
|
||||||
$this->clientError(_('No content!'));
|
$this->clientError(_('No content!'));
|
||||||
}
|
}
|
||||||
|
@ -40,15 +40,16 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
|||||||
*/
|
*/
|
||||||
class RepeatAction extends FormAction
|
class RepeatAction extends FormAction
|
||||||
{
|
{
|
||||||
protected $needPost = true; // At least for now, until repeat interface is available
|
|
||||||
|
|
||||||
protected $notice = null; // Notice that is being repeated.
|
protected $notice = null; // Notice that is being repeated.
|
||||||
protected $repeat = null; // The resulting repeat object/notice.
|
protected $repeat = null; // The resulting repeat object/notice.
|
||||||
|
|
||||||
protected function prepare(array $args=array())
|
function title()
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
return _m('TITLE', 'Repeat notice');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doPreparation()
|
||||||
|
{
|
||||||
$id = $this->trimmed('notice');
|
$id = $this->trimmed('notice');
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
|
@ -27,9 +27,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form action extendable class
|
* Form action extendable class
|
||||||
@ -125,8 +123,6 @@ class FormAction extends ManagedAction
|
|||||||
*/
|
*/
|
||||||
protected function handlePost()
|
protected function handlePost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
// check for this before token since all POST and FILES data
|
// check for this before token since all POST and FILES data
|
||||||
// is losts when size is exceeded
|
// is losts when size is exceeded
|
||||||
if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
|
if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
|
||||||
@ -138,6 +134,6 @@ class FormAction extends ManagedAction
|
|||||||
throw new ClientException($msg);
|
throw new ClientException($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkSessionToken();
|
return parent::handlePost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,27 @@ class ManagedAction extends Action
|
|||||||
$this->showPage();
|
$this->showPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is extended in child classes, they should
|
||||||
|
* end with 'return parent::handlePost();' - and they
|
||||||
|
* should only extend this function if what they do
|
||||||
|
* cannot be handled in ->doPost()
|
||||||
|
*/
|
||||||
protected function handlePost()
|
protected function handlePost()
|
||||||
{
|
{
|
||||||
// This will only be run if the Action has the property canPost==true
|
// This will only be run if the Action has the property canPost==true
|
||||||
assert($this->canPost);
|
assert($this->canPost);
|
||||||
|
|
||||||
|
$this->checkSessionToken();
|
||||||
|
return $this->doPost();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do Post stuff. Return a string if successful,
|
||||||
|
* describing what has been done. Always throw an
|
||||||
|
* exception on failure, with a descriptive message.
|
||||||
|
*/
|
||||||
|
protected function doPost() {
|
||||||
|
throw new Exception('Unhandled POST');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for posting new direct messages
|
* Action for posting new direct messages
|
||||||
@ -52,7 +50,7 @@ class NewmessageAction extends FormAction
|
|||||||
var $to = null;
|
var $to = null;
|
||||||
var $other = null;
|
var $other = null;
|
||||||
|
|
||||||
protected $form = 'message'; // will become MessageForm later
|
protected $form = 'Message'; // will become MessageForm later
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the page
|
* Title of the page
|
||||||
@ -68,18 +66,8 @@ class NewmessageAction extends FormAction
|
|||||||
return _('New message');
|
return _('New message');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function doPreparation()
|
||||||
* Handle input, produce output
|
|
||||||
*
|
|
||||||
* @param array $args $_REQUEST contents
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected function prepare(array $args=array())
|
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
|
||||||
|
|
||||||
$this->content = $this->trimmed('content');
|
$this->content = $this->trimmed('content');
|
||||||
$this->to = $this->trimmed('to');
|
$this->to = $this->trimmed('to');
|
||||||
|
|
||||||
@ -107,29 +95,27 @@ class NewmessageAction extends FormAction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
||||||
|
|
||||||
if (!$this->content) {
|
if (empty($this->content)) {
|
||||||
// TRANS: Form validator error displayed trying to send a direct message without content.
|
// TRANS: Form validator error displayed trying to send a direct message without content.
|
||||||
$this->clientError(_('No content!'));
|
$this->clientError(_('No content!'));
|
||||||
} else {
|
|
||||||
$content_shortened = $this->scoped->shortenLinks($this->content);
|
|
||||||
|
|
||||||
if (Message::contentTooLong($content_shortened)) {
|
|
||||||
// TRANS: Form validation error displayed when message content is too long.
|
|
||||||
// TRANS: %d is the maximum number of characters for a message.
|
|
||||||
$this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
|
|
||||||
'That\'s too long. Maximum message size is %d characters.',
|
|
||||||
Message::maxContent()),
|
|
||||||
Message::maxContent()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->other) {
|
$content_shortened = $this->scoped->shortenLinks($this->content);
|
||||||
|
|
||||||
|
if (Message::contentTooLong($content_shortened)) {
|
||||||
|
// TRANS: Form validation error displayed when message content is too long.
|
||||||
|
// TRANS: %d is the maximum number of characters for a message.
|
||||||
|
$this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
|
||||||
|
'That\'s too long. Maximum message size is %d characters.',
|
||||||
|
Message::maxContent()),
|
||||||
|
Message::maxContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->other instanceof Profile) {
|
||||||
// TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
|
// TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
|
||||||
$this->clientError(_('No recipient specified.'));
|
$this->clientError(_('No recipient specified.'));
|
||||||
} else if (!$this->scoped->mutuallySubscribed($this->other)) {
|
} else if (!$this->scoped->mutuallySubscribed($this->other)) {
|
||||||
@ -145,86 +131,18 @@ class NewmessageAction extends FormAction
|
|||||||
$message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
|
$message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
|
||||||
$message->notify();
|
$message->notify();
|
||||||
|
|
||||||
if ($this->boolean('ajax')) {
|
if (GNUsocial::isAjax()) {
|
||||||
$this->startHTML('text/xml;charset=utf-8');
|
// TRANS: Confirmation text after sending a direct message.
|
||||||
$this->elementStart('head');
|
// TRANS: %s is the direct message recipient.
|
||||||
// TRANS: Page title after sending a direct message.
|
return sprintf(_('Direct message to %s sent.'), $this->other->getNickname());
|
||||||
$this->element('title', null, _('Message sent'));
|
|
||||||
$this->elementEnd('head');
|
|
||||||
$this->elementStart('body');
|
|
||||||
$this->element('p', array('id' => 'command_result'),
|
|
||||||
// TRANS: Confirmation text after sending a direct message.
|
|
||||||
// TRANS: %s is the direct message recipient.
|
|
||||||
sprintf(_('Direct message to %s sent.'),
|
|
||||||
$this->other->nickname));
|
|
||||||
$this->elementEnd('body');
|
|
||||||
$this->endHTML();
|
|
||||||
} else {
|
|
||||||
$url = common_local_url('outbox',
|
|
||||||
array('nickname' => $this->scoped->nickname));
|
|
||||||
common_redirect($url, 303);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
|
||||||
|
common_redirect($url, 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show an Ajax-y error message
|
|
||||||
*
|
|
||||||
* Goes back to the browser, where it's shown in a popup.
|
|
||||||
*
|
|
||||||
* @param string $msg Message to show
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
|
|
||||||
function ajaxErrorMsg($msg)
|
|
||||||
{
|
|
||||||
$this->startHTML('text/xml;charset=utf-8', true);
|
|
||||||
$this->elementStart('head');
|
|
||||||
// TRANS: Page title after an AJAX error occurred on the "send direct message" page.
|
|
||||||
$this->element('title', null, _('Ajax Error'));
|
|
||||||
$this->elementEnd('head');
|
|
||||||
$this->elementStart('body');
|
|
||||||
$this->element('p', array('id' => 'error'), $msg);
|
|
||||||
$this->elementEnd('body');
|
|
||||||
$this->endHTML();
|
|
||||||
}
|
|
||||||
|
|
||||||
function showForm($msg = null)
|
|
||||||
{
|
|
||||||
if ($msg && $this->boolean('ajax')) {
|
|
||||||
$this->ajaxErrorMsg($msg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->msg = $msg;
|
|
||||||
if ($this->trimmed('ajax')) {
|
|
||||||
$this->startHTML('text/xml;charset=utf-8');
|
|
||||||
$this->elementStart('head');
|
|
||||||
// TRANS: Page title on page for sending a direct message.
|
|
||||||
$this->element('title', null, _('New message'));
|
|
||||||
$this->elementEnd('head');
|
|
||||||
$this->elementStart('body');
|
|
||||||
$this->showNoticeForm();
|
|
||||||
$this->elementEnd('body');
|
|
||||||
$this->endHTML();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->showPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPageNotice()
|
|
||||||
{
|
|
||||||
if ($this->msg) {
|
|
||||||
$this->element('p', 'error', $this->msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do nothing (override)
|
|
||||||
|
|
||||||
function showNoticeForm()
|
function showNoticeForm()
|
||||||
{
|
{
|
||||||
$message_form = new MessageForm($this, $this->other, $this->content);
|
// Just don't show a NoticeForm
|
||||||
$message_form->show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,48 +44,41 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
|||||||
*/
|
*/
|
||||||
class DisfavorAction extends FormAction
|
class DisfavorAction extends FormAction
|
||||||
{
|
{
|
||||||
public function showForm($msg=null, $success=false)
|
protected $needPost = true;
|
||||||
|
|
||||||
|
protected function doPreparation()
|
||||||
{
|
{
|
||||||
if ($success) {
|
$this->target = Notice::getKV($this->trimmed('notice'));
|
||||||
common_redirect(common_local_url('showfavorites',
|
if (!$this->target instanceof Notice) {
|
||||||
array('nickname' => $this->scoped->nickname)), 303);
|
throw new ServerException(_m('No such notice.'));
|
||||||
}
|
}
|
||||||
parent::showForm($msg, $success);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
$id = $this->trimmed('notice');
|
|
||||||
$notice = Notice::getKV($id);
|
|
||||||
if (!$notice instanceof Notice) {
|
|
||||||
$this->serverError(_('Notice not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$fave = new Fave();
|
$fave = new Fave();
|
||||||
$fave->user_id = $this->scoped->id;
|
$fave->user_id = $this->scoped->getID();
|
||||||
$fave->notice_id = $notice->id;
|
$fave->notice_id = $this->target->getID();
|
||||||
if (!$fave->find(true)) {
|
if (!$fave->find(true)) {
|
||||||
throw new NoResultException($fave);
|
// TRANS: Client error displayed when trying to remove a 'favor' when there is none in the first place.
|
||||||
|
throw new AlreadyFulfilledException(_('This is already not favorited.'));
|
||||||
}
|
}
|
||||||
$result = $fave->delete();
|
$result = $fave->delete();
|
||||||
if (!$result) {
|
if ($result === false) {
|
||||||
common_log_db_error($fave, 'DELETE', __FILE__);
|
common_log_db_error($fave, 'DELETE', __FILE__);
|
||||||
// TRANS: Server error displayed when removing a favorite from the database fails.
|
// TRANS: Server error displayed when removing a favorite from the database fails.
|
||||||
$this->serverError(_('Could not delete favorite.'));
|
throw new ServerException(_('Could not delete favorite.'));
|
||||||
}
|
|
||||||
Fave::blowCacheForProfileId($this->scoped->id);
|
|
||||||
if (GNUsocial::isAjax()) {
|
|
||||||
$this->startHTML('text/xml;charset=utf-8');
|
|
||||||
$this->elementStart('head');
|
|
||||||
// TRANS: Title for page on which favorites can be added.
|
|
||||||
$this->element('title', null, _('Add to favorites'));
|
|
||||||
$this->elementEnd('head');
|
|
||||||
$this->elementStart('body');
|
|
||||||
$favor = new FavorForm($this, $notice);
|
|
||||||
$favor->show();
|
|
||||||
$this->elementEnd('body');
|
|
||||||
$this->endHTML();
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
Fave::blowCacheForProfileId($this->scoped->getID());
|
||||||
|
|
||||||
|
// TRANS: Message when a disfavor action has been taken for a notice.
|
||||||
|
return _('Disfavored the notice.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showContent()
|
||||||
|
{
|
||||||
|
// We show the 'Favor' form because right now all calls to Disfavor will directly disfavor a notice.
|
||||||
|
$disfavor = new FavorForm($this, $this->target);
|
||||||
|
$disfavor->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,29 +46,21 @@ class FavorAction extends FormAction
|
|||||||
{
|
{
|
||||||
protected $needPost = true;
|
protected $needPost = true;
|
||||||
|
|
||||||
protected $object = null;
|
protected function doPreparation()
|
||||||
|
|
||||||
protected function prepare(array $args=array())
|
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
|
||||||
|
|
||||||
$this->target = Notice::getKV($this->trimmed('notice'));
|
$this->target = Notice::getKV($this->trimmed('notice'));
|
||||||
if (!$this->target instanceof Notice) {
|
if (!$this->target instanceof Notice) {
|
||||||
throw new ServerException(_m('No such notice.'));
|
throw new ServerException(_m('No such notice.'));
|
||||||
}
|
}
|
||||||
if (!$this->target->inScope($this->scoped)) {
|
if (!$this->target->inScope($this->scoped)) {
|
||||||
// TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
|
// TRANS: Client error displayed when trying to interact with a notice a the target has no access to.
|
||||||
// TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
|
// TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
|
||||||
throw new ClientException(sprintf(_m('%1$s has no right to reply to notice %2$d.'), $this->scoped->getNickname(), $this->target->id), 403);
|
throw new ClientException(sprintf(_m('%1$s has no right to interact with notice %2$d.'), $this->scoped->getNickname(), $this->target->getID()), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePost()
|
protected function doPost()
|
||||||
{
|
{
|
||||||
parent::handlePost();
|
|
||||||
|
|
||||||
if (Fave::existsForProfile($this->target, $this->scoped)) {
|
if (Fave::existsForProfile($this->target, $this->scoped)) {
|
||||||
// TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
|
// TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
|
||||||
throw new AlreadyFulfilledException(_('You have already favorited this!'));
|
throw new AlreadyFulfilledException(_('You have already favorited this!'));
|
||||||
@ -77,14 +69,13 @@ class FavorAction extends FormAction
|
|||||||
// throws exception on failure
|
// throws exception on failure
|
||||||
$stored = Fave::addNew($this->scoped, $this->target);
|
$stored = Fave::addNew($this->scoped, $this->target);
|
||||||
|
|
||||||
|
// TRANS: Message when a favor action has been taken for a notice.
|
||||||
return _('Favorited the notice');
|
return _('Favorited the notice');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function showContent()
|
protected function showContent()
|
||||||
{
|
{
|
||||||
if ($this->target instanceof Notice) {
|
$disfavor = new DisfavorForm($this, $this->target);
|
||||||
$disfavor = new DisfavorForm($this, $this->target);
|
$disfavor->show();
|
||||||
$disfavor->show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user