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 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);
$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); } }