コード例 #1
0
/**
 *	serve a resource associated with an object
 *
 *	the function might not return (e.g. when a module calls serve_file()).
 *	@param string $s object (e.g. page.rev.obj)
 *	@param bool $dl download file
 *	@return bool
 */
function serve_resource($s, $dl)
{
    load_modules('glue');
    // resolve symlinks
    $ret = object_get_symlink(array('name' => $s));
    if ($ret['#error'] == false && $ret['#data'] !== false) {
        log_msg('debug', 'controller: resolved resource ' . quot($s) . ' into ' . quot($ret['#data']));
        $s = $ret['#data'];
    }
    $obj = load_object(array('name' => $s));
    if ($obj['#error']) {
        return false;
    } else {
        $obj = $obj['#data'];
    }
    $ret = invoke_hook_while('serve_resource', false, array('obj' => $obj, 'dl' => $dl));
    // this is probably not needed as the module will most likely call
    // serve_file() on success, which does not return
    foreach ($ret as $key => $val) {
        if ($val !== false) {
            return true;
        }
    }
    return false;
}
コード例 #2
0
/**
 *	list all objects referencing a certain file in the shared directory
 *
 *	@param array $args arguments
 *		key 'pagename' is the pagename (i.e. page)
 *		key 'file' filename of file in the shared directory
 *		key 'stop_after' n references
 *	@return array response
 *		array of objects (i.e. page.rev.obj)
 */
function upload_references($args)
{
    $revs = revisions($args);
    if ($revs['#error']) {
        return $revs;
    } else {
        $revs = $revs['#data'];
    }
    if (empty($args['file'])) {
        return response('Required argument "file" missing or empty', 400);
    }
    // this is an optimization for delete_upload()
    if (@is_numeric($args['stop_after'])) {
        $stop_after = intval($args['stop_after']);
    } else {
        $stop_after = 0;
    }
    $ret = array();
    // for each revision
    foreach ($revs as $rev) {
        // load all objects
        $files = @scandir(CONTENT_DIR . '/' . $args['pagename'] . '/' . $rev);
        foreach ($files as $f) {
            if ($f == '.' || $f == '..') {
                continue;
            }
            $obj = load_object(array('name' => $args['pagename'] . '.' . $rev . '.' . $f));
            if ($obj['#error']) {
                continue;
            } else {
                $obj = $obj['#data'];
            }
            // and handle the object to our modules
            log_msg('debug', 'upload_references: checking ' . quot($obj['name']));
            $revs = invoke_hook_while('has_reference', false, array('file' => $args['file'], 'obj' => $obj));
            if (count($revs)) {
                $ret[] = $args['pagename'] . '.' . $rev . '.' . $f;
                if (count($ret) == $stop_after) {
                    // return prematurely
                    return response($ret);
                }
            }
        }
    }
    return response($ret);
}