You are here

function focal_point_save in Focal Point 7

Save the focal point data for a given file.

Parameters

int $fid: The id of the image file in question.

string $focal_point: In the form xx,yy where xx represents the left offset as a percent and yy represents the top offset as a percent.

3 calls to focal_point_save()
focal_point_file_presave in ./focal_point.module
Implements hook_file_presave().
focal_point_migrate_imagefield_focus_data in ./focal_point.install
Convert existing imagefield_focus data to focal point.
_focal_point_images_save in ./focal_point.module
Save the focal point for the provided images.

File

./focal_point.module, line 345

Code

function focal_point_save($fid, $focal_point) {
  $existing_focal_point = focal_point_get($fid);
  $record = array(
    'fid' => $fid,
    'focal_point' => $focal_point,
  );

  // If the focal point has not changed, then there is nothing to see here.
  if ($existing_focal_point == $focal_point) {
    return;
  }

  // Create, update or delete the focal point.
  if ($existing_focal_point) {
    if (!empty($focal_point)) {

      // The focal point has changed to a non-empty value.
      _focal_point_save($record, 'fid');
    }
    else {

      // The focal point has changed to an empty value. Generated images will
      // be flushed in the delete function.
      focal_point_delete($fid);
    }
  }
  elseif (!empty($focal_point)) {

    // The focal point is both new and non-empty.
    _focal_point_save($record);
  }

  // Clear the static caches.
  $cached =& drupal_static('focal_point_get_multiple');
  unset($cached[$fid]);
  entity_get_controller('file')
    ->resetCache(array(
    $fid,
  ));
}