The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
which variables in which hook?
hey!
since I couldnt find an mod that does what I want, and I cant get another coder on boat right now, I decided to code a plugin myself... I started by finding out which hooks I need to work with, but already came across a problem.. where/how can I find out, which variables are already set, inside hook XYZ? f.e. right now I need to run a query when a user writes a new post. so created a plugin which kicks with the usage of hook "postdata_start". now I want to save the "userid" of the posting user, but all vars I tried out are empty. $userinfo['userid'] $this->userinfo['userid'] $vbulletin->userinfo['userid'] Non of them work. Can somebody point me in the right direction? Maybe not just to get the userid, but how to find out which vars are available at any hook. Thanks in Advance ! |
#2
|
|||
|
|||
I think you're in the wrong file. For anything to do with new posts you would need to look at the hook locations "newreply_ ..........".
$vbulletin->userinfo['userid'] should always give the userid in any file that produces a page. |
#3
|
|||
|
|||
Quote:
Anyway, you could answer your question by searching the files for postdata_start, and you'd find this, in includes/class_dm_threapost.php: Code:
function vB_DataManager_Post(&$registry, $errtype = ERRTYPE_STANDARD) { parent::vB_DataManager_ThreadPost($registry, $errtype); ($hook = vBulletinHook::fetch_hook('postdata_start')) ? eval($hook) : false; } So the problem with trying to use $vbulletin->userdata['userid'] is that $vbulletin isn't in scope. You could add a "global $vbulletin;" line to your plugin code, or you could use the $registry parameter instead since that's probably the same thing. Whether or not that's the hook you want to use is another question (as nerbert mentioned above). You can work it "backwards", i.e. look at the code for the vb page you're insterested in, then find the fetch_hook() calls that are in locations that are useful to you. I hope that helps. As for your current project, you didn't give a lot of details, and maybe postdata_start will work for you, but you could also look at function build_new_post() in includes/functions_newpost.php. Hook location newpost_process is good for a lot of purposes. |
Благодарность от: | ||
Lynne |
#4
|
|||
|
|||
Hey!
First of all thanks for your replys, I really appreciate it Now back to topic! I code PHP since a couple of years (beginner / average skills), but never found time to learn vbulletin. I kinda thought this is going to be easy... Said to myself "Just find the hook which gets called when a post gets saved, and insert your code there". So I first thought I gotta pick the "newreply_" hooks. I placed a mysql_query via the write function into my plugin code to see if the hook gets called or not, when creating a new post, but somehow the query never got made! No matter if I choosed "newreply_" or "newpost_".... I googled and found somebody who tried to achieve a similar thing and they told him to use "postdata_start". I tried it out, and the query got made So, did I use the wrong "newreply_" hook? I thought I tried all of them, but the query somehow never got made... Trying "newreply_start" again now... EDIT: Nope, the query didnt got processed! changing to postdata_start again for now. About the variables... Ok, I understood that. Seems I really gotta dig into the sourcecode :/ no pain, no gain! Btw: I am trying to build something like a "activities" plugin, which will make a users profil similar to facebook profile pages. for this i need to save every post / thread / blog post / avatar change etc. in the first place, then go ahead and work with it on the member profile page got the whole plugin theory on paper, now I "just" need to code it! And since I want to learn "vbulletin", its a good combination... So if you want to help me with pointing me in the right directions to fasten up the learn process, I would really appreciate it !! |
#5
|
|||
|
|||
Quote:
It could be easy to create your plugin. If you just want to know which hook to use you can explain what you're doing and we'll try to tell you which hook. I only gave you the complicated answer because you asked how to know which variables you can use. Anyway, I think the thing about postdata_start is that you maybe won't be sure that the post is actually saved because it's possible it could fail later. Also, it's possible that that class is used whenever any changes are made to a post, not just when a new one is created. I think maybe newpost_complete would be better. Also, in plugin code using that hook, you can check for $type == 'thread', if it's true it's a new thread, otherwise it's a reply. (See build_new_post() in includes/functions_newpost.php). BTW, I don't know why the newreply_ hooks didn't do anything for you, but I think it would be harder to use one of those hooks because the newreply script is used for a number of functions, and saving the post is only one of them. Quote:
No problem, just post here (or in a new thread) when you have questions. |
#6
|
|||
|
|||
I'm sure $vbulletin->userinfo['userid'] is available on any file in the forum folder. Perhaps you have a typo.
I would try this: PHP Code:
|
#7
|
|||
|
|||
Quote:
I just switched to the hook "newpost_complete" and it works, and I dont need to set the $vbulletin var to global since it already happened in the main script, thanks for the hint! Now I just need to find out which vars are available at this point, so I can save it to my db table Trying it out, and I am going to explain what I want to code below: Im trying to build a activities plugin, which tracks the following actions and saves them into db. - thread creation - posting a new reply - changing avatar - posting a message on somebodys wall - joined a group - created a picture album - uploaded pictures to an album - created a new blog entry After achieving this, I want to create the acp interface for it, where I can define which usergroups are able to use it + set default settings. Then I want to create the usercp for it, where users can define if they want to use it at all + which things they want to get tracked. And when this is done, I want to create a new tab on the member profile page, which grabs the data my plugin collects and makes it look pretty (of course there will need to be some filtering I guess... but Ill handle that when the time is right) I guess when im done with this, I became a good vb coder haha Of course you can have the plugin if I manage to get it working, since your helping me here EDIT: New post + News thread is working... now im trying to complete the rest! going to ask questions when I run into problems It wasnt available inside postdata_save, but it is in newpost_complete thanks! |
#8
|
|||
|
|||
Well, to be fair what nerbert said is correct - you should have been able to use $vbulletin at any of the newreply_ hooks.
|
#9
|
|||
|
|||
I could swear the output was empty, but maybe I just had a typo or something in my code
UPDATE: Ok, so now I want to track if somebody posts a visitormessage. I created a plugin with the hook "visitormessagedata_postsave" and "visitor_message_post_complete", but none of them runs my query :/ Digging into the files right now "visitormessage.php" & class_dm_visitormessage.php... Plugin Code Code:
if($vbulletin->userinfo['userid'] == 2){ $vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "activities VALUES( NULL, '" . time() . "', '" . $vbulletin->userinfo['userid'] . "', 'NEW VISITOR MESSAGE')"); } ok it works now... what I forgot was that my forum setup uses the ajax version, and so I had to use the "visitor_message_post_ajax" hook" --------------- Added [DATE]1319040016[/DATE] at [TIME]1319040016[/TIME] --------------- Alright, got these plugins running now: - thread creation - posting a new reply - posting a message on somebodys wall - uploaded pictures to an album - joined a group and these are missing, since until now I couldnt figure out which hook would be best/works at all - changing avatar - created a picture album - created a new blog entry the working ones need fine tuning of course, right now they just react to the associated actions and run my test query. after I got all plugins doing the query, I will do the fine tuning and will code up the real querys. so if you guys want to help me, you can point me into the direction for the 3 missing plugin hooks. thing is, the "blog entry" is a bit difficult, because my main forum (vb 3.x) has no blog and afaik vb4 has a blog as default? if this is right, the blog option will be not available in the vb 3.x version of my addon. |
#10
|
|||
|
|||
Sorry, that's one small problem with using the same thread. The auto-merge makes it so that it's not obvious when you post an update.
Anyway, I only know the avatar one - I think you could use profile_updateavatar_complete. Look in file profile.php around line 3058. I've found out that if a product contains a plugin that uses a hook that doesn't exist, it will install OK but that plugin won't ever run. So if you want to include a blog plugin with a hook that is only in vb4, it just won't be used in vb3. It's also possible to check the vb version number in your code if you find a need for that. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|