Index: node_images.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_images/node_images.module,v retrieving revision 1.11.2.13 diff -u -r1.11.2.13 node_images.module --- node_images.module 3 Nov 2008 14:35:51 -0000 1.11.2.13 +++ node_images.module 17 Jan 2009 12:46:19 -0000 @@ -1,5 +1,5 @@ Internationalization package).', array('@i18n' => url('http://drupal.org/project/i18n'))); + } + $output = '

'.$output.'

'; + break; + } + return $output; +} + +/** * Implementation of hook_perm(). */ function node_images_perm() { @@ -171,10 +199,11 @@ case 'delete': // Delete image and thumbnail files - $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); while ($r = db_fetch_object($sql)) { file_delete($r->filepath); file_delete($r->thumbpath); + module_invoke('i18nstrings', 'remove_string', _node_images_build_i18nstrings_context($r)); } // Delete all images associated with the node db_query('DELETE FROM {node_images} WHERE nid=%d', $node->nid); @@ -301,8 +330,8 @@ $size = $file->thumbsize; } else { - $name = mime_header_encode($file->filename); - $size = $file->filesize; + $name = mime_header_encode($file->filename); + $size = $file->filesize; } $type = mime_header_encode($file->filemime); return array( @@ -317,6 +346,16 @@ } } +/** + * Implementation of hook_locale(). + */ +function node_images_locale($op = 'groups', $group = NULL) { + switch ($op) { + case 'groups': + return array('node_images' => t('Node images')); + } +} + /************************************************************ * Upload functions @@ -751,10 +790,11 @@ if ($teaser === FALSE && $page === FALSE) return; // load node images for the current node + $nid = ($node->tnid && $node->tnid != $node->nid ? $node->tnid : $node->nid); $images = array(); $where = 'WHERE nid=%d'; if ($teaser || $page) $where .= ' AND status=1 AND list=1'; - $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); while ($r = db_fetch_object($sql)) { $images[$r->id] = $r; } @@ -912,4 +952,31 @@ 'file_size' => variable_get('node_images_file_limit', 1) * 1024 * 1024, 'resolution' => variable_get('node_images_large_resolution', 0), ); +} + +function _node_images_is_translation_source($node) { + global $language; + if ($node->tnid) return $node->nid == $node->tnid; + + if (module_exists('i18n')) { + $current = i18n_get_lang(); + $default = i18n_default_language(); + return $current == $default; + } + + return ($language->language == language_default('language')); + + $lang = ($node->language ? $node->language : language_default('language')); + return $lang == $language->language; +} + +function _node_images_translate(&$file, $update = FALSE) { + global $language; + + //$current_language = $language->language; + //$default_language = language_default('language'); + $context = 'node_images:node_image:'.$file->id.':description'; + if (module_exists('i18nstrings') && function_exists('tt')) { + $file->description = tt($context, $file->description, NULL, $update); + } } \ No newline at end of file Index: node_images.pages.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_images/node_images.pages.inc,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 node_images.pages.inc --- node_images.pages.inc 3 Nov 2008 13:41:25 -0000 1.1.2.5 +++ node_images.pages.inc 17 Jan 2009 00:19:18 -0000 @@ -1,5 +1,5 @@ TRUE, ); - if (_node_images_access('create', $node)) { + if (_node_images_access('create', $node) && $is_translation_source) { $form['new'] = array( '#type' => 'fieldset', '#title' => t('Upload a new image'), @@ -115,10 +116,10 @@ // set an appropriate value for delta in weight selectbox $delta = db_result(db_query('SELECT MAX(ABS(weight)) FROM {node_images} WHERE nid=%d', $node->nid)); $delta += count($node_images); - $authors = array(); $submit = FALSE; - + $form['node_images']['is_translation_source'] = array('#type' => 'value', '#value' => $is_translation_source); + foreach ($node_images as $key => $file) { $file = (object)$file; $update_access = _node_images_access('update', $node, $file); @@ -128,22 +129,28 @@ if (!isset($authors[$file->uid])) { $authors[$file->uid] = user_load(array('uid' => $file->uid)); } - $author = $authors[$file->uid]; - $url = file_create_url($file->filepath); $thumb = file_create_url($file->thumbpath); - $description = file_create_url($file->filepath); - $description = "". check_plain($description) .""; $row = array(); $row['id'] = array('#type' => 'value', '#value' => $file->id); - $row['delete'] = array('#type' => 'checkbox', '#attributes' => ($delete_access ? array() : array('disabled' => 'true'))); - $row['list'] = array('#type' => 'checkbox', '#default_value' => $file->list, '#attributes' => ($update_access ? array() : array('disabled' => 'true'))); $row['thumbnail'] = array('#value' => ''); - $row['description'] = ($update_access ? - array('#type' => 'textfield', '#default_value' => $file->description, '#maxlength' => 255, '#size' => 40) : - array('#value' => $file->description) - ); + + if ($is_translation_source) { + $row['delete'] = array('#type' => 'checkbox', '#attributes' => ($delete_access ? array() : array('disabled' => 'true'))); + $row['list'] = array('#type' => 'checkbox', '#default_value' => $file->list, + '#attributes' => ($update_access && $is_translation_source ? array() : array('disabled' => 'true'))); + _node_images_translate($file); + $element = array('#type' => 'textfield', '#default_value' => $file->description, '#maxlength' => 255, '#size' => 40); + } + else { + _node_images_translate($file); + $element = array('#value' => $file->description); + } + $row['description'] = $element; + + $author = $authors[$file->uid]; $row['author'] = array('#value' => theme('username', $author)); + $row['filepath'] = array('#value' => l($file->filepath, file_create_url($file->filepath), array('attributes' => array('target' => '_blank')))); $row['filesize'] = array('#value' => format_size($file->filesize)); $row['date'] = array('#value' => format_date($file->timestamp)); @@ -151,7 +158,7 @@ $form['node_images']['images'][$key] = $row; } - if ($submit) { + if ($submit && $is_translation_source) { $form['node_images']['submit'] = array('#type' => 'submit', '#value' => t('Save changes'), '#submit' => array('_node_images_form_submit')); } } @@ -168,13 +175,17 @@ * An associative array containing the current state of the form. */ function _node_images_form_submit($form, &$form_state) { - global $user; + global $user, $language; $node = node_load($form_state['values']['nid']); if (!isset($node->nid)) return drupal_set_message(t('Unable to load node.'), 'error'); + // Get languages + $current_language = $language->language; + $default_language = language_default('language'); + foreach($form_state['values']['node_images']['images'] as $id => $values) { - $file = db_fetch_object(db_query('SELECT filepath, thumbpath, uid, nid FROM {node_images} WHERE id=%d AND nid=%d', + $file = db_fetch_object(db_query('SELECT id, filepath, thumbpath, uid, nid FROM {node_images} WHERE id=%d AND nid=%d', $id, $node->nid)); if ($values['delete']) { // check delete access for the current image @@ -185,6 +196,7 @@ file_delete($file->filepath); file_delete($file->thumbpath); db_query('DELETE FROM {node_images} WHERE id=%d AND nid=%d', $id, $node->nid); + module_invoke('i18nstrings', 'remove_string', _node_images_build_i18nstrings_context($file)); } else { // check update access for the current image @@ -194,6 +206,7 @@ $update = array('id', 'nid'); $object = (object)$values; $object->nid = $node->nid; + _node_images_translate($object, TRUE); drupal_write_record('node_images', $object, $update); } } @@ -206,17 +219,17 @@ * @ingroup themeable */ function theme_node_images_form_upload(&$form) { - $output = '
'; - $output .= drupal_render($form['description']); - $output .= '
'; - $output .= '
'; - $output .= drupal_render($form['weight']); - $output .= '
'; + $output = ''; + foreach (array('description', 'weight') as $key) { + $output .= '
'; + $output .= drupal_render($form[$key]); + $output .= '
'; + } $output .= '
'; $output .= drupal_render($form['list']); $output .= '
'; - $output .= '
'; + $output .= '
'; $output .= drupal_render($form); return $output; } @@ -227,7 +240,13 @@ * @ingroup themeable */ function theme_node_images_form_list(&$form) { - $header = array('', t('Delete'), t('List'), t('Thumbnail'), t('Description and info'), t('Weight'), t('Size')); + $is_translation_source = $form['is_translation_source']['#value']; + + $header = array(); + if ($is_translation_source) { + $header = array('', t('Delete'), t('List')); + } + $header = array_merge($header, array(t('Thumbnail'), t('Description and info'), t('Weight'), t('Size'))); drupal_add_tabledrag('node_images_list', 'order', 'sibling', 'node_images-weight'); foreach (element_children($form['images']) as $key) { @@ -240,18 +259,27 @@ $info .= '
'.t('Uploaded on: %date', array('%date' => drupal_render($form['images'][$key]['date']))).'
'; $info .= '
'.t('Path: !path', array('!path' => drupal_render($form['images'][$key]['filepath']))).'
'; - $row = array(''); - $row[] = drupal_render($form['images'][$key]['delete']); - $row[] = drupal_render($form['images'][$key]['list']); + $row = array(); + if ($is_translation_source) { + $row[] = ''; + $row[] = drupal_render($form['images'][$key]['delete']); + $row[] = drupal_render($form['images'][$key]['list']); + } $row[] = drupal_render($form['images'][$key]['thumbnail']); $row[] = array('data' => drupal_render($form['images'][$key]['description']).$info, 'width' => '100%'); $row[] = drupal_render($form['images'][$key]['weight']); $row[] = array('data' => drupal_render($form['images'][$key]['filesize']), 'class' => 'nowrap'); - $rows[] = array('data' => $row, 'class' => 'draggable'); + if ($is_translation_source) { + $rows[] = array('data' => $row, 'class' => 'draggable'); + } + else { + $rows[] = $row; + } } $output = ' '; if (!empty($rows)) $output .= theme('table', $header, $rows, array('id' => 'node_images_list')); + $output .= drupal_render($form['translation_warning']); $output .= drupal_render($form); return $output; } @@ -275,7 +303,13 @@ $i = 1; $thumbs = array(); - foreach ($node->node_images as $id=>$image) { + foreach ($node->node_images as $id => $image) { + // i18n support for description + if (module_exists('i18nstrings')) { + // translate description + to('node_images:node_image:'.$image->id.':description', $image, array('description')); + } + $thumb_path = file_create_url($image->thumbpath); $thumbs[$i] = array( 'src' => $thumb_path, @@ -351,9 +385,9 @@ function theme_node_images_gallery_thumbs($thumbs, $cols = 2) { $output = ''; foreach($thumbs as $id => $thumb) { + $url = url($_GET['q'], array('query' => 'page='.$id, 'absolute' => TRUE)); $description = '
'.truncate_utf8($thumb['title'], 40, FALSE, TRUE).'
'; - $output .= '
'.l('', $_GET['q'], - array('title' => $thumb['title'], 'rel' => 'nofollow', 'html' => TRUE), 'page='.$id, NULL, FALSE, TRUE).$description.'
'; + $output .= '
'.l('', $url, array('attributes' => array('title' => $thumb['title']), 'html' => TRUE)).$description.'
'; } return $output; } \ No newline at end of file