vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Modify template by install code (https://vborg.vbsupport.ru/showthread.php?t=276056)

Valter 12-27-2011 12:09 PM

Modify template by install code
 
I want to do simple search/replace in the template on product install.

It works fine, however until it's re-saved manually changes are not visible.

I guess I need to re-cache the template?

How to solve this?

Thanks in advance.

Boofo 12-27-2011 01:57 PM

Why don't you just use the parse_templates hook and do it in the mod itself? I know of no way to do it on the actual install procedure of a mod.

Lynne 12-27-2011 04:41 PM

You don't want to actually change the master style. I think that would be a no-no.

Valter 12-28-2011 08:11 AM

Thanks for you replies.

I've tried to do this in parse_templates but it won't work:
Code:

$vsa_tlmu_rstr_s = '<a class="title';
$vsa_tlmu_rstr_r = '<a style="{vb:raw thread.vsa_tlmu_css}" class="title';
$vbulletin->templatecache["threadbit"] = str_replace($vsa_tlmu_rstr_s, $vsa_tlmu_rstr_r, $vbulletin->templatecache["threadbit"]);


When I manually add
Code:

style="{vb:raw thread.vsa_tlmu_css}"
to the template, it works perfect.

thread.vsa_tlmu_css is produced in threadbit_process hook.

Boofo 12-28-2011 08:45 AM

vb 4 does it differently. Try this in the parse_templates or process_templates_complete hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<a class="title');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<a style="{vb:raw thread.vsa_tlmu_css}" class="title');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit']);
unset($find, $replace);


Valter 12-28-2011 08:58 AM

Yes, it works.

You are genius. Thank You!

Edit: It also works when added after my code in threadbit_process.

Boofo 12-28-2011 09:10 AM

You had doubts? ;)

And you are welcome, my friend.

Scanu 01-03-2012 10:31 PM

thanks Boofo for your code it helped me too :)

Boofo 01-03-2012 10:46 PM

I expect residuals. ;)


All times are GMT. The time now is 03:53 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00994 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete