PDA

View Full Version : newbie with lots of newbie questions!


White_Snake
01-26-2010, 10:44 PM
hello!

i been studing some basic php stuff and now im open to take the challenge to learn how does vbulletin works, so far i been checking random php files on vbulletin base files and some plugins from modifications, and i have the following questions which i havent been able to solve by myself:


what does this->registry->options[] means/contains? i know this-> its part of classes on php, but, im not sure how does the whole thing works on vbulletin
how does vbulletin->GPC and vbulletin->input->clean_array_gpc works? its the same as on vbulletin 3 documentation? (https://vborg.vbsupport.ru/showthread.php?t=119372)
i need to use "Send PM" automatically functions, i have found a vbulletin 3 article on this (https://vborg.vbsupport.ru/showthread.php?t=82786) but, i suppose its obsolete on vb4, i have tried to find how to do this by examinating private.php on vb4 and i havent had any luck, any suggestions?
is the $db-> fuction list is the same as vb3?


thanks in advance for your time and replies :)

Lynne
01-26-2010, 11:58 PM
- Hmmm, I'm not a php guru, but there are some functions that require you to use $this->registry->posts or $this->registry->options instead of just $posts or $vbulletin->options. The best thing to figure out which to use is to locate the hook you are wanting to use in the php code and see the syntax used right there.

- information regarding the input cleaner is still valid for vB4

- I don't know anything about the send PM article, sorry

- $db should all be the same. If you are writing code for the CMS however, the syntax will be a little different with a "vB::" in front of it.

White_Snake
01-27-2010, 02:41 AM
- Hmmm, I'm not a php guru, but there are some functions that require you to use $this->registry->posts or $this->registry->options instead of just $posts or $vbulletin->options. The best thing to figure out which to use is to locate the hook you are wanting to use in the php code and see the syntax used right there.

- information regarding the input cleaner is still valid for vB4

- I don't know anything about the send PM article, sorry

- $db should all be the same. If you are writing code for the CMS however, the syntax will be a little different with a "vB::" in front of it.

hello Lynne!

thanks a lot for your answers :) now i hope someone else can help me with the PM bit, in the meanwhile ill check the rest of the stuff you commented, thanks again!

BBR-APBT
01-27-2010, 03:05 AM
Have you tried using that code? It seems as it should still work. If you have any specific questions regarding a error with that code you have posted feel to post with a specific question.

I can not start to help you when you have not even tried to use that code thus have no real question as of yet.

White_Snake
01-27-2010, 03:14 AM
Have you tried using that code? It seems as it should still work. If you have any specific questions regarding a error with that code you have posted feel to post with a specific question.

I can not start to help you when you have not even tried to use that code thus have no real question as of yet.

thanks for your reply!

i just havent tried it because im not sure which part is the correct one but i suppose its time to start poking around, vbulletin its a *HUGE* script and its hard for a php green rookie like me to find the right direction, but ill start checking files and see what i can come up with thanks!

BBR-APBT
01-27-2010, 03:22 AM
You would use plugins. If you want it to send a welcome message you would use a hook like register_addmember_complete. Then when the user finishes registering it would call up the code you just put in the plugin. So if you put that code for the private message in there it would send the message when they finished.

You should set up a test board so that it is on a password protected directory. This way you can do all your testing there and not worry about breaking your live site.

White_Snake
01-27-2010, 07:14 PM
You would use plugins. If you want it to send a welcome message you would use a hook like register_addmember_complete. Then when the user finishes registering it would call up the code you just put in the plugin. So if you put that code for the private message in there it would send the message when they finished.

You should set up a test board so that it is on a password protected directory. This way you can do all your testing there and not worry about breaking your live site.


im running a test board already, i have done some other modifications, what exactly i want to do is to make a modification where the user receives a notification once he makes 50 posts, i have already the full code working in the right hook which is postbit_display_complete but, the only element im missing here is the function or class vbulletin uses to send a PM which i can run everytime a user hits the 50 post mark :)

BBR-APBT
01-27-2010, 07:16 PM
im running a test board already, i have done some other modifications, what exactly i want to do is to make a modification where the user receives a notification once he makes 50 posts, i have already the full code working in the right hook which is postbit_display_complete but, the only element im missing here is the function or class vbulletin uses to send a PM which i can run everytime a user hits the 50 post mark :)
That is what the code you linked to. That is what you need.

White_Snake
01-27-2010, 08:17 PM
That is what the code you linked to. That is what you need.
i checked both classes on vb3 and vb4 and they are identical, im gonna play around with it for a while, thanks!

