Fóruns
The great place to discuss topics with other users
“last seen” status on profile pages
'
Join the Conversation
Resposta ao Post
2026-04-12 14:27:59
Hi developers 👋
Here is a clean, ready-to-use Smarty template snippet for Sngine to display a user's “last seen” status on profile pages (e.g., “Online now”, “Online 5 minutes ago”, etc.).
📌 Template File
/content/themes/default/templates/_profile.tpl
✅ Code (fully working)
{if !empty($profile['user_last_seen'])}
{assign var=now value=$smarty.now}
{assign var=last_seen value=$profile['user_last_seen']|date_format:"%s"}
{assign var=diff value=$now-$last_seen}
{assign var=minutes value=$diff/60|floor}
{assign var=hours value=$diff/3600|floor}
{assign var=days value=$diff/86400|floor}
<span class="badge bg-white text-dark border" style="font-size:11px;font-weight:500;margin-left:6px;">
{if $diff < 60}
<i class="fa fa-circle text-success" style="font-size:9px;"></i>
Online now
{elseif $minutes < 60}
<i class="fa fa-circle text-secondary" style="font-size:9px;"></i>
Online {$minutes} minute{if $minutes > 1}s{/if} ago
{elseif $hours < 24}
<i class="fa fa-circle text-secondary" style="font-size:9px;"></i>
Online {$hours} hour{if $hours > 1}s{/if} ago
{else}
<i class="fa fa-circle text-secondary" style="font-size:9px;"></i>
Online {$days} day{if $days > 1}s{/if} ago
{/if}
</span>
{/if}
⚙️ Notes
user_last_seenmust be available in$profile- Works with both:
- UNIX timestamp
- MySQL DATETIME (converted using
|date_format:"%s")
🔥 Behavior
< 60 seconds→ Online now< 60 minutes→ Online X minutes ago< 24 hours→ Online X hours ago> 24 hours→ Online X days ago
💡 Optional tweak
To extend “Online now” window (e.g., 2 minutes):
{if $diff < 120}
🚀 Result
- Real-time feeling UI
- Clean badge display
- No AJAX required
- Fully compatible with Sngine core
If anyone wants an AJAX real-time version (like Messenger / Facebook), I can provide a full implementation.