SimplePortal

Customization => Custom Coding => Topic started by: Dallape on February 04, 2010, 05:33:46 PM

Title: User Stats Block Code
Post by: Dallape on February 04, 2010, 05:33:46 PM
I need php code of this block, can someone give it to me? :)
Title: Re: User Stats Block Code
Post by: Nathaniel on February 05, 2010, 11:35:54 PM
You should have the code within your Sources/PortalBlocks.template.php file. Search for the 'sp_userInfor' function.It should be the first function in that file.
Title: Re: User Stats Block Code
Post by: Dallape on February 07, 2010, 07:06:12 PM
Thanks, I have a code now. Can you tell me how to choose which member will be displayed. For example I want to display members
http://mysite.net/index.php?action=profile;u=1
and
http://mysite.net/index.php?action=profile;u=127

???
Title: Re: User Stats Block Code
Post by: Nathaniel on February 07, 2010, 07:45:31 PM
Well, that will require some diffferent code. That block is only intended to show the user information about themselves.

Try the code below in a custom php block.
Code: [Select]

global $context, $txt, $scripturl, $memberContext, $modSettings, $user_info, $color_profile;

$users = array(1, 127);
foreach ($users as $user_id)
{
loadMemberData($user_id);
loadMemberContext($user_id);

$member_info = $memberContext[$user_id];

if (sp_loadColors($member_info['id']) !== false)
$member_info['colored_name'] = $color_profile[$member_info['id']]['colored_name'];

$member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];

echo '
<strong>', !empty($member_info['colored_name']) ? $member_info['colored_name'] : $member_info['name'], '</strong>
<br /><br />';

if (!empty($member_info['avatar']['image']))
echo '
', $member_info['avatar']['image'], '<br /><br />';

if (!empty($member_info['group']))
echo '
', $member_info['group'], '<br />';
else
echo '
', $member_info['post_group'], '<br />';

echo '
', $member_info['group_stars'], '<br />';

echo '
<br />
<ul class="sp_list">';

echo '
<li>', sp_embed_image('dot'), ' <strong>', $txt[21], ':</strong> ', $member_info['posts'], '</li>';

if (!empty($modSettings['karmaMode']))
{
echo '
<li>', sp_embed_image('dot'), ' <strong>', $modSettings['karmaLabel'], '</strong> ';

if ($modSettings['karmaMode'] == 1)
echo $member_info['karma']['total'];
elseif ($modSettings['karmaMode'] == 2)
echo '+', $member_info['karma']['good'], '/-', $member_info['karma']['bad'];

echo '</li>';
}

if (allowedTo('pm_read'))
{
echo '
<li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usertmessage'], ':</strong> <a href="', $scripturl, '?action=pm">', $context['user']['messages'], '</a></li>
<li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usernmessage'], ':</strong> ', $context['user']['unread_messages'], '</li>';
}

echo '
<li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unread">', $txt['unread_topics_visit'], '</a></li>
<li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unreadreplies">', $txt['unread_replies'], '</a></li>';

echo '
</ul>
<br />';

echo '
', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=profile">', $txt[79], '</a> ', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', $txt[108], '</a><br /><br />';
}
Title: Re: User Stats Block Code
Post by: ccbtimewiz on February 07, 2010, 07:53:32 PM
Nathaniel, that's a bit dirty to do (calling both loadMemberData and loadMemberContext) in a loop. You're just calling data not needed over and over again.

