vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How do I access a variable from a custom include? (https://vborg.vbsupport.ru/showthread.php?t=148016)

ScubaAddict 05-24-2007 11:29 AM

How do I access a variable from a custom include?
 
Ok, I posted this question on vb.com, and after some research figured that this is the board with the smarter people ;) So I figured it would be answered better here.

Here it is:

I am including a file into the member profile using the plugin system (ob_start()... etc).

The plugin works fine, except for one thing:

I can't figure out how to get the username variable of the profile being viewed.

For example, if you look at this page:
http://www.scubaaddict.com/scuba-forums/member.php?u=66

I have written a customization showing the articles written by that user.

Is there any way to get access to the $vbulletin->userinfo['username'] and have the value be that user (mcm007)?

Whenever I try to access that variable from my include, it shows my username (Addict) - even though the exact same code in the template shows produces 'mcm007'.

Currently, I am snagging the uid from the Querystring and getting the username by using that uid in a query - problem is that if you access the same profile in a different manner, that querystring parameter is not available.

Does anyone know how I can use this variable like I want to? or can point me to a place that has a more detailed explanation of how to use the variables in the templates?

TIA - Addict

Dismounted 05-25-2007 09:11 AM

$userinfo[username]

It works in the template, not sure if it works out of the template though, worth a try.

ScubaAddict 05-25-2007 02:57 PM

Dismounted - No, that doesn't work ($userinfo[username] contains my username when viewing someone else's profile) - but thanks for replying :)

Maybe I need to figure out a different way to insert my table...

---------------UPDATE----------------

Ok, there has to be a way.

If you wanted to modify this page:

http://www.scubaaddict.com/scuba-for...stposter&t=162

how would you get to that user's id, or username? It isn't in a variable anywhere. I did a print_r($vbulletin) and there is nothing with that users id or username on the above page, so how does it display the username on that page?

---------------UPDATE----------------

The only way I see to get the userid on the member profile is to drop in a conditional in the include that queries based on the querystring parameter provided.
PHP Code:

if (isset($_GET['u'])) {
$profile_uid =$_GET['u'];

} elseif (isset(
$_GET['find']) && ($_GET['find'] == 'lastposter') && (isset($_GET['t']))) {
mysql_select_db("message_boards");
$sql "SELECT post.userid FROM thread LEFT JOIN post on thread.lastpostid = post.postid WHERE thread.threadid = ".$_GET['t'];
$profile_query mysql_query($sql);
$profile_result mysql_fetch_array($profile_query);
$profile_uid $profile_result['userid'];

} elseif (isset(
$_GET['find']) && ($_GET['find'] == 'lastposter') && (isset($_GET['f']))) {
mysql_select_db("message_boards");
$sql "SELECT post.userid FROM forum LEFT JOIN post on forum.lastpostid = post.postid WHERE forum.forumid = ".$_GET['f'];
$profile_query mysql_query($sql);
$profile_result mysql_fetch_array($profile_query);
$profile_uid $profile_result['userid'];


It works for me whether they click on the users name in the forum, thread or post view.

Seems expensive, so if anyone knows of a better way, please let me know.

Addict

Dismounted 05-27-2007 05:37 AM

No it doesn't, $bbuserinfo contains your own, $userinfo contains theirs.

ScubaAddict 05-27-2007 12:49 PM

Dismounted,

Are you talking in the template or an included file? In the template it shows fine, but if you put that variable in an included file, the value I am getting for both variables is my username.

Dismounted 05-28-2007 04:58 AM

Quote:

Originally Posted by ScubaAddict (Post 1255531)
Are you talking in the template or an included file? In the template it shows fine, but if you put that variable in an included file, the value I am getting for both variables is my username.

Quote:

Originally Posted by Dismounted (Post 1254378)
It works in the template, not sure if it works out of the template though, worth a try.

:).

Kungfu 05-28-2007 02:19 PM

Quote:

Originally Posted by ScubaAddict (Post 1255531)
Dismounted,

Are you talking in the template or an included file? In the template it shows fine, but if you put that variable in an included file, the value I am getting for both variables is my username.

try to include $vbulletin globally.

Not sure what your script looks like but $vbulletin->userinfo['username'] should work.

Dismounted 05-29-2007 08:15 AM

He wants the loaded member profile's info, not his own...


All times are GMT. The time now is 02:15 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.01508 seconds
  • Memory Usage 1,739KB
  • 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
  • (1)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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