]> git.mxchange.org Git - friendica.git/commitdiff
create workaround for not working php
authorJakobus Schürz <jakobus.schuerz@schuerz.at>
Mon, 13 Mar 2023 23:34:50 +0000 (00:34 +0100)
committerJakobus Schürz <jakobus.schuerz@schuerz.at>
Sun, 19 Mar 2023 17:52:45 +0000 (18:52 +0100)
Strings:getBytesFromShorthand

i created a js-function which converts integer, k, m and g to MB
Just remove this code, when we found out, why Strings is in some files
not working.

mod/photos.php
src/Content/Conversation.php
src/Module/Post/Edit.php
src/Object/Post.php
view/templates/item/compose.tpl
view/theme/frio/js/dropzone-frio.js [new file with mode: 0644]
view/theme/frio/templates/comment_item.tpl
view/theme/frio/templates/head.tpl
view/theme/frio/templates/jot.tpl

index 440aae92ebf46e3bbd497f091abb39ff2657f6c0..97c0fb22e6106e981ba6b2dd5dc5a93d44375b02 100644 (file)
@@ -1141,6 +1141,8 @@ function photos_content(App $a)
                                                '$qcomment' => $qcomment,
                                                '$rand_num' => Crypto::randomDigits(12),
                                                // Dropzone
+                                                //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                                                // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
                                                '$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
                                        ]);
                                }
@@ -1198,6 +1200,8 @@ function photos_content(App $a)
                                                '$qcomment' => $qcomment,
                                                '$rand_num' => Crypto::randomDigits(12),
                                                // Dropzone
+                                                //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                                                // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
                                                '$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
                                        ]);
                                }
@@ -1274,6 +1278,8 @@ function photos_content(App $a)
                                                        '$qcomment' => $qcomment,
                                                        '$rand_num' => Crypto::randomDigits(12),
                                                        // Dropzone
+                                                        //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                                                        // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
                                                        '$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
                                                ]);
                                        }
index 586b0bc540c2b03f90a4966d92721f2c674c6fe3..8460f942326d8efc1d06c8dfac522ef3d470d5a9 100644 (file)
@@ -35,6 +35,7 @@ use Friendica\Core\Renderer;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\Theme;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item as ItemModel;
 use Friendica\Model\Post;
@@ -408,10 +409,11 @@ class Conversation
 
                        '$compose_link_title'  => $this->l10n->t('Open Compose page'),
                        '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
+
                        // Dropzone
-                       //'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
-                       // DI::config.. does not work here, so it is set to a manual value
-                       '$max_imagesize'       => 600000,
+                        //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                        // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
+                       '$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
 
                ]);
 
index d5b27d648f228c1c590cd6925fcc9f531192d555..3e47889b219e34bff58a11dedba0b431af058310 100644 (file)
@@ -185,9 +185,9 @@ class Edit extends BaseModule
 
                        '$compose_link_title' => $this->t('Open Compose page'),
                        // Dropzone
-                       //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
                        //'$max_imagesize'       => \Friendica\\Util\\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
-                        // both not working, so just workaround here until fixed
+                       //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                        // both not working, so just workaround in template and serve the bare value
                        '$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
                ]);
 
index 59617573e0e9338cad0a5d64ce8975c5736ea94d..9e569c6a161634db39453ffd81b7bbeb83b5c68c 100644 (file)
@@ -1070,6 +1070,8 @@ class Post
                                '$indent'      => $indent,
                                '$rand_num'    => Crypto::randomDigits(12),
                                // Dropzone
+                                //'$max_imagesize'       => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
+                                // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
                                '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
                        ]);
                }
index 3db9a64f5598f3a295501e25e375866e65100916..226014ff9a5faa9d8ad5be1d2f04107bc6ca10df 100644 (file)
        </div>
 </div>
 <script>
+       // getMByte() is from view/theme/frio/js/dropzone-frio.js
+       // to workaround dysfunctional php Strings:getBytesFromShorthand
        Dropzone.autoDiscover = false;
-       var maxis = {{$max_imagesize}} / 10^6;
        var dropzoneCompose = new Dropzone( '#comment-edit-form-{{$id}}',  { 
                paramName: "userfile", // The name that will be used to transfer the file
-               maxFilesize: maxis, // MB
+               maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
                previewsContainer: '#dz-previewsCompose',
                preventDuplicates: true,
                clickable: true,
diff --git a/view/theme/frio/js/dropzone-frio.js b/view/theme/frio/js/dropzone-frio.js
new file mode 100644 (file)
index 0000000..c165633
--- /dev/null
@@ -0,0 +1,24 @@
+function isInteger(value) {
+       return /^\d+$/.test(value);
+}
+
+function getMBytes(value) {
+       var res;
+       if (isInteger(value)) {
+               res = value;
+       } else {
+               eh = value.slice(-1);
+               am = Number(value.slice(0, -1));
+               switch (eh) {
+                       case 'k':
+                               res = am * 1024;
+                               break;
+                       case 'm':
+                               res = am * 1024 * 1024;
+                               break;
+                       case 'g':
+                               res = am * 1024 * 1024 * 1024;
+               }
+       }
+       return res / 1000000;
+}
index 119b5956e7073332887b552b486d42f2a585349f..b66b77557f649f68d2c3f31d62729d5f29cb6915 100644 (file)
 </div>
 
 <script>
+       // getMByte() is from view/theme/frio/js/dropzone-frio.js
+       // to workaround dysfunctional php Strings:getBytesFromShorthand
        Dropzone.autoDiscover = false;
-       var maxis = {{$max_imagesize}} / 10^6;
        var dropzone{{$id}} = new Dropzone( '#comment-edit-wrapper-{{$id}}', {
                paramName: "userfile", // The name that will be used to transfer the file
-               maxFilesize: maxis, // MB
+               maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
                previewsContainer: '#dz-preview-{{$id}}',
                preventDuplicates: true,
                clickable: true,
index b506ad2786633577d6d1132cc6889a06afa58859..b7bed6810bb9a55b87cd79e1e160691ed739d845 100644 (file)
                <script type="text/javascript" src="view/theme/frio/js/hovercard.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
        {{/if}}
        <script type="text/javascript" src="view/theme/frio/js/textedit.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
-        <script type="text/javascript" src="vendor/enyo/dropzone/dist/min/dropzone.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
+       <script type="text/javascript" src="vendor/enyo/dropzone/dist/min/dropzone.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
+       <script type="text/javascript" src="view/theme/frio/js/dropzone-frio.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
 
        {{* Include the strings which are needed for some js functions (e.g. translation)
 They are loaded into the html <head> so that js functions can use them *}}
index 2d20fef442080a56ca6a4702c82fe5432225f12e..70769109461536c0d5248adcd98711688229f7bf 100644 (file)
@@ -180,11 +180,12 @@ can load different content into the jot modal (e.g. the item edit jot)
 </script>
 
 <script>
+       // getMByte() is from view/theme/frio/js/dropzone-frio.js
+       // to workaround dysfunctional php Strings:getBytesFromShorthand
        Dropzone.autoDiscover = false;
-       var maxis = {{$max_filesize}} / 10^6;
        var dropzoneJot = new Dropzone( '#jot-modal-content', {
                paramName: "userfile", // The name that will be used to transfer the file
-               maxFilesize: maxis, // MB
+               maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
                previewsContainer: '#dz-preview-jot',
                url: "/media/photo/upload?response=url&album=",
                accept: function(file, done) {