vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How Would I pull Information From vBulletin? (https://vborg.vbsupport.ru/showthread.php?t=154021)

Pc 1203 08-01-2007 04:33 PM

How Would I pull Information From vBulletin?
 
Hi All,
I'm wondering how would I pull information from vBulletin? I would like to pull:

Username
Posts
And Some Additional Information

- Pc1203

[EDIT]Sorry, the pages are outside of vBulletin.[/EDIT]

Kirk Y 08-01-2007 06:12 PM

Are you trying to display this information on a page within vBulletin or are you using it outside of vBulletin?

Pc 1203 08-01-2007 06:15 PM

A page outside of vBulletin.

- Pc1203

Kirk Y 08-01-2007 06:25 PM

This might of use to you: https://vborg.vbsupport.ru/showthread.php?t=108026

Pc 1203 08-01-2007 06:31 PM

Well, that really isn't what I wanted. I wanted to pull a users posts into an external page. And, yes I checked, vBExternal doesn't do what I'm thinking of.

- Pc1203

Kirk Y 08-01-2007 06:35 PM

What are you trying to do specifically, because I've used a modified vBExternal in the past to display trimmed posts, with the Author's Username, and date of posting on an external page.

Pc 1203 08-01-2007 06:38 PM

Ok, this is what I'm trying to do. I'm trying to create a small profile system for my website. In it somewhere, it says the users posts, join date, username, and some custom profile fields. Hope this is better.

- Pc1203

Kirk Y 08-01-2007 06:44 PM

Well it's really just a matter of querying the database for the relevant information.

Place the following at the very top of the pages you're displaying information on; make sure they're PHP files as well.

Code:

<?php
chdir('/path/to/forum');
require_once('/path/to/global.php');
?>

Then you're free to use the DB class to retrieve information.

Example:
Code:

$stats = $db->query_read("SELECT threadcount, replycount FROM " . TABLE_PREFIX . "forum");
while ($forum = $db->fetch_array($stats))
{
    $threads += $forum['threadcount'];
    $posts += $forum['replycount'];
}
$threads = vb_number_format($threads);
$posts = vb_number_format($posts);


Pc 1203 08-01-2007 06:46 PM

Ok, Thanks alot!

// I would add rep but I guess it's disabled.

- Pc1203

EDIT: I get a blank page after trying this code:

Code:

<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');
?>
<html>
<head>
</head>
<body>
Test
<?php
$stats = $db->query_read("SELECT threadcount, replycount FROM " . TABLE_PREFIX . "forum");
while ($forum = $db->fetch_array($stats))
{
    $threads += $forum['threadcount'];
    $posts += $forum['replycount'];
}
$threads = vb_number_format($threads);
$posts = vb_number_format($posts);

$stats
?>
</body>
</html>

EDIT2: Uh-Oh. I guess I miss-lead you. I want to display a USERS posts/join date/if online/not, ect. Sorry.

- Pc1203

Pc 1203 08-02-2007 07:55 PM

Bump

- Pc1203

Opserty 08-02-2007 08:12 PM

Something like this:
PHP Code:

// Add the usual require stuff here
$wanted_userid 9// The user id of the user you want the data from 
$userinfo fetch_userinfo($wanted_userid);

$posts $userinfo['posts'];
// $joindate = $userinfo['joindate']; // Unformatted
$joindate vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug 

ef

(Untested)

Pc 1203 08-02-2007 08:23 PM

Ok, but would I need to include any files like global.php to get that to work?

- Pc1203

Opserty 08-02-2007 08:27 PM

Yes you will need to include the global.php file from the main forum directory.

Pc 1203 08-02-2007 08:33 PM

I just get a blank page. Here is my code:

Code:

<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');

// Add the usual require stuff here
$wanted_userid = 9; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);

$posts = $userinfo['posts'];
// $joindate = $userinfo['joindate']; // Unformatted
$joindate = vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug

$joindate
?>

EDIT: Stupid Me! I forgot to use the print command. It works! Thanks Alot! Do you know how to get custom profile fields, though?

