vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with plugin array and option settings (https://vborg.vbsupport.ru/showthread.php?t=264820)

Simon Lloyd 06-06-2011 11:19 PM

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!

kh99 06-06-2011 11:43 PM

Have you tried just explode("\n", $vbulletin->options['bs_sel_list']) ? (explode returns an array so you don't need array())

Simon Lloyd 06-06-2011 11:52 PM

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 ;)

BirdOPrey5 06-08-2011 12:34 AM

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.

Simon Lloyd 06-08-2011 01:02 AM

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 :)

BirdOPrey5 06-08-2011 01:13 AM

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.

kh99 06-08-2011 02:16 AM

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.

Simon Lloyd 06-08-2011 02:35 AM

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)

kh99 06-08-2011 02:42 AM

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.

Simon Lloyd 06-08-2011 02:47 AM

:), 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


All times are GMT. The time now is 12:30 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.01111 seconds
  • Memory Usage 1,740KB
  • 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
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)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