Esempio n. 1
0
function pleio_api_delete_file($file_id)
{
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    if ($file_id && $user_id) {
        if (strlen($file_id) != 32) {
            $file = new ElggFile($file_id);
            if ($file && $file->guid && $file->canEdit($user_id) && $file->delete()) {
                return new SuccessResult(elgg_echo("file:deleted"));
            }
        } else {
            $url = pleio_api_swordfish_baseurl() . "delete-file?id=" . $file_id;
            $swordfish_name = pleio_api_swordfish_username($user->username);
            $result = pleio_api_call_swordfish_api($swordfish_name, $url, "POST");
            if ($result->ok) {
                return new SuccessResult(elgg_echo("file:deleted"));
            }
        }
    }
    return new ErrorResult(elgg_echo("file:deletefailed"));
}
Esempio n. 2
0
elgg_load_library('odt_editor:locking');
// Get variables
$file_guid = (int) get_input('file_guid');
$lock_guid = get_input('lock_guid');
$lock_set = (int) get_input('lock_set') == 1;
$user_guid = elgg_get_logged_in_user_guid();
// load original file object
$file = new ElggFile($file_guid);
if (!$file) {
    if ($lock) {
        register_error(elgg_echo('odt_editor:error:file_removed'));
    }
    forward(REFERER);
}
// user must be able to edit file
if (!$file->canEdit()) {
    register_error(elgg_echo('You do no longer have write access to the file that is edited.'));
    forward(REFERER);
}
// save folder guid in parameter to make sure file_tools_object_handler does not overwrite the relationship
$relationships = get_entity_relationships($file->guid, FILE_TOOLS_RELATIONSHIP, true);
if (elgg_is_active_plugin('file_tools') && count($relationships) > 0) {
    set_input('folder_guid', $relationships[0]->guid_one);
}
// recreate lock, user closed window but cancelled
if ($lock_set && !odt_editor_locking_is_locked($file)) {
    trigger_error("Restored lock", E_USER_WARNING);
    odt_editor_locking_create_lock($file, $user_guid, $lock_guid);
    forward(REFERER);
}
// check for lost lock
Esempio n. 3
0
    if (isset($params->container_guid)) {
        $container = get_entity($params->container_guid);
    } else {
        $container = elgg_get_logged_in_user_entity();
    }
}
if (!$container instanceof ElggEntity) {
    register_error(elgg_echo('images:error:not_found'));
    forward(REFERRER);
}
if (!$entity) {
    $entity = new ElggFile();
    $entity->subtype = 'file';
    $entity->container_guid = $container ? $container->guid : elgg_get_logged_in_user_guid();
}
if (!$entity->canEdit() || !$container->canWriteToContainer(0, $entity->getType(), $entity->getSubtype())) {
    register_error(elgg_echo('images:error:permission_denied'));
    forward(REFERRER);
}
$entity = images()->createFromUpload('upload', $entity);
if (!$entity) {
    register_error(elgg_echo('images:upload:error:invalid_file'));
    forward(REFERRER);
}
$entity->title = $params->title;
$entity->description = $params->description;
$entity->tags = string_to_tag_array((string) $params->tags);
$entity->access_id = isset($params->access_id) ? $params->access_id : get_default_access();
if ($entity->save()) {
    if (elgg_is_xhr()) {
        echo json_encode($entity->toObject());