akirk / friends

A social network between WordPresses. Privacy focused, by itself a self-hosted RSS++ reader with notifications.
https://wpfriends.at/
GNU General Public License v2.0
80 stars 15 forks source link

Multisite support? #96

Open uniphonic opened 2 years ago

uniphonic commented 2 years ago

Does the Friends plugin work in multisite?

On a multisite network site with the Friends plugin installed, I'm getting an error when trying to add a friend: "There has been a critical error on this website."

akirk commented 2 years ago

Yes, it should work. I've also just run through the flow in my test multisite install successfully. Did you maybe receive an e-mail (something like "Your Site is Experiencing a Technical Issue") with a more concrete error message?

uniphonic commented 2 years ago

Thanks for the reply. For me, works from the main parent site, but not from a child site. I haven't received the error email, so I'm going to try activating an SMTP plugin to see if that allows me to receive it.

akirk commented 2 years ago

Hm, I've tried all sorts of combinations between main, child, and non-multisite but haven't been able to generate an error. Do you have access to the server's error log? Maybe something could be found there.

uniphonic commented 2 years ago

I turned on debugging, and got the error:

Fatal error: Uncaught Error: Call to undefined function Friends_Mf2\mb_convert_encoding() in /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php:100 Stack trace: #0 /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php(369): Friends_Mf2\unicodeToHtmlEntities('<!DOCTYPE html>...') #1 /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php(45): Friends_Mf2\Parser->__construct('<!DOCTYPE html>...', 'https://acceler...') #2 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-feed.php(844): Friends_Mf2\parse('<!DOCTYPE html>...', 'https://acceler...') #3 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-feed.php(666): Friends_Feed->discover_link_rel_feeds('<!DOCTYPE html>...', 'https://acceler...', Object(Requests_Utility_CaseInsensitiveDictionary)) #4 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-admin.php(1302): Friends_Feed->discover_available_feeds('https://acceler...') #5 /home/userfolder/public_h in /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php on line 100 There has been a critical error on this website.

uniphonic commented 2 years ago

It appears that something that might be related is that the site that is getting the error is a multisite instance that is set up for subdirectories, rather than subdomains. I just tried the Friends plugin on a different multisite instance that was set up for subdomains, and it worked fine. The only place where I've found that it doesn't work is a sub-site on a multisite instance that is set up for subdirectories.

I hope that is helpful for replicating the issue?

Thanks!

akirk commented 2 years ago

Thank you, that error message was helpful! I've committed a fix (https://github.com/akirk/friends/commit/e7d940467a96f41730678aff348553a7a365f3d2) and released version 1.8.4. Could you try if it fixes the fatal error?

uniphonic commented 2 years ago

Thanks! I updated the single file, but I'm still getting an error which looks very similar:

Fatal error: Uncaught Error: Call to undefined function mb_convert_encoding() in /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php:100 Stack trace: #0 /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php(369): Friends_Mf2\unicodeToHtmlEntities('<!DOCTYPE html>...') #1 /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php(45): Friends_Mf2\Parser->__construct('<!DOCTYPE html>...', 'https://acceler...') #2 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-feed.php(844): Friends_Mf2\parse('<!DOCTYPE html>...', 'https://acceler...') #3 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-feed.php(666): Friends_Feed->discover_link_rel_feeds('<!DOCTYPE html>...', 'https://acceler...', Object(Requests_Utility_CaseInsensitiveDictionary)) #4 /home/userfolder/public_html/wp-content/plugins/friends/includes/class-friends-admin.php(1302): Friends_Feed->discover_available_feeds('https://acceler...') #5 /home/userfolder/public_html/wp-conte in /home/userfolder/public_html/wp-content/plugins/friends/libs/Mf2/Parser.php on line 100 There has been a critical error on this website.

If you want to replicate the issue, you might try it on a multisite instance that is set up for subdirectories rather than subdomains?

Thank you!

akirk commented 2 years ago

It looks like your PHP doesn't have support for mb_* functions. I'll check if I can work around that but it's not a quick fix.

uniphonic commented 2 years ago

OK, thanks! I'm on PHP 7.4, but I could could move to 8.0 or 8.1 if that would be preferred?

Update: I just tried both PHP 8.0 and 8.1, and they both threw errors, so It seems that 7.4 is the version I should stick with. But please give a recommendation if you think I should try something different?

Thanks!

uniphonic commented 2 years ago

