Thursday 11 October 2012

Profile Gadget with avatars and post counts

,
Hii Friends Iam reposting this widget this widget has been posted by yabtb.You Can check the original post from here Yabtb-Widget This is especially for multi author blogs. In multi author blog the profile gadget is very simple looking. It only contains author names in <ul>/<li> list. There is "avatar" but that is the default blogger logo.





My multi author blog profile gadget looks like this:



It works on single author blogs, too, and one could customize it to look about the same as the default single author blog profile gadget, but I'll leave that for you as an exercise. :)

Installation is simple. Add HTML/Javascript gadget into your blog, and paste the following code there:

<style type="text/css">
.author-line     {margin: 3px 0;}
.author-avatar   {vertical-align:middle;}
</style>
<script type="text/javascript">
//
// Blog authors gadget, works like multi author profile gadget,
// but with post counts and avatars, ordered most written first,
// by MS-potilas 2012. See http://yabtb.blogspot.fi/2012/06/profile-gadget-with-avatars-and-post.html
//
// CONFIG:
var maxUserNameLength = 42; // 0: don't cut, >4: cut usernames
//
var txtAuthorLine = '[image] [user] has written [count] [post]'; // can also use [#] (=position)
//
var sizeAvatar = 20;
var cropAvatar = true;
//
var urlNoAvatar = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir1Kp8oA8QTFH7VlDnec8WYg6LnwHgZjrRjvM0D6OLyLkQYe_p4JNMEnH-okwMW_nAz_GpQHM9NijnGFzTXGpdRq8Sz2QhGTMQTyQcrPDXUhEBZXNXs7zw1QQUkd4s2nB3Z0IJOwQvm7Y/"+sizeAvatar+"/avatar_blue_m_96.png"; // http://www.blogger.com/img/avatar_blue_m_96.png resizeable
// config end

function replaceAuthorVars(text, item, position)
{
  if(!item || !item.author) return text;
  var author = item.author;

  var authorUri = "";
  if(author.uri && author.uri.$t != "")
    authorUri = author.uri.$t;

  var avaimg = urlNoAvatar;
  if(author.gd$image && author.gd$image.src)
    avaimg = author.gd$image.src;
  if(avaimg == "http://img2.blogblog.com/img/b16-rounded.gif" && urlNoAvatar != "")
    avaimg = urlNoAvatar;
  var newsize="s"+sizeAvatar;
  avaimg = avaimg.replace(/\/s\d\d+-c\//, "/"+newsize+"-c/");
  if(cropAvatar) newsize+="-c";
  avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, "/"+newsize+"/");

  var authorName = author.name.$t;
  var imgcode = '<img class="author-avatar" height="'+sizeAvatar+'" width="'+sizeAvatar+'" title="'+authorName+'" src="'+avaimg+'" />';
  if(authorUri!="") imgcode = '<a href="'+authorUri+'">'+imgcode+'</a>';

  if(maxUserNameLength > 3 && authorName.length > maxUserNameLength)
    authorName = authorName.substr(0, maxUserNameLength-3) + "...";
  var authorcode = authorName;
  if(authorUri!="") authorcode = '<a class="profile-name-link" href="'+authorUri+'">'+authorcode+'</a>';

  text = text.replace('[user]', authorcode);
  text = text.replace('[image]', imgcode);
  text = text.replace('[#]', position);
  text = text.replace('[count]', item.count);
  if(item.count != 1)
    text = text.replace('[post]', "posts");
  else
    text = text.replace('[post]', "post");
  return text;
}

var blauthors = {};
var blndxbase = 1;
function showAuthors(json) {
  for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
    var entry = json.feed.entry[i];
    var authorUri = "";
    if(entry.author[0].uri && entry.author[0].uri.$t != "")
      authorUri = entry.author[0].uri.$t;

    var authorName = entry.author[0].name.$t;

    if(blauthors[authorName])
      blauthors[authorName].count++;
    else {
      var aut = new Object();
      aut.author = entry.author[0];
      aut.count = 1;
      blauthors[authorName] = aut;
    }
  }
  if(json.feed.entry.length == 500) {
    blndxbase += 500;
    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>');
    return;
  }
  var tuplear = [];
  for(var key in blauthors) tuplear.push([key, blauthors[key]]);

  tuplear.sort(function(a, b) {
    if(b[1].count-a[1].count)
        return b[1].count-a[1].count;
    return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;
  });

  // output authors:
  document.write('<di'+'v class="blog-author">');
  for(var i = 0; i < tuplear.length ; i++) {
    var item = tuplear[i][1];
    document.write('<di'+'v class="author-line">');
    document.write(replaceAuthorVars(txtAuthorLine, item, i+1));
    document.write('</d'+'iv>');
  }
  document.write('</d'+'iv>');
}
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>');
</script>

 You can configure some things in the script: maximum user name length, author line template, avatar size, and is avatar cropped or streched. As always, you can also modify the CSS to your liking.

This was "thrown together" very quickly, but it works ok so I decided to publish it. Hope you like it.

Its Done GuYs...

0 comments to “Profile Gadget with avatars and post counts”

Post a Comment