View Full Version : How to str_replace in vb4
Easy5s.net
08-17-2012, 12:53 AM
I use a code for VB3 and I want to convert it to work on vb4.
$myput = '<!-- message area -->';
$vbulletin->templatecache['newthread'] = str_replace($myput,$myput.fetch_template('new_post ing_newthread'),$vbulletin->templatecache['newthread']);
thank.
Scanu
08-17-2012, 03:21 PM
I use a code for VB3 and I want to convert it to work on vb4.
$myput = '<!-- message area -->';
$vbulletin->templatecache['newthread'] = str_replace($myput,$myput.fetch_template('new_post ing_newthread'),$vbulletin->templatecache['newthread']);
thank.
I never code for vb3 so i don't know that code is doing, however the generic code for str_replace on vb4 is easy you should use this code
$find = 'find this code';
$replace = 'replace $find with this code';
$vbulletin->templatecache['newthread'] = str_replace($find,$replace,$vbulletin->templatecache['newthread']);
Instead if you're trying to add some codes to the begin or to the end of a template, the code will looks differently
Badshah93
08-17-2012, 03:33 PM
in vB 4
$myput = '<!-- message area -->';
$replace = vB_Template::create('new_posting_newthread')->render();
$vbulletin->templatecache['newthread'] = str_replace($myput, $myput.$replace, $vbulletin->templatecache['newthread']);
The problem is that in vb3, templates were stored as if they were a php double quoted string without the quotes, so you could just replace part of one cached template with another entire template. In vb4, they're stored as php code that when eval()'d sets the $final_rendered variable to the html string to be output. So if you think about that, just inserting another template doesn't work - you end up with invalid php code.
In any case, you could try this:
$myput = '<!-- message area -->';
$replace = '\'; $final_rendered .= \'' . $myinput . substr(fetch_template('new_posting_newthread'), 19) . ' $final_rendered .= \'';
$vbulletin->templatecache['newthread'] = str_replace($myput,$replace,$vbulletin->templatecache['newthread']);
Edit: what badshah posted above is obviously simpler and will work if you haven't used any variables from the newthread template.
Easy5s.net
08-21-2012, 03:56 AM
thank all but <!-- message area --> not in the temp newthread of the vB4 which only vbb3
ChiNa
08-21-2012, 11:51 AM
Very helpfull, Thank you all of you for answering, I have learned a lot on this one!
thank all but <!-- message area --> not in the temp newthread of the vB4 which only vbb3
You could try this: change the hook location to newthread_form_complete and use this code:
$templater = vB_Template::create('new_posting_newthread');
$messagearea = $templater->render() . $messagearea;
Easy5s.net
08-21-2012, 12:09 PM
You could try this: change the hook location to newthread_form_complete and use this code:
$templater = vB_Template::create('new_posting_newthread');
$messagearea = $templater->render() . $messagearea;
Ok, I will try, thank you. And I can not click like for you because it is the message:
"You must 'Like' someone else's post before liking any more by kh99".
That's ok, you'd probably want to wait to see if it works. :)
Easy5s.net
08-21-2012, 12:28 PM
That's ok, you'd probably want to wait to see if it works. :)
Ok, it works, thank you again, but why I can not click like for you?
"You must 'Like' someone else's post before liking any more by kh99"
Scanu
08-21-2012, 01:01 PM
Because you can't like Like his posts 2 times in a row, you have to like someone else's post before like on one of his posts, i think this always happens with Kevin because all of his posts are helpful.
Ok, it works, thank you again, but why I can not click like for you?
I believe it's to prevent abuse - without that limitation you could just "like" every post someone has ever made.
i think this always happens with Kevin because all of his posts are helpful.
Thanks, but to be fair a lot of people are helpful here. I think it's just that I spend so much time here that I occasionally end up helping the same person a few times in a row. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.