Author Topic: [Tip/Trick]  How to add a default avatar to the Simple Portal Top Posters block  (Read 7291 times)


0 Members and 1 Guest are viewing this topic.

July 11, 2013, 11:16:02 PM

Offline Brian

  • Administrator
  • Jr. Member
  • *
  • Posts: 49
  • Country: us
  • Karma: 0
    • View Profile
[Tip/Trick] How to add a default avatar to the Simple Portal Top Posters block
« on: July 11, 2013, 11:16:02 PM »

(Register to disable this ad!)
"ns"

One of the omissions in the default blocks of Simple Portal is
what to do if the user doesn't have an avatar picture. Here's
a simple and easy fix, using the Top Posters block as an example:



Note: These modifications apply to Simple Portal v2.3.5

Step 1: Open \Sources\PortalBlocks.php and find:

Find: (line 445 or so)
Code: [Select]
function sp_topPoster($parameters, $id, $return_parameters = false)
{
global $smcFunc, $context, $scripturl, $modSettings, $txt, $color_profile;
Replace:
Code: [Select]
function sp_topPoster($parameters, $id, $return_parameters = false)
{
global $smcFunc, $context, $scripturl, $modSettings, $txt, $color_profile, $settings;
The above change adds the $settings variable to the global keyword. This is used to get the default theme URL address with $settings['default_theme_url']


Step 2: In PortalBlocks.php Find and replace the following:

Find: (Line 563 or so)
Code: [Select]
	foreach ($members as $member)
echo '
<tr>
<td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '"><img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" /></a>' : '', '
</td>
<td>
', $member['link'], '<br />
', $member['posts'], ' ', $txt['posts'], '
</td>
</tr>';

echo '
</table>';
}

Replace:
Code: [Select]
	foreach ($members as $member)
    {
                if (empty($member['avatar']['href']))
                $member['avatar']['href'] = $settings['default_theme_url'] . '/images/sp/default_avatar.gif';
echo '
<tr>
<td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '"><img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" /></a>' : '', '
</td>
<td>
', $member['link'], '<br />
', $member['posts'], ' ', $txt['posts'], '
</td>
</tr>';
    }
echo '
</table>';
}
The above simply checks if the avatar URL ( $member['avatar']['href'] ) is empty; if it is, it changes it to point to the default_avatar.gif image. Note the added open { and close } was needed to encapsulate the foreach construct since it now included a conditional if construct inside that loop.

Step 3: Download the attached sample default_avatar.gif and upload your default_avatar.gif image to: /Themes/default/images/sp/default_avatar.gif

Done!

There are a number of blocks in Simple Portal that this modification could be applied to. I will explore making the necessary changes to those blocks in the near future.  8)
« Last Edit: June 27, 2014, 11:15:31 AM by Brian »

July 12, 2013, 12:54:04 AMReply #1

Offline Brian

  • Administrator
  • Jr. Member
  • *
  • Posts: 49
  • Country: us
  • Karma: 0
    • View Profile
Re: How to add a default avatar to the Simple Portal Top Posters block
« Reply #1 on: July 12, 2013, 12:54:04 AM »
Here's the modification for the Forum Staff block:

Open up \Sources\PortalBlocks.php

