]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/forms/bookmark.php
Use getUrl() on File and File_thumbnail instead of ->url
[quix0rs-gnu-social.git] / plugins / Bookmark / forms / bookmark.php
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
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Form to add a new bookmark
39  *
40  * @category  Bookmark
41  * @package   StatusNet
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/
46  */
47 class BookmarkForm extends Form
48 {
49     private $_title       = null;
50     private $_url         = null;
51     private $_tags        = null;
52     private $_description = null;
53     private $_thumbnail   = null;
54
55     /**
56      * Construct a bookmark form
57      *
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
63      *
64      * @return void
65      */
66     function __construct($out=null, $title=null, $url=null, $tags=null,
67                          $description=null, $thumbnail=null)
68     {
69         parent::__construct($out);
70
71         $this->_title       = $title;
72         $this->_url         = $url;
73         $this->_tags        = $tags;
74         $this->_description = $description;
75         $this->_thumbnail   = $thumbnail;
76     }
77
78     /**
79      * ID of the form
80      *
81      * @return int ID of the form
82      */
83     function id()
84     {
85         return 'form_new_bookmark';
86     }
87
88     /**
89      * class of the form
90      *
91      * @return string class of the form
92      */
93     function formClass()
94     {
95         return 'form_settings ajax-notice';
96     }
97
98     /**
99      * Action of the form
100      *
101      * @return string URL of the action
102      */
103     function action()
104     {
105         return common_local_url('newbookmark');
106     }
107
108     /**
109      * Data elements of the form
110      *
111      * @return void
112      */
113     function formData()
114     {
115         $this->out->elementStart('fieldset', array('id' => 'new_bookmark_data'));
116         $this->out->elementStart('ul', 'form_data');
117
118         $this->li();
119         $this->out->input('bookmark-url',
120                           // TRANS: Field label on form for adding a new bookmark.
121                           _m('LABEL','URL'),
122                           $this->_url,
123                           null,
124                           'url',
125                           true);    // HTML5 "required" attribute
126         $this->unli();
127
128         if (!empty($this->_thumbnail)) {
129
130             list($width, $height) = $this->scaleImage($this->_thumbnail->width,
131                                                       $this->_thumbnail->height);
132
133             $this->out->element('img',
134                                 array('src' => $this->_thumbnail->getUrl(),
135                                       'class' => 'bookmarkform-thumbnail',
136                                       'width' => $width,
137                                       'height' => $height));
138         }
139
140         $this->li();
141         $this->out->input('bookmark-title',
142                           // TRANS: Field label on form for adding a new bookmark.
143                           _m('LABEL','Title'),
144                           $this->_title,
145                           null,
146                           'title',
147                           true);    // HTML5 "required" attribute
148         $this->unli();
149
150         $this->li();
151         $this->out->textarea('bookmark-description',
152                              // TRANS: Field label on form for adding a new bookmark.
153                              _m('LABEL','Notes'),
154                              $this->_description,
155                              null,
156                              'description');
157         $this->unli();
158
159         $this->li();
160         $this->out->input('bookmark-tags',
161                           // TRANS: Field label on form for adding a new bookmark.
162                           _m('LABEL','Tags'),
163                           $this->_tags,
164                           // TRANS: Field title on form for adding a new bookmark.
165                           _m('Comma- or space-separated list of tags.'),
166                           'tags');
167         $this->unli();
168
169         $this->out->elementEnd('ul');
170
171         $toWidget = new ToSelector($this->out,
172                                    common_current_user(),
173                                    null);
174         $toWidget->show();
175
176         $this->out->elementEnd('fieldset');
177     }
178
179     /**
180      * Action elements
181      *
182      * @return void
183      */
184
185     function formActions()
186     {
187         // TRANS: Button text for action to save a new bookmark.
188         $this->out->submit('bookmark-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
189     }
190
191     function scaleImage($width, $height)
192     {
193         $maxwidth = common_config('thumbnail', 'width');
194         $maxheight = common_config('thumbnail', 'height');
195
196         if ($width > $height && $width > $maxwidth) {
197             $height = (int) ((((float)$maxwidth)/(float)($width))*(float)$height);
198             $width = $maxwidth;
199         } else if ($height > $maxheight) {
200             $width = (int) ((((float)$maxheight)/(float)($height))*(float)$width);
201             $height = $maxheight;
202         }
203
204         return array($width, $height);
205     }
206 }