From: Evan Prodromou Date: Fri, 6 Feb 2009 08:13:08 +0000 (-0500) Subject: Move common_avatar_* functions to Avatar X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=343cd6f20577c44487eae4e90ec10bfd954980e3;p=quix0rs-gnu-social.git Move common_avatar_* functions to Avatar Moved the common_avatar_* functions to the Avatar class. Typically either as methods on the object or as static methods. Replaced all the uses of the functions in other modules. --- diff --git a/actions/avatarbynickname.php b/actions/avatarbynickname.php index 9bbdecefac..ca58c96537 100644 --- a/actions/avatarbynickname.php +++ b/actions/avatarbynickname.php @@ -90,9 +90,9 @@ class AvatarbynicknameAction extends Action $url = $avatar->url; } else { if ($size == 'original') { - $url = common_default_avatar(AVATAR_PROFILE_SIZE); + $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE); } else { - $url = common_default_avatar($size+0); + $url = Avatar::defaultImage($size+0); } } common_redirect($url, 302); diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php index 3f50ca24cd..a0be5d8f88 100644 --- a/actions/avatarsettings.php +++ b/actions/avatarsettings.php @@ -200,7 +200,7 @@ class AvatarsettingsAction extends AccountSettingsAction 'class' => 'avatar_view')); $this->element('h2', null, _("Original")); $this->elementStart('div', array('id'=>'avatar_original_view')); - $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $user->nickname)); @@ -212,7 +212,7 @@ class AvatarsettingsAction extends AccountSettingsAction 'class' => 'avatar_view')); $this->element('h2', null, _("Preview")); $this->elementStart('div', array('id'=>'avatar_preview_view')); - $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $user->nickname)); @@ -281,12 +281,12 @@ class AvatarsettingsAction extends AccountSettingsAction $cur = common_current_user(); - $filename = common_avatar_filename($cur->id, + $filename = Avatar::filename($cur->id, image_type_to_extension($imagefile->type), null, 'tmp'.common_timestamp()); - $filepath = common_avatar_path($filename); + $filepath = Avatar::path($filename); move_uploaded_file($imagefile->filepath, $filepath); diff --git a/actions/grouplogo.php b/actions/grouplogo.php index 7cf198dc73..650c952556 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -263,7 +263,7 @@ class GrouplogoAction extends Action 'class' => 'avatar_view')); $this->element('h2', null, _("Original")); $this->elementStart('div', array('id'=>'avatar_original_view')); - $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $this->group->nickname)); @@ -275,7 +275,7 @@ class GrouplogoAction extends Action 'class' => 'avatar_view')); $this->element('h2', null, _("Preview")); $this->elementStart('div', array('id'=>'avatar_preview_view')); - $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $this->group->nickname)); @@ -343,12 +343,12 @@ class GrouplogoAction extends Action return; } - $filename = common_avatar_filename($this->group->id, + $filename = Avatar::filename($this->group->id, image_type_to_extension($imagefile->type), null, 'group-temp-'.common_timestamp()); - $filepath = common_avatar_path($filename); + $filepath = Avatar::path($filename); move_uploaded_file($imagefile->filepath, $filepath); diff --git a/actions/noticesearch.php b/actions/noticesearch.php index c0c2381209..a5f01350c4 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -166,7 +166,7 @@ class NoticesearchAction extends SearchAction $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); $this->elementStart('a', array('href' => $profile->profileurl, 'class' => 'url')); - $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE), + $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE), 'class' => 'avatar photo', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, diff --git a/actions/showstream.php b/actions/showstream.php index 224bbce9fb..28bb8453f8 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -242,7 +242,7 @@ class ShowstreamAction extends Action $this->elementStart('dl', 'entity_depiction'); $this->element('dt', null, _('Photo')); $this->elementStart('dd'); - $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE), + $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE), 'class' => 'photo avatar', 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, diff --git a/actions/tagother.php b/actions/tagother.php index cbace5b6b5..3e8a12fd69 100644 --- a/actions/tagother.php +++ b/actions/tagother.php @@ -80,7 +80,7 @@ class TagotherAction extends Action $this->elementStart('dl', 'entity_depiction'); $this->element('dt', null, _('Photo')); $this->elementStart('dd'); - $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE), + $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE), 'class' => 'photo avatar', 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, diff --git a/actions/twittersettings.php b/actions/twittersettings.php index b3bf67dc3f..2d41469bba 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -250,8 +250,8 @@ class TwittersettingsAction extends ConnectSettingsAction $avatar = $other->getAvatar(AVATAR_MINI_SIZE); $avatar_url = ($avatar) ? - common_avatar_display_url($avatar) : - common_default_avatar(AVATAR_MINI_SIZE); + $avatar->displayUrl() : + Avatar::defaultImage(AVATAR_MINI_SIZE); $this->element('img', array('src' => $avatar_url, 'width' => AVATAR_MINI_SIZE, diff --git a/classes/Avatar.php b/classes/Avatar.php index 6a9ea76865..6248a84d3b 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -4,18 +4,18 @@ */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Avatar extends Memcached_DataObject +class Avatar extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ public $__table = 'avatar'; // table name public $profile_id; // int(4) primary_key not_null - public $original; // tinyint(1) + public $original; // tinyint(1) public $width; // int(4) primary_key not_null public $height; // int(4) primary_key not_null public $mediatype; // varchar(32) not_null - public $filename; // varchar(255) + public $filename; // varchar(255) public $url; // varchar(255) unique_key public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP @@ -33,13 +33,51 @@ class Avatar extends Memcached_DataObject { $filename = $this->filename; if (parent::delete()) { - @unlink(common_avatar_path($filename)); + @unlink(Avatar::path($filename)); } } - - function &pkeyGet($kv) + + function &pkeyGet($kv) { return Memcached_DataObject::pkeyGet('Avatar', $kv); } + // where should the avatar go for this user? + + static function filename($id, $extension, $size=null, $extra=null) + { + if ($size) { + return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension; + } else { + return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension; + } + } + + static function path($filename) + { + return INSTALLDIR . '/avatar/' . $filename; + } + + static function url($filename) + { + return common_path('avatar/'.$filename); + } + + function displayUrl() + { + $server = common_config('avatar', 'server'); + if ($server) { + return 'http://'.$server.'/'.$this->filename; + } else { + return $this->url; + } + } + + static function defaultAvatar($size) + { + static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile', + AVATAR_STREAM_SIZE => 'stream', + AVATAR_MINI_SIZE => 'mini'); + return theme_path('default-avatar-'.$sizenames[$size].'.png'); + } } diff --git a/classes/Profile.php b/classes/Profile.php index 5be632f87c..f3bfe299cf 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -71,7 +71,7 @@ class Profile extends Memcached_DataObject function setOriginal($filename) { - $imagefile = new ImageFile($this->id, common_avatar_path($filename)); + $imagefile = new ImageFile($this->id, Avatar::path($filename)); $avatar = new Avatar(); $avatar->profile_id = $this->id; @@ -80,22 +80,22 @@ class Profile extends Memcached_DataObject $avatar->mediatype = image_type_to_mime_type($imagefile->type); $avatar->filename = $filename; $avatar->original = true; - $avatar->url = common_avatar_url($filename); + $avatar->url = Avatar::url($filename); $avatar->created = DB_DataObject_Cast::dateTime(); # current time # XXX: start a transaction here if (!$this->delete_avatars() || !$avatar->insert()) { - @unlink(common_avatar_path($filename)); + @unlink(Avatar::path($filename)); return null; } foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { # We don't do a scaled one if original is our scaled size if (!($avatar->width == $size && $avatar->height == $size)) { - + $scaled_filename = $imagefile->resize($size); - + //$scaled = DB_DataObject::factory('avatar'); $scaled = new Avatar(); $scaled->profile_id = $this->id; @@ -104,7 +104,7 @@ class Profile extends Memcached_DataObject $scaled->original = false; $scaled->mediatype = image_type_to_mime_type($imagefile->type); $scaled->filename = $scaled_filename; - $scaled->url = common_avatar_url($scaled_filename); + $scaled->url = Avatar::url($scaled_filename); $scaled->created = DB_DataObject_Cast::dateTime(); # current time if (!$scaled->insert()) { @@ -194,4 +194,13 @@ class Profile extends Memcached_DataObject } } + function avatarUrl($size=AVATAR_PROFILE_SIZE) + { + $avatar = $this->getAvatar($size); + if ($avatar) { + return $avatar->displayUrl(); + } else { + return Avatar::defaultImage($size); + } + } } diff --git a/classes/User_group.php b/classes/User_group.php index 340d7f67a7..d152f9d567 100755 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -90,13 +90,13 @@ class User_group extends Memcached_DataObject function setOriginal($filename) { - $imagefile = new ImageFile($this->id, common_avatar_path($filename)); + $imagefile = new ImageFile($this->id, Avatar::path($filename)); $orig = clone($this); - $this->original_logo = common_avatar_url($filename); - $this->homepage_logo = common_avatar_url($imagefile->resize(AVATAR_PROFILE_SIZE)); - $this->stream_logo = common_avatar_url($imagefile->resize(AVATAR_STREAM_SIZE)); - $this->mini_logo = common_avatar_url($imagefile->resize(AVATAR_MINI_SIZE)); + $this->original_logo = Avatar::url($filename); + $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE)); + $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE)); + $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE)); common_debug(common_log_objstring($this)); return $this->update($orig); } diff --git a/lib/imagefile.php b/lib/imagefile.php index fa0581dd05..db344db8f8 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -153,12 +153,12 @@ class ImageFile imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h); - $outname = common_avatar_filename($this->id, + $outname = Avatar::filename($this->id, image_type_to_extension($this->type), $size, common_timestamp()); - $outpath = common_avatar_path($outname); + $outpath = Avatar::path($outname); switch ($this->type) { case IMAGETYPE_GIF: diff --git a/lib/jabber.php b/lib/jabber.php index f1be577681..f41d984d62 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -178,7 +178,7 @@ function jabber_format_entry($profile, $notice) $entry .= "\n"; $entry .= "\n"; $entry .= "" . $profile->nickname . "\n"; - $entry .= "" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "\n"; + $entry .= "" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "\n"; $entry .= "\n"; $entry .= "" . htmlspecialchars($msg) . "\n"; $entry .= "" . htmlspecialchars($msg) . "\n"; diff --git a/lib/mailbox.php b/lib/mailbox.php index e8323dc289..d77234549a 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -183,8 +183,8 @@ class MailboxAction extends PersonalAction 'class' => 'url')); $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); $this->element('img', array('src' => ($avatar) ? - common_avatar_display_url($avatar) : - common_default_avatar(AVATAR_STREAM_SIZE), + $avatar->displayUrl() : + Avatar::defaultImage(AVATAR_STREAM_SIZE), 'class' => 'photo avatar', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, diff --git a/lib/noticelist.php b/lib/noticelist.php index 3ef6691afa..9fc0126b3e 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -285,8 +285,8 @@ class NoticeListItem extends Widget $avatar = $this->profile->getAvatar($avatar_size); $this->out->element('img', array('src' => ($avatar) ? - common_avatar_display_url($avatar) : - common_default_avatar($avatar_size), + $avatar->displayUrl() : + Avatar::defaultImage($avatar_size), 'class' => 'avatar photo', 'width' => $avatar_size, 'height' => $avatar_size, diff --git a/lib/noticesection.php b/lib/noticesection.php index aa8e032298..97b5175296 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -82,7 +82,7 @@ class NoticeSection extends Section $profile->nickname, 'href' => $profile->profileurl, 'class' => 'url')); - $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)), + $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)), 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', diff --git a/lib/profilelist.php b/lib/profilelist.php index 6e14c0b692..4d924b039e 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -97,7 +97,7 @@ class ProfileList extends Widget $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); $this->out->elementStart('a', array('href' => $this->profile->profileurl, 'class' => 'url')); - $this->out->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE), + $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE), 'class' => 'photo avatar', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, diff --git a/lib/profileminilist.php b/lib/profileminilist.php index 81cd7aed55..0d466bba81 100644 --- a/lib/profileminilist.php +++ b/lib/profileminilist.php @@ -74,7 +74,7 @@ class ProfileMiniList extends ProfileList 'rel' => 'contact member', 'class' => 'url')); $avatar = $this->profile->getAvatar(AVATAR_MINI_SIZE); - $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)), + $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)), 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', diff --git a/lib/profilesection.php b/lib/profilesection.php index 3642ae164a..8ed290e03a 100644 --- a/lib/profilesection.php +++ b/lib/profilesection.php @@ -86,7 +86,7 @@ class ProfileSection extends Section 'rel' => 'contact member', 'class' => 'url')); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); - $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)), + $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)), 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', diff --git a/lib/rssaction.php b/lib/rssaction.php index 2bd7f1f19d..131e8ac65a 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -199,7 +199,7 @@ class Rss10Action extends Action $this->element('dc:date', null, common_date_w3dtf($notice->created)); $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname); $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri)); - $this->element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile))); + $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl())); $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); $this->elementEnd('item'); $this->creators[$creator_uri] = $profile; @@ -216,7 +216,7 @@ class Rss10Action extends Action $this->element('foaf:name', null, $profile->fullname); } $this->element('sioc:id', null, $id); - $avatar = common_profile_avatar_url($profile); + $avatar = $profile->avatarUrl(); $this->element('sioc:avatar', array('rdf:resource' => $avatar)); $this->elementEnd('sioc:User'); } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index da8b8b1e5b..a4d183fcd0 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -43,7 +43,7 @@ class TwitterapiAction extends Action $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE); + $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE); $twitter_user['protected'] = 'false'; # not supported by Laconica yet $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; diff --git a/lib/util.php b/lib/util.php index 5275ad6b6e..0655ebf276 100644 --- a/lib/util.php +++ b/lib/util.php @@ -395,15 +395,15 @@ function common_render_text($text) function common_replace_urls_callback($text, $callback) { // Start off with a regex preg_match_all('#(?:(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://|(?:mailto|aim|tel):)[^.\s]+\.[^\s]+|(?:[^.\s/]+\.)+(?:museum|travel|[a-z]{2,4})(?:[:/][^\s]*)?)#i', $text, $matches); - + // Then clean up what the regex left behind $offset = 0; foreach($matches[0] as $url) { $url = htmlspecialchars_decode($url); - + // Make sure we didn't pick up an email address if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue; - + // Remove trailing punctuation $url = rtrim($url, '.?!,;:\'"`'); @@ -422,48 +422,48 @@ function common_replace_urls_callback($text, $callback) { // Remove trailing punctuation again (in case there were some inside parens) $url = rtrim($url, '.?!,;:\'"`'); - + // Make sure we didn't capture part of the next sentence preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts); - + // Were the parts capitalized any? $last_part = (mb_strtolower($url_parts[2]) !== $url_parts[2]) ? true:false; $prev_part = (mb_strtolower($url_parts[1]) !== $url_parts[1]) ? true:false; - + // If the first part wasn't cap'd but the last part was, we captured too much if ((!$prev_part && $last_part)) { $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0)); } - + // Capture the new TLD preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts); - + $tlds = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw'); if (!in_array($url_parts[2], $tlds)) continue; - + // Call user specified func $modified_url = $callback($url); - + // Replace it! $start = mb_strpos($text, $url, $offset); $text = mb_substr($text, 0, $start).$modified_url.mb_substr($text, $start + mb_strlen($url), mb_strlen($text)); $offset = $start + mb_strlen($modified_url); } - + return $text; } function common_linkify($url) { $display = $url; $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url:$url; - + if ($longurl = common_longurl($url)) { $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8'); $title = "title=\"$longurl\""; } else $title = ''; - + return "$display"; } @@ -653,48 +653,6 @@ function common_relative_profile($sender, $nickname, $dt=null) return null; } -// where should the avatar go for this user? - -function common_avatar_filename($id, $extension, $size=null, $extra=null) -{ - global $config; - - if ($size) { - return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension; - } else { - return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension; - } -} - -function common_avatar_path($filename) -{ - global $config; - return INSTALLDIR . '/avatar/' . $filename; -} - -function common_avatar_url($filename) -{ - return common_path('avatar/'.$filename); -} - -function common_avatar_display_url($avatar) -{ - $server = common_config('avatar', 'server'); - if ($server) { - return 'http://'.$server.'/'.$avatar->filename; - } else { - return $avatar->url; - } -} - -function common_default_avatar($size) -{ - static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile', - AVATAR_STREAM_SIZE => 'stream', - AVATAR_MINI_SIZE => 'mini'); - return theme_path('default-avatar-'.$sizenames[$size].'.png'); -} - function common_local_url($action, $args=null, $fragment=null) { $url = null; @@ -1511,16 +1469,6 @@ function common_markup_to_html($c) return Markdown($c); } -function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) -{ - $avatar = $profile->getAvatar($size); - if ($avatar) { - return common_avatar_display_url($avatar); - } else { - return common_default_avatar($size); - } -} - function common_profile_uri($profile) { if (!$profile) { diff --git a/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php index 3a4f8315d3..40f60da5d8 100755 --- a/scripts/enjitqueuehandler.php +++ b/scripts/enjitqueuehandler.php @@ -74,7 +74,7 @@ class EnjitQueueHandler extends QueueHandler $atom .= "\n"; $atom .= " $profile->nickname)) . "'/>\n"; $atom .= "" . $profile->nickname . "\n"; - $atom .= "" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "\n"; + $atom .= "" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "\n"; $atom .= "\n"; $atom .= "" . htmlspecialchars($msg) . "\n"; $atom .= "" . htmlspecialchars($msg) . "\n";