3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Form for adding a new bookmark
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Form to add a new bookmark
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2010 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class BookmarkForm extends Form
49 private $_title = null;
51 private $_tags = null;
52 private $_description = null;
53 private $_thumbnail = null;
56 * Construct a bookmark form
58 * @param HTMLOutputter $out output channel
59 * @param string $title Title of the bookmark
60 * @param string $url URL of the bookmark
61 * @param string $tags Tags to show
62 * @param string $description Description of the bookmark
66 function __construct($out=null, $title=null, $url=null, $tags=null,
67 $description=null, $thumbnail=null)
69 parent::__construct($out);
71 $this->_title = $title;
74 $this->_description = $description;
75 $this->_thumbnail = $thumbnail;
81 * @return int ID of the form
85 return 'form_new_bookmark';
91 * @return string class of the form
95 return 'form_settings ajax-notice';
101 * @return string URL of the action
105 return common_local_url('newbookmark');
109 * Data elements of the form
115 $this->out->elementStart('fieldset', array('id' => 'new_bookmark_data'));
116 $this->out->elementStart('ul', 'form_data');
119 $this->out->input('bookmark-url',
120 // TRANS: Field label on form for adding a new bookmark.
127 if (!empty($this->_thumbnail)) {
129 list($width, $height) = $this->scaleImage($this->_thumbnail->width,
130 $this->_thumbnail->height);
132 $this->out->element('img',
133 array('src' => $this->_thumbnail->url,
134 'class' => 'bookmarkform-thumbnail',
136 'height' => $height));
140 $this->out->input('bookmark-title',
141 // TRANS: Field label on form for adding a new bookmark.
149 $this->out->textarea('bookmark-description',
150 // TRANS: Field label on form for adding a new bookmark.
158 $this->out->input('bookmark-tags',
159 // TRANS: Field label on form for adding a new bookmark.
162 // TRANS: Field title on form for adding a new bookmark.
163 _m('Comma- or space-separated list of tags.'),
167 $this->out->elementEnd('ul');
169 $toWidget = new ToSelector($this->out,
170 common_current_user(),
174 $this->out->elementEnd('fieldset');
183 function formActions()
185 // TRANS: Button text for action to save a new bookmark.
186 $this->out->submit('bookmark-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
189 function scaleImage($width, $height)
191 $maxwidth = common_config('attachments', 'thumb_width');
192 $maxheight = common_config('attachments', 'thumb_height');
194 if ($width > $height && $width > $maxwidth) {
195 $height = (int) ((((float)$maxwidth)/(float)($width))*(float)$height);
197 } else if ($height > $maxheight) {
198 $width = (int) ((((float)$maxheight)/(float)($height))*(float)$width);
199 $height = $maxheight;
202 return array($width, $height);