user.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * @file
  4. * Provide diff functions for the user module.
  5. *
  6. * Note as users do not have revisions enabled, most use cases for comparisons
  7. * will be between two different users.
  8. */
  9. /**
  10. * Private callback function to render the name field.
  11. */
  12. function _user_entity_diff_additional_options_name($old_user, $new_user, $context) {
  13. $row = array(
  14. '#name' => t('Username'),
  15. '#states' => array(),
  16. '#weight' => -5,
  17. '#settings' => array(
  18. 'show_header' => variable_get('diff_show_header_user', 1),
  19. ),
  20. );
  21. foreach ($context['states'] as $state) {
  22. switch ($state) {
  23. case 'rendered':
  24. $row['#states'][$state] = array(
  25. '#old' => theme('username', array('account' => $old_user)),
  26. '#new' => theme('username', array('account' => $old_user)),
  27. );
  28. break;
  29. // We specify a default so that the name is always compared.
  30. case 'raw':
  31. default:
  32. $row['#states'][$state] = array(
  33. '#old' => array($old_user->name),
  34. '#new' => array($new_user->name),
  35. );
  36. break;
  37. }
  38. }
  39. return $row;
  40. }
  41. /**
  42. * Private callback function to render the mail field.
  43. */
  44. function _user_entity_diff_additional_options_mail($old_user, $new_user, $context) {
  45. $row = array(
  46. '#name' => t('E-mail address'),
  47. '#states' => array(),
  48. '#weight' => -4,
  49. '#settings' => array(),
  50. );
  51. foreach ($context['states'] as $state) {
  52. $row['#states'][$state] = array(
  53. '#old' => array($old_user->mail),
  54. '#new' => array($new_user->mail),
  55. );
  56. }
  57. return $row;
  58. }
  59. /**
  60. * Private callback function to render the status field.
  61. */
  62. function _user_entity_diff_additional_options_status($old_user, $new_user, $context) {
  63. $row = array(
  64. '#name' => t('Status'),
  65. '#states' => array(),
  66. '#weight' => -3,
  67. '#settings' => array(),
  68. );
  69. foreach ($context['states'] as $state) {
  70. $row['#states'][$state] = array(
  71. '#old' => array($old_user->status ? t('Active') : t('Blocked')),
  72. '#new' => array($new_user->status ? t('Active') : t('Blocked')),
  73. );
  74. }
  75. return $row;
  76. }
  77. /**
  78. * Private callback function to render the timezone field.
  79. */
  80. function _user_entity_diff_additional_options_timezone($old_user, $new_user, $context) {
  81. $row = array(
  82. '#name' => t('Time zone'),
  83. '#states' => array(),
  84. '#weight' => -1,
  85. '#settings' => array(),
  86. );
  87. $system_time_zones = system_time_zones(TRUE);
  88. $old_zone = isset($old_user->timezone) ? $old_user->timezone : '';
  89. $new_zone = isset($new_user->timezone) ? $new_user->timezone : '';
  90. foreach ($context['states'] as $state) {
  91. $row['#states'][$state] = array(
  92. '#old' => array(isset($system_time_zones[$old_zone]) ? $system_time_zones[$old_zone] : t('- None selected -')),
  93. '#new' => array(isset($system_time_zones[$new_zone]) ? $system_time_zones[$new_zone] : t('- None selected -')),
  94. );
  95. }
  96. return $row;
  97. }
  98. /**
  99. * Private callback function to render the password field.
  100. */
  101. function _user_entity_diff_additional_options_password($old_user, $new_user, $context) {
  102. $row = array(
  103. '#name' => t('Password Hash'),
  104. '#states' => array(),
  105. '#weight' => -1,
  106. '#settings' => array(),
  107. );
  108. foreach ($context['states'] as $state) {
  109. $row['#states'][$state] = array(
  110. '#old' => array($old_user->pass),
  111. '#new' => array($new_user->pass),
  112. );
  113. }
  114. return $row;
  115. }
  116. /**
  117. * Private callback function to render the roles field.
  118. */
  119. function _user_entity_diff_additional_options_roles($old_user, $new_user, $context) {
  120. $row = array(
  121. '#name' => t('Roles'),
  122. '#states' => array(),
  123. '#weight' => -1,
  124. '#settings' => array(),
  125. );
  126. $roles = user_roles(TRUE);
  127. unset($roles[DRUPAL_AUTHENTICATED_RID]);
  128. foreach ($context['states'] as $state) {
  129. $row['#states'][$state] = array(
  130. '#old' => array(implode("\n", array_intersect_key($roles, $old_user->roles))),
  131. '#new' => array(implode("\n", array_intersect_key($roles, $new_user->roles))),
  132. );
  133. }
  134. return $row;
  135. }