• Home
  • Get help
  • Ask a question
Last post 5 hours 44 min ago
Posts last week 110
Average response time last week 29 min
All time posts 67424
All time tickets 10424
All time avg. posts per day 21

Helpdesk is open from Monday through Friday CET

Please create an (free) account to post any question in the support area.
Please check the development versions area. Look at the changelog, maybe your specific problem has been resolved already!
All tickets are private and they cannot be viewed by anyone. We have made public only a few tickets that we found helpful, after removing private information from them.

#7396 – Question about Com Contact Views and Layouts

Posted in ‘sh404SEF’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Wednesday, 16 September 2020 07:48 UTC
TheSDHotel

Hello,

I'm doing a big use of the com_contact component and I was experimenting with different layouts.

Much like with articles, in a com_contact menu item (eg. List all Contacts in a Category)  you can select which layout you would like the contacts to have. Eg:



So this would allow to display contacts in different ways.

However, sh404sef does not take into account the layout in the stored URL (neither nonsef or sef), so there doesn't seem to have a way to do something like:

user/andy/
user/andy/aaa/
user/andy/layout3/

Is there any chance you could add support for com_contacts layouts in sh404sef?

Also I guess my idea would also require some tweaks or custom redirect rule, as I assume that even if sh404sef supported &layout=blabla, it would still be a set as a duplicate of the main URL user/andy/, and not as a different URL like user/andy/blabla/ 

Let me know if you have any insight / ideas :)

Thanks!
Andy

 

Wednesday, 16 September 2020 07:49 UTC
TheSDHotel

The previous image didn' get attached so here it is:

 

 

Wednesday, 16 September 2020 09:12 UTC
wb_weeblr

Hi Andy

However, sh404sef does not take into account the layout in the stored URL (neither nonsef or sef),

That's not exactly how it works. As you know, sh404SEF merely records non-SEF URLs, it has no impact on them. The problem with Joomla is that it does not include the layout in the non-SEF URLs it creates. Instead, the layout is attached to a menu item and it's the menu item used in the non-sef URL that decides which layout (or any parameter attached to the menu item for that matter) will be used.

So if you have 2 menu items:

menu item 123 - layout = default

and

menu item 123 - layout = GTA HOTEL

and a SEF URL /contact-us, which layout is used depends on the non-sef found on your site:

- index.php?option=com_contact&Itemid=123 -> default layout

- index.php?option=com_contact&Itemid=456 -> GTA Hotel layout

So it depends on how you link to those pages, how much duplicates there are and in the end which menu item is in the "main" non-sef URL for that SEF.

Options are:

- Make sure the proper Itemid is selected in the "main" non- SEF URL

- If using multiple format on the same site, customize different URLs so that you have different non-sef (with proper Itemids) for different SEF.

- Alternatively, you can go to "By component" and set com_contact to:

             1. Use default handler

             2. Use router.php with menu item

These settings will cause sh404SEF to mimic closely Joomla URLs construction and should provide you with a better result in that specific case. Note that after changing the "By component" settings for com_contact, you should delete any com_contact URL from the SEF URL manager so that new ones can be re-created.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 

 

 

 
Wednesday, 16 September 2020 09:20 UTC
TheSDHotel

Thank you as always for your awesome support and explanation!

If using multiple format on the same site, customize different URLs so that you have different non-sef (with proper Itemids) for different SEF.

So this would my case.

In this case, how could I go about it?

How could I make sh404sef generate a differently formatted SEF URL based on the non-sef URL Itemid?

So for example:

- Nonsef: index.php?option=com_contact&....&Itemid=123 -> default layout
SEF: user/andy/

- Nonsef: index.php?option=com_contact&....&Itemid=456 -> My Other Layout
SEF: user/andy/my-other-layout/

I would need this to happen automatically (and not manually customized) as I have over 15.000 users registered on my site (the contact component is used to display their profile page).

Any idea comes to mind to accomplish it? Maybe with a custom redirect/alias rule?

Thanks a lot again!
Best,
Andy

Wednesday, 16 September 2020 09:25 UTC
wb_weeblr

Hi

I would need this to happen automatically (and not manually customized) 

I'd go with switching com_contact to "Use router.php with menu item". You should do that first on a staging site of course. That's the only way to build different SEF based on the menu item.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 09:36 UTC
TheSDHotel

Hello,

