Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2011, 11:19 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with plugin array and option settings

Firstly sorry if the title is misleading, i am trying to create a plugin that should check for each instance in an array, the array should look like array('FOO', 'BAR', 'FOOBAR');, however i am trying to read a multi line textarea in to the array like this: array($vbulletin->options['bs_sel_list']); but it only works if there is only one item in the textarea, if i put two or more, each on its own line or on the same line it doesn't work, i then tried this array(explode("\r\n", $vbulletin->options['bs_sel_list'])); but it doesn't make any difference!

How can i read the $vbulletin->options['bs_sel_list'] in to the array to get it to look like array('FOO', 'BAR', 'FOOBAR');

Any help or advice is appreciated!
Reply With Quote
  #2  
Old 06-06-2011, 11:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried just explode("\n", $vbulletin->options['bs_sel_list']) ? (explode returns an array so you don't need array())
Reply With Quote
  #3  
Old 06-06-2011, 11:52 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, there was a little change with that, my list in bs_sel_list looks like this example
(foo)123
(bar + 1ht) there
foobar(foo) + there
With your suggestion it only finds foobar(foo) + there the last one in the array

Any further suggestions?

Thanks for your help by the way

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

Actually i think your suggestion does work!, i think i had my for each check the wrong way round...a couple more tests and i'll confirm it

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

Yep it works!, thanks for the suggestion too
Reply With Quote
  #4  
Old 06-08-2011, 12:34 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I wonder if ti varies by server? Because all my mods that use multi-line text boxes I separate each line into array using this exact code:
PHP Code:
 $up_data explode ("\r\n"$vbulletin->options['bop5up_data']); 
And it works all the time.
Reply With Quote
  #5  
Old 06-08-2011, 01:02 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BoP5, that is correct and thats what KH99 was getting at, if you check my example i state its as Array(explode.... which was my downfall, removing Array( allowed it to work, the other issue was my fault because im still green at this
Reply With Quote
  #6  
Old 06-08-2011, 01:13 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry I thought the difference was "\n" as opposed to "\r\n" - I was just saying i know \r\n works. Never tried just \n. I hadn't even noticed the array() call.
Reply With Quote
  #7  
Old 06-08-2011, 02:16 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Joe's right. I was suggesting just "\n" but it looks like there is "\r\n" between each line, so if you only use a "\n" it works but you end up with a "\r" at the end of each string. I guess if you later trim() the strings either would work, but Joe's way is correct.

In any case, I'm glad you got it working.
Reply With Quote
  #8  
Old 06-08-2011, 02:35 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

While i have your attention guys, any idea why this doesn't seem to work, im using the hook global_complete
Quote:
function banned_redirect($to, $code = '307 Temporary Redirect') {
header("HTTP/1.1 ".$code);
header("Location: http://$to");
exit();
}
if ($vbulletin->options['bsactive'])
{
$user_agent = strtolower(getenv('HTTP_USER_AGENT'));
$bots = explode("\r\n", $vbulletin->options['bs_sel_list']);
$n = sizeof($bots);
for ($i=0;$i<$n;$i++) {
if (strstr($user_agent,$bots[$i])) banned_redirect('www.google.com.cn/search?hl=zh-CN&q=crystal+light+centrum&meta=');
}
}
For some reason it's not or doesn't seem to be redirecting the spiders, i use http://www.botsvsbrowsers.com/ to check if the user agent is getting redirected as it should, right now i'm trying one for yandex and one for baidu here's that agent:
Quote:
Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
Reply With Quote
  #9  
Old 06-08-2011, 02:42 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...well, the only thing I can think of is, were you always using the "\r\n" in the explode? If you were using "\n" it could be that the extra "\r" that I mentioned above was messing things up for you.
Reply With Quote
  #10  
Old 06-08-2011, 02:47 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

, always used the \r\n but either way it doesn't seem to work in the plugin, i have tried changing the execution order but no go, and im pretty sure the syntax is right?

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

infact if i have the execution order earlier than another plugin using the same hook that checks user agents the plugin doesn't work, so it kind of looks like its stopping the user agent from getting through any further but it's not redirecting????

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

I have also substituted strtolower($_SERVER['HTTP_USER_AGENT']); for strtoupper($_SERVER['HTTP_USER_AGENT']); but no change
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 10:19 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.04330 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
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete