'[imagecache-preset].', '[imagecache-slash]' => '[imagecache-preset]/', '[imagecache-underscore-pre]' => '_[imagecache-preset]', '[imagecache-underscore-post]' => '[imagecache-preset]_', ); $file['filealias'] = filefield_paths_process_string($settings['filealias']['value'], 'node', $node, $settings['filealias']); $file['filealias'] = filefield_paths_process_string($file['filealias'], 'field', array(0 => $file['field']), $settings['filealias']); $file['filealias'] = str_replace(array_keys($tokens), array_values($tokens), $file['filealias']); $file['filealias'] = explode('[imagecache-preset]', $file['filealias']); // @TODO - Support for private filesystem. $imagecache_path = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC ? file_directory_path() . '/imagecache/' : 'system/files'; // Regular expression to replace file reference with file alias. $pattern = array( 'regex' => str_replace('/', '\/', $imagecache_path) . '([^"]*?)' . str_replace('/', '\/', str_replace(file_directory_path(), '', $file['filepath']['new'])), 'regex_enc' => str_replace('/', '\/', drupal_urlencode($imagecache_path)) . '([^"]*?)' . str_replace('/', '\/', str_replace(drupal_urlencode(file_directory_path()), '', drupal_urlencode($file['filepath']['new']))), 'replace' => $file['filealias'][0] . '$1' . $file['filealias'][1], ); // Process regular expression. _filefield_paths_replace_pattern($pattern, $node, $update); } } $settings['filealias'] = preg_replace('/\[imagecache.*?\]/', '', $settings['filealias']); } function file_aliases_form_alter(&$form, $form_state, $form_id) { if (in_array('filefield_paths_form_submit', $form['#submit'])) { $form['#submit'][] = 'file_aliases_imagecache_menu_rebuild'; } } function file_aliases_imagecache_menu_rebuild($form, &$form_state) { menu_rebuild(); } function file_aliases_menu_alter(&$items) { $results = db_query("SELECT filealias FROM {filefield_paths}"); while ($result = db_fetch_object($results)) { $data = unserialize($result->filealias); $path = array(); foreach (explode('/', $data['value']) as $string) { $path[] = (strstr($string, '[')) ? '%' : $string; } $items[implode('/', $path)] = array( 'page callback' => 'file_aliases_imagecache_alias', 'page arguments' => array($data['value']), 'access callback' => TRUE, ); } } function file_aliases_imagecache_alias($pattern) { $tokens = array( '[imagecache-dot]' => ')(.*?)\.(', '[imagecache-slash]' => ')(.*?)/(', '[imagecache-underscore-pre]' => ')_(.*?)(', '[imagecache-underscore-post]' => ')(.*?)\_(', ); $path = str_replace(base_path(), '', request_uri()); $pattern = preg_replace('/\[.*?\]/', '.*', str_replace(array_keys($tokens), array_values($tokens), str_replace('.', '\.', $pattern))); preg_match('/(' . str_replace('/', '\/', $pattern) . ')/', $path, $matches); // Does ImageCache preset exist? $preset = $matches[2]; if (count(imagecache_preset_by_name($preset)) == 0) { drupal_not_found(); } // Does filealias exist? $filealias = $matches[1] . $matches[3]; if (!$source = drupal_lookup_path('source', $filealias)) { drupal_not_found(); } $fid = str_replace('filefield_paths/alias/', '', $source); $result = db_fetch_object(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid)); // Does file with file id exist? if (!$result) { drupal_not_found(); } // Return ImageCache. imagecache_cache($preset, $result->filepath); }