Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2012, 07:36 AM
nambisolo nambisolo is offline
 
Join Date: Feb 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Cannot access lastposterid from within plugin

Hello

I'm attempting to create a plugin that retrieves a user profile field to display on the forum home page. The code is as follows.

$lastpostuserid = $lastpostinfo['lastposterid'];

/*write custom query here to get display name*/

$lastposter = $db->query_first("SELECT field6 FROM " . TABLE_PREFIX . "userfield WHERE userid = '$lastpostuserid'");

$lastposterhome_var = $lastposter['field6'];*/

/* register variable in the 'memberaction_dropdown' template */

vB_Template:reRegister('memberaction_dropdown',a rray('lastposterhome_var'=> $lastposterhome_var));


The hook I'm using is forumbit_display. The problem is that the value of last $lastpostinfo['lastposterid'] is not available and subsequently I'm not getting a result. The value is available though in the template containing memberaction_dropdown (forumhome_lastpostby). The plugin does work if I assign arbitrary text to my variable just to test.

I do have a very similar plugin working on the forum display page which is using the threadbit_display hook and $thread['lastposterid']

I'm quite new to this so any advice would be most welcome.

Thanks.

Mike
Reply With Quote
  #2  
Old 03-27-2012, 10:53 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It looks like you should be able to use $lastpostinfo['lastposterid'] . Are you sure that's the problem?
Reply With Quote
  #3  
Old 03-27-2012, 12:19 PM
nambisolo nambisolo is offline
 
Join Date: Feb 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi

I've just run a check by trying to return the $lastpostinfo['lastposterid'] value directly to the memberaction_dropdown e.g.

$lastposterhome_var = $lastpostuserid;

I have discovered a value is being returned, as you said it should, but there's an anomalie. The lastposterid is in fact the id of the poster of the last thread in the forum above (this is the forum home page where each forum is listed).

The database query was failing because the first forum on the page had no post.

Any ideas why the ids are out of sync like this?

Thanks.

Mike
Reply With Quote
  #4  
Old 03-27-2012, 12:57 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, the problem might be that $lastpostinfo is an empty array if there is no last thread (a forum is private or doesn't allow posts). So maybe if you do something like:

Code:
if (!empty($lastpostinfo))
{
  // your code here
}
Reply With Quote
  #5  
Old 03-28-2012, 07:48 AM
nambisolo nambisolo is offline
 
Join Date: Feb 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, the first forum in the list had no threads. I added your suggested test which did not catch an empty array. I added a thread to the forum which had no affect either. I have also removed the first forum from the list (display order set to zero) but the issue is then transferred to the forum that moves to the top of the list. It appears the first forum in the list has no access to the $lastpostinfo array. Any ideas?
Reply With Quote
  #6  
Old 03-28-2012, 11:34 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The problem is that the memberaction_dropdown is created before the forumbit_display hook is called (sorry, I should have realized that yesterday). I think you can use the memberaction_dropdown hook, I'm trying to work that out now.

Edit: OK, this seems to work (using hook memberaction_dropdown):

Code:
$lastpostuserid = $memberinfo['userid'];

/*write custom query here to get display name*/

global $db;
$lastposter = $db->query_first("SELECT field6 FROM " . TABLE_PREFIX . "userfield WHERE userid = '$lastpostuserid'");

$lastposterhome_var = $lastposter['field6'];

/* register variable in the 'memberaction_dropdown' template */
vB_Template::preRegister('memberaction_dropdown',array('lastposterhome_var'=> $lastposterhome_var));
Reply With Quote
  #7  
Old 03-28-2012, 02:22 PM
nambisolo nambisolo is offline
 
Join Date: Feb 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks but I don't see the hook memberaction_dropdown in the dropdown list of hook locations. Isn't this the name of the template?
Reply With Quote
  #8  
Old 03-28-2012, 02:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's also a hook location. I had trouble finding it at first too, because it comes before all the "member_" hooks so it kind of looks like it's out of order. It's just after the "mail_" hooks.
Reply With Quote
  #9  
Old 03-28-2012, 03:51 PM
nambisolo nambisolo is offline
 
Join Date: Feb 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've double checked and it's definately not in the list.
Reply With Quote
  #10  
Old 03-28-2012, 03:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What version are you running? Maybe it was added recently (although I thought I checked a previous version to make sure it was there).

Edit: I checked again and it looks like it's in vb4.1.3 (which is the earliest vb4 version I have the source for).
Reply With Quote
Reply


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 01:40 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
  • Page Generation 0.04311 seconds
  • Memory Usage 2,253KB
  • Queries Executed 11 (?)
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)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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete