aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php457
1 files changed, 336 insertions, 121 deletions
diff --git a/include/attach.php b/include/attach.php
index 937d33ea3..78e133b03 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -209,7 +209,7 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $
// Retrieve all columns except 'data'
- $r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, os_storage, is_dir, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra ORDER BY $orderby $limit",
+ $r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, os_path, display_path, os_storage, is_dir, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra ORDER BY $orderby $limit",
intval($channel_id)
);
@@ -284,6 +284,7 @@ function attach_by_hash($hash, $observer_hash, $rev = 0) {
return $ret;
}
+
function attach_can_view_folder($uid,$ob_hash,$folder_hash) {
$sql_extra = permissions_sql($uid,$ob_hash);
@@ -348,7 +349,7 @@ function attach_by_hash_nodata($hash, $observer_hash, $rev = 0) {
// Now we'll see if we can access the attachment
- $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, is_dir, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1",
+ $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, os_path, display_path, is_dir, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1",
intval($r[0]['uid']),
dbesc($hash)
);
@@ -422,6 +423,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
$upload_path = (($arr && $arr['directory']) ? $arr['directory'] : '');
$visible = (($arr && $arr['visible']) ? $arr['visible'] : '');
+ $notify = (($arr && $arr['notify']) ? $arr['notify'] : '');
$observer = array();
@@ -458,6 +460,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// By default remove $src when finished
$remove_when_processed = true;
+ $import_replace = false;
if($options === 'import') {
$src = $arr['src'];
@@ -474,6 +477,9 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($arr['preserve_original'])
$remove_when_processed = false;
+ if($arr['replace'])
+ $import_replace = true;
+
// if importing a directory, just do it now and go home - we're done.
if(array_key_exists('is_dir',$arr) && intval($arr['is_dir'])) {
@@ -531,7 +537,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($options === 'update' && $arr && array_key_exists('revision',$arr))
$sql_options = " and revision = " . intval($arr['revision']) . " ";
- $x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1",
+ $x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, os_storage, is_photo, os_path, display_path, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1",
dbesc($arr['hash']),
intval($channel_id)
);
@@ -609,13 +615,16 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// A freshly uploaded file. Check for duplicate and resolve with the channel's overwrite settings.
- $r = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
+ $r = q("select filename, id, hash, filesize from attach where uid = %d and filename = '%s' and folder = '%s' ",
+ intval($channel_id),
dbesc($filename),
dbesc($folder_hash)
);
if($r) {
- $overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
+ $overwrite = (($import_replace || get_pconfig($channel_id,'system','overwrite_dup_files')) ? true : false);
if(($overwrite) || ($options === 'import')) {
+ if(! array_key_exists('edited',$arr))
+ $arr['edited'] = datetime_convert();
$options = 'replace';
$existing_id = $x[0]['id'];
$existing_size = intval($x[0]['filesize']);
@@ -631,7 +640,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$ext = $def_extension;
}
- $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
+ $r = q("select filename from attach where uid = %d and ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
+ intval($channel_id),
dbesc($basename . $ext),
dbesc($basename . '(%)' . $ext),
dbesc($folder_hash)
@@ -702,11 +712,11 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$os_relpath .= $folder_hash . '/';
}
- $os_relpath .= $hash;
+ $os_relpath .= $hash;
+ $os_relpath = ltrim($os_relpath,'/');
- // not yet used
- $os_path = '';
- $display_path = '';
+ $os_path = $os_relpath;
+ $display_path = ltrim($pathname . '/' . $filename,'/');
if($src)
@file_put_contents($os_basepath . $os_relpath,@file_get_contents($src));
@@ -810,7 +820,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($is_photo) {
- $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options );
+ $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'])
$args['contact_allow'] = $arr['contact_allow'];
if($arr['group_allow'])
@@ -883,6 +893,12 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
build_sync_packet($channel['channel_id'],array('file' => array($sync)));
}
+ 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);
+ }
+
return $ret;
}
@@ -914,7 +930,7 @@ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') {
if(count($paths) > 1) {
$curpath = array_shift($paths);
- $r = q("select hash, id, is_dir from attach where uid = %d and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id) . " limit 1",
+ $r = q("select hash, id, is_dir from attach where uid = %d and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id,$observer_hash) . " limit 1",
intval($channel_id),
dbesc($curpath)
);
@@ -929,7 +945,7 @@ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') {
else
$paths = array($pathname);
- $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, is_photo, is_dir, os_storage, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and folder = '%s' and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id),
+ $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_path, display_path, is_photo, is_dir, os_storage, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and folder = '%s' and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id),
intval($channel_id),
dbesc($parent_hash),
dbesc($paths[0])
@@ -968,12 +984,15 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
$sql_options = '';
- $basepath = 'store/' . $channel['channel_address'];
+ $os_basepath = 'store/' . $channel['channel_address'];
- logger('attach_mkdir: basepath: ' . $basepath);
+ logger('attach_mkdir: basepath: ' . $os_basepath);
- if(! is_dir($basepath))
- os_mkdir($basepath,STORAGE_DEFAULT_PERMISSIONS, true);
+ if(! is_dir($os_basepath))
+ os_mkdir($os_basepath,STORAGE_DEFAULT_PERMISSIONS, true);
+
+
+ $os_basepath .= '/';
if(! perm_is_allowed($channel_id, $observer_hash, 'write_storage')) {
$ret['message'] = t('Permission denied.');
@@ -1019,10 +1038,13 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
$lpath = '';
$lfile = $arr['folder'];
+ $dpath = '';
+
$sql_options = permissions_sql($channel['channel_id']);
+
do {
- $r = q("select filename, hash, flags, is_dir, folder from attach where uid = %d and hash = '%s' and is_dir != 0
+ $r = q("select filename, hash, flags, is_dir, folder, display_path from attach where uid = %d and hash = '%s' and is_dir = 1
$sql_options limit 1",
intval($channel['channel_id']),
dbesc($lfile)
@@ -1032,22 +1054,26 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
$ret['message'] = t('Path not found.');
return $ret;
}
+
+ $dpath = $r[0]['filename'] . (($dpath) ? '/' . $dpath : '');
+
if($lfile)
- $lpath = $r[0]['hash'] . '/' . $lpath;
+ $lpath = $r[0]['hash'] . (($lpath) ? '/' . $lpath : '');
+
$lfile = $r[0]['folder'];
+
} while ( ($r[0]['folder']) && intval($r[0]['is_dir'])) ;
- $path = $basepath . '/' . $lpath;
+
+ $path = $lpath;
}
else
- $path = $basepath . '/';
-
- $path .= $arr['hash'];
+ $path = '';
$created = datetime_convert();
- // not yet used
- $os_path = '';
- $display_path = '';
+ $os_path = ltrim($path . '/' . $arr['hash'],'/');
+ $display_path = ltrim($dpath . '/' . $arr['filename'],'/');
+
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_dir, content, created, edited, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
@@ -1062,7 +1088,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
dbesc($arr['folder']),
intval(1),
intval(1),
- dbescbin($path),
+ dbescbin($os_basepath . $os_path),
dbesc($created),
dbesc($created),
dbesc($os_path),
@@ -1074,7 +1100,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
);
if($r) {
- if(os_mkdir($path, STORAGE_DEFAULT_PERMISSIONS, true)) {
+ if(os_mkdir($os_basepath . $os_path, STORAGE_DEFAULT_PERMISSIONS, true)) {
$ret['success'] = true;
// update the parent folder's lastmodified timestamp
@@ -1092,7 +1118,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
$ret['data'] = $z[0];
}
else {
- logger('attach_mkdir: ' . mkdir . ' ' . $path . ' failed.');
+ logger('attach_mkdir: ' . mkdir . ' ' . $os_basepath . $os_path . ' failed.');
$ret['message'] = t('mkdir failed.');
}
}
@@ -1286,8 +1312,8 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
return;
}
- $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource);
- $object = get_file_activity_object($channel_id, $resource, $cloudpath);
+ $url = get_cloudpath($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'])) {
@@ -1428,7 +1454,7 @@ function get_cloudpath($arr) {
* @param string $attachHash
* @return string with the full folder path
*/
-function get_parent_cloudpath($channel_id, $channel_name, $attachHash) {
+function get_cloud_url($channel_id, $channel_name, $attachHash) {
$parentFullPath = '';
// build directory tree
$parentHash = $attachHash;
@@ -1440,9 +1466,9 @@ function get_parent_cloudpath($channel_id, $channel_name, $attachHash) {
}
} while ($parentHash);
- $parentFullPath = z_root() . '/cloud/' . $channel_name . '/' . $parentFullPath;
+ $url = z_root() . '/cloud/' . $channel_name . '/' . $parentFullPath . find_filename_by_hash($channel_id, $attachHash);
- return $parentFullPath;
+ return $url;
}
/**
@@ -1477,18 +1503,34 @@ function find_folder_hash_by_attach_hash($channel_id, $attachHash, $recurse = fa
function find_folder_hash_by_path($channel_id, $path) {
- $filename = end(explode('/', $path));
+ if(! $path)
+ return '';
- $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' LIMIT 1",
- intval($channel_id),
- dbesc($filename)
- );
+ $comps = explode('/',$path);
+ $errors = false;
+ $parent_hash = '';
- $hash = '';
- if($r && $r[0]['hash']) {
- $hash = $r[0]['hash'];
+ for($x = 0; $x < count($comps); $x ++) {
+ $element = $comps[$x];
+ $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' AND folder = '%s' LIMIT 1",
+ intval($channel_id),
+ dbesc($element),
+ dbesc($parent_hash)
+ );
+ if($r) {
+ $parent_hash = $r[0]['hash'];
+ }
+ else {
+ $errors ++;
+ break;
+ }
}
- return $hash;
+
+ if($errors)
+ return '';
+
+ return $parent_hash;
+
}
/**
@@ -1569,7 +1611,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$folder_hash = $object['folder'];
- $r_perms = recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash);
+ $r_perms = attach_recursive_perms($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash);
+
+ if($r_perms === false) //nobody has recursive perms - nobody must be notified
+ return;
//split up returned perms
$arr_allow_cid = $r_perms['allow_cid'];
@@ -1648,17 +1693,9 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$arr['obj'] = $u_jsonobject;
$arr['body'] = '';
- $post = item_store($arr);
- $item_id = $post['item_id'];
- if($item_id) {
- Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id));
- }
-
- call_hooks('post_local_end', $arr);
+ post_activity_item($arr);
$update = false;
-
- //notice( t('File activity updated') . EOL);
}
//don't create new activity if notify was not enabled
@@ -1683,16 +1720,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$arr['obj'] = (($update) ? $u_jsonobject : $jsonobject);
$arr['body'] = '';
- $post = item_store($arr);
- $item_id = $post['item_id'];
-
- if($item_id) {
- Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id));
- }
-
- call_hooks('post_local_end', $arr);
-
- //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL));
+ post_activity_item($arr);
return;
}
@@ -1704,14 +1732,14 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
* @param string $hash
* @param string $cloudpath
*/
-function get_file_activity_object($channel_id, $hash, $cloudpath) {
+function get_file_activity_object($channel_id, $hash, $url) {
$x = q("SELECT creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, is_dir, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
intval($channel_id),
dbesc($hash)
);
- $url = rawurlencode($cloudpath . $x[0]['filename']);
+ $url = rawurlencode($url);
$links = array();
$links[] = array(
@@ -1749,7 +1777,7 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) {
}
/**
- * @brief Returns array of channels which have recursive permission for a file
+ * @brief Returns recursive permissions array or false if nobody has recursive permissions
*
* @param array $arr_allow_cid
* @param array $arr_allow_gid
@@ -1757,19 +1785,20 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) {
* @param array $arr_deny_gid
* @param string $folder_hash
*/
-function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) {
+function attach_recursive_perms($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) {
$ret = array();
$parent_arr = array();
$count_values = array();
$poster = App::get_observer();
- //turn allow_gid into allow_cid's
- foreach($arr_allow_gid as $gid) {
- $in_group = group_get_members($gid);
+ //lookup all channels in sharee group and add them to sharee $arr_allow_cid
+ if($arr_allow_gid) {
+ $in_group = expand_groups($arr_allow_gid);
$arr_allow_cid = array_unique(array_merge($arr_allow_cid, $in_group));
}
+ //count existing parent folders - we will compare to that count later
$count = 0;
while($folder_hash) {
$x = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid, folder FROM attach WHERE hash = '%s' LIMIT 1",
@@ -1778,30 +1807,20 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny
//only process private folders
if($x[0]['allow_cid'] || $x[0]['allow_gid'] || $x[0]['deny_cid'] || $x[0]['deny_gid']) {
-
$parent_arr['allow_cid'][] = expand_acl($x[0]['allow_cid']);
$parent_arr['allow_gid'][] = expand_acl($x[0]['allow_gid']);
-
- /**
- * @TODO should find a much better solution for the allow_cid <-> allow_gid problem.
- * Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid.
- * */
- if($parent_arr['allow_gid']) {
- foreach($parent_arr['allow_gid'][$count] as $gid) {
- $in_group = group_get_members($gid);
- $parent_arr['allow_cid'][$count] = array_unique(array_merge($parent_arr['allow_cid'][$count], $in_group));
- }
- }
-
$parent_arr['deny_cid'][] = expand_acl($x[0]['deny_cid']);
$parent_arr['deny_gid'][] = expand_acl($x[0]['deny_gid']);
+ //this is the number of all existing parent folders - we will compare to that count later
$count++;
}
$folder_hash = $x[0]['folder'];
}
+ //logger(EOL . 'parent_arr: ' . print_r($parent_arr,true));
+
//if none of the parent folders is private just return file perms
if(!$parent_arr['allow_cid'] && !$parent_arr['allow_gid'] && !$parent_arr['deny_cid'] && !$parent_arr['deny_gid']) {
$ret['allow_gid'] = $arr_allow_gid;
@@ -1812,7 +1831,7 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny
return $ret;
}
- //if there are no perms on the file we get them from the first parent folder
+ //if there are no perms on the file we will work with the perms from the first parent folder
if(!$arr_allow_cid && !$arr_allow_gid && !$arr_deny_cid && !$arr_deny_gid) {
$arr_allow_cid = $parent_arr['allow_cid'][0];
$arr_allow_gid = $parent_arr['allow_gid'][0];
@@ -1820,52 +1839,83 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny
$arr_deny_gid = $parent_arr['deny_gid'][0];
}
- //allow_cid
- $r_arr_allow_cid = false;
- foreach ($parent_arr['allow_cid'] as $folder_arr_allow_cid) {
- foreach ($folder_arr_allow_cid as $ac_hash) {
- $count_values[$ac_hash]++;
+
+ /***
+ *
+ * check if sharee has perms for all parent folders
+ *
+ ***/
+
+ $r_arr_allow_cid = [];
+
+ if($parent_arr['allow_cid']) {
+ //check sharee arr_allow_cid against allow_cid of all parent folders
+ foreach($parent_arr['allow_cid'] as $folder_arr_allow_cid) {
+ foreach($folder_arr_allow_cid as $ac_hash) {
+ $count_values[$ac_hash]++;
+ }
}
- }
- foreach ($arr_allow_cid as $fac_hash) {
- if($count_values[$fac_hash] == $count)
- $r_arr_allow_cid[] = $fac_hash;
+ foreach($arr_allow_cid as $fac_hash) {
+ if($count_values[$fac_hash] == $count)
+ $r_arr_allow_cid[] = $fac_hash;
+ }
+ //logger(EOL . 'r_arr_allow_cid: ' . print_r($r_arr_allow_cid,true));
}
- //allow_gid
- $r_arr_allow_gid = false;
- foreach ($parent_arr['allow_gid'] as $folder_arr_allow_gid) {
- foreach ($folder_arr_allow_gid as $ag_hash) {
- $count_values[$ag_hash]++;
+ if($parent_arr['allow_gid']) {
+ //check sharee arr_allow_cid against members of allow_gid of all parent folders
+ foreach($parent_arr['allow_gid'] as $folder_arr_allow_gid) {
+ //get the group members
+ $folder_arr_allow_cid = expand_groups($folder_arr_allow_gid);
+ foreach($folder_arr_allow_cid as $ac_hash) {
+ $count_values[$ac_hash]++;
+ }
}
- }
- foreach ($arr_allow_gid as $fag_hash) {
- if($count_values[$fag_hash] == $count)
- $r_arr_allow_gid[] = $fag_hash;
+ foreach($arr_allow_cid as $fac_hash) {
+ if($count_values[$fac_hash] == $count)
+ $r_arr_allow_cid[] = $fac_hash;
+ }
+ //logger(EOL . 'groups - r_arr_allow_cid: ' . print_r($r_arr_allow_cid,true));
}
- //deny_gid
- foreach($parent_arr['deny_gid'] as $folder_arr_deny_gid) {
- $r_arr_deny_gid = array_merge($arr_deny_gid, $folder_arr_deny_gid);
- }
- $r_arr_deny_gid = array_unique($r_arr_deny_gid);
+
+ /***
+ *
+ * check if sharee is denied somewhere in parent folders and deny him if so
+ *
+ ***/
//deny_cid
- foreach($parent_arr['deny_cid'] as $folder_arr_deny_cid) {
- $r_arr_deny_cid = array_merge($arr_deny_cid, $folder_arr_deny_cid);
+ $r_arr_deny_cid = [];
+
+ if($parent_arr['deny_cid']) {
+ foreach($parent_arr['deny_cid'] as $folder_arr_deny_cid) {
+ $r_arr_deny_cid = array_merge($arr_deny_cid, $folder_arr_deny_cid);
+ }
+ $r_arr_deny_cid = array_unique($r_arr_deny_cid);
+ //logger(EOL . 'r_arr_deny_cid: ' . print_r($r_arr_deny_cid,true));
}
- $r_arr_deny_cid = array_unique($r_arr_deny_cid);
- //if none is allowed restrict to self
- if(($r_arr_allow_gid === false) && ($r_arr_allow_cid === false)) {
- $ret['allow_cid'] = $poster['xchan_hash'];
- } else {
- $ret['allow_gid'] = $r_arr_allow_gid;
- $ret['allow_cid'] = $r_arr_allow_cid;
- $ret['deny_gid'] = $r_arr_deny_gid;
- $ret['deny_cid'] = $r_arr_deny_cid;
+ //deny_gid
+ $r_arr_deny_gid = [];
+
+ if($parent_arr['deny_cid']) {
+ foreach($parent_arr['deny_gid'] as $folder_arr_deny_gid) {
+ $r_arr_deny_gid = array_merge($arr_deny_gid, $folder_arr_deny_gid);
+ }
+ $r_arr_deny_gid = array_unique($r_arr_deny_gid);
+ //logger(EOL . 'r_arr_deny_gid: ' . print_r($r_arr_dr_arr_deny_gideny_cid,true));
}
+ //if no channel is allowed return false
+ if(! $r_arr_allow_cid)
+ return false;
+
+ $ret['allow_gid'] = []; // eventual group members are already collected in $r_arr_allow_cid
+ $ret['allow_cid'] = $r_arr_allow_cid;
+ $ret['deny_gid'] = $r_arr_deny_gid;
+ $ret['deny_cid'] = $r_arr_deny_cid;
+
return $ret;
}
@@ -2196,10 +2246,23 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
intval($r[0]['id'])
);
+
+ $x = attach_syspaths($channel_id,$resource_id);
+
+ $t1 = q("update attach set os_path = '%s', display_path = '%s' where id = %d",
+ dbesc($x['os_path']),
+ dbesc($x['path']),
+ intval($r[0]['id'])
+ );
+
+
if($r[0]['is_photo']) {
- $t = q("update photo set album = '%s', filename = '%s' where resource_id = '%s' and uid = %d",
+ $t = q("update photo set album = '%s', filename = '%s', os_path = '%s', display_path = '%s'
+ where resource_id = '%s' and uid = %d",
dbesc($newdirname),
dbesc($filename),
+ dbesc($x['os_path']),
+ dbesc($x['path']),
dbesc($resource_id),
intval($channel_id)
);
@@ -2227,8 +2290,9 @@ function attach_folder_select_list($channel_id) {
if($r) {
foreach($r as $rv) {
$x = attach_folder_rpaths($r,$rv);
- if($x)
+ if($x) {
$out[$x[0]] = $x[1];
+ }
}
}
@@ -2250,7 +2314,6 @@ function attach_folder_rpaths($all_folders,$that_folder) {
continue;
if($selected['hash'] == $parent_hash) {
$path = '/' . $selected['filename'] . $path;
- $current_hash = $selected['hash'];
$parent_hash = $selected['folder'];
$found = true;
break;
@@ -2264,3 +2327,155 @@ function attach_folder_rpaths($all_folders,$that_folder) {
return (($error) ? false : [ $current_hash , $path ]);
}
+
+
+function attach_syspaths($channel_id,$attach_hash) {
+
+ $os_path = '';
+ $path = '';
+ do {
+
+ $r = q("select folder, filename, hash from attach where hash = '%s' and uid = %d",
+ dbesc($attach_hash),
+ intval($channel_id)
+ );
+ if(! $r)
+ break;
+
+ $os_path = $r[0]['hash'] . (($os_path) ? '/' . $os_path : '');
+ $path = $r[0]['filename'] . (($path) ? '/' . $path : '');
+ $attach_hash = $r[0]['folder'];
+ }
+ while($attach_hash);
+
+ return [ 'os_path' => $os_path, 'path' => $path ];
+
+
+}
+
+
+
+function attach_upgrade() {
+
+ $r = q("select id, uid, hash from attach where os_path = '' and display_path = '' limit 100");
+ if($r) {
+ foreach($r as $rv) {
+ $x = attach_syspaths($rv['uid'],$rv['hash']);
+ if($x) {
+ $w = q("update attach set os_path = '%s', display_path = '%s' where id = %d",
+ dbesc($x['os_path']),
+ dbesc($x['path']),
+ intval($rv['id'])
+ );
+ $y = 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'])
+ );
+ }
+ }
+ }
+}
+
+
+function save_chunk($channel,$start,$end,$len) {
+
+ $result = [];
+
+ $tmp_path = $_FILES['files']['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'];
+
+ if(! file_exists($new_path)) {
+ rename($tmp_path,$new_path);
+ }
+ else {
+ $istream = fopen($tmp_path,'rb');
+ $ostream = fopen($new_path,'ab');
+ if($istream && $ostream) {
+ pipe_streams($istream,$ostream);
+ fclose($istream);
+ fclose($ostream);
+ }
+ }
+ if(($len - 1) == $end) {
+ unlink($tmp_path);
+ $result['name'] = $_FILES['files']['tmp_name'];
+ $result['type'] = $_FILES['files']['type'];
+ $result['tmp_name'] = $new_path;
+ $result['error'] = 0;
+ $result['size'] = $len;
+ $result['complete'] = true;
+ return $result;
+ }
+ $result['partial'] = true;
+ $result['length'] = intval(filesize($new_path));
+ return $result;
+}
+
+
+/*
+ * chunkloader
+ * Submit handler for chunked uploads
+ *
+ */
+
+function chunkloader($channel,$arr) {
+
+ logger('request: ' . print_r($arr,true), LOGGER_DEBUG);
+ logger('files: ' . print_r($_FILES,true), LOGGER_DEBUG);
+
+
+ $result = [];
+
+
+ $tmp_path = $_FILES['file']['tmp_name'];
+ $new_base = 'store/[data]/' . $channel['channel_address'] . '/tmp';
+ os_mkdir($new_base,STORAGE_DEFAULT_PERMISSIONS,true);
+
+ $new_path = $new_base . '/' . $arr['resumableFilename'];
+
+ rename($tmp_path,$new_path . '.' . intval($arr['resumableChunkNumber']));
+
+ $missing_parts = false;
+ for($x = 1; $x <= intval($arr['resumableTotalChunks']); $x ++) {
+ if(! file_exists($new_path . '.' . $x)) {
+ $missing_parts = true;
+ break;
+ }
+ }
+
+ if($missing_parts) {
+ $result['partial'] = true;
+ return $result;
+ }
+
+ if(intval($arr['resumableTotalChunks']) === 1) {
+ rename($new_path . '.' . '1', $new_path);
+ }
+ else {
+ for($x = 1; $x <= intval($arr['resumableTotalChunks']); $x ++) {
+ $istream = fopen($new_path . '.' . $x,'rb');
+ $ostream = fopen($new_path,'ab');
+ if($istream && $ostream) {
+ pipe_streams($istream,$ostream);
+ fclose($istream);
+ fclose($ostream);
+ }
+ unlink($new_path . '.' . $x);
+ }
+ }
+
+ $result['name'] = $arr['resumableFilename'];
+ $result['type'] = $arr['resumableType'];
+ $result['tmp_name'] = $new_path;
+ $result['error'] = 0;
+ $result['size'] = $arr['resumableTotalSize'];
+ $result['complete'] = true;
+ return $result;
+
+}
+