vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How can I create Friends widget on the home page (https://vborg.vbsupport.ru/showthread.php?t=282767)

KimK 05-11-2012 08:04 AM

How can I create Friends widget on the home page
 
1 Attachment(s)
Hello,
I need to create a widget on the home page that shows my friends like the widget on my profile. But I don't know how. Can anyone help me with this :)

I just need to know the code that I can use on the widget to show my friends (Maybe limit the friends widget to show 6 friends only).

I attached an image for the widget that I want to create one like it on the home page.

Thanks a lot,

kh99 05-11-2012 12:06 PM

You could show up to 6 random friends like this:

Code:

global $vbulletin;

$friends = $vbulletin->db->query_read_slave("SELECT
                                user.*, userlist.type, userlist.friend
                        FROM " . TABLE_PREFIX . "userlist AS userlist
                        INNER JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = userlist.relationid)
                        WHERE userlist.userid = " . $vbulletin->userinfo['userid'] . " AND userlist.type='buddy' AND userlist.friend='yes'
                        ORDER BY RAND()
                        LIMIT 6
                ");

while ($friend = $vbulletin->db->fetch_array($friends))
{
    $output .= '<a href="member.php?u=' . $friend['userid'] . '">' . $friend['username'] . "</a><br />\r\n";
}


KimK 05-11-2012 04:52 PM

Thank you kh99 for your reply. But could you please teach me how to add your code in widget on the home page. Because I created a new HTML static widget and I paste your code into the widget but when I browsed the Home Page I found the widget shows your code as it is. So I replaced the HTML Static widget with PHP Direct Execution widget and when I browsed the Home Page I found the date of today showing up only in the widget.

Can you help me please. I don't know where's the problem.

kh99 05-11-2012 05:52 PM

The php direct execution widget should work. By default the "configure" text area has a sample line of code that displays the date. You need to make sure you remove that.

KimK 05-12-2012 12:09 AM

Hi kh99,
You are absolutely right. I used php direct execution widget and I replaced the code for the date with your code and the widget works fine now. But is there any chance to list the names of my friends with their profile photos as in the friends widget in my profile (see the attached image in the first post)??

kh99 05-12-2012 12:29 AM

I've started working on something like that. Hopefully it won't take too long (and hopefully I'll actually finish :) ).

KimK 05-12-2012 10:19 AM

A million thanks to you Kh99. I wish you best of luck with the developing of this widget.
I'll keep monitoring your progress with joy!

s_cocis 11-14-2012 04:43 PM

very good !

CAG CheechDogg 09-30-2013 05:07 AM

To show all your friends online in a widget you would use this:

Code:

global $vbulletin;


if (!$vbulletin->userinfo['userid'])
{
}
else
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];

$buddys = $vbulletin->db->query_read("
SELECT
user.username, user.userid, user.lastactivity
FROM " . TABLE_PREFIX . "userlist AS userlist
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = userlist.relationid)
WHERE userlist.userid = {$vbulletin->userinfo['userid']} AND userlist.relationid = user.userid AND type = 'buddy' AND user.lastactivity > $datecut
ORDER BY username ASC
");
$output = '';


while ($buddy = $vbulletin->db->fetch_array($buddys))
{
$output .= ' <a href="member.php?' . $buddy['userid'] . '"> ' . $buddy['username'] . '</a> ';
}
if ($output != '')
{
/*$output = '<font color=#ff0000>Friends Online:</font>' . $output;*/

$template_hook['navtab_end'] .= '


';
}
}

If you see this kh99 would you be kind enough my Man to modify it so that it shows the markups to show the different user groups and comma list after each member ?

kh99 09-30-2013 11:45 AM

lol, I guess I never did finish this. Anyway, I haven't tried it but I think something like this should work:

Code:

global $vbulletin;


if (!$vbulletin->userinfo['userid'])
{
}
else
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];

$buddys = $vbulletin->db->query_read("
SELECT
user.username, user.userid, user.lastactivity, user.usergroupid, user.displaygroupid
FROM " . TABLE_PREFIX . "userlist AS userlist
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = userlist.relationid)
WHERE userlist.userid = {$vbulletin->userinfo['userid']} AND userlist.relationid = user.userid AND type = 'buddy' AND user.lastactivity > $datecut
ORDER BY username ASC
");
$output = '';
$separator = '';

while ($buddy = $vbulletin->db->fetch_array($buddys))
{
fetch_musername($buddy);
$output .= $separator . '<a href="member.php?' . $buddy['userid'] . '">' . $buddy['musername'] . '</a> ';
$separator = ', ';
}
if ($output != '')
{
/*$output = '<font color=#ff0000>Friends Online:</font>' . $output;*/

$template_hook['navtab_end'] .= '


';
}
}


CAG CheechDogg 09-30-2013 03:29 PM

I am gonnah cry from joy! lol ...Works great kh99 thank you once again !

Just a quick note, you must include at the very top of the code the following if not the widget will not show up.

global $vbulletin;

kh99 09-30-2013 03:33 PM

Quote:

Originally Posted by CAG CheechDogg (Post 2449020)
Just a quick note, you must include at the very top of the code the following if not the widget will not show up.

global $vbulletin;


Thanks, I added it above. I guess I missed it when I copy/pasted the code.

CAG CheechDogg 09-30-2013 04:14 PM

Yeerp, thank you kh99 once again my Man you rock!

jimsflies 10-24-2013 10:21 AM

Could this be turned into a forum block too? If so, how?


All times are GMT. The time now is 05:49 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.01109 seconds
  • Memory Usage 1,748KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (14)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