123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class AvatarLink
- {
- public $url;
- public $type;
- public $size;
- public $width;
- public $height;
- function __construct($element=null)
- {
- if ($element) {
-
- $this->url = $element->getAttribute('href');
- $this->type = $element->getAttribute('type');
- $width = $element->getAttribute('media:width');
- if ($width != null) {
- $this->width = intval($width);
- }
- $height = $element->getAttribute('media:height');
- if ($height != null) {
- $this->height = intval($height);
- }
- }
- }
- static function fromAvatar(Avatar $avatar)
- {
- $alink = new AvatarLink();
- $alink->type = $avatar->mediatype;
- $alink->height = $avatar->height;
- $alink->width = $avatar->width;
- $alink->url = $avatar->displayUrl();
- return $alink;
- }
- static function fromFilename($filename, $size)
- {
- $alink = new AvatarLink();
- $alink->url = $filename;
- $alink->height = $size;
- $alink->width = $size;
- if (!empty($filename)) {
- $alink->type = self::mediatype($filename);
- } else {
- $alink->url = User_group::defaultLogo($size);
- $alink->type = 'image/png';
- }
- return $alink;
- }
-
- static function mediatype($filename) {
- $parts = explode('.', $filename);
- $ext = strtolower(end($parts));
- if ($ext == 'jpeg') {
- $ext = 'jpg';
- }
-
- $types = array('png', 'gif', 'jpg', 'jpeg');
- if (in_array($ext, $types)) {
- return 'image/' . $ext;
- }
- return null;
- }
- }
|