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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2012, 06:32 AM
Infinity101 Infinity101 is offline
 
Join Date: Feb 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Comparing Friend UserID

Hello, I am in the process of writing a script which highlights buddy posts. I'm having trouble however passing a condition to only highlight the buddies and not everyone.

I have tried several conditionals, all either ending in showing no posts, or all posts. Below are variations of code I have used.

In myphp file:

When pulling information (used from misc.php):
PHP Code:
    $postbuddies $db->query_read_slave("
            SELECT
            user.username, (user.options & " 
$vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.userid, session.lastactivity
            FROM " 
TABLE_PREFIX "userlist AS userlist
            LEFT JOIN " 
TABLE_PREFIX "user AS user ON(user.userid = userlist.relationid)
            LEFT JOIN " 
TABLE_PREFIX "session AS session ON(session.userid = user.userid)
            WHERE userlist.userid = 
{$vbulletin->userinfo['userid']} AND userlist.relationid = user.userid AND type = 'buddy'
            ORDER BY username ASC, session.lastactivity DESC
        "
); 
When Comparing
PHP Code:
if(in_array(postbuddies['userid'], array(memberpost['userid'])){} 
Pulling in separate instance (the above would be removed):
PHP Code:
postbuddies explode(' '$buddies); 
and in template:
Code:
<vb:if condition="is_array($memberpost[userid], array($postbuddies))"></vb:if>
I have tried several other variations similar to the above. I have ran a loops to make sure I was gathering the buddy userid which was successful. The problem seems to be when comparing with a poster's userid.

I hope my post makes sense, it's very late night for me and at this point I feel like my mind is going bonkers. Than you kindly for any help.
Reply With Quote
  #2  
Old 08-12-2012, 01:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need array() in the conditional, it should be:
Code:
<vb:if condition="is_array($memberpost[userid], $postbuddies)"></vb:if>

But that will only work if you register $postbuddies to the template. A way around that would be to add it to an array that is already registered, like:
Code:
$memberpost[postbuddies] = $postbuddies;

then
Code:
<vb:if condition="is_array($memberpost[userid], $memberpost[postbuddies])"></vb:if>

I should also mention that rendered posts are cached, so that may also give you trouble. With the post caching, you can't really have the background change based on something that is specific to the user viewing the post.
Reply With Quote
  #3  
Old 08-12-2012, 04:55 PM
Infinity101 Infinity101 is offline
 
Join Date: Feb 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi kh99, thank you for your response. This is not the first time you have helped me and I'm very thankful.

If I do not include the array() in the conditional, I receive a malformed conditional error when compiling.

Code:
<vb:if condition="in_array($memberpost[userid], $memberpost[postbuddies])">
If I do this (below) I receive the same error even when including array().
Code:
<vb:if condition="is_array($memberpost[userid], $memberpost[postbuddies])">
In the PHP I have:
PHP Code:
    $postbuddiesexplode(' 'trim($userinfo['buddylist']));
    
  
    
$memberpost[postbuddies] = $postbuddies
Thank you again for taking the time in teaching me.
Reply With Quote
  #4  
Old 08-12-2012, 05:06 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, one thing I didn't notice - you should be using in_array(), not is_array().

Which hook is your plugin using, and which template is your conditional in?
Reply With Quote
  #5  
Old 08-13-2012, 02:46 AM
Infinity101 Infinity101 is offline
 
Join Date: Feb 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, I'm using misc_buddylist_start for the hook. I'm using a module from vbadvanced cmps, more or less similar to the "News" module if you're familiar with it.

Thanks!
Reply With Quote
  #6  
Old 08-27-2012, 05:13 AM
Infinity101 Infinity101 is offline
 
Join Date: Feb 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I continue to have difficulty with this. Any input? Thanks!
Reply With Quote
  #7  
Old 08-27-2012, 11:29 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One very important thing I missed the first time around - you can't directly use the return value of query_read_slave(), it won't be an array. If you're only expecting one row from your query, you should call query_read_first(), which will return an array representing the first row returned from the query.
Reply With Quote
  #8  
Old 08-27-2012, 04:12 PM
Infinity101 Infinity101 is offline
 
Join Date: Feb 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Excellent, thank you kh99. I'm going to try this out.

--------------- Added [DATE]1346099203[/DATE] at [TIME]1346099203[/TIME] ---------------

Thank you kh99, I have had more success. I wanted to verify whether or not I was pulling the information correctly through the php hook. I used print_r to see the array. When using query_first(); unfortunately their was no return. When using query_ready() was able to return the array however.


Array ( [0] => 111 ) Array ( [0] => 2379 ) Array ( [0] => 103 ) Array ( [0] => 28 ) Array ( [0] => 6 ) Array ( [0] => 49 ) Array ( [0] => 192 ) Array ( [0] => 2399 )

PHP Code:
    while ($buddy $db->fetch_array($buddys))
    {
        if (
$doneuser["$buddy[userid]"])
        {
            continue;
        }
        
$buddylistexplode(' 'trim($buddy['userid']));
        
$comment['buddylist'] = $buddylist;
        
print_r($comment['buddylist']);
        
$doneuser["$buddy[userid]"] = true;

    } 


When comparing in the template however, I receive this error:


Code:
<vb:if condition="in_array($comment[buddylist], $comment[userid])">A friend posted!</vb:if>
Code:
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Do you think this is a problem with the template reading the variable? Or should I use a different method in comparing the values?

Thanks for your continued support.
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 07:48 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.04526 seconds
  • Memory Usage 2,248KB
  • 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
  • (8)bbcode_code
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete