Quote:
Originally Posted by emath
1. it worked for me, why is that if i used the <head> to do the replace ?
|
Well, like I mentioned, if you're only looking for a simple piece of html then that's OK. So maybe the code you originally posted would be able to match if you figured out the correct string (which I guess is what you were asking in the first place). It still may be helpful to look at the compiled template and find that section, and see what needs to be matched. It could be that the newline is not in the compiled template at all.
In any case, what your replacing is inside a php single quoted string. So your replacement can be only html. (Well, it could actually be any php code you wanted, as long as the result of your replacement ends up as valid php). If your replacement contains any single quote characters, they would have to be escaped with backslashes or else they would cause an error when the template is rendered.
Quote:
2. why here i must use preRegister .
|
It depends on exactly what's in the template cache after the replacement is done. You only need the preRegister if resulting php code uses that variable. In the code you posted above, the replacement inserts the $jsvar variable so that it's evaluated when the template is rendered, so the preRegister is required. It might have been possible to insert the actual value of $jsvar instead of the variable (if the value is known at the time of the replacement), then preRegister wouldn't be needed.
Quote:
3. tried this on global_complete with no success at all :
|
It seems like that should have done something if there's at least one <p> tag in the page somewhere. Also, again your replacement cannot contain template tags. or {vb:raw.., {vb:rawphrase.., etc. So maybe a replacement did happen but didn't display anything on the page.
Quote:
after its compiled - its a php code. after its rendered - does it includes the {vb:rawphr... or puts a text instead already ?
|
When the template is compiled (before you do your replace on it), {vb:raw... is replaced with a variable, and {vb:rawphrase...} is replaced with the phrase text (the contents of $vbphrase['phrasename'], or a call to construct_phrase() if there are parameters).
In short, you need to do the work of the template compiler before you do the replacement, but it's not difficult because the template tags just get converted to php code. For the replacement you posted above, you coudl try something like this:
Code:
$find = '<div id="thread_active_users"><p>' ;
$replace = " <!-- Refresh Button -->\n";
if ($vbulletin->options['active_users_onoff'])
$replace .= '<button onclick="showUsers()" type="button" style="float:left;"> ' . htmlspecialchars_uni($vbphrase['refresh_button']) . '</button>';
$replace .= $find;
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']);
(I made the assumption that the newline is just missing, but like I mentions above, you might have to look at the compiled template to figure out what $find should be). The call to htmlspecialchars_uni() should take care of any quotes or special characters that might be in the phrase text.
ETA: Actually, now that I look at the above again, I guess you'd only want to do the replacement if the options was true, so something like this may be better:
Code:
if ($vbulletin->options['active_users_onoff'])
{
$find = '<div id="thread_active_users"><p>' ;
$replace = ' <!-- Refresh Button -->
<button onclick="showUsers()" type="button" style="float:left;"> ' . htmlspecialchars_uni($vbphrase['refresh_button']) . '</button>' . $find;
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']);
}