function imageinfo_cache_primer in Imageinfo Cache 6.2
Same name and namespace in other branches
- 6 imageinfo_cache.module \imageinfo_cache_primer()
Run various theme functions so the cache is primed.
Parameters
$values: object File info
$op: string insert or delete
1 call to imageinfo_cache_primer()
- imageinfo_cache_shutdown_async in ./
imageinfo_cache.module - Function that gets called right after a file has been uploaded.
1 string reference to 'imageinfo_cache_primer'
- imageinfo_cache_menu in ./
imageinfo_cache.module - Implements hook_menu().
File
- ./
imageinfo_cache.module, line 442 - Cache image info for theme_imagecache & theme_imagefield_image.
Code
function imageinfo_cache_primer($values = NULL) {
// watchdog('debug', str_replace(' ', ' ', nl2br(htmlentities(print_r($values, TRUE) . print_r($_REQUEST, TRUE)))));
$async = FALSE;
// Exit if key does not match & called with $file not set.
if (is_null($values)) {
if (empty($_POST['key']) || empty($_POST['files'])) {
return;
}
$key = variable_get('imageinfo_cache_url_key', md5(drupal_get_private_key()));
if ($key != $_POST['key']) {
return;
}
else {
// Break connection so processing is async. Return key given to calling url.
httprl_background_processing(check_plain($_POST['key']));
$async = TRUE;
}
$values = array();
// $_POST['files'] is trusted because the key matches.
$values['files'] = $_POST['files'];
}
// Process every file.
foreach ($values['files'] as $file) {
$file = (object) $file;
// Skip if we do not have a file ID or filepath.
if (empty($file->fid) || !is_numeric($file->fid) || empty($file->filepath)) {
continue;
}
if ($file->op == 'insert') {
// If node type given, match it.
$node_types = node_get_types();
if (!empty($file->field['type_name']) && empty($node_types[$file->field['type_name']])) {
continue;
}
// If cck field given, match it.
if (module_exists('content')) {
$content_types = content_types();
if (!empty($file->field['field_name']) && empty($content_types[$file->field['type_name']]['fields'][$file->field['field_name']])) {
continue;
}
}
// If filefiled_paths module exists, check to see if there are settings for it.
// If there are filefiled_paths settings, then do not process.
if (module_exists('filefield_paths') && !empty($file->field['field_name']) && !empty($file->field['field_name']) && $file->state == 'widget' && db_result(db_query("SELECT TRUE FROM {filefield_paths} WHERE type = '%s' AND field = '%s'", $file->field['type_name'], $file->field['field_name']))) {
continue;
}
// Prime imagefield theme cache.
theme('imagefield_image', (array) $file);
// Do imagecache presets.
if (module_exists('imagecache') && function_exists('imagecache_generate_image') && variable_get('imageinfo_cache_imagecache_pregenerate', IMAGEINFO_CACHE_IMAGECACHE_PREGENERATE)) {
foreach (imageinfo_cache_presets_to_generate($file) as $preset) {
// Generate each imagecache preset.
imagecache_generate_image($preset, $file->filepath);
// For each imagecache preset, Prime the imagecache theme cache.
theme('imagecache', $preset, $file->filepath);
}
}
}
elseif ($file->op == 'delete') {
// Clear the imagefield cache.
$cid = 'theme_imagefield_' . md5($file->filepath);
cache_clear_all($cid, 'cache_imageinfo');
// Do imagecache presets.
if (module_exists('imagecache') && function_exists('imagecache_generate_image')) {
// Remove the files.
imagecache_image_flush($file->filepath);
// Clear the imagecache cache.
foreach (imageinfo_cache_presets_to_generate() as $preset) {
// Remove the imagecache cache object.
$cid = 'imagecache_' . $preset . '_' . md5($file->filepath);
cache_clear_all($cid, 'cache_imageinfo');
}
}
}
else {
watchdog('imageinfo_cache', 'No operation was matched. ' . $file->op . print_r($file, TRUE));
}
}
if ($async) {
// Do not start a session for this request.
exit;
}
else {
return;
}
}