Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-19-2011, 08:33 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default "Compiled template"

Hi everybody! Let's start
Here what kh99

Quote:
Originally Posted by kh99 View Post
Unfortunately it's difficult, I could write pages and still not explain everything (partly because I don't fully understand it myself). But in this case I happen to have a mod that changes the SHOWTHREAD template. It uses the showthread_getinfo hook location and has code like this
Code:
$find = "some string";
$replace = "other string";
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']);

but, $vbulletin->templatecache contains compiled templates so it doesn't look like what you see in the template editor. That makes it tricky to know what you can search for and match. You could look in the template table in the database, the "template" column shows the compiled template. Or what I usually do is put in temporary code to write the cached template string to a file, like

Code:
$fp = fopen("showthread.txt", "wb");
fwrite($fp, $vbulletin->templatecache['SHOWTHREAD']);

Then I open that file in my editor so I can refer to it.

I hope that makes some sense.
i need to know what's the code of the compiled template "forumhome_forumbit_level2_post"

I tried your code (FOR SHOWTHREAD) and it gets me a blank text file, so nothing

This is the code that i need to "convert"

Code:
<vb:comment><h2 class="forumtitle"><a href="{vb:link forum, {vb:raw forum}}">{vb:raw forum.title}</a></h2></vb:comment> 
        <h2 class="forumtitle"><div id="scanu"><a <vb:if condition="$show[\'forumdescription\']">title=\'<scanu>{vb:raw forum.description}</scanu>\'</vb:if> href="{vb:link forum, {vb:raw forum}}">{vb:raw forum.title}</a></div></h2>   
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>    
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js"></script>   
<script>   
$("#scanu a[title]").tooltip({   
position: \'center right\',   
effect: \'slide\'   
});   
</script>   
<style>   
scanu {   
background:black;   
color:white;   
padding: 5px 10px;   
-moz-border-radius: 8px;   
-webkit-border-radius: 8px;   
filter:alpha(opacity=68);    
-moz-opacity:.68;   
opacity:.68;   
}   
</style>
how can i do?
thanks in advance

--------------- Added [DATE]1324331782[/DATE] at [TIME]1324331782[/TIME] ---------------

I see the database and i've tried this code
Code:
$find = '<h2 class="forumtitle"><a href="' . vB_Template_Runtime::linkBuild("forum", $forum) . '">' . $forum['title'] . '</a></h2>';
$replace = '
 <h2 class="forumtitle"><div id="scanu"><a title=\'<scanu>' . $forum['description'] . '</scanu>\' href="' . vB_Template_Runtime::linkBuild("forum", $forum) . '">' . $forum['title'] . '</a></div></h2>   


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>    
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js"></script>   
<script>   
$("#scanu a[title]").tooltip({   
position: \'center right\',   
effect: \'slide\'   
});   
</script>   
<style>   
scanu {   
background:black;   
color:white;   
padding: 5px 10px;   
-moz-border-radius: 8px;   
-webkit-border-radius: 8px;   
filter:alpha(opacity=68);    
-moz-opacity:.68;   
opacity:.68;   
}   
</style>';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
But didn't work

--------------- Added [DATE]1324332260[/DATE] at [TIME]1324332260[/TIME] ---------------

Code:
$find = '' . $forum['title'] . '';
$replace = '';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
This code would be delete the title of the forum but doesn't work! This code instead that would be delete the text "test" without variables works D:
Code:
$find = 'test';
$replace = '';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
Reply With Quote
  #2  
Old 12-19-2011, 09:10 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The reason the code using the showthread hook didn't work for you is that not every template is loaded on every page, and the forumbit templates aren't loaded on the showthread page. But as you figured out, you can look in the database and find the same info.

I'm not sure if you're saying you figured it out or you still have a problem.
Reply With Quote
  #3  
Old 12-19-2011, 09:20 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok i try the code of the showthread for the showthread exactly as you said just for see, but doesn't work. then yesy i see the code in the databse and i tried this code
Code:
$find = '<h2 class="forumtitle"><a href="' . vB_Template_Runtime::linkBuild("forum", $forum) . '">' . $forum['title'] . '</a></h2>';
$replace = '
 <h2 class="forumtitle"><div id="scanu"><a title=\'<scanu>' . $forum['description'] . '</scanu>\' href="' . vB_Template_Runtime::linkBuild("forum", $forum) . '">' . $forum['title'] . '</a></div></h2>   


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>    
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js"></script>   
<script>   
$("#scanu a[title]").tooltip({   
position: \'center right\',   
effect: \'slide\'   
});   
</script>   
<style>   
scanu {   
background:black;   
color:white;   
padding: 5px 10px;   
-moz-border-radius: 8px;   
-webkit-border-radius: 8px;   
filter:alpha(opacity=68);    
-moz-opacity:.68;   
opacity:.68;   
}   
</style>';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
and so i'm asking to me why? :S
Reply With Quote
  #4  
