Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2008, 08:12 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Globalizing a Variable/Function

This is becoming a serious problem for me, as I need to find a way to have a certain function work on other areas of my board. The function is:

$prepared['isfriend']


It checks for friendship on the MEMBERINFO template, but not on any other page. What would I need to do in order to have it function on other pages. Any help or suggestions are welcome.
Reply With Quote
  #2  
Old 05-05-2008, 08:16 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's how I used it in my User CP Referrer hack to get the referrer name in the profile, it this helps at all:

PHP Code:
global $show;
 
if (
$this->registry->options['usereferrer'])
{
 
$referral $this->registry->db->query_first_slave("
  SELECT userid, username FROM " 
TABLE_PREFIX "user
  WHERE userid = " 
$this->userinfo['referrerid'] . "
 "
);
 
$this->prepared['referralsname'] = $referral['username'];
 
$this->prepared['referralsuserid'] = $referral['userid'];
 
 if (
$this->prepared['referralsuserid'] > 0)
 {
  
$show['referrer'] = true;
 }
 else
 {
  
$show['referrer'] = false;
 }

I used it in the userprofile_create hook.
Reply With Quote
  #3  
Old 05-05-2008, 09:23 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your reply, I think I may have stumbled upon what I need, but am having no luck with the result.

Inside includes/functions.php I discovered the following lines:

Line 1226:
Code:
define('FETCH_USERINFO_ISFRIEND',   0x80);
Line 1269:
Code:
    // no cache available - query the user
    $user = $vbulletin->db->query_first_slave("
        SELECT " .
            iif(($option & FETCH_USERINFO_ADMIN), ' administrator.*, ') . "
            userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate,
            IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid" .
            iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], ', avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight, customavatar.height_thumb AS avheight_thumb, customavatar.width_thumb AS avwidth_thumb, customavatar.filedata_thumb').
            iif(($option & FETCH_USERINFO_PROFILEPIC), ', customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight') .
            iif(($option & FETCH_USERINFO_SIGPIC), ', sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight') .
            (($option & FETCH_USERINFO_USERCSS) ? ', usercsscache.cachedcss, IF(usercsscache.cachedcss IS NULL, 0, 1) AS hascachedcss, usercsscache.buildpermissions AS cssbuildpermissions' : '') .
            iif(!isset($vbphrase), fetch_language_fields_sql(), '') .
            (($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
                ", IF(userlist1.friend = 'yes', 1, 0) AS isfriend, IF (userlist1.friend = 'pending' OR userlist1.friend = 'denied', 1, 0) AS ispendingfriend" .
                ", IF(userlist1.userid IS NOT NULL, 1, 0) AS u_iscontact_of_bbuser, IF (userlist2.friend = 'pending', 1, 0) AS requestedfriend" .
                ", IF(userlist2.userid IS NOT NULL, 1, 0) AS bbuser_iscontact_of_user" : "") . "
            $hook_query_fields
        FROM " . TABLE_PREFIX . "user AS user
        LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (user.userid = userfield.userid)
        LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid) " .
        iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) ") .
        iif(($option & FETCH_USERINFO_PROFILEPIC), "LEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid) ") .
        iif(($option & FETCH_USERINFO_ADMIN), "LEFT JOIN " . TABLE_PREFIX . "administrator AS administrator ON (administrator.userid = user.userid) ") .
        iif(($option & FETCH_USERINFO_SIGPIC), "LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON (user.userid = sigpic.userid) ") .
        (($option & FETCH_USERINFO_USERCSS) ? 'LEFT JOIN ' . TABLE_PREFIX . 'usercsscache AS usercsscache ON (user.userid = usercsscache.userid)' : '') .
        iif(!isset($vbphrase), "LEFT JOIN " . TABLE_PREFIX . "language AS language ON (language.languageid = " . (!empty($languageid) ? $languageid : "IF(user.languageid = 0, " . intval($vbulletin->options['languageid']) . ", user.languageid)") . ") ") .
        (($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
            "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist1 ON (userlist1.relationid = user.userid AND userlist1.type = 'buddy' AND userlist1.userid = " . $vbulletin->userinfo['userid'] . ")" .
            "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist2 ON (userlist2.userid = user.userid AND userlist2.type = 'buddy' AND userlist2.relationid = " . $vbulletin->userinfo['userid'] . ")" : "") . "
        $hook_query_joins
        WHERE user.userid = $userid
    ");
The code in red seems to be defining what it is that the isfriend function is suposed to do, am I correct? I tried different ways of creating a plugin based on this code and merging it into yours in different ways but came up with errors. It seems that what i need to do is re-fetch this command, rather than copying and pasting it over again.

Can anyone help me with this?
Reply With Quote
  #4  
Old 05-05-2008, 09:52 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you trying to get a list of friends or just for one user? You should be able to do a query for that, I would think.
Reply With Quote
  #5  
Old 05-05-2008, 10:05 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, actually I want to use the function to verify if the user is a friend, and if so, it would display the information accordingly.

For example:
Code:
<if condition="$prepared['isfriend']">
This message will be displayed if I am a friend of this user
<else />
This message will be displayed If I am not a friend of this user
</if>
Reply With Quote
  #6  
Old 05-07-2008, 01:26 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Inside member.php, line 277, I found:

Code:
$fetch_userinfo_options = (
    FETCH_USERINFO_AVATAR | FETCH_USERINFO_LOCATION |
    FETCH_USERINFO_PROFILEPIC | FETCH_USERINFO_SIGPIC |
    FETCH_USERINFO_USERCSS | FETCH_USERINFO_ISFRIEND
);
I copied and pasted this info a plugin with the hook postbit_display_start and it had no effect unfortunately, I received no errors though.

What else could I be missing in my plugin code that isn't allowing this function to run? I have tried including both these in my postbit template and neither appear:

Code:
<if condition="$userinfo['isfriend']">
content
</if>
Code:
<if condition="$prepared['isfriend']">
content
</if>
Reply With Quote
  #7  
Old 05-07-2008, 10:13 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please post the entire plugin.
Reply With Quote
  #8  
Old 05-07-2008, 10:23 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's the problem, I don't have a plugin and need to create one but have no little idea as to what I should include in it. I'm positive I am using the correct hook, but the contents of my plugin are what I need help in creating. Here is all the code associated with my function in question.

This is found in functions.php, line 1248:

Code:
function fetch_userinfo(&$userid, $option = 0, $languageid = 0)
{
    global $vbulletin, $usercache, $vbphrase, $permissions, $phrasegroups;

    if ($userid == $vbulletin->userinfo['userid'] AND $option != 0 AND isset($usercache["$userid"]))
    {
        // clear the cache if we are looking at ourself and need to add one of the JOINS to our information.
        unset($usercache["$userid"]);
    }

    $userid = intval($userid);

    // return the cached result if it exists
    if (isset($usercache["$userid"]))
    {
        return $usercache["$userid"];
    }

    $hook_query_fields = $hook_query_joins = '';
    ($hook = vBulletinHook::fetch_hook('fetch_userinfo_query')) ? eval($hook) : false;

    // no cache available - query the user
    $user = $vbulletin->db->query_first_slave("
        SELECT " .
            iif(($option & FETCH_USERINFO_ADMIN), ' administrator.*, ') . "
            userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate,
            IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid" .
            iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], ', avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight, customavatar.height_thumb AS avheight_thumb, customavatar.width_thumb AS avwidth_thumb, customavatar.filedata_thumb').
            iif(($option & FETCH_USERINFO_PROFILEPIC), ', customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight') .
            iif(($option & FETCH_USERINFO_SIGPIC), ', sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight') .
            (($option & FETCH_USERINFO_USERCSS) ? ', usercsscache.cachedcss, IF(usercsscache.cachedcss IS NULL, 0, 1) AS hascachedcss, usercsscache.buildpermissions AS cssbuildpermissions' : '') .
            iif(!isset($vbphrase), fetch_language_fields_sql(), '') .
            (($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
                ", IF(userlist1.friend = 'yes', 1, 0) AS isfriend, IF (userlist1.friend = 'pending' OR userlist1.friend = 'denied', 1, 0) AS ispendingfriend" .
                ", IF(userlist1.userid IS NOT NULL, 1, 0) AS u_iscontact_of_bbuser, IF (userlist2.friend = 'pending', 1, 0) AS requestedfriend" .
                ", IF(userlist2.userid IS NOT NULL, 1, 0) AS bbuser_iscontact_of_user" : "") . "
            $hook_query_fields
        FROM " . TABLE_PREFIX . "user AS user
        LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (user.userid = userfield.userid)
        LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid) " .
        iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) ") .
        iif(($option & FETCH_USERINFO_PROFILEPIC), "LEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid) ") .
        iif(($option & FETCH_USERINFO_ADMIN), "LEFT JOIN " . TABLE_PREFIX . "administrator AS administrator ON (administrator.userid = user.userid) ") .
        iif(($option & FETCH_USERINFO_SIGPIC), "LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON (user.userid = sigpic.userid) ") .
        (($option & FETCH_USERINFO_USERCSS) ? 'LEFT JOIN ' . TABLE_PREFIX . 'usercsscache AS usercsscache ON (user.userid = usercsscache.userid)' : '') .
        iif(!isset($vbphrase), "LEFT JOIN " . TABLE_PREFIX . "language AS language ON (language.languageid = " . (!empty($languageid) ? $languageid : "IF(user.languageid = 0, " . intval($vbulletin->options['languageid']) . ", user.languageid)") . ") ") .
        (($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
            "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist1 ON (userlist1.relationid = user.userid AND userlist1.type = 'buddy' AND userlist1.userid = " . $vbulletin->userinfo['userid'] . ")" .
            "LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist2 ON (userlist2.userid = user.userid AND userlist2.type = 'buddy' AND userlist2.relationid = " . $vbulletin->userinfo['userid'] . ")" : "") . "
        $hook_query_joins
        WHERE user.userid = $userid
    ");
    if (!$user)
    {
        return false;
    }

    if (!isset($vbphrase) AND $user['lang_options'] === null)
    {
        trigger_error('The requested language does not exist, reset via tools.php.', E_USER_ERROR);
    }

    $user['languageid'] = (!empty($languageid) ? $languageid : $user['languageid']);

    // decipher 'options' bitfield
    $user['options'] = intval($user['options']);

    foreach ($vbulletin->bf_misc_useroptions AS $optionname => $optionval)
    {
        $user["$optionname"] = ($user['options'] & $optionval ? 1 : 0);
        //DEVDEBUG("$optionname = $user[$optionname]");
    }

    foreach($vbulletin->bf_misc_adminoptions AS $optionname => $optionval)
    {
        $user["$optionname"] = ($user['adminoptions'] & $optionval ? 1 : 0);
    }

    // make a username variable that is safe to pass through URL links
    $user['urlusername'] = urlencode(unhtmlspecialchars($user['username']));

    fetch_musername($user);

    // get the user's real styleid (not the cookie value)
    $user['realstyleid'] = $user['styleid'];

    $user['securitytoken'] = sha1($user['userid'] . sha1($user['salt']) . sha1(COOKIE_SALT));
    $user['logouthash'] =& $user['securitytoken'];

    if ($option & FETCH_USERINFO_LOCATION)
    { // Process Location info for this user
        require_once(DIR . '/includes/functions_online.php');
        $user = fetch_user_location_array($user);
    }

    ($hook = vBulletinHook::fetch_hook('fetch_userinfo')) ? eval($hook) : false;

    $usercache["$userid"] = $user;
    return $usercache["$userid"];
}
This is the only page which contains the isfriend conditional in this fashion.

