You are here

function epsacrop_nodeapi in EPSA Crop - Image Cropping 6.2

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

File

./epsacrop.module, line 127
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);
        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 (strcmp(serialize($coord), serialize($previous_data[$fid])) == 0) {
            continue;
          }
          _epsacrop_update_file($fid, $coord, $node->nid);
        }
      }
      break;
    case 'load':
      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;
  }
}