Just tried that. It kinda works but not ideally :(

This turns this:

- Nonsef: index.php?option=com_contact&....&Itemid=456 -> My Other Layout

into:
SEF: my-other-layout/2/

where (my-other-layout is the menu alias, and 2 is the id of contact)

So it loses the name (eg. andy) and it used the ID instead. And it also makes the layout prepended instead of appended. In an ideal scenario I would like to have something like:

SEF: user/andy/my-other-layout/

Not sure if there is any way for that...

Wednesday, 16 September 2020 10:18 UTC
wb_weeblr

Hi

where (my-other-layout is the menu alias, and 2 is the id of contact)

When you enable back Joomla router (which you do by making the changes in By component), sh404SEF has no control anymore on the URL created. You get what Joomla gives back.

- Nonsef: index.php?option=com_contact&....&Itemid=456 -> My Other Layout

But what is the FULL non-sef and how is it displayed? by what extension? what created the non-sef? 

By "the full non-sef" I don't mean the one recorded by sh404SEF - which is processed and simplified - but the original one in the page source code: if you disable both sh404SEF and Joomla SEF, so as to have fully non-sef only URLs on your site, and you navigate to a page with a link to the contact page, what is the full non-sef URL as seen in the source?

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 10:40 UTC
TheSDHotel

URL simply looks like this:

index.php?option=com_contact&Itemid=562&id=2&lang=en&view=contact

The source one and the nonsef recorded by sh404sef both look like this :)

Wednesday, 16 September 2020 10:42 UTC
TheSDHotel

So this:

index.php?option=com_contact&Itemid=562&id=2&lang=en&view=contact

Generates:

user/andybadwool

(where user/ is the alias of the contact category)

What I would like to do ideally is that this:

index.php?option=com_contact&Itemid=999&id=2&lang=en&view=contact
 (other menu ID which used a different layout param) 

would generate:

 

user/andybadwool/other-layout

 

Wednesday, 16 September 2020 11:02 UTC
wb_weeblr

Hi

That's not something sh404SEF can do I'm afraid. The closest you can get is the /other-layout/{user_id} you got previously. You will get the functionality, not the pretty URL.

Just to be clear, do you plan on having the multiple layouts active at the same time on the site - ie you have links to /user/id/layout-a somewhere and links to /user/id/layout-b - or is this only to "experiment" with multiple layouts before picking one?

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 11:10 UTC
TheSDHotel

Yeah, I was planning on having multiple layouts, mostly because I wanted to "mis-use" layouts to display different groups of custom fields (custom fields can also be assigned to user/contacts, not just articles).

The real use of this would be:

user/my-name/gta5-layout
(shows all user custom fields pertaining to GTA V game)

user/my-name/rdr2-layout
(shows all user custom fields pertaining to Red Dead game)

Of course the conditionals of which fields to show in which layouts, that's something I would do in PHP in the layouts itself.

The reason I would like to split custom fields output across different pages, is because having everything in one page makes it very cumbersome, heavy, and slow to load.

So I was thinking of splitting things in multiple pages, and the idea that came to mind was using layouts to do that.

This to give you a background on the reasoning behind it :)

But I understand if it's something that cannot be done. In that case I will try of thinking of something else.

Thanks again!

 

Wednesday, 16 September 2020 11:22 UTC
wb_weeblr

Hi

But I understand if it's something that cannot be done.

It can't be done AND keep the full URLs. Or writing a custom com_contact plugin that would check the menu item, look at the selected layout and build a URL accordingly. Not impossible to do but still require some custom development.

One easier way, still with some sort of custom dev, would be to use one of sh404SEF hooks, in the /libraries/weeblr/sh404sef_functions.php file. I think you used that already. You can probably use the "sh404sef_after_plugin_build" filter:

ShlHook::add(
	'sh404sef_after_plugin_build',
	function ($string, $vars, $pluginType, $extPluginPath) {
		if (
			'com_contact' == wbArrayGet($vars, 'option', '')
			&&
			'contact' == wbArrayGet($vars, 'view', '')
		)
		{
			$menuItemId = wbArrayGet($vars, 'Itemid', 0);
			switch ($menuItemId)
			{
				case 123:
					$string .= '/layout-a';
					break;
				case 456:
					$string .= '/layout-b';
					break;
			}

		}

		return $string;
	}
);

