mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-03 01:39:15 +02:00
Auto Shortening URLs
This commit is contained in:
parent
08c44cfb05
commit
059e64adb1
7 changed files with 43 additions and 2 deletions
|
@ -84,6 +84,11 @@ languageselection = false
|
||||||
; the documents encryption key.
|
; the documents encryption key.
|
||||||
; urlshortener = "https://shortener.example.com/api?link="
|
; urlshortener = "https://shortener.example.com/api?link="
|
||||||
|
|
||||||
|
; (optional) Whether to shorten the URL by default when a new document is created.
|
||||||
|
; If set to true, the "Shorten URL" functionality will be automatically called.
|
||||||
|
; This only works if the "urlshortener" option is set.
|
||||||
|
; shortenbydefault = false
|
||||||
|
|
||||||
; (optional) Let users create a QR code for sharing the document URL with one click.
|
; (optional) Let users create a QR code for sharing the document URL with one click.
|
||||||
; It works both when a new document is created and when you view a document.
|
; It works both when a new document is created and when you view a document.
|
||||||
; qrcode = true
|
; qrcode = true
|
||||||
|
|
|
@ -210,6 +210,7 @@
|
||||||
"Encrypted note on %s": "Encrypted note on %s",
|
"Encrypted note on %s": "Encrypted note on %s",
|
||||||
"Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.": "Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.",
|
"Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.": "Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.",
|
||||||
"URL shortener may expose your decrypt key in URL.": "URL shortener may expose your decrypt key in URL.",
|
"URL shortener may expose your decrypt key in URL.": "URL shortener may expose your decrypt key in URL.",
|
||||||
|
"URL shortener is enabled by default.": "URL shortener is enabled by default.",
|
||||||
"Save document": "Save document",
|
"Save document": "Save document",
|
||||||
"Your IP is not authorized to create documents.": "Your IP is not authorized to create documents.",
|
"Your IP is not authorized to create documents.": "Your IP is not authorized to create documents.",
|
||||||
"Trying to shorten a URL that isn't pointing at our instance.": "Trying to shorten a URL that isn't pointing at our instance.",
|
"Trying to shorten a URL that isn't pointing at our instance.": "Trying to shorten a URL that isn't pointing at our instance.",
|
||||||
|
|
|
@ -2120,6 +2120,21 @@ jQuery.PrivateBin = (function($) {
|
||||||
Helper.selectText($pasteUrl[0]);
|
Helper.selectText($pasteUrl[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if auto-shortening is enabled and sends the link to the shortener if it is.
|
||||||
|
*
|
||||||
|
* @name PasteStatus.checkAutoShorten
|
||||||
|
* @function
|
||||||
|
*/
|
||||||
|
me.checkAutoShorten = function() {
|
||||||
|
// check if auto-shortening is enabled
|
||||||
|
if ($shortenButton.data('autoshorten') === true) {
|
||||||
|
// if so, we send the link to the shortener
|
||||||
|
// we do not remove the button, in case shortener fails
|
||||||
|
sendToShortener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extracts URLs from given string
|
* extracts URLs from given string
|
||||||
*
|
*
|
||||||
|
@ -5030,6 +5045,8 @@ jQuery.PrivateBin = (function($) {
|
||||||
TopNav.hideDownloadButton();
|
TopNav.hideDownloadButton();
|
||||||
Editor.hide();
|
Editor.hide();
|
||||||
|
|
||||||
|
PasteStatus.checkAutoShorten();
|
||||||
|
|
||||||
// parse and show text
|
// parse and show text
|
||||||
// (preparation already done in me.sendPaste())
|
// (preparation already done in me.sendPaste())
|
||||||
PasteViewer.run();
|
PasteViewer.run();
|
||||||
|
|
|
@ -61,6 +61,7 @@ class Configuration
|
||||||
'languageselection' => false,
|
'languageselection' => false,
|
||||||
'languagedefault' => '',
|
'languagedefault' => '',
|
||||||
'urlshortener' => '',
|
'urlshortener' => '',
|
||||||
|
'shortenbydefault' => false,
|
||||||
'qrcode' => true,
|
'qrcode' => true,
|
||||||
'email' => true,
|
'email' => true,
|
||||||
'icon' => 'jdenticon',
|
'icon' => 'jdenticon',
|
||||||
|
|
|
@ -477,6 +477,7 @@ class Controller
|
||||||
$page->assign('EXPIRE', $expire);
|
$page->assign('EXPIRE', $expire);
|
||||||
$page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire'));
|
$page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire'));
|
||||||
$page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener'));
|
$page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener'));
|
||||||
|
$page->assign('SHORTENBYDEFAULT', $this->_conf->getKey('shortenbydefault'));
|
||||||
$page->assign('QRCODE', $this->_conf->getKey('qrcode'));
|
$page->assign('QRCODE', $this->_conf->getKey('qrcode'));
|
||||||
$page->assign('EMAIL', $this->_conf->getKey('email'));
|
$page->assign('EMAIL', $this->_conf->getKey('email'));
|
||||||
$page->assign('HTTPWARNING', $this->_conf->getKey('httpwarning'));
|
$page->assign('HTTPWARNING', $this->_conf->getKey('httpwarning'));
|
||||||
|
|
|
@ -565,12 +565,20 @@ endif;
|
||||||
if (!empty($URLSHORTENER)) :
|
if (!empty($URLSHORTENER)) :
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
<button id="shortenbutton" data-shortener="<?php echo I18n::encode($URLSHORTENER); ?>" type="button" class="btn btn-<?php echo $isDark ? 'warning' : 'primary'; ?> btn-block">
|
<button id="shortenbutton" data-shortener="<?php echo I18n::encode($URLSHORTENER); ?>"
|
||||||
|
<?php if ($SHORTENBYDEFAULT) : ?>
|
||||||
|
data-autoshorten="true"
|
||||||
|
<?php endif; ?>
|
||||||
|
type="button" class="btn btn-<?php echo $isDark ? 'warning' : 'primary'; ?> btn-block"
|
||||||
|
>
|
||||||
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo I18n::_('Shorten URL'), PHP_EOL; ?>
|
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo I18n::_('Shorten URL'), PHP_EOL; ?>
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
<div role="alert" class="alert alert-danger">
|
<div role="alert" class="alert alert-danger">
|
||||||
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
|
||||||
|
<?php if ($SHORTENBYDEFAULT) : ?>
|
||||||
|
<?php echo I18n::_('URL shortener is enabled by default.'), PHP_EOL; ?>
|
||||||
|
<?php endif; ?>
|
||||||
<?php echo I18n::_('URL shortener may expose your decrypt key in URL.'), PHP_EOL; ?>
|
<?php echo I18n::_('URL shortener may expose your decrypt key in URL.'), PHP_EOL; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -432,12 +432,20 @@ endif;
|
||||||
if (!empty($URLSHORTENER)) :
|
if (!empty($URLSHORTENER)) :
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
<button id="shortenbutton" data-shortener="<?php echo I18n::encode($URLSHORTENER); ?>" type="button" class="btn btn-primary btn-block d-flex justify-content-center align-items-center gap-1">
|
<button id="shortenbutton" data-shortener="<?php echo I18n::encode($URLSHORTENER); ?>"
|
||||||
|
<?php if ($SHORTENBYDEFAULT) : ?>
|
||||||
|
data-autoshorten="true"
|
||||||
|
<?php endif; ?>
|
||||||
|
type="button" class="btn btn-primary btn-block d-flex justify-content-center align-items-center gap-1"
|
||||||
|
>
|
||||||
<svg width="16" height="16" fill="currentColor" aria-hidden="true"><use href="img/bootstrap-icons.svg#send" /></svg> <?php echo I18n::_('Shorten URL'), PHP_EOL; ?>
|
<svg width="16" height="16" fill="currentColor" aria-hidden="true"><use href="img/bootstrap-icons.svg#send" /></svg> <?php echo I18n::_('Shorten URL'), PHP_EOL; ?>
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
<div role="alert" class="alert alert-danger">
|
<div role="alert" class="alert alert-danger">
|
||||||
<svg width="16" height="16" fill="currentColor" aria-hidden="true"><use href="img/bootstrap-icons.svg#exclamation-circle" /></svg>
|
<svg width="16" height="16" fill="currentColor" aria-hidden="true"><use href="img/bootstrap-icons.svg#exclamation-circle" /></svg>
|
||||||
|
<?php if ($SHORTENBYDEFAULT) : ?>
|
||||||
|
<?php echo I18n::_('URL shortener is enabled by default.'), PHP_EOL; ?>
|
||||||
|
<?php endif; ?>
|
||||||
<?php echo I18n::_('URL shortener may expose your decrypt key in URL.'), PHP_EOL; ?>
|
<?php echo I18n::_('URL shortener may expose your decrypt key in URL.'), PHP_EOL; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue