From: rabuzarus <> Date: Tue, 21 Mar 2017 22:08:37 +0000 (+0100) Subject: upload images to the selected album X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=835e54dfc367a30f714d8369857c5c575fb77eae;p=friendica.git upload images to the selected album --- diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 1f71f36b62..2f3bd14154 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -7,6 +7,7 @@ function wall_upload_post(App $a, $desktopmode = true) { logger("wall upload: starting new upload", LOGGER_DEBUG); $r_json = (x($_GET,'response') && $_GET['response']=='json'); + $album = (x($_GET, 'album') ? notags(trim($_GET['album'])) : ''); if($a->argc > 1) { if(! x($_FILES,'media')) { @@ -211,9 +212,14 @@ function wall_upload_post(App $a, $desktopmode = true) { $smallest = 0; + // If we don't have an album name use the Wall Photos album + if (! strlen($album)) { + $album = t('Wall Photos'); + } + $defperm = '<' . $default_cid . '>'; - $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); + $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm); if(! $r) { $msg = t('Image upload failed.'); @@ -227,14 +233,14 @@ function wall_upload_post(App $a, $desktopmode = true) { if($width > 640 || $height > 640) { $ph->scaleImage(640); - $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); + $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm); if($r) $smallest = 1; } if($width > 320 || $height > 320) { $ph->scaleImage(320); - $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); + $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm); if($r AND ($smallest == 0)) $smallest = 2; } diff --git a/view/theme/frio/js/filebrowser.js b/view/theme/frio/js/filebrowser.js index d18bf8e796..8617e80207 100644 --- a/view/theme/frio/js/filebrowser.js +++ b/view/theme/frio/js/filebrowser.js @@ -68,6 +68,7 @@ var FileBrowser = { nickname : "", type : "", event: "", + folder: "", id : null, init: function(nickname, type, hash) { @@ -99,6 +100,7 @@ var FileBrowser = { $(".fbrowser").on("click", ".folders a, .path a", function(e) { e.preventDefault(); var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none"; + FileBrowser.folder = this.dataset.folder; FileBrowser.loadContent(url); }); @@ -134,7 +136,7 @@ var FileBrowser = { this.dataset.filename, embed, FileBrowser.id, - this.dataset.img, + this.dataset.img ]); // Close model @@ -157,9 +159,12 @@ var FileBrowser = { // Initialize the AjaxUpload for the upload buttons uploadButtons: function() { if ($("#upload-image").length) { + // To get the albumname we need to convert it from hex + var albumname = hex2bin(FileBrowser.folder); + //AjaxUpload for images var image_uploader = new window.AjaxUpload( 'upload-image', - { action: 'wall_upload/'+FileBrowser.nickname+'?response=json', + { action: 'wall_upload/'+FileBrowser.nickname+'?response=json&album=' + albumname, name: 'userfile', responseType: 'json', onSubmit: function(file,ext) { @@ -178,7 +183,7 @@ var FileBrowser = { // location = baseurl + "/fbrowser/image/?mode=none"+location['hash']; // location.reload(true); - var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none" + var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none"; // load new content to fbrowser window FileBrowser.loadContent(url); } @@ -187,9 +192,10 @@ var FileBrowser = { } if ($("#upload-file").length) { + //AjaxUpload for files var file_uploader = new window.AjaxUpload( 'upload-file', - { action: 'wall_attach/'+FileBrowser.nickname+'?response=json', + { action: 'wall_attach/' + FileBrowser.nickname + '?response=json', name: 'userfile', onSubmit: function(file,ext) { $(".fbrowser-content").hide(); @@ -207,15 +213,16 @@ var FileBrowser = { // location = baseurl + "/fbrowser/file/?mode=none"+location['hash']; // location.reload(true); - var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none" + var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"; // Load new content to fbrowser window - FileBrowser.loadContent(url) + FileBrowser.loadContent(url); } } ); } }, + // Stuff which should be executed if ne content was loaded postLoad: function() { FileBrowser.initGallery(); $(".fbrowser .fbswitcher .btn").removeClass("active"); @@ -225,6 +232,7 @@ var FileBrowser = { }, + // Load new content (e.g. change photo album) loadContent: function(url) { $(".fbrowser-content").hide(); $(".fbrowser .profile-rotator-wrapper").show(); @@ -239,6 +247,7 @@ var FileBrowser = { }); }, + // Initialize justified Gallery initGallery: function() { $(".fbrowser.image .fbrowser-content-container").justifiedGallery({ 'rowHeight': 80, diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index 62cd85df9b..09f96da36c 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -617,3 +617,53 @@ function htmlToText(htmlString) { return text; } + +// Decodes a hexadecimally encoded binary string +function hex2bin (s) { + // discuss at: http://locutus.io/php/hex2bin/ + // original by: Dumitru Uzun (http://duzun.me) + // example 1: hex2bin('44696d61') + // returns 1: 'Dima' + // example 2: hex2bin('00') + // returns 2: '\x00' + // example 3: hex2bin('2f1q') + // returns 3: false + var ret = []; + var i = 0; + var l; + s += ''; + + for (l = s.length; i < l; i += 2) { + var c = parseInt(s.substr(i, 1), 16); + var k = parseInt(s.substr(i + 1, 1), 16); + if (isNaN(c) || isNaN(k)) { + return false; + } + ret.push((c << 4) | k); + } + return String.fromCharCode.apply(String, ret); +} + +// Convert binary data into hexadecimal representation +function bin2hex (s) { + // From: http://phpjs.org/functions + // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + bugfixed by: Onno Marsman + // + bugfixed by: Linuxworld + // + improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616) + // * example 1: bin2hex('Kev'); + // * returns 1: '4b6576' + // * example 2: bin2hex(String.fromCharCode(0x00)); + // * returns 2: '00' + + var i, l, o = "", n; + + s += ""; + + for (i = 0, l = s.length; i < l; i++) { + n = s.charCodeAt(i).toString(16); + o += n.length < 2 ? "0" + n : n; + } + + return o; +} \ No newline at end of file diff --git a/view/theme/frio/templates/filebrowser.tpl b/view/theme/frio/templates/filebrowser.tpl index cb05348951..826b82c545 100644 --- a/view/theme/frio/templates/filebrowser.tpl +++ b/view/theme/frio/templates/filebrowser.tpl @@ -16,8 +16,11 @@ X + {{* The breadcrumb navigation *}}