create workaround for not working php

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.
This commit is contained in:
Jakobus Schürz 2023-03-14 00:34:50 +01:00
parent 00ae7d0f59
commit 3688196859
9 changed files with 50 additions and 12 deletions

View file

@ -1141,6 +1141,8 @@ function photos_content(App $a)
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone // 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'), '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);
} }
@ -1198,6 +1200,8 @@ function photos_content(App $a)
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone // 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'), '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);
} }
@ -1274,6 +1278,8 @@ function photos_content(App $a)
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone // 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'), '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);
} }

View file

@ -35,6 +35,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\Theme; use Friendica\Core\Theme;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item as ItemModel; use Friendica\Model\Item as ItemModel;
use Friendica\Model\Post; use Friendica\Model\Post;
@ -408,10 +409,11 @@ class Conversation
'$compose_link_title' => $this->l10n->t('Open Compose page'), '$compose_link_title' => $this->l10n->t('Open Compose page'),
'$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false), '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
// Dropzone // Dropzone
//'$max_imagesize' => DI::config()->get('system', 'maximagesize'), //'$max_imagesize' => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
// DI::config.. does not work here, so it is set to a manual value // Strings::getBytresFromShorthand not working, so just workaround in template and serve the bare value
'$max_imagesize' => 600000, '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);

View file

@ -185,9 +185,9 @@ class Edit extends BaseModule
'$compose_link_title' => $this->t('Open Compose page'), '$compose_link_title' => $this->t('Open Compose page'),
// Dropzone // Dropzone
//'$max_imagesize' => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
//'$max_imagesize' => \Friendica\\Util\\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'), '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);

View file

@ -1070,6 +1070,8 @@ class Post
'$indent' => $indent, '$indent' => $indent,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone // 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'), '$max_imagesize' => DI::config()->get('system', 'maximagesize'),
]); ]);
} }

View file

@ -96,11 +96,12 @@
</div> </div>
</div> </div>
<script> <script>
// getMByte() is from view/theme/frio/js/dropzone-frio.js
// to workaround dysfunctional php Strings:getBytesFromShorthand
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
var maxis = {{$max_imagesize}} / 10^6;
var dropzoneCompose = new Dropzone( '#comment-edit-form-{{$id}}', { var dropzoneCompose = new Dropzone( '#comment-edit-form-{{$id}}', {
paramName: "userfile", // The name that will be used to transfer the file paramName: "userfile", // The name that will be used to transfer the file
maxFilesize: maxis, // MB maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
previewsContainer: '#dz-previewsCompose', previewsContainer: '#dz-previewsCompose',
preventDuplicates: true, preventDuplicates: true,
clickable: true, clickable: true,

View file

@ -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;
}

View file

@ -66,11 +66,12 @@
</div> </div>
<script> <script>
// getMByte() is from view/theme/frio/js/dropzone-frio.js
// to workaround dysfunctional php Strings:getBytesFromShorthand
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
var maxis = {{$max_imagesize}} / 10^6;
var dropzone{{$id}} = new Dropzone( '#comment-edit-wrapper-{{$id}}', { var dropzone{{$id}} = new Dropzone( '#comment-edit-wrapper-{{$id}}', {
paramName: "userfile", // The name that will be used to transfer the file paramName: "userfile", // The name that will be used to transfer the file
maxFilesize: maxis, // MB maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
previewsContainer: '#dz-preview-{{$id}}', previewsContainer: '#dz-preview-{{$id}}',
preventDuplicates: true, preventDuplicates: true,
clickable: true, clickable: true,

View file

@ -139,7 +139,8 @@
<script type="text/javascript" src="view/theme/frio/js/hovercard.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <script type="text/javascript" src="view/theme/frio/js/hovercard.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
{{/if}} {{/if}}
<script type="text/javascript" src="view/theme/frio/js/textedit.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <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) {{* 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 *}} They are loaded into the html <head> so that js functions can use them *}}

View file

@ -180,11 +180,12 @@ can load different content into the jot modal (e.g. the item edit jot)
</script> </script>
<script> <script>
// getMByte() is from view/theme/frio/js/dropzone-frio.js
// to workaround dysfunctional php Strings:getBytesFromShorthand
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
var maxis = {{$max_filesize}} / 10^6;
var dropzoneJot = new Dropzone( '#jot-modal-content', { var dropzoneJot = new Dropzone( '#jot-modal-content', {
paramName: "userfile", // The name that will be used to transfer the file paramName: "userfile", // The name that will be used to transfer the file
maxFilesize: maxis, // MB maxFilesize: getMBytes('{{$max_imagesize}}'), // MB
previewsContainer: '#dz-preview-jot', previewsContainer: '#dz-preview-jot',
url: "/media/photo/upload?response=url&album=", url: "/media/photo/upload?response=url&album=",
accept: function(file, done) { accept: function(file, done) {