You are here

function autosave_autosave_prevent_alter in Autosave 7.2

Implements hook_autosave_prevent_alter().

File

./autosave.module, line 419
Does background saves of node being edited.

Code

function autosave_autosave_prevent_alter(&$prevent_autosave) {

  // TODO: Do something clever for not just node forms.
  global $user;
  $path = $_POST['autosave_form_path'];
  $path_args = explode("/", $path);

  // 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
  if ($path_args[0] == 'node') {

    // update case
    if ($path_args[2] == 'edit' && is_numeric($path_args[1])) {
      $submitted = node_load($path_args[1]);
    }
    elseif ($path_args[1] == 'add') {

      // add case
      $submitted = db_query_range("SELECT created AS changed FROM {node} WHERE uid = :uid and type = :type ORDER BY created DESC", 0, 1, array(
        ':uid' => $user->uid,
        ':type' => str_replace("-", "_", $path_args[2]),
      ))
        ->fetchObject();
    }
    $prevent_autosave = $submitted && REQUEST_TIME - $submitted->changed < variable_get('autosave_period', 10) ? TRUE : $prevent_autosave;
  }
}