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 04-07-2012, 05:08 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 04-07-2012, 05:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 04-07-2012, 05:26 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #4  
Old 04-07-2012, 05:35 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
LifesGreatestGift
  #5  
Old 04-07-2012, 05:51 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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']); 
Reply With Quote
  #6  
Old 04-07-2012, 07:05 AM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
LifesGreatestGift
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 07:29 PM.


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.04176 seconds
  • Memory Usage 2,234KB
  • 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
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (2)post_thanks_box_bit
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete