function autosave_save in Autosave 5.3
Same name and namespace in other branches
- 5 autosave.module \autosave_save()
- 5.2 autosave.module \autosave_save()
- 6.2 autosave.module \autosave_save()
- 6 autosave.module \autosave_save()
- 7.2 autosave.module \autosave_save()
- 7 autosave.module \autosave_save()
Menu callback; autosaves the node.
1 string reference to 'autosave_save'
- autosave_menu in ./
autosave.module - Implementation of hook_menu().
File
- ./
autosave.module, line 124 - Automatically saves a node after a period of time.
Code
function autosave_save() {
global $user;
$path = $_POST['q'];
$form_id = $_POST['form_id'];
// Not all variables need to be serialized.
//unset($_POST['form_token'], $_POST['q']);
unset($_POST['q']);
$serialized = serialize($_POST);
// check if node has just been saved - if it has then it's because AS ajax fired off as user was submitting
// if it had just been submitted - no need to AS now
// - easy to figure out if we are submitting an edit to existing node
// - little harder if we have just added a node
$path_args = explode("/", $path);
// update case
if (is_numeric($path_args[1])) {
$submitted = node_load($path_args[1]);
}
else {
// add case
$submitted->changed = db_result(db_query("SELECT created FROM {node} WHERE uid = %d and type = '%s' ORDER BY created DESC LIMIT 1", $user->uid, str_replace("-", "_", $path_args[2])));
}
if (!$submitted || time() - $submitted->changed > 10) {
// Currently, each user can have only one autosave form at a particular path.
db_query("DELETE FROM {autosaved_forms} WHERE form_id = '%s' AND path = '%s' AND uid = %d", $form_id, $path, $user->uid);
db_query("INSERT INTO {autosaved_forms} (form_id, path, uid, timestamp, serialized) VALUES ('%s', '%s', %d, %d, '%s')", $form_id, $path, $user->uid, time(), $serialized);
}
exit;
}