You are here

function event_node_import_prepare in Node import 5

Implementation of hook_node_import_prepare().

File

supported/event.inc, line 35

Code

function event_node_import_prepare(&$node, $preview = FALSE) {
  if (!event_is_enabled($node->type)) {
    return;
  }
  $errors = array();
  foreach (array(
    'start',
    'end',
  ) as $what) {
    $whatdate = 'node_import_event_' . $what;

    // Hard code a default date since event module seems to break if you don't
    if (!isset($node->{$what . '_year'})) {
      $node->{$what . '_year'} = 1970;
    }
    if (!isset($node->{$what . '_month'})) {
      $node->{$what . '_month'} = 1;
    }
    if (!isset($node->{$what . '_day'})) {
      $node->{$what . '_day'} = 1;
    }
    if (!isset($node->{$what . '_hour'})) {
      $node->{$what . '_hour'} = 0;
    }
    if (!isset($node->{$what . '_minute'})) {
      $node->{$what . '_minute'} = 0;
    }
    if (isset($node->{$whatdate})) {
      if (($time = node_import_valid_date($node->{$whatdate})) > -1) {
        $node->{$what . '_year'} = date('Y', $time);
        $node->{$what . '_month'} = date('n', $time);
        $node->{$what . '_day'} = date('d', $time);
        $node->{$what . '_hour'} = date('H', $time);
        $node->{$what . '_minute'} = date('i', $time);
      }
      unset($node->{$whatdate});
    }
    if (module_exists('jscalendar')) {

      // jscalendar.module supplies $node->{$what.'_date'} and event.module
      // always uses that when jscalendar is enabled. So we need to set
      // it. The format is: YYYY.MM.DD.hh.mm.ss (where dots are ignored).
      $parts = array(
        $node->{$what . '_year'},
        $node->{$what . '_month'},
        $node->{$what . '_day'},
        $node->{$what . '_hour'},
        $node->{$what . '_minute'},
        "00",
      );
      $node->{$what . '_date'} = implode(' ', $parts);
    }
  }

  // Let event module add proper event related fields on the basis of the above
  event_nodeapi($node, 'submit');
  return $errors;
}