diff options
author | friendica <info@friendica.com> | 2013-02-05 20:14:19 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-02-05 20:14:19 -0800 |
commit | 2a6abaf9d54f7345e04db8b3fb5fe96eaa2a5c1d (patch) | |
tree | 98fd3d7d1b0d29e5e2c3fbed5db9067801c0253a /mod | |
parent | f3eb2eb9e7f5da80dae8518a70e05514a203d0f1 (diff) | |
download | volse-hubzilla-2a6abaf9d54f7345e04db8b3fb5fe96eaa2a5c1d.tar.gz volse-hubzilla-2a6abaf9d54f7345e04db8b3fb5fe96eaa2a5c1d.tar.bz2 volse-hubzilla-2a6abaf9d54f7345e04db8b3fb5fe96eaa2a5c1d.zip |
partial cleanup of mod/profile_photo - needs a LOT more
Diffstat (limited to 'mod')
-rw-r--r-- | mod/profile_photo.php | 117 |
1 files changed, 65 insertions, 52 deletions
diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 1bee046d1..560cd6b12 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -27,7 +27,6 @@ function profile_photo_aside(&$a) { function profile_photo_post(&$a) { if(! local_user()) { - notice ( t('Permission denied.') . EOL ); return; } @@ -51,12 +50,12 @@ function profile_photo_post(&$a) { // phase 2 - we have finished cropping - if($a->argc != 2) { + if(argc() != 2) { notice( t('Image uploaded but image cropping failed.') . EOL ); return; } - $image_id = $a->argv[1]; + $image_id = argv(1); if(substr($image_id,-2,1) == '-') { $scale = substr($image_id,-1,1); @@ -69,41 +68,44 @@ function profile_photo_post(&$a) { $srcW = $_POST['xfinal'] - $srcX; $srcH = $_POST['yfinal'] - $srcY; - $r = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1", + $r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND scale = %d LIMIT 1", dbesc($image_id), dbesc(local_user()), intval($scale)); - if(count($r)) { + if($r) { $base_image = $r[0]; $im = new Photo($base_image['data'], $base_image['type']); if($im->is_valid()) { + $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); + $aid = get_account_id(); - $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], + $r1 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile); - if($r === false) - notice ( sprintf(t('Image size reduction [%s] failed.'),"175") . EOL ); - $im->scaleImage(80); - $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], + $r2 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile); - if($r === false) - notice( sprintf(t('Image size reduction [%s] failed.'),"80") . EOL ); - $im->scaleImage(48); - $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], + $r3 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 6, $is_default_profile); - if($r === false) - notice( sprintf(t('Image size reduction [%s] failed.'),"48") . EOL ); + if($r1 === false || $r2 === false || $r3 === false) { + // if one failed, delete them all so we can start over. + notice( t('Image resize failed.') . EOL ); + $x = q("delete from photo where resource_id = '%s' and uid = %d and scale >= 4 ", + dbesc($base_image['resource_id']), + local_user() + ); + return; + } // If setting for the default profile, unset the profile photo flag from any other photos I own @@ -186,6 +188,8 @@ function profile_photo_content(&$a) { return; } + $channel = $a->get_channel(); + $newuser = false; if(argc() == 2 && argv(1) === 'new') @@ -200,13 +204,14 @@ function profile_photo_content(&$a) { // check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo'); $resource_id = argv(2); - //die(":".local_user()); - $r=q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' ORDER BY `scale` ASC", + + + $r = q("SELECT id, album, scale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY scale ASC", intval(local_user()), dbesc($resource_id) - ); - if (!count($r)){ - notice( t('Permission denied.') . EOL ); + ); + if(! $r) { + notice( t('Photo not available.') . EOL ); return; } $havescale = false; @@ -215,65 +220,74 @@ function profile_photo_content(&$a) { $havescale = true; } - // set an already uloaded photo as profile photo - // if photo is in 'Profile Photos', change it in db - if (($r[0]['album']== t('Profile Photos')) && ($havescale)){ - $r=q("UPDATE `photo` SET `profile`=0 WHERE `profile`=1 AND `uid`=%d", + // set an already loaded photo as profile photo + + 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_user())); - $r=q("UPDATE `photo` SET `profile`=1 WHERE `uid` = %d AND `resource_id` = '%s'", + // 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_user()), dbesc($resource_id) ); - - $r = q("UPDATE `contact` SET `avatar_date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1", + + $r = q("UPDATE xchan set xchan_photo_date = '%s' + where xchan_hash = '%s' limit 1", dbesc(datetime_convert()), - intval(local_user()) + dbesc($channel['xchan_hash']) ); - - // Update global directory in background - $url = $_SESSION['my_url']; - if($url && strlen(get_config('system','directory_submit_url'))) - proc_run('php',"include/directory.php","$url"); - + + proc_run('php','include/directory.php',local_user()); goaway($a->get_baseurl() . '/profiles'); - return; // NOTREACHED } + + $r = q("SELECT data, type FROM photo WHERE id = %d and uid = %d limit 1", + intval($r[0]['id']), + intval(local_user()) + + ); + if(! $r) { + notice( t('Photo not available.') . EOL ); + return; + } + $ph = new Photo($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); - // go ahead as we have jus uploaded a new photo to crop } - $profiles = q("select `id`,`profile_name` as `name`,`is_default` as `default` from profile where uid = %d", + $profiles = q("select id, profile_name as name, is_default as default from profile where uid = %d", intval(local_user()) ); - - if(! x($a->config,'imagecrop')) { + if(! x($a->data,'imagecrop')) { $tpl = get_markup_template('profile_photo.tpl'); $o .= replace_macros($tpl,array( - '$user' => $a->user['nickname'], + '$user' => $a->channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("profile_photo"), - '$select' => sprintf('%s %s', t('or'), ($newuser) ? '<a href="' . $a->get_baseurl() . '">' . t('skip this step') . '</a>' : '<a href="'. $a->get_baseurl() . '/photos/' . $a->user['nickname'] . '">' . t('select a photo from your photo albums') . '</a>') +// FIXME - yuk + '$select' => sprintf('%s %s', t('or'), ($newuser) ? '<a href="' . $a->get_baseurl() . '">' . t('skip this step') . '</a>' : '<a href="'. $a->get_baseurl() . '/photos/' . $a->channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>') )); return $o; } else { - $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.'.$a->config['imagecrop_ext']; - $resolution = $a->config['imagecrop_resolution']; + $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'] . '.' . $a->data['imagecrop_ext']; + $resolution = $a->data['imagecrop_resolution']; $tpl = get_markup_template("cropbody.tpl"); $o .= replace_macros($tpl,array( '$filename' => $filename, '$profile' => intval($_REQUEST['profile']), - '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'], + '$resource' => $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'], '$image_url' => $a->get_baseurl() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), @@ -289,24 +303,23 @@ function profile_photo_content(&$a) { if(! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(&$a, $ph){ + $max_length = get_config('system','max_image_length'); if(! $max_length) $max_length = MAX_IMAGE_LENGTH; if($max_length > 0) $ph->scaleImage($max_length); - $width = $ph->getWidth(); + $width = $ph->getWidth(); $height = $ph->getHeight(); if($width < 175 || $height < 175) { $ph->scaleImageUp(200); - $width = $ph->getWidth(); + $width = $ph->getWidth(); $height = $ph->getHeight(); } $hash = photo_new_resource(); - - $smallest = 0; $r = $ph->store(get_account_id(), local_user(), '', $hash, $filename, t('Profile Photos'), 0 ); @@ -326,9 +339,9 @@ function profile_photo_crop_ui_head(&$a, $ph){ $smallest = 1; } - $a->config['imagecrop'] = $hash; - $a->config['imagecrop_resolution'] = $smallest; - $a->config['imagecrop_ext'] = $ph->getExt(); + $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; }} |