bookmark.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * Form for adding 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. * Form to 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 BookmarkForm extends Form
  46. {
  47. private $_title = null;
  48. private $_url = null;
  49. private $_tags = null;
  50. private $_description = null;
  51. private $_thumbnail = null;
  52. /**
  53. * Construct a bookmark form
  54. *
  55. * @param HTMLOutputter $out output channel
  56. * @param string $title Title of the bookmark
  57. * @param string $url URL of the bookmark
  58. * @param string $tags Tags to show
  59. * @param string $description Description of the bookmark
  60. *
  61. * @return void
  62. */
  63. function __construct($out=null, $title=null, $url=null, $tags=null,
  64. $description=null, $thumbnail=null)
  65. {
  66. parent::__construct($out);
  67. $this->_title = $title;
  68. $this->_url = $url;
  69. $this->_tags = $tags;
  70. $this->_description = $description;
  71. $this->_thumbnail = $thumbnail;
  72. }
  73. /**
  74. * ID of the form
  75. *
  76. * @return int ID of the form
  77. */
  78. function id()
  79. {
  80. return 'form_new_bookmark';
  81. }
  82. /**
  83. * class of the form
  84. *
  85. * @return string class of the form
  86. */
  87. function formClass()
  88. {
  89. return 'form_settings ajax-notice';
  90. }
  91. /**
  92. * Action of the form
  93. *
  94. * @return string URL of the action
  95. */
  96. function action()
  97. {
  98. return common_local_url('newbookmark');
  99. }
  100. /**
  101. * Data elements of the form
  102. *
  103. * @return void
  104. */
  105. function formData()
  106. {
  107. $this->out->elementStart('fieldset', array('id' => 'new_bookmark_data'));
  108. $this->out->elementStart('ul', 'form_data');
  109. $this->li();
  110. $this->out->input('bookmark-url',
  111. // TRANS: Field label on form for adding a new bookmark.
  112. _m('LABEL','URL'),
  113. $this->_url,
  114. null,
  115. 'url',
  116. true); // HTML5 "required" attribute
  117. $this->unli();
  118. if (!empty($this->_thumbnail)) {
  119. list($width, $height) = $this->scaleImage($this->_thumbnail->width,
  120. $this->_thumbnail->height);
  121. $this->out->element('img',
  122. array('src' => $this->_thumbnail->url,
  123. 'class' => 'bookmarkform-thumbnail',
  124. 'width' => $width,
  125. 'height' => $height));
  126. }
  127. $this->li();
  128. $this->out->input('bookmark-title',
  129. // TRANS: Field label on form for adding a new bookmark.
  130. _m('LABEL','Title'),
  131. $this->_title,
  132. null,
  133. 'title',
  134. true); // HTML5 "required" attribute
  135. $this->unli();
  136. $this->li();
  137. $this->out->textarea('bookmark-description',
  138. // TRANS: Field label on form for adding a new bookmark.
  139. _m('LABEL','Notes'),
  140. $this->_description,
  141. null,
  142. 'description');
  143. $this->unli();
  144. $this->li();
  145. $this->out->input('bookmark-tags',
  146. // TRANS: Field label on form for adding a new bookmark.
  147. _m('LABEL','Tags'),
  148. $this->_tags,
  149. // TRANS: Field title on form for adding a new bookmark.
  150. _m('Comma- or space-separated list of tags.'),
  151. 'tags');
  152. $this->unli();
  153. $this->out->elementEnd('ul');
  154. $toWidget = new ToSelector($this->out,
  155. common_current_user(),
  156. null);
  157. $toWidget->show();
  158. $this->out->elementEnd('fieldset');
  159. }
  160. /**
  161. * Action elements
  162. *
  163. * @return void
  164. */
  165. function formActions()
  166. {
  167. // TRANS: Button text for action to save a new bookmark.
  168. $this->out->submit('bookmark-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
  169. }
  170. function scaleImage($width, $height)
  171. {
  172. $maxwidth = common_config('thumbnail', 'width');
  173. $maxheight = common_config('thumbnail', 'height');
  174. if ($width > $height && $width > $maxwidth) {
  175. $height = (int) ((((float)$maxwidth)/(float)($width))*(float)$height);
  176. $width = $maxwidth;
  177. } else if ($height > $maxheight) {
  178. $width = (int) ((((float)$maxheight)/(float)($height))*(float)$width);
  179. $height = $maxheight;
  180. }
  181. return array($width, $height);
  182. }
  183. }