nudge.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * User by ID action class.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @author Robin Millette <millette@status.net>
  11. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  12. * @link http://status.net/
  13. *
  14. * StatusNet - the distributed open-source microblogging tool
  15. * Copyright (C) 2008, 2009, StatusNet, Inc.
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR . '/lib/util/mail.php';
  34. /**
  35. * Nudge a user action class.
  36. *
  37. * @category Action
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @author Robin Millette <millette@status.net>
  41. * @author Sarven Capadisli <csarven@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  43. * @link http://status.net/
  44. */
  45. class NudgeAction extends Action
  46. {
  47. /**
  48. * Class handler.
  49. *
  50. * @param array $args array of arguments
  51. *
  52. * @return nothing
  53. */
  54. function handle()
  55. {
  56. parent::handle();
  57. if (!common_logged_in()) {
  58. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  59. $this->clientError(_('Not logged in.'));
  60. }
  61. $user = common_current_user();
  62. $other = User::getKV('nickname', $this->arg('nickname'));
  63. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  64. common_redirect(common_local_url('showstream',
  65. array('nickname' => $other->nickname)));
  66. }
  67. // CSRF protection
  68. $token = $this->trimmed('token');
  69. if (!$token || $token != common_session_token()) {
  70. // TRANS: Client error displayed when the session token does not match or is not given.
  71. $this->clientError(_('There was a problem with your session token. Try again, please.'));
  72. }
  73. if (!$other->email || !$other->emailnotifynudge) {
  74. // TRANS: Client error displayed trying to nudge a user that cannot be nudged.
  75. $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set their email address yet.'));
  76. }
  77. $this->notify($user, $other);
  78. if ($this->boolean('ajax')) {
  79. $this->startHTML('text/xml;charset=utf-8');
  80. $this->elementStart('head');
  81. // TRANS: Page title after sending a nudge.
  82. $this->element('title', null, _('Nudge sent'));
  83. $this->elementEnd('head');
  84. $this->elementStart('body');
  85. // TRANS: Confirmation text after sending a nudge.
  86. $this->element('p', array('id' => 'nudge_response'), _('Nudge sent!'));
  87. $this->elementEnd('body');
  88. $this->endHTML();
  89. } else {
  90. // display a confirmation to the user
  91. common_redirect(common_local_url('showstream',
  92. array('nickname' => $other->nickname)),
  93. 303);
  94. }
  95. }
  96. /**
  97. * Do the actual notification
  98. *
  99. * @param class $user nudger
  100. * @param class $other nudgee
  101. *
  102. * @return nothing
  103. */
  104. function notify($user, $other)
  105. {
  106. if ($other->id != $user->id) {
  107. if ($other->email && $other->emailnotifynudge) {
  108. mail_notify_nudge($user, $other);
  109. }
  110. // XXX: notify by IM
  111. // XXX: notify by SMS
  112. }
  113. }
  114. function isReadOnly($args)
  115. {
  116. return true;
  117. }
  118. }