Upcoming events Custom Island

Ubb.threads has a very underused, but powerful capability in what are called “Custom Islands”.

You essentially can have a php code module be scheduled to run at whatever interval you want to produce output to be used as one of the custom islands (left or right) on your forums.

I was recently asked to provide such a beast for a customer of mind at Fishing Minnesota and figured that I would share it with the Threads public. Thanks to Rick Paquin for this!

I’ve done the work, so all you have to do is copy the code and paste it into one of your empty custom islands, enable it, set a schedule for how often it updates and you are good to go.

The code is shown below:

[nosmiley]

/* PHP CODE HERE, IF NECESSARY */

# Change the next parameter to the maximum future events you want
$maxEvents = 10;
# Change to whichever column this Custom Island will be shown (for CSS)
$portalCol = 'left';

# -- Nothing changes below, unless you are non-n00bers ;)
$intTime = time();
$dateParts = getdate($intTime);
$dtYr = $dateParts['year'];

$q = "
 SELECT ce.CALENDAR_EVENT_SUBJECT, ce.TOPIC_ID, t.POST_ID,
 ce.CALENDAR_EVENT_DAY, ce.CALENDAR_EVENT_MONTH,
 ce.CALENDAR_EVENT_YEAR, ce.CALENDAR_EVENT_BODY
 FROM {$config['TABLE_PREFIX']}CALENDAR_EVENTS ce, {$config['TABLE_PREFIX']}TOPICS t
 WHERE ce.CALENDAR_EVENT_TYPE='public'
 AND ce.CALENDAR_EVENT_RECURRING = 'never'
 AND ce.CALENDAR_EVENT_YEAR >= $dtYr
 AND ce.TOPIC_ID=t.TOPIC_ID
";
$r = $dbh->do_query($q);
$ceList = array();
while (list($ceSubject, $topicID, $postID, $ceDay, $ceMon, $ceYr) = $dbh->fetch_array($r)) {
 $ceTime = mktime(0,0,0,$ceMon,$ceDay,$ceYr);
 if ($ceTime >= $intTime) {
 $ceList[$ceTime]['Subject'] = $ceSubject;
 $ceList[$ceTime]['postID'] = $postID;
 }
}

# Create the list
$i=0;
sort($ceList);
foreach ($ceList as $ce) {
 $cssExt = ($i++&1) ? '2' : '1';
 $cssClass = 'class="' . $portalCol . 'alt-' . $cssExt .'"';
 if ($i == 1) {
 $htmlList .= "<a href=\"{$config['FULL_URL']}/ubbthreads.php?ubb=showflat&Number={$ce['postID']}\">{$ce['Subject']}</a>";
 } else {
 $htmlList .= "</td></tr><tr><td $cssClass>";
 $htmlList .= "<a href=\"{$config['FULL_URL']}/ubbthreads.php?ubb=showflat&Number={$ce['postID']}\">{$ce['Subject']}</a>";
 }
}

/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF

$htmlList

EOF;
/* DO NOT CHANGE THE LINE ABOVE */

[/nosmiley]

There really are only two things to change here:

  • How many upcoming events to display (line 4)
  • Which column the island will be on (left or right – line 6)

That’s it for the code!

The final thing to do is to configure the custom island’s behavior and I’ll just show a screenie of the parameters I chose:

I set the island to update every 2 hours (120), gave it a title and that was it! Well, almost. One final thing was to go to portal settings and select which column (left or right) to display it on and what order.

Here’s how it looks on the right hand column at Fishing Minnesota forums:

Enjoy and hit the tip jar on the upper right of the site, if you find this worth it :)

No comments yet... Be the first to leave a reply!

Leave a Reply

You must be logged in to post a comment.