]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/tentative_pristine
Some fixups of patches not already migrated to trunk to bring inline with PEAR coding...
[quix0rs-gnu-social.git] / _darcs / tentative_pristine
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();
8 -               }
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();
17 +        } else {
18 +            $this->show_form(_('Unexpected form submission.'));
19 +        }
20 hunk ./actions/profilesettings.php 77
21 -               common_element_start('form', array('method' => 'POST',
22 -                                                                                  'id' => 'profilesettings',
23 -                                                                                  'action' =>
24 -                                                                                  common_local_url('profilesettings')));
25 -               common_hidden('token', common_session_token());
26 -               
27 -               # too much common patterns here... abstractable?
28 -               
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());
50 +        
51 +        # too much common patterns here... abstractable?
52 +        
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
71 -
72 hunk ./actions/profilesettings.php 142
73 -               if ($original) {
74 -                       common_element('img', array('src' => $original->url,
75 -                                                                               'class' => 'avatar original',
76 -                                                                               'width' => $original->width,
77 -                                                                               'height' => $original->height,
78 -                                                                               'alt' => $user->nickname));
79 -               }
80 +        if ($original) {
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');
91 +        }
92 hunk ./actions/profilesettings.php 157
93 -               if ($avatar) {
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));
99 -               }
100 +        if ($avatar) {
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));
116 +            }
117 +            common_submit('crop', _('Crop'));
118 +        }
119 hunk ./actions/profilesettings.php 184
120 -
121 hunk ./actions/profilesettings.php 410
122 -               @unlink($_FILES['avatarfile']['tmp_name']);
123 -       }
124 +        @unlink($_FILES['avatarfile']['tmp_name']);
125 +    }
126 +
127 +    function crop_avatar() {
128 +
129 +        $user = common_current_user();
130 +        $profile = $user->getProfile();
131 +
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');
136 +
137 +        if ($profile->crop_avatars($x, $y, $w, $h)) {
138 +            $this->show_form(_('Avatar updated.'), true);
139 +        } else {
140 +            $this->show_form(_('Failed updating avatar.'));
141 +        }
142 +    }
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);
152 -               } else {
153 -                       return NULL;
154 -               }
155 -       }
156 -       
157 -       function &pkeyGet($kv) {
158 -               return Memcached_DataObject::pkeyGet('Avatar', $kv);
159 -       }
160 +    function scale_and_crop($size, $x, $y, $w, $h) 
161 +    {
162 +
163 +        $image_s = imagecreatetruecolor($size, $size);
164 +        $image_a = $this->to_image();
165 +
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);
170 +
171 +        imagecopyresized($image_s, $image_a, 0, 0, $x, $y, $size, $size, $w, $h);
172 +
173 +        $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png";
174 +
175 +        $filename = common_avatar_filename($this->profile_id, $ext, $size, common_timestamp());
176 +
177 +        if ($this->mediatype == 'image/jpeg') {
178 +            imagejpeg($image_s, common_avatar_path($filename));
179 +        } else {
180 +            imagepng($image_s, common_avatar_path($filename));
181 +        }
182 +
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
192 +
193 +        if ($cropped->insert()) {
194 +            return $cropped;
195 +        } else {
196 +            return NULL;
197 +        }
198 +    }
199 +
200 +    function to_image() 
201 +    {
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);
209 +        } else {
210 +            return NULL;
211 +        }
212 +    }
213 +    
214 +    function &pkeyGet($kv) 
215 +    {
216 +        return Memcached_DataObject::pkeyGet('Avatar', $kv);
217 +    }
218 +
219 hunk ./classes/Profile.php 124
220 -       function delete_avatars() {
221 -               $avatar = new Avatar();
222 -               $avatar->profile_id = $this->id;
223 -               $avatar->find();
224 -               while ($avatar->fetch()) {
225 -                       $avatar->delete();
226 -               }
227 -               return true;
228 -       }
229 +    function crop_avatars($x, $y, $w, $h) 
230 +    {
231 +
232 +        $avatar = $this->getOriginalAvatar();
233 +        $this->delete_avatars(false); # don't delete original
234 +
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);
239 +                if (!$s) {
240 +                    return NULL;
241 +                }
242 +            }
243 +        }
244 +        return true;
245 +    }
246 +
247 +    function delete_avatars($original=true) 
248 +    {
249 +        $avatar = new Avatar();
250 +        $avatar->profile_id = $this->id;
251 +        $avatar->find();
252 +        while ($avatar->fetch()) {
253 +            if ($avatar->original) {
254 +                if ($original == false) {
255 +                    continue;
256 +                }
257 +            }
258 +            $avatar->delete();
259 +        }
260 +        return true;
261 +    }
262 hunk ./lib/settingsaction.php 63
263 -       function form_header($title, $msg=NULL, $success=false) {
264 -               common_show_header($title,
265 -                                  NULL,
266 -                                  array($msg, $success),
267 -                                                  array($this, 'show_top'));
268 -       }
269 +    function form_header($title, $msg=NULL, $success=false) 
270 +    {
271 +        common_show_header($title,
272 +                           array($this, 'show_header'),
273 +                           array($msg, $success),
274 +                           array($this, 'show_top'));
275 +    }
276 +
277 +    function show_header() 
278 +    {
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')));
287 +    }