You are here

function node_gallery_api_node_insert in Node Gallery 7

Implements hook_node_insert().

File

./node_gallery_api.module, line 708
Node Gallery module.

Code

function node_gallery_api_node_insert($node) {
  if (in_array($node->type, (array) node_gallery_api_get_types('item'))) {
    $relationships = node_gallery_api_get_relationships(NULL, $node->nid);
    foreach ($relationships as $relationship) {
      $cover_nid = node_gallery_api_get_cover_nid($relationship->ngid);
      if (empty($cover_nid)) {
        node_gallery_api_set_gallery_cover_item($node->nid, $relationship->ngid);
      }
      node_gallery_api_clear_gallery_caches($relationship->ngid);
      node_gallery_api_update_image_counts($relationship->ngid);
    }
    if (isset($node->pluploaded) && $node->pluploaded == TRUE && variable_get('node_gallery_plupload_manage_images_integration', TRUE)) {
      if (!isset($_SESSION['node_gallery_plupload_nids'][$node->ngid])) {
        $_SESSION['node_gallery_plupload_nids'][$node->ngid] = array();
      }
      array_unshift($_SESSION['node_gallery_plupload_nids'][$node->ngid], $node->nid);
    }
  }
  elseif (in_array($node->type, (array) node_gallery_api_get_types('gallery'))) {
    $node->ngid = $node->nid;
    drupal_write_record('node_gallery_galleries', $node);
    node_gallery_api_update_image_counts($node->ngid);
  }
}