--------------- Added 1264633171 at 1264633171 ---------------

okay i tried it out and it works nicely except for one issue, the constant TIMENOW on vb3 is not working anymore on vb4 so i need to find its equivalent

--------------- Added 1264640546 at 1264640546 ---------------

nevermind the timenow issue, it was a mistake on my side, the issue im having is that the internal vbulletin arrays arent working in the plugin, this is my code:


$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', 1);
$pmdm->set('fromusername', Admin);
$pmdm->set('title', 'congratulations');
$pmdm->set('message', "congratulations $vbulletin->userinfo['username'] you have made your 50th post, we're all so prod of you keep on posting");
$pmdm->set_recipients('$vbulletin->userinfo['username']', $permissions);
$pmdm->set('dateline', TIMENOW);

$pmdm->save();


if i directly write a username on the set_recipients instead of $vbulletin->userinfo['username'] the PM works perfectly, but if i use it, the PM is not sent, as well, if i use $vbulletin->userinfo['username'] in the message, i get: Array['username'] in the output instead of the nick of the user receiving the PM

thanks again for any help :)

BBR-APBT
01-27-2010, 11:45 PM
This line

$pmdm->set_recipients('$vbulletin->userinfo['username']', $permissions);


would be

$pmdm->set_recipients($vbulletin->userinfo['username'], $permissions);

White_Snake
01-28-2010, 01:43 AM
This line

$pmdm->set_recipients('$vbulletin->userinfo['username']', $permissions);


would be

$pmdm->set_recipients($vbulletin->userinfo['username'], $permissions);


that did the trick, any suggestion on parsing the code inside the pm message area?

BBR-APBT
01-28-2010, 02:36 AM
that did the trick, any suggestion on parsing the code inside the pm message area?

What do you mean parsing the code in the message area?

You mean like the user name?

White_Snake
01-28-2010, 03:57 AM
What do you mean parsing the code in the message area?

You mean like the user name?

my apologies, i should have been more clear with my question
this is what i mean:

$pmdm->set('message', "congratulations $vbulletin->userinfo['username'] you have made your 50th post, we're all so prod of you keep on posting");

that line gives me the following output:

congratulations Array['username'] you have made your 50th post, we're all so prod of you keep on posting

BBR-APBT
01-28-2010, 04:27 AM
my apologies, i should have been more clear with my question
this is what i mean:

$pmdm->set('message', "congratulations $vbulletin->userinfo['username'] you have made your 50th post, we're all so prod of you keep on posting");

that line gives me the following output:

congratulations Array['username'] you have made your 50th post, we're all so prod of you keep on posting


$50postusername = $vbulletin->userinfo['username']
$pmdm->set('message', "congratulations $50postusername you have made your 50th post, we're all so prod of you keep on posting");



it may even be

$50postusername = $vbulletin->userinfo['username']
$pmdm->set('message', "congratulations " . $50postusername . " you have made your 50th post, we're all so prod of you keep on posting");

White_Snake
01-28-2010, 04:22 PM
$50postusername = $vbulletin->userinfo['username']
$pmdm->set('message', "congratulations $50postusername you have made your 50th post, we're all so prod of you keep on posting");



it may even be

$50postusername = $vbulletin->userinfo['username']
$pmdm->set('message', "congratulations " . $50postusername . " you have made your 50th post, we're all so prod of you keep on posting");


thank you!

but apparently using the line " $50postusername = $vbulletin->userinfo['username']; " makes the script to stop working, and i have tried with both possibilities you have posted in here, the one with the joined strings and the one with the direct variable this is my full code:


if ($foruminfo['countposts'] AND $vbulletin->userinfo['posts'] + 1 == 50) {
$50postusername = $vbulletin->userinfo['username'];
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', 1);
$pmdm->set('fromusername', Administrator);
$pmdm->set('title', 'Congratulations');
$pmdm->set('message', "congratulations $50postusername you have made your 50th post, we're all so prod of you keep on posting");
$pmdm->set_recipients($vbulletin->userinfo['username'], $permissions);
$pmdm->set('dateline', TIMENOW);

$pmdm->pre_save();

// process errors if there are any
$errors = array_merge($errors, $pmdm->errors);

if (!empty($errors))
{
$errorlist = '';
foreach ($pmdm->errors AS $index => $error)
{
$errorlist .= "<li>$error</li>";
}
}
else
{
// everything's good!
$pmdm->save();
}
}

im using the $pmdm->error() function too and its not giving me any error, its almost as if the script was dying because of the extra variable im setting in before reaching the end

