diff -urp /users/wmostrey/Desktop/flag.old/flag.inc flag/flag.inc --- /users/wmostrey/Desktop/flag.old/flag.inc 2008-10-04 02:20:35.000000000 +0200 +++ flag/flag.inc 2008-10-14 01:20:29.000000000 +0200 @@ -737,11 +737,29 @@ class flag_node extends flag_flag { 'show_on_page' => TRUE, 'show_on_teaser' => TRUE, 'show_on_form' => FALSE, + 'i18n' => FALSE, ); } function options_form(&$form) { parent::options_form($form); + if(module_exists('translation') && $form['#flag']['content_type']=="node") { + if(arg(3)=="add") { + $form['i18n'] = array( + '#type' => 'checkbox', + '#title' => t("Internationzalition"), + '#default_value' => $this->i18n, + '#description' => t('If checked, the translation source will be flagged. If unchecked, only the selected node will be flagged. Once set, this setting can not be changed again.'), + ); + } + else { + $form['i18n'] = array( + '#type' => 'item', + '#title' => t("Internationzalition"), + '#value' => $this->i18n ? t("The translation source will be flagged.") : t("Only the selected node will be flagged."), + ); + } + } $form['display']['show_on_teaser'] = array( '#type' => 'checkbox', '#title' => t('Display link on node teaser'), @@ -839,7 +857,25 @@ class flag_node extends flag_flag { } return $passed; } - + + /** + * Return the node field to be used for flagging. + */ + function translation_get_field() { + return $this->i18n ? 'tnid' : 'nid'; + } + + /** + * Return the node ID field to be used for flagging. + * + * If the flag type is set to use the source translation for flagging, the {node}.tnid + * value will be returned if set. Otherwise, the {node}.nid value will be returned. + */ + function translation_get_value($node) { + $field = $this->translation_get_field(); + return (isset($node->$field) && !empty($node->$field)) ? $node->$field : $node->nid; + } + } /** diff -urp /users/wmostrey/Desktop/flag.old/flag.install flag/flag.install --- /users/wmostrey/Desktop/flag.old/flag.install 2008-09-30 05:08:49.000000000 +0200 +++ flag/flag.install 2008-10-14 16:07:42.000000000 +0200 @@ -68,6 +68,11 @@ function flag_requirements($phase) { $requirements['flag_content_clash']['severity'] = REQUIREMENT_ERROR; $requirements['flag_content_clash']['description'] = _flag_flag_content_message(); } + if(module_exists('translation') && !module_exists('translation_helpers')) { + $requirements['flag_translation']['title'] = $t('Flag'); + $requirements['flag_translation']['severity'] = REQUIREMENT_ERROR; + $requirements['flag_translation']['description'] = $t('To have the flag module work with translations, you need to install and enable the !url module.', array('!url' => l('translation_helpers', 'http://drupal.org/project/translation_helpers'))); + } } return $requirements; } diff -urp /users/wmostrey/Desktop/flag.old/flag.module flag/flag.module --- /users/wmostrey/Desktop/flag.old/flag.module 2008-10-03 17:32:07.000000000 +0200 +++ flag/flag.module 2008-10-14 15:30:48.000000000 +0200 @@ -251,21 +251,30 @@ function flag_nodeapi(&$node, $op, $teas if (isset($node->flag)) { foreach ($node->flag as $name => $state) { $flag = flag_get_flag($name); + $id = $flag->translation_get_value($node); // Flagging may trigger actions. We want actions to get the current // node, not a stale database-loaded one: if (!$remembered) { - $flag->remember_content($node->nid, $node); + $flag->remember_content($id, $node); // Actions may modify a node, and we don't want to overwrite this // modification: $remembered = TRUE; } - flag($state ? 'flag' : 'unflag', $name, $node->nid); + flag($state ? 'flag' : 'unflag', $name, $id); } } break; case 'delete': - db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND content_id = %d", $node->nid); - db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND content_id = %d", $node->nid); + db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND content_id = %d", $id); + db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND content_id = %d", $id); + break; + case 'translation_change': + if (isset($node->translation_change)) { + // If there is only one node remaining, track by nid rather than tnid. Otherwise, use the new tnid. + $new = $node->translation_change['new_tnid'] == 0 ? $node->translation_change['remaining_nid'] : $node->translation_change['new_tnid']; + db_query("UPDATE {flag_content} SET content_id = %d WHERE content_type = 'node' AND content_id = %d", $new, $node->translation_change['old_tnid']); + db_query("UPDATE {flag_counts} SET content_id = %d WHERE content_type = 'node' AND content_id = %d", $new, $node->translation_change['old_tnid']); + } break; } } @@ -331,14 +340,16 @@ function flag_admin_page() { )); $roles = array_flip(array_intersect(array_flip(user_roles()), $flag->roles)); - $rows[] = array( + $row = array( $flag->name, $flag->content_type, empty($flag->roles) ? '' . t('No roles') . '' : implode(', ', $roles), $flag->types ? implode(', ', $flag->types) : '-', $flag->global ? t('Yes') : t('No'), - $ops, ); + if (module_exists('translation') && $flag->content_type=="node") $row[] = $flag->i18n ? t('Yes') : t('No'); + $row[] = $ops; + $rows[] = $row; } if (!$flags) { $rows[] = array( @@ -346,7 +357,16 @@ function flag_admin_page() { ); } - $output .= theme('table', array(t('Flag'), t('Flag type'), t('Roles'), t('Node types'), t('Global?'), t('Operations')), $rows); + $titles = array( + t('Flag'), + t('Flag type'), + t('Roles'), + t('Node types'), + t('Global?'), + ); + if (module_exists('translation') && $flag->content_type=="node") $titles[] = t('Internationzalized?'); + $titles[] = t('Operations'); + $output .= theme('table', $titles, $rows); if (!module_exists('views')) { $output .= '
' . t('The Views module is not installed, or not enabled. It is recommended that you install the Views module to be able to easily produce lists of flagged content.', array('@views-url' => url('http://drupal.org/project/views'))) . '
';