/** * Get a path or URL to a user pciture * * @param integer $id * @param string $name * @param string $email * @param bool $thumbnail * @return string */ public function picture($id, $name, $email, $thumbnail = true) { $processor = new Processor(); $size = $this->pictureSize; $file = $this->pictureName; if ($thumbnail) { $size = $this->thumbnailSize; $file = $this->thumbnailName; } $dir = $this->path . DIRECTORY_SEPARATOR . String::pad($id, 5) . DIRECTORY_SEPARATOR; $path = $dir . $file; if (file_exists($path)) { return with(new Moderator($path))->getUrl(); } $image = $processor->getImageData($email, $size, $this->color); if (!is_dir($dir)) { @mkdir($dir, 0755, true); } @file_put_contents($path, $image); if (!file_exists($path)) { return sprintf('data:image/png;base64,%s', base64_encode($image)); } return with(new Moderator($path))->getUrl(); }
/** * Get member picture * * @param mixed $member Member to get picture for * @param integer $anonymous Anonymous user? * @param boolean $thumbit Display thumbnail (default) or full image? * @return string Image URL */ public static function getMemberPhoto($member, $anonymous = 0, $thumbit = true, $serveFile = true) { static $dfthumb; static $dffull; $config = \Component::params('com_members'); // Get the default picture // We need to do this here as it may be needed by the Gravatar service if (!$dffull) { $dffull = '/core/components/com_members/site/assets/img/profile.gif'; //ltrim($config->get('defaultpic', '/components/com_members/site/assets/img/profile.gif'), DS); } if (!$dfthumb) { if ($thumbit) { $dfthumb = self::thumbit($dffull); } } // lets make sure we have a profile object if ($member instanceof User) { return $member->picture($anonymous, $thumbit, $serveFile); } else { if (is_numeric($member) || is_string($member)) { $member = Profile::getInstance($member); } } $paths = array(); $apppath = trim(substr(PATH_APP, strlen(PATH_ROOT)), DS) . '/site/members'; // If not anonymous if (!$anonymous) { // If we have a member if (is_object($member)) { if (!$member->get('picture')) { // Do we auto-generate a picture? if ($config->get('identicon')) { $path = PATH_APP . DS . trim($config->get('webpath', '/site/members'), DS) . DS . self::niceidformat($member->get('uidNumber')); if (!is_dir($path)) { \App::get('filesystem')->makeDirectory($path); } if (is_dir($path)) { $identicon = new Identicon(); // Create a profile image $imageData = $identicon->getImageData($member->get('email'), 200, $config->get('identicon_color', null)); file_put_contents($path . DS . 'identicon.png', $imageData); // Create a thumbnail image $imageData = $identicon->getImageData($member->get('email'), 50, $config->get('identicon_color', null)); file_put_contents($path . DS . 'identicon_thumb.png', $imageData); // Save image to profile $member->set('picture', 'identicon.png'); // Update directly. Using update() method can cause unexpected data loss in some cases. $database = \App::get('db'); $database->setQuery("UPDATE `#__xprofiles` SET picture=" . $database->quote($member->get('picture')) . " WHERE uidNumber=" . $member->get('uidNumber')); $database->query(); //$member->update(); } } } // If member has a picture set if ($member->get('picture')) { $thumb = DS . $apppath . DS . self::niceidformat($member->get('uidNumber')); $thumbAlt = $thumb . DS . ltrim($member->get('picture'), DS); if ($thumbit) { $thumbAlt = $thumb . DS . 'thumb.png'; } $thumb .= DS . ltrim($member->get('picture'), DS); if ($thumbit) { $thumb = self::thumbit($thumb); } $paths[] = $thumbAlt; $paths[] = $thumb; } else { // If use of gravatars is enabled if ($config->get('gravatar')) { $hash = md5(strtolower(trim($member->get('email')))); $protocol = \App::get('request')->isSecure() ? 'https' : 'http'; //$paths[] = $protocol . '://www.gravatar.com/avatar/' . htmlspecialchars($hash) . '?' . (!$thumbit ? 's=300&' : '') . 'd=' . urlencode(JURI::base() . $dfthumb); return $protocol . '://www.gravatar.com/avatar/' . htmlspecialchars($hash) . '?' . (!$thumbit ? 's=300&' : '') . 'd=' . urlencode(str_replace('/administrator', '', rtrim(\App::get('request')->base(), '/')) . '/' . $dfthumb); } } } } // Add the default picture last $paths[] = $thumbit ? $dfthumb : $dffull; // Start running through paths until we find a valid one foreach ($paths as $path) { if ($path && file_exists(PATH_ROOT . $path)) { if (!$anonymous) { // build base path (ex. /site/members/12345) $baseMemberPath = DS . $apppath . DS . self::niceidformat($member->get('uidNumber')); // if we want to serve file & path is within /site if ($serveFile && strpos($path, $baseMemberPath) !== false) { // get picture name (allows to pics in subfolder) $pic = trim(str_replace($baseMemberPath, '', $path), DS); // build serve link $link = with(new \Hubzero\Content\Moderator(PATH_ROOT . $path))->getUrl(); return $link; } } return str_replace('/administrator', '', rtrim(\App::get('request')->base(true), '/')) . $path; } } }
/** * Get a path or URL to a user pciture * * @param string $email * @param bool $thumbnail * @return string */ public function picture($email, $thumbnail = true) { $processor = new Processor(); $size = $this->pictureSize; $file = $this->pictureName; if ($thumbnail) { $size = $this->thumbnailSize; $file = $this->thumbnailName; } $path = $this->path . DIRECTORY_SEPARATOR . $file; if (file_exists($path)) { return $path; } $image = $processor->getImageData($email, $size, $this->color); @file_put_contents($path, $image); if (!file_exists($path)) { return sprintf('data:image/png;base64,%s', base64_encode($image)); } return $path; }