Includes some minor changes to other things as well, such as the session
token input element now having the same 'name' attribute as everyone else.
(it still retains a 'token-'+noticeid 'id' attribute for clientside JS)
* PHP version 5
*
* @category Action
* PHP version 5
*
* @category Action
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
* 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') && !defined('LACONICA')) {
- exit(1);
-}
-
-require_once INSTALLDIR.'/lib/favorform.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
+ * DisfavorAction class.
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
-class DisfavorAction extends Action
+class DisfavorAction extends FormAction
- /**
- * Class handler.
- *
- * @param array $args query arguments
- *
- * @return void
- */
- function handle($args)
+ public function showForm($msg=null, $success=false)
- parent::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.'));
- return;
- }
- $user = common_current_user();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
common_redirect(common_local_url('showfavorites',
common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)));
- return;
+ array('nickname' => $this->scoped->nickname)), 303);
+ parent::showForm($msg, $success);
+ }
+
+ protected function handlePost()
+ {
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
- $token = $this->trimmed('token-'.$notice->id);
- if (!$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;
+ if (!$notice instanceof Notice) {
+ $this->serverError(_('Notice not found'));
- $fave->user_id = $user->id;
+ $fave->user_id = $this->scoped->id;
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
- // TRANS: Client error displayed when trying to remove favorite status for a notice that is not a favorite.
- $this->clientError(_('This notice is not a favorite!'));
- return;
+ throw new NoResultException($fave);
}
$result = $fave->delete();
if (!$result) {
common_log_db_error($fave, 'DELETE', __FILE__);
// TRANS: Server error displayed when removing a favorite from the database fails.
$this->serverError(_('Could not delete favorite.'));
}
$result = $fave->delete();
if (!$result) {
common_log_db_error($fave, 'DELETE', __FILE__);
// TRANS: Server error displayed when removing a favorite from the database fails.
$this->serverError(_('Could not delete favorite.'));
- $user->blowFavesCache();
- if ($this->boolean('ajax')) {
+ $this->scoped->blowFavesCache();
+ if (StatusNet::isAjax()) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Title for page on which favorites can be added.
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Title for page on which favorites can be added.
$favor->show();
$this->elementEnd('body');
$this->elementEnd('html');
$favor->show();
$this->elementEnd('body');
$this->elementEnd('html');
- } else {
- common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)),
- 303);
* PHP version 5
*
* @category Action
* PHP version 5
*
* @category Action
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
* 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') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
require_once INSTALLDIR.'/lib/mail.php';
require_once INSTALLDIR.'/lib/mail.php';
-require_once INSTALLDIR.'/lib/disfavorform.php';
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
-class FavorAction extends Action
+class FavorAction extends FormAction
- /**
- * Class handler.
- *
- * @param array $args query arguments
- *
- * @return void
- */
- function handle($args)
+ // We overload this because success should redirect
+ public function showForm($msg=null, $success=false)
- parent::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.'));
- return;
- }
- $user = common_current_user();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
common_redirect(common_local_url('showfavorites',
common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)));
- return;
+ array('nickname' => $user->nickname)), 303);
+
+ parent::showForm($msg, $success);
+ }
+
+ protected function handlePost()
+ {
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
- $token = $this->trimmed('token-'.$notice->id);
- if (!$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;
+ if (!($notice instanceof Notice)) {
+ $this->serverError(_('Notice not found'));
- if ($user->hasFave($notice)) {
+ if ($this->scoped->hasFave($notice)) {
// TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
$this->clientError(_('This notice is already a favorite!'));
// TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
$this->clientError(_('This notice is already a favorite!'));
- $fave = Fave::addNew($user->getProfile(), $notice);
+ $fave = Fave::addNew($this->scoped, $notice);
if (!$fave) {
// TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
$this->serverError(_('Could not create favorite.'));
if (!$fave) {
// TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
$this->serverError(_('Could not create favorite.'));
- $this->notify($notice, $user);
- $user->blowFavesCache();
- if ($this->boolean('ajax')) {
+ $this->notify($notice, $this->scoped->getUser());
+ $this->scoped->blowFavesCache();
+ if (StatusNet::isAjax()) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Page title for page on which favorite notices can be unfavourited.
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Page title for page on which favorite notices can be unfavourited.
$disfavor->show();
$this->elementEnd('body');
$this->elementEnd('html');
$disfavor->show();
$this->elementEnd('body');
$this->elementEnd('html');
- } else {
- common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)),
- 303);
+ common_redirect(common_local_url('showfavorites',
+ array('nickname' => $this->scoped->nickname)),
+ 303);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
-
-require_once INSTALLDIR.'/lib/form.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Form for disfavoring a notice
*
* @category Form
/**
* Form for disfavoring a notice
*
* @category Form
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
- common_session_token());
+ common_session_token(),
+ 'token');
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
-
-require_once INSTALLDIR.'/lib/form.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Form for favoring a notice
*
* @category Form
/**
* Form for favoring a notice
*
* @category Form
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://status.net/
+ * @link http://www.gnu.org/software/social/
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
- common_session_token());
+ common_session_token(),
+ 'token');
* 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')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Anonymous disfavor class
/**
* Anonymous disfavor class
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
- $token = $this->trimmed('token-' . $notice->id);
-
- if (!$token || $token != common_session_token()) {
- // TRANS: Client error.
- $this->clientError(_m('There was a problem with your session token. Try again, please.'));
- return;
- }
+ $token = $this->checkSessionToken();
$fave = new Fave();
$fave->user_id = $profile->id;
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
$fave = new Fave();
$fave->user_id = $profile->id;
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
- // TRANS: Client error.
- $this->clientError(_m('This notice is not a favorite!'));
- return;
+ throw new NoResultException($fave);
}
$result = $fave->delete();
}
$result = $fave->delete();
* 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')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Anonymous favor class
/**
* Anonymous favor class
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
- $token = $this->trimmed('token-' . $notice->id);
-
- if (empty($token) || $token != common_session_token()) {
- // TRANS: Client error.
- $this->clientError(_m('There was a problem with your session token. Try again, please.'));
- return;
- }
-
+ $token = $this->checkSessionToken();
if ($profile->hasFave($notice)) {
// TRANS: Client error.
if ($profile->hasFave($notice)) {
// TRANS: Client error.
ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
"<fieldset>"+
"<legend>Favor this notice</legend>"+
ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
"<fieldset>"+
"<legend>Favor this notice</legend>"+
- "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
+ "<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
"</fieldset>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
"</fieldset>"+
rf = "<form id=\"repeat-"+id+"\" class=\"form_repeat\" method=\"post\" action=\""+RealtimeUpdate._repeaturl+"\">"+
"<fieldset>"+
"<legend>Repeat this notice?</legend>"+
rf = "<form id=\"repeat-"+id+"\" class=\"form_repeat\" method=\"post\" action=\""+RealtimeUpdate._repeaturl+"\">"+
"<fieldset>"+
"<legend>Repeat this notice?</legend>"+
- "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
+ "<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"repeat-submit-"+id+"\" name=\"repeat-submit-"+id+"\" class=\"submit\" value=\"Yes\" title=\"Repeat this notice\"/>"+
"</fieldset>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"repeat-submit-"+id+"\" name=\"repeat-submit-"+id+"\" class=\"submit\" value=\"Yes\" title=\"Repeat this notice\"/>"+
"</fieldset>"+