X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fprofile_photo.php;h=b21d9162a01e3622ccf6ec8a8abfc6e1f66efe5b;hb=d2e20d029ab603479400393ea4d6fb0e8be9a5eb;hp=ebd9f1b48104caa8c3b44783ffcf0812011892b5;hpb=d11c1c63c02e88b3c73336741a2240ccc18d3b02;p=friendica.git diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ebd9f1b481..b21d9162a0 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -45,7 +45,7 @@ function profile_photo_post(&$a) { //dbg(3); $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1", dbesc($image_id), - dbesc($_SESSION['uid']), + dbesc(local_user()), intval($scale)); if(count($r)) { @@ -53,32 +53,42 @@ function profile_photo_post(&$a) { $base_image = $r[0]; $im = new Photo($base_image['data']); - $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); + if($im->is_valid()) { + $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); - $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, 1); + $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, 1); - if($r === false) - notice ( t('Image size reduction (175) failed.') . EOL ); + if($r === false) + notice ( t('Image size reduction [175] failed.') . EOL ); - $im->scaleImage(80); + $im->scaleImage(80); - $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, 1); + $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, 1); - if($r === false) - notice( t('Image size reduction (80) failed.') . EOL ); - - // Unset the profile photo flag from any other photos I own - - $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", - dbesc($base_image['resource-id']), - intval($_SESSION['uid']) - ); - - $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1", - dbesc(datetime_convert()), - intval($_SESSION['uid']) - ); - + if($r === false) + notice( t('Image size reduction [80] failed.') . EOL ); + + // Unset the profile photo flag from any other photos I own + + $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", + dbesc($base_image['resource-id']), + intval(local_user()) + ); + + $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1", + dbesc(datetime_convert()), + intval(local_user()) + ); + + // Update global directory in background + $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + $url = $_SESSION['my_url']; + if($url && strlen(get_config('system','directory_submit_url'))) + proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &", + array(),$foo)); + } + else + notice( t('Unable to process image') . EOL); } goaway($a->get_baseurl() . '/profiles'); return; // NOTREACHED @@ -91,7 +101,7 @@ function profile_photo_post(&$a) { $imagedata = @file_get_contents($src); $ph = new Photo($imagedata); - if(! ($image = $ph->getImage())) { + if(! $ph->is_valid()) { notice( t('Unable to process image.') . EOL ); @unlink($src); return; @@ -108,12 +118,12 @@ function profile_photo_post(&$a) { $height = $ph->getHeight(); } - $hash = hash('md5',uniqid(mt_rand(),true)); + $hash = photo_new_resource(); $smallest = 0; - $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 0 ); + $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 ); if($r) notice( t('Image uploaded successfully.') . EOL ); @@ -122,17 +132,17 @@ function profile_photo_post(&$a) { if($width > 640 || $height > 640) { $ph->scaleImage(640); - $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 1 ); + $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 ); if($r === false) - notice( t('Image size reduction (640) failed.') . EOL ); + notice( t('Image size reduction [640] failed.') . EOL ); else $smallest = 1; } $a->config['imagecrop'] = $hash; $a->config['imagecrop_resolution'] = $smallest; - $a->page['htmlhead'] .= file_get_contents("view/crophead.tpl"); + $a->page['htmlhead'] .= load_view_file("view/crophead.tpl"); return; } @@ -147,7 +157,7 @@ function profile_photo_content(&$a) { if(! x($a->config,'imagecrop')) { - $tpl = file_get_contents('view/profile_photo.tpl'); + $tpl = load_view_file('view/profile_photo.tpl'); $o .= replace_macros($tpl,array( @@ -158,7 +168,7 @@ function profile_photo_content(&$a) { else { $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.jpg'; $resolution = $a->config['imagecrop_resolution']; - $tpl = file_get_contents("view/cropbody.tpl"); + $tpl = load_view_file("view/cropbody.tpl"); $o .= replace_macros($tpl,array( '$filename' => $filename, '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'],