Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 10-18-2011, 12:07 AM
rmd1 rmd1 is offline
 
Join Date: Dec 2008
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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 !
Reply With Quote
  #2  
Old 10-18-2011, 01:18 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 10-18-2011, 01:54 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rmd1 View Post
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?
I don't think there's really any way except to read the source code. At least that's what I do. I have all the vbulletin files on my local computer set up so I can search them. I use something called NetBeans, but it's probably overkill unless you want a full development environment for other purposes. There's something called notepad++ that I think does everything you need. In any case, both are free.

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.
Reply With Quote
Благодарность от:
Lynne
  #4  
Old 10-18-2011, 10:13 AM
rmd1 rmd1 is offline
 
Join Date: Dec 2008
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 !!
Reply With Quote
  #5  
Old 10-18-2011, 07:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rmd1 View Post
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.

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

No problem, just post here (or in a new thread) when you have questions.
Reply With Quote
  #6  
Old 10-18-2011, 10:14 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
if($vbulletin->userinfo['userid'] ==  ### PUT YOUR USERID HERE ###)
{
     if(
$_REQUEST['do'] == 'postreply')
     {
           echo 
"usable hook";
     }

Try this in various hooks in newreply.php, I would guess the first hook available would do it. Then post test replies to a test thread.
Reply With Quote
  #7  
Old 10-19-2011, 10:47 AM
rmd1 rmd1 is offline
 
Join Date: Dec 2008
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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. .
Ah, ok that sounds very logic! Since for now I only want to do something if a "new post" gets created! Also thanks for the hint about how to check if a new thread gets created!
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

Quote:
Originally Posted by nerbert View Post
I'm sure $vbulletin->userinfo['userid'] is available on any file in the forum folder. Perhaps you have a typo.
It wasnt available inside postdata_save, but it is in newpost_complete thanks!
Reply With Quote
  #8  
Old 10-19-2011, 11:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rmd1 View Post
It wasnt available inside postdata_save, but it is in newpost_complete thanks!
Well, to be fair what nerbert said is correct - you should have been able to use $vbulletin at any of the newreply_ hooks.
Reply With Quote
  #9  
Old 10-19-2011, 11:38 AM
rmd1 rmd1 is offline
 
Join Date: Dec 2008
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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')");
}
UPDATE 2:
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.
Reply With Quote
  #10  
Old 10-19-2011, 10:36 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

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 04:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06631 seconds
  • Memory Usage 2,279KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (1)bbcode_php
  • (6)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
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete