News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Avatars on Board and/or MessageIndex

Started by Pipke, April 05, 2016, 06:27:00 PM

Previous topic - Next topic

Pipke

Link to the mod

Avatars on Board and/or MessageIndex

For SMF 2.0.x
Same mod for SMF 2.1.* can be found here

This mod will display the avatar of last poster in Board(Child)Index and or the avatar of first and or last poster of topics in MessageIndex.
Extra setting: Display topic starter time in MessageIndex.


Hook install

Tested only with the SMF default theme...but should work with other themes aswell!

License

* This SMF modification is subject to the BSD 2-Clause License
* Which can be found here

Settings

- Admin->Configuration->Modification Settings->Avatars on Board/MessageIndex

Languages

- English/utf8
- Spanish_latin/utf8 by Rock Lee

Changelog

Version 2.0.17 - Jan 3, 2020
- Fixed: Script proxy for external avatar urls

Version 2.0 - Dec 28, 2017
- Fixed: Illegal string offset 'value' (due > PHP 7.1)
- Added: Proxy for external avatar urls

Version 1.9 - May 18, 2017
- Fixed: More Undefined index and Undefined offset errors

Version 1.8 - Jan 10, 2017
- Fixed: Admin setting "Show avatar of last poster on the BoardIndex"

Version 1.7 - Sep 01, 2016
- Fixed: The 'abm_id={}' text in subject column when avatar path is fault or been removed from server

Version 1.6 - Aug 20, 2016
- Fixed: Mod messed up array for template when Board has Child in Child and deeper Child etc.
- Fixed: The 'abm_id={}' text in last column when avatar path is fault or been removed from server

Version 1.5 - Jul 14, 2016
- Fixed: Last post link icon to topic was unclickable
- Fixed: The 'abm' text in last column on other costum themes!
- Fixed: Database error, given array of integer values is empty
- Fixed: Some undefined index errors

Version 1.4 - Jul 12, 2016
- New: Fully 'Hook' Mod
- Fixed: Query messed up the array output when id of poster was quest or deleted/removed
- Added: You can set the size of the avatars
- Added: You can change the width of the output column to make room for avatar
- Added: Avatar stays in center/equal to column/output text
- Added: SMF 'global' avatars can be set with round borders!
- Added: Avatars now display also on unread posts and new replies index

Version 1.0 - April 03, 2016
- Initial Release
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

-Rock Lee-

A really great job this change had something different when you need it but I think more than one will leave you the translation into Latin Spanish I hope you help :D


Regards!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

JBlaze

Jason Clemons
Former Team Member 2009 - 2012

OCJ

I have a problem but maybe it is because I store member avatars as png files in another folder. That is an accepted method on SMF.

You can see the screenshot with missing avatars replaced by question mark.

It was also showing my avatar instead of the last poster inside the board with view of topics list.

Pipke

Quote from: igirisjin on April 05, 2016, 11:15:04 PM
I have a problem but maybe it is because I store member avatars as png files in another folder. That is an accepted method on SMF.

You can see the screenshot with missing avatars replaced by question mark.

It was also showing my avatar instead of the last poster inside the board with view of topics list.

ill check that later if i can do something about that.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

OCJ

It was given quite a bit of promotion as a way of improving performance - several posts on the site about it.

This is in the SMF wiki - official. The first suggestion:
http://wiki.simplemachines.org/smf/Performance_enhancements

QuoteBasic Improvements

Just about anyone can make use of these optimizations, regardless of how much control you have over your server. The first few options here can have an extremely dramatic effect on your server's performance, I've sorted them roughly in order of potential impact.
Move your uploaded avatars directory


In the administration panel, go to Attachments and Avatars, and then go to Avatar settings.

For Upload avatars to... select: Specific directory... For Upload directory: put in the raw, publicly accessible server directory you want them added to ie /var/www/yoursite/docs/forums/avs

So assuming /docs was your webroot, you would put /forums/avs for your upload URL. Do not do what I did and make it a subdirectory of your main avatars directory, SMF still handles it like an attachment directory for some reason so if someone uploads a .png avatar, someone else decides to use it and the first person replaces it with a .jpg avatar, the first will be deleted.

The benefit of this borders on the ridiculous
. Every single avatar load is another php call, which loads a session, the user's settings and permissions, the board and its theme. In addition, two additional calls to the database are made to load the avatar itself, and to increment the view counter. So not only are you reducing the processor load on your server, but you are also reducing your database load. If five different avatars are displayed on a page, that's five additional php calls and dozens of database queries getting made.

nend

Quote from: Pipke on April 06, 2016, 03:05:04 AM
Quote from: igirisjin on April 05, 2016, 11:15:04 PM
I have a problem but maybe it is because I store member avatars as png files in another folder. That is an accepted method on SMF.

You can see the screenshot with missing avatars replaced by question mark.

It was also showing my avatar instead of the last poster inside the board with view of topics list.

ill check that later if i can do something about that.

