Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show image size limit in Frio as "usagemessage" for photo_upload #12267

Merged
merged 51 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d402fe3
Show image size limit in Frio as "usagemessage" for photo_upload
Nov 25, 2022
c11e2b0
updated messages.po
Nov 25, 2022
9dd1cf8
Update mod/photos.php
MarekBenjamin Nov 25, 2022
bb67f6e
Added check if upload_max_filesize (php.ini) or friendica option 'max…
Nov 25, 2022
74bab60
message.po once more
Nov 25, 2022
c4c1bd2
changed var name
Nov 25, 2022
907deed
introduced getBytesFromShorthand function to covert from shorthand no…
Nov 26, 2022
f4d49e5
fixed a forgotten debug output
Nov 26, 2022
f88722b
Better formatting
Nov 26, 2022
6c73077
whitespaces
Nov 26, 2022
ce56cab
Update src/Util/Strings.php
MarekBenjamin Nov 26, 2022
765b50b
Update src/Util/Strings.php
MarekBenjamin Nov 26, 2022
54289b2
Integrated isnumeric check to limit comparison condition
Nov 26, 2022
597f1ba
using constant value for calculation of MiB output, really no need to…
Nov 26, 2022
f45b358
using constant value for calculation of MiB output, really no need to…
Nov 26, 2022
719c294
Added info about upload_max_filesize to admin page
Nov 26, 2022
a01872a
Merge branch 'develop' into show_image_upload_limit
Nov 27, 2022
6ebf0f8
messages.po
Nov 27, 2022
6877f8a
Update src/Module/Admin/Site.php
MarekBenjamin Nov 28, 2022
5b2ac7b
Added missing ')'
Nov 28, 2022
d43e393
and now the missing ')' at the correct position
Nov 28, 2022
361908c
and the messages.po
Nov 28, 2022
bfe220c
Merge branch 'friendica:develop' into show_image_upload_limit
MarekBenjamin Nov 28, 2022
77c68d1
Merge branch 'develop' into show_image_upload_limit
Nov 28, 2022
3cf0b9b
Merge branch 'friendica:develop' into show_image_upload_limit
MarekBenjamin Nov 29, 2022
25ba8bf
allow shorthands in the system.maximagesize
Nov 30, 2022
10e0672
wanted to use a constant for the shorthand regex to be used in the fo…
Nov 30, 2022
e73451d
Added Strings::getBytesFromShorthand() for file size check at upload …
Nov 30, 2022
9c383e2
allow shorthands in the system.maximagesize
Nov 30, 2022
d44968c
split-off! Trends.php allow shorthands in the system.maximagesize
Nov 30, 2022
c03784e
wanted to use a constant for the shorthand regex to be used in the fo…
Nov 30, 2022
978fe26
Added Strings::getBytesFromShorthand() for file size check at upload …
Nov 30, 2022
b2f962c
Merge remote-tracking branch 'origin/show_image_upload_limit' into sh…
Nov 30, 2022
7d86cb1
Removed Trends.php which for what ever reason found its way in my bra…
Nov 30, 2022
72b3bbb
Update src/Module/Admin/Site.php
MarekBenjamin Nov 30, 2022
0ea219f
Use previously already available field.5 for short hand pattern ad ad…
Nov 30, 2022
49db646
Merge remote-tracking branch 'origin/show_image_upload_limit' into sh…
Nov 30, 2022
2794100
Fixed meaning of "maximagesize" = 0 --> infinity
Nov 30, 2022
99e1c64
Added info that shorthands can be used for maxfilesize Admin Site
Nov 30, 2022
bbd1c34
Wrapped all occurrences of DI::config()->get('system', 'maximagesize'…
Nov 30, 2022
ca7af7a
Merge branch 'develop' into show_image_upload_limit
Nov 30, 2022
97a3587
Added handling as infinity if maxfilesize is set to 0
Nov 30, 2022
bb9afc5
Added getBytesFromShorthand at the remaining places.
Nov 30, 2022
037e181
use the existing function for format byte values to KiB, MiB, GiB
Nov 30, 2022
75b01f6
Check for inf values before try to converts bytes to binary prefix st…
Nov 30, 2022
a3d8a59
Correctly output binary prefix values since base 2 is used for conver…
Nov 30, 2022
0080832
message.po
Nov 30, 2022
79235b6
Removed redundant maximagesize = INF statements
Nov 30, 2022
f9c0d5a
Update src/Module/Media/Photo/Upload.php
MarekBenjamin Nov 30, 2022
e4fd9d4
Update src/Module/Media/Photo/Upload.php
MarekBenjamin Nov 30, 2022
8f5d6fd
Merge branch 'friendica:develop' into show_image_upload_limit
MarekBenjamin Nov 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion mod/photos.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,19 @@ function photos_content(App $a)
'$submit' => DI::l10n()->t('Submit'),
]);

