[Solved] Make UCP redirects always go to i=(module_id) URLs instead of verbose URLs

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
teebling
Registered User
Posts: 113
Joined: Sat Apr 14, 2018 7:38 pm
Contact:

[Solved] Make UCP redirects always go to i=(module_id) URLs instead of verbose URLs

Post by teebling »

Each module in phpBB's UCP can be accessed from two different URLs - a 'verbose' version (for example /ucp.php?i=ucp_profile&mode=profile_info) or by using the module's ID as a parameter (for example /ucp.php?i=200). Both URLs lead to the exact same page, so one could argue why would you use one over the other...

Personally I prefer the 'module ID paramater' version far more because it allows me to target individual modules with marttiphpBB's paramater template variables extension (instead of less specific script names or areas), which means that I can be MUCH more precise with templating.

Yes, I know that his ext also can target the 'verbose' URLs, but not precisely - for example if modules have been moved into different categories, they still inherit the ancestors verbose URL, making them impossible to target with a template variable. This is not the case with the module ID parameter URLs, which always, no matter what, can be targeted individually with a parameter template variable, no matter where they lie in the categorisation of modules.

So...

This has been working fine for me so far, and I've been able to build some very cool navigation UI for the UCP - but I've run into a problem - after a user successfully submits a form in the UCP and is presented with the 'Information' page, they are either
  • Redirected automatically to the previous page, but unfortunately this is the 'verbose' URL of the module.
  • Or they manually click the 'Return to the user control panel' link and again, unfortunately, this takes them to the 'verbose' URL of the module.
What I'd like to do is to modify the redirect() function somehow so that any redirects to modules in the UCP redirect to the module ID paramater version of the URL. So that no matter what they always end up on the /ucp.php?i=200 page, NOT on the /ucp.php?i=ucp_profile&mode=profile_info page.

Any ideas on how I might attempt this? I've tried using 301 redirects but these are too powerful and of course stop the forms from being submitted in the first place.

Update

I managed to get the breadcrumb links to always link to the module_ID version of the URLs (yay!) by doing the following:

In includes/functions_module.php

Find:

Code: Select all

			// if the item has a name use it, else use its id
			if (empty($item_ary['name']))
			{
				$u_title .= $item_ary['id'];
			}
			else
			{
				// if the category has a name, then use it.
				$u_title .= $this->get_module_identifier($item_ary['name']);
			}
Replace with:

Code: Select all

// always use the module_id instead of the module name when building UCP breadcrumb links
$u_title .= $item_ary['id'];
So that's cool, but it doesn't solve the redirecting issue.

After a bit of digging I've found that the action attribute in the page's <form> tag determines what the eventual redirect link will be - so I can already see an easy workaround to this using javascript to replace that URL with the type I want after the page has loaded.

But..... I want to see if I can first try and do this before the DOM loads (with PHP) instead of after (with JS)... so I looked further and found that the S_UCP_ACTION variable is what goes in that 'action' attribute - and it is defined in includes/ucp/ucp_xxxx.php files for each module as $this->u_action). However, after trying to dig more, I can't find where this $u_action variable is made - if I could get to that then maybe I could change it to construct the URL with i=xxx syntax instead of verbose. If you guys can point me in the right direction I'd appreciate it :)

Update 2 - Solved!

Found the bit I needed, here's how to make the redirects always go to the module_ID variant of the URL:

In includes/functions_module.php:

Find:

Code: Select all

			$this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_name)) . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
Replace with:

Code: Select all

			$this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_id)) . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: [Solved] Make UCP redirects always go to i=(module_id) URLs instead of verbose URLs

Post by thecoalman »

teebling wrote: Tue Apr 13, 2021 5:23 pm So that no matter what they always end up on the /ucp.php?i=200 page, NOT on the /ucp.php?i=ucp_profile&mode=profile_info page.
Be aware that number is not static across all forums and can change under certain circumstances. I know mine are not the same but I don't remember exactly why. I'm running a forum that is very old and went through a lot of changes over the years. I know at one point I went on link fixing spree and making sure those were accurate using the verbose link.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
teebling
Registered User
Posts: 113
Joined: Sat Apr 14, 2018 7:38 pm
Contact:

Re: [Solved] Make UCP redirects always go to i=(module_id) URLs instead of verbose URLs

Post by teebling »

thecoalman wrote: Wed Apr 14, 2021 12:31 am
teebling wrote: Tue Apr 13, 2021 5:23 pm So that no matter what they always end up on the /ucp.php?i=200 page, NOT on the /ucp.php?i=ucp_profile&mode=profile_info page.
Be aware that number is not static across all forums and can change under certain circumstances. I know mine are not the same but I don't remember exactly why. I'm running a forum that is very old and went through a lot of changes over the years. I know at one point I went on link fixing spree and making sure those were accurate using the verbose link.
Yeah that's true - I think they change when a module is added by an ext (depending on the order the exts are installed in), or if they have been moved around.
Post Reply

Return to “phpBB Custom Coding”