imageinfo_cache.admin.inc

  1. cis7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  2. cle7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  3. ecd7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  4. elmsmedia7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  5. harmony7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  6. icor7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  7. meedjum_blog7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
  8. mooc7 sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc

Admin page callbacks for the imageinfo cache module.

Functions

Namesort descending Description
imageinfo_cache_admin_settings_form Form builder; Configure advagg settings.
imageinfo_cache_admin_settings_form_submit Only record the non-default presets.

File

sites/all/modules/ulmus/imageinfo_cache/imageinfo_cache.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the imageinfo cache module.
  5. */
  6. /**
  7. * Form builder; Configure advagg settings.
  8. *
  9. * @ingroup forms
  10. * @see system_settings_form()
  11. */
  12. function imageinfo_cache_admin_settings_form($form, $form_state) {
  13. drupal_set_title(t('Imageinfo Cache Configuration'));
  14. module_load_include('inc', 'imageinfo_cache', 'imageinfo_cache');
  15. $form = array();
  16. $form['imageinfo_cache_use_httprl'] = array(
  17. '#type' => 'checkbox',
  18. '#title' => t('Use HTTPRL for background image generation'),
  19. '#default_value' => module_exists('httprl') ? variable_get('imageinfo_cache_use_httprl', IMAGEINFO_CACHE_USE_HTTPRL) : FALSE,
  20. '#description' => t('If <a href="@link">HTTPRL</a> is installed, image styles will be generated in a background parallel process, thus not slowing down entity saves and image file uploads.', array('@link' => 'http://drupal.org/project/httprl')),
  21. '#disabled' => module_exists('httprl') ? FALSE : TRUE,
  22. );
  23. $form['pre_generation'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('Pre Generation of Image Styles'),
  26. '#description' => t('Styles that end with * are enabled by default as they are being used for that field.'),
  27. );
  28. // Get image styles.
  29. $image_styles = array_keys(image_styles());
  30. $image_styles = array_combine($image_styles, $image_styles);
  31. ksort($image_styles);
  32. // Get image fields.
  33. $image_field_defaults = imageinfo_cache_get_image_fields(FALSE);
  34. $image_fields = imageinfo_cache_get_image_fields();
  35. $all_image_styles_used = array();
  36. foreach ($image_fields as $field_name => $image_styles_used) {
  37. if (isset($image_styles_used['#field_info'])) {
  38. unset($image_styles_used['#field_info']);
  39. }
  40. $image_styles_used = array_keys($image_styles_used);
  41. // Create the fieldset.
  42. $form['pre_generation']['field_' . $field_name] = array(
  43. '#type' => 'fieldset',
  44. '#title' => t('@field_name: @styles_checked', array(
  45. '@field_name' => strpos($field_name, 'field_') === 0 ? substr($field_name, 6) : $field_name,
  46. '@styles_checked' => implode(', ', $image_styles_used),
  47. )),
  48. '#collapsible' => TRUE,
  49. '#collapsed' => TRUE,
  50. );
  51. // Add a * to the end of default styles.
  52. if (isset($image_field_defaults[$field_name]['#field_info'])) {
  53. unset($image_field_defaults[$field_name]['#field_info']);
  54. }
  55. $temp_image_styles = array();
  56. foreach ($image_styles as $key => $style_name) {
  57. if (!empty($image_field_defaults[$field_name][$style_name])) {
  58. $style_name .= '*';
  59. }
  60. $temp_image_styles[$key] = $style_name;
  61. }
  62. // Create the checkboxes field.
  63. $form['pre_generation']['field_' . $field_name]['imageinfo_cache_' . $field_name] = array(
  64. '#type' => 'checkboxes',
  65. '#options' => $temp_image_styles,
  66. '#default_value' => $image_styles_used,
  67. );
  68. $all_image_styles_used = array_merge($all_image_styles_used, $image_styles_used);
  69. }
  70. $all_image_styles_used = array_values(array_unique($all_image_styles_used));
  71. $all_image_styles_used = array_combine($all_image_styles_used, $all_image_styles_used);
  72. ksort($all_image_styles_used);
  73. $styles_not_used = array_diff($image_styles, $all_image_styles_used);
  74. $form['pre_generation']['styles_not_in_use'] = array(
  75. '#type' => 'textfield',
  76. '#title' => 'Image Styles Not in Use',
  77. '#value' => implode(', ', $styles_not_used),
  78. );
  79. $form['buttons']['reset'] = array(
  80. '#type' => 'submit',
  81. '#value' => t('Reset to defaults'),
  82. );
  83. // Clear the cache bins on submit.
  84. $form['#submit'][] = 'imageinfo_cache_admin_settings_form_submit';
  85. $form['actions']['#type'] = 'actions';
  86. $form['actions']['submit'] = array(
  87. '#type' => 'submit',
  88. '#value' => t('Save configuration'),
  89. );
  90. // By default, render the form using theme_system_settings_form().
  91. $form['#theme'] = 'system_settings_form';
  92. return $form;
  93. }
  94. // Submit callback.
  95. /**
  96. * Only record the non-default presets.
  97. */
  98. function imageinfo_cache_admin_settings_form_submit($form, &$form_state) {
  99. $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  100. if ($op == t('Reset to defaults')) {
  101. foreach ($form_state['values'] as $key => $value) {
  102. if (is_array($value)) {
  103. variable_del($key);
  104. }
  105. }
  106. drupal_set_message(t('The configuration options have been reset to their default values.'));
  107. return;
  108. }
  109. module_load_include('inc', 'imageinfo_cache', 'imageinfo_cache');
  110. // Get image styles; set value to 0.
  111. $image_styles = array_fill_keys(array_keys(image_styles()), 0);
  112. // Get the default values.
  113. $default_values = array();
  114. $image_fields = imageinfo_cache_get_image_fields(FALSE);
  115. foreach ($image_fields as $field_name => &$image_styles_used) {
  116. if (isset($image_styles_used['#field_info'])) {
  117. unset($image_styles_used['#field_info']);
  118. }
  119. $image_styles_used = array_keys($image_styles_used);
  120. if (empty($image_styles_used)) {
  121. $default_values['imageinfo_cache_' . $field_name] = array();
  122. }
  123. else {
  124. $default_values['imageinfo_cache_' . $field_name] = array_combine($image_styles_used, $image_styles_used);
  125. }
  126. // Add in not selected image styles.
  127. if (!is_array($default_values['imageinfo_cache_' . $field_name])) {
  128. $default_values['imageinfo_cache_' . $field_name] = array();
  129. }
  130. $default_values['imageinfo_cache_' . $field_name] += $image_styles;
  131. ksort($default_values['imageinfo_cache_' . $field_name]);
  132. }
  133. // Get the saved values.
  134. $values = array();
  135. foreach ($form_state['values'] as $field_name => $selection) {
  136. if (is_array($selection) && isset($default_values[$field_name])) {
  137. ksort($selection);
  138. $values[$field_name] = $selection;
  139. }
  140. }
  141. // Compute the array difference.
  142. $array_diff = array();
  143. foreach ($default_values as $field_name => $image_styles_used) {
  144. $array_diff[$field_name] = array_diff_assoc($values[$field_name], $image_styles_used);
  145. }
  146. // Save values.
  147. foreach ($array_diff as $key => $value) {
  148. if (empty($value)) {
  149. variable_del($key);
  150. }
  151. variable_set($key, $value);
  152. }
  153. drupal_set_message(t('The configuration options have been saved.'));
  154. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.