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-10 12:16:11.000000000 +0200 @@ -737,11 +737,18 @@ 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); + $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.'), + ); $form['display']['show_on_teaser'] = array( '#type' => 'checkbox', '#title' => t('Display link on node teaser'), @@ -839,7 +846,27 @@ class flag_node extends flag_flag { } return $passed; } - + + /** + * Return the node field to be used for flagging. + */ + function translation_get_field() { + watchdog("test2", $this->i18n); + 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) { + watchdog("test1", $this->i18n); + $field = $this->translation_get_field(); + return (isset($node->$field) && !empty($node->$field)) ? $node->$field : $node->nid; + } + } /** 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-10 12:12:27.000000000 +0200 @@ -251,21 +251,22 @@ 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; } } @@ -337,6 +338,7 @@ function flag_admin_page() { empty($flag->roles) ? '' . t('No roles') . '' : implode(', ', $roles), $flag->types ? implode(', ', $flag->types) : '-', $flag->global ? t('Yes') : t('No'), + $flag->i18n ? t('Yes') : t('No'), $ops, ); } @@ -346,7 +348,7 @@ function flag_admin_page() { ); } - $output .= theme('table', array(t('Flag'), t('Flag type'), t('Roles'), t('Node types'), t('Global?'), t('Operations')), $rows); + $output .= theme('table', array(t('Flag'), t('Flag type'), t('Roles'), t('Node types'), t('Global?'), t('Internationzalized?'), t('Operations')), $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'))) . '

';