function updateGroupAvatars($group)
{
    if (!have_option('q', 'quiet')) {
        print "Updating avatars for group '" . $group->nickname . "' (" . $group->id . ")...";
    }
    if (empty($group->original_logo)) {
        print "(none found)...";
    } else {
        // Using clone here was screwing up the group->find() iteration
        $orig = User_group::staticGet('id', $group->id);
        $group->original_logo = Avatar::url(basename($group->original_logo));
        $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
        $group->stream_logo = Avatar::url(basename($group->stream_logo));
        $group->mini_logo = Avatar::url(basename($group->mini_logo));
        if (!$group->update($orig)) {
            throw new Exception("Can't update avatars for group " . $group->nickname . ".");
        }
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
Esempio n. 2
0
function updateGroupUrls()
{
    printfnq("Updating group URLs...\n");
    $group = new User_group();
    if ($group->find()) {
        while ($group->fetch()) {
            try {
                printfv("Updating group {$group->nickname}...");
                $orig = User_group::getKV('id', $group->id);
                if (!empty($group->original_logo)) {
                    $group->original_logo = Avatar::url(basename($group->original_logo));
                    $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
                    $group->stream_logo = Avatar::url(basename($group->stream_logo));
                    $group->mini_logo = Avatar::url(basename($group->mini_logo));
                }
                // XXX: this is a hack to see if a group is local or not
                $localUri = common_local_url('groupbyid', array('id' => $group->id));
                if ($group->getUri() != $localUri) {
                    $group->mainpage = common_local_url('showgroup', array('nickname' => $group->nickname));
                }
                $group->update($orig);
                printfv("DONE.");
            } catch (Exception $e) {
                echo "Can't update avatars for group " . $group->nickname . ": " . $e->getMessage();
            }
        }
    }
}
Esempio n. 3
0
 function showCropForm()
 {
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_avatar', 'class' => 'form_settings', 'action' => common_local_url('grouplogo', array('nickname' => $this->group->nickname))));
     $this->elementStart('fieldset');
     $this->element('legend', null, _('Avatar settings'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     $this->elementStart('li', array('id' => 'avatar_original', 'class' => 'avatar_view'));
     $this->element('h2', null, _("Original"));
     $this->elementStart('div', array('id' => 'avatar_original_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $this->group->nickname));
     $this->elementEnd('div');
     $this->elementEnd('li');
     $this->elementStart('li', array('id' => 'avatar_preview', 'class' => 'avatar_view'));
     $this->element('h2', null, _("Preview"));
     $this->elementStart('div', array('id' => 'avatar_preview_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $this->group->nickname));
     $this->elementEnd('div');
     foreach (array('avatar_crop_x', 'avatar_crop_y', 'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
         $this->element('input', array('name' => $crop_info, 'type' => 'hidden', 'id' => $crop_info));
     }
     $this->submit('crop', _('Crop'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     // XXX: Do we want to have a bunch of different size icons? homepage, stream, mini?
     // or just one and control size via CSS? --Zach
     $orig = clone $this;
     $this->icon = Avatar::url($filename);
     common_debug(common_log_objstring($this));
     return $this->update($orig);
 }
Esempio n. 5
0
 function showCropForm()
 {
     $user = common_current_user();
     $profile = $user->getProfile();
     if (!$profile) {
         common_log_db_error($user, 'SELECT', __FILE__);
         $this->serverError(_('User without matching profile.'));
         return;
     }
     $original = $profile->getOriginalAvatar();
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_avatar', 'class' => 'form_settings', 'action' => common_local_url('avatarsettings')));
     $this->elementStart('fieldset');
     $this->element('legend', null, _('Avatar settings'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     $this->elementStart('li', array('id' => 'avatar_original', 'class' => 'avatar_view'));
     $this->element('h2', null, _("Original"));
     $this->elementStart('div', array('id' => 'avatar_original_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $user->nickname));
     $this->elementEnd('div');
     $this->elementEnd('li');
     $this->elementStart('li', array('id' => 'avatar_preview', 'class' => 'avatar_view'));
     $this->element('h2', null, _("Preview"));
     $this->elementStart('div', array('id' => 'avatar_preview_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $user->nickname));
     $this->elementEnd('div');
     foreach (array('avatar_crop_x', 'avatar_crop_y', 'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
         $this->element('input', array('name' => $crop_info, 'type' => 'hidden', 'id' => $crop_info));
     }
     $this->submit('crop', _('Crop'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
 function newAvatar($profile_id, $size, $mediatype, $filename)
 {
     global $config;
     $avatar = new Avatar();
     $avatar->profile_id = $profile_id;
     switch ($size) {
         case 'mini':
             $avatar->width = 24;
             $avatar->height = 24;
             break;
         case 'normal':
             $avatar->width = 48;
             $avatar->height = 48;
             break;
         default:
             // Note: Twitter's big avatars are a different size than
             // StatusNet's (StatusNet's = 96)
             $avatar->width = 73;
             $avatar->height = 73;
     }
     $avatar->original = 0;
     // we don't have the original
     $avatar->mediatype = $mediatype;
     $avatar->filename = $filename;
     $avatar->url = Avatar::url($filename);
     $avatar->created = common_sql_now();
     try {
         $id = $avatar->insert();
     } catch (Exception $e) {
         common_log(LOG_WARNING, $this->name() . ' Couldn\'t insert avatar - ' . $e->getMessage());
     }
     if (empty($id)) {
         common_log_db_error($avatar, 'INSERT', __FILE__);
         return null;
     }
     common_debug($this->name() . " - Saved new {$size} avatar for {$profile_id}.");
     return $id;
 }
Esempio n. 7
0
 function showCropForm()
 {
     $user = common_current_user();
     $profile = $user->getProfile();
     if (!$profile) {
         common_log_db_error($user, 'SELECT', __FILE__);
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_('User has no profile.'));
         return;
     }
     $original = $profile->getOriginalAvatar();
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_avatar', 'class' => 'form_settings', 'action' => common_local_url('avatarsettings')));
     $this->elementStart('fieldset');
     // TRANS: Avatar upload page crop form legend.
     $this->element('legend', null, _('Avatar settings'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     $this->elementStart('li', array('id' => 'avatar_original', 'class' => 'avatar_view'));
     // TRANS: Header on avatar upload crop form for thumbnail of originally uploaded avatar (h2).
     $this->element('h2', null, _('Original'));
     $this->elementStart('div', array('id' => 'avatar_original_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $user->nickname));
     $this->elementEnd('div');
     $this->elementEnd('li');
     $this->elementStart('li', array('id' => 'avatar_preview', 'class' => 'avatar_view'));
     // TRANS: Header on avatar upload crop form for thumbnail of to be used rendition of uploaded avatar (h2).
     $this->element('h2', null, _('Preview'));
     $this->elementStart('div', array('id' => 'avatar_preview_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $user->nickname));
     $this->elementEnd('div');
     foreach (array('avatar_crop_x', 'avatar_crop_y', 'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
         $this->element('input', array('name' => $crop_info, 'type' => 'hidden', 'id' => $crop_info));
     }
     // TRANS: Button on avatar upload crop form to confirm a selected crop as avatar.
     $this->submit('crop', _m('BUTTON', 'Crop'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Esempio n. 8
0
 function setOriginal($filename)
 {
     // This should be handled by the Profile->setOriginal function so user and group avatars are handled the same
     $imagefile = new ImageFile(null, Avatar::path($filename));
     $sizes = array('homepage_logo' => AVATAR_PROFILE_SIZE, 'stream_logo' => AVATAR_STREAM_SIZE, 'mini_logo' => AVATAR_MINI_SIZE);
     $orig = clone $this;
     $this->original_logo = Avatar::url($filename);
     foreach ($sizes as $name => $size) {
         $filename = Avatar::filename($this->profile_id, image_type_to_extension($imagefile->preferredType()), $size, common_timestamp());
         $imagefile->resizeTo(Avatar::path($filename), array('width' => $size, 'height' => $size));
         $this->{$name} = Avatar::url($filename);
     }
     common_debug(common_log_objstring($this));
     return $this->update($orig);
 }
Esempio n. 9
0
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $avatar = new Avatar();
     $avatar->profile_id = $this->id;
     $avatar->width = $imagefile->width;
     $avatar->height = $imagefile->height;
     $avatar->mediatype = image_type_to_mime_type($imagefile->type);
     $avatar->filename = $filename;
     $avatar->original = true;
     $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(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;
             $scaled->width = $size;
             $scaled->height = $size;
             $scaled->original = false;
             $scaled->mediatype = image_type_to_mime_type($imagefile->type);
             $scaled->filename = $scaled_filename;
             $scaled->url = Avatar::url($scaled_filename);
             $scaled->created = DB_DataObject_Cast::dateTime();
             # current time
             if (!$scaled->insert()) {
                 return null;
             }
         }
     }
     return $avatar;
 }
Esempio n. 10
0
 public function setOriginal($filename)
 {
     if ($this->isGroup()) {
         // Until Group avatars are handled just like profile avatars.
         return $this->getGroup()->setOriginal($filename);
     }
     $imagefile = new ImageFile(null, Avatar::path($filename));
     $avatar = new Avatar();
     $avatar->profile_id = $this->id;
     $avatar->width = $imagefile->width;
     $avatar->height = $imagefile->height;
     $avatar->mediatype = image_type_to_mime_type($imagefile->type);
     $avatar->filename = $filename;
     $avatar->original = true;
     $avatar->url = Avatar::url($filename);
     $avatar->created = common_sql_now();
     // XXX: start a transaction here
     if (!Avatar::deleteFromProfile($this, true) || !$avatar->insert()) {
         // If we can't delete the old avatars, let's abort right here.
         @unlink(Avatar::path($filename));
         return null;
     }
     return $avatar;
 }
Esempio n. 11
0
function updateAvatars($user)
{
    $touched = false;
    if (!have_option('q', 'quiet')) {
        print "Updating avatars for user '" . $user->nickname . "' (" . $user->id . ")...";
    }
    $avatar = new Avatar();
    $avatar->profile_id = $user->id;
    if (!$avatar->find()) {
        if (have_option('v', 'verbose')) {
            print "(none found)...";
        }
    } else {
        while ($avatar->fetch()) {
            if (have_option('v', 'verbose')) {
                if ($avatar->original) {
                    print "original...";
                } else {
                    print $avatar->width . "...";
                }
            }
            $orig_url = $avatar->url;
            $avatar->url = Avatar::url($avatar->filename);
            if ($avatar->url != $orig_url) {
                $sql = "UPDATE avatar SET url = '" . $avatar->url . "' " . "WHERE profile_id = " . $avatar->profile_id . " " . "AND width = " . $avatar->width . " " . "AND height = " . $avatar->height . " ";
                if ($avatar->original) {
                    $sql .= "AND original = 1 ";
                }
                if (!$avatar->query($sql)) {
                    throw new Exception("Can't update avatar for user " . $user->nickname . ".");
                } else {
                    $touched = true;
                }
            }
        }
    }
    if ($touched) {
        $profile = $user->getProfile();
        common_broadcast_profile($profile);
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
Esempio n. 12
0
 protected function newAvatar(Profile $profile, $url, $filename, $mediatype)
 {
     // Clear out old avatars, won't do anything if there are none
     Avatar::deleteFromProfile($profile);
     // throws exception if unable to fetch
     $this->fetchRemoteUrl($url, Avatar::path($filename));
     $avatar = new Avatar();
     $avatar->profile_id = $profile->id;
     $avatar->original = 1;
     // this is an original/"uploaded" avatar
     $avatar->mediatype = $mediatype;
     $avatar->filename = $filename;
     $avatar->url = Avatar::url($filename);
     $avatar->width = $this->avatarsize;
     $avatar->height = $this->avatarsize;
     $avatar->created = common_sql_now();
     $id = $avatar->insert();
     if (empty($id)) {
         common_log(LOG_WARNING, __METHOD__ . " Couldn't insert avatar - " . $e->getMessage());
         common_log_db_error($avatar, 'INSERT', __FILE__);
         throw new ServerException('Could not insert avatar');
     }
     common_debug(__METHOD__ . " - Saved new avatar for {$profile->id}.");
     return $avatar;
 }
Esempio n. 13
0
 function displayUrl()
 {
     return Avatar::url($this->filename);
 }
Esempio n. 14
0
 static function newSize(Profile $target, $width)
 {
     $width = intval($width);
     if ($width < 1 || $width > common_config('avatar', 'maxsize')) {
         // TRANS: An error message when avatar size is unreasonable
         throw new Exception(_m('Avatar size too large'));
     }
     // So far we only have square avatars and I don't have time to
     // rewrite support for non-square ones right now ;)
     $height = $width;
     $original = Avatar::getUploaded($target);
     $imagefile = new ImageFile(null, Avatar::path($original->filename));
     $filename = Avatar::filename($target->getID(), image_type_to_extension($imagefile->preferredType()), $width, common_timestamp());
     $imagefile->resizeTo(Avatar::path($filename), array('width' => $width, 'height' => $height));
     $scaled = clone $original;
     $scaled->original = false;
     $scaled->width = $width;
     $scaled->height = $height;
     $scaled->url = Avatar::url($filename);
     $scaled->filename = $filename;
     $scaled->created = common_sql_now();
     if (!$scaled->insert()) {
         // TRANS: An error message when unable to insert avatar data into the db
         throw new Exception(_m('Could not insert new avatar data to database'));
     }
     // Return the new avatar object
     return $scaled;
 }
Esempio n. 15
0
 function showCropForm()
 {
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_avatar', 'class' => 'form_settings', 'action' => common_local_url('grouplogo', array('nickname' => $this->group->nickname))));
     $this->elementStart('fieldset');
     // TRANS: Legend for group logo settings fieldset.
     $this->element('legend', null, _('Avatar settings'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     $this->elementStart('li', array('id' => 'avatar_original', 'class' => 'avatar_view'));
     // TRANS: Header for originally uploaded file before a crop on the group logo page.
     $this->element('h2', null, _('Original'));
     $this->elementStart('div', array('id' => 'avatar_original_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => $this->filedata['width'], 'height' => $this->filedata['height'], 'alt' => $this->group->nickname));
     $this->elementEnd('div');
     $this->elementEnd('li');
     $this->elementStart('li', array('id' => 'avatar_preview', 'class' => 'avatar_view'));
     // TRANS: Header for the cropped group logo on the group logo page.
     $this->element('h2', null, _('Preview'));
     $this->elementStart('div', array('id' => 'avatar_preview_view'));
     $this->element('img', array('src' => Avatar::url($this->filedata['filename']), 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $this->group->nickname));
     $this->elementEnd('div');
     foreach (array('avatar_crop_x', 'avatar_crop_y', 'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
         $this->element('input', array('name' => $crop_info, 'type' => 'hidden', 'id' => $crop_info));
     }
     // TRANS: Button text for cropping an uploaded group logo.
     $this->submit('crop', _('Crop'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Esempio n. 16
0
 function displayUrl()
 {
     $server = common_config('avatar', 'server');
     if ($server && !empty($this->filename)) {
         return Avatar::url($this->filename);
     } else {
         return $this->url;
     }
 }
Esempio n. 17
0
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $orig = clone $this;
     $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);
 }
Esempio n. 18
0
 function newAvatar($profile_id, $size, $mediatype, $filename)
 {
     global $config;
     $avatar = new Avatar();
     $avatar->profile_id = $profile_id;
     switch ($size) {
         case 'mini':
             $avatar->width = 24;
             $avatar->height = 24;
             break;
         case 'normal':
             $avatar->width = 48;
             $avatar->height = 48;
             break;
         default:
             // Note: Twitter's big avatars are a different size than
             // Laconica's (Laconica's = 96)
             $avatar->width = 73;
             $avatar->height = 73;
     }
     $avatar->original = 0;
     // we don't have the original
     $avatar->mediatype = $mediatype;
     $avatar->filename = $filename;
     $avatar->url = Avatar::url($filename);
     if (defined('SCRIPT_DEBUG')) {
         common_debug("new filename: {$avatar->url}");
     }
     $avatar->created = common_sql_now();
     $id = $avatar->insert();
     if (empty($id)) {
         common_log_db_error($avatar, 'INSERT', __FILE__);
         return null;
     }
     if (defined('SCRIPT_DEBUG')) {
         common_debug("Saved new {$size} avatar for {$profile_id}.");
     }
     return $id;
 }