1 image.module image_style_save_allowed_uris()

Shutdown callback used to save the whitelist of requested image styles.

See also

image_style_add_allowed_uri()

File

core/modules/image/image.module, line 1036
Exposes global functionality for creating image styles.

Code

function image_style_save_allowed_uris() {
  $added_uris = &image_style_add_allowed_uri();

  // This is not a blocking lock. If the lock is not acquired immediately, it is
  // not worth making the page wait. Instead images will be generated using the
  // throttled mode, or another page request will update the whitelist.
  if (count($added_uris) && lock_acquire('image_style_allowed_uris')) {
    $allowed_uris = (array) tempstore_get('image_style_allowed_uris', 'list');
    $allowed_uris = array_filter(array_merge($allowed_uris, $added_uris));

    // The tempstore record is only set for 60 seconds, which is plenty for the
    // browser to make the image request. Tempstore is only cleared out on cron
    // jobs, so this may persist quite a bit longer than 60 seconds.
    if ($allowed_uris) {
      tempstore_set('image_style_allowed_uris', 'list', $allowed_uris, REQUEST_TIME + 60);
    }
    else {
      tempstore_clear('image_style_allowed_uris', 'list');
    }
    lock_release('image_style_allowed_uris');
    $added_uris = array();
  }
}