vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Cannot access lastposterid from within plugin (https://vborg.vbsupport.ru/showthread.php?t=280711)

nambisolo 03-27-2012 07:36 AM

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::preRegister('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

kh99 03-27-2012 10:53 AM

It looks like you should be able to use $lastpostinfo['lastposterid'] . Are you sure that's the problem?

nambisolo 03-27-2012 12:19 PM

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

kh99 03-27-2012 12:57 PM

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
}


nambisolo 03-28-2012 07:48 AM

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?

kh99 03-28-2012 11:34 AM

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));


nambisolo 03-28-2012 02:22 PM

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?

kh99 03-28-2012 02:30 PM

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.

nambisolo 03-28-2012 03:51 PM

I've double checked and it's definately not in the list.

kh99 03-28-2012 03:53 PM

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).


All times are GMT. The time now is 10:25 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.01117 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete