function ad_image_validate_size in Advertisement 5.2
Same name and namespace in other branches
- 5 image/ad_image.module \ad_image_validate_size()
- 6.3 image/ad_image.module \ad_image_validate_size()
- 6 image/ad_image.module \ad_image_validate_size()
- 6.2 image/ad_image.module \ad_image_validate_size()
- 7 image/ad_image.module \ad_image_validate_size()
Validate that the size of the uploaded image is within the defined limits.
2 calls to ad_image_validate_size()
- ad_image_load_image in image/
ad_image.module - ad_image_node_form in image/
ad_image.module - Adapi helper function for displaying a node form.
File
- image/
ad_image.module, line 279 - Enhances the ad module to support banner ads.
Code
function ad_image_validate_size($file, $nid) {
$size = NULL;
$error = FALSE;
$edit = $_POST['edit'];
if (is_object($file)) {
// TODO: Detect if new terms have been set, and if so validate against
// them, not the old ones. See what's in $edit['taxonomy'].
$terms = module_invoke('taxonomy', 'node_get_terms', $nid);
if (count($terms) == 0) {
// We need at least a single (NULL) term to be ensure we still get the
// default image size.
$terms[] = NULL;
}
foreach ($terms as $tid => $term) {
$format = ad_image_format_load($tid);
list($size->width, $size->height) = getimagesize($file->filepath);
if ($size->width < $format->min_width) {
drupal_set_message(t('The image <em>%name</em> is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array(
'%name' => $file->filename,
'%current' => $size->width,
'%minimum' => $format->min_width,
'%group' => theme_placeholder($term->name),
)), 'error');
$error = TRUE;
}
else {
if ($format->max_width && $size->width > $format->max_width) {
drupal_set_message(t('The image <em>%name</em> is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array(
'%name' => $file->filename,
'%current' => $size->width,
'%maximum' => $format->max_width,
'%group' => theme_placeholder($term->name),
)), 'error');
$error = TRUE;
}
}
if ($size->height < $format->min_height) {
drupal_set_message(t('The image <em>%name</em> is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array(
'%name' => $file->filename,
'%current' => $size->height,
'%minimum' => $format->min_height,
'%group' => theme_placeholder($term->name),
)), 'error');
$error = TRUE;
}
else {
if ($format->max_height && $size->height > $format->max_height) {
drupal_set_message(t('The image <em>%name</em> is %current pixels high, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array(
'%name' => $file->filename,
'%current' => $size->height,
'%maximum' => $format->max_height,
'%group' => theme_placeholder($term->name),
)), 'error');
$error = TRUE;
}
}
}
}
else {
$error = TRUE;
drupal_set_message('Please report error: $file is not an object, bug #146147.');
}
if ($error) {
return FALSE;
}
else {
return $size;
}
}