/** * @param Lead $lead * * @return mixed */ public function getAvatar(Lead $lead) { $preferred = $lead->getPreferredProfileImage(); $socialData = $lead->getSocialCache(); $leadEmail = $lead->getEmail(); 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->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']; } if (empty($img)) { // Default to gravatar if others failed if (!empty($leadEmail)) { $img = $this->factory->getHelper('template.gravatar')->getImage($leadEmail); } else { $img = $this->getDefaultAvatar(); } } return $img; }
/** * {@inheritDoc} */ public function getSocialCache() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSocialCache', array()); return parent::getSocialCache(); }
/** * Get the user's social profile data from cache or integrations if indicated * * @param \Mautic\LeadBundle\Entity\Lead $lead * @param array $fields * @param bool $refresh * @param string $specificIntegration * @param bool $persistLead * @param bool $returnSettings * * @return array */ public function getUserProfiles($lead, $fields = array(), $refresh = false, $specificIntegration = null, $persistLead = true, $returnSettings = false) { $socialCache = $lead->getSocialCache(); $featureSettings = array(); if ($refresh) { //regenerate from integrations $now = new DateTimeHelper(); //check to see if there are social profiles activated $socialIntegrations = $this->getIntegrationObjects($specificIntegration, array('public_profile', 'public_activity')); /* @var \MauticPlugin\MauticSocialBundle\Integration\SocialIntegration $sn */ foreach ($socialIntegrations as $integration => $sn) { $settings = $sn->getIntegrationSettings(); $features = $settings->getSupportedFeatures(); $identifierField = $this->getUserIdentifierField($sn, $fields); if ($returnSettings) { $featureSettings[$integration] = $settings->getFeatureSettings(); } if ($identifierField && $settings->isPublished()) { $profile = !isset($socialCache[$integration]) ? array() : $socialCache[$integration]; //clear the cache unset($profile['profile'], $profile['activity']); if (in_array('public_profile', $features) && $sn->isAuthorized()) { $sn->getUserData($identifierField, $profile); } if (in_array('public_activity', $features) && $sn->isAuthorized()) { $sn->getPublicActivity($identifierField, $profile); } if (!empty($profile['profile']) || !empty($profile['activity'])) { if (!isset($socialCache[$integration])) { $socialCache[$integration] = array(); } $socialCache[$integration]['profile'] = !empty($profile['profile']) ? $profile['profile'] : array(); $socialCache[$integration]['activity'] = !empty($profile['activity']) ? $profile['activity'] : array(); $socialCache[$integration]['lastRefresh'] = $now->toUtcString(); } } elseif (isset($socialCache[$integration])) { //integration is now not applicable unset($socialCache[$integration]); } } if ($persistLead && !empty($socialCache)) { $lead->setSocialCache($socialCache); $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->saveEntity($lead); } } elseif ($returnSettings) { $socialIntegrations = $this->getIntegrationObjects($specificIntegration, array('public_profile', 'public_activity')); foreach ($socialIntegrations as $integration => $sn) { $settings = $sn->getIntegrationSettings(); $featureSettings[$integration] = $settings->getFeatureSettings(); } } if ($specificIntegration) { return $returnSettings ? array(array($specificIntegration => $socialCache[$specificIntegration]), $featureSettings) : array($specificIntegration => $socialCache[$specificIntegration]); } return $returnSettings ? array($socialCache, $featureSettings) : $socialCache; }