streams/mod/filestorage.php

154 lines
4.2 KiB
PHP
Raw Normal View History

2013-09-09 01:06:21 +00:00
<?php
/**
* @file mod/filestorage.php
*
*/
2013-09-09 01:06:21 +00:00
require_once('include/attach.php');
/**
*
* @param object &$a
*/
function filestorage_post(&$a) {
$channel_id = ((x($_POST, 'uid')) ? intval($_POST['uid']) : 0);
if((! $channel_id) || (! local_user()) || ($channel_id != local_user())) {
notice( t('Permission denied.') . EOL);
return;
}
$recurse = ((x($_POST, 'recurse')) ? intval($_POST['recurse']) : 0);
$resource = ((x($_POST, 'filehash')) ? notags($_POST['filehash']) : '');
if(! $resource) {
notice(t('Item not found.') . EOL);
return;
}
$str_group_allow = perms2str($_REQUEST['group_allow']);
$str_contact_allow = perms2str($_REQUEST['contact_allow']);
$str_group_deny = perms2str($_REQUEST['group_deny']);
$str_contact_deny = perms2str($_REQUEST['contact_deny']);
attach_change_permissions($channel_id, $resource, $str_contact_allow, $str_group_allow, $str_contact_deny,$str_group_deny, $recurse = false);
//Build directory tree and redirect
$channel = $a->get_channel();
$cloudPath = get_parent_cloudpath($channel_id, $channel['channel_address'], $resource);
goaway($cloudPath);
}
2013-09-09 01:06:21 +00:00
function filestorage_content(&$a) {
if(argc() > 1)
$which = argv(1);
else {
notice( t('Requested profile is not available.') . EOL );
$a->error = 404;
return;
}
$r = q("select * from channel where channel_address = '%s'",
dbesc($which)
);
if($r) {
$channel = $r[0];
$owner = intval($r[0]['channel_id']);
2013-09-09 01:06:21 +00:00
}
$observer = $a->get_observer();
$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
$perms = get_all_perms($owner, $ob_hash);
if(! $perms['view_storage']) {
notice( t('Permission denied.') . EOL);
return;
}
// Since we have ACL'd files in the wild, but don't have ACL here yet, we
// need to return for anyone other than the owner, despite the perms check for now.
2013-09-09 01:06:21 +00:00
$is_owner = (((local_user()) && ($owner == local_user())) ? true : false);
if(! $is_owner) {
info( t('Permission Denied.') . EOL );
return;
2013-09-09 01:06:21 +00:00
}
if(argc() > 3 && argv(3) === 'delete') {
if(! $perms['write_storage']) {
notice( t('Permission denied.') . EOL);
return;
}
$file = intval(argv(2));
$r = q("SELECT hash FROM attach WHERE id = %d AND uid = %d LIMIT 1",
2013-09-09 01:06:21 +00:00
dbesc($file),
intval($owner)
);
2014-01-08 08:03:01 +00:00
if(! $r) {
notice( t('File not found.') . EOL);
goaway(z_root() . '/cloud/' . $which);
2014-01-08 08:03:01 +00:00
}
$f = $r[0];
$channel = $a->get_channel();
$parentpath = get_parent_cloudpath($channel['channel_id'], $channel['channel_address'], $f['hash']);
2013-09-09 01:06:21 +00:00
attach_delete($owner, $f['hash']);
goaway($parentpath);
}
2013-09-09 01:06:21 +00:00
if(argc() > 3 && argv(3) === 'edit') {
require_once('include/acl_selectors.php');
if(! $perms['write_storage']) {
notice( t('Permission denied.') . EOL);
return;
}
$file = intval(argv(2));
$r = q("select id, uid, folder, filename, revision, flags, hash, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and uid = %d limit 1",
intval($file),
intval($owner)
);
$f = $r[0];
$channel = $a->get_channel();
$cloudpath = get_cloudpath($f) . (($f['flags'] & ATTACH_FLAG_DIR) ? '?f=&davguest=1' : '');
$parentpath = get_parent_cloudpath($channel['channel_id'], $channel['channel_address'], $f['hash']);
$aclselect_e = populate_acl($f, false);
$is_a_dir = (($f['flags'] & ATTACH_FLAG_DIR) ? true : false);
$lockstate = (($f['allow_cid'] || $f['allow_gid'] || $f['deny_cid'] || $f['deny_gid']) ? 'lock' : 'unlock');
$o = replace_macros(get_markup_template('attach_edit.tpl'), array(
'$header' => t('Edit file permissions'),
'$file' => $f,
'$cloudpath' => z_root() . '/' . $cloudpath,
'$parentpath' => $parentpath,
'$uid' => $channel['channel_id'],
'$channelnick' => $channel['channel_address'],
'$permissions' => t('Permissions'),
'$aclselect' => $aclselect_e,
'$lockstate' => $lockstate,
'$permset' => t('Set/edit permissions'),
'$recurse' => t('Include all files and sub folders'),
'$backlink' => t('Return to file list'),
'$isadir' => $is_a_dir,
2014-01-07 03:43:54 +00:00
'$cpdesc' => t('Copy/paste this code to attach file to a post'),
'$cpldesc' => t('Copy/paste this URL to link file from a web page'),
'$submit' => t('Submit')
));
return $o;
}
goaway(z_root() . '/cloud/' . $which);
2013-09-09 01:06:21 +00:00
}