SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: avenger on March 31, 2010, 09:13:46 AM

Title: latest member bloack with Avatar displayed
Post by: avenger on March 31, 2010, 09:13:46 AM
Hi,

can we have a module which shows latest members with their Avatar displayed.
Title: Re: latest member bloack with Avatar displayed
Post by: [SiNaN] on March 31, 2010, 12:15:35 PM
You can use this in a Custom PHP block:

SMF 1.1:

Code: [Select]
global $db_prefix, $context, $scripturl, $modSettings, $txt, $color_profile;

$limit = 5;

$request = db_query("
SELECT
m.ID_MEMBER, m.realName, m.dateRegistered, m.avatar,
a.ID_ATTACH, a.attachmentType, a.filename
FROM {$db_prefix}members as m
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = m.ID_MEMBER)
ORDER BY id_member DESC
LIMIT $limit", __FILE__, __LINE__);
$members = array();
$colorids = array();
while ($row = mysql_fetch_assoc($request))
{
if (!empty($row['ID_MEMBER']))
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
{
$sizes = url_image_size($row['avatar']);

if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
{
$row['avatar'] = '';
updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
}
}

$members[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'date' => timeformat($row['dateRegistered'], '%d %B'),
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
)
);
}
mysql_free_result($request);

if (empty($members))
{
echo '
', $txt['error_sp_no_members_found'];
return;
}

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($members as $k => $p)
{
if (!empty($color_profile[$p['id']]['link']))
$members[$k]['link'] = $color_profile[$p['id']]['link'];
}
}

echo '
<table class="sp_fullwidth">';

foreach ($members as $member)
echo '
<tr>
<td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
<img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" />' : '', '
</td>
<td>
', $member['link'], '<br />
', $member['date'], '
</td>
</tr>';

echo '
</table>';

SMF 2.0:

Code: [Select]
global $smcFunc, $context, $scripturl, $modSettings, $txt, $color_profile;

$limit = 5;

$request = $smcFunc['db_query']('','
SELECT
m.id_member, m.real_name, m.date_registered, m.avatar,
a.id_attach, a.attachment_type, a.filename
FROM {db_prefix}members AS m
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
ORDER BY id_member DESC
LIMIT {int:limit}',
array(
'limit' => $limit,
)
);
$members = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

$members[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'date' => timeformat($row['date_registered'], '%d %B'),
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($members))
{
echo '
', $txt['error_sp_no_members_found'];
return;
}

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($members as $k => $p)
{
if (!empty($color_profile[$p['id']]['link']))
$members[$k]['link'] = $color_profile[$p['id']]['link'];
}
}

echo '
<table class="sp_fullwidth">';

foreach ($members as $member)
echo '
<tr>
<td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
<img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" />' : '', '
</td>
<td>
', $member['link'], '<br />
', $member['date'], '
</td>
</tr>';

echo '
</table>';

Edit: Fixed a typo in SMF 2.0 code.
Title: Re: latest member bloack with Avatar displayed
Post by: avenger on April 02, 2010, 10:30:28 AM
Thank you Sinan,

tweaked it to show in ASC order.....thank you very much!
Title: Re: latest member bloack with Avatar displayed
Post by: [SiNaN] on April 02, 2010, 03:54:06 PM
You're welcome. ;)
Title: Re: latest member bloack with Avatar displayed
Post by: avenger on April 06, 2010, 01:39:20 AM
Hi sinan, sorry for the trouble, how can i display this list horizontally, what should i edit?

thanks.
Title: Re: latest member bloack with Avatar displayed
Post by: [SiNaN] on April 06, 2010, 01:47:10 AM
Code: (Find and Remove) [Select]
<tr>
Code: (Find and Remove) [Select]
</tr>
Code: (Find) [Select]
<table class="sp_fullwidth">
Code: (Replace) [Select]
<table class="sp_fullwidth"><tr>
Code: (Find) [Select]
</table>
Code: (Replace) [Select]
</tr></table>
Title: Re: latest member bloack with Avatar displayed
Post by: avenger on April 06, 2010, 02:10:49 AM
Thank you so much! :D

ok if anyone needs to display the latest member list horizontally in SMF 2 here is the edited code a big thank to Sinan.

Code: [Select]
global $smcFunc, $context, $scripturl, $modSettings, $txt, $color_profile;

   $limit = 5;

   $request = $smcFunc['db_query']('','
      SELECT
         m.id_member, m.real_name, m.date_registered, m.avatar,
         a.id_attach, a.attachment_type, a.filename
      FROM {db_prefix}members AS m
         LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
      ORDER BY posts DESC
      LIMIT {int:limit}',
      array(
         'limit' => $limit,
      )
   );
   $members = array();
   $colorids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if (!empty($row['id_member']))
         $colorids[$row['id_member']] = $row['id_member'];

      if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
      {
         $avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
         $avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
      }
      else
      {
         $avatar_width = '';
         $avatar_height = '';
      }

      $members[] = array(
         'id' => $row['id_member'],
         'name' => $row['real_name'],
         'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
         'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
         'date' => timeformat($row['date_registered'], '%d %B'),
         'avatar' => array(
            'name' => $row['avatar'],
            'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
            'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
            'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
         ),
      );
   }
   $smcFunc['db_free_result']($request);

   if (empty($members))
   {
      echo '
                        ', $txt['error_sp_no_members_found'];
      return;
   }

   if (!empty($colorids) && sp_loadColors($colorids) !== false)
   {
      foreach ($members as $k => $p)
      {
         if (!empty($color_profile[$p['id']]['link']))
            $members[$k]['link'] = $color_profile[$p['id']]['link'];
      }
   }

   echo '
                        <table class="sp_fullwidth"><tr>';

   foreach ($members as $member)
      echo '
                           
                              <td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
                                 <img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" />' : '', '
                              </td>
                              <td>
                                 ', $member['link'], '<br />
                                 ', $member['date'], '
                              </td>
                           ';

   echo '
                        </tr></table>';