Find: (Line 2226)
Code: [Select]
function sp_staff($parameters, $id, $return_parameters = false)
{
global $smcFunc, $sourcedir, $scripturl, $modSettings, $color_profile;
Replace:
Code: [Select]
function sp_staff($parameters, $id, $return_parameters = false)
{
global $smcFunc, $sourcedir, $scripturl, $modSettings, $color_profile, $settings;

Find: (Line 2334)
Code: [Select]
	foreach ($staff_list as $staff)
echo '
<tr>
<td class="sp_staff sp_center">', !empty($staff['avatar']['href']) ? '
<a href="' . $scripturl . '?action=profile;u=' . $staff['id'] . '"><img src="' . $staff['avatar']['href'] . '" alt="' . $staff['name'] . '" width="40" /></a>' : '', '
</td>
<td class="sp_staff_info', $staff_count != ++$count ? ' sp_staff_divider' : '', '">
', sp_embed_image($icons[$staff['type']]), ' ', $staff['link'], '<br />
', $staff['group'], '
</td>
</tr>';

echo '
</table>';
}

Replace:
Code: [Select]
	foreach ($staff_list as $staff)
        {
                if (empty($staff['avatar']['href']))
                $staff['avatar']['href'] = $settings['default_theme_url'] . '/images/sp/default_avatar.gif';
echo '
<tr>
<td class="sp_staff sp_center">', !empty($staff['avatar']['href']) ? '
<a href="' . $scripturl . '?action=profile;u=' . $staff['id'] . '"><img src="' . $staff['avatar']['href'] . '" alt="' . $staff['name'] . '" width="40" /></a>' : '', '
</td>
<td class="sp_staff_info', $staff_count != ++$count ? ' sp_staff_divider' : '', '">
', sp_embed_image($icons[$staff['type']]), ' ', $staff['link'], '<br />
', $staff['group'], '
</td>
</tr>';
        }
echo '
</table>';
}
« Last Edit: November 16, 2013, 07:26:53 AM by Brian »

July 12, 2013, 01:21:07 AMReply #2

Offline Brian

  • Administrator
  • Jr. Member
  • *
  • Posts: 49
  • Country: us
  • Karma: 0
    • View Profile
Re: How to add a default avatar to the Simple Portal Top Posters block
« Reply #2 on: July 12, 2013, 01:21:07 AM »
User Info Block:

Open up \Sources\PortalBlocks.php

Find: (Line 175)
Code: [Select]
		if (!empty($member_info['avatar']['image']))
echo '
<a href="', $scripturl, '?action=profile;u=', $member_info['id'], '">', $member_info['avatar']['image'], '</a><br /><br />';

Replace:
Code: [Select]
        if (empty($member_info['avatar']['image']))
                $member_info['avatar']['image'] = '<img src="' . $settings['default_theme_url'] . '/images/sp/default_avatar.gif'. '">';
echo '
<a href="', $scripturl, '?action=profile;u=', $member_info['id'], '">', $member_info['avatar']['image'], '</a><br /><br />';
« Last Edit: November 16, 2013, 07:26:37 AM by Brian »

July 12, 2013, 02:17:55 AMReply #3

Offline Brian

  • Administrator
  • Jr. Member
  • *
  • Posts: 49
  • Country: us
  • Karma: 0
    • View Profile
Re: How to add a default avatar to the Simple Portal Top Posters block
« Reply #3 on: July 12, 2013, 02:17:55 AM »
Top Member Stats:

Open up \Sources\PortalBlocks.php

Find: (Line 995)
Code: [Select]
	foreach ($members as $member)
{
echo '
<tr>
<td class="sp_top_poster sp_center">', !empty($member['avatar']['href']) ? '
<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '"><img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" /></a>' : '', '
</td>
<td>
', $member['link'], '<br />', $member['output'], '
</td>
</tr>';
}
echo '
</table>';

}

Replace:
Code: [Select]
	foreach ($members as $member)
{
        if (empty($member['avatar']['href']))
                {
                $member['avatar']['href'] = $settings['default_theme_url'] . '/images/sp/default_avatar.gif';
                }
echo '
<tr>
<td class="sp_top_poster sp_center">
<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '"><img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" /></a>
</td>
<td>
', $member['link'], '<br />', $member['output'], '
</td>
</tr>';
}
echo '
</table>';

}
« Last Edit: November 16, 2013, 07:39:01 AM by Brian »

November 16, 2013, 07:34:21 AMReply #4

Offline Brian

  • Administrator
  • Jr. Member
  • *
  • Posts: 49
  • Country: us
  • Karma: 0
    • View Profile
Re: How to add a default avatar to the Simple Portal Top Posters block
« Reply #4 on: November 16, 2013, 07:34:21 AM »
If you don't want to make the changes yourself, you can download the attached PortalBlocks.php file and copy it over the existing file in your \Sources folder.

Remember - this file only works with Simple Portal v2.3.5.
* PortalBlocks.php
(123.04 kB ~ Downloads: 188)
« Last Edit: November 16, 2013, 07:36:36 AM by Brian »

Click here for $50 off!
Click here for $50 off!
 

Click here for $50 off!
Click here for $50 off!