Add this to you /libraries/weeblr/sh404sef_functions.php file (on your staging site!!!), delete existing contact links from the SEF URL manager and navigate to your pages to see the newly created links. You'll need to adjust the numbers and the bit added to the URLs as needed.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 11:38 UTC
TheSDHotel

Hey Yannick,

That solution would be amazing!

I tried it and unfortunately it didn't work It looks like.

When generating the URL for: index.php?option=com_contact&Itemid=932&id=2&lang=en&view=contact

It still generates normally without the specified suffix (I did of course change the ID to 932 from your example above.

Wednesday, 16 September 2020 12:21 UTC
wb_weeblr

 

It still generates normally without the specified suffix (I did of course change the ID to 932 from your example above.

You deleted this SEF URL and any duplicate it may have had from the SEF URL manager after adding the code?

Ah also, you'd need to switch back com_contact to "Use sh404SEF plugin if available", don't think that code will run when using Joomla router.php file.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 12:23 UTC
TheSDHotel

Yeah, I've done both things.

When I go to: index.php?option=com_contact&Itemid=932&id=2&lang=en&view=contact

It generates this as a duplicate of user/andybadwool (which main nonsef is: index.php?option=com_contact&Itemid=562&id=2&lang=en&view=contact)

If I delete it again, and try again, it still stores it as user/andybadwool

Thanks a lot again for your support!

Wednesday, 16 September 2020 13:13 UTC
wb_weeblr

So the custom code is not executed. Please modify it like so:

function ($string, $vars, $pluginType, $extPluginPath) {
die("menuItemid: " . $menuItemId);

 Delete again all duplicates and navigate to a page where have a link to that contact page. This should cause the rendering to die half-way through and display "menuItemid: xxx".

This is to check the code is executed or not. Comment out the die(...) command afterward.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 13:36 UTC
TheSDHotel

Looks like the if check is going wrong.

if (

'com_contact' == wbArrayGet($vars, 'option', '')

&&

'contact' == wbArrayGet($vars, 'view', '')

)

If I exit before the if check, it exits.

If I exit inside the if code, it doesn't exit.

So I guess the if is not passing correctly...

Wednesday, 16 September 2020 13:43 UTC
TheSDHotel

Also, despite the code being executed, the string does not get appended to the turl

Even when the if check is not done, still no string gets appended anyway. So I guess there is some issue there too :(

Wednesday, 16 September 2020 13:45 UTC
TheSDHotel

Have you tried this on your local setup, can you reproduce it?

Wednesday, 16 September 2020 13:52 UTC
wb_weeblr

Hi

Have you tried this on your local setup, can you reproduce it?

Nope and I won't, just setting up a valid repro is too much time.

If I exit before the if check, it exits.

So the filter is running.

So I guess the if is not passing correctly...

Correct.

Also, despite the code being executed, the string does not get appended to the turl

If the "if" is not working as expected, then the string is not appended as appending is subject to the "if" test passing.

Can you paste here the entirety of your sh404sef_functions.php?

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Wednesday, 16 September 2020 13:59 UTC
TheSDHotel

Nope and I won't, just setting up a valid repro is too much time.

Are you sure? I think it's much faster that may think, you don't need two layouts, just use the default with the default menu item and see if it appends the string with the sh404sef_functions

It would be a 3 steps thing, with your sh404sef_functions implemented:

- Create one contact
- Simply create a Menu Item of type "Contact" > "List Contacts in a Category" that lists the contacts list
- Paste your sh404sef_function in the file with the above Itemid
- Visit this page, see if the Contact URL gets generated with the appended string or not.

Probably take 3 mins to reproduce :P

If the "if" is not working as expected, then the string is not appended as appending is subject to the "if" test passing.

I tried to append the string with no if, still not working :(

Can you paste here the entirety of your sh404sef_functions.php?

It's just the function that you gave me, with the only difference being the itemid. All the rest is code that's commented out.

Thanks a lot again for all the support.

 

 

Thursday, 17 September 2020 08:08 UTC
wb_weeblr

Hi

You were right, I should have tested. The code is correct but that's just not the right hook being used. The code above modifies the URL but in a different context and that modified URL is not saved to the database.

The correct code and hook to use is this one:

ShlHook::add(
	'sh404sef_url_before_create',
	function ($sef, $nonSef, $rank, $dateAdd) {

		if (
			'com_contact' == Sh404sefHelperUrl::getUrlVar($nonSef, 'option', '')
			&&
			'contact' == Sh404sefHelperUrl::getUrlVar($nonSef, 'view', '')
		)
		{
			$menuItemId = Sh404sefHelperUrl::getUrlVar($nonSef, 'Itemid', 0);
			switch ($menuItemId)
			{
				case 229:
					$sef .= '/layout-a';
					break;
				case 456:
					$sef .= '/layout-b';
					break;
			}
		}

		return $sef;
	}
);

Should work better.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Thursday, 17 September 2020 08:27 UTC
TheSDHotel

Wooooo, awesome, it works!

You da best!

Thanks man :)

Got two questions:

1) Does the sh404sef_functions file get overridden when updating sh404sef? Or is the code safe from updates?

2) I noticed that, while the SEF URL gets generated correctly, when using two layouts, the 2nd URL gets stored with a "rank" value of "1" in the database. Essentially it still thinks it's a duplicate of the other layout even though the SEF URL is different. Any tweak for this?

But awesome, thanks again, I now have a workable solution! :)

Thursday, 17 September 2020 08:30 UTC
TheSDHotel

By the way, point 2) is not a big deal. The URL still works and loads correctly :)

