Advertisement
Guest User

Count Blogger posts per author

a guest
Jun 3rd, 2012
135
0
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 with post counts and avatars, ordered most written first,
  8. // by MS-potilas 2012. See http://yabtb.blogspot.com/
  9. //
  10. // CONFIG:
  11. var maxUserNameLength = 42; // 0: don't cut, >4: cut usernames
  12. //
  13. var txtAuthorLine = '[image] [user] has written [count] posts'; // can also use [#] (=position)
  14. //
  15. var sizeAvatar = 20;
  16. var cropAvatar = true;
  17. //
  18. 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
  19. // config end
  20. // for old IEs & IE modes:
  21. if(!Array.indexOf) {
  22.  Array.prototype.indexOf=function(obj) {
  23.   for(var i=0;i<this.length;i++) if(this[i]==obj) return i;
  24.   return -1;
  25. }}
  26. function replaceAuthorVars(text, item, position)
  27. {
  28.   if(!item || !item.author) return text;
  29.   var author = item.author;
  30.  
  31.   var authorUri = "";
  32.   if(author.uri && author.uri.$t != "")
  33.     authorUri = author.uri.$t;
  34.  
  35.   var avaimg = urlNoAvatar;
  36.   var bloggerprofile = "http://www.blogger.com/profile/";
  37.   if(author.gd$image && author.gd$image.src && (authorUri.substr(0,bloggerprofile.length) == bloggerprofile || authorUri == ""))
  38.     avaimg = author.gd$image.src;
  39.   else {
  40.     var parseurl = document.createElement('a');
  41.     if(authorUri != "") {
  42.       parseurl.href = authorUri;
  43.       avaimg = 'http://www.google.com/s2/favicons?domain=' + parseurl.hostname;
  44.     }
  45.   }
  46.   if(avaimg == "http://img2.blogblog.com/img/b16-rounded.gif" && urlNoAvatar != "")
  47.     avaimg = urlNoAvatar;
  48.   var newsize="s"+sizeAvatar;
  49.   avaimg = avaimg.replace(/\/s\d\d+-c\//, "/"+newsize+"-c/");
  50.   if(cropAvatar) newsize+="-c";
  51.   avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, "/"+newsize+"/");
  52.  
  53.   var authorName = author.name.$t;
  54.   var imgcode = '<img class="author-avatar" height="'+sizeAvatar+'" width="'+sizeAvatar+'" title="'+authorName+'" src="'+avaimg+'" />';
  55.   if(authorUri!="") imgcode = '<a href="'+authorUri+'">'+imgcode+'</a>';
  56.  
  57.   if(maxUserNameLength > 3 && authorName.length > maxUserNameLength)
  58.     authorName = authorName.substr(0, maxUserNameLength-3) + "...";
  59.   var authorcode = authorName;
  60.   if(authorUri!="") authorcode = '<a class="profile-name-link" href="'+authorUri+'">'+authorcode+'</a>';
  61.  
  62.   text = text.replace('[user]', authorcode);
  63.   text = text.replace('[image]', imgcode);
  64.   text = text.replace('[#]', position);
  65.   text = text.replace('[count]', item.count);
  66.   return text;
  67. }
  68.  
  69. var authors = {};
  70. var ndxbase = 1;
  71. function showAuthors(json) {
  72.   for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
  73.     var entry = json.feed.entry[i];
  74.     var authorUri = "";
  75.     if(entry.author[0].uri && entry.author[0].uri.$t != "")
  76.       authorUri = entry.author[0].uri.$t;
  77.  
  78.     var authorName = entry.author[0].name.$t;
  79.  
  80.     var hash=entry.author[0].name.$t + "-" + authorUri;
  81.     if(authors[hash])
  82.       authors[hash].count++;
  83.     else {
  84.       var aut = new Object();
  85.       aut.author = entry.author[0];
  86.       aut.count = 1;
  87.       authors[hash] = aut;
  88.     }
  89.   }
  90.   if(json.feed.entry.length == 500) {
  91.     ndxbase += 500;
  92.     document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&start-index='+ndxbase+'&alt=json-in-script&callback=showAuthors"></'+'script>');
  93.     return;
  94.   }
  95.   var tuplear = [];
  96.   for(var key in authors) tuplear.push([key, authors[key]]);
  97.  
  98.   tuplear.sort(function(a, b) {
  99.     if(b[1].count-a[1].count)
  100.         return b[1].count-a[1].count;
  101.     return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;
  102.   });
  103.  
  104.   // output authors:
  105.   for(var i = 0; i < tuplear.length ; i++) {
  106.     var item = tuplear[i][1];
  107.     document.write('<di'+'v class="author-line">');
  108.     document.write(replaceAuthorVars(txtAuthorLine, item, i+1));
  109.     document.write('</d'+'iv>');
  110.   }
  111. }  
  112. 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>');
  113. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement