The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
str_replace problem
im trying to relpace a two rows in SHOWTHREAD template,
this is my code : PHP Code:
Edit : tried also with "\n" instead of PHP_EOL with no success . thanks |
#2
|
|||
|
|||
$vbulletin->templatecache contains the compiled template, so you probably won't be able to figure out what to match when doing a str_replace() by looking at the template in the template editor (except maybe in a case where you're trying to match a small piece of html). Also, you cannot use template tags or curly braces in your replacement since it's already been compiled. So I think there are two things you can do: figure out the right replacement for the compiled template, or do a replacement after it's been rendered.
You can look in the database "template" table, and the "template" column contains the compiled version of the template (or you can put code in a plugin to print out what's in $vbulletin->templatecache). The cached version of a template is php code that sets a $final_rendered variable when it's eval()'d. You can figure out a str_replace() for that, but it can be tricky to get the quotes right. If you want to try the second method, you could use hook global_complete and do str_replace() on the $output variable (and probably check for THIS_SCRIPT == 'showthread' so you're not doing it for every page). For this method you can look at the html source of the page in your browser to figure out the replacement. ETA: Also, I don't think you need the call to vB_Template:reRegister(). |
Благодарность от: | ||
emath |
#3
|
|||
|
|||
the first option is not good cause i need to change a <div> tag and i cant find such in the compiled template .
about this code : PHP Code:
2. why here i must use preRegister . 3. tried this on global_complete with no success at all : PHP Code:
also, on global_complete can i use {vb:rawphrase.. ? after its compiled - its a php code. after its rendered - does it includes the {vb:rawphr... or puts a text instead already ? Thanks alot for the help . |
#4
|
||||
|
||||
Quote:
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:
Quote:
Quote:
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']); } |
#5
|
|||
|
|||
thats looks very helpful though it still not what i need .
i want to change the <div> tag to <div id="thread_active_users"> actually, the code in the SHOWTHREAD template is : Code:
<div> <p> Code:
<!-- Refresh Button --> <vb:if condition="$vbulletin->options[\'active_users_onoff\']"> <button onclick="showUsers()" type="button" style="float:left;"> {vb:rawphrase refresh_button} </button> </vb:if> <div id="thread_active_users"> <p> PHP Code:
though this on the hook showthread_complete doesnt work. --------------- Added [DATE]1368635293[/DATE] at [TIME]1368635293[/TIME] --------------- how can i find the right text to find? the compiled version of SHOWTHREAD doesnt help at all... this is the right part of it i think, but it tells me nothing : Code:
' . vB_Template_Runtime::parsePhrase("users_browsing_this_thread") . ' ' . vB_Template_Runtime::parsePhrase("users_currently_browsing_x_y_z", '' . $totalonline . '', '' . $numberregistered . '', '' . $numberguest . '') . ' |
#6
|
|||
|
|||
I think your problem might be the white space. Looking at the html source for the showthread page on my test server, it looks like there's a newline followed by 4 tabs, so you might try "\n\t\t\t\t". And if that doesn't work, maybe try "\r\n\t\t\t\t".
|
#7
|
|||
|
|||
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|