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",
48 dbesc($_SESSION['uid']),
55 $im = new Photo($base_image['data']);
56 $im->cropImage(175,$srcX,$srcY,$srcW,$srcH);
58 $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, 1);
61 notice ( t('Image size reduction (175) failed.') . EOL );
65 $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, 1);
68 notice( t('Image size reduction (80) failed.') . EOL );
70 // Unset the profile photo flag from any other photos I own
72 $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
73 dbesc($base_image['resource-id']),
74 intval($_SESSION['uid'])
77 $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
78 dbesc(datetime_convert()),
79 intval($_SESSION['uid'])
83 goaway($a->get_baseurl() . '/profiles');
87 $src = $_FILES['userfile']['tmp_name'];
88 $filename = basename($_FILES['userfile']['name']);
89 $filesize = intval($_FILES['userfile']['size']);
91 $imagedata = @file_get_contents($src);
92 $ph = new Photo($imagedata);
94 if(! ($image = $ph->getImage())) {
95 notice( t('Unable to process image.') . EOL );
102 $width = $ph->getWidth();
103 $height = $ph->getHeight();
105 if($width < 175 || $height < 175) {
106 $ph->scaleImageUp(200);
107 $width = $ph->getWidth();
108 $height = $ph->getHeight();
111 $hash = hash('md5',uniqid(mt_rand(),true));
116 $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 0 );
119 notice( t('Image uploaded successfully.') . EOL );
121 notice( t('Image upload failed.') . EOL );
123 if($width > 640 || $height > 640) {
124 $ph->scaleImage(640);
125 $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 1 );
128 notice( t('Image size reduction (640) failed.') . EOL );
133 $a->config['imagecrop'] = $hash;
134 $a->config['imagecrop_resolution'] = $smallest;
135 $a->page['htmlhead'] .= file_get_contents("view/crophead.tpl");
140 if(! function_exists('profile_photo_content')) {
141 function profile_photo_content(&$a) {
144 notice( t('Permission denied.') . EOL );
148 if(! x($a->config,'imagecrop')) {
150 $tpl = file_get_contents('view/profile_photo.tpl');
152 $o .= replace_macros($tpl,array(
159 $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg';
160 $resolution = $a->config['imagecrop_resolution'];
161 $tpl = file_get_contents("view/cropbody.tpl");
162 $o .= replace_macros($tpl,array(
163 '$filename' => $filename,
164 '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],
165 '$image_url' => $a->get_baseurl() . '/photo/' . $filename
171 return; // NOTREACHED