aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/attach.php98
1 files changed, 55 insertions, 43 deletions
diff --git a/include/attach.php b/include/attach.php
index c66ba40d5..a201fd3d4 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -779,10 +779,12 @@ function attach_delete($channel_id, $resource) {
intval($channel_id)
);
-
if(! $r)
return;
+ $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource);
+ $object = get_file_activity_object($channel_id, $resource, $cloudpath);
+
// If resource is a directory delete everything in the directory recursive
if($r[0]['flags'] & ATTACH_FLAG_DIR) {
$x = q("SELECT hash, flags FROM attach WHERE folder = '%s' AND uid = %d",
@@ -825,7 +827,8 @@ function attach_delete($channel_id, $resource) {
intval($channel_id)
);
- file_activity($channel_id, $resource, $cloudpath='', $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'drop', $no_activity=false);
+ file_activity($channel_id, $object, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'update', $no_activity=false);
+
}
/**
@@ -961,21 +964,15 @@ function pipe_streams($in, $out) {
return $size;
}
-function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) {
+function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) {
require_once('include/items.php');
- $poster = get_app()->get_observer();
-
switch($verb) {
case 'post':
$activity = ACTIVITY_POST;
- $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
- intval($channel_id),
- dbesc($hash)
- );
break;
- case 'drop':
+ case 'update':
$activity = ACTIVITY_UPDATE;
break;
default:
@@ -983,48 +980,25 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
break;
}
- $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable');
+ $poster = get_app()->get_observer();
$mid = item_message_id();
- $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
-
- $links = array();
- $links[] = array(
- 'rel' => 'alternate',
- 'type' => 'text/html',
- 'href' => $url
- );
-
$objtype = ACTIVITY_OBJ_FILE;
- $object = array(
- 'type' => ACTIVITY_OBJ_FILE,
- 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'),
- 'id' => $url,
- 'link' => $links,
+ $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
- 'hash' => $hash,
- 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''),
- 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''),
- 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''),
- 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''),
- 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''),
- 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''),
- 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''),
- 'created' => (($x[0]['created']) ? $x[0]['created'] : ''),
- 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '')
- );
+ $jsonobject = json_encode($object);
$private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0);
if($verb == 'post') {
//check if activity item exists
//if yes send update (drop) activity and create a new one
- $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object LIKE '%s'",
+ $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1",
dbesc(ACTIVITY_POST),
- dbesc(ACTIVITY_OBJ_FILE),
- dbesc('%"hash":"' . $hash . '"%')
+ dbesc($objtype),
+ dbesc($jsonobject)
);
if($y) {
@@ -1033,6 +1007,8 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
$object['mid'] = $mid; //attach mid for update object
+ $ujsonobject = json_encode($object);
+
$arr = array();
$arr['aid'] = get_account_id();
@@ -1052,7 +1028,7 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
$arr['item_private'] = 0;
$arr['verb'] = ACTIVITY_UPDATE;
$arr['obj_type'] = $objtype;
- $arr['object'] = json_encode($object);
+ $arr['object'] = $ujsonobject;
$arr['body'] = '';
$post = item_store($arr);
@@ -1064,8 +1040,6 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
call_hooks('post_local_end', $arr);
- unset($object['mid']); //remove mid for new object
-
//notice( t('File activity updated') . EOL);
if($no_activity) {
@@ -1097,7 +1071,7 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
$arr['item_private'] = $private;
$arr['verb'] = $activity;
$arr['obj_type'] = $objtype;
- $arr['object'] = json_encode($object);
+ $arr['object'] = $jsonobject;
$arr['body'] = '';
$post = item_store($arr);
@@ -1114,3 +1088,41 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
return;
}
+
+function get_file_activity_object($channel_id, $hash, $cloudpath) {
+
+ $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
+ intval($channel_id),
+ dbesc($hash)
+ );
+
+ $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable');
+
+ $links = array();
+ $links[] = array(
+ 'rel' => 'alternate',
+ 'type' => 'text/html',
+ 'href' => $url
+ );
+
+ $object = array(
+ 'type' => ACTIVITY_OBJ_FILE,
+ 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'),
+ 'id' => $url,
+ 'link' => $links,
+
+ 'hash' => $hash,
+ 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''),
+ 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''),
+ 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''),
+ 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''),
+ 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''),
+ 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''),
+ 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''),
+ 'created' => (($x[0]['created']) ? $x[0]['created'] : ''),
+ 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '')
+ );
+
+ return $object;
+
+}