Title: Re: latest member bloack with Avatar displayed
Post by: Divecall on May 25, 2010, 04:53:08 PM
I have a problem with this code (for SMF 2 RC 2 and SP 2.3.1)

When i click on the link (username) for the new member (shown in this block), it gives me a blak page and in the url-field frim my browser i can read
Code: [Select]
http://www.mysite/http://www.mysite.de/profile/?u=(any number)
why is the name of my site twice ?

can somebody help ?

thanks in advance...
Title: Re: latest member bloack with Avatar displayed
Post by: Nathaniel on May 25, 2010, 06:42:05 PM
Which code are you using, the code from Sinan's or from avenger's post?

Do you have any mods on your forum that alter the url's of your forum?
Title: Re: latest member bloack with Avatar displayed
Post by: Divecall on May 26, 2010, 12:53:40 PM
Thank you for your response.

i am using this code:
Code: [Select]
  global $smcFunc, $context, $scripturl, $modSettings, $txt, $color_profile;

   $limit = 7;

   $request = $smcFunc['db_query']('','
      SELECT
         m.id_member, m.real_name, m.date_registered, m.avatar,
         a.id_attach, a.attachment_type, a.filename
      FROM {db_prefix}members AS m
         LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
      ORDER BY id_member DESC
      LIMIT {int:limit}',
      array(
         'limit' => $limit,
      )
   );
   $members = array();
   $colorids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if (!empty($row['id_member']))
         $colorids[$row['id_member']] = $row['id_member'];

      if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
      {
         $avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
         $avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
      }
      else
      {
         $avatar_width = '';
         $avatar_height = '';
      }

      $members[] = array(
         'id' => $row['id_member'],
         'name' => $row['real_name'],
         'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
         'link' => '<a href="http://www.forexfabrik.de/' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
         'date' => timeformat($row['date_registered'], '%d %B'),
         'avatar' => array(
            'name' => $row['avatar'],
            'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
            'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
            'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
         ),
      );
   }
   $smcFunc['db_free_result']($request);

   if (empty($members))
   {
      echo '
                        ', $txt['error_sp_no_members_found'];
      return;
   }

   if (!empty($colorids) && sp_loadColors($colorids) !== false)
   {
      foreach ($members as $k => $p)
      {
         if (!empty($color_profile[$p['id']]['link']))
            $members[$k]['link'] = $color_profile[$p['id']]['link'];
      }
   }

   echo '
                        <table class="sp_fullwidth">';

   foreach ($members as $member)
      echo '
                           <tr>
                              <td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
                                 <img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" />' : '', '
                              </td>
                              <td>
                                 ', $member['link'], '<br />
                                 ', $member['date'], '
                              </td>
                           </tr>';

   echo '
                        </table>';

The only mod what change the Url and what i´m using is PrettyURL (sure, what else...really, you are a good one !)

Thank you in advance
Title: Re: latest member bloack with Avatar displayed
Post by: Nathaniel on May 26, 2010, 08:07:06 PM
Well, it looks like you changed the link/url part of that code.

Code: [Select]
'link' => '<a href="http://www.forexfabrik.de/' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
Should be:

Code: [Select]
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
Title: Re: latest member bloack with Avatar displayed
Post by: Divecall on May 27, 2010, 05:17:38 AM
well....this happend every time:

i copy the code in the edit-block area, all is ok.

when i click on preview, this piece of code
Code: [Select]
. $scripturl
was changing automatic to:
Code: [Select]
http://www.mysite.de/
Title: Re: latest member bloack with Avatar displayed
Post by: Nathaniel on May 27, 2010, 06:55:13 AM
I can't replicate that specific issue with previewing, for SP 2.3.2. It could be a bug with 2.3.1 that was fixed with 2.3.2, you may want to consider upgrading (for the other bugfixes as well of course).

Can you put in $scripturl and then get it to work without testing it with the previewing functionality? Ie. just save it, don't click on preview first.
Title: Re: latest member bloack with Avatar displayed
Post by: yakup on August 22, 2010, 11:31:50 AM
I have 150x200 sized avatars - would you please ID the changes in the above Horizontal block to be able to mess with the sizing output?  The current code outputs a very tiny image.

Thanks
Title: Re: latest member bloack with Avatar displayed
Post by: dsantana on September 15, 2010, 10:17:48 AM
You guys here are awesome!!!
Could someone tweak this code a bit so that it shows the last five (5) members that have joined?
I like the way the stock block in Simple Portal works, I would just like it horizontal.
Title: Re: latest member bloack with Avatar displayed
Post by: Ahmad Rasyid Ismail on September 18, 2010, 08:47:23 AM
Nice tips. Thanks. I've been looking for this.
Title: Re: latest member bloack with Avatar displayed
Post by: big red on December 03, 2010, 02:57:42 AM
     Hi

 I'm using the code (works well) provided by the former named "Sinan". I also use the default avatar mod here - http://custom.simplemachines.org/mods/index.php?mod=2665. But the default avatar "doesn't show" in the latest member block.

  Could someone have a look to see if the default avatar could be shown in the block?? I'm using latest versions of SMF & SP.

       Thanks!
Title: Re: latest member bloack with Avatar displayed
Post by: big red on December 06, 2010, 04:48:59 PM
   Anyone  :(
SimplePortal 2.3.8 © 2008-2024, SimplePortal