$usage_message = '';
// Determine which setting actually limits upload size of images: limit of Friendica ('maximagesize') or upload_max_filesize
MrPetovan marked this conversation as resolved.
Show resolved Hide resolved
$maximagesize_Mbytes = 0;
// Get the relevant size limits for uploads. Abbreviated var names: MaxImageSize -> mis; upload_max_filesize -> umf
$mis_bytes = DI::config()->get('system', 'maximagesize');
$umf_bytes = Strings::getBytesFromShorthand(get_cfg_var('upload_max_filesize'));

if (is_numeric($mis_bytes)) {
MrPetovan marked this conversation as resolved.
Show resolved Hide resolved
// When PHP is configured with upload_max_filesize less than maximagesize provide this lower limit.
($umf_bytes < $mis_bytes) ?
($maximagesize_Mbytes = ($umf_bytes / (10 ** 6))) : ($maximagesize_Mbytes = ($mis_bytes / (10 ** 6)));
}

$usage_message = DI::l10n()->t('The maximum accepted image size is %.3g MB', $maximagesize_Mbytes);

$tpl = Renderer::getMarkupTemplate('photos_upload.tpl');

Expand Down
32 changes: 32 additions & 0 deletions src/Util/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,36 @@ function ($matches) use ($blocks) {

return $text;
}

/**
* This function converts a PHP's shorhand notation string for file sizes in to an integer number of total bytes.
* For example: The string for shorthand notation of '2M' (which is 2,097,152 Bytes) is converted to 2097152
* For more information about file size shorhand notation see:
* https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
MarekBenjamin marked this conversation as resolved.
Show resolved Hide resolved
* @param string $shorthand
* @return int
*/
public static function getBytesFromShorthand(string $shorthand): int
{
$shorthand = trim($shorthand);

if (is_numeric($shorthand))
return $shorthand;

$last = strtolower($shorthand[strlen($shorthand)-1]);
$shorthand = substr($shorthand, 0, -1); // necessary since PHP 7.1; otherwise optional

switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$shorthand *= 1024;
case 'm':
$shorthand *= 1024;
case 'k':
$shorthand *= 1024;
}
MarekBenjamin marked this conversation as resolved.
Show resolved Hide resolved

return $shorthand;
}

}
114 changes: 59 additions & 55 deletions view/lang/C/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2022.12-dev\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-23 18:16+0100\n"
"POT-Creation-Date: 2022-11-25 23:01+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -23,8 +23,8 @@ msgstr ""
msgid "Photos"
msgstr ""

#: mod/fbrowser.php:119 mod/fbrowser.php:146 mod/photos.php:997
#: mod/photos.php:1098 src/Content/Conversation.php:389
#: mod/fbrowser.php:119 mod/fbrowser.php:146 mod/photos.php:1037
#: mod/photos.php:1138 src/Content/Conversation.php:389
#: src/Module/Contact/Follow.php:173 src/Module/Contact/Revoke.php:109
#: src/Module/Contact/Unfollow.php:126 src/Module/Post/Edit.php:164
#: src/Module/Post/Tag/Remove.php:109 src/Module/Profile/RemoteFollow.php:134
Expand All @@ -45,7 +45,7 @@ msgstr ""
msgid "Unable to locate original post."
msgstr ""

#: mod/item.php:179 mod/item.php:184 mod/item.php:853 mod/message.php:69
#: mod/item.php:179 mod/item.php:184 mod/item.php:855 mod/message.php:69
#: mod/message.php:114 mod/notes.php:44 mod/photos.php:159 mod/photos.php:884
#: src/Module/Attach.php:56 src/Module/BaseApi.php:94
#: src/Module/BaseNotifications.php:98 src/Module/BaseSettings.php:52
Expand Down Expand Up @@ -84,23 +84,23 @@ msgstr ""
msgid "Permission denied."
msgstr ""

#: mod/item.php:328 mod/item.php:333
#: mod/item.php:330 mod/item.php:335
msgid "Empty post discarded."
msgstr ""

#: mod/item.php:671
#: mod/item.php:673
msgid "Post updated."
msgstr ""

#: mod/item.php:681 mod/item.php:686
#: mod/item.php:683 mod/item.php:688
msgid "Item wasn't stored."
msgstr ""

