1 hunk ./actions/profilesettings.php 57
2 - if ($this->arg('save')) {
3 - $this->save_profile();
4 - } else if ($this->arg('upload')) {
5 - $this->upload_avatar();
6 - } else if ($this->arg('changepass')) {
7 - $this->change_password();
9 + if ($this->arg('save')) {
10 + $this->save_profile();
11 + } else if ($this->arg('upload')) {
12 + $this->upload_avatar();
13 + } else if ($this->arg('crop')) {
14 + $this->crop_avatar();
15 + } else if ($this->arg('changepass')) {
16 + $this->change_password();
18 + $this->show_form(_('Unexpected form submission.'));
20 hunk ./actions/profilesettings.php 77
21 - common_element_start('form', array('method' => 'POST',
22 - 'id' => 'profilesettings',
24 - common_local_url('profilesettings')));
25 - common_hidden('token', common_session_token());
27 - # too much common patterns here... abstractable?
29 - common_input('nickname', _('Nickname'),
30 - ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname,
31 - _('1-64 lowercase letters or numbers, no punctuation or spaces'));
32 - common_input('fullname', _('Full name'),
33 - ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname);
34 - common_input('homepage', _('Homepage'),
35 - ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage,
36 - _('URL of your homepage, blog, or profile on another site'));
37 - common_textarea('bio', _('Bio'),
38 - ($this->arg('bio')) ? $this->arg('bio') : $profile->bio,
39 - _('Describe yourself and your interests in 140 chars'));
40 - common_input('location', _('Location'),
41 - ($this->arg('location')) ? $this->arg('location') : $profile->location,
42 - _('Where you are, like "City, State (or Region), Country"'));
43 - common_input('tags', _('Tags'),
44 - ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()),
45 - _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated'));
46 + common_element_start('form', array('method' => 'POST',
47 + 'id' => 'profilesettings',
48 + 'action' => common_local_url('profilesettings')));
49 + common_hidden('token', common_session_token());
51 + # too much common patterns here... abstractable?
53 + common_input('nickname', _('Nickname'),
54 + ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname,
55 + _('1-64 lowercase letters or numbers, no punctuation or spaces'));
56 + common_input('fullname', _('Full name'),
57 + ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname);
58 + common_input('homepage', _('Homepage'),
59 + ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage,
60 + _('URL of your homepage, blog, or profile on another site'));
61 + common_textarea('bio', _('Bio'),
62 + ($this->arg('bio')) ? $this->arg('bio') : $profile->bio,
63 + _('Describe yourself and your interests in 140 chars'));
64 + common_input('location', _('Location'),
65 + ($this->arg('location')) ? $this->arg('location') : $profile->location,
66 + _('Where you are, like "City, State (or Region), Country"'));
67 + common_input('tags', _('Tags'),
68 + ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()),
69 + _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated'));
70 hunk ./actions/profilesettings.php 118
72 hunk ./actions/profilesettings.php 142
74 - common_element('img', array('src' => $original->url,
75 - 'class' => 'avatar original',
76 - 'width' => $original->width,
77 - 'height' => $original->height,
78 - 'alt' => $user->nickname));
81 + common_element_start('div', array('id'=>'avatar_original', 'class'=>'avatar_view'));
82 + common_element('h3', null, _("Original:"));
83 + common_element_start('div', array('id'=>'avatar_original_view'));
84 + common_element('img', array('src' => $original->url,
85 + 'class' => 'avatar original',
86 + 'width' => $original->width,
87 + 'height' => $original->height,
88 + 'alt' => $user->nickname));
89 + common_element_end('div');
90 + common_element_end('div');
92 hunk ./actions/profilesettings.php 157
94 - common_element('img', array('src' => $avatar->url,
95 - 'class' => 'avatar profile',
96 - 'width' => AVATAR_PROFILE_SIZE,
97 - 'height' => AVATAR_PROFILE_SIZE,
98 - 'alt' => $user->nickname));
101 + common_element_start('div', array('id'=>'avatar_preview', 'class'=>'avatar_view'));
102 + common_element('h3', null, _("Preview:"));
103 + common_element_start('div', array('id'=>'avatar_preview_view'));
104 + common_element('img', array('src' => $original->url,//$avatar->url,
105 + 'class' => 'avatar profile',
106 + 'width' => AVATAR_PROFILE_SIZE,
107 + 'height' => AVATAR_PROFILE_SIZE,
108 + 'alt' => $user->nickname));
109 + common_element_end('div');
110 + common_element_end('div');
111 hunk ./actions/profilesettings.php 169
112 + foreach(array('avatar_crop_x', 'avatar_crop_y', 'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
113 + common_element('input', array('name' => $crop_info,
114 + 'type' => 'hidden',
115 + 'id' => $crop_info));
117 + common_submit('crop', _('Crop'));
119 hunk ./actions/profilesettings.php 184
121 hunk ./actions/profilesettings.php 410
122 - @unlink($_FILES['avatarfile']['tmp_name']);
124 + @unlink($_FILES['avatarfile']['tmp_name']);
127 + function crop_avatar() {
129 + $user = common_current_user();
130 + $profile = $user->getProfile();
132 + $x = $this->arg('avatar_crop_x');
133 + $y = $this->arg('avatar_crop_y');
134 + $w = $this->arg('avatar_crop_w');
135 + $h = $this->arg('avatar_crop_h');
137 + if ($profile->crop_avatars($x, $y, $w, $h)) {
138 + $this->show_form(_('Avatar updated.'), true);
140 + $this->show_form(_('Failed updating avatar.'));
143 hunk ./classes/Avatar.php 82
144 - function to_image() {
145 - $filepath = common_avatar_path($this->filename);
146 - if ($this->mediatype == 'image/gif') {
147 - return imagecreatefromgif($filepath);
148 - } else if ($this->mediatype == 'image/jpeg') {
149 - return imagecreatefromjpeg($filepath);
150 - } else if ($this->mediatype == 'image/png') {
151 - return imagecreatefrompng($filepath);
157 - function &pkeyGet($kv) {
158 - return Memcached_DataObject::pkeyGet('Avatar', $kv);
160 + function scale_and_crop($size, $x, $y, $w, $h)
163 + $image_s = imagecreatetruecolor($size, $size);
164 + $image_a = $this->to_image();
166 + # Retain alpha channel info if possible for .pngs
167 + $background = imagecolorallocate($image_s, 0, 0, 0);
168 + ImageColorTransparent($image_s, $background);
169 + imagealphablending($image_s, false);
171 + imagecopyresized($image_s, $image_a, 0, 0, $x, $y, $size, $size, $w, $h);
173 + $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png";
175 + $filename = common_avatar_filename($this->profile_id, $ext, $size, common_timestamp());
177 + if ($this->mediatype == 'image/jpeg') {
178 + imagejpeg($image_s, common_avatar_path($filename));
180 + imagepng($image_s, common_avatar_path($filename));
183 + $cropped = DB_DataObject::factory('avatar');
184 + $cropped->profile_id = $this->profile_id;
185 + $cropped->width = $size;
186 + $cropped->height = $size;
187 + $cropped->original = false;
188 + $cropped->mediatype = ($this->mediattype == 'image/jpeg') ? 'image/jpeg' : 'image/png';
189 + $cropped->filename = $filename;
190 + $cropped->url = common_avatar_url($filename);
191 + $cropped->created = DB_DataObject_Cast::dateTime(); # current time
193 + if ($cropped->insert()) {
200 + function to_image()
202 + $filepath = common_avatar_path($this->filename);
203 + if ($this->mediatype == 'image/gif') {
204 + return imagecreatefromgif($filepath);
205 + } else if ($this->mediatype == 'image/jpeg') {
206 + return imagecreatefromjpeg($filepath);
207 + } else if ($this->mediatype == 'image/png') {
208 + return imagecreatefrompng($filepath);
214 + function &pkeyGet($kv)
216 + return Memcached_DataObject::pkeyGet('Avatar', $kv);
219 hunk ./classes/Profile.php 124
220 - function delete_avatars() {
221 - $avatar = new Avatar();
222 - $avatar->profile_id = $this->id;
224 - while ($avatar->fetch()) {
229 + function crop_avatars($x, $y, $w, $h)
232 + $avatar = $this->getOriginalAvatar();
233 + $this->delete_avatars(false); # don't delete original
235 + foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
236 + # We don't do a scaled one if original is our scaled size
237 + if (!($avatar->width == $size && $avatar->height == $size)) {
238 + $s = $avatar->scale_and_crop($size, $x, $y, $w, $h);
247 + function delete_avatars($original=true)
249 + $avatar = new Avatar();
250 + $avatar->profile_id = $this->id;
252 + while ($avatar->fetch()) {
253 + if ($avatar->original) {
254 + if ($original == false) {
262 hunk ./lib/settingsaction.php 63
263 - function form_header($title, $msg=NULL, $success=false) {
264 - common_show_header($title,
266 - array($msg, $success),
267 - array($this, 'show_top'));
269 + function form_header($title, $msg=NULL, $success=false)
271 + common_show_header($title,
272 + array($this, 'show_header'),
273 + array($msg, $success),
274 + array($this, 'show_top'));
277 + function show_header()
279 + common_element('link', array('rel' => 'stylesheet',
280 + 'type' => 'text/css',
281 + 'href' => common_path('js/jcrop/jquery.Jcrop.css?version='.LACONICA_VERSION),
282 + 'media' => 'screen, projection, tv'));
283 + common_element('script', array('type' => 'text/javascript',
284 + 'src' => common_path('js/jcrop/jquery.Jcrop.pack.js')));
285 + common_element('script', array('type' => 'text/javascript',
286 + 'src' => common_path('js/jcrop/jquery.Jcrop.go.js')));