![]() |
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! |
Have you tried just explode("\n", $vbulletin->options['bs_sel_list']) ? (explode returns an array so you don't need array())
|
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 ;) |
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:
|
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 :)
|
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.
|
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. |
While i have your attention guys, any idea why this doesn't seem to work, im using the hook global_complete
Quote:
Quote:
|
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.
|
:), 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 |
Can you write files via php on your server? I like to debug stuff by printing things to a file then looking at it after loading the page. Like sometimes I just throw in a
Code:
fwrite(fopen("output.txt", "w"), print_r($var, true)); ...I think that actually shouldn't work on a "live" server ( unless you put in a path to a different directory) because the web server user usually doesn't have write access. But anyway the point is that it will probably save time if you can figure out some way to see what's going on in there. |
I have dedicated so have all the access i need!, do i just use that line like that or does it need modifying to suit?
|
You'd want to replace $var with the variable you want to see (or any message you want to print out). And of course you could put a path on the file name if you need to. And if you want to print out in more than one place you can separate the fopen() from fwrite()s. (like $fp = fopen("output.txt", "w"); fwrite($fp, "Hello World"); etc)
That the kind of thing I've been using, but maybe someone else has a better idea. |
lol, now you've lost me!, firstly the line does work on a live server :), i've changed it to this (if its correct) fwrite(fopen("output.txt", "w"), print_r($bots[$i], true)); and put it ight after the redirect statement. Below is what it gave:
MOZILLA/5.0 (COMPATIBLE; BAIDUSPIDER/2.0; +HTTP://WWW.BAIDU.COM/SEARCH/SPIDER.HTML) Does that mean the plugin is working? |
At least you know that the plugin is running. I'm not sure exactly where you put the line.
The way that line is above, if you fopen with "w" it will truncate the file, so if you put it in a loop you're only seeing the last time through the loop. You can change it to "a" to append, but then it will add to the file every time you run it. (I guess the thing to do is to put one in at the beginning with "w" and if you put it in more than once, make the others "a"). Anyway, I'm sure you get the idea. You can see what code's executing and what the string values are and you should be able to figure out where it's failing (unless it's working and just not doing what you expect) :) |
Thanks very much for this help, thats really useful :)
|
Oh, I see now you said that you put the line right after the redirect (I guess its too late for me to be thinking). Do you mean after the call to banned_redirect()? Then I guess strstr() isn't matching or else it wouldn't get there.
Anyway, let us know how it goes. |
Right, i put the line like below and tried different variations:
PHP Code:
PHP Code:
Quote:
--------------- Added [DATE]1307508696[/DATE] at [TIME]1307508696[/TIME] --------------- It's 6am here and im off home to bed in a couple of hours, maybe i'll catch you later :) |
Oh right, there's no newline in that fwrite so you're just getting multiple prints coming out on the same line. And I think what I said earlier wasn't exactly correct - if you want to print out a string you don't need the print_r. And I find when printing out strings it's a little less confusing if you put some quotes in there. So you'd probably want something like:
fwrite(fopen("output.txt", "a"), "'" . stristr($user_agent,$bots[$i]) . "'\n"); |
For some reason all i get with that line is '' on many lines but no info?
|
That's actually what I'd expect to see if the stristr() was never matching anything. Maybe try this:
Code:
... |
KH99, thanks for that, could you amend the code so that it keeps appending, right now it just gives one set of results which i assume are the last set to be written.
Quote:
|
Yeah, just change the "w" to "a" in the fopen line, like:
$fp = fopen("output.txt", "a"); and maybe add an extra \n to the "Nothing Matched" message so that there'll be some separation between runs. |
Well it does seem to be working as intended
Quote:
--------------- Added [DATE]1307551911[/DATE] at [TIME]1307551911[/TIME] --------------- I guess that somehow this particular plugin has to be initiated at first call of the forum so it's in the header as im assuming the page is already loading before this gets executed so no redirect takes place??? What do you think? --------------- Added [DATE]1307555486[/DATE] at [TIME]1307555486[/TIME] --------------- I changed the fwrite line and removed the others to only show matched, and sure enough they still do, i've tried different hooks but no redirect? Quote:
Maybe it is working, ran it for around 15 minutes and BAIDU disappeared!, juts doing some more tests over 30 minutes and will report back:) --------------- Added [DATE]1307558959[/DATE] at [TIME]1307558959[/TIME] --------------- Yep, found a hook....etc that works, thanks for all your diagnostic help getting the output for each of the actions, thats something i'll always use now :) --------------- Added [DATE]1307565957[/DATE] at [TIME]1307565957[/TIME] --------------- One more question (honest!) how would i date and time stamp this entry PHP Code:
|
Quote:
To date it use the php date() function. I would try this: Code:
fwrite($fp, "Matched bots[$i]: . $bots[$i] . \nWith User Agent: . $user_agent . " . date('m-d-Y H:i:s') . " \n\n"); |
Code changed as requested :), ialready tried a version of the date function
PHP Code:
|
Quote:
|
Thanks Boofo but i'm not sure what you're referring to :), as for the date/time stamp BoP5's suggestion of cutting down my original stamp works, i can't understand why mine gave just 1900 and time 00:00?
|
All times are GMT. The time now is 03:52 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|