re-introducing (optional) URL shortener support, resolves #58

This commit is contained in:
El RIDO 2016-01-31 09:56:06 +01:00
parent d510e861d2
commit a4ebdbc606
18 changed files with 133 additions and 14 deletions

View File

@ -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]

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

BIN
img/icon_shorten.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

View File

@ -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 <a id="pasteurl" href="%s">%s</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span>', url, url));
$('#pastelink').html(
i18n._(
'Your paste is <a id="pasteurl" href="%s">%s</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span>',
url, url
) + zerobin.shortenUrl(url)
);
$('#deletelink').html('<a href="' + deleteUrl + '">' + i18n._('Delete data') + '</a>');
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 ' ' + $('<div />').append(shortenerHtml.clone()).html();
}
return '';
},
/**
* Put the screen in "New paste" mode.
*/

View File

@ -44,6 +44,7 @@ class configuration
'base64version' => '2.1.9',
'languageselection' => false,
'languagedefault' => '',
'urlshortener' => '',
),
'expire' => array(
'default' => '1week',

View File

@ -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'));
}

View File

@ -169,7 +169,11 @@
<div id="pasteresult" role="alert" class="hidden alert alert-success">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> {function="t('Shorten URL')"}
</button>
{/if}</div>
</div>
</header>
<section class="container">

View File

@ -165,7 +165,11 @@
<div id="pasteresult" role="alert" class="hidden alert alert-success">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> {function="t('Shorten URL')"}
</button>
{/if}</div>
</div>
</header>
<section class="container">

View File

@ -165,7 +165,11 @@
<div id="pasteresult" role="alert" class="hidden alert alert-success">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> {function="t('Shorten URL')"}
</button>
{/if}</div>
</div>
</header>
<section class="container">

View File

@ -165,7 +165,11 @@
<div id="pasteresult" role="alert" class="hidden alert alert-success">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> {function="t('Shorten URL')"}
</button>
{/if}</div>
</div>
</header>
<section class="container">

View File

@ -165,7 +165,11 @@
<div id="pasteresult" role="alert" class="hidden alert alert-success">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> {function="t('Shorten URL')"}
</button>
{/if}</div>
</div>
</header>
<section class="container">

View File

@ -84,7 +84,9 @@
</div>
<div id="pasteresult" class="hidden">
<div id="deletelink"></div>
<div id="pastelink"></div>
<div id="pastelink">{if="strlen($URLSHORTENER)"}
<button id="shortenbutton" data-shortener="{$URLSHORTENER|htmlspecialchars}"><img src="img/icon_shorten.png" width="13" height="15" />{function="t('Shorten URL')"}</button>
{/if}</div>
</div>{if="$FILEUPLOAD"}
<div id="attachment" class="hidden"><a>{function="t('Download attachment')"}</a></div>
<div id="attach" class="hidden">

View File

@ -44,6 +44,7 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
$page->assign('EXPIRE', self::$expire);
$page->assign('EXPIREDEFAULT', self::$expire_default);
$page->assign('EXPIRECLONE', true);
$page->assign('URLSHORTENER', '');
ob_start();
$page->draw('page');
$this->_content = ob_get_contents();

View File

@ -16,6 +16,7 @@ class configurationTest extends PHPUnit_Framework_TestCase
'base64version' => '2.1.9',
'languageselection' => false,
'languagedefault' => '',
'urlshortener' => '',
),
'expire' => array(
'default' => '1week',

View File

@ -44,6 +44,13 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$content,
'outputs title correctly'
);
$this->assertNotTag(
array(
'id' => 'shortenbutton'
),
$content,
'doesn\'t output shortener button'
);
}
/**
@ -70,6 +77,56 @@ class zerobinTest extends PHPUnit_Framework_TestCase
);
}
/**
* @runInSeparateProcess
*/
public function testViewForceLanguageDefault()
{
$this->reset();
$options = parse_ini_file(CONF, true);
$options['main']['languageselection'] = false;
$options['main']['languagedefault'] = 'fr';
helper::confBackup();
helper::createIniFile(CONF, $options);
$_COOKIE['lang'] = 'de';
ob_start();
new zerobin;
$content = ob_get_contents();
$this->assertTag(
array(
'tag' => 'title',
'content' => 'ZeroBin'
),
$content,
'outputs title correctly'
);
}
/**
* @runInSeparateProcess
*/
public function testViewUrlShortener()
{
$shortener = 'https://shortener.example.com/api?link=';
$this->reset();
$options = parse_ini_file(CONF, true);
$options['main']['urlshortener'] = $shortener;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_COOKIE['lang'] = 'de';
ob_start();
new zerobin;
$content = ob_get_contents();
$this->assertTag(
array(
'id' => 'shortenbutton',
'attributes' => array('data-shortener' => $shortener)
),
$content,
'outputs configured shortener URL correctly'
);
}
/**
* @runInSeparateProcess
*/