Thursday, 17 September 2020 08:53 UTC
wb_weeblr

Hi

1 - Code is safe, it's the entire point of using this "hook" system: your custom code is separate from sh404SEF's

2 - Hmm, did not realize that. Need to look, don't think there's a way to change that for now, maybe need another filter for it.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Thursday, 17 September 2020 09:28 UTC
TheSDHotel

Awesome, thanks a lot again man :)

Thursday, 17 September 2020 10:42 UTC
wb_weeblr

Hi

So I had to add a new filter for that, it would work that way with the existing ones. You'll need to update to the latest development version (from the development versions download area)

Then the filter is now:

ShlHook::add(
	'sh404sef_url_before_store',
	function ($sefUrl, $nonSefUrl) {
		if (
			'com_contact' == Sh404sefHelperUrl::getUrlVar($nonSefUrl, 'option', '')
			&&
			'contact' == Sh404sefHelperUrl::getUrlVar($nonSefUrl, 'view', '')
		)
		{
			$menuItemId = Sh404sefHelperUrl::getUrlVar($nonSefUrl, 'Itemid', 0);
			switch ($menuItemId)
			{
				case 229:
					$sefUrl .= '/layout-a';
					break;
				case 456:
					$sefUrl .= '/layout-b';
					break;
			}
		}

		return $sefUrl;
	}
);

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Thursday, 17 September 2020 12:13 UTC
TheSDHotel

You beautiful monster! Haha it works perfectly :)

Now the other URL is also stored with rank 1, awesome!

Thursday, 17 September 2020 12:30 UTC
TheSDHotel

I meant rank 0 :P

Thursday, 17 September 2020 12:47 UTC
wb_weeblr

Hi again,

Ah glad to heart that. It'll be in next release, you won't have to change your code in sh404sef_functions.php.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Thursday, 17 September 2020 12:49 UTC
TheSDHotel

Awesome! A filter like this can be really useful, I can think of many other ways this can be useful to automatically mass-create custom-built URLs based on certain conditions. Awesome addition!

Thanks a lot again for your great support, have a great day :)

Thursday, 17 September 2020 13:55 UTC
wb_weeblr

Hi

That's correct! The downside - for me - is that users can now create whatever URL they want according to unknown conditions. And then 6 months later they come asking "why does sh404SEF create this URL like that, but not always..." and I have to dig for hours to figure it out ;)

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
Saturday, 19 September 2020 08:07 UTC
TheSDHotel

Haha, I feel you, hopefully not :D If that's the case, you know what is the first place to look :)

Anyway thanks a lot again for your help, much appreciated!

You can close this ticket now. 

Best,
Andy

Monday, 21 September 2020 11:20 UTC
wb_weeblr

Hi

If that's the case, you know what is the first place to look :)

Except I'd need (S)FTP access to check this, which I usually don't have. Of course, I can ask the user if they have any custom code running, but their automatic and instant reply is "No" so ...

Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.

If you created any superadmin account for us, be sure to delete or block it now to avoid unnecessary risk in the future.

Best regards

Yannick Gaultier

weeblr.com / @weeblr

 

 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.