PDA

View Full Version : Converting vBulletin widget to WordPress


ExoticAgenda
05-06-2012, 12:10 PM
Hi, I have a snippet of code that I found and use as a widget to display the next 5 upcoming events in my calendar. I am looking to port this over to WordPress as that is now my homepage. The code is below. Any assistance would be greatly appreciated. Thanks


ob_start();


// %d
$show_count = 5;

$query = sprintf("SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from > '%d' || ( dateline_from > '%d' AND dateline_to < '%d' )) ORDER BY dateline_from ASC LIMIT %d",TIMENOW,TIMENOW,TIMENOW,$show_count);

$event_get = vB::$db->query_read($query);

$output_bits = '';
while($event = vB::$db->fetch_array($event_get)) {

if($event['dateline_to'] == 0 )
{
$format = sprintf("On %s",date('jS M Y',$event['dateline_from']));
} else {
$format = sprintf("From %s to %s",date('jS M Y',$event['dateline_from']),date('jS M Y',$event['dateline_to']));
}

$output_bits .= sprintf('
<div class = "cms_widget_post_bit"><h4 class="cms_widget_post_header"><a href="calendar.php?do=getinfo&e=%d"><p style="color:red">%s</p></a></h4>
<p class="cms_widget_post_content">%s</p>
</div>
',$event['eventid'],$event['title'],$format);

}
$output = $output_bits;

ob_end_clean();

LifesGreatestGift
05-06-2012, 01:19 PM
why convert it? just install a php code widget on wordpress, chdir to the forum directory require global.php, change back and bam.

ExoticAgenda
05-07-2012, 06:29 PM
How would I do that? WordPress and vBulletin are both installed on the root of my website. When i chdir i get this error:
Fatal error: Access to undeclared static property: VB::$db

thanks

kh99
05-07-2012, 07:54 PM
If vb's global.php is in the same directory as the script that's running your code, then you don't need to chdir. If you still get that error, try removing the VB:: from in front of $db.

ExoticAgenda
05-08-2012, 12:11 AM
I did that, I removed the VB:: and now nothing shows up (atleast no errors), but now I am not sure what to check next. thanks

kh99
05-08-2012, 12:52 AM
A vb widget only sets $output to the widget html. I don't know how a WordPress widget works, but unless it works exactly the same way then you're probably not going to get any output.

ExoticAgenda
05-08-2012, 02:20 PM
hm, ok. is there any way to figure out how to display the text? Or am I going to need to have a widget made from scratch that queries the table. thanks

kh99
05-08-2012, 02:58 PM
I think what you need is some info on how to write a WordPress widget (which may be quite different than a vb widget even though they're both called widgets). Of course this is a vb forum and not WP, but someone here probably knows. Or you could try a wordpress forum.

ExoticAgenda
05-11-2012, 11:07 AM
yeah ill need to look into that, thanks for the help though

ExoticAgenda
06-10-2012, 08:11 PM
To follow up on this, I got it working. I needed to echo out the output and remove the vB:: and other small things. But it works now.

<?php

global $db;

require('global.php');

// %d
$show_count = 5;

$query = sprintf("SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from > '%d' || ( dateline_from > '%d' AND dateline_to < '%d' )) ORDER BY dateline_from ASC LIMIT %d",TIMENOW,TIMENOW,TIMENOW,$show_count);

$event_get = $db->query_read($query);

$output_bits = '';
while($event = $db->fetch_array($event_get)) {

if($event['dateline_to'] == 0 )
{
$format = sprintf("On %s",date('jS M Y',$event['dateline_from']));
} else {
$format = sprintf("From %s to %s",date('jS M Y',$event['dateline_from']),date('jS M Y',$event['dateline_to']));
}

$output_bits .= sprintf('
<div style="text-align: left; margin-left: 25px;"><b><a href="calendar.php?do=getinfo&e=%d">%s</a></b>
%s</div><br />
',$event['eventid'],$event['title'],$format);

}

echo "$output_bits";
echo "<a style='margin-right: auto;' href='http://www.exoticagenda.com/calendar.php'>See more events</a>";
?>