| 1 |
<?php
|
| 2 |
// $Id: img_assist.module,v 1.106 2009/08/03 21:47:25 sun Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Image assist administrative functionality.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_settings().
|
| 11 |
*/
|
| 12 |
function img_assist_admin_settings() {
|
| 13 |
require_once drupal_get_path('module', 'img_assist') .'/includes/img_assist.token.inc';
|
| 14 |
|
| 15 |
// Access settings.
|
| 16 |
$form['access'] = array(
|
| 17 |
'#type' => 'fieldset',
|
| 18 |
'#title' => t('Access settings'),
|
| 19 |
'#collapsible' => TRUE,
|
| 20 |
'#collapsed' => TRUE,
|
| 21 |
);
|
| 22 |
$form['access']['img_assist_paths_type'] = array(
|
| 23 |
'#type' => 'radios',
|
| 24 |
'#title' => t('Display Image assist on paths'),
|
| 25 |
'#default_value' => variable_get('img_assist_paths_type', 2),
|
| 26 |
'#options' => array(t('on specific paths'), t('not on specific paths'), t('all paths')),
|
| 27 |
);
|
| 28 |
$form['access']['img_assist_paths'] = array(
|
| 29 |
'#type' => 'textarea',
|
| 30 |
'#title' => t('Paths'),
|
| 31 |
'#default_value' => variable_get('img_assist_paths', "node/*\ncomment/*"),
|
| 32 |
'#cols' => 40,
|
| 33 |
'#rows' => 5,
|
| 34 |
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
| 35 |
);
|
| 36 |
$form['access']['img_assist_textareas_type'] = array(
|
| 37 |
'#type' => 'radios',
|
| 38 |
'#title' => t('Display Image assist on text areas'),
|
| 39 |
'#default_value' => variable_get('img_assist_textareas_type', 2),
|
| 40 |
'#options' => array(t('Show on every textarea except the listed textareas.'), t('Show on only the listed textareas.'), t('Show on all textareas.')),
|
| 41 |
);
|
| 42 |
$form['access']['img_assist_textareas'] = array(
|
| 43 |
'#type' => 'textarea',
|
| 44 |
'#title' => t('Text areas'),
|
| 45 |
'#default_value' => variable_get('img_assist_textareas', "edit-body\nedit-comment"),
|
| 46 |
'#cols' => 40,
|
| 47 |
'#rows' => 5,
|
| 48 |
'#description' => t("Enter one text area form-id per line. Form-id's are used by Drupal to typify them, which allows themers and coders to modify certain form fields, but not all. Find form-id's using this method: view the source of the webpage, then search for the string that's just above the text area and you'll see the form-id nearby. The '*' character is a wildcard. For example, you can specify all CCK fields as %cck-example.", array('%cck-example' => 'edit-field-*')),
|
| 49 |
);
|
| 50 |
$form['access']['img_assist_link'] = array(
|
| 51 |
'#type' => 'select',
|
| 52 |
'#title' => t('Textarea image link'),
|
| 53 |
'#default_value' => variable_get('img_assist_link', 'icon'),
|
| 54 |
'#options' => array('icon' => t('Show icon'), 'text' => t('Show text link'), 'none' => t('Do not show a link')),
|
| 55 |
'#description' => t('Choose what to show under the textareas for which Image assist is enabled.'),
|
| 56 |
);
|
| 57 |
|
| 58 |
// Prepare select options for image browser views.
|
| 59 |
$options = array();
|
| 60 |
views_include('admin');
|
| 61 |
$views = views_get_all_views();
|
| 62 |
$base_tables = views_fetch_base_tables();
|
| 63 |
foreach ($views as $view) {
|
| 64 |
// Exclude malformed views (@see views/admin.inc).
|
| 65 |
if (!empty($view->disabled) || empty($view->display)) {
|
| 66 |
continue;
|
| 67 |
}
|
| 68 |
// Exclude views considered unusable for IA.
|
| 69 |
if (!($view->base_table == 'node' || $view->base_table == 'files')) {
|
| 70 |
continue;
|
| 71 |
}
|
| 72 |
$options[$view->name] = ($view->get_title() == '') ? $view->name : $view->get_title();
|
| 73 |
}
|
| 74 |
$form['access']['img_assist_views'] = array(
|
| 75 |
'#type' => 'select',
|
| 76 |
'#multiple' => TRUE,
|
| 77 |
'#title' => t('Image browser views'),
|
| 78 |
'#default_value' => variable_get('img_assist_views', drupal_map_assoc(array('img_assist_browser'))),
|
| 79 |
'#options' => $options,
|
| 80 |
'#required' => TRUE,
|
| 81 |
'#description' => t('Select the views to use for selecting images.'),
|
| 82 |
);
|
| 83 |
|
| 84 |
if (module_exists('taxonomy')) {
|
| 85 |
$vocs = array(0 => '<'. t('none') .'>');
|
| 86 |
foreach (taxonomy_get_vocabularies() as $vid => $voc) {
|
| 87 |
$vocs[$vid] = $voc->name;
|
| 88 |
}
|
| 89 |
if (count($vocs) > 1) {
|
| 90 |
$form['access']['img_assist_vocabs'] = array(
|
| 91 |
'#type' => 'select',
|
| 92 |
'#multiple' => TRUE,
|
| 93 |
'#title' => t('Select the vocabularies to use for Image assist'),
|
| 94 |
'#default_value' => variable_get('img_assist_vocabs', array()),
|
| 95 |
'#options' => $vocs,
|
| 96 |
'#description' => t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of Image assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'),
|
| 97 |
);
|
| 98 |
}
|
| 99 |
}
|
| 100 |
|
| 101 |
// Image settings.
|
| 102 |
$form['image'] = array(
|
| 103 |
'#type' => 'fieldset',
|
| 104 |
'#title' => t('Image generation settings'),
|
| 105 |
'#collapsible' => TRUE,
|
| 106 |
'#collapsed' => TRUE,
|
| 107 |
);
|
| 108 |
$form['image']['img_assist_max_size'] = array(
|
| 109 |
'#type' => 'textfield',
|
| 110 |
'#title' => t('Maximum inline image size allowed'),
|
| 111 |
'#default_value' => variable_get('img_assist_max_size', '640x640'),
|
| 112 |
'#size' => 9,
|
| 113 |
'#maxlength' => 9,
|
| 114 |
'#description' => t('Enter the number of maximum image dimensions to display with Image assist. This is a way to prevent users from breaking your layouts. This is applied when the filter tag is processed, so it will affect existing images. If an existing image exceeds these dimensions, a smaller derivative of the image will be substituted (or a smaller version will be created if you have allowed Image assist to create its own derivatives).'),
|
| 115 |
);
|
| 116 |
if (function_exists('image_get_sizes')) {
|
| 117 |
$max_size = explode('x', variable_get('img_assist_max_size', '640x640'));
|
| 118 |
$oversize_count = 0;
|
| 119 |
foreach (image_get_sizes() as $key => $size) {
|
| 120 |
$dimensions = $size['width'] .'x'. $size['height'];
|
| 121 |
if ((!empty($size['width']) && $size['width'] <= $max_size[0]) || (!empty($size['height']) && $size['height'] <= $max_size[1])) {
|
| 122 |
$derivatives[$dimensions] = $size['label'];
|
| 123 |
}
|
| 124 |
elseif ($key == IMAGE_THUMBNAIL) {
|
| 125 |
// Thumbnail option is shown even if it is larger than maximum size.
|
| 126 |
$derivatives[$dimensions] = $size['label'];
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
$oversize_count++;
|
| 130 |
}
|
| 131 |
$allsizes[$key] = $size['label'];
|
| 132 |
}
|
| 133 |
|
| 134 |
$form['image']['img_assist_popup_label'] = array(
|
| 135 |
'#type' => 'select',
|
| 136 |
'#title' => t('Popup size'),
|
| 137 |
'#default_value' => variable_get('img_assist_popup_label', IMAGE_PREVIEW),
|
| 138 |
'#options' => $allsizes,
|
| 139 |
'#description' => t('Select the size of the image that is popped up.'),
|
| 140 |
);
|
| 141 |
|
| 142 |
$oversize_alert = ($oversize_count) ? '<br /><strong>'. format_plural($oversize_count, '1 image size is not being shown because it exceeds the the maximum inline image size setting (see above).', '@count image sizes are not being shown because they exceed the the maximum inline image size setting (see above).') .'</strong>' : '';
|
| 143 |
$form['image']['img_assist_default_label'] = array(
|
| 144 |
'#type' => 'select',
|
| 145 |
'#title' => t('Default size for inline images'),
|
| 146 |
'#default_value' => variable_get('img_assist_default_label', '100x100'),
|
| 147 |
'#options' => $derivatives,
|
| 148 |
'#description' => t('Select a derivative to be used by default for inline images.') . $oversize_alert,
|
| 149 |
);
|
| 150 |
}
|
| 151 |
$form['image']['img_assist_create_derivatives'] = array(
|
| 152 |
'#type' => 'checkboxes',
|
| 153 |
'#title' => t('Creation of image derivatives'),
|
| 154 |
'#default_value' => variable_get('img_assist_create_derivatives', array()),
|
| 155 |
'#options' => array(
|
| 156 |
'properties' => t('Create 200x200 images for the image properties window (useful if the thumbnail size is small).'),
|
| 157 |
'custom_advanced' => t('Allow users with %access permission to create custom size inline images.', array('%access' => 'access advanced options')),
|
| 158 |
'custom_all' => t('Allow all users to create custom size inline images.'),
|
| 159 |
),
|
| 160 |
'#description' => t('These options allow Image assist to generate its custom image sizes (in the same manner as image.module) when a user would prefer a different size from the default image sizes defined in the image.module settings.'),
|
| 161 |
);
|
| 162 |
|
| 163 |
// Other properties.
|
| 164 |
$form['properties'] = array(
|
| 165 |
'#type' => 'fieldset',
|
| 166 |
'#title' => t('Image property dialog settings'),
|
| 167 |
'#collapsible' => TRUE,
|
| 168 |
'#collapsed' => TRUE,
|
| 169 |
);
|
| 170 |
$form['properties']['img_assist_default_link_behavior'] = array(
|
| 171 |
'#type' => 'select',
|
| 172 |
'#title' => t('Default link behavior'),
|
| 173 |
'#default_value' => variable_get('img_assist_default_link_behavior', 'none'),
|
| 174 |
'#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),
|
| 175 |
'#description' => t('The link behavior can be overridden when inserting images by users with the proper permissions, but these defaults will still be used for everyone else.'),
|
| 176 |
);
|
| 177 |
$form['properties']['img_assist_default_link_url'] = array(
|
| 178 |
'#type' => 'textfield',
|
| 179 |
'#title' => t('Default URL'),
|
| 180 |
'#default_value' => variable_get('img_assist_default_link_url', 'http://'),
|
| 181 |
'#size' => 30,
|
| 182 |
'#maxlength' => 255,
|
| 183 |
'#description' => t('The default URL is used when Go to URL is choosen as the link behavior.'),
|
| 184 |
);
|
| 185 |
$form['properties']['img_assist_default_insert_mode'] = array(
|
| 186 |
'#type' => 'select',
|
| 187 |
'#title' => t('Default insert mode'),
|
| 188 |
'#default_value' => variable_get('img_assist_default_insert_mode', 'none'),
|
| 189 |
'#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
|
| 190 |
'#description' => t('The insert behavior can be overridden by users with the %permission permission when inserting images. <strong>Warning:</strong> If images are inserted as HTML, Image Assist is not able to correct a link or image URL afterwards. Please also note that users will not be able to edit already inserted images when using HTML code and the TinyMCE plugin.', array('%permission' => t('access advanced options'))),
|
| 191 |
);
|
| 192 |
$form['properties']['img_assist_load_title'] = array(
|
| 193 |
'#type' => 'radios',
|
| 194 |
'#title' => t('Preset caption title'),
|
| 195 |
'#default_value' => variable_get('img_assist_load_title', 1),
|
| 196 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 197 |
'#description' => t('If enabled, the title from the image will be loaded as the bolded caption by default.'),
|
| 198 |
);
|
| 199 |
$token_installed = module_exists('token');
|
| 200 |
$token_instructions = (!$token_installed ? t('Requires the !token module.', array('!token' => l('Token', 'http://drupal.org/project/token'))) : t('See below for a list of available replacement patterns.'));
|
| 201 |
$form['properties']['img_assist_title_pattern'] = array(
|
| 202 |
'#type' => 'textfield',
|
| 203 |
'#title' => t('Caption title pattern'),
|
| 204 |
'#default_value' => variable_get('img_assist_title_pattern', '[title]'),
|
| 205 |
'#size' => 60,
|
| 206 |
'#maxlength' => 255,
|
| 207 |
'#description' => t('The pattern to generate the bolded caption title from.') .' '. $token_instructions,
|
| 208 |
'#disabled' => !$token_installed,
|
| 209 |
);
|
| 210 |
$form['properties']['img_assist_load_description'] = array(
|
| 211 |
'#type' => 'radios',
|
| 212 |
'#title' => t('Preset caption text'),
|
| 213 |
'#default_value' => variable_get('img_assist_load_description', 1),
|
| 214 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 215 |
'#description' => t('If enabled, the body text from the image will be loaded as the caption by default.'),
|
| 216 |
);
|
| 217 |
$form['properties']['img_assist_description_pattern'] = array(
|
| 218 |
'#type' => 'textfield',
|
| 219 |
'#title' => t('Caption text pattern'),
|
| 220 |
'#default_value' => variable_get('img_assist_description_pattern', '[body]'),
|
| 221 |
'#size' => 60,
|
| 222 |
'#maxlength' => 255,
|
| 223 |
'#description' => t('The pattern to generate the caption text from.') .' '. $token_instructions,
|
| 224 |
'#disabled' => !$token_installed,
|
| 225 |
);
|
| 226 |
if ($token_installed) {
|
| 227 |
$form['properties']['token_help'] = array(
|
| 228 |
'#title' => t('Replacement patterns'),
|
| 229 |
'#type' => 'fieldset',
|
| 230 |
'#collapsible' => TRUE,
|
| 231 |
'#collapsed' => TRUE,
|
| 232 |
);
|
| 233 |
$form['properties']['token_help'][] = array(
|
| 234 |
'#value' => theme('token_help', 'node'),
|
| 235 |
);
|
| 236 |
}
|
| 237 |
if (module_exists('content')) {
|
| 238 |
$options = array();
|
| 239 |
$info = _content_type_info();
|
| 240 |
foreach ($info['content types']['image']['fields'] as $field) {
|
| 241 |
$options[$field['field_name']] = t($field['widget']['label']) .' ('. $field['field_name'] .')';
|
| 242 |
}
|
| 243 |
$form['properties']['img_assist_display_properties'] = array(
|
| 244 |
'#type' => 'checkboxes',
|
| 245 |
'#title' => t('Image properties shown'),
|
| 246 |
'#default_value' => variable_get('img_assist_display_properties', array()),
|
| 247 |
'#options' => $options,
|
| 248 |
'#description' => t('All selected CCK fields from the Image node will be displayed in the Image Assist pop-up window.'),
|
| 249 |
);
|
| 250 |
if (empty($options)) {
|
| 251 |
$form['properties']['img_assist_display_properties']['#description'] .= '<br />'. t('<strong>Note:</strong> The <a href="!content-type">Image content-type</a> does not contain any CCK fields currently.', array('!content-type' => url('admin/content/node-type/image/fields')));
|
| 252 |
}
|
| 253 |
}
|
| 254 |
|
| 255 |
// Image display settings.
|
| 256 |
$form['display'] = array(
|
| 257 |
'#type' => 'fieldset',
|
| 258 |
'#title' => t('Image display settings'),
|
| 259 |
'#collapsible' => TRUE,
|
| 260 |
'#collapsed' => TRUE,
|
| 261 |
);
|
| 262 |
$form['display']['img_assist_page_styling'] = array(
|
| 263 |
'#type' => 'select',
|
| 264 |
'#title' => t('Include img_assist.css on all pages for styling inline images?'),
|
| 265 |
'#default_value' => variable_get('img_assist_page_styling', 'yes'),
|
| 266 |
'#options' => array('yes' => t('yes'), 'no' => t('no')),
|
| 267 |
'#description' => t('Advanced users can customize their theme\'s CSS file so that inclusion of the img_assist.css file will not be necessary. See notes at the bottom of img_assist.css for details.'),
|
| 268 |
);
|
| 269 |
|
| 270 |
return system_settings_form($form);
|
| 271 |
}
|
| 272 |
|
| 273 |
/**
|
| 274 |
* Validate Image Assist settings.
|
| 275 |
*/
|
| 276 |
function img_assist_admin_settings_validate($form, &$form_state) {
|
| 277 |
// img_assist_max_size must contain a value for width and height.
|
| 278 |
if (!preg_match('/\d+x\d+/', $form_state['values']['img_assist_max_size'])) {
|
| 279 |
form_set_error('img_assist_max_size', t('Allowed maximum inline image size has to indicate width and height, for example %example.', array('%example' => '200x300')));
|
| 280 |
}
|
| 281 |
}
|
| 282 |
|
| 283 |
/**
|
| 284 |
* Menu callback; clears relevant caches, then redirects to the previous page.
|
| 285 |
*
|
| 286 |
* @see devel_cache_clear()
|
| 287 |
*/
|
| 288 |
function img_assist_cache_clear() {
|
| 289 |
// clear core tables
|
| 290 |
$core = array('cache_filter', 'cache_page');
|
| 291 |
foreach ($core as $table) {
|
| 292 |
cache_clear_all('*', $table, TRUE);
|
| 293 |
}
|
| 294 |
drupal_set_message('Cache cleared.');
|
| 295 |
drupal_goto('admin/settings/img_assist');
|
| 296 |
}
|
| 297 |
|