newbookmark.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * Add a new bookmark
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Bookmark
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2010 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Add a new bookmark
  37. *
  38. * @category Bookmark
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2010 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class NewbookmarkAction extends FormAction
  46. {
  47. protected $complete = null;
  48. protected $title = null;
  49. protected $url = null;
  50. protected $tags = null;
  51. protected $description = null;
  52. function title()
  53. {
  54. // TRANS: Title for action to create a new bookmark.
  55. return _m('New bookmark');
  56. }
  57. protected function doPreparation()
  58. {
  59. $this->title = $this->trimmed('title');
  60. $this->url = $this->trimmed('url');
  61. $this->tags = preg_split('/[\s,]+/', $this->trimmed('tags'), null, PREG_SPLIT_NO_EMPTY);
  62. $this->description = $this->trimmed('description');
  63. return true;
  64. }
  65. /**
  66. * Add a new bookmark
  67. *
  68. * @return void
  69. */
  70. function handlePost()
  71. {
  72. if (empty($this->title)) {
  73. // TRANS: Client exception thrown when trying to create a new bookmark without a title.
  74. throw new ClientException(_m('Bookmark must have a title.'));
  75. }
  76. if (empty($this->url)) {
  77. // TRANS: Client exception thrown when trying to create a new bookmark without a URL.
  78. throw new ClientException(_m('Bookmark must have an URL.'));
  79. }
  80. $options = array();
  81. ToSelector::fillOptions($this, $options);
  82. $saved = Bookmark::addNew($this->scoped,
  83. $this->title,
  84. $this->url,
  85. $this->tags,
  86. $this->description,
  87. $options);
  88. }
  89. /**
  90. * Output a notice
  91. *
  92. * Used to generate the notice code for Ajax results.
  93. *
  94. * @param Notice $notice Notice that was saved
  95. *
  96. * @return void
  97. */
  98. function showNotice(Notice $notice)
  99. {
  100. class_exists('NoticeList'); // @fixme hack for autoloader
  101. $nli = new NoticeListItem($notice, $this);
  102. $nli->show();
  103. }
  104. /**
  105. * Show the bookmark form
  106. *
  107. * @return void
  108. */
  109. function showContent()
  110. {
  111. if (!empty($this->error)) {
  112. $this->element('p', 'error', $this->error);
  113. }
  114. $form = new BookmarkForm($this,
  115. $this->title,
  116. $this->url,
  117. $this->tags,
  118. $this->description);
  119. $form->show();
  120. return;
  121. }
  122. /**
  123. * Return true if read only.
  124. *
  125. * MAY override
  126. *
  127. * @param array $args other arguments
  128. *
  129. * @return boolean is read only action?
  130. */
  131. function isReadOnly($args)
  132. {
  133. if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
  134. $_SERVER['REQUEST_METHOD'] == 'HEAD') {
  135. return true;
  136. } else {
  137. return false;
  138. }
  139. }
  140. }