aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2011-04-20 13:13:22 -0300
committerSilvio <silvio@devlet.com.br>2011-04-20 13:13:22 -0300
commitdf070a36a81a6ef897a83922f0915e70c2154b2f (patch)
tree6a78980a19dd188b2e61b7f55be1615705af14ef
parentfe89bd169c8c2e7bc585fa787e8037ee13901ce8 (diff)
downloadimagecache_auto-df070a36a81a6ef897a83922f0915e70c2154b2f.tar.gz
imagecache_auto-df070a36a81a6ef897a83922f0915e70c2154b2f.tar.bz2
Adding admin config page and preset validation
-rw-r--r--imagecache_auto.admin.inc36
-rw-r--r--imagecache_auto.module28
2 files changed, 54 insertions, 10 deletions
diff --git a/imagecache_auto.admin.inc b/imagecache_auto.admin.inc
new file mode 100644
index 0000000..4d31bc5
--- /dev/null
+++ b/imagecache_auto.admin.inc
@@ -0,0 +1,36 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ *
+ * Administration page callbacks.
+ */
+
+/**
+ * Form builder. Configure ImageCache Auto.
+ *
+ * @ingroup forms
+ * @see system_settings_form()
+ */
+function imagecache_auto_admin_settings() {
+ $form['imagecache_auto_max_width'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Maximum preset width (pixels)'),
+ '#default_value' => variable_get('imagecache_auto_max_width', '10000'),
+ '#size' => 10,
+ '#maxlength' => 64,
+ '#description' => t('The maximum width an automatically created ImageCache preset can have.'),
+ );
+
+ $form['imagecache_auto_max_height'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Maximum preset height (pixels)'),
+ '#default_value' => variable_get('imagecache_auto_max_height', '10000'),
+ '#size' => 10,
+ '#maxlength' => 64,
+ '#description' => t('The maximum height an automatically created ImageCache preset can have.'),
+ );
+
+ return system_settings_form($form);
+}
diff --git a/imagecache_auto.module b/imagecache_auto.module
index f55fcd5..e022fa5 100644
--- a/imagecache_auto.module
+++ b/imagecache_auto.module
@@ -14,9 +14,9 @@
function imagecache_auto_menu() {
$items = array();
- $items['admin/settings/imagecache/auto'] = array(
- 'title' => 'ImageCache Auto Configuration',
- 'description' => 'Adjust ImageCache Auto settings.',
+ $items['admin/build/imagecache/auto'] = array(
+ 'title' => 'ImageCache Auto',
+ 'description' => 'ImageCache Auto settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('imagecache_auto_admin_settings'),
'access arguments' => array('administer site configuration'),
@@ -27,7 +27,7 @@ function imagecache_auto_menu() {
$items[file_directory_path() .'/imagecache_auto'] = array(
'page callback' => 'imagecache_auto',
'access callback' => TRUE,
- 'type' => MENU_CALLBACK
+ 'type' => MENU_CALLBACK,
);
return $items;
@@ -35,24 +35,32 @@ function imagecache_auto_menu() {
/**
* Automatically create ImageCache presets.
- *
- * @todo
- * Specify maximum and minimum dimensions.
*/
function imagecache_auto() {
include_once('imagecache_auto.inc');
- $args = func_get_args();
- $options = array(
+ $max_width = variable_get('imagecache_auto_max_width', '10000');
+ $max_height = variable_get('imagecache_auto_max_height', '10000');
+ $args = func_get_args();
+ $options = array(
'width' => (int) check_plain(array_shift($args)),
'height' => (int) check_plain(array_shift($args)),
'path' => implode('/', $args),
);
+ // Validation.
+ if ($options['width'] == NULL || $options['width'] < 0 || $options['width'] > $max_width) {
+ drupal_not_found();
+ }
+ else if ($options['height'] == NULL || $options['height'] < 0 || $options['height'] > $max_height) {
+ drupal_not_found();
+ }
+
// Make sure that the preset exists.
imagecache_auto_create_preset($options);
// Redirect to the image cache image version.
- $path = file_directory_path() .'/imagecache/'. $options['width'] .'x'. $options['height'] .'/'. $options['path'];
+ $preset = $options['width'] .'x'. $options['height'];
+ $path = file_directory_path() .'/imagecache/'. $preset .'/'. $options['path'];
drupal_goto($path);
}