PDA

View Full Version : Need to call up custom field in "lastpostby" template


bzcomputers
12-18-2012, 05:45 PM
I need to be able to call up a custom field - "field12" in the "forumhome_lastpostby" template.

I've tried numerous plugins and hooks (including forumbit_display) but still can't get the information to display in the "lastpostby" section.


I was able to get it to work fine on forumdisplay using using hook "forumdisplay_query" and this plugin code:

$hook_query_fields .= ', userfield.field12 ';
$hook_query_joins .= ' LEFT JOIN ' . 'userfield AS userfield ON (userfield.userid = thread.postuserid) ';

Lynne
12-18-2012, 06:27 PM
You would need to run a query to get that information since all of the lastpostby information is cached and it doesn't include field12.

bzcomputers
12-18-2012, 09:40 PM
I knew there had to be something different. Thanks for the heads up on the caching and need for a query.

I'm still pretty novice at this so if someone has some step by step on how to do this or a place I can go to read up on it it would be appreciated. Thanks.

kh99
12-18-2012, 10:15 PM
I started thinking about this when you first posted but Lynne beat me to answering. Anyway, I think this works, using hook location cache_ordered_forums:

if (THIS_SCRIPT == 'index')
{
$tachyjoin .= " LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (forum.lastposterid = userfield.userid) ";
$counter_select .= ", userfield.field12";
}

and then use {vb:raw lastpostinfo.field12} in the template.

But that only works on the home page. Getting it to work in the threadbit template on the forumdisplay page is a different issue.

bzcomputers
12-18-2012, 11:39 PM
Couldn't get that to work.

kh99
12-18-2012, 11:48 PM
Hmm...I actually tried it and it seems to work. But maybe I'm doing something differently. But like I mentioned, it only works for the home page.

I just now noticed that you were doing something really similar in your first post, maybe something like that would work for the forumdisplay pages.

bzcomputers
12-19-2012, 12:13 AM
I think I figured out the issue.

I had mod "Vsa Last Post Info Enhancements" installed. Which already has a join. When disabled your code does work.

Can you look at his plugin code and see if it can be modified to include this. Thanks.

