You are here

function epsacrop_nodeapi in EPSA Crop - Image Cropping 6

Same name and namespace in other branches
  1. 6.2 epsacrop.module \epsacrop_nodeapi()

File

./epsacrop.module, line 160
The main file of module

Code

function epsacrop_nodeapi(&$node, $op, $a3, $a4) {
  switch ($op) {
    case 'delete':
      _epsacrop_delete($node->nid);
      break;
    case 'insert':
    case 'update':
      if (!empty($node->epsacropcoords)) {
        $coords = json_decode($node->epsacropcoords, TRUE);
        $previous_data = FALSE;
        if ($node->nid) {

          // If node exists (op=update) get previous cropping data.
          $previous_data = _epsacrop_get_coords_from_nid($node->nid);
        }
        foreach ($coords as $fid => $coord) {

          // Skip file update for the files that the cropping area haven't changed for any of the presets.
          if (!empty($previous_data) && strcmp(serialize($coord), serialize($previous_data[$fid])) == 0) {
            continue;
          }
          _epsacrop_update_file($fid, $coord, $node->nid);
        }
      }
      break;
    case 'load':

      // Add this when it required (for example, when editablefields exists)
      if (module_exists('editablefields')) {
        $node->epsacropcoords = _epsacrop_get_coords_from_nid($node->nid) ? json_encode(_epsacrop_get_coords_from_nid($node->nid)) : NULL;
      }
      break;
    case 'prepare':
      if ($node->nid) {
        $node->epsacropcoords = _epsacrop_get_coords_from_nid($node->nid) ? json_encode(_epsacrop_get_coords_from_nid($node->nid)) : NULL;
      }
      break;
  }
}