vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Website Intergration with vB 3.8 (https://vborg.vbsupport.ru/showthread.php?t=211461)

ScottC2105 04-17-2009 08:27 AM

Website Intergration with vB 3.8
 
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

Quote:

Originally Posted by Dismounted (Post 1793112)
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 [DATE]1239987506[/DATE] at [TIME]1239987506[/TIME] ---------------

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):

PHP Code:

$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:

PHP Code:

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

Quote:

Originally Posted by Choo (Post 1793441)
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):

PHP Code:

$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:

PHP Code:

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 [DATE]1240006133[/DATE] at [TIME]1240006133[/TIME] ---------------

Quote:

Originally Posted by ScottC2105 (Post 1793526)
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

Quote:

Originally Posted by ScottC2105 (Post 1793526)
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:

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 [DATE]1240073997[/DATE] at [TIME]1240073997[/TIME] ---------------

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

Quote:

Originally Posted by Floris (Post 1793122)
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.

Quote:

Originally Posted by ScottC2105 (Post 1793819)
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
Code:

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


All times are GMT. The time now is 03:26 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01173 seconds
  • Memory Usage 1,758KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (4)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (12)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete