コード例 #1
0
ファイル: locking.php プロジェクト: pleio/odt_editor
/**
 * @param ElggFile $file
 * @return bool
 */
function odt_editor_locking_is_locked($file)
{
    // do not lock file if the editor is the same
    if (odt_editor_locking_lock_owner_guid($file) == elgg_get_logged_in_user_guid()) {
        return false;
    }
    // 15 secs longer than lock refresh cycle, to avoid race conditions
    $odt_editor_locking_lock_validity_duration = 5 * 60 + 15;
    // in seconds
    return $file->getPrivateSetting('odt_editor_lock_time') && $file->getPrivateSetting('odt_editor_lock_time') + $odt_editor_locking_lock_validity_duration >= time();
}
コード例 #2
0
ファイル: refresh_filelock.php プロジェクト: pleio/odt_editor
    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
if (odt_editor_locking_lock_guid($file) != $lock_guid) {
    $lock_owner_guid = odt_editor_locking_lock_owner_guid($file);
    if ($lock_owner_guid != $user_guid) {
        $locking_user = get_entity($lock_owner_guid);
        $locking_user_name = $locking_user ? $locking_user->name : elgg_echo("odt_editor:unknown_user");
        register_error(elgg_echo('odt_editor:lock_lost_to', array($locking_user_name)));
    } else {
        register_error(elgg_echo('odt_editor:lock_lost_to_self'));
    }
    forward(REFERER);
}
// update lock time
if ($lock_set == 1) {
    odt_editor_locking_update_lock($file);
} else {
    odt_editor_locking_remove_lock($file);
}
コード例 #3
0
ファイル: upload_asnew.php プロジェクト: smellems/odt_editor
$file->title = $title;
$file->access_id = $access_id;
$file->description = $description;
$file->container_guid = $container_guid;
$file->tags = $tags;
$file->setMimeType("application/vnd.oasis.opendocument.text");
$file->simpletype = "document";
// same naming pattern as in file/actions/file/upload.php
$filestorename = "file/" . elgg_strtolower(time() . $_FILES['upload']['name']);
$file->setFilename($filestorename);
// Open the file to guarantee the directory exists
$file->open("write");
$file->close();
// now put file into destination
move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore());
// create lock
$lock_guid = odt_editor_locking_create_lock($file, $user_guid);
$file->save();
// log success
system_message(elgg_echo("file:saved"));
add_to_river('river/object/file/create', 'create', $user_guid, $file->guid);
// reply to client
$reply = array("file_guid" => $file->guid, "document_url" => elgg_get_site_url() . "file/download/{$file->uid}", "file_name" => $file->getFilename(), "lock_guid" => $lock_guid);
print json_encode($reply);
// remove lock from old file
if ($old_file_guid != 0) {
    $old_file = new ElggFile($old_file_guid);
    if ($old_file && odt_editor_locking_lock_guid($old_file) == $old_lock_guid && odt_editor_locking_lock_owner_guid($old_file) == $user_guid) {
        odt_editor_locking_remove_lock($old_file);
    }
}
コード例 #4
0
ファイル: odt_editor.php プロジェクト: smellems/odt_editor
    $edit_mode = "readwrite";
} else {
    $file = get_entity($file_guid);
    // TODO: is there a way to get the original filename when uploaded?
    $file_name = $file->getFilename();
    $user_guid = elgg_get_logged_in_user_guid();
    $edit_mode = "readonly";
    if ($file->canEdit()) {
        // 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);
        }
        // currently locked?
        if (odt_editor_locking_is_locked($file)) {
            $locking_user = get_entity(odt_editor_locking_lock_owner_guid($file));
            $locking_user_name = $locking_user ? $locking_user->name : elgg_echo("odt_editor:unknown_user");
            system_message(elgg_echo("odt_editor:document_locked_by", array($locking_user_name)));
        } else {
            $lock_guid = odt_editor_locking_create_lock($file, $user_guid);
            if ($file->save()) {
                $edit_mode = "readwrite";
            } else {
                register_error(elgg_echo("odt_editor:error:cannotwritelock"));
            }
        }
    } else {
        system_message(elgg_echo("odt_editor:read_only"));
    }
    $title = $file->title;
    $container_guid = $file->container_guid;