PDA

View Full Version : How to get user picture info for use outside of vB


gcc.programmer
03-03-2010, 09:43 AM
I don't know if anyone has an interest in this information, but I thought I'd share it.

My boss has an old, established, and huge vB site, and as part of his new web offerings, he wanted to have a main outside of vB page that showed all the site stats, latest thread posts, user pics, etc., and of course allow users to link to the relevant things on his actual vB site. And of course allow log-in shared between the two.

Being new to vB, I spent some time scanning the source code, and reading a lot of posts and articles here. Finally, it became clear to me that for most of what I needed to do, I had to become intimate with vB's database.

User profile pictures, from what I've found, are stored default in the database, but I think there's an option for you to move them to the file system if you wish. My bosses installation, I found, had ALL the picture's, etc., stored within the database.

vB does offer image.php for display of images, and for situations where you've already got a session to work with, you might want to explore that route. Unfortunately, in my case, that wasn't an option, so I essentially duplicated the relevant parts of that in my own function.

I'm going to walk through the high lites of what I did. I'm a HUGE codeigniter framework fan, so the code snippet is based on that.


So, the problem is: Get a list of some of the most popular members, based on profile visits, and then pull their profile pictures ( if they have one ), and display them on our other site.

To obtain MOST PROFILE VISITS, an sql statement to get you started would be:

SELECT username, userid, profilevisits FROM user ORDER BY profilevisits DESC LIMIT 0,6

This gives you back the username, userid, and total profile visits of the top folks.

The userid is important, as it is needed for both pulling and displaying the picture.

To obtain the picture info for these folks, some starter sql might be:

SELECT filedata, filename FROM customprofilepic WHERE userid=$uid

$uid is passed in to the php routine that runs this query.

This gives you back the filename, and the actual picture data( filedata ).

To show this picture, a basic PHP function might look like:
//this is a codeigniter function that pulls the filename and filedata from the db
function showPicture( $id ){
$this->load->model( 'DB', '', true );
$pic = $this->DB->picInfo( $id );
$extension = trim( substr( strrchr( strtolower( $pic['filename'] ), '.' ), 1 ) );
if ( $extension == 'jpg' OR $extension == 'jpeg' ){
header('Content-type: image/jpeg');
} else if ( $extension == 'png' ){
header('Content-type: image/png' );
} else {
header('Content-type: image/gif' );
}
echo $pic['filedata'];
}

This function takes in the userid, determined from the first sql query, and spits a picture out ( provided of course there is one in the db ).

If you just run this function alone, it will output the picture into your bowser. If you want to use the picture in an <img> tag, you need to use the FULL url to the function.

With some playing around, I was able to get everything we needed for display outside vB. Things like: Total number of users, number and content of Polls, Threads, Forums, posts, etc.
vB keeps everything in the db, so it only stands to reason with proper querrying, you can get all that stuff back out.

You can also pull albums, etc. belonging to users, yada, yada.

Bear in mind, though, that a lot of these things have visibility settings, and in some cases privacy settings. Before you indescriminantly pull pictures and such out of the db for display, be sure you check through these and make sure you're not violating the users desired privacy .

Hopefully, you found this of some use.