EDIT2: When I look at join date I get "1177448760" for my user....

EnIgMa1234 08-02-2007 08:36 PM

You need to add the variables to a template

Kirk Y 08-02-2007 08:38 PM

You need to use the vbdate() function to convert the timestamp into a readable format.

Pc 1203 08-02-2007 08:41 PM

Ok, I did that and I'm still getting the same thing. Here is my code:

Code:

<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');

// Add the usual require stuff here
$wanted_userid = $_GET['u']; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);

$posts = $userinfo['posts'];
$username = $userinfo['username'];
//$joindate = $userinfo['joindate']; // Unformatted
$joindate = vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug

print "<h1>$username</h1>";
print "Posts: $posts";
print "<br />";
print "$username Joined On: $joindate";
?>

It outputs:

Pc1203

Posts: 1044
Pc1203 Joined On: 1177448760

- Pc1203

EnIgMa1234 08-02-2007 08:41 PM

This is how to use vbdate.

Code:

vbdate($vbulletin->options[dateformat], $userinfo['joindate']);

Kirk Y 08-02-2007 08:44 PM

Sample query for profile fields:
Code:

$fields = $vbulletin->db->query_first("SELECT * FROM userfield WHERE userid =".$userid);
Then you can use $fields['fieldX'] to retrieve a particular field.

Also, you should look into cleaning the variables you're using in queries - or you'll leave this page open to SQL injection.

Pc 1203 08-02-2007 08:45 PM

Ok Thanks EnIgMa1234! The date works now. Any ideas on how to get some custom profile fields?

- Pc1203

EDIT: Ok, Kirk Y. I'll try that. Also you said I should change the variables, is that what you meant?

EnIgMa1234 08-02-2007 08:47 PM

[sql]$fields = $vbulletin->db->query_first("SELECT * FROM userfield
WHERE userid = '" . $userid . "');[/sql]

Opserty 08-02-2007 08:59 PM

Kirk/Enigma: Does fetch_userinfo() not fetch custom fields?

Kirk Y 08-02-2007 09:22 PM

I've never used it, you may be right.

Pc 1203 08-02-2007 09:26 PM

Quote:

Originally Posted by Kirk Y (Post 1308416)
Also, you should look into cleaning the variables you're using in queries - or you'll leave this page open to SQL injection.

What do you mean by "cleaning the variables"?

- Pc1203

Kirk Y 08-02-2007 09:38 PM

If Opserty is correct in you being able to simply use $userinfo['fieldX'] in place of the query I suggested, you don't need to worry about cleaning the $_GET superglobal.

Pc 1203 08-02-2007 09:45 PM

Yup, Opserty is correct. So I don't have to worrie about anything then, right?

- Pc1203

Kirk Y 08-02-2007 09:53 PM

No, as long as you're not querying anything more.

Pc 1203 08-02-2007 10:03 PM

Ok, and for future reference here is the source:

Code:

<?php
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');

// Add the usual require stuff here
$wanted_userid = $_GET['u']; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);

$posts = $userinfo['posts'];
$username = $userinfo['username'];
$joindate = vbdate($vbulletin->options[dateformat], $userinfo['joindate']);
?>
<h1>
<?php print $username; ?>
</h1>
Posts: <?php print $posts; ?><br />
<?php print $username; ?> Joined On: <?php print $joindate; ?><p>
Custom Profile Field #1: <?php print $userinfo['field4']; ?><br />

**NOTE** Change "chdir('/path/to/your/forums');" to the full path to your forums directory and "require_once('/path/to/your/forums/global.php');" to the full path to the global.php file.

- Pc1203

Dismounted 08-03-2007 10:42 AM

PHP Code:

$wanted_userid $_GET['u']; 

Should really be.
PHP Code:

$wanted_userid intval($_GET['u']); 



All times are GMT. The time now is 09:20 PM.

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.01235 seconds
  • Memory Usage 1,783KB
  • 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
  • (8)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (29)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