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 07-05-2011, 12:08 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default str_replace help please

Ok, this is my 1st time playing around with str_replace and I'm obviously doing SOMETHING wrong as my code isn't working lol

Basically what I'm trying to do, is turn this into an automatic template edit, and eventually do the same with most of my personal modifications which haven't and won't be released here. So no need to worry about if user x installs on a custom style, he/she may run into problems later.

Anyway, on with the codes

Currently, I have this in a plugin
PHP Code:
$find '<vb:if condition=\"$post['signature']\">';
$replace '<vb:if condition=\"$post['signature'] AND !$vboptions['shownsigs'][$post[userid]] AND $vboptions['shownsigs'][$post[userid]] = true\">';
$output str_replace($find,$replace.$find$output); 
Which probably isn't right, but a lot of the threads I've searched through for vB 4 str_replace are incomplete as far as an official WORKING answer.

Now, with the code above, I've tried using the hook locations:
Quote:
global_start
showthread_start
parse_templates
showthread_postbit_create
postbit_display_start
postbit_display_complete
showthread_complete
Which seem to be the most logical ones to use for this modification, but it still isn't working. So, to me, that HOPEFULLY narrows it down to my code not being correct.

So, my next question is, what's wrong with it?

/ str_replace noob
Reply With Quote
  #2  
Old 07-05-2011, 12:12 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Templates get compiled when you save into actual PHP code, and evaluated before it gets to global_shutdown.

global_start (or vb4 equivalent)
PHP Code:
echo $vbulletin->templatecache['TEMPLATE_NAME']; exit; 
See what that prints out, and you'll have to do str_replace() on that variable, rather than $output.

PHP Code:
$vbulletin->templatecache['postbit'] = str_replace(
    
$find,
    
$replace,
    
$vbulletin->templatecache['postbit'
); 
--------------- Added [DATE]1309828392[/DATE] at [TIME]1309828392[/TIME] ---------------

Alternatively, you could probably do it all in PHP.

Once you've rendered it once, set $post['signature'] = '';
Reply With Quote
  #3  
Old 07-05-2011, 12:30 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
Templates get compiled when you save into actual PHP code, and evaluated before it gets to global_shutdown.

global_start (or vb4 equivalent)
PHP Code:
echo $vbulletin->templatecache['TEMPLATE_NAME']; exit; 
See what that prints out, and you'll have to do str_replace() on that variable, rather than $output.
That gave me a blank white page
Quote:
Originally Posted by Adrian Schneider View Post
PHP Code:
$vbulletin->templatecache['postbit'] = str_replace(
    
$find,
    
$replace,
    
$vbulletin->templatecache['postbit'
); 
--------------- Added 04 Jul 2011 at 21:13 ---------------

Alternatively, you could probably do it all in PHP.

Once you've rendered it once, set $post['signature'] = '';
And you lost me there lol
Reply With Quote
  #4  
Old 07-05-2011, 12:39 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Move that first plugin to global_complete (for example's sake). I always forget that the global_start one has output buffering which would give you the blank page.

Once you see the output from a compiled template, it will give you an idea on how to actually figure out what to put in $find and $replace.


For the alternate method, upon successfully displaying the signature once, you can empty that variable so it won't display again, rather than relying on the template edit.

postbit_display_start
PHP Code:
// if signature exists, and cached (already displayed on page)
if ($this->post['signature'] and $this->cache['sig'][$this->post['userid']]) {
    
$this->post['signature']     = '';
    
$this->post['showsignature'] = false;

Not tested, but may work.
Reply With Quote
  #5  
Old 07-05-2011, 12:51 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
Move that first plugin to global_complete (for example's sake). I always forget that the global_start one has output buffering which would give you the blank page.

Once you see the output from a compiled template, it will give you an idea on how to actually figure out what to put in $find and $replace.
Sorry, guess I should've mentioned I tried global_complete too, and that too gave a blank page.

Quote:
Originally Posted by Adrian Schneider View Post
For the alternate method, upon successfully displaying the signature once, you can empty that variable so it won't display again, rather than relying on the template edit.

postbit_display_start
PHP Code:
// if signature exists, and cached (already displayed on page)
if ($this->post['signature'] and $this->cache['sig'][$this->post['userid']]) {
    
$this->post['signature']     = '';
    
$this->post['showsignature'] = false;

Not tested, but may work.
Just tested and this DOES work. Thanks. Now just need an updated tutorial for str_replace for vB 4 lol
Reply With Quote
  #6  
Old 07-05-2011, 01:57 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Look how I did it here:

https://vborg.vbsupport.ru/showthread.php?t=259687

I did the mod for this for vb4.
Reply With Quote
  #7  
Old 07-05-2011, 06:56 AM
MaryTheG(r)eek MaryTheG(r)eek is offline
 
Join Date: Sep 2006
Location: Greece
Posts: 1,340
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think that:
Code:
$output = str_replace($find,$replace.$find, $output); 
is correct. You evaluate an expression there which maybe will cause endless loop by having $find there, which is also the first argument. I haven't seen all your code, but if you want to use that expression is better to add another variable before. eg:
Code:
$mynewreplace = $replace.$find;
$output = str_replace($find,$mynewreplace, $output); 
Maria
Reply With Quote
  #8  
Old 07-05-2011, 07:20 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In vb4, find doesn't work with if conditions very well. That is why your code below didn't work.

Code:
$find = '<vb:if condition=\"$post['signature']\">';
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 08:41 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.04079 seconds
  • Memory Usage 2,261KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_code
  • (7)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete