aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-11-03 20:55:58 -0800
committerfriendica <info@friendica.com>2013-11-03 20:55:58 -0800
commitd783183572d26585983959564a1b38b6e63b95ff (patch)
treec2eb61b4b2af65c2c417c0a9e9c043c73c5bbc9b /include/attach.php
parenta966e53ee40316792efa9926deb740ee736fbc21 (diff)
downloadvolse-hubzilla-d783183572d26585983959564a1b38b6e63b95ff.tar.gz
volse-hubzilla-d783183572d26585983959564a1b38b6e63b95ff.tar.bz2
volse-hubzilla-d783183572d26585983959564a1b38b6e63b95ff.zip
add attach_mkdir()
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/include/attach.php b/include/attach.php
index da08154c6..152489179 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -500,4 +500,75 @@ function z_readdir($channel_id,$observer_hash,$pathname, $parent_hash = '') {
$ret['success'] = true;
$ret['data'] = $r;
return $ret;
+}
+
+
+/**
+ * @function attach_mkdir($channel,$observer_hash,$arr);
+ *
+ * Create directory
+ *
+ * @param $channel channel array of owner
+ * @param $observer_hash hash of current observer
+ * @param $arr parameter array to fulfil request
+ *
+ * Required:
+ * $arr['filename']
+ * $arr['folder'] // hash of parent directory, empty string for root directory
+ *
+ * Optional:
+ * $arr['hash'] // precumputed hash for this node
+ * $arr['allow_cid']
+ * $arr['allow_gid']
+ * $arr['deny_cid']
+ * $arr['deny_gid']
+ */
+
+function attach_mkdir($channel,$observer_hash,$arr = null) {
+
+ $ret = array('success' => false);
+ $channel_id = $channel['channel_id'];
+ $sql_options = '';
+
+ if(! perm_is_allowed($channel_id,get_observer_hash(),'write_storage')) {
+ $ret['message'] = t('Permission denied.');
+ return $ret;
+ }
+
+ // Walk the directory tree from root to parent to make sure the parent is valid and name is unique.
+ // FIXME
+
+
+ $arr['hash'] = (($arr['hash']) ? $arr['hash'] : random_string());
+ $created = datetime_convert();
+
+ $r = q("INSERT INTO attach ( aid, uid, hash, filename, filetype, filesize, revision, folder, flags, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
+ VALUES ( %d, %d, '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ intval($channel['channel_account_id']),
+ intval($channel_id),
+ dbesc($arr['hash']),
+ dbesc($arr['filename']),
+ dbesc('multipart/mixed'),
+ intval(0),
+ intval(0),
+ dbesc($arr['folder']),
+ intval(ATTACH_FLAGS_DIR),
+ dbesc(''),
+ dbesc($created),
+ dbesc($created),
+ dbesc(($arr && array_key_exists('allow_cid',$arr)) ? $arr['allow_cid'] : '<' . $channel['channel_hash'] . '>'),
+ dbesc(($arr && array_key_exists('allow_gid',$arr)) ? $arr['allow_gid'] : ''),
+ dbesc(($arr && array_key_exists('deny_cid',$arr)) ? $arr['deny_cid'] : ''),
+ dbesc(($arr && array_key_exists('deny_gid',$arr)) ? $arr['deny_gid'] : '')
+ );
+
+ if(! $r)
+ $ret['message'] = t('database storage failed.');
+ else {
+ $ret['success'] = true;
+ $ret['data'] = $arr;
+ }
+
+ return $ret;
+
} \ No newline at end of file