comparison modules/translation/translation.module @ 19:3edae6ecd6c6 6.9

Drupal 6.9
author Franck Deroche <franck@defr.org>
date Thu, 15 Jan 2009 10:15:56 +0100
parents 4347c45bb494
children
comparison
equal deleted inserted replaced
18:f5131a9cd9e5 19:3edae6ecd6c6
1 <?php 1 <?php
2 // $Id: translation.module,v 1.23.2.3 2008/12/10 20:35:06 goba Exp $ 2 // $Id: translation.module,v 1.23.2.4 2009/01/14 23:34:07 goba Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * Manages content translations. 6 * Manages content translations.
7 * 7 *
74 * Only display translation tab for node types, which have translation enabled 74 * Only display translation tab for node types, which have translation enabled
75 * and where the current node is not language neutral (which should span 75 * and where the current node is not language neutral (which should span
76 * all languages). 76 * all languages).
77 */ 77 */
78 function _translation_tab_access($node) { 78 function _translation_tab_access($node) {
79 if (!empty($node->language) && translation_supported_type($node->type)) { 79 return !empty($node->language) && translation_supported_type($node->type) && node_access('view', $node) && user_access('translate content');
80 return user_access('translate content');
81 }
82 return FALSE;
83 } 80 }
84 81
85 /** 82 /**
86 * Implementation of hook_perm(). 83 * Implementation of hook_perm().
87 */ 84 */
190 return; 187 return;
191 } 188 }
192 189
193 switch ($op) { 190 switch ($op) {
194 case 'prepare': 191 case 'prepare':
195 if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) && 192 if (empty($node->nid) && user_access('translate content') && isset($_GET['translation']) && isset($_GET['language']) && is_numeric($_GET['translation'])) {
196 ($source_nid = $_GET['translation']) && ($language = $_GET['language']) && 193 $translation_source = node_load($_GET['translation']);
197 (user_access('translate content'))) { 194 if (empty($translation_source) || !node_access('view', $translation_source)) {
198 // We are translating a node from a source node, so 195 // Source node not found or no access to view. We should not check
199 // load the node to be translated and populate fields. 196 // for edit access, since the translator might not have permissions
200 $node->language = $language; 197 // to edit the source node but should still be able to translate.
201 $node->translation_source = node_load($source_nid); 198 return;
202 $node->title = $node->translation_source->title; 199 }
203 $node->body = $node->translation_source->body; 200 $language_list = language_list();
201 if (!isset($language_list[$_GET['language']]) || ($translation_source->language == $_GET['language'])) {
202 // If not supported language, or same language as source node, break.
203 return;
204 }
205 // Populate fields based on source node.
206 $node->language = $_GET['language'];
207 $node->translation_source = $translation_source;
208 $node->title = $translation_source->title;
209 // If user has no access to the filter used for the body, Drupal core
210 // does not let the edit form to appear, so we should avoid exposing
211 // the source text here too.
212 $node->body = filter_access($translation_source->format) ? $translation_source->body : '';
204 // Let every module add custom translated fields. 213 // Let every module add custom translated fields.
205 node_invoke_nodeapi($node, 'prepare translation'); 214 node_invoke_nodeapi($node, 'prepare translation');
206 } 215 }
207 break; 216 break;
208 217