Gravatar to recent comments

Is there anyway to add gravatar images to recent comments, i was messing with the template funcions.php file, but i can only get the default gravatar too print out and not individual ones?

Comments

  • Comments (and other fields) are filtered for "valid" HTML tags. See the `allowed tags` option. Any tags not permitted in this list are stripped.
  • This is my implementation, i can get it to show the default image, but not the user with a gravatar? the original pieces of code can be found at the bottom

    `
    function printLatestComments($number, $shorten='123') {
    if(getOption('mod_rewrite')) {
    $albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
    } else {
    $albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
    }
    $email = getCommentAuthorEmail();
    $comments = getLatestComments($number,$shorten);
    echo "
    \n";
    echo "
      \n";
      foreach ($comments as $comment) {
      if($comment['anon'] === "0") {
      $author = " ".$comment['name'] .gettext(" said: ")." ";
      } else {
      $author = "";
      }
      $album = $comment['folder'];
      if($comment['type'] === "images") {
      $imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
      } else {
      $imagetag = "";
      }
      $date = $comment['date'];
      $albumtitle = $comment['albumtitle'];
      if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
      $website = $comment['website'];
      $shortcomment = truncate_string($comment['comment'], $shorten);
      if(!empty($title)) {
      $title = ": ".$title;
      }

      $default = "http://www.thehilln10.com/images/defaultGrav.gif";
      $size = 20;
      $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&default=".urlencode($default)."&size=".$size;

      echo "
    • ".$author."
      \n";
      echo "".$shortcomment."
    • ";
      echo '';

      }
      echo "
    \n";
    echo "
    \n";
    }
    `
    The original gravatar hack:

    `
    <?php
    $email = getCommentAuthorEmail();
    $default = "http://www.thehilln10.com/images/defaultGrav.gif";
    $size = 40;
    $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&default=".urlencode($default)."&size=".$size; ?>
    image" alt="" class="gravatar" />
    `
    The original print latest comments code:

    `
    function printLatestComments($number, $shorten='123') {
    if(getOption('mod_rewrite')) {
    $albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
    } else {
    $albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
    }
    $comments = getLatestComments($number,$shorten);
    echo "
    \n";
    echo "
      \n";
      foreach ($comments as $comment) {
      if($comment['anon'] === "0") {
      $author = " ".$comment['name'] .gettext(" said: ")." ";
      } else {
      $author = "";
      }
      $album = $comment['folder'];
      if($comment['type'] === "images") {
      $imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
      } else {
      $imagetag = "";
      }
      $date = $comment['date'];
      $albumtitle = $comment['albumtitle'];
      if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
      $website = $comment['website'];
      $shortcomment = truncate_string($comment['comment'], $shorten);
      if(!empty($title)) {
      $title = ": ".$title;
      }

      echo "
    • ".$author."
      \n";
      echo "".$shortcomment."
    • ";

      }
      echo "
    \n";
    echo "
    \n";
    }
    `
  • I know nothing of gravatar, however I can tell you from your code that if it is only displaying the default image then there is some problem with the gravatar_id bit. Maybe passing the md5 of the email address is not sufficient or not correct.
  • Gravatar is indeed a neat feature to hook up to ZenPhoto comment system.

    I have used Gravatar in BBpress with great results.

    here is some info about code.

    http://en.gravatar.com/site/implement

    This is how they state to do it on their web page.

    PHP

    Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:

    `
    $email = "someone@somewhere.com";
    $default = "http://www.somewhere.com/homestar.jpg";
    $size = 40;
    `
    You can construct your gravatar url with the following php code:

    `
    $grav_url = "http://www.gravatar.com/avatar.php?
    gravatar_id=".md5( strtolower($email) ).
    "&default=".urlencode($default).
    "&size=".$size;
    `
    Once the gravatar URL is created, you can output it whenever you please:
  • Based on what Olihar posted, I made a simple function that puts together the Gravatar url. All you have to pass it is the e-mail address.

    `
    function gravatar($email) {
    $default = "http://www.somewhere.com/homestar.jpg";
    $size = 60;

    $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5( strtolower($email) )."&default=".urlencode($default)."&size=".$size;
    echo $grav_url;
    }
    `
    I put this in a file called customfunctions.php within my theme folder and you would call it like this
    `
    image">
    `
  • @kingkool68

    I don't follow, I don't seem to get this to work that way....

    After a long try the only thing I get is empty photo.
Sign In or Register to comment.