From 25ba8bfb53cd53bcbe4be28d70edce2b01b4fa48 Mon Sep 17 00:00:00 2001 From: Marek Bachmann Date: Wed, 30 Nov 2022 01:05:32 +0100 Subject: [PATCH] allow shorthands in the system.maximagesize --- mod/photos.php | 5 ++- src/Module/Admin/Site.php | 13 ++++-- src/Module/Api/Mastodon/Trends.php | 54 +++++++++++++++++++++++ view/templates/field_input.tpl | 2 +- view/theme/frio/css/mod_admin.css | 8 ++++ view/theme/frio/templates/field_input.tpl | 2 +- 6 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/Module/Api/Mastodon/Trends.php diff --git a/mod/photos.php b/mod/photos.php index 4bca8275e3..d44afa588c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -916,13 +916,14 @@ function photos_content(App $a) $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'); + $mis_bytes = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')); $umf_bytes = Strings::getBytesFromShorthand(ini_get('upload_max_filesize')); // When PHP is configured with upload_max_filesize less than maximagesize provide this lower limit. $maximagesize_Mbytes = (is_numeric($mis_bytes) && ($mis_bytes < $umf_bytes) ? $mis_bytes : $umf_bytes) / (1048576); - $usage_message = DI::l10n()->t('The maximum accepted image size is %.3g MB', $maximagesize_Mbytes); + // @todo We may be want to use appropriate binary prefixed dynamicly + $usage_message = DI::l10n()->t('The maximum accepted image size is %.6g MB', $maximagesize_Mbytes); $tpl = Renderer::getMarkupTemplate('photos_upload.tpl'); diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index a6931ce916..8aa43c5564 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -34,6 +34,7 @@ use Friendica\Model\User; use Friendica\Module\BaseAdmin; use Friendica\Module\Conversation\Community; use Friendica\Module\Register; +use Friendica\Navigation\SystemMessages; use Friendica\Protocol\Relay; use Friendica\Util\BasePath; use Friendica\Util\EMailer\MailBuilder; @@ -41,6 +42,8 @@ use Friendica\Util\Strings; class Site extends BaseAdmin { +// const SHORTHAND_REGEX = '/*/i'; + protected function post(array $request = []) { self::checkAdminAccess(); @@ -68,7 +71,7 @@ class Site extends BaseAdmin $language = (!empty($_POST['language']) ? trim($_POST['language']) : ''); $theme = (!empty($_POST['theme']) ? trim($_POST['theme']) : ''); $theme_mobile = (!empty($_POST['theme_mobile']) ? trim($_POST['theme_mobile']) : ''); - $maximagesize = (!empty($_POST['maximagesize']) ? intval(trim($_POST['maximagesize'])) : 0); + $maximagesize = (!empty($_POST['maximagesize']) ? trim($_POST['maximagesize']) : 0); $maximagelength = (!empty($_POST['maximagelength']) ? intval(trim($_POST['maximagelength'])) : -1); $jpegimagequality = (!empty($_POST['jpegimagequality']) ? intval(trim($_POST['jpegimagequality'])) : 100); @@ -240,7 +243,11 @@ class Site extends BaseAdmin } else { DI::config()->set('system', 'singleuser', $singleuser); } - DI::config()->set('system', 'maximagesize' , $maximagesize); + if (preg_match('/\d+(?:\s*[kmg])?/i', $maximagesize)) { + DI::config()->set('system', 'maximagesize', $maximagesize); + } else { + DI::sysmsg()->addNotice(DI::l10n()->t('%s is no valid input for maximum image size', $maximagesize)); + } DI::config()->set('system', 'max_image_length' , $maximagelength); DI::config()->set('system', 'jpeg_quality' , $jpegimagequality); @@ -471,7 +478,7 @@ class Site extends BaseAdmin '$maximagesize' => ['maximagesize', DI::l10n()->t('Maximum image size'), DI::config()->get('system', 'maximagesize'), DI::l10n()->t('Maximum size in bytes of uploaded images. Default is 0, which means no limits. The value of upload_max_filesize in your PHP.ini needs be set to at least the desired limit. Currently upload_max_filesize is set to %s (%sB)', Strings::getBytesFromShorthand(ini_get('upload_max_filesize')), ini_get('upload_max_filesize')), - '1 kB = 1 KiB = 1024 Bytes'], + '', '', '', '\d+(?:\s*[kmg])?'], '$maximagelength' => ['maximagelength', DI::l10n()->t('Maximum image length'), DI::config()->get('system', 'max_image_length'), DI::l10n()->t('Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.')], '$jpegimagequality' => ['jpegimagequality', DI::l10n()->t('JPEG image quality'), DI::config()->get('system', 'jpeg_quality'), DI::l10n()->t('Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.')], diff --git a/src/Module/Api/Mastodon/Trends.php b/src/Module/Api/Mastodon/Trends.php new file mode 100644 index 0000000000..c42a27641b --- /dev/null +++ b/src/Module/Api/Mastodon/Trends.php @@ -0,0 +1,54 @@ +. + * + */ + +namespace Friendica\Module\Api\Mastodon; + +use Friendica\Core\System; +use Friendica\DI; +use Friendica\Model\Tag; +use Friendica\Module\BaseApi; + +/** + * @see https://docs.joinmastodon.org/methods/instance/trends/ + */ +class Trends extends BaseApi +{ + /** + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + protected function rawContent(array $request = []) + { + $request = $this->getRequest([ + 'limit' => 20, // Maximum number of results to return. Defaults to 10. + ], $request); + + $trending = []; + $tags = Tag::getGlobalTrendingHashtags(24, 20); + foreach ($tags as $tag) { + $tag['name'] = $tag['term']; + $history = [['day' => (string)time(), 'uses' => (string)$tag['score'], 'accounts' => (string)$tag['authors']]]; + $hashtag = new \Friendica\Object\Api\Mastodon\Tag(DI::baseUrl(), $tag, $history); + $trending[] = $hashtag->toArray(); + } + + System::jsonExit(array_slice($trending, 0, $request['limit'])); + } +} diff --git a/view/templates/field_input.tpl b/view/templates/field_input.tpl index 3455891b9d..95a13cfb7b 100644 --- a/view/templates/field_input.tpl +++ b/view/templates/field_input.tpl @@ -1,7 +1,7 @@
- + {{if $field.3}} {{$field.3 nofilter}} {{/if}} diff --git a/view/theme/frio/css/mod_admin.css b/view/theme/frio/css/mod_admin.css index 3475d1d82a..355cfd1401 100644 --- a/view/theme/frio/css/mod_admin.css +++ b/view/theme/frio/css/mod_admin.css @@ -40,3 +40,11 @@ tr.details th { .adminpage td { word-break: break-all; } + +.adminpage input[id=id_maximagesize]:valid { + background-color: palegreen; +} + +.adminpage input[id=id_maximagesize]:invalid { + background-color: lightpink; +} \ No newline at end of file diff --git a/view/theme/frio/templates/field_input.tpl b/view/theme/frio/templates/field_input.tpl index 3a9e54d06a..9812e3466f 100644 --- a/view/theme/frio/templates/field_input.tpl +++ b/view/theme/frio/templates/field_input.tpl @@ -3,7 +3,7 @@ {{if !isset($label) || $label != false }} {{/if}} - + {{if $field.3}} {{$field.3 nofilter}} {{/if}}