aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php200
1 files changed, 184 insertions, 16 deletions
diff --git a/include/attach.php b/include/attach.php
index d986f4af1..80f71b9ea 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -12,6 +12,9 @@
*/
use Zotlabs\Lib\Libsync;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Access\PermissionLimits;
+use Zotlabs\Daemon\Master;
require_once('include/permissions.php');
require_once('include/security.php');
@@ -1024,9 +1027,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);
+ attach_store_item($channel, $observer, $r[0]);
}
return $ret;
@@ -1452,9 +1453,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 +1496,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 +1518,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 +1552,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/.
@@ -1754,6 +1768,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 +1817,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 +1916,148 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
return;
}
+*/
+
+
+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];
+
+ }
+
+ $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.
+ // 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']) {
+
+ /* 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]) {
+ 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['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_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);
+ $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=' . $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 = item_store($arr);
+
+ $item_id = $post['item_id'];
+
+ if($item_id) {
+ Master::Summon(['Notifier', 'activity', $item_id]);
+ }
+
+}
+
/**
* @brief Create file activity object.
@@ -1917,17 +2074,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,