Tumblr: Users can now follow tags #1378

Merged
MrPetovan merged 2 commits from heluecht/friendica-addons:tumblr-tags into develop 2023-04-29 21:23:58 +02:00
Owner

Users can now enter tags that they want to follow on Tumblr. Since we have to perform the requests per tag, the maximum number of tags is limited. Also we now store the post reason, so that users can easily see why a Tumblr posts had been imported.

Users can now enter tags that they want to follow on Tumblr. Since we have to perform the requests per tag, the maximum number of tags is limited. Also we now store the post reason, so that users can easily see why a Tumblr posts had been imported.
heluecht added 1 commit 2023-04-29 09:24:31 +02:00
MrPetovan requested changes 2023-04-29 13:26:23 +02:00
@ -297,6 +296,7 @@ function tumblr_addon_admin(string &$o)
'$submit' => DI::l10n()->t('Save Settings'),
'$consumer_key' => ['consumer_key', DI::l10n()->t('Consumer Key'), DI::config()->get('tumblr', 'consumer_key'), ''],
'$consumer_secret' => ['consumer_secret', DI::l10n()->t('Consumer Secret'), DI::config()->get('tumblr', 'consumer_secret'), ''],
'$max_tags' => ['max_tags', DI::l10n()->t('Maximum tags'), DI::config()->get('tumblr', 'max_tags', TUMBLR_DEFAULT_MAXIMUM_TAGS), DI::l10n()->t('Maximum number of tags that a user can follow. Enter 0 to deactivate the feature.')],
Owner
		'$max_tags'        => ['max_tags', DI::l10n()->t('Maximum tags'), DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS, DI::l10n()->t('Maximum number of tags that a user can follow. Enter 0 to deactivate the feature.')],
``` '$max_tags' => ['max_tags', DI::l10n()->t('Maximum tags'), DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS, DI::l10n()->t('Maximum number of tags that a user can follow. Enter 0 to deactivate the feature.')], ```
@ -315,7 +316,11 @@ function tumblr_settings(array &$data)
$enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'post', false);
$def_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'post_by_default', false);
$import = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'import', false);
$tags = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'tags');
Owner
	$tags        = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'tags') ?? [];
``` $tags = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'tags') ?? []; ```
@ -317,1 +318,4 @@
$import = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'import', false);
$tags = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'tags');
$max_tags = DI::config()->get('tumblr', 'max_tags', TUMBLR_DEFAULT_MAXIMUM_TAGS);
Owner

Now that we fully support the null-coalescing operator ??, we should be using it instead of the third parameter of the Config->get method to prevent the evaluation of the default value if it isn't used.

	$max_tags = DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS;
Now that we fully support the null-coalescing operator `??`, we should be using it instead of the third parameter of the `Config->get` method to prevent the evaluation of the default value if it isn't used. ``` $max_tags = DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS; ```
@ -318,1 +320,4 @@
$max_tags = DI::config()->get('tumblr', 'max_tags', TUMBLR_DEFAULT_MAXIMUM_TAGS);
$tags_str = implode(', ', $tags ?? []);
Owner
	$tags_str = implode(', ', $tags);
``` $tags_str = implode(', ', $tags); ```
@ -381,2 +387,4 @@
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'post_by_default', intval($_POST['tumblr_bydefault']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'import', intval($_POST['tumblr_import']));
$max_tags = DI::config()->get('tumblr', 'max_tags', TUMBLR_DEFAULT_MAXIMUM_TAGS);
Owner
		$max_tags = DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS;
``` $max_tags = DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS; ```
@ -685,0 +707,4 @@
*/
function tumblr_fetch_tags(int $uid)
{
if (!DI::config()->get('tumblr', 'max_tags', TUMBLR_DEFAULT_MAXIMUM_TAGS)) {
Owner
	if (!DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS) {
``` if (!DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS) { ```
@ -685,0 +711,4 @@
return;
}
foreach (DI::pConfig()->get($uid, 'tumblr', 'tags', []) as $tag) {
Owner
	foreach (DI::pConfig()->get($uid, 'tumblr', 'tags') ?? [] as $tag) {
``` foreach (DI::pConfig()->get($uid, 'tumblr', 'tags') ?? [] as $tag) { ```
Author
Owner

What is the advantage of changing this?

What is the advantage of changing this?
Owner

It saves having to compute the default value when there isn't any need for it. In these cases the savings are minimal, but in other cases where the default value is another misspelled config value, it would prevent querying it when the corrected value is finally set.

It saves having to compute the default value when there isn't any need for it. In these cases the savings are minimal, but in other cases where the default value is another misspelled config value, it would prevent querying it when the corrected value is finally set.
heluecht added 1 commit 2023-04-29 21:16:57 +02:00
MrPetovan approved these changes 2023-04-29 21:23:51 +02:00
MrPetovan merged commit 94eb2ec197 into develop 2023-04-29 21:23:58 +02:00
MrPetovan added the
2023.05
label 2023-04-29 21:24:03 +02:00
heluecht deleted branch tumblr-tags 2023-04-29 21:26:02 +02:00
Sign in to join this conversation.
No description provided.