array( 'field_types' => 'file', 'name' => t('file'), 'description' => t('file styles'), 'path' => drupal_get_path('module', 'file_styles') .'/includes/styles', 'file' => 'FileStyles.inc', ), ); } /** * Styles filter callback. * * This will determine the correct style container corresponding to media type. */ function file_styles_styles_filter($object, $element = NULL) { // Ensure we're working against the fully loaded file object. $file = file_uri_to_object($object->uri); // Allow other modules to define their own file styles. // In general, they'll most likely want to check against the mimetype. $containers = styles_default_containers('file'); $filters = module_invoke_all('file_styles_filter', $object); foreach ($filters as $filter) { if (isset($containers['containers'][$filter])) { return $filter; } } // Now check the part of the mimetype before the slash. // Note that we can't use strstr($haystack, $needle, $before_needle) // < PHP 5.3, so we need a work-around. $filter = file_styles_strstr($object->filemime, '/', TRUE); if (isset($containers['containers'][$filter])) { return $filter; } // Fallback to default. return 'default'; } /** * Support for strstr with $before_needle < PHP 5.3. */ function file_styles_strstr($haystack, $needle, $before_needle = FALSE){ if ($before_needle) { return array_shift(explode($needle, $haystack, 2)); } return strstr($haystack, $needle); } /** * Return the path to the image for previews in Styles UI. * * If it doesn't yet exist, then copy the source to the files directory. * * @param boolean $replace * If TRUE, then replace the file. * * @return mixed * The path to the image preview file, or FALSE if unable to copy. */ function file_styles_preview_image($replace = FALSE) { $path = file_styles_variable_get('preview_image'); if (!$path || $replace) { $dir = file_default_scheme() . '://' . file_styles_variable_get('preview_image_directory'); if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) { $source = file_styles_variable_get('image_style_preview_image'); if ($path = file_unmanaged_copy($source, $dir . '/' . basename($source), FILE_EXISTS_REPLACE)) { file_styles_variable_set('preview_image', $path); } } } return $path; } /** * Implementation of hook_theme(). */ function file_styles_theme($existing, $type, $theme, $path) { return array( 'file_styles_image' => array( 'variables' => array('image_uri' => '', 'alt' => '', 'title' => '', 'attributes' => array(), 'image_style' => NULL, 'instance' => NULL), 'file' => 'file_styles.theme.inc', 'path' => $path . '/includes/themes', ), 'file_styles_image_preview' => array( 'variables' => array('style_name' => NULL), 'file' => 'file_styles.theme.inc', 'path' => $path . '/includes/themes', ), ); }