3 require_once("Photo.php");
5 function profile_photo_init(&$a) {
10 require_once("mod/profile.php");
11 profile_load($a,$a->user['nickname']);
15 function profile_photo_post(&$a) {
18 notice ( "Permission denied." . EOL );
22 if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) {
24 // phase 2 - we have finished cropping
27 notice( "Image uploaded but image cropping failed." . EOL );
31 $image_id = $a->argv[1];
33 if(substr($image_id,-2,1) == '-') {
34 $scale = substr($image_id,-1,1);
35 $image_id = substr($image_id,0,-2);
39 $srcX = $_POST['xstart'];
40 $srcY = $_POST['ystart'];
41 $srcW = $_POST['xfinal'] - $srcX;
42 $srcH = $_POST['yfinal'] - $srcY;
44 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1",
46 dbesc($_SESSION['uid']),
53 $im = new Photo($base_image['data']);
54 $im->cropImage(175,$srcX,$srcY,$srcW,$srcH);
56 $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
57 `height`, `width`, `data`, `scale`, `profile` )
58 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 4, 1 )",
59 intval($_SESSION['uid']),
60 dbesc($base_image['resource-id']),
63 dbesc($base_image['filename']),
64 intval($im->getHeight()),
65 intval($im->getWidth()),
66 dbesc($im->imageString())
70 notice ("Image size reduction (175) failed." . EOL );
74 $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
75 `height`, `width`, `data`, `scale`, `profile` )
76 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 5, 1 )",
77 intval($_SESSION['uid']),
78 dbesc($base_image['resource-id']),
81 dbesc($base_image['filename']),
82 intval($im->getHeight()),
83 intval($im->getWidth()),
84 dbesc($im->imageString())
88 notice("Image size reduction (80) failed." . EOL);
90 // Unset the profile photo flag from any other photos I own
92 $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
93 dbesc($base_image['resource-id']),
94 intval($_SESSION['uid'])
98 goaway($a->get_baseurl() . '/profiles');
102 $src = $_FILES['userfile']['tmp_name'];
103 $filename = basename($_FILES['userfile']['name']);
104 $filesize = intval($_FILES['userfile']['size']);
106 $imagedata = @file_get_contents($src);
107 $ph = new Photo($imagedata);
109 if(! ($image = $ph->getImage())) {
110 notice("Unable to process image." . EOL);
117 $width = $ph->getWidth();
118 $height = $ph->getHeight();
120 if($width < 175 || $height < 175) {
121 $ph->scaleImageUp(200);
122 $width = $ph->getWidth();
123 $height = $ph->getHeight();
126 $hash = hash('md5',uniqid(mt_rand(),true));
128 $str_image = $ph->imageString();
131 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
132 `height`, `width`, `data`, `scale` )
133 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
134 intval($_SESSION['uid']),
138 dbesc(basename($filename)),
143 notice("Image uploaded successfully." . EOL);
145 notice("Image upload failed." . EOL);
147 if($width > 640 || $height > 640) {
148 $ph->scaleImage(640);
149 $str_image = $ph->imageString();
150 $width = $ph->getWidth();
151 $height = $ph->getHeight();
153 $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
154 `height`, `width`, `data`, `scale` )
155 VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
156 intval($_SESSION['uid']),
160 dbesc(basename($filename)),
161 intval($ph->getHeight()),
162 intval($ph->getWidth()),
163 dbesc($ph->imageString())
166 notice("Image size reduction (640) failed." . EOL );
171 $a->config['imagecrop'] = $hash;
172 $a->config['imagecrop_resolution'] = $smallest;
173 $a->page['htmlhead'] .= file_get_contents("view/crophead.tpl");
178 if(! function_exists('profile_photo_content')) {
179 function profile_photo_content(&$a) {
182 notice("Permission denied." . EOL );
186 if(! x($a->config,'imagecrop')) {
188 $tpl = file_get_contents('view/profile_photo.tpl');
190 $o .= replace_macros($tpl,array(
197 $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg';
198 $resolution = $a->config['imagecrop_resolution'];
199 $tpl = file_get_contents("view/cropbody.tpl");
200 $o .= replace_macros($tpl,array(
201 '$filename' => $filename,
202 '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],
203 '$image_url' => $a->get_baseurl() . '/photo/' . $filename
209 return; // NOTREACHED