vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Comparing Friend UserID (https://vborg.vbsupport.ru/showthread.php?t=286555)

Infinity101 08-12-2012 06:32 AM

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.

kh99 08-12-2012 01:53 PM

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.

Infinity101 08-12-2012 04:55 PM

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.

kh99 08-12-2012 05:06 PM

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?

Infinity101 08-13-2012 02:46 AM

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!

Infinity101 08-27-2012 05:13 AM

I continue to have difficulty with this. Any input? Thanks!

kh99 08-27-2012 11:29 AM

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.

Infinity101 08-27-2012 04:12 PM

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.


All times are GMT. The time now is 03:03 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.01084 seconds
  • Memory Usage 1,751KB
  • 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
  • (5)bbcode_php_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