| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
|
* Implementation of hook_help(). |
| 11 |
|
*/ |
| 12 |
|
function node_images_help($path, $arg) { |
| 13 |
|
switch ($path) { |
| 14 |
|
case 'node/%/images': |
| 15 |
|
$node = node_load($arg[1]); |
| 16 |
|
if (_node_images_is_translation_source($node)) { |
| 17 |
|
$output = t('This page allows you to manage node images.'); |
| 18 |
|
} |
| 19 |
|
else { |
| 20 |
|
$output = t('This page allows you to view node images.'); |
| 21 |
|
if (_node_images_access('create', $node)) { |
| 22 |
|
$output .= ' '.t('You can upload new images or edit current images by switching to the default language.'); |
| 23 |
|
} |
| 24 |
|
} |
| 25 |
|
if (module_exists('i18nstrings')) { |
| 26 |
|
$output .= ' '.t('Image descriptions can be translated using the localization interface.'); |
| 27 |
|
} |
| 28 |
|
else { |
| 29 |
|
$output .= ' '.t('Image descriptions can be translated using the localization interface and the i18nstrings module (available in the <a href="@i18n">Internationalization</a> package).', array('@i18n' => url('http://drupal.org/project/i18n'))); |
| 30 |
|
} |
| 31 |
|
$output = '<p>'.$output.'</p>'; |
| 32 |
|
break; |
| 33 |
|
} |
| 34 |
|
return $output; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
/** |
| 38 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 39 |
*/ |
*/ |
| 40 |
function node_images_perm() { |
function node_images_perm() { |
| 199 |
|
|
| 200 |
case 'delete': |
case 'delete': |
| 201 |
// Delete image and thumbnail files |
// Delete image and thumbnail files |
| 202 |
$sql = db_query('SELECT filepath, thumbpath FROM {node_images} WHERE nid=%d', $node->nid); |
$sql = db_query('SELECT id, filepath, thumbpath FROM {node_images} WHERE nid=%d', $node->nid); |
| 203 |
while ($r = db_fetch_object($sql)) { |
while ($r = db_fetch_object($sql)) { |
| 204 |
file_delete($r->filepath); |
file_delete($r->filepath); |
| 205 |
file_delete($r->thumbpath); |
file_delete($r->thumbpath); |
| 206 |
|
module_invoke('i18nstrings', 'remove_string', _node_images_build_i18nstrings_context($r)); |
| 207 |
} |
} |
| 208 |
// Delete all images associated with the node |
// Delete all images associated with the node |
| 209 |
db_query('DELETE FROM {node_images} WHERE nid=%d', $node->nid); |
db_query('DELETE FROM {node_images} WHERE nid=%d', $node->nid); |
| 330 |
$size = $file->thumbsize; |
$size = $file->thumbsize; |
| 331 |
} |
} |
| 332 |
else { |
else { |
| 333 |
$name = mime_header_encode($file->filename); |
$name = mime_header_encode($file->filename); |
| 334 |
$size = $file->filesize; |
$size = $file->filesize; |
| 335 |
} |
} |
| 336 |
$type = mime_header_encode($file->filemime); |
$type = mime_header_encode($file->filemime); |
| 337 |
return array( |
return array( |
| 346 |
} |
} |
| 347 |
} |
} |
| 348 |
|
|
| 349 |
|
/** |
| 350 |
|
* Implementation of hook_locale(). |
| 351 |
|
*/ |
| 352 |
|
function node_images_locale($op = 'groups', $group = NULL) { |
| 353 |
|
switch ($op) { |
| 354 |
|
case 'groups': |
| 355 |
|
return array('node_images' => t('Node images')); |
| 356 |
|
} |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
|
| 360 |
/************************************************************ |
/************************************************************ |
| 361 |
* Upload functions |
* Upload functions |
| 790 |
if ($teaser === FALSE && $page === FALSE) return; |
if ($teaser === FALSE && $page === FALSE) return; |
| 791 |
|
|
| 792 |
// load node images for the current node |
// load node images for the current node |
| 793 |
|
$nid = ($node->tnid && $node->tnid != $node->nid ? $node->tnid : $node->nid); |
| 794 |
$images = array(); |
$images = array(); |
| 795 |
$where = 'WHERE nid=%d'; |
$where = 'WHERE nid=%d'; |
| 796 |
if ($teaser || $page) $where .= ' AND status=1 AND list=1'; |
if ($teaser || $page) $where .= ' AND status=1 AND list=1'; |
| 797 |
$sql = db_query('SELECT * FROM {node_images} ' .$where. ' ORDER BY weight', $node->nid); |
$sql = db_query('SELECT * FROM {node_images} ' .$where. ' ORDER BY weight', $nid); |
| 798 |
while ($r = db_fetch_object($sql)) { |
while ($r = db_fetch_object($sql)) { |
| 799 |
$images[$r->id] = $r; |
$images[$r->id] = $r; |
| 800 |
} |
} |
| 952 |
'file_size' => variable_get('node_images_file_limit', 1) * 1024 * 1024, |
'file_size' => variable_get('node_images_file_limit', 1) * 1024 * 1024, |
| 953 |
'resolution' => variable_get('node_images_large_resolution', 0), |
'resolution' => variable_get('node_images_large_resolution', 0), |
| 954 |
); |
); |
| 955 |
|
} |
| 956 |
|
|
| 957 |
|
function _node_images_is_translation_source($node) { |
| 958 |
|
global $language; |
| 959 |
|
if ($node->tnid) return $node->nid == $node->tnid; |
| 960 |
|
|
| 961 |
|
if (module_exists('i18n')) { |
| 962 |
|
$current = i18n_get_lang(); |
| 963 |
|
$default = i18n_default_language(); |
| 964 |
|
return $current == $default; |
| 965 |
|
} |
| 966 |
|
|
| 967 |
|
return ($language->language == language_default('language')); |
| 968 |
|
|
| 969 |
|
$lang = ($node->language ? $node->language : language_default('language')); |
| 970 |
|
return $lang == $language->language; |
| 971 |
|
} |
| 972 |
|
|
| 973 |
|
function _node_images_translate(&$file, $update = FALSE) { |
| 974 |
|
global $language; |
| 975 |
|
|
| 976 |
|
//$current_language = $language->language; |
| 977 |
|
//$default_language = language_default('language'); |
| 978 |
|
$context = 'node_images:node_image:'.$file->id.':description'; |
| 979 |
|
if (module_exists('i18nstrings') && function_exists('tt')) { |
| 980 |
|
$file->description = tt($context, $file->description, NULL, $update); |
| 981 |
|
} |
| 982 |
} |
} |