#: mod/item.php:697
#: mod/item.php:699
msgid "Item couldn't be fetched."
msgstr ""

#: mod/item.php:829 src/Module/Admin/Themes/Details.php:39
#: mod/item.php:831 src/Module/Admin/Themes/Details.php:39
#: src/Module/Admin/Themes/Index.php:59 src/Module/Debug/ItemBody.php:42
#: src/Module/Debug/ItemBody.php:57 src/Module/Item/Feed.php:80
msgid "Item not found."
Expand Down Expand Up @@ -316,16 +316,16 @@ msgstr ""
msgid "Insert web link"
msgstr ""

#: mod/message.php:203 mod/message.php:360 mod/photos.php:1484
#: mod/message.php:203 mod/message.php:360 mod/photos.php:1524
#: src/Content/Conversation.php:371 src/Content/Conversation.php:717
#: src/Module/Item/Compose.php:204 src/Module/Post/Edit.php:142
#: src/Module/Profile/UnkMail.php:155 src/Object/Post.php:537
msgid "Please wait"
msgstr ""

#: mod/message.php:204 mod/message.php:359 mod/photos.php:914
#: mod/photos.php:1018 mod/photos.php:1290 mod/photos.php:1331
#: mod/photos.php:1387 mod/photos.php:1461
#: mod/photos.php:1058 mod/photos.php:1330 mod/photos.php:1371
#: mod/photos.php:1427 mod/photos.php:1501
#: src/Module/Calendar/Event/Form.php:250 src/Module/Contact/Advanced.php:132
#: src/Module/Contact/Profile.php:327
#: src/Module/Debug/ActivityPubConversion.php:140
Expand Down Expand Up @@ -431,7 +431,7 @@ msgstr ""
msgid "Recent Photos"
msgstr ""

#: mod/photos.php:110 mod/photos.php:1066
#: mod/photos.php:110 mod/photos.php:1106
#: src/Module/Profile/Photos/Index.php:172
#: src/Module/Profile/Photos/Index.php:189
msgid "Upload New Photos"
Expand Down Expand Up @@ -521,183 +521,187 @@ msgstr ""
msgid "Access to this item is restricted."
msgstr ""

#: mod/photos.php:924
#: mod/photos.php:953
msgid "The maximum accepted image size is %.3g MB"
msgstr ""

#: mod/photos.php:964
msgid "Upload Photos"
msgstr ""

#: mod/photos.php:928 mod/photos.php:1014
#: mod/photos.php:968 mod/photos.php:1054
msgid "New album name: "
msgstr ""

#: mod/photos.php:929
#: mod/photos.php:969
msgid "or select existing album:"
msgstr ""

#: mod/photos.php:930
#: mod/photos.php:970
msgid "Do not show a status post for this upload"
msgstr ""

#: mod/photos.php:932 mod/photos.php:1286 src/Content/Conversation.php:373
#: mod/photos.php:972 mod/photos.php:1326 src/Content/Conversation.php:373
#: src/Module/Calendar/Event/Form.php:253 src/Module/Post/Edit.php:179
msgid "Permissions"
msgstr ""

#: mod/photos.php:995
#: mod/photos.php:1035
msgid "Do you really want to delete this photo album and all its photos?"
msgstr ""

#: mod/photos.php:996 mod/photos.php:1019
#: mod/photos.php:1036 mod/photos.php:1059
msgid "Delete Album"
msgstr ""

#: mod/photos.php:1023
#: mod/photos.php:1063
msgid "Edit Album"
msgstr ""

#: mod/photos.php:1024
#: mod/photos.php:1064
msgid "Drop Album"
msgstr ""

#: mod/photos.php:1028
#: mod/photos.php:1068
msgid "Show Newest First"
msgstr ""

#: mod/photos.php:1030
#: mod/photos.php:1070
msgid "Show Oldest First"
msgstr ""

#: mod/photos.php:1051 src/Module/Profile/Photos/Index.php:140
#: mod/photos.php:1091 src/Module/Profile/Photos/Index.php:140
msgid "View Photo"
msgstr ""

#: mod/photos.php:1084
#: mod/photos.php:1124
msgid "Permission denied. Access to this item may be restricted."
msgstr ""

#: mod/photos.php:1086
#: mod/photos.php:1126
msgid "Photo not available"
msgstr ""

#: mod/photos.php:1096
#: mod/photos.php:1136
msgid "Do you really want to delete this photo?"
msgstr ""

