addmirror.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * PHP version 5
  20. *
  21. * @category Action
  22. * @package StatusNet
  23. * @author Brion Vibber <brion@status.net>
  24. * @copyright 2010 StatusNet, Inc.
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  26. * @link http://status.net/
  27. */
  28. if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
  29. /**
  30. * Takes parameters:
  31. *
  32. * - feed: a profile ID
  33. * - token: session token to prevent CSRF attacks
  34. * - ajax: boolean; whether to return Ajax or full-browser results
  35. *
  36. * Only works if the current user is logged in.
  37. *
  38. * @category Action
  39. * @package StatusNet
  40. * @copyright 2010 StatusNet, Inc.
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  42. * @link http://status.net/
  43. */
  44. class AddMirrorAction extends BaseMirrorAction
  45. {
  46. var $feedurl;
  47. /**
  48. * Check pre-requisites and instantiate attributes
  49. *
  50. * @param Array $args array of arguments (URL, GET, POST)
  51. *
  52. * @return boolean success flag
  53. */
  54. protected function prepare(array $args=array())
  55. {
  56. parent::prepare($args);
  57. $feedurl = $this->getFeedUrl();
  58. $this->feedurl = $this->validateFeedUrl($feedurl);
  59. $this->profile = $this->profileForFeed($this->feedurl);
  60. return true;
  61. }
  62. function getFeedUrl()
  63. {
  64. $provider = $this->trimmed('provider');
  65. switch ($provider) {
  66. case 'feed':
  67. return $this->trimmed('feedurl');
  68. default:
  69. // TRANS: Exception thrown when a feed provider could not be recognised.
  70. throw new Exception(_m('Internal form error: Unrecognized feed provider.'));
  71. }
  72. }
  73. protected function saveMirror()
  74. {
  75. $this->oprofile->subscribe();
  76. SubMirror::saveMirror($this->user, $this->profile);
  77. }
  78. }