3 require_once("Photo.php");
5 function profile_photo_init(&$a) {
11 require_once("mod/profile.php");
12 profile_load($a,$a->user['nickname']);
17 function profile_photo_post(&$a) {
20 notice ( t('Permission denied.') . EOL );
24 if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) {
26 // phase 2 - we have finished cropping
29 notice( t('Image uploaded but image cropping failed.') . EOL );
33 $image_id = $a->argv[1];
35 if(substr($image_id,-2,1) == '-') {
36 $scale = substr($image_id,-1,1);
37 $image_id = substr($image_id,0,-2);
41 $srcX = $_POST['xstart'];
42 $srcY = $_POST['ystart'];
43 $srcW = $_POST['xfinal'] - $srcX;
44 $srcH = $_POST['yfinal'] - $srcY;
46 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1",
55 $im = new Photo($base_image['data']);
57 $im->cropImage(175,$srcX,$srcY,$srcW,$srcH);
59 $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, 1);
62 notice ( t('Image size reduction [175] failed.') . EOL );
66 $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, 1);
69 notice( t('Image size reduction [80] failed.') . EOL );
73 $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 6, 1);
76 notice( t('Image size reduction [48] failed.') . EOL );
78 // Unset the profile photo flag from any other photos I own
80 $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
81 dbesc($base_image['resource-id']),
85 $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
86 dbesc(datetime_convert()),
90 // Update global directory in background
91 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
92 $url = $_SESSION['my_url'];
93 if($url && strlen(get_config('system','directory_submit_url')))
94 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
98 notice( t('Unable to process image') . EOL);
101 goaway($a->get_baseurl() . '/profiles');
102 return; // NOTREACHED
105 $src = $_FILES['userfile']['tmp_name'];
106 $filename = basename($_FILES['userfile']['name']);
107 $filesize = intval($_FILES['userfile']['size']);
109 $maximagesize = get_config('system','maximagesize');
111 if(($maximagesize) && ($filesize > $maximagesize)) {
112 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
117 $imagedata = @file_get_contents($src);
118 $ph = new Photo($imagedata);
120 if(! $ph->is_valid()) {
121 notice( t('Unable to process image.') . EOL );
128 $width = $ph->getWidth();
129 $height = $ph->getHeight();
131 if($width < 175 || $height < 175) {
132 $ph->scaleImageUp(200);
133 $width = $ph->getWidth();
134 $height = $ph->getHeight();
137 $hash = photo_new_resource();
142 $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 );
145 notice( t('Image uploaded successfully.') . EOL );
147 notice( t('Image upload failed.') . EOL );
149 if($width > 640 || $height > 640) {
150 $ph->scaleImage(640);
151 $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 );
154 notice( t('Image size reduction [640] failed.') . EOL );
159 $a->config['imagecrop'] = $hash;
160 $a->config['imagecrop_resolution'] = $smallest;
161 $a->page['htmlhead'] .= load_view_file("view/crophead.tpl");
166 if(! function_exists('profile_photo_content')) {
167 function profile_photo_content(&$a) {
170 notice( t('Permission denied.') . EOL );
174 if(! x($a->config,'imagecrop')) {
176 $tpl = load_view_file('view/profile_photo.tpl');
178 $o .= replace_macros($tpl,array(
185 $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg';
186 $resolution = $a->config['imagecrop_resolution'];
187 $tpl = load_view_file("view/cropbody.tpl");
188 $o .= replace_macros($tpl,array(
189 '$filename' => $filename,
190 '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],
191 '$image_url' => $a->get_baseurl() . '/photo/' . $filename
197 return; // NOTREACHED