From 5af2c03966f8da401c45d086abfc96b4fa6060a0 Mon Sep 17 00:00:00 2001 From: Ron Shimshock Date: Sat, 5 Mar 2016 09:11:41 -0600 Subject: [PATCH] Create image thumbnails --- imce.install | 12 ++++++++++++ imce.module | 27 +++++++++++++++++++++++++++ inc/imce.admin.inc | 12 ++++++++++++ inc/imce.page.inc | 4 ++++ js/imce_extras.js | 9 +++++++-- tpl/imce-file-list.tpl.php | 2 +- 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/imce.install b/imce.install index 40ddcd3..75305de 100644 --- a/imce.install +++ b/imce.install @@ -121,4 +121,16 @@ function imce_update_7002() { variable_set('imce_roles_profiles', $roles); } } +} + +/** + * Adds image style path token variable if IMCE is enabled + */ +function imce_update_7003() { + if (module_exists('imce')) { + if (!array_key_exists('imce_process_path_tokens', $funcs = variable_get('imce_custom_process', array()))) { + $funcs['imce_process_path_tokens'] = TRUE; + } + variable_set('imce_custom_process', $funcs); + } } \ No newline at end of file diff --git a/imce.module b/imce.module index f3dc4bf..59c2e9e 100644 --- a/imce.module +++ b/imce.module @@ -130,6 +130,33 @@ function imce_textarea($element) { } /** + * Custom path tokens process. Sets image style path tokens for preview images. + */ +function imce_process_path_tokens(&$imce) { + $imce_preview_style = variable_get('imce_settings_preview_style', ''); + if ($imce_preview_style && !empty($imce['furl']) && !empty($imce['files'])) { + $uri_paths = array(); + foreach ($imce['files'] as $file) { + $uri_paths[] = file_build_uri($imce['dir'] . '/' . $file['name']); + } + $uris = db_select('file_managed', 'fm') + ->condition('uri', $uri_paths) + ->fields('fm', array('uri', 'filename')) + ->execute() + ->fetchAllKeyed(); + foreach ($imce['files'] as &$file) { + if (!variable_get('image_suppress_itok_output', FALSE)) { + $image_uri = file_build_uri($imce['dir'] . '/' . $file['name']); + $file['itok'] = !empty($uris[$image_uri]) ? image_style_path_token($imce_preview_style, $image_uri) : ''; + } + else { + $file['itok'] = ''; + } + } + } +} + +/** * Returns the configuration profile assigned to a user for a specific file scheme. */ function imce_user_profile($user, $scheme = NULL) { diff --git a/inc/imce.admin.inc b/inc/imce.admin.inc index 587aa47..e7582b3 100644 --- a/inc/imce.admin.inc +++ b/inc/imce.admin.inc @@ -109,6 +109,17 @@ function imce_admin_form($form, &$form_state) { '#default_value' => variable_get('imce_settings_disable_private', 1), '#description' => t('IMCE serves all files under private files directory without applying any access restrictions. This allows anonymous access to any file(/system/files/filename) unless there is a module restricting access to the files. Here you can disable this feature.'), ); + $styles = image_styles(); + foreach ($styles as &$style) { + $style = $style['label']; + } + $form['common']['preview_style'] = array( + '#type' => 'select', + '#title' => t('File browser image preview style'), + '#options' => array_merge(array('' => t('None')), $styles), + '#default_value' => variable_get('imce_settings_preview_style', NULL), + '#description' => t('Select image style to use as preview in the file browser. Select "None" for no preview.'), + ); $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); $form['#theme'] = 'imce_admin'; @@ -183,6 +194,7 @@ function imce_admin_submit($form, &$form_state) { variable_set('imce_settings_replace', $form_state['values']['replace']); variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']); variable_set('imce_settings_disable_private', $form_state['values']['disable_private']); + variable_set('imce_settings_preview_style', $form_state['values']['preview_style']); drupal_set_message(t('Changes have been saved.')); } diff --git a/inc/imce.page.inc b/inc/imce.page.inc index 9f42d34..1204079 100644 --- a/inc/imce.page.inc +++ b/inc/imce.page.inc @@ -85,6 +85,10 @@ function imce_content($user, $scheme = NULL, $jsop = NULL) { drupal_add_js($imce_ref, 'setting'); + if ($imce_preview_style = variable_get('imce_settings_preview_style', '')) { + drupal_add_js(array('imce' => array('prvstyle' => $imce_preview_style)), 'setting'); + } + return $content; } diff --git a/js/imce_extras.js b/js/imce_extras.js index b558cc5..cc96696 100644 --- a/js/imce_extras.js +++ b/js/imce_extras.js @@ -222,13 +222,18 @@ imce.cookie = function (name, value) { //view thumbnails(smaller than tMaxW x tMaxH) inside the rows. //Large images can also be previewed by setting imce.vars.prvstyle to a valid image style(imagecache preset) imce.thumbRow = function (row) { + imce.vars.prvstyle = Drupal.settings.imce.prvstyle; var w = row.cells[2].innerHTML * 1; if (!w) return; var h = row.cells[3].innerHTML * 1; + var itok = jQuery(row).data('itok'); + if (typeof itok === 'undefined') { + return; + } if (imce.vars.tMaxW < w || imce.vars.tMaxH < h) { if (!imce.vars.prvstyle || imce.conf.dir.indexOf('styles') == 0) return; var img = new Image(); - img.src = imce.imagestyleURL(imce.getURL(row.id), imce.vars.prvstyle); + img.src = imce.imagestyleURL(imce.getURL(row.id), imce.vars.prvstyle) + '?itok=' + itok; img.className = 'imagestyle-' + imce.vars.prvstyle; } else { @@ -243,7 +248,7 @@ imce.thumbRow = function (row) { prvW = prvH*w/h; } } - var img = new Image(prvW, prvH); + img = new Image(prvW, prvH); img.src = imce.getURL(row.id); } var cell = row.cells[0]; diff --git a/tpl/imce-file-list.tpl.php b/tpl/imce-file-list.tpl.php index 189eed4..bdccb1a 100644 --- a/tpl/imce-file-list.tpl.php +++ b/tpl/imce-file-list.tpl.php @@ -13,7 +13,7 @@ $imce =& $imce_ref['imce'];//keep this line. $file) {?> - + data-itok=""> -- 2.7.2