aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-01-30 17:27:32 -0800
committerfriendica <info@friendica.com>2013-01-30 17:27:32 -0800
commit3767bba3c3669b6e882139abfaa3553db61d1474 (patch)
tree5d2b662c62b42027d64292b6229edecdb2dd782b /include
parente270bd3874bb4526138cc06cd26e2a1153778894 (diff)
downloadvolse-hubzilla-3767bba3c3669b6e882139abfaa3553db61d1474.tar.gz
volse-hubzilla-3767bba3c3669b6e882139abfaa3553db61d1474.tar.bz2
volse-hubzilla-3767bba3c3669b6e882139abfaa3553db61d1474.zip
beginning of backend file/attachment api
Diffstat (limited to 'include')
-rw-r--r--include/attach.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/attach.php b/include/attach.php
index 6d611cec0..61514bb51 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -81,3 +81,71 @@ function z_mime_content_type($filename) {
}
}
+
+
+function attach_count_files($channel_id, $observer, $hash = '', $filename = '', $filetype = '') {
+
+ $ret = array('success' => false);
+
+ if(! perm_is_allowed($channel_id,$observer, 'read_storage')) {
+ $ret['message'] = t('Permission denied.');
+ return $ret;
+ }
+
+ require_once('include/security.php');
+ $sql_extra = permissions_sql($channel_id);
+
+ if($hash)
+ $sql_extra .= protect_sprintf(" and hash = '" . dbesc($hash) . "' ");
+
+ if($filename)
+ $sql_extra .= protect_sprintf(" and filename like '@" . dbesc($filename) . "@' ");
+
+ if($filetype)
+ $sql_extra .= protect_sprintf(" and filetype like '@" . dbesc($filetype) . "@' ");
+
+ $r = q("select id from attach where channel_id = %d $sql_extra",
+ intval($channel_id)
+ );
+
+ $ret['success'] = ((is_array($r)) ? true : false);
+ $ret['results'] = ((is_array($r)) ? count($r) : false);
+ return $ret;
+
+}
+
+function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $filetype = '', $orderby = 'created desc', $start = 0, $entries = 0) {
+
+ $ret = array('success' => false);
+
+ if(! perm_is_allowed($channel_id,$observer, 'read_storage')) {
+ $ret['message'] = t('Permission denied.');
+ return $ret;
+ }
+
+ require_once('include/security.php');
+ $sql_extra = permissions_sql($channel_id);
+
+ if($hash)
+ $sql_extra .= protect_sprintf(" and hash = '" . dbesc($hash) . "' ");
+
+ if($filename)
+ $sql_extra .= protect_sprintf(" and filename like '@" . dbesc($filename) . "@' ");
+
+ if($filetype)
+ $sql_extra .= protect_sprintf(" and filetype like '@" . dbesc($filetype) . "@' ");
+
+ if($entries)
+ $limit = " limit " . intval($start) . ", " . intval(entries) . " ";
+
+ // Retrieve all columns except 'data'
+
+ $r = q("select id, aid, uid, hash, filename, filetype, filesize, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where channel_id = %d $sql_extra $orderby $limit",
+ intval($channel_id)
+ );
+
+ $ret['success'] = ((is_array($r)) ? true : false);
+ $ret['results'] = ((is_array($r)) ? $r : false);
+ return $ret;
+
+}