code cleanup for profile_photos
This commit is contained in:
parent
b8c5a91940
commit
acf26d5c63
@ -219,7 +219,7 @@ class Connedit extends \Zotlabs\Web\Controller {
|
|||||||
//Update profile photo permissions
|
//Update profile photo permissions
|
||||||
|
|
||||||
logger('A new profile was assigned - updating profile photos');
|
logger('A new profile was assigned - updating profile photos');
|
||||||
profile_photo_set_profile_perms($profile_id);
|
profile_photo_set_profile_perms(local_channel(),$profile_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function post() {
|
function post() {
|
||||||
|
|
||||||
if(! local_channel()) {
|
if(! local_channel()) {
|
||||||
return;
|
return;
|
||||||
@ -271,7 +271,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
|
|
||||||
if(! local_channel()) {
|
if(! local_channel()) {
|
||||||
notice( t('Permission denied.') . EOL );
|
notice( t('Permission denied.') . EOL );
|
||||||
|
@ -53,26 +53,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
|
check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
|
||||||
|
|
||||||
if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) {
|
if((array_key_exists('postfinal',$_POST)) && (intval($_POST['cropfinal']) == 1)) {
|
||||||
|
|
||||||
// unless proven otherwise
|
|
||||||
$is_default_profile = 1;
|
|
||||||
|
|
||||||
if($_REQUEST['profile']) {
|
|
||||||
$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) {
|
|
||||||
$profile = $r[0];
|
|
||||||
if(! intval($profile['is_default']))
|
|
||||||
$is_default_profile = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
logger('profile: ' . $_REQUEST['profile']);
|
|
||||||
|
|
||||||
|
|
||||||
// phase 2 - we have finished cropping
|
// phase 2 - we have finished cropping
|
||||||
|
|
||||||
@ -87,7 +68,23 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
$scale = substr($image_id,-1,1);
|
$scale = substr($image_id,-1,1);
|
||||||
$image_id = substr($image_id,0,-2);
|
$image_id = substr($image_id,0,-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// unless proven otherwise
|
||||||
|
$is_default_profile = 1;
|
||||||
|
|
||||||
|
if($_REQUEST['profile']) {
|
||||||
|
$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) {
|
||||||
|
$profile = $r[0];
|
||||||
|
if(! intval($profile['is_default']))
|
||||||
|
$is_default_profile = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$srcX = $_POST['xstart'];
|
$srcX = $_POST['xstart'];
|
||||||
$srcY = $_POST['ystart'];
|
$srcY = $_POST['ystart'];
|
||||||
@ -111,30 +108,38 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
|
|
||||||
$aid = get_account_id();
|
$aid = get_account_id();
|
||||||
|
|
||||||
$p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'],
|
$p = [
|
||||||
'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
|
'aid' => $aid,
|
||||||
|
'uid' => local_channel(),
|
||||||
|
'resource_id' => $base_image['resource_id'],
|
||||||
|
'filename' => $base_image['filename'],
|
||||||
|
'album' => t('Profile Photos')
|
||||||
|
];
|
||||||
|
|
||||||
$p['imgscale'] = 4;
|
$p['imgscale'] = PHOTO_RES_PROFILE_300;
|
||||||
$p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
|
$p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
|
||||||
|
|
||||||
$r1 = $im->save($p);
|
$r1 = $im->save($p);
|
||||||
|
|
||||||
$im->scaleImage(80);
|
$im->scaleImage(80);
|
||||||
$p['imgscale'] = 5;
|
$p['imgscale'] = PHOTO_RES_PROFILE_80;
|
||||||
|
|
||||||
$r2 = $im->save($p);
|
$r2 = $im->save($p);
|
||||||
|
|
||||||
$im->scaleImage(48);
|
$im->scaleImage(48);
|
||||||
$p['imgscale'] = 6;
|
$p['imgscale'] = PHOTO_RES_PROFILE_48;
|
||||||
|
|
||||||
$r3 = $im->save($p);
|
$r3 = $im->save($p);
|
||||||
|
|
||||||
if($r1 === false || $r2 === false || $r3 === false) {
|
if($r1 === false || $r2 === false || $r3 === false) {
|
||||||
// if one failed, delete them all so we can start over.
|
// if one failed, delete them all so we can start over.
|
||||||
notice( t('Image resize failed.') . EOL );
|
notice( t('Image resize failed.') . EOL );
|
||||||
$x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale >= 4 ",
|
$x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ",
|
||||||
dbesc($base_image['resource_id']),
|
dbesc($base_image['resource_id']),
|
||||||
local_channel()
|
local_channel(),
|
||||||
|
intval(PHOTO_RES_PROFILE_300),
|
||||||
|
intval(PHOTO_RES_PROFILE_80),
|
||||||
|
intval(PHOTO_RES_PROFILE_48)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -184,10 +189,7 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
|
|
||||||
// Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures'
|
// 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(local_channel(),$_REQUEST['profile']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
notice( t('Unable to process image') . EOL);
|
notice( t('Unable to process image') . EOL);
|
||||||
@ -197,7 +199,9 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
return; // NOTREACHED
|
return; // NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A new photo was uploaded. Store it and save some important details
|
||||||
|
// in App::$data for use in the cropping function
|
||||||
|
|
||||||
|
|
||||||
$hash = photo_new_resource();
|
$hash = photo_new_resource();
|
||||||
$smallest = 0;
|
$smallest = 0;
|
||||||
@ -221,7 +225,7 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
$os_storage = false;
|
$os_storage = false;
|
||||||
|
|
||||||
foreach($i as $ii) {
|
foreach($i as $ii) {
|
||||||
if(intval($ii['imgscale']) < 2) {
|
if(intval($ii['imgscale']) < PHOTO_RES_640) {
|
||||||
$smallest = intval($ii['imgscale']);
|
$smallest = intval($ii['imgscale']);
|
||||||
$os_storage = intval($ii['os_storage']);
|
$os_storage = intval($ii['os_storage']);
|
||||||
$imagedata = $ii['content'];
|
$imagedata = $ii['content'];
|
||||||
@ -239,7 +243,10 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
|
return $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
|
||||||
|
|
||||||
|
// This will "fall through" to the get() method, and since
|
||||||
|
// App::$data['imagecrop'] is set, it will proceed to cropping
|
||||||
|
// rather than present the upload form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -294,11 +301,11 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
}
|
}
|
||||||
$havescale = false;
|
$havescale = false;
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
if($rr['imgscale'] == 5)
|
if($rr['imgscale'] == PHOTO_RES_PROFILE_80)
|
||||||
$havescale = true;
|
$havescale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set an already loaded photo as profile photo
|
// set an already loaded and cropped photo as profile photo
|
||||||
|
|
||||||
if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) {
|
if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) {
|
||||||
// unset any existing profile photos
|
// unset any existing profile photos
|
||||||
@ -319,7 +326,7 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
dbesc($channel['xchan_hash'])
|
dbesc($channel['xchan_hash'])
|
||||||
);
|
);
|
||||||
|
|
||||||
profile_photo_set_profile_perms(); // Reset default photo permissions to public
|
profile_photo_set_profile_perms(local_channel()); // Reset default photo permissions to public
|
||||||
\Zotlabs\Daemon\Master::Summon(array('Directory',local_channel()));
|
\Zotlabs\Daemon\Master::Summon(array('Directory',local_channel()));
|
||||||
goaway(z_root() . '/profiles');
|
goaway(z_root() . '/profiles');
|
||||||
}
|
}
|
||||||
@ -351,7 +358,7 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
if($i) {
|
if($i) {
|
||||||
$hash = $i[0]['resource_id'];
|
$hash = $i[0]['resource_id'];
|
||||||
foreach($i as $ii) {
|
foreach($i as $ii) {
|
||||||
if(intval($ii['imgscale']) < 2) {
|
if(intval($ii['imgscale']) < PHOTO_RES_640) {
|
||||||
$smallest = intval($ii['imgscale']);
|
$smallest = intval($ii['imgscale']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,9 +366,14 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
|
$this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
|
||||||
|
|
||||||
|
// falls through with App::$data['imagecrop'] set so we go straight to the cropping section
|
||||||
}
|
}
|
||||||
|
|
||||||
$profiles = q("select id, profile_name as name, is_default from profile where uid = %d",
|
|
||||||
|
// present an upload form
|
||||||
|
|
||||||
|
$profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc",
|
||||||
intval(local_channel())
|
intval(local_channel())
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -388,6 +400,9 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// present a cropping form
|
||||||
|
|
||||||
$filename = \App::$data['imagecrop'] . '-' . \App::$data['imagecrop_resolution'];
|
$filename = \App::$data['imagecrop'] . '-' . \App::$data['imagecrop_resolution'];
|
||||||
$resolution = \App::$data['imagecrop_resolution'];
|
$resolution = \App::$data['imagecrop_resolution'];
|
||||||
$tpl = get_markup_template("cropbody.tpl");
|
$tpl = get_markup_template("cropbody.tpl");
|
||||||
@ -425,13 +440,13 @@ logger('profile: ' . $_REQUEST['profile']);
|
|||||||
if($max_length > 0)
|
if($max_length > 0)
|
||||||
$ph->scaleImage($max_length);
|
$ph->scaleImage($max_length);
|
||||||
|
|
||||||
$width = $ph->getWidth();
|
\App::$data['width'] = $ph->getWidth();
|
||||||
$height = $ph->getHeight();
|
\App::$data['height'] = $ph->getHeight();
|
||||||
|
|
||||||
if($width < 500 || $height < 500) {
|
if(\App::$data['width'] < 500 || \App::$data['height'] < 500) {
|
||||||
$ph->scaleImageUp(400);
|
$ph->scaleImageUp(400);
|
||||||
$width = $ph->getWidth();
|
\App::$data['width'] = $ph->getWidth();
|
||||||
$height = $ph->getHeight();
|
\App::$data['height'] = $ph->getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class Profperm extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
//Time to update the permissions on the profile-pictures as well
|
//Time to update the permissions on the profile-pictures as well
|
||||||
|
|
||||||
profile_photo_set_profile_perms($profile['id']);
|
profile_photo_set_profile_perms(local_channel(),$profile['id']);
|
||||||
|
|
||||||
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
|
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
|
||||||
intval(local_channel()),
|
intval(local_channel()),
|
||||||
|
@ -707,40 +707,65 @@ function gps2Num($coordPart) {
|
|||||||
return floatval($parts[0]) / floatval($parts[1]);
|
return floatval($parts[0]) / floatval($parts[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function profile_photo_set_profile_perms($profileid = '') {
|
function profile_photo_set_profile_perms($uid, $profileid = 0) {
|
||||||
|
|
||||||
$allowcid = '';
|
$allowcid = '';
|
||||||
if (x($profileid)) {
|
if($profileid) {
|
||||||
|
$r = q("SELECT photo, profile_guid, id, is_default, uid
|
||||||
$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));
|
FROM profile WHERE uid = %d and ( profile.id = %d OR profile.profile_guid = '%s') LIMIT 1",
|
||||||
|
intval($profileid),
|
||||||
} else {
|
dbesc($profileid)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
logger('Resetting permissions on default-profile-photo for user'.local_channel());
|
logger('Resetting permissions on default-profile-photo for user'.local_channel());
|
||||||
$r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval(local_channel()) ); //If no profile is given, we update the default profile
|
|
||||||
|
$r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile
|
||||||
|
WHERE profile.uid = %d AND is_default = 1 LIMIT 1",
|
||||||
|
intval($uid)
|
||||||
|
); //If no profile is given, we update the default profile
|
||||||
}
|
}
|
||||||
|
if(! $r)
|
||||||
|
return;
|
||||||
|
|
||||||
$profile = $r[0];
|
$profile = $r[0];
|
||||||
if(x($profile['id']) && x($profile['photo'])) {
|
|
||||||
preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id);
|
if($profile['id'] && $profile['photo']) {
|
||||||
$resource_id = $resource_id[0];
|
preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id);
|
||||||
|
$resource_id = $resource_id[0];
|
||||||
|
|
||||||
if (intval($profile['is_default']) != 1) {
|
if (! intval($profile['is_default'])) {
|
||||||
$r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval(local_channel()) );
|
$r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1",
|
||||||
$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.
|
intval($uid)
|
||||||
$r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid']));
|
);
|
||||||
|
//Should not be needed in future. Catches old int-profile-ids.
|
||||||
|
$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'])
|
||||||
|
);
|
||||||
$allowcid = "<" . $r0[0]['channel_hash'] . ">";
|
$allowcid = "<" . $r0[0]['channel_hash'] . ">";
|
||||||
foreach ($r1 as $entry) {
|
foreach ($r1 as $entry) {
|
||||||
$allowcid .= "<" . $entry['abook_xchan'] . ">";
|
$allowcid .= "<" . $entry['abook_xchan'] . ">";
|
||||||
}
|
}
|
||||||
foreach ($r2 as $entry) {
|
foreach ($r2 as $entry) {
|
||||||
$allowcid .= "<" . $entry['abook_xchan'] . ">";
|
$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']));
|
q("UPDATE photo SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d",
|
||||||
|
dbesc($allowcid),
|
||||||
|
dbesc($resource_id),
|
||||||
|
intval($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
|
else {
|
||||||
|
//Reset permissions on default profile picture to public
|
||||||
|
q("UPDATE photo SET allow_cid = '' WHERE photo_usage = %d AND uid = %d",
|
||||||
|
intval(PHOTO_PROFILE),
|
||||||
|
intval($uid)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
minWidth: 240,
|
minWidth: 240,
|
||||||
minHeight: 87,
|
minHeight: 87,
|
||||||
maxWidth: 320,
|
maxWidth: 320,
|
||||||
maxHeight: 320,
|
maxHeight: 116,
|
||||||
ratioDim: { x: 100, y:36 },
|
ratioDim: { x: 100, y:36 },
|
||||||
displayOnInit: true,
|
displayOnInit: true,
|
||||||
onEndCrop: onEndCrop
|
onEndCrop: onEndCrop
|
||||||
|
Reference in New Issue
Block a user