From 414ab0eb718b605ef738adf3bca2f8ecdae8509b Mon Sep 17 00:00:00 2001 From: rugk Date: Mon, 25 Dec 2017 14:59:15 +0100 Subject: [PATCH] Add config and basic page template support * load JS file asyncronously (just HTML5 async attribut) * add basic support for page template, where it generates the code inside of a simple div at the top * added option to turn off QR code support --- cfg/conf.sample.php | 4 +++ css/bootstrap/privatebin.css | 10 ------ img/icon_qr.png | Bin 0 -> 437 bytes js/{kjua.min.js => kjua-0.1.2.min.js} | 0 js/privatebin.js | 43 +++++++++++------------ lib/Configuration.php | 1 + lib/PrivateBin.php | 1 + tpl/bootstrap.php | 20 ++++++++--- tpl/page.php | 47 +++++++++++++++++--------- 9 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 img/icon_qr.png rename js/{kjua.min.js => kjua-0.1.2.min.js} (100%) diff --git a/cfg/conf.sample.php b/cfg/conf.sample.php index 4db8a33..e693a32 100644 --- a/cfg/conf.sample.php +++ b/cfg/conf.sample.php @@ -56,6 +56,10 @@ languageselection = false ; the pastes encryption key ; urlshortener = "https://shortener.example.com/api?link=" +; (optional) Let users create a QR code for sharing the paste URL with one click. +; It works both when a new paste is created and when you view a paste. +; qrcode = true + ; (optional) IP based icons are a weak mechanism to detect if a comment was from ; a different user when the same username was used in a comment. It might be ; used to get the IP of a non anonymous comment poster if the server salt is diff --git a/css/bootstrap/privatebin.css b/css/bootstrap/privatebin.css index 3740475..e0dd81f 100644 --- a/css/bootstrap/privatebin.css +++ b/css/bootstrap/privatebin.css @@ -79,16 +79,6 @@ body.loading { margin-left: 5px; } -#qrcodelink { - color: #337ab7; - float: right; - margin-left: 5px; - cursor: pointer; -} -#qrcodelink:hover, #qrcodelink:focus { - color: #23527c; -} - #qrcodemodalClose { float: right; } diff --git a/img/icon_qr.png b/img/icon_qr.png new file mode 100644 index 0000000000000000000000000000000000000000..9d32efbfd4d86ff8ccb63cf1e50466f751d02b25 GIT binary patch literal 437 zcmV;m0ZRUfP)ZgXgFbngSdJ^%m#M@d9MR9J=W zmr-)WAP9!B(|g66L2hPFMqgHkDxjv@EuGnKh8Kel!9RaAF*8FDKK{A@$-5X6egFVl zfrxx}t_(@2&V2R*$8kW;*_?2m=hDK6Xg({Yz;#{YgTB?W{Tf;xOxoXri1D|{EheP| zDJ38xcM)a=W>&X`h}t?oD(2M;0+!S_)dXEiX&v)A=Y0$VcLfZJSS?}xO94N{fwebY zjj)~BcHoMZV+p;wt>?-BurJ_URz)3dn_4maa8c-jkWx zZCA%;F>~cm+vFCbxw4n1{Rrg;QIVovF6Pw?0=C@NL*`pIgq68Zy=&h&{e=~9;ybqb fON8poyBLcvlVeHxeZHAL00000NkvXXu0mjf*L=96 literal 0 HcmV?d00001 diff --git a/js/kjua.min.js b/js/kjua-0.1.2.min.js similarity index 100% rename from js/kjua.min.js rename to js/kjua-0.1.2.min.js diff --git a/js/privatebin.js b/js/privatebin.js index 5b1789e..a8c3b61 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1206,8 +1206,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { var $pasteSuccess, $pasteUrl, $remainingTime, - $shortenButton, - $qrCodeLink; + $shortenButton; /** * forward to URL shortener @@ -1242,23 +1241,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { } } - /** - * Shows the QR code of the current paste. - * - * @name PasteStatus.displayQrCode - * @function - * @param {Event} event - */ - function displayQrCode(event) - { - var qrCanvas = kjua({ - render: 'canvas', - text: $pasteUrl.attr('href') - }); - $('#qrcode-display').html(qrCanvas); - - } - /** * creates a notification after a successfull paste upload * @@ -1355,11 +1337,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // $pasteUrl is saved in me.createPasteNotification() after creation $remainingTime = $('#remainingtime'); $shortenButton = $('#shortenbutton'); - $qrCodeLink = $('#qrcodelink'); // bind elements $shortenButton.click(sendToShortener); - $qrCodeLink.click(displayQrCode); } return me; @@ -2429,6 +2409,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $password, $passwordInput, $rawTextButton, + $qrCodeLink, $sendButton; var pasteExpiration = '1week'; @@ -2606,6 +2587,22 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { event.preventDefault(); } + /** + * Shows the QR code of the current paste (URL). + * + * @name TopNav.displayQrCode + * @function + * @param {Event} event + */ + function displayQrCode(event) + { + var qrCanvas = kjua({ + render: 'canvas', + text: window.location.href + }); + $('#qrcode-display').html(qrCanvas); + } + /** * Shows all elements belonging to viwing an existing pastes * @@ -2622,6 +2619,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $newButton.removeClass('hidden'); $cloneButton.removeClass('hidden'); $rawTextButton.removeClass('hidden'); + $qrCodeLink.removeClass('hidden'); viewButtonsDisplayed = true; } @@ -2642,6 +2640,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $newButton.addClass('hidden'); $cloneButton.addClass('hidden'); $rawTextButton.addClass('hidden'); + $qrCodeLink.addClass('hidden'); viewButtonsDisplayed = false; } @@ -2892,6 +2891,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $passwordInput = $('#passwordinput'); $rawTextButton = $('#rawtextbutton'); $sendButton = $('#sendbutton'); + $qrCodeLink = $('#qrcodelink'); // bootstrap template drop down $('#language ul.dropdown-menu li a').click(setLanguage); @@ -2906,6 +2906,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $cloneButton.click(Controller.clonePaste); $rawTextButton.click(rawText); $fileRemoveButton.click(removeAttachment); + $qrCodeLink.click(displayQrCode); // bootstrap template drop downs $('ul.dropdown-menu li a', $('#expiration').parent()).click(updateExpiration); diff --git a/lib/Configuration.php b/lib/Configuration.php index 274743e..c7c8451 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -52,6 +52,7 @@ class Configuration 'languageselection' => false, 'languagedefault' => '', 'urlshortener' => '', + 'qrcode' => true, 'icon' => 'identicon', 'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer; sandbox allow-same-origin allow-scripts allow-forms allow-popups', 'zerobincompatibility' => false, diff --git a/lib/PrivateBin.php b/lib/PrivateBin.php index 7b53fa1..f26abad 100644 --- a/lib/PrivateBin.php +++ b/lib/PrivateBin.php @@ -448,6 +448,7 @@ class PrivateBin $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->assign('QRCODE', $this->_conf->getKey('qrcode')); $page->draw($this->_conf->getKey('template')); } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 5b7cfe1..bdcd90b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -43,8 +43,12 @@ endif; - + + @@ -71,7 +75,7 @@ if ($MARKDOWN): - + @@ -174,6 +178,15 @@ endif; + + +