You could just lap up all the IDs you will load before. Eg...

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

   $users = array(1, 127);
   loadMemberData($users);

   foreach ($users as $user_id)
   {
      loadMemberContext($user_id);

      $member_info = $memberContext[$user_id];

      if (sp_loadColors($member_info['id']) !== false)
         $member_info['colored_name'] = $color_profile[$member_info['id']]['colored_name'];

      $member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];

      echo '
                           <strong>', !empty($member_info['colored_name']) ? $member_info['colored_name'] : $member_info['name'], '</strong>
                           <br /><br />';

      if (!empty($member_info['avatar']['image']))
         echo '
                           ', $member_info['avatar']['image'], '<br /><br />';

      if (!empty($member_info['group']))
         echo '
                           ', $member_info['group'], '<br />';
      else
         echo '
                           ', $member_info['post_group'], '<br />';

      echo '
                           ', $member_info['group_stars'], '<br />';

      echo '
                           <br />
                           <ul class="sp_list">';

      echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $txt[21], ':</strong> ', $member_info['posts'], '</li>';

      if (!empty($modSettings['karmaMode']))
      {
         echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $modSettings['karmaLabel'], '</strong> ';

         if ($modSettings['karmaMode'] == 1)
            echo $member_info['karma']['total'];
         elseif ($modSettings['karmaMode'] == 2)
            echo '+', $member_info['karma']['good'], '/-', $member_info['karma']['bad'];

         echo '</li>';
      }

      if (allowedTo('pm_read'))
      {
         echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usertmessage'], ':</strong> <a href="', $scripturl, '?action=pm">', $context['user']['messages'], '</a></li>
                              <li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usernmessage'], ':</strong> ', $context['user']['unread_messages'], '</li>';
      }

      echo '
                              <li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unread">', $txt['unread_topics_visit'], '</a></li>
                              <li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unreadreplies">', $txt['unread_replies'], '</a></li>';

      echo '
                           </ul>
                           <br />';

      echo '
                           ', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=profile">', $txt[79], '</a> ', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', $txt[108], '</a><br /><br />';
   }
Title: Re: User Stats Block Code
Post by: Dallape on February 07, 2010, 11:39:34 PM
Nathaniel, that's a bit dirty to do (calling both loadMemberData and loadMemberContext) in a loop. You're just calling data not needed over and over again.

You could just lap up all the IDs you will load before. Eg...

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

   $users = array(1, 127);
   loadMemberData($users);

   foreach ($users as $user_id)
   {
      loadMemberContext($user_id);

      $member_info = $memberContext[$user_id];

      if (sp_loadColors($member_info['id']) !== false)
         $member_info['colored_name'] = $color_profile[$member_info['id']]['colored_name'];

      $member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];

      echo '
                           <strong>', !empty($member_info['colored_name']) ? $member_info['colored_name'] : $member_info['name'], '</strong>
                           <br /><br />';

      if (!empty($member_info['avatar']['image']))
         echo '
                           ', $member_info['avatar']['image'], '<br /><br />';

      if (!empty($member_info['group']))
         echo '
                           ', $member_info['group'], '<br />';
      else
         echo '
                           ', $member_info['post_group'], '<br />';

      echo '
                           ', $member_info['group_stars'], '<br />';

      echo '
                           <br />
                           <ul class="sp_list">';

      echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $txt[21], ':</strong> ', $member_info['posts'], '</li>';

      if (!empty($modSettings['karmaMode']))
      {
         echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $modSettings['karmaLabel'], '</strong> ';

         if ($modSettings['karmaMode'] == 1)
            echo $member_info['karma']['total'];
         elseif ($modSettings['karmaMode'] == 2)
            echo '+', $member_info['karma']['good'], '/-', $member_info['karma']['bad'];

         echo '</li>';
      }

      if (allowedTo('pm_read'))
      {
         echo '
                              <li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usertmessage'], ':</strong> <a href="', $scripturl, '?action=pm">', $context['user']['messages'], '</a></li>
                              <li>', sp_embed_image('dot'), ' <strong>', $txt['sp-usernmessage'], ':</strong> ', $context['user']['unread_messages'], '</li>';
      }

      echo '
                              <li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unread">', $txt['unread_topics_visit'], '</a></li>
                              <li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=unreadreplies">', $txt['unread_replies'], '</a></li>';

      echo '
                           </ul>
                           <br />';

      echo '
                           ', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=profile">', $txt[79], '</a> ', sp_embed_image('arrow'), ' <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', $txt[108], '</a><br /><br />';
   }

Yes, that's it... One more thing, now is displaying stats: Username, avatar, membergroup star, posts, karma, total messages, new messages, Recent  Unread Topics, Updated Topics profile and log out link. Can it be changed like on this picture:
(http://ultraphoto.org/images/tlyyxcxqn5amz01e5i.jpg)

And the members are one under other, and i need  one along other. How to do that? To be more specific, I need just like this picture.
(http://ultraphoto.org/images/xxu66ybskbkodjynapm.jpg)
SimplePortal 2.3.8 © 2008-2024, SimplePortal