From a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sun, 6 Jan 2013 14:42:51 -0700 Subject: implement Smarty3 --- mod/profile_photo.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index e78d2ca6f..e7be543c6 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -14,6 +14,16 @@ function profile_photo_init(&$a) { } +function profile_photo_init(&$a) { + + if(! local_user()) { + return; + } + + profile_aside($a); +} + + function profile_photo_post(&$a) { if(! local_user()) { @@ -318,7 +328,7 @@ function profile_photo_crop_ui_head(&$a, $ph){ $a->config['imagecrop'] = $hash; $a->config['imagecrop_resolution'] = $smallest; $a->config['imagecrop_ext'] = $ph->getExt(); - $a->page['htmlhead'] .= get_markup_template("crophead.tpl"); + $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array()); return; }} -- cgit v1.2.3 From f04ce3b093c03fc343fce5b93e6ec6c7fd1ab214 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 7 Jan 2013 13:40:58 -0800 Subject: more work on notification system, fix a couple of minor issues from smarty conversion --- mod/profile_photo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index e7be543c6..d1e24269a 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -14,13 +14,13 @@ function profile_photo_init(&$a) { } -function profile_photo_init(&$a) { +function profile_photo_aside(&$a) { if(! local_user()) { return; } - profile_aside($a); + profile_create_sidebar($a); } -- cgit v1.2.3 From cf2488e999944ca1135ac62955527a376ad0eac2 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 22 Jan 2013 17:48:42 -0800 Subject: clean up the photo storage backend, revamp mod/wall_upload --- mod/profile_photo.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index d1e24269a..1bee046d1 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -81,8 +81,9 @@ function profile_photo_post(&$a) { $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(local_user(), 0, $base_image['resource_id'],$base_image['filename'], + $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile); if($r === false) @@ -90,7 +91,7 @@ function profile_photo_post(&$a) { $im->scaleImage(80); - $r = $im->store(local_user(), 0, $base_image['resource_id'],$base_image['filename'], + $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile); if($r === false) @@ -98,7 +99,7 @@ function profile_photo_post(&$a) { $im->scaleImage(48); - $r = $im->store(local_user(), 0, $base_image['resource_id'],$base_image['filename'], + $r = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], t('Profile Photos'), 6, $is_default_profile); if($r === false) @@ -308,7 +309,7 @@ function profile_photo_crop_ui_head(&$a, $ph){ $smallest = 0; - $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 ); + $r = $ph->store(get_account_id(), local_user(), '', $hash, $filename, t('Profile Photos'), 0 ); if($r) info( t('Image uploaded successfully.') . EOL ); @@ -317,7 +318,7 @@ function profile_photo_crop_ui_head(&$a, $ph){ if($width > 640 || $height > 640) { $ph->scaleImage(640); - $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 ); + $r = $ph->store(get_account_id(), local_user(), '' , $hash, $filename, t('Profile Photos'), 1 ); if($r === false) notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); -- cgit v1.2.3 From 2a6abaf9d54f7345e04db8b3fb5fe96eaa2a5c1d Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 5 Feb 2013 20:14:19 -0800 Subject: partial cleanup of mod/profile_photo - needs a LOT more --- mod/profile_photo.php | 117 ++++++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 52 deletions(-) (limited to 'mod/profile_photo.php') 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) ? '' . t('skip this step') . '' : '' . t('select a photo from your photo albums') . '') +// FIXME - yuk + '$select' => sprintf('%s %s', t('or'), ($newuser) ? '' . t('skip this step') . '' : '' . t('select a photo from your photo albums') . '') )); 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; }} -- cgit v1.2.3 From 32d07c3df72ad12dae62f9d5f5d2a3f3c8f4ed7d Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 10 Feb 2013 19:54:43 -0800 Subject: fix profile selector on profile_photo page (unquoted mysql reserved word 'default') --- mod/profile_photo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 560cd6b12..5e58ee093 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -257,11 +257,11 @@ function profile_photo_content(&$a) { // go ahead as if we have just uploaded a new photo to crop profile_photo_crop_ui_head($a, $ph); } - - $profiles = q("select id, profile_name as name, is_default as default from profile where uid = %d", +dbg(1); + $profiles = q("select id, profile_name as name, is_default as pdefault from profile where uid = %d", intval(local_user()) ); - +dbg(0); if(! x($a->data,'imagecrop')) { $tpl = get_markup_template('profile_photo.tpl'); -- cgit v1.2.3 From 3ee75a795a471573de307d7be70bfb61bf1d63fa Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Feb 2013 02:02:35 -0800 Subject: Whinging whining stupid fucks. --- mod/profile_photo.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 5e58ee093..7b29b3635 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -38,7 +38,7 @@ 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, is_default from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_user()) ); @@ -110,7 +110,7 @@ function profile_photo_post(&$a) { // 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", + $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()) ); @@ -137,11 +137,9 @@ function profile_photo_post(&$a) { ); info( t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL); - // Update global directory in background - $url = $a->get_baseurl() . '/channel/' . $a->user['nickname']; - if($url && strlen(get_config('system','directory_submit_url'))) - proc_run('php',"include/directory.php","$url"); + // Update directory in background + proc_run('php',"include/directory.php",$channel['channel_id']); } else notice( t('Unable to process image') . EOL); @@ -257,11 +255,11 @@ function profile_photo_content(&$a) { // go ahead as if we have just uploaded a new photo to crop profile_photo_crop_ui_head($a, $ph); } -dbg(1); + $profiles = q("select id, profile_name as name, is_default as pdefault from profile where uid = %d", intval(local_user()) ); -dbg(0); + if(! x($a->data,'imagecrop')) { $tpl = get_markup_template('profile_photo.tpl'); -- cgit v1.2.3 From c42936e2652a0d0f422afb2b7157b03aa0f2eaf6 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 15 Feb 2013 17:23:02 -0800 Subject: we don't need to quote or rename 'default' in mySQL if we just use the original column name 'is_default' --- mod/profile_photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 7b29b3635..ea7a01bc9 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -256,7 +256,7 @@ function profile_photo_content(&$a) { profile_photo_crop_ui_head($a, $ph); } - $profiles = q("select id, profile_name as name, is_default as pdefault from profile where uid = %d", + $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", intval(local_user()) ); -- cgit v1.2.3 From 72e83f69bc3afe3646b423a19f11c99d03e3b66a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 25 Apr 2013 20:01:24 -0700 Subject: photo driver abstraction --- mod/profile_photo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ea7a01bc9..64dfc0e83 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -1,6 +1,6 @@ is_valid()) { $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); @@ -164,7 +164,7 @@ function profile_photo_post(&$a) { } $imagedata = @file_get_contents($src); - $ph = new Photo($imagedata, $filetype); + $ph = photo_factory($imagedata, $filetype); if(! $ph->is_valid()) { notice( t('Unable to process image.') . EOL ); @@ -251,7 +251,7 @@ function profile_photo_content(&$a) { return; } - $ph = new Photo($r[0]['data'], $r[0]['type']); + $ph = photo_factory($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); } -- cgit v1.2.3 From 20b22421d3731bfcc8b349fbc082156d001a099a Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 7 Aug 2013 01:42:45 -0700 Subject: big changes to photo->store() which is now photo->save() and takes an array instead of a list of args. Also the beginning of the migration to using photo_flags to indicate special purpose photos such as profile photos and contact photos and "thing" photos. --- mod/profile_photo.php | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 64dfc0e83..f8eda43cf 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -84,18 +84,23 @@ function profile_photo_post(&$a) { $aid = get_account_id(); - $r1 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 4, $is_default_profile); + $p = array('aid' => $aid, 'uid' => local_user(), 'resource_id' => $base_image['resource_id'], + 'filename' => $base_image['filename'], 'album' => t('Profile Photos')); + + $p['scale'] = 4; + $p['photo_flags'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); + + $r1 = $im->save($p); $im->scaleImage(80); + $p['scale'] = 5; - $r2 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 5, $is_default_profile); + $r2 = $im->save($p); $im->scaleImage(48); + $p['scale'] = 6; - $r3 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 6, $is_default_profile); + $r3 = $im->save($p); if($r1 === false || $r2 === false || $r3 === false) { // if one failed, delete them all so we can start over. @@ -114,6 +119,13 @@ function profile_photo_post(&$a) { dbesc($base_image['resource_id']), intval(local_user()) ); + $r = q("UPDATE photo SET ( photo_flags ^ %d ) WHERE (photo_flags & %d ) + AND resource_id != '%s' AND `uid` = %d", + intval(PHOTO_PROFILE), + intval(PHOTO_PROFILE), + dbesc($base_image['resource_id']), + intval(local_user()) + ); } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d limit 1", @@ -224,6 +236,10 @@ function profile_photo_content(&$a) { // 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 (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", + intval(PHOTO_PROFILE), + intval(PHOTO_PROFILE), + intval(local_user())); // set all sizes of this one as profile photos $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", @@ -231,6 +247,12 @@ function profile_photo_content(&$a) { dbesc($resource_id) ); + $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", + intval(PHOTO_PROFILE), + intval(local_user()), + dbesc($resource_id) + ); + $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s' limit 1", dbesc(datetime_convert()), @@ -241,7 +263,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` FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_user()) @@ -320,7 +342,9 @@ function profile_photo_crop_ui_head(&$a, $ph){ $hash = photo_new_resource(); $smallest = 0; - $r = $ph->store(get_account_id(), local_user(), '', $hash, $filename, t('Profile Photos'), 0 ); + $p = array('aid' => get_account_id(), 'uid' => local_user(), 'resource_id' => $hash, + 'filename' => $filename, 'album' => t('Profile Photos'), 'scale' => 0); + $r = $ph->save($p); if($r) info( t('Image uploaded successfully.') . EOL ); @@ -329,7 +353,9 @@ function profile_photo_crop_ui_head(&$a, $ph){ if($width > 640 || $height > 640) { $ph->scaleImage(640); - $r = $ph->store(get_account_id(), local_user(), '' , $hash, $filename, t('Profile Photos'), 1 ); + $p['scale'] = 1; + + $r = $ph->save($p); if($r === false) notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); -- cgit v1.2.3 From 38577cf26cc241245731f786704ac773bfc52952 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 5 Dec 2013 18:17:16 -0800 Subject: issue #225 --- mod/profile_photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index f8eda43cf..7893cc302 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -42,7 +42,7 @@ function profile_photo_post(&$a) { intval($_REQUEST['profile']), intval(local_user()) ); - if(count($r) && (! intval($r[0]['is_default']))) + if(($r) && (! intval($r[0]['is_default']))) $is_default_profile = 0; } -- cgit v1.2.3 From 7ae371d2865c063144490fbd6e1097f90c75eaf3 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 5 Dec 2013 20:40:27 -0800 Subject: couple of errant SQL queries --- mod/profile_photo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 7893cc302..e86e2a828 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -119,7 +119,7 @@ function profile_photo_post(&$a) { dbesc($base_image['resource_id']), intval(local_user()) ); - $r = q("UPDATE photo SET ( photo_flags ^ %d ) WHERE (photo_flags & %d ) + $r = q("UPDATE photo SET photo_flags = ( photo_flags ^ %d ) WHERE ( photo_flags & %d ) AND resource_id != '%s' AND `uid` = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), @@ -236,7 +236,7 @@ function profile_photo_content(&$a) { // 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 (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", + $r = q("UPDATE photo SET photo_flags = (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_user())); -- cgit v1.2.3 From 40e2900326a25ba0e2feedb802d38b7052b194cc Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 11 Dec 2013 14:54:36 -0800 Subject: comanchify all the simple cases - those that only load a profile. Rework permission checks for the profile sidebar so that it is all done internally. Remove crepair which we aren't using. --- mod/profile_photo.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index e86e2a828..876e3a931 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -14,16 +14,6 @@ function profile_photo_init(&$a) { } -function profile_photo_aside(&$a) { - - if(! local_user()) { - return; - } - - profile_create_sidebar($a); -} - - function profile_photo_post(&$a) { if(! local_user()) { -- cgit v1.2.3 From 8b8feea12f886a22f7eb66456be7828b7aef455e Mon Sep 17 00:00:00 2001 From: sirius Date: Mon, 14 Apr 2014 00:45:24 +0200 Subject: Added hackish support for permissions-sync between profile and profile-pictures --- mod/profile_photo.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 876e3a931..2cf7a8abf 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -2,6 +2,34 @@ require_once('include/photo/photo_driver.php'); +function profile_photo_set_profile_perms($profileid) { + + $allowcid = ''; + $r = q("SELECT photo, profile_guid, id FROM profile WHERE profile.id = %d LIMIT 1", intval($profileid)); + $profile = $r[0]; + + if(x($profile['photo'])) { + preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); + $resource_id = $resource_id[0]; + + if(x($profileid)) { + + $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = %d ", intval($profile['id'])); + $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid'])); + foreach ($r1 as $entry) { + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } + foreach ($r2 as $entry) { + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } + if(x($allowcid)) { + q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s'",dbesc($allowcid),dbesc($resource_id)); + } + } + } + return; +} + function profile_photo_init(&$a) { if(! local_user()) { @@ -142,6 +170,11 @@ function profile_photo_post(&$a) { // Update directory in background proc_run('php',"include/directory.php",$channel['channel_id']); + + // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures' + + profile_photo_set_profile_perms($_REQUEST['profile']); + } else notice( t('Unable to process image') . EOL); -- cgit v1.2.3 From 3845e1de7d73664c818360c12ae2b7b3b1882c90 Mon Sep 17 00:00:00 2001 From: sirius Date: Sun, 20 Apr 2014 00:31:18 +0200 Subject: Added permission handling of profile-photos Now we automatically set the appropiate viewing-permissions on profile edit and revert photos chosen as default profile picture bacl to public access. --- mod/profile_photo.php | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ef0a31673..ab7c3b12f 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -13,30 +13,43 @@ require_once('include/photo/photo_driver.php'); * @return void */ -function profile_photo_set_profile_perms($profileid) { +function profile_photo_set_profile_perms($profileid = '') { $allowcid = ''; if (x($profileid)) { - $r = q("SELECT photo, profile_guid, id, is_default FROM profile WHERE profile.id = %d LIMIT 1", intval($profileid)); - $profile = $r[0]; - if(x($profile['id']) && x($profile['photo']) && intval($profile['is_default']) != 1) { //Only set perms when query suceeded and when we are not on the default profile - preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); - $resource_id = $resource_id[0]; + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d LIMIT 1", intval($profileid)); + } else { + + logger('Resetting permissions on default-profile-photo for user'.local_user()); + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval(local_user()) ); //If no profile is given, we update the default profile + } + + $profile = $r[0]; + if(x($profile['id']) && x($profile['photo'])) { + preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); + $resource_id = $resource_id[0]; + + if (intval($profile['is_default']) != 1) { + $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval(local_user()) ); $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = %d ", intval($profile['id'])); //Should not be needed in future. Catches old int-profile-ids. $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid'])); + $allowcid = "<" . $r0[0]['channel_hash'] . ">"; foreach ($r1 as $entry) { $allowcid .= "<" . $entry['abook_xchan'] . ">"; } foreach ($r2 as $entry) { - $allowcid .= "<" . $entry['abook_xchan'] . ">"; - } - if(x($allowcid)) { - q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d",dbesc($allowcid),dbesc($resource_id),intval($profile['id'])); - } + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } + + q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d",dbesc($allowcid),dbesc($resource_id),intval($profile['uid'])); + + } else { + q("UPDATE `photo` SET allow_cid = '' WHERE profile = 1 AND uid = %d",intval($profile['uid'])); //Reset permissions on default profile picture to public } } + return; } @@ -273,7 +286,7 @@ function profile_photo_content(&$a) { intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_user())); - + // 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()), @@ -292,7 +305,8 @@ function profile_photo_content(&$a) { dbesc($channel['xchan_hash']) ); - proc_run('php','include/directory.php',local_user()); + profile_photo_set_profile_perms(); //Reset default photo permissions to public + proc_run('php','include/directory.php',local_user()); goaway($a->get_baseurl() . '/profiles'); } @@ -316,7 +330,7 @@ function profile_photo_content(&$a) { ); if(! x($a->data,'imagecrop')) { - + $tpl = get_markup_template('profile_photo.tpl'); $o .= replace_macros($tpl,array( @@ -389,7 +403,7 @@ function profile_photo_crop_ui_head(&$a, $ph){ $p['scale'] = 1; $r = $ph->save($p); - + if($r === false) notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); else -- cgit v1.2.3 From 6cf5a69d7e8ac12c9c946397ca5c9a1126665974 Mon Sep 17 00:00:00 2001 From: sirius Date: Sun, 20 Apr 2014 00:58:26 +0200 Subject: Now we also refresh permissions after the user posted connedit. --- mod/profile_photo.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'mod/profile_photo.php') diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ab7c3b12f..c587b9606 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -18,7 +18,7 @@ function profile_photo_set_profile_perms($profileid = '') { $allowcid = ''; if (x($profileid)) { - $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d LIMIT 1", intval($profileid)); + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d OR profile.profile_guid = '%s' LIMIT 1", intval($profileid), dbesc($profileid)); } else { @@ -53,6 +53,13 @@ function profile_photo_set_profile_perms($profileid = '') { return; } +/* @brief Initalize the profile-photo edit view + * + * @param $a Current application + * @return void + * + */ + function profile_photo_init(&$a) { if(! local_user()) { @@ -64,6 +71,12 @@ function profile_photo_init(&$a) { } +/* @brief Evaluate posted values + * + * @param $a Current application + * @return void + * + */ function profile_photo_post(&$a) { @@ -235,6 +248,13 @@ function profile_photo_post(&$a) { } +/* @brief Generate content of profile-photo view + * + * @param $a Current application + * @return void + * + */ + if(! function_exists('profile_photo_content')) { function profile_photo_content(&$a) { @@ -367,6 +387,14 @@ function profile_photo_content(&$a) { return; // NOTREACHED }} +/* @brief Generate the UI for photo-cropping + * + * @param $a Current application + * @param $ph Photo-Factory + * @return void + * + */ + if(! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(&$a, $ph){ -- cgit v1.2.3