diff options
Diffstat (limited to 'mod/profile_photo.php')
-rw-r--r-- | mod/profile_photo.php | 214 |
1 files changed, 139 insertions, 75 deletions
diff --git a/mod/profile_photo.php b/mod/profile_photo.php index c70e8fc94..7067a9f76 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -92,12 +92,15 @@ function profile_photo_post(&$a) { $is_default_profile = 1; if($_REQUEST['profile']) { - $r = q("select id, is_default from profile where id = %d and uid = %d limit 1", + $r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()) ); - if(($r) && (! intval($r[0]['is_default']))) - $is_default_profile = 0; + if($r) { + $profile = $r[0]; + if(! intval($profile['is_default'])) + $is_default_profile = 0; + } } @@ -130,7 +133,7 @@ function profile_photo_post(&$a) { if($r) { $base_image = $r[0]; - $base_image['data'] = dbunescbin($base_image['data']); + $base_image['data'] = (($r[0]['os_storage']) ? @file_get_contents($base_image['data']) : dbunescbin($base_image['data'])); $im = photo_factory($base_image['data'], $base_image['type']); if($im->is_valid()) { @@ -143,7 +146,7 @@ function profile_photo_post(&$a) { 'filename' => $base_image['filename'], 'album' => t('Profile Photos')); $p['scale'] = 4; - $p['photo_flags'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); + $p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); $r1 = $im->save($p); @@ -167,20 +170,21 @@ function profile_photo_post(&$a) { return; } + $channel = $a->get_channel(); + // If setting for the default profile, unset the profile photo flag from any other photos I own if($is_default_profile) { - $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND resource_id != '%s' AND `uid` = %d", - dbesc($base_image['resource_id']), - intval(local_channel()) - ); - $r = q("UPDATE photo SET photo_flags = ( photo_flags & ~%d ) WHERE ( photo_flags & %d )>0 + $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND `uid` = %d", - intval(PHOTO_PROFILE), + intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), dbesc($base_image['resource_id']), intval(local_channel()) ); + + send_profile_photo_activity($channel,$base_image,$profile); + } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", @@ -194,7 +198,6 @@ function profile_photo_post(&$a) { // We'll set the updated profile-photo timestamp even if it isn't the default profile, // so that browsers will do a cache update unconditionally - $channel = $a->get_channel(); $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'", @@ -210,7 +213,9 @@ function profile_photo_post(&$a) { // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures' - profile_photo_set_profile_perms($_REQUEST['profile']); + profile_photo_set_profile_perms($_REQUEST['profile']); + + } else @@ -221,34 +226,104 @@ function profile_photo_post(&$a) { return; // NOTREACHED } - $src = $_FILES['userfile']['tmp_name']; - $filename = basename($_FILES['userfile']['name']); - $filesize = intval($_FILES['userfile']['size']); - $filetype = $_FILES['userfile']['type']; - if ($filetype=="") $filetype=guess_image_type($filename); - - $maximagesize = get_config('system','maximagesize'); - - if(($maximagesize) && ($filesize > $maximagesize)) { - notice( sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL); - @unlink($src); - return; + + + $hash = photo_new_resource(); + $smallest = 0; + + require_once('include/attach.php'); + + $res = attach_store($a->get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash)); + + logger('attach_store: ' . print_r($res,true)); + + if($res && intval($res['data']['is_photo'])) { + $i = q("select * from photo where resource_id = '%s' and uid = %d order by scale", + dbesc($hash), + intval(local_channel()) + ); + + if(! $i) { + notice( t('Image upload failed.') . EOL ); + return; + } + $os_storage = false; + + foreach($i as $ii) { + if(intval($ii['scale']) < 2) { + $smallest = intval($ii['scale']); + $os_storage = intval($ii['os_storage']); + $imagedata = $ii['data']; + $filetype = $ii['type']; + } + } } - $imagedata = @file_get_contents($src); + $imagedata = (($os_storage) ? @file_get_contents($imagedata) : $imagedata); $ph = photo_factory($imagedata, $filetype); if(! $ph->is_valid()) { notice( t('Unable to process image.') . EOL ); - @unlink($src); return; } - $ph->orient($src); - @unlink($src); - return profile_photo_crop_ui_head($a, $ph); + + return profile_photo_crop_ui_head($a, $ph, $hash, $smallest); } +function send_profile_photo_activity($channel,$photo,$profile) { + + // for now only create activities for the default profile + + if(! intval($profile['is_default'])) + return; + + $arr = array(); + $arr['item_thread_top'] = 1; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['obj_type'] = ACTIVITY_OBJ_PHOTO; + $arr['verb'] = ACTIVITY_UPDATE; + + $arr['object'] = json_encode(array( + 'type' => $arr['obj_type'], + 'id' => z_root() . '/photo/profile/l/' . $channel['channel_id'], + 'link' => array('rel' => 'photo', 'type' => $photo['type'], 'href' => z_root() . '/photo/profile/l/' . $channel['channel_id']) + )); + + if(stripos($profile['gender'],t('female')) !== false) + $t = t('%1$s updated her %2$s'); + elseif(stripos($profile['gender'],t('male')) !== false) + $t = t('%1$s updated his %2$s'); + else + $t = t('%1$s updated their %2$s'); + + $ptext = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . t('profile photo') . '[/zrl]'; + + $ltext = '[zrl=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . '[zmg=150x150]' . z_root() . '/photo/' . $photo['resource_id'] . '-4[/zmg][/zrl]'; + + $arr['body'] = sprintf($t,$channel['channel_name'],$ptext) . "\n\n" . $ltext; + + $acl = new AccessList($channel); + $x = $acl->get(); + $arr['allow_cid'] = $x['allow_cid']; + + $arr['allow_gid'] = $x['allow_gid']; + $arr['deny_cid'] = $x['deny_cid']; + $arr['deny_gid'] = $x['deny_gid']; + + $arr['uid'] = $channel['channel_id']; + $arr['aid'] = $channel['channel_account_id']; + + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $channel['channel_hash']; + + post_activity_item($arr); + + +} + + /* @brief Generate content of profile-photo view * * @param $a Current application @@ -257,7 +332,6 @@ function profile_photo_post(&$a) { */ -if(! function_exists('profile_photo_content')) { function profile_photo_content(&$a) { if(! local_channel()) { @@ -301,20 +375,12 @@ function profile_photo_content(&$a) { if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) { // unset any existing profile photos - $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", - intval(local_channel())); - $r = q("UPDATE photo SET photo_flags = (photo_flags & ~%d ) WHERE (photo_flags & %d )>0 AND uid = %d", - intval(PHOTO_PROFILE), + $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", + intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel())); - // set all sizes of this one as profile photos - $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", - intval(local_channel()), - dbesc($resource_id) - ); - - $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", + $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($resource_id) @@ -331,7 +397,7 @@ function profile_photo_content(&$a) { goaway($a->get_baseurl() . '/profiles'); } - $r = q("SELECT `data`, `type` FROM photo WHERE id = %d and uid = %d limit 1", + $r = q("SELECT `data`, `type`, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_channel()) @@ -341,9 +407,31 @@ function profile_photo_content(&$a) { return; } - $ph = photo_factory(dbunescbin($r[0]['data']), $r[0]['type']); - // go ahead as if we have just uploaded a new photo to crop - profile_photo_crop_ui_head($a, $ph); + if(intval($r[0]['os_storage'])) + $data = @file_get_contents($r[0]['data']); + else + $data = dbunescbin($r[0]['data']); + + $ph = photo_factory($data, $r[0]['type']); + $smallest = 0; + if($ph->is_valid()) { + // go ahead as if we have just uploaded a new photo to crop + $i = q("select resource_id, scale from photo where resource_id = '%s' and uid = %d order by scale", + dbesc($r[0]['resource_id']), + intval(local_channel()) + ); + + if($i) { + $hash = $i[0]['resource_id']; + foreach($i as $ii) { + if(intval($ii['scale']) < 2) { + $smallest = intval($ii['scale']); + } + } + } + } + + profile_photo_crop_ui_head($a, $ph, $hash, $smallest); } $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", @@ -371,7 +459,7 @@ function profile_photo_content(&$a) { return $o; } else { - $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'] . '.' . $a->data['imagecrop_ext']; + $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution']; $resolution = $a->data['imagecrop_resolution']; $tpl = get_markup_template("cropbody.tpl"); $o .= replace_macros($tpl,array( @@ -388,7 +476,7 @@ function profile_photo_content(&$a) { } return; // NOTREACHED -}} +} /* @brief Generate the UI for photo-cropping * @@ -399,8 +487,8 @@ function profile_photo_content(&$a) { */ -if(! function_exists('profile_photo_crop_ui_head')) { -function profile_photo_crop_ui_head(&$a, $ph){ + +function profile_photo_crop_ui_head(&$a, $ph, $hash, $smallest){ $max_length = get_config('system','max_image_length'); if(! $max_length) @@ -417,34 +505,10 @@ function profile_photo_crop_ui_head(&$a, $ph){ $height = $ph->getHeight(); } - $hash = photo_new_resource(); - $smallest = 0; - - $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, - 'filename' => $filename, 'album' => t('Profile Photos'), 'scale' => 0); - $r = $ph->save($p); - - if($r) - info( t('Image uploaded successfully.') . EOL ); - else - notice( t('Image upload failed.') . EOL ); - - if($width > 640 || $height > 640) { - $ph->scaleImage(640); - $p['scale'] = 1; - - $r = $ph->save($p); - - if($r === false) - notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); - else - $smallest = 1; - } $a->data['imagecrop'] = $hash; $a->data['imagecrop_resolution'] = $smallest; - $a->data['imagecrop_ext'] = $ph->getExt(); $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array()); return; -}} +} |