#: mod/photos.php:1097 mod/photos.php:1291
#: mod/photos.php:1137 mod/photos.php:1331
msgid "Delete Photo"
msgstr ""

#: mod/photos.php:1189
#: mod/photos.php:1229
msgid "View photo"
msgstr ""

#: mod/photos.php:1191
#: mod/photos.php:1231
msgid "Edit photo"
msgstr ""

#: mod/photos.php:1192
#: mod/photos.php:1232
msgid "Delete photo"
msgstr ""

#: mod/photos.php:1193
#: mod/photos.php:1233
msgid "Use as profile photo"
msgstr ""

#: mod/photos.php:1200
#: mod/photos.php:1240
msgid "Private Photo"
msgstr ""

#: mod/photos.php:1206
#: mod/photos.php:1246
msgid "View Full Size"
msgstr ""

#: mod/photos.php:1259
#: mod/photos.php:1299
msgid "Tags: "
msgstr ""

#: mod/photos.php:1262
#: mod/photos.php:1302
msgid "[Select tags to remove]"
msgstr ""

#: mod/photos.php:1277
#: mod/photos.php:1317
msgid "New album name"
msgstr ""

#: mod/photos.php:1278
#: mod/photos.php:1318
msgid "Caption"
msgstr ""

#: mod/photos.php:1279
#: mod/photos.php:1319
msgid "Add a Tag"
msgstr ""

#: mod/photos.php:1279
#: mod/photos.php:1319
msgid "Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping"
msgstr ""

#: mod/photos.php:1280
#: mod/photos.php:1320
msgid "Do not rotate"
msgstr ""

#: mod/photos.php:1281
#: mod/photos.php:1321
msgid "Rotate CW (right)"
msgstr ""

#: mod/photos.php:1282
#: mod/photos.php:1322
msgid "Rotate CCW (left)"
msgstr ""

#: mod/photos.php:1328 mod/photos.php:1384 mod/photos.php:1458
#: mod/photos.php:1368 mod/photos.php:1424 mod/photos.php:1498
#: src/Module/Contact.php:547 src/Module/Item/Compose.php:188
#: src/Object/Post.php:983
msgid "This is you"
msgstr ""

#: mod/photos.php:1330 mod/photos.php:1386 mod/photos.php:1460
#: mod/photos.php:1370 mod/photos.php:1426 mod/photos.php:1500
#: src/Object/Post.php:531 src/Object/Post.php:985
msgid "Comment"
msgstr ""

#: mod/photos.php:1332 mod/photos.php:1388 mod/photos.php:1462
#: mod/photos.php:1372 mod/photos.php:1428 mod/photos.php:1502
#: src/Content/Conversation.php:386 src/Module/Calendar/Event/Form.php:248
#: src/Module/Item/Compose.php:199 src/Module/Post/Edit.php:162
#: src/Object/Post.php:997
msgid "Preview"
msgstr ""

#: mod/photos.php:1333 src/Content/Conversation.php:341
#: mod/photos.php:1373 src/Content/Conversation.php:341
#: src/Module/Post/Edit.php:127 src/Object/Post.php:987
msgid "Loading..."
msgstr ""

#: mod/photos.php:1419 src/Content/Conversation.php:633 src/Object/Post.php:255
#: mod/photos.php:1459 src/Content/Conversation.php:633 src/Object/Post.php:255
msgid "Select"
msgstr ""

#: mod/photos.php:1420 src/Content/Conversation.php:634
#: mod/photos.php:1460 src/Content/Conversation.php:634
#: src/Module/Moderation/Users/Active.php:136
#: src/Module/Moderation/Users/Blocked.php:136
#: src/Module/Moderation/Users/Index.php:151
#: src/Module/Settings/Connectors.php:242
msgid "Delete"
msgstr ""

#: mod/photos.php:1481 src/Object/Post.php:378
#: mod/photos.php:1521 src/Object/Post.php:378
msgid "Like"
msgstr ""

#: mod/photos.php:1482 src/Object/Post.php:378
#: mod/photos.php:1522 src/Object/Post.php:378
msgid "I like this (toggle)"
msgstr ""

#: mod/photos.php:1483 src/Object/Post.php:379
#: mod/photos.php:1523 src/Object/Post.php:379
msgid "Dislike"
msgstr ""

#: mod/photos.php:1485 src/Object/Post.php:379
#: mod/photos.php:1525 src/Object/Post.php:379
msgid "I don't like this (toggle)"
msgstr ""

#: mod/photos.php:1507
#: mod/photos.php:1547
msgid "Map"
msgstr ""

Expand Down