The location where it is functional now, only on the member.php includes the following code on line 277:
Code:
$fetch_userinfo_options = (
    FETCH_USERINFO_AVATAR | FETCH_USERINFO_LOCATION |
    FETCH_USERINFO_PROFILEPIC | FETCH_USERINFO_SIGPIC |
    FETCH_USERINFO_USERCSS | FETCH_USERINFO_ISFRIEND
);
The code above does not appear to be inside another function but rather by itself. I tested the code by removing it and I noticed all the accociated functions with the isfriend function ceased to work, so it seems that it is indeed the right code.

The issue is my lacking ability to create a plugin for this function to work on other areas of my board, that's all.
Reply With Quote
  #9  
Old 05-07-2008, 10:35 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to use the friend code on any other page then member.php, you will need to retrieve the data first.

Create a plugin that will retrieve it for the userid you need, something like:

PHP Code:
$friendinfo fetch_userinfo(<<userid>>, FETCH_USERINFO_ISFRIEND); 
Info should be available in $friendinfo after this.

PS If you plan to do this on posts, then please be aware that this can be very server intensive if you want to retrieve this for each post on a page.
Reply With Quote
  #10  
Old 05-07-2008, 10:48 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think there was some confusion, or I am simply misinterpreting the code. Based on my understanding of plugin you created, I am to assume that it will fetch specific data (and display it) by using the $friendinfo function on a template.

This is not what I am looking for, as the content I wish to appear is already in the template, I simply want to restrict the content to only those permitted, in this case being the friends of the user.

At the moment in my profile if i specify 'friends only', it will only show the content in the following conditional to only that users friends.
Code:
<if condition="$prepared['isfriend']">
content
</if>
The issue is that this code was hard coded to only function only certain pages, although I would like to extend this functionality elsewhere. I have already posted above how it is included inside member.php, it is also included inside profile.php, but this code is very specific to this page, so I can't use it in my plugin exactly as is:
PHP Code:
$userinfo verify_id('user'$vbulletin->GPC['userid'], truetrueFETCH_USERINFO_ISFRIEND); 
I tried using your plugin as follows:
PHP Code:
$friendinfo fetch_userinfo($vbulletin->GPC['userid'], FETCH_USERINFO_ISFRIEND); 
But I am almost postive this is incorrect, but received no error. Neither did my content appear as it should by using <if condition="$userinfo['friendinfo']">
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:55 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.12321 seconds
  • Memory Usage 2,296KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_code
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete