× Here you can get community support related to ReDJ.

{str_replace} not working in redirect->to?

  • thesilentman
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 5 months ago #3290 by thesilentman
{str_replace} not working in redirect->to? was created by thesilentman
Hi,
I am testing ReDJ and until now it's been a great component. Bravo!!
However I am stuck with the following problem.

I don't know if I am doing it wrong or if this might be a bug. I'd like to do the following, but get internal server errors:

from url: /aaa/bbb/ccc/
to url: {scheme}://{siteurl}{str_replace '/ccc/','/'}{path}{/str_replace}

an example url is:
mytest.com/aaa/bbb/ccc/12-hello

and I want it to redirect (301) to (result is to remove '/ccc'):
mytest.com/aaa/bbb/12-hello


The problem gets introduced as soon as I insert the str_replace part into the string.

Thanks,
Frank

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #3292 by admin
Replied by admin on topic {str_replace} not working in redirect->to?
Hi Frank,
you cannot use nested macros, because there is no iterative process to replace them. You must use placeholders, that solve the problem with a sequential process of replacement:
path={path}
newpath={str_replace '/ccc/','/'}${path}{/str_replace}

Then you can put ${newpath} placeholder in your "To URL" fileld.

Kind regards,
Luigi
The following user(s) said Thank You: thesilentman

Please Log in or Create an account to join the conversation.

  • thesilentman
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 5 months ago - 9 years 5 months ago #3293 by thesilentman
Replied by thesilentman on topic {str_replace} not working in redirect->to?
Hello Luigi,

thanks for your quick reply!! :)

unfortunately that didn't work either at the moment, but read on...

However I got the problem solved and it even works with my initial string :D

having turned on error reporting I got the following, where the internal error occured.
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /*webpath_here*/plugins/system/redj/redj.php on line 1183
Call Stack
#	Time	Memory	Function	Location
1	0.0000	245912	{main}( )	../index.php:0
2	0.0056	830000	JApplicationCms->execute( )	../index.php:40
3	0.0056	830408	JApplicationSite->doExecute( )	../cms.php:251
4	0.0056	830960	JApplicationSite->initialiseApp( )	../site.php:209
5	0.0078	1079760	JApplicationCms->initialiseApp( )	../site.php:649
6	0.0154	1950712	JApplicationBase->triggerEvent( )	../cms.php:583
7	0.0154	1950760	JEventDispatcher->trigger( )	../base.php:106
8	0.0154	1951504	JEvent->update( )	../dispatcher.php:162
9	0.0154	1951992	call_user_func_array:{/*webpath_here*/libraries/joomla/event/event.php:71} ( )	../event.php:71
10	0.0154	1952664	plgSystemReDJ->onAfterInitialise( )	../event.php:71
11	0.0155	1955776	plgSystemReDJ->setRedirect( )	../redj.php:1283
12	0.0360	1984800	plgSystemReDJ::evaluatePlaceholders( )	../redj.php:1401
13	0.0378	1998504	preg_replace ( )	../redj.php:1183


While this is only a deprecation warning, I was getting the reason for the internal error in the end:


Fatal error: Class 'plgSystemTagMeta' not found in 
/*webpath_here*/plugins/system/redj/redj.php(1183) : regexp code on line 1
Call Stack
#	Time	Memory	Function	Location
1	0.0000	245912	{main}( )	../index.php:0
2	0.0056	830000	JApplicationCms->execute( )	../index.php:40
3	0.0056	830408	JApplicationSite->doExecute( )	../cms.php:251
4	0.0056	830960	JApplicationSite->initialiseApp( )	../site.php:209
5	0.0078	1079760	JApplicationCms->initialiseApp( )	../site.php:649
6	0.0154	1950712	JApplicationBase->triggerEvent( )	../cms.php:583
7	0.0154	1950760	JEventDispatcher->trigger( )	../base.php:106
8	0.0154	1951504	JEvent->update( )	../dispatcher.php:162
9	0.0154	1951992	call_user_func_array:{/*webpath_here*/libraries/joomla/event/event.php:71} ( )	../event.php:71
10	0.0154	1952664	plgSystemReDJ->onAfterInitialise( )	../event.php:71
11	0.0155	1955776	plgSystemReDJ->setRedirect( )	../redj.php:1283
12	0.0360	1984800	plgSystemReDJ::evaluatePlaceholders( )	../redj.php:1401
13	0.0378	1998504	preg_replace ( )	../redj.php:1183
14	0.0394	2013728	preg_replace( )	../redj.php:1183

So I searched for the dreaded "plgsystemtagmeta" and found it. I guess it falls under the category "copy/paste bugs" :)

Instead of calling the manageMacroParams on itself, it was calling the method on the other plugin. If that was not installed, it was doomed ;)

Attached is a diff with the fix.

BTW, it would probably be better to call the methods with self:: to avoid those kinds of errors.

This message has an attachment file.
Please log in or register to see it.

Last edit: 9 years 5 months ago by thesilentman.

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #3296 by admin
Replied by admin on topic {str_replace} not working in redirect->to?
I guess you are using last 1.7.6 Community version, I know this issue, already fixed in the last 1.7.8 Enterprise, but the corresponding Community is not released yet. Now there is something like:
$patterns_callback[39] = "/\{(str_replace) ([^\}]+)\}(.*)\{\/str_replace\}/suU";

According to PHP tips to solve the deprecation warning...

I will try to release the 1.7.8 Community ASAP, but meanwhile this fix could help someone else, thanks :)

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

Time to create page: 0.096 seconds