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 $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
59 `height`, `width`, `data`, `scale`, `profile` )
60 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 4, 1 )",
61 intval($_SESSION['uid']),
62 dbesc($base_image['resource-id']),
65 dbesc($base_image['filename']),
66 dbesc( t('Profile Photos') ),
67 intval($im->getHeight()),
68 intval($im->getWidth()),
69 dbesc($im->imageString())
73 notice ( t('Image size reduction (175) failed.') . EOL );
77 $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
78 `height`, `width`, `data`, `scale`, `profile` )
79 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 5, 1 )",
80 intval($_SESSION['uid']),
81 dbesc($base_image['resource-id']),
84 dbesc($base_image['filename']),
85 dbesc( t('Profile Photos') ),
86 intval($im->getHeight()),
87 intval($im->getWidth()),
88 dbesc($im->imageString())
92 notice( t('Image size reduction (80) failed.') . EOL );
94 // Unset the profile photo flag from any other photos I own
96 $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
97 dbesc($base_image['resource-id']),
98 intval($_SESSION['uid'])
102 goaway($a->get_baseurl() . '/profiles');
103 return; // NOTREACHED
106 $src = $_FILES['userfile']['tmp_name'];
107 $filename = basename($_FILES['userfile']['name']);
108 $filesize = intval($_FILES['userfile']['size']);
110 $imagedata = @file_get_contents($src);
111 $ph = new Photo($imagedata);
113 if(! ($image = $ph->getImage())) {
114 notice( t('Unable to process image.') . EOL );
121 $width = $ph->getWidth();
122 $height = $ph->getHeight();
124 if($width < 175 || $height < 175) {
125 $ph->scaleImageUp(200);
126 $width = $ph->getWidth();
127 $height = $ph->getHeight();
130 $hash = hash('md5',uniqid(mt_rand(),true));
132 $str_image = $ph->imageString();
135 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
136 `height`, `width`, `data`, `scale` )
137 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
138 intval($_SESSION['uid']),
142 dbesc(basename($filename)),
143 dbesc( t('Profile Photos') ),
148 notice( t('Image uploaded successfully.') . EOL );
150 notice( t('Image upload failed.') . EOL );
152 if($width > 640 || $height > 640) {
153 $ph->scaleImage(640);
154 $str_image = $ph->imageString();
155 $width = $ph->getWidth();
156 $height = $ph->getHeight();
158 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
159 `height`, `width`, `data`, `scale` )
160 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
161 intval($_SESSION['uid']),
165 dbesc(basename($filename)),
166 dbesc( t('Profile Photos') ),
167 intval($ph->getHeight()),
168 intval($ph->getWidth()),
169 dbesc($ph->imageString())
172 notice( t('Image size reduction (640) failed.') . EOL );
177 $a->config['imagecrop'] = $hash;
178 $a->config['imagecrop_resolution'] = $smallest;
179 $a->page['htmlhead'] .= file_get_contents("view/crophead.tpl");
184 if(! function_exists('profile_photo_content')) {
185 function profile_photo_content(&$a) {
188 notice( t('Permission denied.') . EOL );
192 if(! x($a->config,'imagecrop')) {
194 $tpl = file_get_contents('view/profile_photo.tpl');
196 $o .= replace_macros($tpl,array(
203 $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg';
204 $resolution = $a->config['imagecrop_resolution'];
205 $tpl = file_get_contents("view/cropbody.tpl");
206 $o .= replace_macros($tpl,array(
207 '$filename' => $filename,
208 '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],
209 '$image_url' => $a->get_baseurl() . '/photo/' . $filename
215 return; // NOTREACHED