From dab96e99a9fffea7232861e059c7aefd8224449f Mon Sep 17 00:00:00 2001 From: Hannes Mannerheim Date: Fri, 23 Jan 2015 16:28:41 +0100 Subject: [PATCH] #89 extended to work with rotation and thumbnails --- QvitterPlugin.php | 8 +-- README.md | 9 ++- actions/apiuploadimage.php | 109 ------------------------------------- actions/qvitter.php | 6 +- js/dom-functions.js | 37 ++++++++++--- js/qvitter.js | 38 ++++++++----- 6 files changed, 67 insertions(+), 140 deletions(-) delete mode 100644 actions/apiuploadimage.php diff --git a/QvitterPlugin.php b/QvitterPlugin.php index a61ee6f..744852b 100644 --- a/QvitterPlugin.php +++ b/QvitterPlugin.php @@ -476,14 +476,14 @@ class QvitterPlugin extends Plugin { // find all thumbs $attachments = $notice->attachments(); - $attachment_url_to_thumb = array(); + $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { try { $enclosure_o = $attachment->getEnclosure(); $thumb = File_thumbnail::getKV('file_id', $attachment->id); if(isset($thumb->url)) { - $attachment_url_to_thumb[$enclosure_o->url] = $thumb->url; + $attachment_url_to_id[$enclosure_o->url] = $attachment->id; } } catch (ServerException $e) { // There was not enough metadata available @@ -494,8 +494,8 @@ class QvitterPlugin extends Plugin { // add thumbs to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { - if (!empty($attachment_url_to_thumb[$attachment['url']])) { - $attachment['thumb_url'] = $attachment_url_to_thumb[$attachment['url']]; + if (!empty($attachment_url_to_id[$attachment['url']])) { + $attachment['id'] = $attachment_url_to_id[$attachment['url']]; } } } diff --git a/README.md b/README.md index 06e532b..fa41e47 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,13 @@ are running the latest GNU Social nightly!) 4. Add `addPlugin('Qvitter');` to your /config.php file. -5. There are a few settings in /plugins/Qvitter/QvitterPlugin.php. By default Qvitter is +5. It's recommended to set this setting in your /config.php file: `$config['thumbnail']['maxsize'] = 3000;` + +6. There are a few settings in /plugins/Qvitter/QvitterPlugin.php. By default Qvitter is opt-out for users. If you set `$settings['enabledbydefault'] = false;` Qvitter will be opt-in instead. -6. Users can go to ://{instance}/settings/qvitter and enable or disable Qvitter. +7. Users can go to ://{instance}/settings/qvitter and enable or disable Qvitter. Optional ----- @@ -52,7 +54,8 @@ $config['site']['qvitter']['defaultlinkcolor'] = '#0084B4'; $config['site']['qvitter']['timebetweenpolling'] = 5000; $config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/yourls-api.php'; $config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983'; -$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg'; +$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg'; +$config['thumbnail']['maxsize'] = 3000; ```` Note: Qvitter is tested with GNU Social version 1.1.1-alpha2 (7e47026085fa4f2071e694d9c3e3fe2aa5142135). diff --git a/actions/apiuploadimage.php b/actions/apiuploadimage.php deleted file mode 100644 index d1935a2..0000000 --- a/actions/apiuploadimage.php +++ /dev/null @@ -1,109 +0,0 @@ - \\\\_\ · - · \\) \____) · - · · - · · - · Qvitter is free software: you can redistribute it and / or modify it · - · under the terms of the GNU Affero General Public License as published by · - · the Free Software Foundation, either version three of the License or (at · - · your option) any later version. · - · · - · Qvitter is distributed in hope that it will be useful but WITHOUT ANY · - · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS · - · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for · - · more details. · - · · - · You should have received a copy of the GNU Affero General Public License · - · along with Qvitter. If not, see . · - · · - · Contact h@nnesmannerhe.im if you have any questions. · - · · - · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ - - -if (!defined('GNUSOCIAL')) { - exit(1); -} - -class ApiUploadImageAction extends ApiAuthAction -{ - protected $needPost = true; - - /** - * Take arguments for running - * - * @param array $args $_REQUEST args - * - * @return boolean success flag - */ - protected function prepare(array $args=array()) - { - parent::prepare($args); - - $this->user = $this->auth_user; - $this->img = $this->trimmed('img'); - - return true; - } - - /** - * Handle the request - * - * @return void - */ - protected function handle() - { - parent::handle(); - - $profile = $this->user->getProfile(); - $base64img = $this->img; - if(stristr($base64img, 'image/jpeg')) { - $base64img_mime = 'image/jpeg'; - } - elseif(stristr($base64img, 'image/png')) { - // should convert to jpg here!! - $base64img_mime = 'image/png'; - } - $base64img = str_replace('data:image/jpeg;base64,', '', $base64img); - $base64img = str_replace('data:image/png;base64,', '', $base64img); - $base64img = str_replace(' ', '+', $base64img); - $base64img_hash = md5($base64img); - $base64img = base64_decode($base64img); - $base64img_basename = basename('qvitterupload'); - $base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime); - $base64img_path = File::path($base64img_filename); - $base64img_success = file_put_contents($base64img_path, $base64img); - $base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename); - $mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype); - $return['shorturl'] = $mediafile->shortUrl(); - - // create thumb - $file = File::getKV('filename',$base64img_filename); - $file->getThumbnail(); - - if(strlen($return['shorturl']) < 1) { - $return['error'] = true; - } - - $this->initDocument('json'); - $this->showJsonObjects($return); - $this->endDocument('json'); - } -} diff --git a/actions/qvitter.php b/actions/qvitter.php index d1d82a7..9b4e1c9 100644 --- a/actions/qvitter.php +++ b/actions/qvitter.php @@ -79,6 +79,7 @@ class QvitterAction extends ApiAction $siterootdomain = common_config('site','server'); $qvitterpath = Plugin::staticPath('Qvitter', ''); $apiroot = common_path('api/', StatusNet::isHTTPS()); + $attachmentroot = common_path('attachment/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); common_set_returnto(''); // forget this @@ -184,7 +185,10 @@ class QvitterAction extends ApiAction window.siteBackground = ''; window.urlShortenerAPIURL = ''; window.urlShortenerSignature = ''; - window.commonSessionToken = ''; + window.commonSessionToken = ''; + window.siteMaxThumbnailSize = ; + window.siteAttachmentURLBase = ''; +