| 1 |
<?php
|
| 2 |
|
| 3 |
function imagecache_asset_settings(){
|
| 4 |
$form[] = array('#value' => '<p>Select which imagecache presets should be available to use as asset formatters.</p>');
|
| 5 |
$presets = _imagecache_get_presets();
|
| 6 |
foreach($presets as $id=>$name){
|
| 7 |
$formats[$name] = array(
|
| 8 |
'name' => $name . ' (imagecache)',
|
| 9 |
'types' => array('jpg','gif','png'),
|
| 10 |
'description' => _imagecache_asset_description($id),
|
| 11 |
);
|
| 12 |
$form['asset_imagecache_preset_'.$id] = array(
|
| 13 |
'#type' => 'checkbox',
|
| 14 |
'#title' => $name,
|
| 15 |
'#default_value' => variable_get('asset_imagecache_preset_'.$id, 1),
|
| 16 |
);
|
| 17 |
}
|
| 18 |
return system_settings_form($form);
|
| 19 |
}
|
| 20 |
|
| 21 |
function imagecache_asset_formatter($op='info',$asset=null,$attr=array()){
|
| 22 |
switch($op){
|
| 23 |
case 'info':
|
| 24 |
$presets = _imagecache_get_presets();
|
| 25 |
foreach($presets as $id=>$name){
|
| 26 |
$formats[$name] = array(
|
| 27 |
'name' => $name . ' (imagecache)',
|
| 28 |
'description' => _imagecache_asset_description($id),
|
| 29 |
'module' => 'imagecache',
|
| 30 |
);
|
| 31 |
}
|
| 32 |
return $formats;
|
| 33 |
case 'load':
|
| 34 |
if($asset->type=='file' && strpos($asset->file['filemime'], 'image/') === 0){
|
| 35 |
$presets = _imagecache_get_presets();
|
| 36 |
foreach($presets as $id=>$name){
|
| 37 |
$formats[] = $name;
|
| 38 |
}
|
| 39 |
}
|
| 40 |
return $formats;
|
| 41 |
case 'img':
|
| 42 |
$path = file_directory_path() .'/imagecache/'. $attr['format'] .'/'. $asset->file['filepath'];
|
| 43 |
return $path;
|
| 44 |
case 'render':
|
| 45 |
$title = $attr['title'] ? $attr['title'] : $asset->title;
|
| 46 |
$alt = $attr['alt'] ? $attr['alt'] : $asset->title;
|
| 47 |
return theme('imagecache', $attr['format'], $asset->file['filepath'], $alt, $title);
|
| 48 |
case 'form':
|
| 49 |
$form['alt'] = array(
|
| 50 |
'#type' => 'textfield',
|
| 51 |
'#title' => t('Alt Text'),
|
| 52 |
'#default_value' => $attr['alt'] ? $attr['alt'] : $asset->title,
|
| 53 |
'#description' => t('Alt attribute for the image'),
|
| 54 |
);
|
| 55 |
$form['title'] = array(
|
| 56 |
'#type' => 'textfield',
|
| 57 |
'#title' => t('Title'),
|
| 58 |
'#default_value' => $attr['title'] ? $attr['title'] : $asset->title,
|
| 59 |
'#description' => t('Title attribute for the image'),
|
| 60 |
);
|
| 61 |
$form['wysiwyg'] = array('#type' => 'hidden', '#value' => urlencode(file_create_url(file_directory_path() .'/imagecache/'. $attr['format'] .'/'. $asset->file['filepath'])));
|
| 62 |
return $form;
|
| 63 |
}
|
| 64 |
}
|
| 65 |
|
| 66 |
function _imagecache_asset_description($preset_id){
|
| 67 |
$actions = _imagecache_actions_get_by_presetid($preset_id);
|
| 68 |
$items = array();
|
| 69 |
foreach($actions as $action){
|
| 70 |
switch($action['data']['function']){
|
| 71 |
case 'scale':
|
| 72 |
$items[] = 'Proportionally scaled to '
|
| 73 |
. $action['data']['fit'] . ' dimensions of '
|
| 74 |
. $action['data']['width'] . 'x' . $action['data']['height']
|
| 75 |
. '.';
|
| 76 |
break;
|
| 77 |
case 'resize':
|
| 78 |
$items[] = 'Non-Proportionally scaled to '
|
| 79 |
. $action['data']['width'] . 'x' . $action['data']['height']
|
| 80 |
. '.';
|
| 81 |
break;
|
| 82 |
case 'crop':
|
| 83 |
$items[] = 'Cropped to '
|
| 84 |
. $action['data']['width'] . 'x' . $action['data']['height']
|
| 85 |
. ' at offset '
|
| 86 |
. $action['data']['xoffset'] . ',' . $action['data']['yoffset']
|
| 87 |
. '.';
|
| 88 |
break;
|
| 89 |
}
|
| 90 |
}
|
| 91 |
return join($items, ' Then, ');
|
| 92 |
}
|