White_Snake
01-29-2010, 07:26 PM
i tried my code in a separate .php file where i called global.php, then i pasted this code (without the IF statement) and it worked pefectly, the PM was sent correctly without any issue, by some odd reason, just by using any extra variable in the plugin, the code doesnt works at all such as $50postusername, id appreciate if someone can help me with this!

Lynne
01-29-2010, 07:42 PM
Try setting the $message first... ie:


$message = "congratulations......";
$pmdm->set('message', $message);

White_Snake
01-29-2010, 07:53 PM
Try setting the $message first... ie:


$message = "congratulations......";
$pmdm->set('message', $message);


same outcome, the script doesnt runs :( but thanks for the idea :)

Lynne
01-29-2010, 10:25 PM
Let's see exactly what you did. It could be you wrote it incorrectly. And did you ever specific the hook location? You should tell us that information also.

White_Snake
01-29-2010, 10:42 PM
okay, here goes the full plugin, with some extra stuff i added :)

hook location: newpost_complete


if ($vbulletin->userinfo['referrerid'] > 0 AND $foruminfo['countposts'] AND $vbulletin->userinfo['posts'] + 1 == 50){
$ref_raw = $db->query_read("SELECT username FROM user WHERE userid = ".$vbulletin->userinfo['referrerid']);
$ref_nam = $db->fetch_array($ref_raw);

$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', 1);
$pmdm->set('fromusername', Administrator);
$pmdm->set('title', 'Congratulations');
$pmdm->set('message', "congratulations! you have referred the user ".$vbulletin->userinfo['username']." and he has made 50 posts");
$pmdm->set_recipients($ref_nam['username'], $permissions);
$pmdm->set('dateline', TIMENOW);

$pmdm->pre_save();

// process errors if there are any
$errors = @array_merge($errors, $pmdm->errors);

if (!empty($errors))
{
$errorlist = '';
foreach ($pmdm->errors AS $index => $error)
{
$errorlist .= "<li>$error</li>";
}
}
else
{
// everything's good!
$pmdm->save();
}
}


the weird part about this code is that i have tried it on a separate php file under the same directory as the forums that calls includes the file global.php and the whole thing works fine in that separated file, as well i tried to see if this hook had any conflict with others, so i disabled everything and still the problem persist

thanks!

Lynne
01-29-2010, 11:44 PM
Are you getting errors? Anything in the error_logs?

What was the code you tried when you set $message to be something first (like in my suggestion above)? (If you read that article, when I user wanted to use a phrase in the message, they had to set it beforehand like I am suggesting.)

White_Snake
01-29-2010, 11:51 PM
Are you getting errors? Anything in the error_logs?

What was the code you tried when you set $message to be something first (like in my suggestion above)? (If you read that article, when I user wanted to use a phrase in the message, they had to set it beforehand like I am suggesting.)

okay, i did set the message inside a variable, not in the vbullein phrase manager and, where can i check the error_logs part? thank you :)

Lynne
01-30-2010, 02:55 AM
If you don't know where your error_logs are, you will have to ask your host. Usually they are in a /logs directory, but, like I said, just ask your host.

White_Snake
01-31-2010, 02:17 PM
If you don't know where your error_logs are, you will have to ask your host. Usually they are in a /logs directory, but, like I said, just ask your host.

nothing there, but, i have found something interesting, if i execute the code in another hook, such as memberdisplay (hook for displaying the memeber profile) it works perfectly, so i suppose the problem is the hook itself

Lynne
01-31-2010, 02:58 PM
nothing there, but, i have found something interesting, if i execute the code in another hook, such as memberdisplay (hook for displaying the memeber profile) it works perfectly, so i suppose the problem is the hook itself
Yeah, that could be it. plugins can be picky about where you execute them. :)

White_Snake
01-31-2010, 05:22 PM
Yeah, that could be it. plugins can be picky about where you execute them. :)

okay i moved it to newpost_process and its working pefectly but i wonder if the newpost_complete thing its a bug or something like that

Lynne
01-31-2010, 05:36 PM
I don't think so. If you look at the code, you'll see $errors is processed right after newpost_process. newpost_complete is clear down the page after that, so using that hook_location wouldn't work for at least that.

White_Snake
01-31-2010, 11:30 PM
I don't think so. If you look at the code, you'll see $errors is processed right after newpost_process. newpost_complete is clear down the page after that, so using that hook_location wouldn't work for at least that.

okay then, i suppose next time im going to double and triple check the code around the hooks i plan to use, thanks a lot!