123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- diff --git a/i18n_access.module b/i18n_access.module
- index 5f4aa56..a76370d 100644
- --- a/i18n_access.module
- +++ b/i18n_access.module
- @@ -105,18 +105,21 @@ function i18n_access_permission() {
- function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) {
-
- if (isset($form['language']['#options'])) {
- - // Remove inaccessible languages from the select box
- - // don't do it for admininstrators
- + // Remove inaccessible languages from the select box
- + // don't do it for administrators
- if (!user_access('administer nodes')) {
- $perms = i18n_access_load_permissions();
- foreach ($form['language']['#options'] as $key => $value) {
- $perm_key = ($key == '') ? I18N_ACCESS_LANGUAGE_NEUTRAL : $key;
- - if ($key!='en' && empty($perms[$perm_key])) {
- +
- + // remove english from here, we treat english the same as any language
- + // if ($key!='en' && empty($perms[$perm_key])) {
- + if (empty($perms[$perm_key])) {
- unset($form['language']['#options']["$key"]);
- }
- }
- }
- - unset($form['#after_build']['0']);
- + // unset($form['#after_build']['0']);
- }
- }
-
- @@ -125,7 +128,7 @@ function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) {
- */
- function i18n_access_form_alter(&$form, &$form_state, $form_id) {
-
- - //Configuring translation edit form to limit it to allowed language
- + // Configuring translation edit form to limit it to allowed language
- if ($form_id == 'i18n_node_select_translation' && !user_access('administer nodes')) {
-
- $perms = i18n_access_load_permissions();
- @@ -149,7 +152,7 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) {
- }
-
- // Add i18n_access things to user/edit /user/add
- - if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' ) {
- + if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
-
- $form['i18n_access'] = array(
- '#type' => 'fieldset',
- @@ -171,67 +174,100 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) {
- *
- * @see node_access()
- */
- -function i18n_access_node_access($node, $op, $account = NULL) {
- +function i18n_access_node_access($node, $op, $account = NULL, $langcode = NULL) {
- + // big re-work here. discarded entire original function-- replaced with our own
- if (is_object($node)) {
- -
- - global $user;
- -
- - // If no user object is supplied, the access check is for the current user.
- - if (empty($account)) {
- - $account = $user;
- + // make sure that site administrators always have access
- + $permissions = i18n_access_load_permissions($user);
- + if (user_access('site administrator', $account)) {
- + return TRUE;
- }
- + // if langcode is null it means the user is not accessing by translation overview, we throw access deny and allow to hard deny sneaky people and keep unpermitted tabs out of the menu system for the user
- + elseif ($langcode == NULL) {
- + global $language;
- + $langcode = $language->language;
- +
- + switch ($op) {
- + case 'view':
- + return NODE_ACCESS_ALLOW;
- + break;
- + case 'update':
- + if (empty($permissions[$langcode])) {
- + return NODE_ACCESS_DENY;
- + }
- + else {
- + return NODE_ACCESS_ALLOW;
- + }
- + break;
- + case 'create':
- + if (empty($permissions[$langcode])) {
- + return NODE_ACCESS_DENY;
- + }
- + else {
- + return NODE_ACCESS_ALLOW;
- + }
- + break;
-
- - // Bypass completely if node_access returns false.
- - //TODO $access = node_access($node, $op, $account);
- -
- - /* TODO if (!$access) {
- - return FALSE;
- - } */
- -
- - // This module doesn't deal with view permissions
- - if ($op == 'view') {
- - return NODE_ACCESS_IGNORE;
- + }
- }
- -
- - // make sure that administrators always have access
- - if (user_access('administer nodes', $account)) {
- - return TRUE;
- + //if they are accessing by translation overview, the language code gets passed by the translation overview, we send true or false here
- + else {
- + switch ($op) {
- + case 'view':
- + return TRUE;
- + break;
- + case 'update':
- + if (empty($permissions[$langcode])) {
- + return FALSE;
- + }
- + else {
- + return TRUE;
- + }
- + break;
- + case 'create':
- + if (empty($permissions[$langcode])) {
- + return FALSE;
- + }
- + else {
- + return TRUE;
- + }
- + break;
- + }
- }
- -
- - $perms = i18n_access_load_permissions($account->uid);
- -
- - // Make sure to use the language neutral constant if node language is empty
- - $langcode = $node->language ? $node->language : I18N_ACCESS_LANGUAGE_NEUTRAL;
- -
- - //return isset($perms[$langcode]) ? (bool) $perms[$langcode] : NODE_ACCESS_DENY;
- - return isset($perms[$langcode]) ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY;
- }
- }
-
- /**
- * Implements hook_menu_alter().
- */
- -function i18n_access_menu_alter(&$items) {
- +
- +//make function name i18n_access_node_menu_alter
- +function i18n_access_node_menu_alter(&$items) {
- +
- + // due to hook_module_implementation_alter calling entity translation last, we can't change the callback here, i've done it in entity_translation.node.inc - consider calling it here?
- // Replace the translation overview page since we can't hook it.
- $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
- +
- }
-
- function i18n_access_translation_node_overview($node) {
-
- include_once DRUPAL_ROOT . '/includes/language.inc';
-
- - if (!empty($node->tnid)) {
- - // Already part of a set, grab that set.
- - $tnid = $node->tnid;
- - $translations = translation_node_get_translations($node->tnid);
- - }
- - else {
- - // We have no translation source nid, this could be a new set, emulate that.
- - $tnid = $node->nid;
- - $translations = array($node->language => $node);
- + // include functions from i18n_node.pages.inc
- + include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'i18n_node') . '/i18n_node.pages.inc';
- +
- + // this is the part where this thing sorts out how to build a list of existing translations for this node
- + // since we use entity translation, the tnid isn't what we're using to build the translation list. we're using node->translations->data[keys]
- + $available_translations = $node->translations->data;
- +
- + // iterate over each available translation and add its key (which is the 2 letter language code) to the array we call $translations with the node object as the value
- + foreach ($available_translations as $key => $value) {
- + $translations[$key] = $node;
- }
-
- $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
- +
- $header = array(t('Language'), t('Title'), t('Status'), t('Operations'));
-
- //added from i18n/i18n_node/i18n_node.pages.inc function
- @@ -240,9 +276,9 @@ function i18n_access_translation_node_overview($node) {
- $perms = i18n_access_load_permissions($account->uid);
- //end
-
- -
- // Modes have different allowed languages
- foreach (i18n_node_language_list($node) as $langcode => $language_name) {
- +
- if ($langcode == LANGUAGE_NONE) {
- // Never show language neutral on the overview.
- continue;
- @@ -253,16 +289,24 @@ function i18n_access_translation_node_overview($node) {
- // We load the full node to check whether the user can edit it.
- $translation_node = node_load($translations[$langcode]->nid);
- $path = 'node/' . $translation_node->nid;
- - $title = i18n_node_translation_link($translation_node->title, $path, $langcode);
- - if (node_access('update', $translation_node)) {
- +
- + // Account for title field module:
- + if (isset($translation_node->title_field) && isset($translation_node->title_field[$langcode])) {
- + $title = i18n_node_translation_link($translation_node->title_field[$langcode][0]['value'], $path, $langcode);
- + }
- + else {
- + $title = i18n_node_translation_link($translation_node->title, $path, $langcode);
- + }
- +
- + if (i18n_access_node_access($translation_node, 'update', $user, $langcode)) {
- $text = t('edit');
- $path = 'node/' . $translation_node->nid . '/edit';
- $options[] = i18n_node_translation_link($text, $path, $langcode);
- }
- $status = $translation_node->status ? t('Published') : t('Not published');
- - $status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : '';
- + $status .= $translation_node->translate ? ' - ' . t('outdated') . '' : '';
- if ($translation_node->nid == $tnid) {
- - $language_name = t('<strong>@language_name</strong> (source)', array('@language_name' => $language_name));
- + $language_name = t('@language_name (source)', array('@language_name' => $language_name));
- }
- }
- else {
- @@ -316,6 +360,52 @@ function i18n_access_menu() {
- }
-
- /**
- + * Node-specific menu alterations.
- + */
- +function i18n_access_menu_alter(&$items, $backup) {
- + if (isset($backup['node'])) {
- + $item = $backup['node'];
- + // Preserve the menu router item defined by other modules.
- + $callback['page callback'] = $item['page callback'];
- + $callback['file'] = $item['file'];
- + $callback['module'] = $item['module'];
- + $access_arguments = array_merge(array(1, $item['access callback']), $item['access arguments']);
- + }
- + else {
- + $access_arguments = array(1);
- + }
- +
- + // Point the 'translate' tab to point to the i18n_access version of the translation overview page
- + $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
- +
- + // There are 3 page arguments for the entity translation overview, only one for i18n_access:
- + $items['node/%node/translate']['page arguments'] = array(1);
- +
- + // Pass in the i18n_access permissions
- + $items['node/%node/translate']['access arguments'] = $access_arguments;
- +
- + // Point to i18n_access's include for the callback
- + $items['node/%node/translate']['file'] = 'i18n_access.module';
- +
- + // Point to i18n_access module
- + $items['node/%node/translate']['module'] = 'i18n_access';
- +}
- +
- +/**
- + * Implements hook_module_implements_alter().
- + */
- +function i18n_access_module_implements_alter(&$implementations, $hook) {
- + switch ($hook) {
- + case 'menu_alter':
- + // Move our hook_menu_alter implementation to the end of the list.
- + $group = $implementations['i18n_access'];
- + unset($implementations['i18n_access']);
- + $implementations['i18n_access'] = $group;
- + break;
- + }
- +}
- +
- +/**
- * Admin settings form
- */
- function i18n_access_admin_settings() {
- @@ -330,4 +420,4 @@ function i18n_access_admin_settings() {
- );
-
- return system_settings_form($form);
- -}
- \ No newline at end of file
- +}
|