From 5d70d889e908a32c846b9da3eb26703064d20ec6 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 10 Apr 2019 13:25:03 +0200 Subject: Revert "Update htconfig.sample.php" This reverts commit f2126ef18c8b66020305d07dcefeacc4e55a3c12 --- include/attach.php | 11 +++++++++++ include/import.php | 9 ++++----- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index f6594b154..f169e0669 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1521,6 +1521,17 @@ function attach_drop_photo($channel_id,$resource) { if($x) { drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true); } + + $r = q("SELECT content FROM photo WHERE resource_id = '%s' AND uid = %d AND os_storage = 1", + dbesc($resource), + intval($channel_id) + ); + if($r) { + foreach($r as $i) { + @unlink(dbunescbin($i['content'])); + } + } + q("DELETE FROM photo WHERE uid = %d AND resource_id = '%s'", intval($channel_id), dbesc($resource) diff --git a/include/import.php b/include/import.php index 7a1e9aa55..21cdfb68f 100644 --- a/include/import.php +++ b/include/import.php @@ -1385,13 +1385,14 @@ function sync_files($channel, $files) { else $p['content'] = (($p['content'])? base64_decode($p['content']) : ''); - if(intval($p['imgscale']) && (! $p['content'])) { + if(intval($p['imgscale']) && intval($p['os_storage']) && (! empty($p['content']))) { $time = datetime_convert(); - $parr = array('hash' => $channel['channel_hash'], + $parr = array( + 'hash' => $channel['channel_hash'], 'time' => $time, - 'resource' => $att['hash'], + 'resource' => $p['resource_id'], 'revision' => 0, 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])), 'resolution' => $p['imgscale'] @@ -1414,8 +1415,6 @@ function sync_files($channel, $files) { $x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]); fclose($fp); - $p['content'] = file_get_contents($stored_image); - unlink($stored_image); } if(!isset($p['display_path'])) -- cgit v1.2.3 From 42f96dc7a6dca1e507570a8e78ba32b54468fc09 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 10 Apr 2019 14:13:16 +0200 Subject: Fix use UNIX socket file to connect DB --- include/dba/dba_pdo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index 5002f53e7..a70e4a1d7 100755 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -19,7 +19,7 @@ class dba_pdo extends dba_driver { $this->driver_dbtype = $scheme; if(strpbrk($server,':;')) { - $dsn = $server; + $dsn = $this->driver_dbtype . ':unix_socket=' . trim($server, ':;'); } else { $dsn = $this->driver_dbtype . ':host=' . $server . (intval($port) ? ';port=' . $port : ''); -- cgit v1.2.3 From 074ee656f039442244396efa1ccf641ad1d9822e Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 14:56:07 +0200 Subject: Fetch thumbnails and store it in filesystem or DB; update xchan profile edit time on fetch --- include/import.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 21cdfb68f..d1d786321 100644 --- a/include/import.php +++ b/include/import.php @@ -1345,6 +1345,7 @@ function sync_files($channel, $files) { logger('attachment store failed',LOGGER_NORMAL,LOG_ERR); } if($f['photo']) { + foreach($f['photo'] as $p) { unset($p['id']); $p['aid'] = $channel['channel_account_id']; @@ -1366,6 +1367,7 @@ function sync_files($channel, $files) { dbesc($p['resource_id']), intval($channel['channel_id']) ); + $update_xchan = $p['edited']; } // same for cover photos @@ -1385,7 +1387,7 @@ function sync_files($channel, $files) { else $p['content'] = (($p['content'])? base64_decode($p['content']) : ''); - if(intval($p['imgscale']) && intval($p['os_storage']) && (! empty($p['content']))) { + if(intval($p['imgscale']) && (! empty($p['content']))) { $time = datetime_convert(); @@ -1395,10 +1397,10 @@ function sync_files($channel, $files) { 'resource' => $p['resource_id'], 'revision' => 0, 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])), - 'resolution' => $p['imgscale'] + 'resolution' => intval($p['imgscale']) ); - $stored_image = $newfname . '-' . intval($p['imgscale']); + $stored_image = $newfname . '-' . $p['imgscale']; $fp = fopen($stored_image,'w'); if(! $fp) { @@ -1407,7 +1409,6 @@ function sync_files($channel, $files) { } $redirects = 0; - $headers = []; $headers['Accept'] = 'application/x-zot+json' ; $headers['Sigtoken'] = random_string(); @@ -1415,6 +1416,15 @@ function sync_files($channel, $files) { $x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]); fclose($fp); + + // Override remote hub thumbnails storage settings + if(! boolval(get_config('system','filesystem_storage_thumbnails', 0))) { + $p['os_storage'] = 0; + $p['content'] = file_get_contents($stored_image); + @unlink($stored_image); + } + else + $p['os_storage'] = 1; } if(!isset($p['display_path'])) @@ -1446,6 +1456,14 @@ function sync_files($channel, $files) { create_table_from_array('photo',$p, [ 'content' ] ); } } + + // Set xchan photo date to prevent thumbnails fetch for clones on profile update packet recieve + if(isset($update_xchan)) { + $x = q("UPDATE xchan SET xchan_photo_date = '%s' WHERE xchan_hash = '%s'", + dbescdate($update_xchan), + dbesc($channel['channel_hash']) + ); + } } \Zotlabs\Daemon\Master::Summon([ 'Thumbnail' , $att['hash'] ]); -- cgit v1.2.3 From 3a0fa5cb295e271918aad23e68ec754915506c40 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 14:59:13 +0200 Subject: Store thumbnails in filesystem or database --- include/photos.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 44406e0b0..7ea2729ae 100644 --- a/include/photos.php +++ b/include/photos.php @@ -277,8 +277,7 @@ function photo_upload($channel, $observer, $args) { if(($width > 1024 || $height > 1024) && (! $errors)) $ph->scaleImage(1024); - $p['imgscale'] = 1; - $r1 = $ph->save($p); + $r1 = $ph->storeThumbnail($p, PHOTO_RES_1024); $link[1] = array( 'rel' => 'alternate', 'type' => 'text/html', @@ -292,8 +291,7 @@ function photo_upload($channel, $observer, $args) { if(($width > 640 || $height > 640) && (! $errors)) $ph->scaleImage(640); - $p['imgscale'] = 2; - $r2 = $ph->save($p); + $r2 = $ph->storeThumbnail($p, PHOTO_RES_640); $link[2] = array( 'rel' => 'alternate', 'type' => 'text/html', @@ -307,8 +305,7 @@ function photo_upload($channel, $observer, $args) { if(($width > 320 || $height > 320) && (! $errors)) $ph->scaleImage(320); - $p['imgscale'] = 3; - $r3 = $ph->save($p); + $r3 = $ph->storeThumbnail($p, PHOTO_RES_320); $link[3] = array( 'rel' => 'alternate', 'type' => 'text/html', -- cgit v1.2.3 From 5792f4bf074617048837210913886df01345ba1b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 15:00:56 +0200 Subject: Add comment on required changes in upcoming releases --- include/zot.php | 78 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 227d82a13..9f2321bc4 100644 --- a/include/zot.php +++ b/include/zot.php @@ -925,46 +925,62 @@ function import_xchan($arr, $ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { $local = q("select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1", dbesc($xchan_hash) ); + if($local) { + // @FIXME This should be removed in future when profile photo update by file sync procedure will be applied + // on most hubs in the network + // <--- $ph = z_fetch_url($arr['photo'], true); + if($ph['success']) { + + // Do not fetch already received thumbnails + $x = q("SELECT resource_id FROM photo WHERE uid = %d AND imgscale = %d AND filesize = %d LIMIT 1", + intval($local[0]['channel_id']), + intval(PHOTO_RES_PROFILE_300), + strlen($ph['body']) + ); + + if($x) + $hash = $x[0]['resource_id']; + else + $hash = import_channel_photo($ph['body'], $arr['photo_mimetype'], $local[0]['channel_account_id'], $local[0]['channel_id']); + } + + if($hash) { + // unless proven otherwise + $is_default_profile = 1; + + $profile = q("select is_default from profile where aid = %d and uid = %d limit 1", + intval($local[0]['channel_account_id']), + intval($local[0]['channel_id']) + ); + if($profile) { + if(! intval($profile[0]['is_default'])) + $is_default_profile = 0; + } - $hash = import_channel_photo($ph['body'], $arr['photo_mimetype'], $local[0]['channel_account_id'], $local[0]['channel_id']); - - if($hash) { - // unless proven otherwise - $is_default_profile = 1; - - $profile = q("select is_default from profile where aid = %d and uid = %d limit 1", + // If setting for the default profile, unset the profile photo flag from any other photos I own + if($is_default_profile) { + q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND aid = %d AND uid = %d", + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE), + dbesc($hash), intval($local[0]['channel_account_id']), intval($local[0]['channel_id']) ); - if($profile) { - if(! intval($profile[0]['is_default'])) - $is_default_profile = 0; - } - - // If setting for the default profile, unset the profile photo flag from any other photos I own - if($is_default_profile) { - q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND aid = %d AND uid = %d", - intval(PHOTO_NORMAL), - intval(PHOTO_PROFILE), - dbesc($hash), - intval($local[0]['channel_account_id']), - intval($local[0]['channel_id']) - ); - } } - - // reset the names in case they got messed up when we had a bug in this function - $photos = array( - z_root() . '/photo/profile/l/' . $local[0]['channel_id'], - z_root() . '/photo/profile/m/' . $local[0]['channel_id'], - z_root() . '/photo/profile/s/' . $local[0]['channel_id'], - $arr['photo_mimetype'], - false - ); } + // ---> + + // reset the names in case they got messed up when we had a bug in this function + $photos = array( + z_root() . '/photo/profile/l/' . $local[0]['channel_id'], + z_root() . '/photo/profile/m/' . $local[0]['channel_id'], + z_root() . '/photo/profile/s/' . $local[0]['channel_id'], + $arr['photo_mimetype'], + false + ); } else { $photos = import_xchan_photo($arr['photo'], $xchan_hash); -- cgit v1.2.3 From d3a619659f4815c648603698c13a752d4be3f673 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 15:38:10 +0200 Subject: Fix 'os_syspath' if we store thumbnails in filesystem --- include/import.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index d1d786321..0a70b114c 100644 --- a/include/import.php +++ b/include/import.php @@ -1423,8 +1423,10 @@ function sync_files($channel, $files) { $p['content'] = file_get_contents($stored_image); @unlink($stored_image); } - else + else { $p['os_storage'] = 1; + $p['os_syspath'] = $stored_image; + } } if(!isset($p['display_path'])) -- cgit v1.2.3 From 852343f25448a996298b3b5f892a61b0b7701c7f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 16:27:58 +0200 Subject: Override received 'content' if we saving thumbnail in filesystem --- include/import.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/import.php b/include/import.php index 0a70b114c..69be521de 100644 --- a/include/import.php +++ b/include/import.php @@ -1426,6 +1426,7 @@ function sync_files($channel, $files) { else { $p['os_storage'] = 1; $p['os_syspath'] = $stored_image; + $p['content'] = $stored_image; } } -- cgit v1.2.3 From 04b261057d1123a43e72216ecc3c8172bbda32bc Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Apr 2019 22:34:32 +0200 Subject: Set 'os_syspath' with local path --- include/import.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 69be521de..585a0ac84 100644 --- a/include/import.php +++ b/include/import.php @@ -1417,6 +1417,8 @@ function sync_files($channel, $files) { $x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]); fclose($fp); + $p['os_syspath'] = $stored_image; + // Override remote hub thumbnails storage settings if(! boolval(get_config('system','filesystem_storage_thumbnails', 0))) { $p['os_storage'] = 0; @@ -1425,7 +1427,6 @@ function sync_files($channel, $files) { } else { $p['os_storage'] = 1; - $p['os_syspath'] = $stored_image; $p['content'] = $stored_image; } } -- cgit v1.2.3 From 509067391b9e2b167827a7b999cb5ef455ac68d6 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Apr 2019 14:08:44 +0200 Subject: Update xchan profile edited date only once --- include/import.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 585a0ac84..434a53f10 100644 --- a/include/import.php +++ b/include/import.php @@ -1417,8 +1417,6 @@ function sync_files($channel, $files) { $x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]); fclose($fp); - $p['os_syspath'] = $stored_image; - // Override remote hub thumbnails storage settings if(! boolval(get_config('system','filesystem_storage_thumbnails', 0))) { $p['os_storage'] = 0; @@ -1428,6 +1426,7 @@ function sync_files($channel, $files) { else { $p['os_storage'] = 1; $p['content'] = $stored_image; + $p['os_syspath'] = $stored_image; } } @@ -1461,13 +1460,15 @@ function sync_files($channel, $files) { } } - // Set xchan photo date to prevent thumbnails fetch for clones on profile update packet recieve - if(isset($update_xchan)) { - $x = q("UPDATE xchan SET xchan_photo_date = '%s' WHERE xchan_hash = '%s'", - dbescdate($update_xchan), - dbesc($channel['channel_hash']) - ); - } + } + + // Set xchan photo date to prevent thumbnails fetch for clones on profile update packet recieve + if(isset($update_xchan)) { + + $x = q("UPDATE xchan SET xchan_photo_date = '%s' WHERE xchan_hash = '%s'", + dbescdate($update_xchan), + dbesc($channel['channel_hash']) + ); } \Zotlabs\Daemon\Master::Summon([ 'Thumbnail' , $att['hash'] ]); -- cgit v1.2.3