Old 12-19-2011, 09:23 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, try this:

Code:
$find = '<h2 class="forumtitle"><a href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . '">\' . $forum['title'] . \'</a></h2>';
$replace = '
 <h2 class="forumtitle"><div id="scanu"><a title=\'<scanu>' . $forum['description'] . '</scanu>\' href="' . vB_Template_Runtime::linkBuild("forum", $forum) . '">' . $forum['title'] . '</a></div></h2>

Edit: well, the replace code there isn't right, but the point is that you need to escape all single quotes in the string you're trying to match. You seem to have escaped the quotes in the string you're adding, but not in the string you got from the compiled template.
Reply With Quote
  #5  
Old 12-20-2011, 09:48 AM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What!? The code didn't worked but i've changed this
' . $forum['title'] . '
in this:
' . $forum[\'title\'] . '
And it worked just this code with this code
Code:
$find = '\' . $forum[\'title\'] . \'';
$replace = '';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
Now i will try all the first code

--------------- Added [DATE]1324383827[/DATE] at [TIME]1324383827[/TIME] ---------------

Everything work but there is a problem: This is my code
Code:
$find = '<h2 class="forumtitle"><a href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></h2>';
$replace = '<h2 class="forumtitle"><div id="scanu"><a title="<scanu>\' . $forum[\'description\'] . \'</scanu>" href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></div></h2>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>    
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js"></script>    
<script>   
$("#scanu a[title]").tooltip({   
position: "center right",   
effect: "slide"   
});   
</script>  
<style>   
scanu {   
background:black;   
color:white;   
padding: 5px 10px;   
-moz-border-radius: 8px;   
-webkit-border-radius: 8px;   
filter:alpha(opacity=68);    
-moz-opacity:.68;   
opacity:.68;   
}   
</style>';


$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
If i change this
Code:
title="<scanu>\' . $forum[\'description\'] . \'</scanu>"
in this
Code:
title=\'<scanu>\' . $forum[\'description\'] . \'</scanu>\'
doesn't work! Why?
Reply With Quote
  #6  
Old 12-20-2011, 01:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I believe html attributes need to have " and not '.
Reply With Quote
  #7  
Old 12-20-2011, 01:53 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No that's a choice of the coder (as php) in fact in normal html works but in this code not. As i change " to \' it delete all the template o.o. I need that is ' and not "
In php syntax this would be work That's strange
Reply With Quote
  #8  
Old 12-20-2011, 02:03 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, OK - I don't do enough html to keep that stuff straight. But I think then the reason it doesn't work is that it ends up producing a php string where the quotes are unmatched (or matched but not the way you intended). This stuff gets really confusing and hard to keep track of in my mind, but I think if you did this is might work:

Code:
title=\\'<scanu>\' . $forum[\'description\'] . \'</scanu>\\'
Reply With Quote
  #9  
Old 12-20-2011, 02:18 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Oh, OK - I don't do enough html to keep that stuff straight. But I think then the reason it doesn't work is that it ends up producing a php string where the quotes are unmatched (or matched but not the way you intended). This stuff gets really confusing and hard to keep track of in my mind, but I think if you did this is might work:

Code:
title=\\'<scanu>\' . $forum[\'description\'] . \'</scanu>\\'
That's the same for me, anyway it doesn't work Very strange!
I tried " and it worked but not as i want
I tried \' and it doesn't work
Now i tried \\' and it still doesn't work

Now the last thing i can do is change this
Code:
$replace = '     ';
on
Code:
$replace = "    ";
and so i can leave title = 'etc...' without problems, i have just to place a \ before the "

--------------- Added [DATE]1324395032[/DATE] at [TIME]1324395032[/TIME] ---------------

Worst! Damn this code is perfect!
Code:
$find = '<h2 class="forumtitle"><a href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></h2>';
$replace = '<h2 class="forumtitle"><div id="scanu"><a title="<scanu>\' . $forum[\'description\'] . \'</scanu>" href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></div></h2>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>    
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js"></script>    
<script>   
$("#scanu a[title]").tooltip({   
position: "center right",   
effect: "slide"   
});   
</script>  
<style>   
scanu {   
background:black;   
color:white;   
padding: 5px 10px;   
-moz-border-radius: 8px;   
-webkit-border-radius: 8px;   
filter:alpha(opacity=68);    
-moz-opacity:.68;   
opacity:.68;   
}   
</style>';


$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find, $replace, $vbulletin->templatecache['forumhome_forumbit_level2_post']);
Why i can't change " to \' ?
Reply With Quote
  #10  
Old 12-20-2011, 03:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe try using "heredoc" syntax for the replacement string: http://us2.php.net/manual/en/language.types.string.php
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:54 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09634 seconds
  • Memory Usage 2,295KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (17)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete