function ad_image_validate_size in Advertisement 6
Same name and namespace in other branches
- 5.2 image/ad_image.module \ad_image_validate_size()
- 5 image/ad_image.module \ad_image_validate_size()
- 6.3 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 - Returns image object from given ad node.
- ad_image_node_form in image/
ad_image.module - Adapi helper function for displaying a node form.
File
- image/
ad_image.module, line 350 - Enhances the ad module to support banner ads.
Code
function ad_image_validate_size($file, $nid) {
$size = NULL;
$error = FALSE;
$edit = isset($_POST['edit']) ? $_POST['edit'] : array();
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'].
$node = node_load($nid);
$terms = module_invoke('taxonomy', 'node_get_terms', $node);
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) {
list($size->width, $size->height) = getimagesize($file->filepath);
if ($format = ad_image_format_load($tid)) {
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;
}
}