Search

No worries.

I should note that Alistair has released an Email Field which wraps this functionality up more neatly. Use the Email Field in place of a normal Input Field in your section and the MD5 hash will be created automagically in the Data Source XML. No custom DS needed.

I’m using the piano sonata ensemble and i’m not sure where to insert the <img src="{/data/gravatars/gravatar[@email=current()/email]/@url}" /> call. Can someone advise?

I’ve already included the datasource for my articles page.

If you debug the page, can you confirm the DS is correctly outputing the email address hashes?

The code you include can go anywhere. You’ll want to find the utility that writes out comments (utilities/get-comments.xsl) and include this in the template that matches comments/entry (which renders each comment).

It occurred to me that when I had multiple comments from the same user(email) then duplicate gravatar nodes were generated.

A quick fix here http://www.pastie.org/770017

I have no idea if this is necessary or if there will be any kind of speed increase but for lots of comments with back and forth between commenters I thought that the duplication could get fairly hefty.

i just installed this extension and i’m getting this in my xml output:

<gravatar email=”54” url=”http://www.gravatar.com/avatar/a684eceee76fc522773286a895bc8436?s=40&d=http://s2.vault49.com/v1/extensions/gravatar/assets/default.gif” />

where email is the id value of the comment entry. is this supposed to be the expected behavior? or is it supposed to indeed store the poster’s email address?

edit: just realized that the ds output param should be the email address - i had the System ID selected, hence the id value

I’m using the modified pastie you posted, I get the following error:

Invalid argument supplied for foreach()
/Users/Sites/symphonycms/extensions/gravatar/data-sources/data.gravatars.php line 33

28      
29          $result = new XMLElement($this->dsParamROOTELEMENT);            
30      
31          foreach($this->dependencies as $dependency) {
32          
33              foreach($this->_env["env"]["pool"][preg_replace('/^$/','',$dependency)] as $email) {
34                  $gravatar = new XMLElement("gravatar");
35                  $gravatar->setAttribute("email", $email);
36                  $gravatar->setAttribute("url", "http://www.gravatar.com/avatar/" . md5(strtolower($email)) . "?s=" . $size . $this->size . "&d=" . $this->_env["param"]["root"] . "/extensions/gravatar/assets/default.gif");
37                  $result->appendChild($gravatar);

I’ve even tried attaching both datasources, and the gravatar one to my page and still get the error. I followed the instructions that you posted for the modified one…

Any ideas?

Ok, so I fixed it. Turns out that if I don’t want to add both datasources to the page, so that I can use the gravatar datasource on two seperate sections and pages (ie comments on news and user-reviews on projects), I have to wrap the foreach in an if statement, see the code…

<?php

require_once(TOOLKIT . '/class.datasource.php');

Class datasourcegravatars extends Datasource{

    var $dependencies = array('$ds-comments', '$ds-user-reviews');
    var $size = 40;

    var $dsParamROOTELEMENT = 'gravatars';  
    function __construct(&$parent, $env=NULL, $process_params=true){
        parent::__construct($parent, $env, $process_params);
        $this->_dependencies = $this->dependencies;
    }

    function about(){
        return array(
                 'name' => 'Gravatars',
                 'author' => array(
                        'name' => 'Nick Dunn',
                        'website' => 'http://airlock.com',
                        'email' => 'nick.dunn@airlock.com'),
                 'version' => '1.0',
                 'release-date' => '2008-10-21T15:58:52+00:00');    
    }

    function grab(&$param_pool){

        $result = new XMLElement($this->dsParamROOTELEMENT);            

        foreach($this->dependencies as $dependency) {
            if($this->_env["env"]["pool"][preg_replace('/^$/','',$dependency)]){
                $email_list = array();
                foreach($this->_env["env"]["pool"][preg_replace('/^$/','',$dependency)] as $email) {
                    $email = strtolower($email);
                    if(!in_array($email, $email_list)){
                        $email_list[] = $email;
                        $gravatar = new XMLElement("gravatar");
                        $gravatar->setAttribute("email", $email);
                        $gravatar->setAttribute("url", "http://www.gravatar.com/avatar/" . md5(strtolower($email)) . "?s=" . $size . $this->size . "&amp;d=" . $this->_env["param"]["root"] . "/extensions/gravatar/assets/default.gif");
                        $result->appendChild($gravatar);
                    }
                }
            }
        }

        return $result;
    }

}

?>

This checks that the param pool contains the param first.

Mic, I don’t know how to use git, if you want to branch this or something ;)

Cheers…

edit: I’ve updated the code to take into account robphilp’s change, which is really useful!

@designermonkey - i just tried implementing this code, but i just get an empty <gravatars /> node in my output. also in the $dependencies array, i removed $ds-user-reviews, but left $ds-comments since that’s the only dependency i have right now. any clues?

so right now i’m just seeing the default gravatar icon.

edit: had to do with the regexp check. i changed these two lines:

if($this->env[“env”][“pool”][pregreplace(‘/^$/’,”,$dependency)]){
foreach($this->env[“env”][“pool”][pregreplace(‘/^$/’,”,$dependency)] as $email) {

to this:

if($this->env[“env”][“pool”][pregreplace(‘/^\$/’,”,$dependency)]){
foreach($this->env[“env”][“pool”][pregreplace(‘/^\$/’,”,$dependency)] as $email) {

notice the escaped \$ which I thought was supposed to happen since you’re checking to see if your param (in this case $ds-comment) was available and to check against the param pool, needed to drop the $ in the dependencies array when doing so. looked a little odd since the $ for regexp is normally used to indicate the end of a string.

I completely agree! And I really don’t understand why they’re not escaped… They are in the document I copied and pasted from :S weird!

Thanks for pointing it out on here…

edit: I’m copying and pasting the offending code again to see if it does it again…

if($this->_env["env"]["pool"][preg_replace('/^$/','',$dependency)])

edit2: Interesting… When I edit this post, the $ is escaped, yet it isn’t in the discussion… I’m going to log it as an issue then.

Well spotted!

ya, i realized that that’s what you intended on doing. only after i double escaped my own regexp in my post did i realize that you probably did have it written correctly already and that there’s some sort of sanitizer to strip stuff like that out.

I should note that Alistair has released an Email Field which wraps this functionality up more neatly. Use the Email Field in place of a normal Input Field in your section and the MD5 hash will be created automagically in the Data Source XML. No custom DS needed.

Ah, this is much simpler than a whole custom DS. Thanks to you, kind sirs - you’ve reduced the number of extensions I need to run!

Guys, what is problem? i have following error:

Invalid argument supplied for foreach()
An error occurred in /home/h4097/data/www/chieko.ru/extensions/gravatar/data-sources/data.gravatars.php around line 34
29:         
30:         function grab(&$param_pool){
31:             
32:             $result = new XMLElement($this->dsParamROOTELEMENT);            
33: $email_list = array();
34:             foreach($this->_env["env"]["pool"][$this->ds_comments] as $email) {
35:              $email = strtolower($email);
36:              if(!in_array($email, $email_list)) {
37:              $email_list[] = $email;
38:              $gravatar = new XMLElement("gravatar");

when open no existing article(sample:chieko.ru/articles/ajdfkls)

The function should check that $this->_env["env"]["pool"][$this->ds_comments] isset and is_array before foreach.

Cheers Brendan. Beat me to it! I’ve updated the code on Github, try this new Data Source:

http://github.com/nickdunn/gravatar/blob/master/data-sources/data.gravatars.php

This works. Big thanks guys ;)

Gravatars updated to version 1.2 on 7th of February 2011

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details