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 );
71 // Unset the profile photo flag from any other photos I own
73 $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
74 dbesc($base_image['resource-id']),
78 $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
79 dbesc(datetime_convert()),
83 // Update global directory in background
84 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
85 $url = $_SESSION['my_url'];
86 if($url && strlen(get_config('system','directory_submit_url')))
87 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
91 notice( t('Unable to process image') . EOL);
93 goaway($a->get_baseurl() . '/profiles');
97 $src = $_FILES['userfile']['tmp_name'];
98 $filename = basename($_FILES['userfile']['name']);
99 $filesize = intval($_FILES['userfile']['size']);
101 $imagedata = @file_get_contents($src);
102 $ph = new Photo($imagedata);
104 if(! $ph->is_valid()) {
105 notice( t('Unable to process image.') . EOL );
112 $width = $ph->getWidth();
113 $height = $ph->getHeight();
115 if($width < 175 || $height < 175) {
116 $ph->scaleImageUp(200);
117 $width = $ph->getWidth();
118 $height = $ph->getHeight();
121 $hash = photo_new_resource();
126 $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 );
129 notice( t('Image uploaded successfully.') . EOL );
131 notice( t('Image upload failed.') . EOL );
133 if($width > 640 || $height > 640) {
134 $ph->scaleImage(640);
135 $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 );
138 notice( t('Image size reduction [640] failed.') . EOL );
143 $a->config['imagecrop'] = $hash;
144 $a->config['imagecrop_resolution'] = $smallest;
145 $a->page['htmlhead'] .= load_view_file("view/crophead.tpl");
150 if(! function_exists('profile_photo_content')) {
151 function profile_photo_content(&$a) {
154 notice( t('Permission denied.') . EOL );
158 if(! x($a->config,'imagecrop')) {
160 $tpl = load_view_file('view/profile_photo.tpl');
162 $o .= replace_macros($tpl,array(
169 $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg';
170 $resolution = $a->config['imagecrop_resolution'];
171 $tpl = load_view_file("view/cropbody.tpl");
172 $o .= replace_macros($tpl,array(
173 '$filename' => $filename,
174 '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],
175 '$image_url' => $a->get_baseurl() . '/photo/' . $filename
181 return; // NOTREACHED