vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to str_replace in vb4 (https://vborg.vbsupport.ru/showthread.php?t=286747)

Easy5s.net 08-17-2012 12:53 AM

How to str_replace in vb4
 
I use a code for VB3 and I want to convert it to work on vb4.

Code:

$myput = '<!-- message area -->';
$vbulletin->templatecache['newthread'] = str_replace($myput,$myput.fetch_template('new_posting_newthread'),$vbulletin->templatecache['newthread']);

thank.

Scanu 08-17-2012 03:21 PM

Quote:

Originally Posted by Easy5s.net (Post 2357567)
I use a code for VB3 and I want to convert it to work on vb4.

Code:

$myput = '<!-- message area -->';
$vbulletin->templatecache['newthread'] = str_replace($myput,$myput.fetch_template('new_posting_newthread'),$vbulletin->templatecache['newthread']);

thank.

I never code for vb3 so i don't know that code is doing, however the generic code for str_replace on vb4 is easy you should use this code
PHP Code:

$find 'find this code';
$replace 'replace $find with this code';
$vbulletin->templatecache['newthread'] = str_replace($find,$replace,$vbulletin->templatecache['newthread']); 

Instead if you're trying to add some codes to the begin or to the end of a template, the code will looks differently

Badshah93 08-17-2012 03:33 PM

in vB 4

PHP Code:

$myput '<!-- message area -->';
$replace vB_Template::create('new_posting_newthread')->render();
$vbulletin->templatecache['newthread'] = str_replace($myput$myput.$replace$vbulletin->templatecache['newthread']); 


kh99 08-17-2012 03:44 PM

The problem is that in vb3, templates were stored as if they were a php double quoted string without the quotes, so you could just replace part of one cached template with another entire template. In vb4, they're stored as php code that when eval()'d sets the $final_rendered variable to the html string to be output. So if you think about that, just inserting another template doesn't work - you end up with invalid php code.

In any case, you could try this:

Code:

$myput = '<!-- message area -->';
$replace = '\'; $final_rendered .= \'' . $myinput . substr(fetch_template('new_posting_newthread'), 19) . ' $final_rendered .= \'';
$vbulletin->templatecache['newthread'] = str_replace($myput,$replace,$vbulletin->templatecache['newthread']);


Edit: what badshah posted above is obviously simpler and will work if you haven't used any variables from the newthread template.

Easy5s.net 08-21-2012 03:56 AM

thank all but <!-- message area --> not in the temp newthread of the vB4 which only vbb3

ChiNa 08-21-2012 11:51 AM

Very helpfull, Thank you all of you for answering, I have learned a lot on this one!

kh99 08-21-2012 12:03 PM

Quote:

Originally Posted by Easy5s.net (Post 2358635)
thank all but <!-- message area --> not in the temp newthread of the vB4 which only vbb3


You could try this: change the hook location to newthread_form_complete and use this code:
Code:

$templater = vB_Template::create('new_posting_newthread');
$messagearea = $templater->render() . $messagearea;


Easy5s.net 08-21-2012 12:09 PM

Quote:

Originally Posted by kh99 (Post 2358707)
You could try this: change the hook location to newthread_form_complete and use this code:
Code:

$templater = vB_Template::create('new_posting_newthread');
$messagearea = $templater->render() . $messagearea;


Ok, I will try, thank you. And I can not click like for you because it is the message:
"You must 'Like' someone else's post before liking any more by kh99".

kh99 08-21-2012 12:14 PM

That's ok, you'd probably want to wait to see if it works. :)

Easy5s.net 08-21-2012 12:28 PM

Quote:

Originally Posted by kh99 (Post 2358716)
That's ok, you'd probably want to wait to see if it works. :)

Ok, it works, thank you again, but why I can not click like for you?

"You must 'Like' someone else's post before liking any more by kh99"


All times are GMT. The time now is 09:17 AM.

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.01118 seconds
  • Memory Usage 1,747KB
  • 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
  • (5)bbcode_code_printable
  • (2)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete