| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: watermark.module,v 1.7 2007/06/27 17:24:23 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 |
| 6 |
|
|
| 7 |
define('WATERMARK_ENABLE', 'watermark_enable'); |
define('WATERMARK_ENABLE', 'watermark_enable'); |
| 8 |
define('WATERMARK_PATH', 'watermark_path'); |
define('WATERMARK_PATH', 'watermark_path'); |
| 24 |
define('WATERMARK_POS_BOTTOMRIGHT', 7); |
define('WATERMARK_POS_BOTTOMRIGHT', 7); |
| 25 |
define('WATERMARK_POS_BOTTOMLEFT', 8); |
define('WATERMARK_POS_BOTTOMLEFT', 8); |
| 26 |
|
|
| 27 |
|
define('WATERMARK_PERM_MANAGE', 'manage watermarks'); |
| 28 |
|
|
| 29 |
function watermark_help($section) { |
function watermark_help($section) { |
| 30 |
switch ($section) { |
switch ($section) { |
| 47 |
return $items; |
return $items; |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
|
function watermark_perm() { |
| 51 |
|
return array(WATERMARK_PERM_MANAGE); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
function watermark_admin_settings() { |
function watermark_admin_settings() { |
| 55 |
if (!watermark_check_functions()) { |
if (!watermark_check_functions()) { |
| 56 |
return; |
return; |
| 233 |
return; |
return; |
| 234 |
} |
} |
| 235 |
|
|
| 236 |
$watermark = variable_get(WATERMARK_PATH, ''); |
// We hook into node validation to be able to have a watermark on all uploads, also in previews! |
| 237 |
// $dir removed --> http://drupal.org/node/142178 |
if ($op == 'validate') { |
| 238 |
// see CHANGELOG.txt and TODO.txt |
// Was a new file uploaded? |
| 239 |
$location = variable_get(WATERMARK_LOCATION, 0); |
$is_new_file = $node->new_file && is_array($node->images); |
| 240 |
|
// Has this node already an image? |
| 241 |
switch ($op) { |
$has_image = !empty($node->images['_original']); |
| 242 |
case 'validate': |
// for users with "manage watermarks" permission bypass automatic watermark process |
| 243 |
// watermark on preview! |
if (user_access(WATERMARK_PERM_MANAGE)) { |
| 244 |
// check for new image upload |
if ($node->wm_apply) { |
| 245 |
if ($node->new_file && is_array($node->images)) { |
// do we need a watermark, is there any image? |
| 246 |
foreach ($node->images as $label => $filepath) { |
if (!$has_image && !$is_new_file) { |
| 247 |
if (variable_get(WATERMARK . $label, false)) { |
return; |
|
if (_watermark_process($filepath, $watermark, $location)) { |
|
|
drupal_set_message(t('Watermark applied to image: %file', array('%file' => $label))); |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Error adding watermark.'), 'error'); |
|
|
watchdog('error', 'Error adding watermark'); |
|
|
} |
|
|
} |
|
| 248 |
} |
} |
| 249 |
|
_watermark_apply($node); |
| 250 |
} |
} |
| 251 |
break; |
} |
| 252 |
|
// normal user, automatic watermark process |
| 253 |
|
else if ($is_new_file) { |
| 254 |
|
_watermark_apply($node); |
| 255 |
|
} |
| 256 |
|
} |
| 257 |
|
} |
| 258 |
|
|
| 259 |
case 'insert': |
function watermark_form_alter($form_id, &$form) { |
| 260 |
case 'update': |
// additional option to toggle watermark process when a user has "manage watermarks" permission |
| 261 |
// new image upload check, when the node is saved without preview |
if ($form_id == 'image_node_form' && user_access(WATERMARK_PERM_MANAGE)) { |
| 262 |
if ($node->new_file && is_array($node->images)) { |
$apply_watermark = true; |
| 263 |
// We get the image from the database to guarantee it is the correct path, not temp files |
|
| 264 |
$result = db_query('SELECT filename, filepath FROM {files} WHERE nid = %d', $node->nid); |
if (preg_match('/^\/node\/[0-9]+\/edit$/i', $form['#action'])) { |
| 265 |
while ($row = db_fetch_object($result)) { |
$apply_watermark = false; |
| 266 |
if (variable_get(WATERMARK . $row->filename, false)) { |
} |
| 267 |
if (_watermark_process($row->filepath, $watermark, $location)) { |
else if ($form['#action'] != '/node/add/image') { |
| 268 |
drupal_set_message(t('Watermark applied to image: %file', array( '%file' => $row->filename ) ) ); |
return; |
| 269 |
} |
} |
| 270 |
else { |
|
| 271 |
drupal_set_message(t('Error adding watermark.'), 'error'); |
$form['watermark'] = array( |
| 272 |
watchdog('error', 'Error adding watermark'); |
'#type' => 'fieldset', |
| 273 |
} |
'#title' => t('Watermark settings'), |
| 274 |
} |
'#collapsible' => true, |
| 275 |
} |
'#collapsed' => false, |
| 276 |
|
); |
| 277 |
|
$form['watermark']['wm_apply'] = array( |
| 278 |
|
'#title' => t('Apply watermark'), |
| 279 |
|
'#type' => 'checkbox', |
| 280 |
|
'#description' => t('<strong>Automatic watermark process bypass:</strong> Please decide yourself if a watermark needs to be applied. <strong>Be careful, do not apply watermarks twice!</strong>'), |
| 281 |
|
'#default_value' => $apply_watermark, |
| 282 |
|
); |
| 283 |
|
} |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
function _watermark_apply($node) { |
| 287 |
|
$watermark = variable_get(WATERMARK_PATH, ''); |
| 288 |
|
$location = variable_get(WATERMARK_LOCATION, 0); |
| 289 |
|
foreach ($node->images as $label => $filepath) { |
| 290 |
|
if (variable_get(WATERMARK . $label, false)) { |
| 291 |
|
if (_watermark_process($filepath, $watermark, $location)) { |
| 292 |
|
drupal_set_message(t('Watermark applied to image: %file', array('%file' => $label))); |
| 293 |
|
} |
| 294 |
|
else { |
| 295 |
|
drupal_set_message(t('Error adding watermark.'), 'error'); |
| 296 |
|
watchdog('error', 'Error adding watermark'); |
| 297 |
} |
} |
| 298 |
break; |
} |
| 299 |
} |
} |
| 300 |
} |
} |
| 301 |
|
|