if ($vbulletin->options['vsalpienh_enable_global'] AND ($forum[vsa_lpienhancements]>1) AND ($forum[threadcount]!=0))
{
$vsa_lpi_forumperms = $vbulletin->userinfo['forumpermissions'][$forumid];
if (($vsa_lpi_forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'] OR can_moderate()) AND (($vsa_lpi_forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) OR can_moderate()) AND (($forum['options'] & $vbulletin->bf_misc_forumoptions['active']) OR can_moderate()))
{
if ($vbulletin->options['apboupc_global_enable'])
{
$vsa_lpi_vsaapbouc_excgroups = explode(",",$vbulletin->options['apboupc_forum_excludedgroups']);
}
$vsa_lpi_childperms = array($forum[childlist]);
$vsalpi_exclfids = '';
foreach($vbulletin->forumcache AS $vsalpi_child)
{
$vsa_lpi_childperms[$vsalpi_child["forumid"]] = fetch_permissions($vsalpi_child['forumid']);
if ((!($vsa_lpi_childperms[$vsalpi_child["forumid"]] & $vbulletin->bf_ugp_forumpermissions['canview'])) OR (!($vsalpi_child['options'] & $vbulletin->bf_misc_forumoptions['active']) AND !$vbulletin->options['showprivateforums'] AND !can_moderate()) OR ($vbulletin->options['apboupc_global_enable'] AND ($vsalpi_child['accessf_nb']>$vbulletin->userinfo['posts']) AND !is_member_of($vbulletin->userinfo, $vsa_lpi_vsaapbouc_excgroups)))
{
$vsalpi_exclfids .= ','.$vsalpi_child['forumid'];
}
}
unset($vsalpi_child);

if (($vbulletin->options['vsalpienh_excl_forums']!='') AND !can_moderate())
{
$vsalpi_exclfids .= ','.$vbulletin->options['vsalpienh_excl_forums'];
}
$vsalpi_exclfids = substr($vsalpi_exclfids, 1);
if ($vsalpi_exclfids!='')
{
$vsalpi_exclforums = "AND forumid NOT IN($vsalpi_exclfids)";
}

$vsalpi_results = $forum[vsa_lpienhancements];
$GLOBALS['vbulletin']->db->hide_errors();
$vsalpi_getinfo = $GLOBALS['vbulletin']->db->query_read("
SELECT thread.threadid, thread.title, thread.lastpost, thread.lastpostid, thread.lastposter, thread.lastposterid, thread.iconid, thread.prefixid, user.userid, user.username
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.lastposterid)
WHERE threadid>0 AND visible=1 AND open!=10 AND forumid IN($forum[childlist]) $vsalpi_exclforums
ORDER BY lastpost DESC
LIMIT 0, $vsalpi_results
");
$GLOBALS['vbulletin']->db->show_errors();
$vsalpi_restot = $GLOBALS['vbulletin']->db->num_rows($vsalpi_getinfo);

$vsalpi_lastpost = '';
while ($lastpostinfo = $GLOBALS['vbulletin']->db->fetch_array($vsalpi_getinfo))
{
$icon = fetch_iconinfo($lastpostinfo['iconid']);
if ($lastpostinfo['prefixid'] AND $vbulletin->options['vsalpienh_enable_prefix'])
{
$vsalpi_tprefix = ($vbulletin->options['vsalpienh_enable_prefix'] == 2 ?
$vbphrase["prefix_$lastpostinfo[prefixid]_title_rich"] :
htmlspecialchars_uni($vbphrase["prefix_$lastpostinfo[prefixid]_title_plain"])
);
}
else
{
$vsalpi_tprefix = '';
}
$lastpostinfo[lastthreadid] = $lastpostinfo[threadid];
$lastpostinfo[lastthread] = strip_tags($lastpostinfo[title]);

$vsalpi_statusicon = '';
if ($vbulletin->options['vsalpienh_enable_statusicons'])
{
if ($lastpostinfo[lastpost]>$vbulletin->userinfo['lastvisit'])
{
$vsalpi_statusicon = '<img class="inlineimg" src="'.vB_Template_Runtime::fetchStyleVar('imgdir_statu sicon').'/post_new.png" alt="'.$vbphrase['new'].'" border="0" width="8" height="8" /> ';
}
else
{
$vsalpi_statusicon = '<img class="inlineimg" src="'.vB_Template_Runtime::fetchStyleVar('imgdir_statu sicon').'/post_old.png" alt="'.$vbphrase['old'].'" border="0" width="8" height="8" /> ';
}
}
$vsalpi_memberaction_dropdown = construct_memberaction_dropdown(fetch_userinfo($la stpostinfo['userid']));
$lastpostinfo_unreadpost = fetch_seo_url('thread', $lastpostinfo, array('goto' => 'newpost'));
$lastpostinfo_lastpost = fetch_seo_url('thread', $lastpostinfo, array('p' => $lastpostinfo['lastpostid'])) . '#post' . $lastpostinfo['lastpostid'];
$lastpostinfo['trimthread'] = fetch_trimmed_title(fetch_censored_text($lastposti nfo['lastthread']));
$lastpostinfo['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $lastpostinfo['lastpost'], 1);
$lastpostinfo['lastposttime'] = vbdate($vbulletin->options['timeformat'], $lastpostinfo['lastpost']);

$templater = vB_Template::Create('vsa_lastpostsinfo_bit');
$templater->register('lastpostinfo', $lastpostinfo);
$templater->register('vsalpi_memberaction_dropdown', $vsalpi_memberaction_dropdown);
$templater->register('lastpostinfo_unreadpost', $lastpostinfo_unreadpost);
$templater->register('lastpostinfo_lastpost', $lastpostinfo_lastpost);
$templater->register('vsalpi_tprefix', $vsalpi_tprefix);
$templater->register('vsalpi_statusicon', $vsalpi_statusicon);
$templater->register('icon', $icon);
$vsalpi_lastpost .= $templater->render();
}
unset($lastpostinfo,$vsalpi_getinfo);

if ($vsalpi_restot > 1)
{
$vsalpi_preins = array(1,2);
foreach ($vsalpi_preins AS $foo)
{
$vsalpi_lastposts = "";
if ($vbulletin->options['vsalpienh_enable_title'])
{
$vsalpi_lastposts .= construct_phrase($vbphrase[vsalpienh_last_x_posts], $vsalpi_restot);
}
$vsalpi_lastposts .= $vsalpi_lastpost;
global $vsalpi_lastposts;
$forum['lastpostinfo'] = $vsalpi_lastposts;
}
}
}
}

kh99
12-19-2012, 12:59 AM
Which hook is that on? And were you getting an error or just not seeing anything? I don't see anything in that code that would interfere with what I posted, but maybe it's just that you would need to make your changes to the vsa_lastpostsinfo_bit template instead.

bzcomputers
12-19-2012, 01:29 AM
Hook is on "forumbit_display".

It may have just been a caching issue. After clearing cache they do seem to be playing well together now.

Looks like I'll now need to figure out how to get the plugin above to show the "field12" also.

Edit: They may not be working together as well as I thought. Seems like with the plugin from Post #4 above enabled, on page refresh the Vsa mod will sometimes work and sometimes not.

kh99
12-19-2012, 01:59 AM
That's really strange. That mod doesn't use the same hook that my code does, and I'm pretty sure what I posted doesn't do anything except add one field to the forumcache. But I didn't really study that code - maybe there's something about that extra field that's causing the problem?

bzcomputers
12-19-2012, 04:55 PM
Thanks for all the help on this.

It looks like the issues have worked themselves out and after about 12 hours everything seems to still be working well together. Think it was just a cache issue I was seeing for a little while.

I have two places left I would like to get this "field12" to display:
1) On the forumdisplay page that also uses "lastpostby"
2) In the sidebar Forum Block "Forum Threads"

If you have any insight on getting it in these two locations it would be appreciated. Thanks again.