GroupSlugRouter Download 3.0

Dutch eric redegeld 10 months ago

🔗 GroupSlugRouter – Clean & Friendly Group URLs + Profile Integration group overview
Give your OSSN groups a professional touch!
🔍 Key Features Implemented
Slug Generation

Automatically generates a slug from a group’s title upon creation.

Stored as an object entity of subtype groupslugname.

Ensures unique slugs using incremental suffixes (e.g., groupname, groupname-1, etc.).

Vanity URL Routing

Redirects https://your-site/g/slugname to the original group URL.

Profile Integration

Adds a Groups tab to user profile pages showing owned groups with sorting options.

Admin Debug Tool

/slugdebug allows admins to test slugs and resolve issues.

Slug Recovery Tool

/administrator/group-slugs/fix allows batch creation of slugs for groups that missed it due to legacy or import issues.

Slug Update on Title Change

When a group title is updated, the corresponding slug is automatically updated and old slugs are deleted.

Critical Discoveries & Fixes
Missing Groups on Activation

Some older groups (e.g., group 291) were not getting slugs during activation due to inconsistent structure or lack of metadata.

This was fixed by:

Switching from ossn_get_entities to raw ossn_get_object queries during activation.

Adding logging to track group title and slug status.

Manual Slug Manipulation Risks

A competing module allowed manual slugs, breaking the link between group title and URL.

GroupSlugRouter now ensures slugs are strictly based on group titles for consistency and integrity.

Error Handling

Fixed early crash due to missing ossn_get_data() by replacing it with ossn_get_object().

Prevented require_once failures with correct GROUPSLUGROUTER path usage.

Admin Warning

If the legacy UserGroups module is active, an admin warning is displayed to avoid conflicts.

đź§  Extra Notes
Slugs are not stored in the ossn_object table but separately as ossn_entities, type object, subtype groupslugname.

Debug logging was extensively used ([SLUG] ...) to track behavior in real time.
đź’ˇ Built with care by Eric Redegeld
Special thanks again to the OSSN community member for taking the time to share insights..

Comments
Dutch Harry Stok Replied 10 months ago

Installed version 3.0, now all the groups have now the slug name.
Thanks

Dutch Eric redegeld Replied 10 months ago

thank you, did some altering and now testing it.

https://github.com/compie67/ossn-GroupSlugRouter/tree/main

German Michael ZĂĽlsdorff Replied 10 months ago

which checks for isset($group->guid) before redirecting.

No, all you check is the returned value of your own function (object or false)

Just by naming it $group doesn't mean you're accessing a true instance of a group object
Rename it like $eric = groupslugrouter_get_group_by_slug($slug);
and do your check on $eric: no difference ;)

You may additionally add a error_log($group->title); which would return the name of the group if your theory is correct, but it won't.

Dutch Eric redegeld Replied 10 months ago

You're right — returning just the owner_guid from groupslugrouter_get_group_by_slug() would simplify the logic, and I agree it’s more elegant in theory. However, during development we encountered a subtle issue with some existing groups (e.g. group 291), where slugs weren’t being recognized properly if only the owner_guid was returned.

By wrapping the result in a minimal object ((object) ['guid' => $entity->owner_guid]), we ensured compatibility with the existing vanity handler logic, which checks for isset($group->guid) before redirecting. This helped maintain consistent behavior, especially in fallback cases where slugs were missing or needed regeneration.

So yes — your suggestion is correct, and would work perfectly if we also refactor the handler to drop the isset($group->guid) check and directly redirect("group/{$group}"). But to keep things robust across edge cases and backwards-compatible, we kept the object structure for now.

Appreciate the insight though — this might be a great simplification for a future version.

German Michael ZĂĽlsdorff Replied 10 months ago

just had a look into 3.0:
and wondering why you still continue passing the result of groupslugrouter_get_group_by_slug() as an object?

All we want is just a simple integer (the owner_guid of the entity) - no reason to do that extra wrapping.

Thus, it could be simplified like

$entities = ossn_get_entities($params);
if ($entities) {
    error_log("[SLUG] âś… Slug '{$slug}' gevonden met owner_guid: {$entities[0]->owner_guid}");
    return $entities[0]->owner_guid; // Direct redirect gebruiken
}

and the adapted groupslugrouter_vanity_handler()

$group = groupslugrouter_get_group_by_slug($slug);
if ($group) {
    return redirect("group/{$group}");
}
Dutch Eric redegeld Replied 10 months ago

Working on update. Myself got fast server. But for smaller ones the limit kicks in.

Dutch Harry Stok Replied 10 months ago

I have download and installed it, then create a new groep, but I see only /group/512 for now.
I will look tomorrow in the database if there is changed something.

Dutch Eric redegeld Replied 10 months ago

What I did with that feedback
âś… I changed the redirect: it now only uses owner_guid, without ossn_get_group_by_guid(), exactly as advised.

âś… I now rely on OSSN's automatic entity cleanup when deleting a group. So there is no separate check anymore.

⚠️ I did consciously choose to delete old slug entities when a group title changes. That way I know for sure that there is only one active slug per group, and I avoid confusion or double references.

I will keep the credits neutral

German Michael ZĂĽlsdorff Replied 10 months ago

Sorry Eric,
but I'm not feeling really comfortable being mentioned for 'optimization ideas' because you just ignored what I tried to explain in your thread https://www.opensource-socialnetwork.org/discussion/view/7521/fancy-url-instead-of-86

Dutch Eric redegeld Replied 10 months ago

enter image description here

Component

Developer: eric
License GPL v2
Type: User admin
Requires OSSN Version : 8.0
Latest Version: 3.0
Last Updated 10 months ago
Repository Url View Repository