123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- defined('GNUSOCIAL') || die();
- class BookmarkForm extends Form
- {
- private $_title = null;
- private $_url = null;
- private $_tags = null;
- private $_description = null;
- private $_thumbnail = null;
-
- public function __construct(
- $out = null,
- $title = null,
- $url = null,
- $tags = null,
- $description = null,
- $thumbnail = null
- ) {
- parent::__construct($out);
- $this->_title = $title;
- $this->_url = $url;
- $this->_tags = $tags;
- $this->_description = $description;
- $this->_thumbnail = $thumbnail;
- }
-
- public function id()
- {
- return 'form_new_bookmark';
- }
-
- public function formClass()
- {
- return 'form_settings ajax-notice';
- }
-
- public function action()
- {
- return common_local_url('newbookmark');
- }
-
- public function formData()
- {
- $this->out->elementStart('fieldset', array('id' => 'new_bookmark_data'));
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->out->input(
- 'bookmark-url',
-
- _m('LABEL', 'URL'),
- $this->_url,
- null,
- 'url',
- true
- );
- $this->unli();
- if (!empty($this->_thumbnail)) {
- [$width, $height] = $this->scaleImage(
- $this->_thumbnail->width,
- $this->_thumbnail->height
- );
- $this->out->element('img', [
- 'src' => $this->_thumbnail->getUrl(),
- 'class' => 'bookmarkform-thumbnail',
- 'width' => $width,
- 'height' => $height,
- ]);
- }
- $this->li();
- $this->out->input(
- 'bookmark-title',
-
- _m('LABEL', 'Title'),
- $this->_title,
- null,
- 'title',
- true
- );
- $this->unli();
- $this->li();
- $this->out->textarea(
- 'bookmark-description',
-
- _m('LABEL', 'Notes'),
- $this->_description,
- null,
- 'description'
- );
- $this->unli();
- $this->li();
- $this->out->input(
- 'bookmark-tags',
-
- _m('LABEL', 'Tags'),
- ($this->_tags ? implode(',', $this->_tags) : null),
-
- _m('Comma- or space-separated list of tags.'),
- 'tags'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $toWidget = new ToSelector(
- $this->out,
- common_current_user(),
- null
- );
- $toWidget->show();
- $this->out->elementEnd('fieldset');
- }
-
- public function formActions()
- {
-
- $this->out->submit('bookmark-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
- }
- public function scaleImage($width, $height)
- {
- $maxwidth = common_config('thumbnail', 'width');
- $maxheight = common_config('thumbnail', 'height');
- if ($width > $height && $width > $maxwidth) {
- $height = (int) ((((float)$maxwidth)/(float)($width))*(float)$height);
- $width = $maxwidth;
- } elseif ($height > $maxheight) {
- $width = (int) ((((float)$maxheight)/(float)($height))*(float)$width);
- $height = $maxheight;
- }
- return array($width, $height);
- }
- }
|