SHARE
TWEET

Blogger Profile gadget with avatars and post counts

mspotilas Jun 6th, 2012 5,443 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <style type="text/css">
  2. .author-line     {margin: 3px 0;}
  3. .author-avatar   {vertical-align:middle;}
  4. </style>
  5. <script type="text/javascript">
  6. //
  7. // Blog authors gadget, works like multi author profile gadget,
  8. // but with post counts and avatars, ordered most written first,
  9. // by MS-potilas 2012. See http://yabtb.blogspot.fi/2012/06/profile-gadget-with-avatars-and-post.html
  10. //
  11. // CONFIG:
  12. var maxUserNameLength = 42; // 0: don't cut, >4: cut usernames
  13. //
  14. var txtAuthorLine = '[image] [user] has written [count] [post]'; // can also use [#] (=position)
  15. //
  16. var sizeAvatar = 20;
  17. var cropAvatar = true;
  18. //
  19. var urlNoAvatar = "http://lh4.googleusercontent.com/-069mnq7DV_g/TvgRrBI_JaI/AAAAAAAAAic/Iot55vywnYw/s"+sizeAvatar+"/avatar_blue_m_96.png"; // http://www.blogger.com/img/avatar_blue_m_96.png resizeable
  20. // config end
  21.  
  22. function replaceAuthorVars(text, item, position)
  23. {
  24.   if(!item || !item.author) return text;
  25.   var author = item.author;
  26.  
  27.   var authorUri = "";
  28.   if(author.uri && author.uri.$t != "")
  29.     authorUri = author.uri.$t;
  30.  
  31.   var avaimg = urlNoAvatar;
  32.   if(author.gd$image && author.gd$image.src)
  33.     avaimg = author.gd$image.src;
  34.   if(avaimg == "http://img2.blogblog.com/img/b16-rounded.gif" && urlNoAvatar != "")
  35.     avaimg = urlNoAvatar;
  36.   var newsize="s"+sizeAvatar;
  37.   avaimg = avaimg.replace(/\/s\d\d+-c\//, "/"+newsize+"-c/");
  38.   if(cropAvatar) newsize+="-c";
  39.   avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, "/"+newsize+"/");
  40.  
  41.   var authorName = author.name.$t;
  42.   var imgcode = '<img class="author-avatar" height="'+sizeAvatar+'" width="'+sizeAvatar+'" title="'+authorName+'" src="'+avaimg+'" />';
  43.   if(authorUri!="") imgcode = '<a href="'+authorUri+'">'+imgcode+'</a>';
  44.  
  45.   if(maxUserNameLength > 3 && authorName.length > maxUserNameLength)
  46.     authorName = authorName.substr(0, maxUserNameLength-3) + "...";
  47.   var authorcode = authorName;
  48.   if(authorUri!="") authorcode = '<a class="profile-name-link" href="'+authorUri+'">'+authorcode+'</a>';
  49.  
  50.   text = text.replace('[user]', authorcode);
  51.   text = text.replace('[image]', imgcode);
  52.   text = text.replace('[#]', position);
  53.   text = text.replace('[count]', item.count);
  54.   if(item.count != 1)
  55.     text = text.replace('[post]', "posts");
  56.   else
  57.     text = text.replace('[post]', "post");
  58.   return text;
  59. }
  60.  
  61. var blauthors = {};
  62. var blndxbase = 1;
  63. function showAuthors(json) {
  64.   for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
  65.     var entry = json.feed.entry[i];
  66.     var authorUri = "";
  67.     if(entry.author[0].uri && entry.author[0].uri.$t != "")
  68.       authorUri = entry.author[0].uri.$t;
  69.  
  70.     var authorName = entry.author[0].name.$t;
  71.  
  72.     if(blauthors[authorName])
  73.       blauthors[authorName].count++;
  74.     else {
  75.       var aut = new Object();
  76.       aut.author = entry.author[0];
  77.       aut.count = 1;
  78.       blauthors[authorName] = aut;
  79.     }
  80.   }
  81.   if(json.feed.entry.length == 500) {
  82.     blndxbase += 500;
  83.     document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&start-index='+blndxbase+'&alt=json-in-script&callback=showAuthors"></'+'script>');
  84.     return;
  85.   }
  86.   var tuplear = [];
  87.   for(var key in blauthors) tuplear.push([key, blauthors[key]]);
  88.  
  89.   tuplear.sort(function(a, b) {
  90.     if(b[1].count-a[1].count)
  91.         return b[1].count-a[1].count;
  92.     return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;
  93.   });
  94.  
  95.   // output authors:
  96.   document.write('<di'+'v class="blog-author">');
  97.   for(var i = 0; i < tuplear.length ; i++) {
  98.     var item = tuplear[i][1];
  99.     document.write('<di'+'v class="author-line">');
  100.     document.write(replaceAuthorVars(txtAuthorLine, item, i+1));
  101.     document.write('</d'+'iv>');
  102.   }
  103.   document.write('</d'+'iv>');
  104. }  
  105. document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&alt=json-in-script&callback=showAuthors"></'+'script>');
  106. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top