PDA

View Full Version : Website Intergration with vB 3.8


ScottC2105
04-17-2009, 08:27 AM
I'm currently building a website and I want to show the latest posts (I.E. new threads and the latest replies) on a sidebar on my main website. I would like to use PHP and connect to the database if possible. I want to have them in alternating rows (in div tags) for example:

http://img206.imageshack.us/img206/3038/altrowvb.jpg

I am also looking to include a login form, once a user logs in the login form area shows there username, a link to user cp, avatar and if there are any new PMs.

I have more I wish to do but I'll leave it for now.

Dismounted
04-17-2009, 08:53 AM
To do this, you will have to include vBulletin's global.php. After this, you will have access to the necessary variables and functions to show that kind of data. Most importantly for you, you will gain access to the $vbulletin->userinfo array.

ScottC2105
04-17-2009, 09:04 AM
To do this, you will have to include vBulletin's global.php. After this, you will have access to the necessary variables and functions to show that kind of data. Most importantly for you, you will gain access to the $vbulletin->userinfo array.

I don't suppose there is a link to an article, document or manual as to what the variables are etc..

Dismounted
04-17-2009, 09:06 AM
Actually, there isn't. What variables are you looking for?

Floris
04-17-2009, 09:08 AM
I recommend browsing the mods directory for your version and see if any modification comes close to what you want. They're great examples to get started.

ScottC2105
04-17-2009, 09:12 AM
I'll be honest my PHP isn't great when it comes to functions etc. At the moment the first thing I want to do is get 10 latest posts showing on my website. Any ideas/help would be much appreciated.

--------------- Added 1239987506 at 1239987506 ---------------

Well I have got my latest posts to work via the external.php file. Is there anyway i could make a login box on my site and show a users username and current new messages if they are logged in.

Choo
04-17-2009, 05:38 PM
In my last project I had the same task and I think I can help you.

At first you need to include global php such way (it is important):

$dir = getcwd();
chdir(PATH_TO_VB);
require './global.php';
chdir($dir);

After that you can work with vb's superobject using $GLOBALS['vbulletin'] variable. You mentioned 2 problems - last posts and authentification. OK... To get last posts you can use something like that:

function get_posts($threadid)
{
$posts = array();
$query = $vbulletin->db->query_read("SELECT * FROM post ORDER BY dateline DESC LIMIT 10");
while($post = $vbulletin->db->fetch_array($query)) $posts[] = $post;
return $posts;
}


Where $vbulletin is vb's superobject.

And now about users. Look at $vbulletin->userinfo property, it contains information about logged user.

ScottC2105
04-17-2009, 08:30 PM
In my last project I had the same task and I think I can help you.

At first you need to include global php such way (it is important):

$dir = getcwd();
chdir(PATH_TO_VB);
require './global.php';
chdir($dir);

After that you can work with vb's superobject using $GLOBALS['vbulletin'] variable. You mentioned 2 problems - last posts and authentification. OK... To get last posts you can use something like that:

function get_posts($threadid)
{
$posts = array();
$query = $vbulletin->db->query_read("SELECT * FROM post ORDER BY dateline DESC LIMIT 10");
while($post = $vbulletin->db->fetch_array($query)) $posts[] = $post;
return $posts;
}


Where $vbulletin is vb's superobject.

And now about users. Look at $vbulletin->userinfo property, it contains information about logged user.

Saint! It works! Thanks for everything! One quick question: How would I show a users avatar?

--------------- Added 1240006133 at 1240006133 ---------------

Saint! It works! Thanks for everything! One quick question: How would I show a users avatar?

I got it, just link to http://forum_url_here/image.php?u=USER_ID_HERE and I can use $vbulletin->userinfo['id'] for USER_ID_HERE. :).

Lynne
04-17-2009, 09:14 PM
I got it, just link to http://forum_url_here/image.php?u=USER_ID_HERE and I can use $vbulletin->userinfo['id'] for USER_ID_HERE. :).
I believe this method will only work if you have the avatars stored in the database. If you ever move them to the file system (which you will want to do when your site gets big), then it is a bit more complicated. I believe there are modifications about putting the avatar here or there that will give you the query needed when you reach that point.

Dismounted
04-18-2009, 05:06 AM
fetch_avatar_from_userinfo() :)

ScottC2105
04-18-2009, 09:17 AM
Good morning everyone. I have a problem with this code:

$dir = getcwd();
chdir(/home/USERNAME/public_html/forum);
require './global.php';
chdir($dir);

I am using it as Choo told me to, to get the current users username etc but I have noticed it only works on www.domain.com not just domain.com. Anyway to fix this?

EDIT: Again, fixed it. You must goto vBulletin Admin -> vBulletin Options -> vBulletin Options -> Cookies and HTTP Header Options -> Cookie Domain and set it from (blank) to .DOMAIN.com.

--------------- Added 1240073997 at 1240073997 ---------------

Right, everything is going good. Thank you all for the help. I have a problem with the code that includes global. I am now getting an error like so:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 77824 bytes)

Is there anyway I can get around this without having to edit php.ini?

Thanks.

wolfstream
04-23-2009, 08:43 PM
I recommend browsing the mods directory for your version and see if any modification comes close to what you want. They're great examples to get started.
This doesn't really "teach" anything, but it lets the user simply add code without understanding what they're doing.


Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 77824 bytes)

Is there anyway I can get around this without having to edit php.ini?


you can try to adjust it in .htaccess by adding

php_value memory_limit 25M

which will raise the memory limit to 25 meg, or you can raise it higher, but remember NOT all webhosts look kindly at that. In fact, many will disable the ability to do so