I just tried enabling the PHP extension "mbstring", and it seems to work now! Thanks! Except that I'm still getting a notice message (twice for some reason):

Notice: Undefined index: autoselect in /home/userfolder/public_html/wp-content/plugins/friends/templates/admin/select-feeds.php on line 118

Notice: Undefined index: autoselect in /home/userfolder/public_html/wp-content/plugins/friends/templates/admin/select-feeds.php on line 118

is this expected? Thanks!

uniphonic commented 2 years ago

Another issue I've run into, is that if two separate sites in a multisite network both try to add the same "Friend" to their site as a subscription feed, it gives an error saying "Error: This username is already registered. Please choose another one.", even though the second user who is trying to add this site doesn't show them as a "friend" or a "user" yet at all.

If I change the site name slightly, it will let me successfully add it, but it seems that it must not conflict with any other friend/user names given by other users? This seems problematic in a multisite context...

If, for instance, 20 different users each with their own sub-site in a multisite install, all want to subscribe to the same site, do they each really have to come up with a unique name for the feed of the same site, so that there are 20 different friend/user names for the same site subscription? It seems like there should be some way to use the same site name for subscriptions across multiple users?

Thanks!

akirk commented 2 years ago

Notice: Undefined index: autoselect in /home/userfolder/public_html/wp-content/plugins/friends/templates/admin/select-feeds.php on line 118

is this expected?

This is among the PHP notices that I fixed for 1.8.4, could you check if those are still there after you upgraded the plugin to that version?

Another issue I've run into, is that if two separate sites in a multisite network both try to add the same "Friend" to their site as a subscription feed, it gives an error saying "Error: This username is already registered. Please choose another one.", even though the second user who is trying to add this site doesn't show them as a "friend" or a "user" yet at all. If I change the site name slightly, it will let me successfully add it, but it seems that it must not conflict with any other friend/user names given by other users? This seems problematic in a multisite context...

You are right! I think this is a regression, I need to check why it is not working (there already is some special handling for this). It should not be a problem for two sites to share the same "external" user. I'll post here again when I have checked why this is happening. Likely this will be fixed in the next version.

uniphonic commented 2 years ago

Awesome! Thanks for the quick fix! That seems to have solved both issues.

One remaining issue I'm seeing, is that I've accepted a friend request, but the notification seems to be persisting for some reason... seen that one before?

akirk commented 2 years ago

Hm, could you check the role of the user on the particular site? The notification is not stored but generated from things like friend requests.

uniphonic commented 2 years ago

@akirk , the user who is accepting the friend request has a role of "Administrator". The user who sent the friend request has a role of "none" in the site, even after the friend request is accepted. Does that help diagnose? I'm assuming the user who sent the friend request should have their elevated to "Friend" instead of "none", in their friends site?

akirk commented 2 years ago

It sounds to me that the roles (Friend, Friend Request etc) have not been created on the second site. Could you check if these are available at all (for example when creating a new user you can choose its role)? Maybe try to deactivate the Friends plugin and reactivate it, it should create the roles.

uniphonic commented 2 years ago

@akirk , it appears you are correct. There is no "Friend" role for this site. Screen Shot 2022-01-23 at 6 55 15 PM

Shouldn't the role be automatically be added when the plugin is installed?

akirk commented 2 years ago

Did you maybe use the "Network Activate" function to activate it across sites? I've added a fix in e13a5e0c7c3565e6395ea5a4607248eafb717110 but you can also fix this on the respective sites by deactivating the plugin and re-activating it, it should create the roles.

uniphonic commented 2 years ago

Yes, I did use the "Network activate" option previously. I just now updated the plugin, then tried Network deactivating, and then Network reactivated, and then tried to accept the friend request again, but I'm still getting the same result as before. Should that work?

Thanks!

akirk commented 2 years ago

No, sorry. I could have explained. Please first delete that user with the role "None" and then send a new friend request. For a friendship to happen the local user needs to have the role "Pending Friend Request" and remote user (i.e. the one accepting) the role "Friend Request."

Also, I haven't released a new version with the fix yet, so please try the deactivate/activate trick on the site that had the user with the role "None" first.

uniphonic commented 2 years ago

Thanks! Activating each site individually won't be feasible for this particular site, so I'm going to wait for the release, and then test again after that. Thank you!

uniphonic commented 2 years ago

Any idea when the fix will be released? Thanks!