Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 12-10-2009, 09:16 AM
mme42 mme42 is offline
 
Join Date: Feb 2009
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Excluding Certain Forums for a Simple str_replace Filter Plug

I've been trying to write a simple filter plug-in to replace certain host/domain names with a message for certain forums only.

I actually started trying to replace the whole hyperlinked URLs or even plain text links with a regular expression. But, it's a bit over my head. And, after asking about it over at Stackoverflow, I've gotten the idea that there might be a better way to do it even if I figured out the REGEX to use. So, until I can begin to understand that stuff more, I've decided to just start with a simple str_replace to at least filter the domain part.

I have the filter part working fine, but I'm not sure how to exclude certain forums. There are less forums that I'd like to exclude than include, so I went about it from perspective of excluding them. I'm not sure if I'm using the right variable for the forum ID or using it in the right way. Here's what I have so far:

PHP Code:
$filteredhosts = array('hostname1''hostname2''hostname3');
$replacemessage 'THIS LINK HAS BEEN FILTERED';
if  (
$foruminfo['forumid'] != array ('1','2','3','4','5','6','7','8')) $this->post['message'] =  str_replace($filteredhosts$replacemessage$this->post['message']); 

The hook location is postbit_display_complete and the execution order is 5 if that matters. So, I'm looking for the correct php forum ID variable and the correct way to use it in this situation if anybody can help.

Thanks.
Reply With Quote
  #2  
Old 12-10-2009, 12:57 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think what you want is something like:

PHP Code:
if  (!in_array($foruminfo['forumid'], array ('1','2','3','4','5','6','7','8'))) 

ETA: ...and you probably don't need the forum numbers in quotes.
Reply With Quote
  #3  
Old 12-10-2009, 01:23 PM
mme42 mme42 is offline
 
Join Date: Feb 2009
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm. Thanks. I've now tried that, but it's still replacing in all sections. I tried with and without the quotes on the forum ID numbers.

This may be a silly question, but I don't need an ELSE do I? As in "IF it's not one of these forums use str_replace ELSE do nothing." Or, what else could be causing this not to work?
Reply With Quote
  #4  
Old 12-10-2009, 01:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I did it again - I missed the fact that you are using "postbit_display_complete", so $foruminfo isn't visible there. But I think it has the same info in $forum, so try $forum['forumid'].
Reply With Quote
  #5  
Old 12-10-2009, 01:57 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Since you are using postbit_display_complete, if $forum['forumid'] doesn't work, try $this->forum['forumid']
Reply With Quote
  #6  
Old 12-10-2009, 01:57 PM
mme42 mme42 is offline
 
Join Date: Feb 2009
Posts: 101
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep, that worked ($forum['forumid']) . Thanks so much! And thanks Lynne, I'll that in mind in case I need it.

Also, I get the impression that I should/could be using a different hook location? Or, what would be the other options postbit_display_start? And, is there any difference/effect?
Reply With Quote
  #7  
Old 12-10-2009, 02:46 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you are trying to filter the posts, then you should use a postbit_* hook location. I think if you used the start one, it may be too soon to do what you want. But you can try it and see on a test site.
Reply With Quote
Reply

Thread Tools
Display Modes

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 10:41 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.06221 seconds
  • Memory Usage 2,217KB
  • 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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • 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