Take a look here.
http://www.simplemachines.org/community/index.php?topic=232539.msg3841891#msg3841891

I  shared this awhile back with VB, his mod does attachments, my site does that along with embeds, avatars and images. It is a fallback method. ;)

Pipke

Quote from: igirisjin on April 05, 2016, 11:15:04 PM
It was also showing my avatar instead of the last poster inside the board with view of topics list.

Fixed this with update. Latest version is now 1.1
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

morris91

even with 1.1 i still get blank avator images on my main board. in the categorys its fine but on the index this still happends.


Pipke

Quote from: morris91 on April 06, 2016, 02:53:50 PM
even with 1.1 i still get blank avator images on my main board. in the categorys its fine but on the index this still happends.



can you post your website url so i can take look whats going on?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Pipke

Quote from: Pipke on April 06, 2016, 03:05:04 AM
Quote from: igirisjin on April 05, 2016, 11:15:04 PM
I have a problem but maybe it is because I store member avatars as png files in another folder. That is an accepted method on SMF.

You can see the screenshot with missing avatars replaced by question mark.

ill check that later if i can do something about that.

fixed, latest version is now 1.2
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

morris91

Quote from: Pipke on April 06, 2016, 02:57:10 PM
Quote from: morris91 on April 06, 2016, 02:53:50 PM
even with 1.1 i still get blank avator images on my main board. in the categorys its fine but on the index this still happends.



can you post your website url so i can take look whats going on?

http://ultrastunting.net/index.php [nofollow]

Also updated to 1.2.

DSystem

Brazil Portuguese translation attached.

DSystem

With this amendment the mod is compatible with as many themes.

