View Full Version : Trying to get this to work... (lightbulb function)
BirdOPrey5
10-20-2010, 08:14 PM
So working backwards from the threadbit templates I've been trying to figure out the code that controls which status icon is shown on forumdisplay (old posts, old posts locked, new posts, new posts locked...) and I want to use that code elsewhere, specifically on the navnar so I can show a notice if a particular forum has an unread message in it.
I've tracked this down to the forum_fetch_lightbulb function in the functions_forumlist.php file. The function takes 3 parameters, two of which are the forum id of the forum and one of which is an array which also is the forum id and the parent id of the forum... why this function needs 3 things with the same info I'm not sure but that isn't the issue.
I am passing it the correct info (I believe) but I'm always only getting the same return value: "old" - Even when there are new posts in the forum with the id I specify. I confirm this by going to forumdisplay and seeing the "new posts" status icon is indeed there.
Any thoughts on what I might need to get this to work? I am temporarily outputting the text to the navbar for now but will obviously be doing something more with it once I can get it to work.
plugin code:
include('includes/functions_forumlist.php');
//set forumid
$checkfid = $checkfid2 = 4;
//build array
$checkarray["forumid"] = $checkfid;
$checkarray["parentid"] = 1;
$sico = fetch_forum_lightbulb($checkfid, $checkarray, $checkfid2);
eval('$template_hook[navbar_buttons_left] .= "' ."<td>" .$sico. "</td>" . '";');
Looking in functions_forumlist.php, it looks like the parameters to fetch_forum_lightbulb should be forumid, lastpostinfo, foruminfo. Stealing some code from that file, you might be able to do something like this (assuming $forumid is already set):
global $vbulletin, $lastpostarray;
// call fetch_last_post_array() first to get last post info for forums
if (!is_array($lastpostarray))
{
fetch_last_post_array(-1);
}
// grab the appropriate forum from the $vbulletin->forumcache
$forum = $vbulletin->forumcache["$forumid"];
$lastpostinfo = (empty($lastpostarray[$forumid]) ? array() : $vbulletin->forumcache["$lastpostarray[$forumid]"]);
$sioc = fetch_forum_lightbulb($forumid, $lastpostinfo, $forum);
And then if you look in functions_forumlist after fetch_forum_lightbulb is called you can see there's some additional code to add the lock for locked threads, if you care about that.
I didin't try any of this so I'm not sure if there might be something else you need to do.
BirdOPrey5
10-20-2010, 11:26 PM
OK I think the issue is that this needs to be in the navbar so a specific forum won't really be available, I want to seed it with the forum id's I need to check.
Also I have it on global_start, not sure if there is a better hook...
I don'r care about locked or not, just "new" or "old"
Integrating your code and my needs I get:
include('includes/functions_forumlist.php');
global $vbulletin, $lastpostarray;
// call fetch_last_post_array() first to get last post info for forums
if (!is_array($lastpostarray))
{
fetch_last_post_array(-1);
}
// setthe appropriate forum id
$forumck = 4;
$forumxx = 4;
$lastpostinfo = (empty($lastpostarray[4]) ? array() : $vbulletin->forumcache["$lastpostarray[4]"]);
$sico = fetch_forum_lightbulb($forumck, $lastpostinfo, $forumxx);
eval('$template_hook[navbar_buttons_left] .= "' ."<td>" .$sico. "</td>" . '";');
This still produces "old" and only "old" for output.
I'm thinking the issue might be in $forumxx (in your code it was just $forum) - what type of info is in this variable? From my looking at the code I thought it was simply the forumid of the forum I'm checking on, but that should be the same as $forumid ($forumck in my code) so that doesn't make too much sense to me. :confused:
yeah, $foruminfo (the third parameter) is an array that has all the info about a forum (or at least everything that's needed to display the page). If you look at the actual code for fetch_forum_lightbulb you can see how it's used. Anyway, I'm not sure if the forumcache is available at global_start or not. Probably it is.
BirdOPrey5
10-21-2010, 01:37 AM
ahhh... thanks... don't know how I missed that.
OK so it's an array... looking at the definition of the fetch_light_bulb function it uses two parts of the array $foruminfo['forumid'] which is no problem, that's something I'm going to set... But it also uses $foruminfo['forumread']... Now I had to find what was in this...
In forumdisplay.php is the line:
$foruminfo['forumread'] = $vbulletin->forumcache["$foruminfo[forumid]"]['forumread'];
So once again the forumid I can again provide since it will be a value I set... but now there's this ['forumread'] thing... I searched though all the text of all the vb files... "['forumread']" occurs 28 times, but is never on the left side of the "equals" (=) sign... Now I know it's not a variable but I don't understand how to figure out what info it's supposed to contain...
It does appear on the left side once but it's in the install files mysql schema and I don't think it's what I'm looking for.
Do you know what is in ['forumread'] ? Is it a date?
Do you know what is in ['forumread'] ? Is it a date?
I think it's a date that comes out of the table "forumread" (the readtime column).
Did you try using "$forum = $vbulletin->forumcache["$forumid"];"? Maybe the forumcache is already set up with that info. If not, it looks like the user-specific info is added by the function cache_ordered_forums in includes/function.php, so maybe you could call that with a 1 for the first parameter. Like
// cache_ordered_forums(1); // uncomment this if it doesn't work without it
$forum = $vbulletin->forumcache["$forumid"];
Then use $forum as the 3rd param to fetch_forum_lightbulb.
If I had time I'd try it out on my test site, but I don't right now.
ETA: Now that I'm more awake...if you just want the forumread field you might be able to do something like:
$forum = $vbulletin->db->query_first("SELECT readtime from ".TABLE_PREFIX."forumread AS forumread
WHERE userid =".$vbulletin->userinfo['userid']."
AND forumid=".$forumid);
$forum['forumid'] = $forumid;
Although it would probably be more efficient to check if the info is already being filled in.
BirdOPrey5
10-21-2010, 04:52 PM
OK Thanks... the first bit of code was a big help- definitely needed to use: cache_ordered_forums(1); for it to work... now I have data in the $forum variable... but still not working. I've narrowed it down to the $lastpostinfo - it's always an empty array.
Current code: (note I had to change the name of $forumid and $forum because the names were interfering with existing code and the forum wouldn't display properly until I changed them so I added an 'x' to the end of each:
include('includes/functions_forumlist.php');
global $vbulletin, $lastpostarray;
// call fetch_last_post_array() first to get last post info for forums
if (!is_array($lastpostarray))
{
fetch_last_post_array(-1);
}
$lastpostinfo = (empty($lastpostarray[4]) ? array() : $vbulletin->forumcache["$lastpostarray[4]"]);
$forumidx = 4;
cache_ordered_forums(1);
$forumx = $vbulletin->forumcache["$forumidx"];
$sico = fetch_forum_lightbulb($forumidx, $lastpostinfo, $forumx);
eval('$template_hook[navbar_buttons_left] .= "' ."<td>" .$sico. $forumx['forumid']. "-" . $forumx['forumread'] . $lastpostinfo['lastpost'] ."</td>" . '";');
The output of this is: old4-1287669138
$lastpostinfo['lastpost'] is empty.
Hmm...$lastpostarray comes from $vbulletin->iforumcache which should be filled in by the call to cache_ordered_forums - maybe try passing a second "1" like:
cache_ordered_forums(1, 1);
ETA: oh...try calling cache_ordered_fourms *before* fetch_last_post_array.
BirdOPrey5
10-21-2010, 07:43 PM
O M G... THANK YOU!!!! That was it (calling cache_ordered_forums first) !!!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.