Skip to content

Commit

Permalink
- Fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Apr 9, 2018
1 parent fea9b06 commit 7304cba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/IPub/Gravatar/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ final class Gravatar

/**
* The default image to use
* Either a string of the gravatar-recognized default image "type" to use, a URL, or FALSE if using the...default gravatar default image (hah)
* Either a string of the gravatar-recognized default image "type" to use, a URL, or NULL if using the...default gravatar default image (hah)
*
* @var mixed
*/
private $defaultImage = FALSE;
private $defaultImage = NULL;

/**
* The maximum rating to allow for the avatar.
Expand Down Expand Up @@ -200,7 +200,7 @@ public function setDefaultImage($image) : void
{
// Quick check against boolean FALSE.
if ($image === FALSE) {
$this->defaultImage = FALSE;
$this->defaultImage = NULL;

} else {
// Check $image against recognized gravatar "defaults"
Expand Down Expand Up @@ -442,11 +442,13 @@ private function createUrl(string $email, ?int $size = NULL, ?string $maxRating
$size = $this->getSize();
}

$defaultImage = $this->getDefaultImage($defaultImage);

// Time to figure out our request params
$params = [
's' => $size,
'r' => $this->getMaxRating($maxRating),
'd' => $this->getDefaultImage($defaultImage),
'd' => $defaultImage === NULL ? FALSE : $defaultImage,
'f' => is_null($email) ? 'y' : NULL,
];

Expand Down
14 changes: 9 additions & 5 deletions src/IPub/Gravatar/Latte/Macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function macroGravatar(MacroNode $node, PhpWriter $writer) : string
throw new Latte\CompileException('Please provide email address.');
}

return $writer->write('echo %escape(property_exists($this, "filters") ? call_user_func($this->filters->gravatar, ' . $arguments['email'] . ', ' . $arguments['size'] . ') : $template->getGravatarService()->buildUrl(' . $arguments['email'] . ', ' . $arguments['size'] . '));');
return $writer->write('echo %escape(property_exists($this, "filters") ? call_user_func($this->filters->gravatar, ' . $arguments['email'] . ', ' . $arguments['size'] . ', ' . $arguments['maxRating'] . ', ' . $arguments['defaultImage'] . ') : $template->getGravatarService()->buildUrl(' . $arguments['email'] . ', ' . $arguments['size'] . ', ' . $arguments['maxRating'] . ', ' . $arguments['defaultImage'] . '));');
}


Expand All @@ -89,7 +89,7 @@ public function macroAttrGravatar(MacroNode $node, PhpWriter $writer) : string
throw new Latte\CompileException('Please provide email address.');
}

return $writer->write('?> ' . ($node->htmlNode->name === 'a' ? 'href' : 'src') . '="<?php echo %escape(property_exists($this, "filters") ? call_user_func($this->filters->gravatar, ' . $arguments['email'] . ', ' . $arguments['size'] . ') : $template->getGravatarService()->buildUrl(' . $arguments['email'] . ', ' . $arguments['size'] . '));?>" <?php');
return $writer->write('?> ' . ($node->htmlNode->name === 'a' ? 'href' : 'src') . '="<?php echo %escape(property_exists($this, "filters") ? call_user_func($this->filters->gravatar, ' . $arguments['email'] . ', ' . $arguments['size'] . ', ' . $arguments['maxRating'] . ', ' . $arguments['defaultImage'] . ') : $template->getGravatarService()->buildUrl(' . $arguments['email'] . ', ' . $arguments['size'] . ', ' . $arguments['maxRating'] . ', ' . $arguments['defaultImage'] . '));?>" <?php');
}


Expand All @@ -105,11 +105,15 @@ public static function prepareMacroArguments(string $macro) : array
}, explode(',', $macro));

$name = $arguments[0];
$size = (isset($arguments[1]) && !empty($arguments[1])) ? $arguments[1] : NULL;
$size = (isset($arguments[1]) && !empty($arguments[1])) ? $arguments[1] : 'NULL';
$maxRating = (isset($arguments[2]) && !empty($arguments[2])) ? $arguments[2] : 'NULL';
$defaultImage = (isset($arguments[3]) && !empty($arguments[3])) ? $arguments[3] : 'NULL';

return [
'email' => $name,
'size' => $size,
'email' => $name,
'size' => $size,
'maxRating' => $maxRating,
'defaultImage' => $defaultImage
];
}
}

0 comments on commit 7304cba

Please sign in to comment.