From aed682305173a67b2af1a56b8595445bec690e2b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 7 Dec 2019 20:14:17 +0100 Subject: Add .webp image format support --- include/attach.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 80efe0838..952270949 100644 --- a/include/attach.php +++ b/include/attach.php @@ -56,6 +56,7 @@ function z_mime_content_type($filename) { 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', + 'webp' => 'image/webp', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', @@ -616,7 +617,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $is_photo = 0; $gis = @getimagesize($src); logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA); - if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) { + if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG || $gis[2] === IMAGETYPE_WEBP)) { $is_photo = 1; if($gis[2] === IMAGETYPE_GIF) $def_extension = '.gif'; @@ -624,6 +625,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $def_extension = '.jpg'; if($gis[2] === IMAGETYPE_PNG) $def_extension = '.png'; + if($gis[2] === IMAGETYPE_WEBP) + $def_extension = '.webp'; } // If we know it's a photo, over-ride the type in case the source system could not determine what it was @@ -908,7 +911,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { ); } - if($is_photo) { + if($is_photo && $r) { $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => $pathname, 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); if($arr['contact_allow']) @@ -942,9 +945,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $args['deliver'] = $dosync; $p = photo_upload($channel,$observer,$args); - if($p['success']) { - $ret['body'] = $p['body']; + if($p['success']) + $ret['body'] = $p['body']; + else { + // Attach as ordinary file if image processing is failed + $x = q("UPDATE attach SET is_photo = 0 WHERE hash = '%s'", + dbesc($hash) + ); } + } if(($options !== 'update') && ($remove_when_processed)) @@ -2654,5 +2663,3 @@ function save_chunk($channel,$start,$end,$len) { $result['length'] = intval(filesize($new_path)); return $result; } - - -- cgit v1.2.3 From 328685d2fbe505fd5b1bf9892a0cce993210ac52 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 9 Apr 2020 09:38:36 +0000 Subject: move from build_sync_packet() to Libsync::build_sync_packet() --- include/attach.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 952270949..d986f4af1 100644 --- a/include/attach.php +++ b/include/attach.php @@ -11,6 +11,8 @@ * @todo Also an 'append' option to the storage function might be a useful addition. */ +use Zotlabs\Lib\Libsync; + require_once('include/permissions.php'); require_once('include/security.php'); require_once('include/group.php'); @@ -1018,7 +1020,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $sync = attach_export_data($channel,$hash); if($sync) - build_sync_packet($channel['channel_id'],array('file' => array($sync))); + Libsync::build_sync_packet($channel['channel_id'],array('file' => array($sync))); } if($notify) { @@ -1403,7 +1405,7 @@ function attach_change_permissions($channel_id, $resource, $allow_cid, $allow_gi $data = attach_export_data($channel,$resource); if($data) - build_sync_packet($channel['channel_id'],array('file' => array($data))); + Libsync::build_sync_packet($channel['channel_id'],array('file' => array($data))); } } -- cgit v1.2.3 From b7a655917ed1f7caa5b8b3d9b92fdd578c6252c4 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 23 Apr 2020 18:19:25 +0000 Subject: some work on deprecating ACTIVITY_OBJ_FILE --- include/attach.php | 92 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 12 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index d986f4af1..7b5972525 100644 --- a/include/attach.php +++ b/include/attach.php @@ -12,6 +12,8 @@ */ use Zotlabs\Lib\Libsync; +use Zotlabs\Access\PermissionLimits; +use Zotlabs\Daemon\Master; require_once('include/permissions.php'); require_once('include/security.php'); @@ -1024,9 +1026,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { } if($notify) { - $cloudPath = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['0']['display_path']; - $object = get_file_activity_object($channel['channel_id'], $r['0']['hash'], $cloudPath); - file_activity($channel['channel_id'], $object, $r['0']['allow_cid'], $r['0']['allow_gid'], $r['0']['deny_cid'], $r['0']['deny_gid'], 'post', $notify); + file_activity($channel, $observer, $r[0]); } return $ret; @@ -1517,7 +1517,7 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { */ call_hooks('attach_delete', $arr); - file_activity($channel_id, $object, $object['allow_cid'], $object['allow_gid'], $object['deny_cid'], $object['deny_gid'], 'update', true); + //file_activity($channel_id, $object, $object['allow_cid'], $object['allow_gid'], $object['deny_cid'], $object['deny_gid'], 'update', true); return; } @@ -1754,6 +1754,7 @@ function pipe_streams($in, $out, $bufsize = 16384) { * @param string $verb * @param boolean $notify */ +/* function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $notify) { require_once('include/items.php'); @@ -1802,7 +1803,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $uuid = item_message_id(); $mid = z_root() . '/item/' . $uuid; - $objtype = ACTIVITY_OBJ_FILE; + $objtype = 'ACTIVITY_OBJ_FILE'; $arr = array(); $arr['aid'] = get_account_id(); @@ -1901,6 +1902,62 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, return; } +*/ + + +function file_activity($channel, $observer, $file) { + + $filetype_parts = explode('/', $file['filetype']); + + switch($filetype_parts[0]) { + case 'image': + $type = 'Image'; + break; + case 'audio': + $type = 'Audio'; + break; + case 'video': + $type = 'Video'; + break; + default: + $type = 'Document'; + } + + $resource_id = $file['hash']; + $uuid = new_uuid(); + + $mid = z_root() . '/item/' . $uuid; + + $arr = []; // Initialize the array of parameters for the post + $arr['aid'] = $channel['channel_account_id']; + $arr['uuid'] = $uuid; + $arr['uid'] = $channel['channel_id']; + $arr['mid'] = $mid; + $arr['parent_mid'] = $mid; + $arr['resource_type'] = 'attach'; + $arr['resource_id'] = $resource_id; + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + $arr['plink'] = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path']; + $arr['llink'] = $arr['plink']; + $arr['title'] = $file['filename']; + $arr['allow_cid'] = $file['allow_cid']; + $arr['allow_gid'] = $file['allow_gid']; + $arr['deny_cid'] = $file['deny_cid']; + $arr['deny_gid'] = $file['deny_gid']; + $arr['item_origin'] = 1; + $arr['item_thread_top'] = 1; + $arr['item_private'] = (($file['allow_cid'] || $file['allow_gid'] || $file['deny_cid'] || $file['deny_gid']) ? 1 : 0); + $arr['verb'] = ACTIVITY_CREATE; + $arr['obj_type'] = $type; + $arr['title'] = $file['filename']; + $body_str = sprintf(t('%s shared a %s with you'), '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]', '[zrl=' . $arr['plink'] . ']' . t('file') . '[/zrl]'); + $arr['body'] = $body_str; + + post_activity_item($arr); + +} + /** * @brief Create file activity object. @@ -1917,17 +1974,28 @@ function get_file_activity_object($channel_id, $hash, $url) { dbesc($hash) ); - $url = rawurlencode($url); - - $links = array(); - $links[] = array( + $links = []; + $links[] = [ 'rel' => 'alternate', - 'type' => 'text/html', + 'type' => $x[0]['filetype'], 'href' => $url - ); + ]; + + $filetype_parts = explode('/', $x[0]['filetype']); + + switch($filetype_parts[0]) { + case 'audio': + $type = 'Audio'; + break; + case 'video': + $type = 'Video'; + break; + default: + $type = 'Document'; + } $object = array( - 'type' => ACTIVITY_OBJ_FILE, + 'type' => $type, 'title' => $x[0]['filename'], 'id' => $url, 'link' => $links, -- cgit v1.2.3 From 7e89d816d7cddbd378e7eaed8e38f9776f3ae167 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 23 Apr 2020 19:14:43 +0000 Subject: more work on deprecating ACTIVITY_OBJ_FILE --- include/attach.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 7b5972525..7149be735 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1026,7 +1026,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { } if($notify) { - file_activity($channel, $observer, $r[0]); + attach_store_item($channel, $observer, $r[0]); } return $ret; @@ -1452,9 +1452,6 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { return; } - $url = get_cloud_url($channel_id, $channel_address, $resource); - $object = get_file_activity_object($channel_id, $resource, $url); - // If resource is a directory delete everything in the directory recursive if(intval($r[0]['is_dir'])) { $x = q("SELECT hash, os_storage, is_dir, flags FROM attach WHERE folder = '%s' AND uid = %d", @@ -1498,6 +1495,9 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { if($r[0]['is_photo']) { attach_drop_photo($channel_id,$resource); } + else { + attach_drop_item($channel_id,$resource); + } // update the parent folder's lastmodified timestamp @@ -1517,8 +1517,6 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { */ call_hooks('attach_delete', $arr); - //file_activity($channel_id, $object, $object['allow_cid'], $object['allow_gid'], $object['deny_cid'], $object['deny_gid'], 'update', true); - return; } @@ -1553,6 +1551,21 @@ function attach_drop_photo($channel_id,$resource) { } +function attach_drop_item($channel_id,$resource) { + + $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'attach' and uid = %d and item_deleted = 0", + dbesc($resource), + intval($channel_id) + ); + + if($x) { + $stage = (($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1); + $interactive = (($x[0]['item_hidden']) ? false : true); + drop_item($x[0]['id'], $interactive, $stage); + } + +} + /** * @brief Returns path to file in cloud/. @@ -1905,7 +1918,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, */ -function file_activity($channel, $observer, $file) { +function attach_store_item($channel, $observer, $file) { $filetype_parts = explode('/', $file['filetype']); @@ -1945,6 +1958,7 @@ function file_activity($channel, $observer, $file) { $arr['allow_gid'] = $file['allow_gid']; $arr['deny_cid'] = $file['deny_cid']; $arr['deny_gid'] = $file['deny_gid']; + $arr['item_wall'] = 1; $arr['item_origin'] = 1; $arr['item_thread_top'] = 1; $arr['item_private'] = (($file['allow_cid'] || $file['allow_gid'] || $file['deny_cid'] || $file['deny_gid']) ? 1 : 0); -- cgit v1.2.3 From e2b10f52e02c4cee77af089a544ec55e62048aba Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 24 Apr 2020 14:25:49 +0000 Subject: more work on deprecating ACTIVITY_OBJ_FILE and adapt mod sharedwithme --- include/attach.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 7149be735..fbf131fb3 100644 --- a/include/attach.php +++ b/include/attach.php @@ -12,6 +12,7 @@ */ use Zotlabs\Lib\Libsync; +use Zotlabs\Lib\Activity; use Zotlabs\Access\PermissionLimits; use Zotlabs\Daemon\Master; @@ -1940,6 +1941,7 @@ function attach_store_item($channel, $observer, $file) { $uuid = new_uuid(); $mid = z_root() . '/item/' . $uuid; + $path = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path']; $arr = []; // Initialize the array of parameters for the post $arr['aid'] = $channel['channel_account_id']; @@ -1951,8 +1953,6 @@ function attach_store_item($channel, $observer, $file) { $arr['resource_id'] = $resource_id; $arr['owner_xchan'] = $channel['channel_hash']; $arr['author_xchan'] = $observer['xchan_hash']; - $arr['plink'] = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path']; - $arr['llink'] = $arr['plink']; $arr['title'] = $file['filename']; $arr['allow_cid'] = $file['allow_cid']; $arr['allow_gid'] = $file['allow_gid']; @@ -1965,9 +1965,22 @@ function attach_store_item($channel, $observer, $file) { $arr['verb'] = ACTIVITY_CREATE; $arr['obj_type'] = $type; $arr['title'] = $file['filename']; - $body_str = sprintf(t('%s shared a %s with you'), '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]', '[zrl=' . $arr['plink'] . ']' . t('file') . '[/zrl]'); + $body_str = sprintf(t('%s shared a %s with you'), '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]', '[zrl=' . $path . ']' . t('file') . '[/zrl]'); $arr['body'] = $body_str; + $meta = [ + 'name' => $file['filename'], + 'type' => $file['filetype'], + 'size' => $file['filesize'], + 'revision' => $file['revision'], + 'size' => $file['filesize'], + 'created' => $file['created'], + 'edited' => $file['edited'], + 'path' => $path + ]; + + set_iconfig($arr, 'attach', 'meta' , $meta, true); + post_activity_item($arr); } -- cgit v1.2.3 From c229f058b4331e3b631d9ca725385ef78bf59778 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 25 Apr 2020 09:15:20 +0000 Subject: fix mod filestorage and fetch the info from attach if only the hash is provided in attach_store_item() --- include/attach.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index fbf131fb3..4c2459046 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1921,6 +1921,20 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, function attach_store_item($channel, $observer, $file) { + + if(is_string($file)) { + $r = q("SELECT * FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($channel['channel_id']), + dbesc($file) + ); + + if(! $r) + return; + + $file = $r[0]; + + } + $filetype_parts = explode('/', $file['filetype']); switch($filetype_parts[0]) { -- cgit v1.2.3 From 079c13e6330bc3b4bc3928c55b89023be0af5ad7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Apr 2020 08:21:33 +0000 Subject: more work on attach_store_item() --- include/attach.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 4c2459046..d648293ee 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1935,6 +1935,59 @@ function attach_store_item($channel, $observer, $file) { } + $path = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path']; + + $r = q("SELECT * FROM item WHERE resource_id = '%s' AND resource_type = 'attach' and uid = %d LIMIT 1", + dbesc($file['hash']), + intval($channel['channel_id']) + ); + + if($r) { + + // At the moment only file permission edits are possible. + // If permissions did not change do nothing. Otherwise delete the item and create a new one with new permissions. + + if($r[0]['allow_cid'] === $file['allow_cid'] && $r[0]['allow_gid'] === $file['allow_gid'] && $r[0]['deny_cid'] === $file['deny_cid'] && $r[0]['deny_gid'] === $file['deny_gid']) { + + /* once possible, other edits (eg rename) can be done here. + + q("UPDATE item SET title = '%s' WHERE id = %d AND uid = %d", + dbesc($file['filename']) + ); + + $meta = [ + 'name' => $file['filename'], + 'type' => $file['filetype'], + 'size' => $file['filesize'], + 'revision' => $file['revision'], + 'size' => $file['filesize'], + 'created' => $file['created'], + 'edited' => $file['edited'], + 'path' => $path + ]; + + set_iconfig($r[0], 'attach', 'meta' , $meta, true); + + $post = item_store($arr); + + $item_id = $post['item_id']; + + if($item_id) { + Master::Summon(['Notifier', 'activity', $item_id]); + } + + */ + + return; + + } + + $stage = (($r[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1); + $interactive = (($r[0]['item_hidden']) ? false : true); + drop_item($r[0]['id'], $interactive, $stage); + + } + $filetype_parts = explode('/', $file['filetype']); switch($filetype_parts[0]) { @@ -1955,7 +2008,6 @@ function attach_store_item($channel, $observer, $file) { $uuid = new_uuid(); $mid = z_root() . '/item/' . $uuid; - $path = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path']; $arr = []; // Initialize the array of parameters for the post $arr['aid'] = $channel['channel_account_id']; @@ -1994,8 +2046,14 @@ function attach_store_item($channel, $observer, $file) { ]; set_iconfig($arr, 'attach', 'meta' , $meta, true); + + $post = item_store($arr); - post_activity_item($arr); + $item_id = $post['item_id']; + + if($item_id) { + Master::Summon(['Notifier', 'activity', $item_id]); + } } -- cgit v1.2.3 From c9794439bcdf7bf738055fdecddc754609b8b9ab Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Apr 2020 08:24:00 +0000 Subject: adjust code comments and whitespace --- include/attach.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index d648293ee..80f71b9ea 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1945,7 +1945,8 @@ function attach_store_item($channel, $observer, $file) { if($r) { // At the moment only file permission edits are possible. - // If permissions did not change do nothing. Otherwise delete the item and create a new one with new permissions. + // Since we do not support permission editing on posts yet, + // we will delete the item and create a new one with the new permissions for now. if($r[0]['allow_cid'] === $file['allow_cid'] && $r[0]['allow_gid'] === $file['allow_gid'] && $r[0]['deny_cid'] === $file['deny_cid'] && $r[0]['deny_gid'] === $file['deny_gid']) { @@ -1967,7 +1968,7 @@ function attach_store_item($channel, $observer, $file) { ]; set_iconfig($r[0], 'attach', 'meta' , $meta, true); - + $post = item_store($arr); $item_id = $post['item_id']; @@ -2046,7 +2047,7 @@ function attach_store_item($channel, $observer, $file) { ]; set_iconfig($arr, 'attach', 'meta' , $meta, true); - + $post = item_store($arr); $item_id = $post['item_id']; -- cgit v1.2.3 From d59b81f11df990c7710378f9d9b0341fc89276e9 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 31 Oct 2020 19:57:14 +0000 Subject: if restarting a previously interrupted upload just return where we ended - fix issue #1485 --- include/attach.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 80f71b9ea..c9649a4ce 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2807,6 +2807,12 @@ function save_chunk($channel,$start,$end,$len) { $new_path = $new_base . '/' . $_FILES['files']['name']; + if(file_exists($new_path) && intval($start) === 0) { + $result['partial'] = true; + $result['length'] = intval(filesize($new_path)); + return $result; + } + if(! file_exists($new_path)) { rename($tmp_path,$new_path); } -- cgit v1.2.3