Skip to content

Commit

Permalink
Custom lead avatar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhartless committed Jul 19, 2015
1 parent f8ba326 commit 8c73e13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
14 changes: 7 additions & 7 deletions app/bundles/CoreBundle/Factory/MauticFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,14 @@ public function getSystemPath($name, $fullPath = false)
//these are absolute regardless as they are configurable
return $this->container->getParameter("kernel.{$name}_dir");
} elseif ($name == 'images') {
$session = $this->getSession();
$imageDir = $session->get('mautic.imagepath');
$imageDir = $this->getParameter('image_path');
if (substr($imageDir, -1) === '/') {
$imageDir = substr(0, -1, $imageDir);
$imageDir = substr($imageDir, 0, -1);
}

$path = $imageDir;

return ($fullPath) ? $paths['local_root'] . '/' . $imageDir : $imageDir;
} elseif (isset($paths[$name])) {
$path = $paths[$name];
$path = $paths[$name];
} else {
throw new \InvalidArgumentException("$name does not exist.");
}
Expand Down Expand Up @@ -654,7 +652,9 @@ public function getVersion()
/**
* Get Symfony's logger
*
* @return \Symfony\Bridge\Monolog\Logger
* @param bool|false $system
*
* @return object
*/
public function getLogger($system = false)
{
Expand Down
14 changes: 10 additions & 4 deletions app/bundles/CoreBundle/Templating/Helper/GravatarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Mautic\CoreBundle\Factory\MauticFactory;
use Mautic\CoreBundle\Helper\UrlHelper;
use Mautic\LeadBundle\Templating\Helper\AvatarHelper;
use Symfony\Component\Templating\Helper\Helper;

/**
Expand All @@ -34,14 +35,19 @@ class GravatarHelper extends Helper
*/
private $assetHelper;

/**
* @var AvatarHelper
*/
private $avatarHelper;
/**
* @param MauticFactory $factory
*/
public function __construct(MauticFactory $factory)
{
$this->devMode = $factory->getEnvironment() == 'dev';
$this->imageDir = $factory->getSystemPath('images');
$this->assetHelper = $factory->getHelper('template.assets');
$this->devMode = $factory->getEnvironment() == 'dev';
$this->imageDir = $factory->getSystemPath('images');
$this->assetHelper = $factory->getHelper('template.assets');
$this->avatarHelper = $factory->getHelper('template.avatar');
}

/**
Expand All @@ -55,7 +61,7 @@ public function getImage($email, $size = '250', $default = null)
{
$localDefault = ($this->devMode) ?
'https://www.mautic.org/media/images/default_avatar.png' :
$this->assetHelper->getUrl($this->imageDir . '/avatar.png', null, null, true, false);
$this->avatarHelper->getDefaultAvatar(true);
$url = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s='.$size;

if ($default === null) {
Expand Down
15 changes: 11 additions & 4 deletions app/bundles/LeadBundle/Templating/Helper/AvatarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function __construct (MauticFactory $factory)

/**
* @param Lead $lead
*
* @return mixed
*/
public function getAvatar(Lead $lead)
{
Expand All @@ -40,7 +42,13 @@ public function getAvatar(Lead $lead)
if ($preferred == 'custom' ) {
if ($fmtime = filemtime($this->getAvatarPath(true) . '/avatar'.$lead->getId())) {
// Append file modified time to ensure the latest is used by browser
$img = $this->getDefaultAvatar(true);
$img = $this->factory->getHelper('template.assets')->getUrl(
$this->getAvatarPath().'/avatar'.$lead->getId() . '?' . $fmtime,
null,
null,
false,
true
);
}
} elseif (isset($socialData[$preferred]) && !empty($socialData[$preferred]['profile']['profileImage'])) {
$img = $socialData[$preferred]['profile']['profileImage'];
Expand Down Expand Up @@ -80,11 +88,10 @@ public function getAvatarPath($absolute = false)
public function getDefaultAvatar($absolute = false)
{
return $this->factory->getHelper('template.assets')->getUrl(
$this->factory->getSystemPath('images').'/avatar.png',
$this->factory->getSystemPath('assets').'/images/avatar.png',
null,
null,
$absolute,
true
$absolute
);
}

Expand Down

0 comments on commit 8c73e13

Please sign in to comment.