aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php149
1 files changed, 63 insertions, 86 deletions
diff --git a/include/attach.php b/include/attach.php
index e5a2900b3..bda4905f1 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -11,11 +11,12 @@
* @todo Also an 'append' option to the storage function might be a useful addition.
*/
-use Zotlabs\Lib\Libsync;
-use Zotlabs\Lib\Activity;
use Zotlabs\Access\PermissionLimits;
use Zotlabs\Daemon\Master;
use Zotlabs\Lib\AccessList;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\Config;
+use Zotlabs\Lib\Libsync;
require_once('include/permissions.php');
require_once('include/security.php');
@@ -112,7 +113,6 @@ function z_mime_content_type($filename) {
'odf' => 'application/vnd.oasis.opendocument.formula',
'odi' => 'application/vnd.oasis.opendocument.image',
'odm' => 'application/vnd.oasis.opendocument.text-master',
- 'odb' => 'application/vnd.oasis.opendocument.base',
'odb' => 'application/vnd.oasis.opendocument.database',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
@@ -801,7 +801,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// Check storage limits
if($options !== 'update') {
- $maxfilesize = get_config('system','maxfilesize');
+ $maxfilesize = Config::Get('system','maxfilesize');
if(($maxfilesize) && ($filesize > $maxfilesize)) {
logger('quota_exceeded');
@@ -1606,8 +1606,7 @@ function attach_drop_photo($channel_id,$resource) {
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);
+ drop_item($x[0]['id'], $stage);
}
$r = q("SELECT content FROM photo WHERE resource_id = '%s' AND uid = %d AND os_storage = 1",
@@ -1636,8 +1635,7 @@ function attach_drop_item($channel_id,$resource) {
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);
+ drop_item($x[0]['id'], $stage);
}
}
@@ -1855,8 +1853,6 @@ function pipe_streams($in, $out, $bufsize = 16384) {
}
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']),
@@ -1906,10 +1902,11 @@ function attach_store_item($channel, $observer, $file) {
$post = item_store($arr);
- $item_id = $post['item_id'];
-
- if($item_id) {
- Master::Summon(['Notifier', 'activity', $item_id]);
+ if ($post['success']) {
+ Master::Summon(['Notifier', 'activity', $post['item_id']]);
+ if (!empty($post['approval_id'])) {
+ Master::Summon(['Notifier', 'activity', $post['approval_id']]);
+ }
}
*/
@@ -1919,8 +1916,11 @@ function attach_store_item($channel, $observer, $file) {
}
$stage = (($r[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1);
- $interactive = (($r[0]['item_hidden']) ? false : true);
- drop_item($r[0]['id'], $interactive, $stage);
+ drop_item($r[0]['id'], $stage);
+
+ if (empty($r[0]['item_hidden'])) {
+ Master::Summon(['Notifier', 'drop', $r[0]['id']]);
+ }
}
@@ -1945,6 +1945,12 @@ function attach_store_item($channel, $observer, $file) {
$mid = z_root() . '/item/' . $uuid;
+ $target = [
+ 'id' => z_root() . '/conversation/' . $uuid,
+ 'type' => 'Collection',
+ 'attributedTo' => channel_url($channel),
+ ];
+
$arr = []; // Initialize the array of parameters for the post
$arr['aid'] = $channel['channel_account_id'];
$arr['uuid'] = $uuid;
@@ -1965,6 +1971,8 @@ function attach_store_item($channel, $observer, $file) {
$arr['item_thread_top'] = 1;
$arr['item_private'] = (($file['allow_cid'] || $file['allow_gid'] || $file['deny_cid'] || $file['deny_gid']) ? 1 : 0);
$arr['verb'] = 'Create';
+ $arr['target'] = $target;
+ $arr['target_type'] = 'Collection';
$arr['obj_type'] = $type;
$arr['title'] = $file['filename'];
@@ -1982,14 +1990,13 @@ function attach_store_item($channel, $observer, $file) {
}
$body_str = sprintf((($type === 'Image') ? t('%s shared an %s with you') : t('%s shared a %s with you')), '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]', '[zrl=' . $path . ']' . (($type === 'Image') ? t('image') : t('file')) . '[/zrl]');
- $arr['body'] .= $body_str;
+ $arr['body'] .= "\r\n" . $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
@@ -1999,10 +2006,11 @@ function attach_store_item($channel, $observer, $file) {
$post = item_store($arr);
- $item_id = $post['item_id'];
-
- if($item_id) {
- Master::Summon(['Notifier', 'activity', $item_id]);
+ if ($post['success']) {
+ Master::Summon(['Notifier', 'activity', $post['item_id']]);
+ if (!empty($post['approval_id'])) {
+ Master::Summon(['Notifier', 'activity', $post['approval_id']]);
+ }
}
}
@@ -2466,8 +2474,8 @@ function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpat
* @param int $channel_id
* @param int $resource_id
* @param string $new_folder_hash
- * @param (optional) string $newname
- * @param (optional) boolean $recurse
+ * @param string (optional) $newname
+ * @param boolean (optional) $recurse
* @return array Associative array with:
* * \e boolean \b success
* * \e string \b resource_id
@@ -2599,33 +2607,31 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '',
intval($r[0]['id'])
);
- if($r[0]['is_photo']) {
- q("update photo set album = '%s', filename = '%s', os_path = '%s', display_path = '%s'
- where resource_id = '%s' and uid = %d",
- dbesc($newalbumname),
- dbesc($filename),
- dbesc($x['os_path']),
- dbesc($x['path']),
- dbesc($resource_id),
- intval($channel_id)
- );
-
- q("update photo set content = CASE imgscale WHEN 0 THEN %s ELSE CONCAT(%s, '-', imgscale) END where resource_id = '%s' and uid = %d and os_storage = 1",
- dbescbin($newstorepath),
- dbescbin($newstorepath),
- dbesc($resource_id),
- intval($channel_id)
- );
-
- // now rename the thumbnails in os_storage - the original should have been copied before already
- $ps = q("SELECT content, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 and os_storage = 1",
+ if ($r[0]['is_photo']) {
+ // update the photo DB entries and copy the thumbnails
+ $ps = q("SELECT imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and os_storage = 1",
intval($channel_id),
dbesc($resource_id)
);
if ($recurse) {
foreach($ps as $p) {
- rename($oldstorepath . '-' . $p['imgscale'], $p['content']);
+ q("update photo set album = '%s', filename = '%s', os_path = '%s', display_path = '%s', content = '%s'
+ where resource_id = '%s' and imgscale = %d and uid = %d",
+ dbesc($newalbumname),
+ dbesc($filename),
+ dbesc($x['os_path']),
+ dbesc($x['path']),
+ dbescbin($newstorepath . ((intval($p['imgscale']) > 0) ? '-' . $p['imgscale'] : '')),
+ dbesc($resource_id),
+ intval($p['imgscale']),
+ intval($channel_id)
+ );
+
+ // the original should have been copied already
+ if (intval($p['imgscale']) > 0) {
+ rename($oldstorepath . '-' . $p['imgscale'], $newstorepath . '-' . $p['imgscale']);
+ }
}
}
}
@@ -2667,8 +2673,8 @@ function attach_move($channel_id, $resource_id, $new_folder_hash, $newname = '',
* @param int $channel_id
* @param int $resource_id
* @param string $new_folder_hash
- * @param (optional) string $newname
- * @param (optional) boolean $recurse
+ * @param string (optional) $newname
+ * @param boolean (optional) $recurse
* @return array Associative array with:
* * \e boolean \b success
* * \e string \b resource_id of the new resource
@@ -2935,41 +2941,6 @@ function attach_syspaths($channel_id,$attach_hash) {
return [ 'os_path' => $os_path, 'path' => $path ];
}
-/**
- * in earlier releases we did not fill in os_path and display_path in the attach DB structure.
- * (It was not needed or used). Going forward we intend to make use of these fields.
- * A cron task checks for empty values (as older attachments may have arrived at our site
- * in a clone operation) and executes attach_syspaths() to generate these field values and correct
- * the attach table entry. The operation is limited to 100 DB entries at a time so as not to
- * overload the system in any cron run. Eventually it will catch up with old attach structures
- * and switch into maintenance mode to correct any that might arrive in clone packets from older
- * sites.
- */
-
-
-
-function attach_upgrade() {
- $r = q("SELECT id, uid, hash FROM attach WHERE os_path = '' OR display_path = '' LIMIT 100");
- if($r) {
- foreach($r as $rv) {
- $x = attach_syspaths($rv['uid'],$rv['hash']);
- if($x) {
- q("update attach set os_path = '%s', display_path = '%s' where id = %d",
- dbesc($x['os_path']),
- dbesc($x['path']),
- intval($rv['id'])
- );
- q("update photo set os_path = '%s', display_path = '%s' where uid = %d and resource_id = '%s'",
- dbesc($x['os_path']),
- dbesc($x['path']),
- intval($rv['uid']),
- dbesc($rv['hash'])
- );
- }
- }
- }
-}
-
/**
* Chunked uploader for integration with the blueimp jquery-uploader
@@ -2981,11 +2952,17 @@ function save_chunk($channel,$start,$end,$len) {
$result = [];
- $tmp_path = $_FILES['files']['tmp_name'];
+ $file = $_FILES['files'] ?? $_FILES['userfile'] ?? [];
+
+ if (!$file) {
+ return $result;
+ }
+
+ $tmp_path = $file['tmp_name'];
$new_base = 'store/[data]/' . $channel['channel_address'] . '/tmp';
os_mkdir($new_base,STORAGE_DEFAULT_PERMISSIONS,true);
- $new_path = $new_base . '/' . $_FILES['files']['name'];
+ $new_path = $new_base . '/' . $file['name'];
if(file_exists($new_path) && intval($start) === 0) {
$result['partial'] = true;
@@ -3007,8 +2984,8 @@ function save_chunk($channel,$start,$end,$len) {
}
if(($len - 1) == $end) {
unlink($tmp_path);
- $result['name'] = $_FILES['files']['name'];
- $result['type'] = $_FILES['files']['type'];
+ $result['name'] = $file['name'];
+ $result['type'] = $file['type'];
$result['tmp_name'] = $new_path;
$result['error'] = 0;
$result['size'] = $len;