<search position="after"><![CDATA[<a href="', $topic['last_post']['href']]]></search>
<add><![CDATA[';
if (($modSettings['abm_messageindex'] == 'last') || ($modSettings['abm_messageindex'] == 'both'))
{
if ((filter_var($topic['last_post']['member']['avatar'], FILTER_VALIDATE_URL) === false) || (empty($topic['last_post']['member']['avatar'])))
echo'', $topic['last_post']['member']['id'] ? '<a href="' .$topic['last_post']['member']['href']. '">' : '', '<img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'.$settings['images_url']. '/abm_avatar.gif" alt="[?]" />', $topic['last_post']['member']['id'] ? '</a>' : '';
else
echo'<a href="' ,$topic['last_post']['member']['href'], '"><img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'. $topic['last_post']['member']['avatar'].'" alt="[?]" /></a>';
}
echo']]></add>
</operation>


After that had no additional themes installation error. ;)

OCJ

Thanks, its an improvement. Not quite there yet.

The topic poster is displaying a [?]  on the left, and previous members also same rather than a default avatar.

OCJ

And something else. I thought the display was a bit odd as only 8 topics displayed. On the second page it was almost blank. After uninstall it was fine again.

morris91

Quote from: DSystem on April 06, 2016, 08:49:26 PM
With this amendment the mod is compatible with as many themes.

<search position="after"><![CDATA[<a href="', $topic['last_post']['href']]]></search>
<add><![CDATA[';
if (($modSettings['abm_messageindex'] == 'last') || ($modSettings['abm_messageindex'] == 'both'))
{
if ((filter_var($topic['last_post']['member']['avatar'], FILTER_VALIDATE_URL) === false) || (empty($topic['last_post']['member']['avatar'])))
echo'', $topic['last_post']['member']['id'] ? '<a href="' .$topic['last_post']['member']['href']. '">' : '', '<img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'.$settings['images_url']. '/abm_avatar.gif" alt="[?]" />', $topic['last_post']['member']['id'] ? '</a>' : '';
else
echo'<a href="' ,$topic['last_post']['member']['href'], '"><img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'. $topic['last_post']['member']['avatar'].'" alt="[?]" /></a>';
}
echo']]></add>
</operation>


After that had no additional themes installation error. ;)

i thought i would try this amendment . get errors but installed anyway. everything works still but the icon problem i stated above now no longer appear at all.

JerzyLS


JerzyLS

Okay, here is the solution for child boards.

Themes/default/MessageIndex.template

Find:

/* The board's and children's 'last_post's have:
time, timestamp (a number that represents the time.), id (of the post), topic (topic id.),
link, href, subject, start (where they should go for the first unread post.),
and member. (which has id, name, link, href, username in it.) */
if (!empty($board['last_post']['id']))
echo '
<p><strong>', $txt['last_post'], '</strong>  ', $txt['by'], ' ', $board['last_post']['member']['link'], '<br />
', $txt['in'], ' ', $board['last_post']['link'], '<br />
', $txt['on'], ' ', $board['last_post']['time'],'
</p>';

echo '
</td>
</tr>';


And replace:

/* The board's and children's 'last_post's have:
time, timestamp (a number that represents the time.), id (of the post), topic (topic id.),
link, href, subject, start (where they should go for the first unread post.),
and member. (which has id, name, link, href, username in it.) */
if (!empty($board['last_post']['id']))
$abm_img_style = 'width:42px; height: 42px; float:left; margin-right: 6px; padding: 0px;';
if (!empty($modSettings['abm_boardindex']))
{
if ((filter_var($board['last_post']['member']['avatar'], FILTER_VALIDATE_URL) === false) || (empty($board['last_post']['member']['avatar'])))
echo'', $board['last_post']['member']['id'] ? '<a href="' .$board['last_post']['member']['href']. '">' : '', '<img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'.$settings['images_url']. '/abm_avatar.gif" alt="[?]" />', $board['last_post']['member']['id'] ? '</a>' : '';
else
echo'<a href="' ,$board['last_post']['member']['href'], '"><img style="',$abm_img_style,' border-radius:',$modSettings['abm_avatar_layout'] ? '50' : '0','%;" src="'. $board['last_post']['member']['avatar'].'" alt="[?]" /></a>';
}
echo '
<p><strong>', $txt['last_post'], '</strong>  ', $txt['by'], ' ', $board['last_post']['member']['link'], '<br />
', $txt['in'], ' ', $board['last_post']['link'], '<br />
', $txt['on'], ' ', $board['last_post']['time'],'
</p>';

echo '
</td>
</tr>';


JerzyLS

Some errors in logs:

8: Undefined variable: abm_img_style
/Themes/default/BoardIndex.template.php
Line: 376

356:
	
	
	
	
// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
357:
	
	
	
	
echo 
'
358:
	
	
	
	
	
<strong><a href="'
$scripturl'?action=recent">'$txt['recent_posts'], '</a></strong>
359:
	
	
	
	
	
<p id="infocenter_onepost" class="middletext">
360:
	
	
	
	
	
	
'
$txt['recent_view'], ' &quot;'$context['latest_post']['link'], '&quot; '$txt['recent_updated'], ' ('$context['latest_post']['time'], ')<br />
361:
	
	
	
	
	
</p>'
;
362:
	
	
	
}
363:
	
	
	
// Show lots of posts.
364:
	
	
	
elseif (!empty(
$context['latest_posts']))
365:
	
	
	
{
366:
	
	
	
	
echo 
'
367:
	
	
	
	
	
<dl id="ic_recentposts" class="middletext">'
;
368:
	

369:
	
	
	
	
/* Each post in latest_posts has:
370:
	
	
	
	
	
	
board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
371:
	
	
	
	
	
	
subject, short_subject (shortened with...), time, link, and href. */
372:
	
	
	
	
foreach (
$context['latest_posts'] as $post)
373:
	
	
	
	
	
echo 
'
374:
	
	
	
	
	
	
<dt><strong>'
$post['link'], '</strong> '$txt['by'], ' '$post['poster']['link'], ' ('$post['board']['link'], ')</dt>
375:
	
	
	
	
	
	
<dd>'
$post['time'], '</dd>';
==>
376:
	
	
	
	
echo 
'
377:
	
	
	
	
	
</dl>'
;
378:
	
	
	
}
379:
	
	
	
echo 
'
380:
	
	
	
	
</div>'
;
381:
	
	
}


8: Undefined variable: board
Themes/default/BoardIndex.template.php
Linia: 375

358:
	
	
	
	
	
<
strong><a href="', $scripturl, '?action=recent">', $txt['recent_posts'], '</a></strong>
359:
	
	
	
	
	
<
p id="infocenter_onepost" class="middletext">
360:
	
	
	
	
	
	
', $txt['recent_view'], ' &quot;', $context['latest_post']['link'], '&quot', $txt['recent_updated'], ' (', $context['latest_post']['time'], ')<br />
361:
	
	
	
	
	
</
p>';
362:
	
	
	
}
363:
	
	
	
// Show lots of posts.
364:
	
	
	
elseif (!empty($context['
latest_posts']))
365:
	
	
	
{
366:
	
	
	
	
echo '
367:
	
	
	
	
	
<
dl id="ic_recentposts" class="middletext">';
368:
	

369:
	
	
	
	
/* Each post in latest_posts has:
370:
	
	
	
	
	
	
board (with an id, name, and link.), topic (the topic'
s id.), poster (with idname, and link.),
371:
	
	
	
	
	
	
subjectshort_subject (shortened with...), timelink, and href. */
372:
	
	
	
	
foreach (
$context['latest_posts'] as $post)
373:
	
	
	
	
	
echo 
'
374:
	
	
	
	
	
	
<dt><strong>'
$post['link'], '</strong> '$txt['by'], ' '$post['poster']['link'], ' ('$post['board']['link'], ')</dt>
==>375:
	
	
	
	
	
	
<dd>'
$post['time'], '</dd>';
376:
	
	
	
	
echo 
'
377:
	
	
	
	
	
</dl>'
;
378:
	
	
	
}
379:
	
	
	
echo 
'
380:
	
	
	
	
</div>'
;
381:
	
	
}

Advertisement: