vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   str_replace and custom template (https://vborg.vbsupport.ru/showthread.php?t=281226)

LifesGreatestGift 04-07-2012 05:08 AM

str_replace and custom template
 
What am I doing wrong? I would like to do a string replace on postbit/postbit_legacy template. Find specific code, insert my custom template after it. Here is what I have and its not working.


PHP Code:

require_once(DIR '/includes/class_template_parser.php'); 
$parser = new vB_TemplateParser('<span class="postcontrols">'); 
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible()); 
$find trim($parser->_parse_nodes($parser->dom_doc->childNodes())); 
$templater vB_Template::create('my_custom_template'); 
$parser = new vB_TemplateParser($templater); 
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible()); 
$replace trim($parser->_parse_nodes($parser->dom_doc->childNodes())); 
$vbulletin->templatecache['postbit'] = str_replace($find$find $replace$vbulletin->templatecache['postbit']);
$vbulletin->templatecache['postbit_legacy'] = str_replace($find$find $replace$vbulletin->templatecache['postbit_legacy']); 
unset(
$find$replace); 

This is using parse_templates.

I tried this in postbit_display_complete and it doesnt work either.

PHP Code:

$find '<span class="postcontrols">'
$replace vB_Template::create('my_custom_template'); 
$vbulletin->templatecache['postbit_legacy'] = str_replace($find$find $replace$vbulletin->templatecache['postbit_legacy']); 
$templater->render(); 
unset(
$find$replace); 

Any help would be appreciated.

kh99 04-07-2012 05:23 AM

I'm not sure, but I think maybe you need:

Code:

$parser = new vB_TemplateParser($templater->render());

(the ->render() added), since the vB_TemplateParser constructor takes a string.

LifesGreatestGift 04-07-2012 05:26 AM

in the current postbit_display_complete code I get this error

Catchable fatal error: Object of class vB_Template could not be converted to string

I need to be able to get a custom template and convert it into a string/variable.

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

and for some reason

$templater = vB_Template::create('my_custom_template');

doesnt work in parse_templates (the way I am using it)

kh99 04-07-2012 05:35 AM

Hmm...this thread has some code for doing a replace: www.vbulletin.org/forum/showthread.php?t=264690 Maybe it's fetch_template_raw() that you're looking for.

LifesGreatestGift 04-07-2012 05:51 AM

AWESOME! That worked!

parse_templates
PHP Code:

$find_string '<span class="postcontrols">'
$repl_string vB_Template::fetch_template_raw('my_custom_template'); 
$vbulletin->templatecache['postbit_legacy'] = str_replace($find_string$find_string $repl_string$vbulletin->templatecache['postbit_legacy']); 


Pandemikk 04-07-2012 07:05 AM

Just as a side note here,

Notice how it's usually: $templater = vB_Template::create();
Then: print_output($templater->render())

The method create() returns an object. $repl_string, in your code, was an object- which explains your fatal error.


All times are GMT. The time now is 06:12 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.01175 seconds
  • Memory Usage 1,742KB
  • 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
  • (1)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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