aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-12-10 15:25:44 -0800
committerzotlabs <mike@macgirvin.com>2017-12-10 15:25:44 -0800
commit27bc5fa4b0f66c47f668c6c6efda77f9732bb603 (patch)
treec94bddd5f8600508a3cf8008c2d8f98d879533ee /include
parentad6cb63e0762a3af3ee0340bd3df80e482c977ef (diff)
downloadvolse-hubzilla-27bc5fa4b0f66c47f668c6c6efda77f9732bb603.tar.gz
volse-hubzilla-27bc5fa4b0f66c47f668c6c6efda77f9732bb603.tar.bz2
volse-hubzilla-27bc5fa4b0f66c47f668c6c6efda77f9732bb603.zip
improvements to file import/export
Diffstat (limited to 'include')
-rw-r--r--include/api_zot.php11
-rw-r--r--include/attach.php22
-rw-r--r--include/import.php37
3 files changed, 59 insertions, 11 deletions
diff --git a/include/api_zot.php b/include/api_zot.php
index aaa9ee497..54f905b4c 100644
--- a/include/api_zot.php
+++ b/include/api_zot.php
@@ -150,7 +150,11 @@
$start = ((array_key_exists('start',$_REQUEST)) ? intval($_REQUEST['start']) : 0);
$records = ((array_key_exists('records',$_REQUEST)) ? intval($_REQUEST['records']) : 0);
- $x = attach_list_files(api_user(),get_observer_hash(),$hash,$filename,$filetype,'created asc',$start,$records);
+ $since = ((array_key_exists('since',$_REQUEST)) ? datetime_convert(date_default_timezone_get(),'UTC',$_REQUEST['since']) : NULL_DATE);
+ $until = ((array_key_exists('until',$_REQUEST)) ? datetime_convert(date_default_timezone_get(),'UTC',$_REQUEST['until']) : datetime_convert());
+
+ $x = attach_list_files(api_user(),get_observer_hash(),$hash,$filename,$filetype,'created asc',$start,$records, $since, $until);
+
if($start || $records) {
$x['start'] = $start;
$x['records'] = count($x['results']);
@@ -226,7 +230,10 @@
if(! $_REQUEST['file_id'])
return false;
- $ret = attach_export_data(api_user(),$_REQUEST['file_id']);
+ $channel = channelx_by_n(api_user());
+
+ $ret = attach_export_data($channel,$_REQUEST['file_id']);
+
if($ret) {
json_return_and_die($ret);
}
diff --git a/include/attach.php b/include/attach.php
index 3a802bd11..4b8841a88 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -189,7 +189,7 @@ function attach_count_files($channel_id, $observer, $hash = '', $filename = '',
* * \e array|boolean \b results array with results, or false
* * \e string \b message with error messages if any
*/
-function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $filetype = '', $orderby = 'created desc', $start = 0, $entries = 0) {
+function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $filetype = '', $orderby = 'created desc', $start = 0, $entries = 0, $since = '', $until = '') {
$ret = array('success' => false);
@@ -198,6 +198,7 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $
return $ret;
}
+
require_once('include/security.php');
$sql_extra = permissions_sql($channel_id);
@@ -213,14 +214,22 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $
if($entries)
$limit = " limit " . intval($start) . ", " . intval($entries) . " ";
- // Retrieve all columns except 'data'
+ if(! $since)
+ $since = NULL_DATE;
+
+ if(! $until)
+ $until = datetime_convert();
+
+ $sql_extra .= " and created >= '" . dbesc($since) . "' and created <= '" . dbesc($until) . "' ";
+
+ // Retrieve all columns except 'content'
$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)
);
$ret['success'] = ((is_array($r)) ? true : false);
- $ret['results'] = ((is_array($r)) ? $r : false);
+ $ret['results'] = ((is_array($r)) ? $r : []);
return $ret;
}
@@ -2052,14 +2061,13 @@ function attach_export_data($channel, $resource_id, $deleted = false) {
if($attach_ptr['is_photo']) {
- $r = q("select * from photo where resource_id = '%s' and uid = %d order by imgscale asc",
+
+ $r = q("select aid,uid,xchan,resource_id,created,edited,title,description,album,filename,mimetype,height,width,filesize,imgscale,photo_usage,profile,is_nsfw,os_storage,display_path,photo_flags,allow_cid,allow_gid,deny_cid,deny_gid from photo where resource_id = '%s' and uid = %d order by imgscale asc",
dbesc($resource_id),
intval($channel['channel_id'])
);
+
if($r) {
- for($x = 0; $x < count($r); $x ++) {
- $r[$x]['content'] = base64_encode(dbunescbin($r[$x]['content']));
- }
$ret['photo'] = $r;
}
diff --git a/include/import.php b/include/import.php
index cd7056497..a5e8adeb5 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1263,10 +1263,43 @@ function sync_files($channel, $files) {
);
}
- if($p['imgscale'] === 0 && $p['os_storage'])
+ if(intval($p['imgscale']) === 0 && $p['os_storage'])
$p['content'] = $store_path;
else
- $p['content'] = base64_decode($p['content']);
+ $p['content'] = (($p['content'])? base64_decode($p['content']) : '');
+
+ if(intval($p['imgscale']) && (! $p['content'])) {
+
+ $time = datetime_convert();
+
+ $parr = array('hash' => $channel['channel_hash'],
+ 'time' => $time,
+ 'resource' => $att['hash'],
+ 'revision' => 0,
+ 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])),
+ 'resolution' => $p['imgscale']
+ );
+
+ $stored_image = $newfname . '-' . intval($p['imgscale']);
+
+ $fp = fopen($stored_image,'w');
+ if(! $fp) {
+ logger('failed to open storage file.',LOGGER_NORMAL,LOG_ERR);
+ continue;
+ }
+ $redirects = 0;
+
+
+ $headers = [];
+ $headers['Accept'] = 'application/x-zot+json' ;
+ $headers['Sigtoken'] = random_string();
+ $headers = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'], 'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,true,'sha512');
+
+ $x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]);
+ fclose($fp);
+ $p['content'] = file_get_contents($stored_image);
+ unlink($stored_image);
+ }
if(!isset($p['display_path']))
$p['display_path'] = '';