| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: watermark.module,v 1.5.2.4 2007/07/03 17:59:47 kbahey Exp $ |
// $Id: watermark.module,v 1.5.2.5 2007/07/07 17:53:29 kbahey Exp $ |
| 4 |
// Author: Khalid Baheyeldin of http://2bits.com |
// Author: Khalid Baheyeldin of http://2bits.com |
| 5 |
// Additional features by schnizZzla for http://BerlinerStrassen.com |
// Additional features by schnizZzla for http://BerlinerStrassen.com |
| 6 |
|
|
| 59 |
$form['watermark'] = array( |
$form['watermark'] = array( |
| 60 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 61 |
'#title' => t('Watermark'), |
'#title' => t('Watermark'), |
| 62 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 63 |
'#weight' => -1, |
'#weight' => -1, |
| 64 |
); |
); |
| 65 |
|
|
| 66 |
$form['watermark'][WATERMARK_ENABLE] = array( |
$form['watermark'][WATERMARK_ENABLE] = array( |
| 67 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 68 |
'#title' => t('Enable watermarking of new images?'), |
'#title' => t('Enable watermarking of new images?'), |
| 69 |
'#default_value' => variable_get(WATERMARK_ENABLE, false), |
'#default_value' => variable_get(WATERMARK_ENABLE, FALSE), |
| 70 |
'#description' => t('Check this box to enable watermarking of new images.'), |
'#description' => t('Check this box to enable watermarking of new images.'), |
| 71 |
); |
); |
| 72 |
|
|
| 75 |
'#title' => t('Watermark overlay image'), |
'#title' => t('Watermark overlay image'), |
| 76 |
'#size' => 70, |
'#size' => 70, |
| 77 |
'#maxlength' => 255, |
'#maxlength' => 255, |
| 78 |
'#required' => true, |
'#required' => TRUE, |
| 79 |
'#default_value' => variable_get(WATERMARK_PATH, ''), |
'#default_value' => variable_get(WATERMARK_PATH, ''), |
| 80 |
'#description' => t('Path of the image that should be used as the watermark image, relative to the Drupal root. This should be a truecolor (32 bit) PNG file with an alpha channel, but other formats may work.'), |
'#description' => t('Path of the image that should be used as the watermark image, relative to the Drupal root. This should be a truecolor (32 bit) PNG file with an alpha channel, but other formats may work.'), |
| 81 |
); |
); |
| 103 |
$form['watermark']['scaling'] = array( |
$form['watermark']['scaling'] = array( |
| 104 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 105 |
'#title' => t('Watermark scaling'), |
'#title' => t('Watermark scaling'), |
| 106 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 107 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 108 |
); |
); |
| 109 |
|
|
| 110 |
$form['watermark']['scaling'][WATERMARK_SCALING] = array( |
$form['watermark']['scaling'][WATERMARK_SCALING] = array( |
| 111 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 112 |
'#title' => t('Scale watermark'), |
'#title' => t('Scale watermark'), |
| 113 |
'#description' => t('Use scaling, if you want the watermark to be proportional to the image width. Please note that the watermark is scaled only, when it is too big.'), |
'#description' => t('Use scaling, if you want the watermark to be proportional to the image width. Please note that the watermark is scaled only, when it is too big.'), |
| 114 |
'#default_value' => variable_get(WATERMARK_SCALING, false), |
'#default_value' => variable_get(WATERMARK_SCALING, FALSE), |
| 115 |
); |
); |
| 116 |
|
|
| 117 |
$form['watermark']['scaling'][WATERMARK_SCALING_PERCENTAGE] = array( |
$form['watermark']['scaling'][WATERMARK_SCALING_PERCENTAGE] = array( |
| 133 |
$form['watermark']['labels'] = array( |
$form['watermark']['labels'] = array( |
| 134 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 135 |
'#title' => t('Apply watermark to the following images'), |
'#title' => t('Apply watermark to the following images'), |
| 136 |
'#collapsible' => false, |
'#collapsible' => FALSE, |
| 137 |
'#description' => t('Check which images you want to apply watermarks for.'), |
'#description' => t('Check which images you want to apply watermarks for.'), |
| 138 |
); |
); |
| 139 |
|
|
| 140 |
foreach (_image_get_sizes() as $size) { |
foreach (_image_get_sizes() as $id => $size) { |
| 141 |
$label_list[] = $size['label']; |
$label_var = WATERMARK . $id; |
|
} |
|
|
$label_list[] = IMAGE_ORIGINAL; |
|
|
|
|
|
foreach ($label_list as $label) { |
|
|
$label_var = WATERMARK . $label; |
|
| 142 |
$form['watermark']['labels'][$label_var] = array( |
$form['watermark']['labels'][$label_var] = array( |
| 143 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 144 |
'#title' => $label, |
'#title' => $size['label'] . " ($id)", |
| 145 |
'#default_value' => variable_get($label_var, false), |
'#default_value' => variable_get($label_var, FALSE), |
| 146 |
); |
); |
| 147 |
} |
} |
| 148 |
|
|
| 153 |
$form['watermark']['toggles'] = array( |
$form['watermark']['toggles'] = array( |
| 154 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 155 |
'#title' => t('Toggles'), |
'#title' => t('Toggles'), |
| 156 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 157 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 158 |
); |
); |
| 159 |
|
|
| 160 |
$form['watermark']['toggles'][WATERMARK_EXCLUDE_TERMS] = array( |
$form['watermark']['toggles'][WATERMARK_EXCLUDE_TERMS] = array( |
| 164 |
'#description' => $exclude_terms_description, |
'#description' => $exclude_terms_description, |
| 165 |
'#default_value' => variable_get(WATERMARK_EXCLUDE_TERMS, array()), |
'#default_value' => variable_get(WATERMARK_EXCLUDE_TERMS, array()), |
| 166 |
'#options' => _watermark_get_gallery_terms(), |
'#options' => _watermark_get_gallery_terms(), |
| 167 |
'#multiple' => true, |
'#multiple' => TRUE, |
| 168 |
); |
); |
| 169 |
|
|
| 170 |
return system_settings_form($form); |
return system_settings_form($form); |
| 208 |
} |
} |
| 209 |
|
|
| 210 |
if (!empty($errors)) { |
if (!empty($errors)) { |
| 211 |
return false; |
return FALSE; |
| 212 |
} |
} |
| 213 |
|
|
| 214 |
return true; |
return TRUE; |
| 215 |
} |
} |
| 216 |
|
|
| 217 |
function watermark_nodeapi(&$node, $op, $teaser = null, $page = null) { |
function watermark_nodeapi(&$node, $op, $teaser = null, $page = null) { |
| 219 |
return; |
return; |
| 220 |
} |
} |
| 221 |
|
|
| 222 |
if (!variable_get(WATERMARK_ENABLE, false)) { |
if (!variable_get(WATERMARK_ENABLE, FALSE)) { |
| 223 |
return; |
return; |
| 224 |
} |
} |
| 225 |
|
|
| 254 |
function watermark_form_alter($form_id, &$form) { |
function watermark_form_alter($form_id, &$form) { |
| 255 |
// additional option to toggle watermark process when a user has "manage watermarks" permission |
// additional option to toggle watermark process when a user has "manage watermarks" permission |
| 256 |
if ($form_id == 'image_node_form' && user_access(WATERMARK_PERM_MANAGE)) { |
if ($form_id == 'image_node_form' && user_access(WATERMARK_PERM_MANAGE)) { |
| 257 |
$apply_watermark = true; |
$apply_watermark = TRUE; |
| 258 |
|
|
| 259 |
if (preg_match('/^\/node\/[0-9]+\/edit$/i', $form['#action'])) { |
if (preg_match('/^\/node\/[0-9]+\/edit$/i', $form['#action'])) { |
| 260 |
$apply_watermark = false; |
$apply_watermark = FALSE; |
| 261 |
} |
} |
| 262 |
else if ($form['#action'] != '/node/add/image') { |
else if ($form['#action'] != '/node/add/image') { |
| 263 |
return; |
return; |
| 266 |
$form['watermark'] = array( |
$form['watermark'] = array( |
| 267 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 268 |
'#title' => t('Watermark settings'), |
'#title' => t('Watermark settings'), |
| 269 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 270 |
'#collapsed' => false, |
'#collapsed' => FALSE, |
| 271 |
); |
); |
| 272 |
$form['watermark']['wm_apply'] = array( |
$form['watermark']['wm_apply'] = array( |
| 273 |
'#title' => t('Apply watermark'), |
'#title' => t('Apply watermark'), |
| 282 |
$watermark = variable_get(WATERMARK_PATH, ''); |
$watermark = variable_get(WATERMARK_PATH, ''); |
| 283 |
$location = variable_get(WATERMARK_LOCATION, 0); |
$location = variable_get(WATERMARK_LOCATION, 0); |
| 284 |
foreach ($node->images as $label => $filepath) { |
foreach ($node->images as $label => $filepath) { |
| 285 |
if (variable_get(WATERMARK . $label, false)) { |
if (variable_get(WATERMARK . $label, FALSE)) { |
| 286 |
if (_watermark_process($filepath, $watermark, $location)) { |
if (_watermark_process($filepath, $watermark, $location)) { |
| 287 |
drupal_set_message(t('Watermark applied to image: %file', array('%file' => $label))); |
drupal_set_message(t('Watermark applied to image: %file', array('%file' => $label))); |
| 288 |
} |
} |
| 296 |
|
|
| 297 |
function _watermark_process($image_path, $watermark_path, $location) { |
function _watermark_process($image_path, $watermark_path, $location) { |
| 298 |
// init return status |
// init return status |
| 299 |
$status = false; |
$status = FALSE; |
| 300 |
|
|
| 301 |
$scaling = variable_get(WATERMARK_SCALING, false); |
$scaling = variable_get(WATERMARK_SCALING, FALSE); |
| 302 |
|
|
| 303 |
if (!$wm_info = _watermark_make_image($watermark_path)) { |
if (!$wm_info = _watermark_make_image($watermark_path)) { |
| 304 |
return false; |
return FALSE; |
| 305 |
} |
} |
| 306 |
$wm = $wm_info['handle']; |
$wm = $wm_info['handle']; |
| 307 |
|
|
| 308 |
if (!$im_info = _watermark_make_image($image_path)) { |
if (!$im_info = _watermark_make_image($image_path)) { |
| 309 |
return false; |
return FALSE; |
| 310 |
} |
} |
| 311 |
$im = $im_info['handle']; |
$im = $im_info['handle']; |
| 312 |
|
|
| 317 |
imagedestroy($im); |
imagedestroy($im); |
| 318 |
$im = $new_im; |
$im = $new_im; |
| 319 |
} |
} |
| 320 |
imagealphablending($im, true); |
imagealphablending($im, TRUE); |
| 321 |
|
|
| 322 |
$im_x = $im_info['width']; |
$im_x = $im_info['width']; |
| 323 |
$im_y = $im_info['height']; |
$im_y = $im_info['height']; |
| 413 |
watchdog(WATERMARK_WATCHDOG, $msg, WATCHDOG_ERROR); |
watchdog(WATERMARK_WATCHDOG, $msg, WATCHDOG_ERROR); |
| 414 |
} |
} |
| 415 |
else { |
else { |
| 416 |
$status = true; |
$status = TRUE; |
| 417 |
} |
} |
| 418 |
|
|
| 419 |
imagedestroy($im); |
imagedestroy($im); |
| 426 |
|
|
| 427 |
if (!file_exists($file)) { |
if (!file_exists($file)) { |
| 428 |
drupal_set_message(t('Image file %file not found.', array('%file' => $file ) ), 'error'); |
drupal_set_message(t('Image file %file not found.', array('%file' => $file ) ), 'error'); |
| 429 |
return false; |
return FALSE; |
| 430 |
} |
} |
| 431 |
|
|
| 432 |
$type = exif_imagetype($file); |
$type = exif_imagetype($file); |
| 447 |
default: |
default: |
| 448 |
// Unsupported type |
// Unsupported type |
| 449 |
drupal_set_message(t('Image file %file is an unsupported format type=%type.', array( '%file' => $file, '%type' => $type ) ), 'error'); |
drupal_set_message(t('Image file %file is an unsupported format type=%type.', array( '%file' => $file, '%type' => $type ) ), 'error'); |
| 450 |
return false; |
return FALSE; |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
$function = 'imagecreatefrom'. $type; |
$function = 'imagecreatefrom'. $type; |
| 455 |
|
|
| 456 |
if (!$handle) { |
if (!$handle) { |
| 457 |
drupal_set_message(t('Failed to create handle for image file %file via function %function.', array( '%file' => $file, '%function' => $function )), 'error'); |
drupal_set_message(t('Failed to create handle for image file %file via function %function.', array( '%file' => $file, '%function' => $function )), 'error'); |
| 458 |
return false; |
return FALSE; |
| 459 |
} |
} |
| 460 |
|
|
| 461 |
// create image info |
// create image info |
| 502 |
if (!$vid) { |
if (!$vid) { |
| 503 |
|
|
| 504 |
// change: we don't want to create any vocabulary here |
// change: we don't want to create any vocabulary here |
| 505 |
return false; |
return FALSE; |
| 506 |
} |
} |
| 507 |
variable_set('image_gallery_nav_vocabulary', $vid); |
variable_set('image_gallery_nav_vocabulary', $vid); |
| 508 |
} |
} |
| 525 |
foreach ($tids as $tid => $status) { |
foreach ($tids as $tid => $status) { |
| 526 |
if ($status!=0 && in_array($tid, $excluded_tids)) { |
if ($status!=0 && in_array($tid, $excluded_tids)) { |
| 527 |
// at least one term matches excluded terms |
// at least one term matches excluded terms |
| 528 |
return true; |
return TRUE; |
| 529 |
} |
} |
| 530 |
} |
} |
| 531 |
} |
} |
| 532 |
// it's not a multiple select vocabulary |
// it's not a multiple select vocabulary |
| 533 |
else if (!empty($tids) && $vid == $gallery_vid && in_array($tids, $excluded_tids)) { |
else if (!empty($tids) && $vid == $gallery_vid && in_array($tids, $excluded_tids)) { |
| 534 |
// excluded term found |
// excluded term found |
| 535 |
return true; |
return TRUE; |
| 536 |
} |
} |
| 537 |
} |
} |
| 538 |
} |
} |
| 539 |
return false; |
return FALSE; |
| 540 |
} |
} |