From a4ebdbc606b997f846b74ff463221c0677173fc6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 31 Jan 2016 09:56:06 +0100 Subject: [PATCH] re-introducing (optional) URL shortener support, resolves #58 --- cfg/conf.ini.sample | 5 +++ i18n/de.json | 3 +- i18n/fr.json | 3 +- i18n/pl.json | 3 +- i18n/sl.json | 3 +- img/icon_shorten.png | Bin 0 -> 262 bytes js/zerobin.js | 35 ++++++++++++++++++--- lib/configuration.php | 1 + lib/zerobin.php | 1 + tpl/bootstrap-compact.html | 6 +++- tpl/bootstrap-dark-page.html | 6 +++- tpl/bootstrap-dark.html | 6 +++- tpl/bootstrap-page.html | 6 +++- tpl/bootstrap.html | 6 +++- tpl/page.html | 4 ++- tst/RainTPL.php | 1 + tst/configuration.php | 1 + tst/zerobin.php | 57 +++++++++++++++++++++++++++++++++++ 18 files changed, 133 insertions(+), 14 deletions(-) create mode 100644 img/icon_shorten.png diff --git a/cfg/conf.ini.sample b/cfg/conf.ini.sample index 4fdce17f..01433a20 100644 --- a/cfg/conf.ini.sample +++ b/cfg/conf.ini.sample @@ -52,6 +52,11 @@ languageselection = false ; if this is set and language selection is disabled, this will be the only language ; languagedefault = "en" +; (optional) URL shortener address to offer after a new paste is created +; it is suggested to only use this with self-hosted shorteners as this will leak +; the pastes encryption key +; urlshortener = "https://shortener.example.com/api?link=" + [expire] ; expire value that is selected per default ; make sure the value exists in [expire_options] diff --git a/i18n/de.json b/i18n/de.json index 4cdebecb..191c69f0 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -135,5 +135,6 @@ "Your browser does not support uploading encrypted files. Please use a newer browser.": "Dein Browser unterstützt das hochladen von verschlüsselten Dateien nicht. Bitte verwende einen neueren Browser.", "Invalid attachment.": "Ungültiger Datei-Anhang.", - "Options": "Optionen" + "Options": "Optionen", + "Shorten URL": "URL verkürzen" } diff --git a/i18n/fr.json b/i18n/fr.json index 87b7ca97..8736314b 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -144,5 +144,6 @@ "Your browser does not support uploading encrypted files. Please use a newer browser.": "Votre navigateur ne supporte pas l'envoi de fichiers chiffrés. Merci d'utiliser un navigateur plus récent.", "Invalid attachment.": "Attachement invalide.", - "Options": "Options" + "Options": "Options", + "Shorten URL": "Raccourcir URL" } diff --git a/i18n/pl.json b/i18n/pl.json index b5ba538b..82085fd1 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -135,5 +135,6 @@ "Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.", "Invalid attachment.": "Invalid attachment.", - "Options": "Options" + "Options": "Options", + "Shorten URL": "Skróć adres URL" } diff --git a/i18n/sl.json b/i18n/sl.json index 53fac9ca..a7e95429 100644 --- a/i18n/sl.json +++ b/i18n/sl.json @@ -144,5 +144,6 @@ "Your browser does not support uploading encrypted files. Please use a newer browser.": "Tvoj brskalnik ne omogoča nalaganje zakodiranih datotek. Prosim uporabi novejši brskalnik.", "Invalid attachment.": "Neveljavna priponka.", - "Options": "Možnosti" + "Options": "Možnosti", + "Shorten URL": "Skrajšajte URL" } diff --git a/img/icon_shorten.png b/img/icon_shorten.png new file mode 100644 index 0000000000000000000000000000000000000000..324cbaae87f386bae349f3355edc66e6561f4b8e GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp@K+Mm<1|;p3UCV(KV{wqX6T`Z5GB1G~wj^(N7l!{J zxM1({$v_d#0*}aI1_tIb5N52s+H?je$X?><>&kwIg`3^fgg3c-Gf=3_)5S4F?&~egq+S}@*+x0KFIxgh)$*5!D zUG`y>_9aG-o#&et*gO2a^rJ6ri}ixD-{U#*R)j4$_57OvkG9Dg>1`L7OW8{A)n7?f zJ~Sg}m%Gc8(mPx~!JC`HYXQ25!PC{xWt~$(69DvG BVt)Vt literal 0 HcmV?d00001 diff --git a/js/zerobin.js b/js/zerobin.js index 460a6b6f..530f8605 100644 --- a/js/zerobin.js +++ b/js/zerobin.js @@ -405,7 +405,7 @@ $(function() { * translation cache */ translations: {} - } + }; /** * filter methods @@ -921,7 +921,7 @@ $(function() { filter.cipher(randomkey, password, e.target.result), filter.cipher(randomkey, password, theFile.name) ); - } + }; })(files[0]); reader.readAsDataURL(files[0]); } @@ -942,7 +942,9 @@ $(function() { /** * Send a new paste to server, step 2 * - * @param Event event + * @param string randomkey + * @param encrypted string cipherdata_attachment + * @param encrypted string cipherdata_attachment_name */ sendDataContinue: function(randomkey, cipherdata_attachment, cipherdata_attachment_name) { @@ -977,7 +979,12 @@ $(function() { zerobin.showStatus('', false); zerobin.errorMessage.addClass('hidden'); - $('#pastelink').html(i18n._('Your paste is %s (Hit [Ctrl]+[c] to copy)', url, url)); + $('#pastelink').html( + i18n._( + 'Your paste is %s (Hit [Ctrl]+[c] to copy)', + url, url + ) + zerobin.shortenUrl(url) + ); $('#deletelink').html('' + i18n._('Delete data') + ''); zerobin.pasteResult.removeClass('hidden'); // We pre-select the link so that the user only has to [Ctrl]+[c] the link. @@ -1004,6 +1011,26 @@ $(function() { }); }, + /** + * Check if a URL shortener was defined and create HTML containing a link to it. + * + * @param string url + * @return string html + */ + shortenUrl: function(url) + { + var shortenerHtml = $('#shortenbutton'); + if (shortenerHtml) { + var shortener = shortenerHtml.data('shortener'); + shortenerHtml.attr( + 'onclick', + "window.location.href = '" + shortener + encodeURIComponent(url) + "';" + ); + return ' ' + $('
').append(shortenerHtml.clone()).html(); + } + return ''; + }, + /** * Put the screen in "New paste" mode. */ diff --git a/lib/configuration.php b/lib/configuration.php index 7895b60e..76ddb552 100644 --- a/lib/configuration.php +++ b/lib/configuration.php @@ -44,6 +44,7 @@ class configuration 'base64version' => '2.1.9', 'languageselection' => false, 'languagedefault' => '', + 'urlshortener' => '', ), 'expire' => array( 'default' => '1week', diff --git a/lib/zerobin.php b/lib/zerobin.php index 81796087..9e02fcb2 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -455,6 +455,7 @@ class zerobin $page->assign('EXPIRE', $expire); $page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire')); $page->assign('EXPIRECLONE', !$this->_doesExpire || ($this->_doesExpire && $this->_conf->getKey('clone', 'expire'))); + $page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener')); $page->draw($this->_conf->getKey('template')); } diff --git a/tpl/bootstrap-compact.html b/tpl/bootstrap-compact.html index 503a47ee..7d44543b 100644 --- a/tpl/bootstrap-compact.html +++ b/tpl/bootstrap-compact.html @@ -169,7 +169,11 @@
diff --git a/tpl/bootstrap-dark-page.html b/tpl/bootstrap-dark-page.html index df17e700..34c031ee 100644 --- a/tpl/bootstrap-dark-page.html +++ b/tpl/bootstrap-dark-page.html @@ -165,7 +165,11 @@
diff --git a/tpl/bootstrap-dark.html b/tpl/bootstrap-dark.html index d39f8e22..289c6470 100644 --- a/tpl/bootstrap-dark.html +++ b/tpl/bootstrap-dark.html @@ -165,7 +165,11 @@
diff --git a/tpl/bootstrap-page.html b/tpl/bootstrap-page.html index f9bbcf5c..4b7f928c 100644 --- a/tpl/bootstrap-page.html +++ b/tpl/bootstrap-page.html @@ -165,7 +165,11 @@
diff --git a/tpl/bootstrap.html b/tpl/bootstrap.html index a56d6fe5..22bafae3 100644 --- a/tpl/bootstrap.html +++ b/tpl/bootstrap.html @@ -165,7 +165,11 @@
diff --git a/tpl/page.html b/tpl/page.html index b8bd5f24..01328f65 100644 --- a/tpl/page.html +++ b/tpl/page.html @@ -84,7 +84,9 @@
{if="$FILEUPLOAD"}