The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Avatar in last posts on the home page

View previous topic View next topic Go down

Solved Avatar in last posts on the home page

Post by Niko on March 12th 2014, 6:28 pm

Hello guys,

as the title says, this is what I want to do Razz

I tried this code
Code:
$(function(){
 
  if(!window.localStorage) return;
 
  // Avatar by default
  var default_avatar= 'http://illiweb.com/fa/invision/pp-blank-thumb.png';
 
  // Time of cache, here : 24hrs * 60m * 60s * 1000ms so one day
  var caching_time= 24*60*60*1000;
 
  // Time of cache in case of error, here : 60s * 1000ms so one minute
  var caching_error= 60*1000;
 
  var set_avatar= function(id) {
  $('.mini_ava.member'+id).html('<img src="'+get_avatar(id)+'" />');
  };
 
  var get_avatar= function(id) {
  if(localStorage.getItem('t_ava'+id) < +new Date - caching_time || (localStorage.getItem('d_ava'+id)==default_avatar && localStorage.getItem('t_ava'+id) < +new Date - caching_error))
  {
  localStorage.setItem('d_ava'+id, default_avatar);
  $.get('/u'+id, function (d){
  localStorage.setItem('t_ava'+id,+new Date);
  localStorage.setItem('d_ava'+id, $('#profile-advanced-right .module:first div img:first,.forumline td.row1.gensmall:first > img, .frm-set.profile-view.left dd img,dl.left-box.details:first dd img, .row1 b .gen:first img, .real_avatar img',d).first().attr('src')||default_avatar);
  set_avatar(id);
  });
  }
  return localStorage.getItem('d_ava'+id);
  };
 
  var to_replace= {};
 
  $('dd.lastpost strong a.gensmall, .ipbtable tr td:last-child span strong a.gensmall, .table td.tcr strong a.gensmall, .forumline .row3.over strong a.gensmall').each(function(){
  to_replace[$(this).attr('href').substr(2)]= 1;
  $(this).closest('td,dd').prepend('<div class="mini_ava member'+$(this).attr('href').substr(2)+'"></div>');
  });
 
  for(i in to_replace)
  {
  set_avatar(i);
  };
 
  });

but actually I don't want to use cache, ecc.



so i tried this one:
Code:
$(document).on('ready', function() {
  $('.statused td.tcr').prepend('<div class="avatar-index"><div>');
  $('.statused td.tcr .avatar-index').each(function () {
  var profileUser = $(this).parent().children('span').children('strong').children('a').attr('href');
  $(this).html('<a href="' + profileUser + '" class="avatar-index-enlace"><img src="http://cdn1.iconfinder.com/data/icons/basicset/user_64.png" alt="No Avatar" /></a>');
  $(this).children('a').load(profileUser + '.profileavatars img');
  });
  });

but nothing..
can you help me?


Last edited by Niko! on March 12th 2014, 6:45 pm; edited 1 time in total

Niko
Hyperactive

Male Posts : 2163
Reputation : 93
Language : English, French, Italian, Spanish, Latin

https://www.translationscloud.com/?utm_source=forumotion&utm

Back to top Go down

Solved Re: Avatar in last posts on the home page

Post by Pizza Boi on March 12th 2014, 6:38 pm

Hi Very Happy

Did you consult this topic? http://help.forumotion.com/t131344-script-for-avatar-in-topics-and-recent-topics-widget

It should have a code for punBB if that is your version.

Regards,
Pizza Boi

Pizza Boi
Hyperactive

Male Posts : 2016
Reputation : 160
Language : French
Location : Pizza Hut!

http://redlustempire.forumtl.com/

Back to top Go down

Solved Re: Avatar in last posts on the home page

Post by Niko on March 12th 2014, 6:41 pm

that's for PhpBB2, or the same with the cache system Sad

Niko
Hyperactive

Male Posts : 2163
Reputation : 93
Language : English, French, Italian, Spanish, Latin

https://www.translationscloud.com/?utm_source=forumotion&utm

Back to top Go down

Solved Re: Avatar in last posts on the home page

Post by Pizza Boi on March 12th 2014, 6:43 pm

Hi Very Happy

That's not for phpBB2. That topic is made by iyaaz who also uses a punBB version Smile. The link posted next IS the one for phpBB2 lol.

@Ange Tuteur wrote:Hello iyaaz,

For lastpost, try this :
Administration Panel > Modules > Javascript codes management > Create a new script

Title : what you wish
Placement : in the homepage
Code:
          $(function(){
           
              if(!window.localStorage) return;
           
              // Avatar by default
                var default_avatar= 'http://illiweb.com/fa/invision/pp-blank-thumb.png';
           
              // Time of cache, here : 24hrs * 60m * 60s * 1000ms so one day
                var caching_time= 24*60*60*1000;
           
              // Time of cache in case of error, here : 60s * 1000ms so one minute
                var caching_error= 60*1000;
           
              var set_avatar= function(id) {
                    $('.mini_ava.member'+id).html('<img src="'+get_avatar(id)+'" />');
                };
           
              var get_avatar= function(id) {
                    if(localStorage.getItem('t_ava'+id) < +new Date - caching_time || (localStorage.getItem('d_ava'+id)==default_avatar && localStorage.getItem('t_ava'+id) < +new Date - caching_error))
                    {
                        localStorage.setItem('d_ava'+id, default_avatar);
                        $.get('/u'+id, function (d){
                            localStorage.setItem('t_ava'+id,+new Date);
                            localStorage.setItem('d_ava'+id, $('#profile-advanced-right .module:first div img:first,.forumline td.row1.gensmall:first > img, .frm-set.profile-view.left dd img,dl.left-box.details:first dd img, .row1 b .gen:first img, .real_avatar img',d).first().attr('src')||default_avatar);
                            set_avatar(id);
                        });
                    }
                    return localStorage.getItem('d_ava'+id);
                };
           
              var to_replace= {};
           
              $('dd.lastpost strong a.gensmall, .ipbtable tr td:last-child span strong a.gensmall, .table td.tcr strong a.gensmall, .forumline .row3.over strong a.gensmall').each(function(){
                    to_replace[$(this).attr('href').substr(2)]= 1;
                    $(this).closest('td,dd').prepend('<div class="mini_ava member'+$(this).attr('href').substr(2)+'"></div>');
                });
           
              for(i in to_replace)
                {
                    set_avatar(i);
                };
           
          });

Then add this CSS :
Display > colors > css stylesheet
Code:
  .mini_ava{
    float:left;
    }
    .mini_ava img{
    width:40px;
    height:40px;
    margin: 0 5px;
    }

Regards,
Pizza Boi

Pizza Boi
Hyperactive

Male Posts : 2016
Reputation : 160
Language : French
Location : Pizza Hut!

http://redlustempire.forumtl.com/

Back to top Go down

Solved Re: Avatar in last posts on the home page

Post by Niko on March 12th 2014, 6:46 pm

but that's the same i used (with the cache system) and I don't want to use cache Sad

btw, I solved by myself Mr. Green

Niko
Hyperactive

Male Posts : 2163
Reputation : 93
Language : English, French, Italian, Spanish, Latin

https://www.translationscloud.com/?utm_source=forumotion&utm

Back to top Go down

Solved Re: Avatar in last posts on the home page

Post by Ange Tuteur on March 15th 2014, 11:22 am

Since no solution was given => Garbaged

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum