]> git.mxchange.org Git - friendica.git/commitdiff
upload images to the selected album
authorrabuzarus <>
Tue, 21 Mar 2017 22:08:37 +0000 (23:08 +0100)
committerrabuzarus <>
Tue, 21 Mar 2017 22:08:37 +0000 (23:08 +0100)
mod/wall_upload.php
view/theme/frio/js/filebrowser.js
view/theme/frio/js/theme.js
view/theme/frio/templates/filebrowser.tpl

index 1f71f36b62d1036f6b224e3df19f0b6d6463bc18..2f3bd14154c99ef6a9d468c01a01fb98eab4b9d2 100644 (file)
@@ -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;
        }
index d18bf8e7964aaa93388484fe0f024cf3629f27f5..8617e802075c96489c9332d6004b07e6a5308b57 100644 (file)
@@ -68,6 +68,7 @@ var FileBrowser = {
        nickname : "",\r
        type : "",\r
        event: "",\r
+       folder: "",\r
        id : null,\r
 \r
        init: function(nickname, type, hash) {\r
@@ -99,6 +100,7 @@ var FileBrowser = {
                $(".fbrowser").on("click", ".folders a, .path a", function(e) {\r
                        e.preventDefault();\r
                        var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none";\r
+                       FileBrowser.folder = this.dataset.folder;\r
 \r
                        FileBrowser.loadContent(url);\r
                });\r
@@ -134,7 +136,7 @@ var FileBrowser = {
                                this.dataset.filename,\r
                                embed,\r
                                FileBrowser.id,\r
-                               this.dataset.img,\r
+                               this.dataset.img\r
                        ]);\r
 \r
                        // Close model\r
@@ -157,9 +159,12 @@ var FileBrowser = {
        // Initialize the AjaxUpload for the upload buttons\r
        uploadButtons: function() {\r
                if ($("#upload-image").length) {\r
+                       // To get the albumname we need to convert it from hex\r
+                       var albumname = hex2bin(FileBrowser.folder);\r
+                       //AjaxUpload for images\r
                        var image_uploader = new window.AjaxUpload(\r
                                'upload-image',\r
-                               {       action: 'wall_upload/'+FileBrowser.nickname+'?response=json',\r
+                               {       action: 'wall_upload/'+FileBrowser.nickname+'?response=json&album=' + albumname,\r
                                        name: 'userfile',\r
                                        responseType: 'json',\r
                                        onSubmit: function(file,ext) {\r
@@ -178,7 +183,7 @@ var FileBrowser = {
 //                                             location = baseurl + "/fbrowser/image/?mode=none"+location['hash'];\r
 //                                             location.reload(true);\r
 \r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"\r
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none";\r
                                                // load new content to fbrowser window\r
                                                FileBrowser.loadContent(url);\r
                                        }\r
@@ -187,9 +192,10 @@ var FileBrowser = {
                }\r
 \r
                if ($("#upload-file").length) {\r
+                       //AjaxUpload for files\r
                        var file_uploader = new window.AjaxUpload(\r
                                'upload-file',\r
-                               {       action: 'wall_attach/'+FileBrowser.nickname+'?response=json',\r
+                               {       action: 'wall_attach/' + FileBrowser.nickname + '?response=json',\r
                                        name: 'userfile',\r
                                        onSubmit: function(file,ext) {\r
                                                $(".fbrowser-content").hide();\r
@@ -207,15 +213,16 @@ var FileBrowser = {
 //                                             location = baseurl + "/fbrowser/file/?mode=none"+location['hash'];\r
 //                                             location.reload(true);\r
 \r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"\r
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none";\r
                                                // Load new content to fbrowser window\r
-                                               FileBrowser.loadContent(url)\r
+                                               FileBrowser.loadContent(url);\r
                                        }\r
                                }\r
                        );\r
                }\r
        },\r
 \r
+       // Stuff which should be executed if ne content was loaded\r
        postLoad: function() {\r
                FileBrowser.initGallery();\r
                $(".fbrowser .fbswitcher .btn").removeClass("active");\r
@@ -225,6 +232,7 @@ var FileBrowser = {
                \r
        },\r
 \r
+       // Load new content (e.g. change photo album)\r
        loadContent: function(url) {\r
                $(".fbrowser-content").hide();\r
                $(".fbrowser .profile-rotator-wrapper").show();\r
@@ -239,6 +247,7 @@ var FileBrowser = {
                });\r
        },\r
 \r
+       // Initialize justified Gallery\r
        initGallery: function() {\r
                $(".fbrowser.image .fbrowser-content-container").justifiedGallery({\r
                        'rowHeight': 80,\r
index 62cd85df9b53975e96ced89b868c78a489cae9ff..09f96da36c757d9438bc4b608531fe1e89375a73 100644 (file)
@@ -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
index cb05348951d4d89abf9f26a8861805d06d49a64a..826b82c54533186c265a0ce5b6c48d0f27ab1d11 100644 (file)
                        <span></span> <a href="#" class='close'>X</a>
                </div>
 
+               {{* The breadcrumb navigation *}}
                <ol class="path breadcrumb">
                        {{foreach $path as $p}}<li><a href="#" data-folder="{{$p.0}}">{{$p.1}}</a></li>{{/foreach}}
+
+                       {{* Switch between image and file mode *}}
                        <div class="fbswitcher btn-group btn-group-xs pull-right">
                                <button type="button" class="btn btn-default" data-mode="image"><i class="fa fa-picture-o" aria-hidden="true"></i></button>
                                <button type="button" class="btn btn-default" data-mode="file"><i class="fa fa-file-o" aria-hidden="true"></i></button>
@@ -25,6 +28,8 @@
                </ol>
 
                <div class="media">
+
+                       {{* List of photo albums *}}
                        {{if $folders }}
                        <div class="folders media-left">
                                <ul>
@@ -33,6 +38,7 @@
                        </div>
                        {{/if}}
 
+                       {{* The main content (images or files) *}}
                        <div class="list {{$type}} media-body">
                                <div class="fbrowser-content-container">
                                        {{foreach $files as $f}}
                </div>
 
                <div class="upload">
-                       <button id="upload-{{$type}}"><img id="profile-rotator" src="images/rotator.gif" alt="{{$wait}}" title="{{$wait|escape:'html'}}" style="display: none;" /> {{"Upload"|t}}</button>
+                       <button id="upload-{{$type}}">{{"Upload"|t}}</button>
                </div>
        </div>
+
+       {{* This part contains the conent loader icon which is visible when new conent is loaded *}}
        <div class="profile-rotator-wrapper" style="display: none;">
                <i class="fa fa-circle-o-notch fa-spin" aria-hidden="true"></i>
        </div>