node.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * @file
  4. * Provide diff functions for the node module.
  5. */
  6. /**
  7. * Private callback function to render the title field.
  8. */
  9. function _node_entity_diff_additional_options_title($old_node, $new_node, $context) {
  10. $type = node_type_get_type($new_node);
  11. $row = array(
  12. '#name' => $type->title_label,
  13. '#states' => array(),
  14. '#weight' => -5,
  15. '#settings' => array(
  16. 'show_header' => variable_get('diff_show_header_node', 1),
  17. ),
  18. );
  19. foreach ($context['states'] as $state) {
  20. switch ($state) {
  21. case 'rendered':
  22. $row['#states'][$state] = array(
  23. '#old' => l($old_node->title, 'node/' . $old_node->title),
  24. '#new' => l($new_node->title, 'node/' . $new_node->title),
  25. );
  26. break;
  27. // We specify a default so that the title is allows compared.
  28. case 'raw':
  29. default:
  30. $row['#states'][$state] = array(
  31. '#old' => array($old_node->title),
  32. '#new' => array($new_node->title),
  33. );
  34. break;
  35. }
  36. }
  37. return $row;
  38. }
  39. /**
  40. * Private callback function to render the type field.
  41. */
  42. function _node_entity_diff_additional_options_type($old_node, $new_node, $context) {
  43. $row = array(
  44. '#name' => t('Content type'),
  45. '#states' => array(),
  46. '#weight' => -4,
  47. '#settings' => array(),
  48. );
  49. $old_type = node_type_get_type($old_node);
  50. $new_type = node_type_get_type($new_node);
  51. foreach ($context['states'] as $state) {
  52. $row['#states'][$state] = array(
  53. '#old' => array($old_type ? $old_type->name : t('Deleted type !type', array('!type' => $old_node->type))),
  54. '#new' => array($new_type ? $new_type->name : t('Deleted type !type', array('!type' => $new_node->type))),
  55. );
  56. }
  57. return $row;
  58. }
  59. /**
  60. * Private callback function to render the author field.
  61. */
  62. function _node_entity_diff_additional_options_author($old_node, $new_node, $context) {
  63. $old_author = user_load($old_node->uid);
  64. $new_author = user_load($new_node->uid);
  65. return _node_entity_diff_additional_options_account(t('Author'), $old_author, $new_author, $context, -4);
  66. }
  67. /**
  68. * Private callback function to render the revision_author field.
  69. */
  70. function _node_entity_diff_additional_options_revision_author($old_node, $new_node, $context) {
  71. $old_author = user_load($old_node->revision_uid);
  72. $new_author = user_load($new_node->revision_uid);
  73. return _node_entity_diff_additional_options_account(t('Revision author'), $old_author, $new_author, $context, -3.9);
  74. }
  75. /**
  76. * Private callback function to render the author field.
  77. */
  78. function _node_entity_diff_additional_options_account($label, $old_author, $new_author, $context, $weight = 0) {
  79. $row = array(
  80. '#name' => $label,
  81. '#states' => array(),
  82. '#weight' => $weight,
  83. '#settings' => array(),
  84. );
  85. foreach ($context['states'] as $state) {
  86. $row['#states'][$state] = array(
  87. '#old' => array($old_author ? format_username($old_author) : t('Deleted user')),
  88. '#new' => array($new_author ? format_username($new_author) : t('Deleted user')),
  89. );
  90. }
  91. return $row;
  92. }
  93. /**
  94. * Private callback function to render the status, sticky and published field.
  95. */
  96. function _node_entity_diff_additional_options_publishing_flags($old_node, $new_node, $context) {
  97. $row = array(
  98. '#name' => t('Publishing options'),
  99. '#states' => array(),
  100. '#weight' => -3,
  101. '#settings' => array(),
  102. );
  103. $old_options = array($old_node->status ? t('Published') : t('Unpublished'));
  104. if ($old_node->promote) {
  105. $old_options[] = t('Promoted to front page');
  106. }
  107. if ($old_node->sticky) {
  108. $old_options[] = t('Sticky at top of lists');
  109. }
  110. $new_options = array($new_node->status ? t('Published') : t('Unpublished'));
  111. if ($new_node->promote) {
  112. $new_options[] = t('Promoted to front page');
  113. }
  114. if ($new_node->sticky) {
  115. $new_options[] = t('Sticky at top of lists');
  116. }
  117. foreach ($context['states'] as $state) {
  118. $row['#states'][$state] = array(
  119. '#old' => $old_options,
  120. '#new' => $new_options,
  121. );
  122. }
  123. return $row;
  124. }
  125. /**
  126. * Private callback function to render the created field.
  127. */
  128. function _node_entity_diff_additional_options_created($old_node, $new_node, $context) {
  129. return _node_entity_diff_additional_options_date_field(t('Created timestamp'), $old_node->created, $new_node->created, $context, -1);
  130. }
  131. /**
  132. * Private callback function to render the changed field.
  133. */
  134. function _node_entity_diff_additional_options_changed($old_node, $new_node, $context) {
  135. return _node_entity_diff_additional_options_date_field(t('Changed timestamp'), $old_node->changed, $new_node->changed, $context, -1);
  136. }
  137. /**
  138. * Private callback function to render the revision_timestamp field.
  139. */
  140. function _node_entity_diff_additional_options_revision_timestamp($old_node, $new_node, $context) {
  141. return _node_entity_diff_additional_options_date_field(t('Revision timestamp'), $old_node->revision_timestamp, $new_node->revision_timestamp, $context, -1);
  142. }
  143. /**
  144. * Helper function to render the date flags.
  145. */
  146. function _node_entity_diff_additional_options_date_field($label, $old_date, $new_date, $context, $weight = 0) {
  147. $row = array(
  148. '#name' => $label,
  149. '#states' => array(),
  150. '#weight' => $weight,
  151. '#settings' => array(),
  152. );
  153. foreach ($context['states'] as $state) {
  154. $row['#states'][$state] = array(
  155. '#old' => array(format_date($old_date)),
  156. '#new' => array(format_date($new_date)),
  157. );
  158. }
  159. return $row;
  160. }
  161. /**
  162. * Private callback function to render the comment field.
  163. */
  164. function _node_entity_diff_additional_options_comment($old_node, $new_node, $context) {
  165. if (!module_exists('comment')) {
  166. return array();
  167. }
  168. $row = array(
  169. '#name' => t('Comment setting'),
  170. '#states' => array(),
  171. '#weight' => -1,
  172. '#settings' => array(),
  173. );
  174. $options = array(
  175. COMMENT_NODE_OPEN => t('Open'),
  176. COMMENT_NODE_CLOSED => t('Closed'),
  177. COMMENT_NODE_HIDDEN => t('Hidden'),
  178. );
  179. foreach ($context['states'] as $state) {
  180. $row['#states'][$state] = array(
  181. '#old' => array($options[$old_node->comment]),
  182. '#new' => array($options[$new_node->comment]),
  183. );
  184. }
  185. return $row;
  186. }