Updated URL Replace addon #1483
No reviewers
Labels
No labels
2018.09
2019.01
2019.03
2019.06
2019.09
2019.12
2020.03
2020.06
2020.09
2020.12
2021.03
2021.07
2021.09
2022.02
2022.06
2022.09
2022.12
2023.04
2023.05
2023.09
2024.03
2024.06
2024.09
2024.12
dependencies
Hackathon 2021
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: friendica/friendica-addons#1483
Loading…
Reference in a new issue
No description provided.
Delete branch "toddy/friendica-addons:2024.03-rc"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
the new patch from @loma-one is great, I think. I've now updated the URL replace addon to support Instagram links as well. Moreover, the comment from @heluecht makes sense to me as well. #1479 (comment)
So I've added checkboxes for all three services (X, YouTube, Instagram). Now a site admin can select which replacements they want.
This should solve the conflict if the invidious addon is enabled simultaneously.
Thanks for your work. Only one thing: AFAIK you cannot simply replace the
youtu.be
domain, since it has got a different URL pattern. Can you check that?Also: When this addon is a one stop shop solution for all URL, then I suggest to set all the other ones to "deprecated", since it otherwise confuses the admins and users.
@ -93,2 +131,4 @@
]);
}
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
Could you use the third parameter of the
get
function for the default value? Also it would be nice to use constants for the default URL. See for example the inviduous addon for that.Thanks for your review. Unfotunately, the third parameter of get() does not work in this case, I've tried that. When the addon is freshly installed, there is no configuration in the database. In that case,
DI::config()->get()
gets a NULL value from the database, so the third parameter will be returned as the default value.However, if the site admin sets another server, then the URL of that server will be stored in the database. If afterwards the site admin deletes that custom server again and leaves the input field blank, then
DI::config()->get()
will get a result from the database -- an empty string. In that case, the empty string will be returned. This is the reason why I'm checking the value with theempty()
function.An alternative approach would be to specifically check in
url_replace_addon_admin_post()
if the posted string is empty. If it is, I could then useDI::config->delete()
instead ofDI::config->set()
, that should solve the problem.The alternative approach could look like this:
Should I rewrite the addon in that style?
Looks better.
As a general rule, the default value parameter of both
Config->get
andIConfig->get
is now deprecated in favor of using the short ternary operators?:
and??
. This allows for a better control for default values.I've just pushed a commit which uses this pattern. Please take a look.
IIRC you can just replace
youtu.be
URLs as well.@tobias is right, Invidious is smart enough to understand the same URL structure which YouTube uses, so you only need to replace the server part.
@heluecht I've now switched to using constants.
@ -12,2 +12,4 @@
use Friendica\DI;
const URL_REPLACE_NITTER_DEFAULT = 'https://nitter.net';
const URL_REPLACE_INVIDIOUS_DEFAULT = 'https://yewtu.be';
Out of interest: Why aren't we using https://invidio.us here? Wouldn't it be better to use the main instances as default values?
You cannot use it to watch something directly, they provide a hub to instances you can use to watch.
You will see this page where you have to select a server. But when you follow one of these links, your content will be loaded. So you will also be able to chose your individual server each time. Also: I just tested with one video. I had to try several servers, until I found one, that finally was able to display the video. So using https://invidio.us helps here.
I agree with @heluecht , let’s use the official portal by default and let admins pick a specific instance later.
TBH, I'm not a big fan of that change. After all, it requires two clicks of the user instead of just one to watch the video. All other alternative frontends provided by this addon show the content directly after following the link.
Moreover, yewtu.be has been around for a long time already and seems to be rather reliable. So IMHO it makes for a good and sensible default server. And it has by far the coolest name. :-)
Well, the first time I tried the service at
yewtub.de
, I received an error. I then had to try two other servers to finally find one, that was able to display it to me. So having the choice is a nice thing. Also this is only a default value, so people can enter their own preferred server afterwards - based on their own experience and their regional location.If this is the last discussion point before being able to merge this PR, I'll give in. :-)
@ -59,2 +90,3 @@
DI::l10n()->t('Specify the URL with protocol. The default is %s.', URL_REPLACE_NITTER_DEFAULT),
null,
'placeholder="https://nitter.net"',
'placeholder="'.URL_REPLACE_NITTER_DEFAULT.'"',
Code standards: Please wrap operators with spaces.
Strange, I did run
bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer
for the file. However, I've seen that you've done some reformatting of my code as well in commiteeb783d71d
-- I'm fine with that, but just out of curiosity: Could you please point me to the canonical configuration settings for PHP-CS-Fixer? I thought it's.php_cs.dist
in the root directory, but when using that, my code does not get reformatted with spaces between operators.Sorry about that, we're following the PSR-12 coding standards: https://www.php-fig.org/psr/psr-12/#62-binary-operators
I don't use PHP CS Fixer myself so I'd be hard-pressed to verify the configuration is correct.
@ -125,3 +184,1 @@
if ($replaced) {
$b['html'] .= '<hr><p><small>' . DI::l10n()->t('(URL replace addon enabled for X, YouTube and some news sites.)') . '</small></p>';
if (count($replacements) > 0) {
I suggest to compare the original value with the new value to decide, if content had been replaced.
You're right, that makes more sense. I'll change that probably tomorrow, I'm short on time right now.
66c0811ace
to5478552040
5478552040
to872a438dcf