Révision 661d64c9
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/diff/includes/node.inc | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Implements hook_entity_diff(). |
|
10 |
* |
|
11 |
* This function compares core node properties. This is currently limited to: |
|
12 |
* - title: The title of the node. |
|
13 |
* |
|
14 |
* @param object $old_node |
|
15 |
* The older node revision. |
|
16 |
* @param object $new_node |
|
17 |
* The newer node revision. |
|
18 |
* @param array $context |
|
19 |
* An associative array containing: |
|
20 |
* - entity_type: The entity type; e.g., 'node' or 'user'. |
|
21 |
* - old_entity: The older entity. |
|
22 |
* - new_entity: The newer entity. |
|
23 |
* - view_mode: The view mode to use. Defaults to FALSE. If no view mode is |
|
24 |
* given, the recommended fallback view mode is 'default'. |
|
25 |
* - states: An array of view states. These could be one of: |
|
26 |
* - raw: The raw value of the diff, the classic 7.x-2.x view. |
|
27 |
* - rendered: The rendered HTML as determined by the view mode. Only |
|
28 |
* return markup for this state if the value is normally shown |
|
29 |
* by this view mode. The user will most likely be able to see |
|
30 |
* the raw or raw_plain state, so this is optional. |
|
31 |
* |
|
32 |
* The rendering state is a work in progress. |
|
33 |
* |
|
34 |
* Conditionally, you can get these states, but setting these will override |
|
35 |
* the user selectable markdown method. |
|
36 |
* |
|
37 |
* - raw_plain: As raw, but text should be markdowned. |
|
38 |
* - rendered_plain: As rendered, but text should be markdowned. |
|
39 |
* |
|
40 |
* @return array |
|
41 |
* An associative array of values keyed by the entity property. |
|
42 |
* |
|
43 |
* This is effectively an unnested Form API-like structure. |
|
44 |
* |
|
45 |
* States are returned as follows: |
|
46 |
* |
|
47 |
* $results['line'] = array( |
|
48 |
* '#name' => t('Line'), |
|
49 |
* '#states' => array( |
|
50 |
* 'raw' => array( |
|
51 |
* '#old' => '<p class="line">This was the old line number [tag].</p>', |
|
52 |
* '#new' => '<p class="line">This is the new line [tag].</p>', |
|
53 |
* ), |
|
54 |
* 'rendered' => array( |
|
55 |
* '#old' => '<p class="line">This was the old line number <span class="line-number">57</span>.</p>', |
|
56 |
* '#new' => '<p class="line">This is the new line <span class="line-number">57</span>.</p>', |
|
57 |
* ), |
|
58 |
* ), |
|
59 |
* ); |
|
60 |
* |
|
61 |
* For backwards compatability, no changes are required to support states, |
|
62 |
* but it is recommended to provide a better UI for end users. |
|
63 |
* |
|
64 |
* For example, the following example is equivalent to returning the raw |
|
65 |
* state from the example above. |
|
66 |
* |
|
67 |
* $results['line'] = array( |
|
68 |
* '#name' => t('Line'), |
|
69 |
* '#old' => '<p class="line">This was the old line number [tag].</p>', |
|
70 |
* '#new' => '<p class="line">This is the new line [tag].</p>', |
|
71 |
* ); |
|
9 |
* Private callback function to render the title field. |
|
72 | 10 |
*/ |
73 |
function node_entity_diff($old_node, $new_node, $context) { |
|
74 |
$result = array(); |
|
75 |
if ($context['entity_type'] == 'node') { |
|
76 |
$type = node_type_get_type($new_node); |
|
77 |
$result['title'] = array( |
|
78 |
'#name' => $type->title_label, |
|
79 |
'#states' => array(), |
|
80 |
'#weight' => -5, |
|
81 |
'#settings' => array( |
|
82 |
// Global setting - 'diff_show_header_' . $entity_type |
|
83 |
'show_header' => variable_get('diff_show_header_node', 1), |
|
84 |
), |
|
85 |
); |
|
86 |
foreach ($context['states'] as $state) { |
|
87 |
switch ($state) { |
|
88 |
case 'rendered': |
|
89 |
$result['title']['#states'][$state] = array( |
|
90 |
'#old' => l($old_node->title, 'node/' . $old_node->title), |
|
91 |
'#new' => l($new_node->title, 'node/' . $new_node->title), |
|
92 |
); |
|
93 |
break; |
|
94 |
|
|
95 |
// We specify a default so that the title is allows compared. |
|
96 |
case 'raw': |
|
97 |
default: |
|
98 |
$result['title']['#states'][$state] = array( |
|
99 |
'#old' => array($old_node->title), |
|
100 |
'#new' => array($new_node->title), |
|
101 |
); |
|
102 |
break; |
|
103 |
} |
|
11 |
function _node_entity_diff_additional_options_title($old_node, $new_node, $context) { |
|
12 |
$type = node_type_get_type($new_node); |
|
13 |
$row = array( |
|
14 |
'#name' => $type->title_label, |
|
15 |
'#states' => array(), |
|
16 |
'#weight' => -5, |
|
17 |
'#settings' => array( |
|
18 |
'show_header' => variable_get('diff_show_header_node', 1), |
|
19 |
), |
|
20 |
); |
|
21 |
foreach ($context['states'] as $state) { |
|
22 |
switch ($state) { |
|
23 |
case 'rendered': |
|
24 |
$row['#states'][$state] = array( |
|
25 |
'#old' => l($old_node->title, 'node/' . $old_node->title), |
|
26 |
'#new' => l($new_node->title, 'node/' . $new_node->title), |
|
27 |
); |
|
28 |
break; |
|
29 |
|
|
30 |
// We specify a default so that the title is allows compared. |
|
31 |
case 'raw': |
|
32 |
default: |
|
33 |
$row['#states'][$state] = array( |
|
34 |
'#old' => array($old_node->title), |
|
35 |
'#new' => array($new_node->title), |
|
36 |
); |
|
37 |
break; |
|
104 | 38 |
} |
105 | 39 |
} |
106 |
return $result; |
|
40 |
return $row; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Private callback function to render the type field. |
|
45 |
*/ |
|
46 |
function _node_entity_diff_additional_options_type($old_node, $new_node, $context) { |
|
47 |
$row = array( |
|
48 |
'#name' => t('Content type'), |
|
49 |
'#states' => array(), |
|
50 |
'#weight' => -4, |
|
51 |
'#settings' => array(), |
|
52 |
); |
|
53 |
$old_type = node_type_get_type($old_node); |
|
54 |
$new_type = node_type_get_type($new_node); |
|
55 |
|
|
56 |
foreach ($context['states'] as $state) { |
|
57 |
$row['#states'][$state] = array( |
|
58 |
'#old' => array($old_type ? $old_type->name : t('Deleted type !type', array('!type' => $old_node->type))), |
|
59 |
'#new' => array($new_type ? $new_type->name : t('Deleted type !type', array('!type' => $new_node->type))), |
|
60 |
); |
|
61 |
} |
|
62 |
return $row; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Private callback function to render the author field. |
|
67 |
*/ |
|
68 |
function _node_entity_diff_additional_options_author($old_node, $new_node, $context) { |
|
69 |
$old_author = user_load($old_node->uid); |
|
70 |
$new_author = user_load($new_node->uid); |
|
71 |
return _node_entity_diff_additional_options_account(t('Author'), $old_author, $new_author, $context, -4); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Private callback function to render the revision_author field. |
|
76 |
*/ |
|
77 |
function _node_entity_diff_additional_options_revision_author($old_node, $new_node, $context) { |
|
78 |
$old_author = user_load($old_node->revision_uid); |
|
79 |
$new_author = user_load($new_node->revision_uid); |
|
80 |
return _node_entity_diff_additional_options_account(t('Revision author'), $old_author, $new_author, $context, -3.9); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Private callback function to render the author field. |
|
85 |
*/ |
|
86 |
function _node_entity_diff_additional_options_account($label, $old_author, $new_author, $context, $weight = 0) { |
|
87 |
$row = array( |
|
88 |
'#name' => $label, |
|
89 |
'#states' => array(), |
|
90 |
'#weight' => $weight, |
|
91 |
'#settings' => array(), |
|
92 |
); |
|
93 |
foreach ($context['states'] as $state) { |
|
94 |
$row['#states'][$state] = array( |
|
95 |
'#old' => array($old_author ? format_username($old_author) : t('Deleted user')), |
|
96 |
'#new' => array($new_author ? format_username($new_author) : t('Deleted user')), |
|
97 |
); |
|
98 |
} |
|
99 |
return $row; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Private callback function to render the status, sticky and published field. |
|
104 |
*/ |
|
105 |
function _node_entity_diff_additional_options_publishing_flags($old_node, $new_node, $context) { |
|
106 |
$row = array( |
|
107 |
'#name' => t('Publishing options'), |
|
108 |
'#states' => array(), |
|
109 |
'#weight' => -3, |
|
110 |
'#settings' => array(), |
|
111 |
); |
|
112 |
$old_options = array($old_node->status ? t('Published') : t('Unpublished')); |
|
113 |
if ($old_node->promote) { |
|
114 |
$old_options[] = t('Promoted to front page'); |
|
115 |
} |
|
116 |
if ($old_node->sticky) { |
|
117 |
$old_options[] = t('Sticky at top of lists'); |
|
118 |
} |
|
119 |
|
|
120 |
$new_options = array($new_node->status ? t('Published') : t('Unpublished')); |
|
121 |
if ($new_node->promote) { |
|
122 |
$new_options[] = t('Promoted to front page'); |
|
123 |
} |
|
124 |
if ($new_node->sticky) { |
|
125 |
$new_options[] = t('Sticky at top of lists'); |
|
126 |
} |
|
127 |
|
|
128 |
foreach ($context['states'] as $state) { |
|
129 |
$row['#states'][$state] = array( |
|
130 |
'#old' => $old_options, |
|
131 |
'#new' => $new_options, |
|
132 |
); |
|
133 |
} |
|
134 |
return $row; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Private callback function to render the created field. |
|
139 |
*/ |
|
140 |
function _node_entity_diff_additional_options_created($old_node, $new_node, $context) { |
|
141 |
return _node_entity_diff_additional_options_date_field(t('Created timestamp'), $old_node->created, $new_node->created, $context, -1); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Private callback function to render the changed field. |
|
146 |
*/ |
|
147 |
function _node_entity_diff_additional_options_changed($old_node, $new_node, $context) { |
|
148 |
return _node_entity_diff_additional_options_date_field(t('Changed timestamp'), $old_node->changed, $new_node->changed, $context, -1); |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Private callback function to render the revision_timestamp field. |
|
153 |
*/ |
|
154 |
function _node_entity_diff_additional_options_revision_timestamp($old_node, $new_node, $context) { |
|
155 |
return _node_entity_diff_additional_options_date_field(t('Revision timestamp'), $old_node->revision_timestamp, $new_node->revision_timestamp, $context, -1); |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Helper function to render the date flags. |
|
160 |
*/ |
|
161 |
function _node_entity_diff_additional_options_date_field($label, $old_date, $new_date, $context, $weight = 0) { |
|
162 |
$row = array( |
|
163 |
'#name' => $label, |
|
164 |
'#states' => array(), |
|
165 |
'#weight' => $weight, |
|
166 |
'#settings' => array(), |
|
167 |
); |
|
168 |
|
|
169 |
foreach ($context['states'] as $state) { |
|
170 |
$row['#states'][$state] = array( |
|
171 |
'#old' => array(format_date($old_date)), |
|
172 |
'#new' => array(format_date($new_date)), |
|
173 |
); |
|
174 |
} |
|
175 |
return $row; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Private callback function to render the comment field. |
|
180 |
*/ |
|
181 |
function _node_entity_diff_additional_options_comment($old_node, $new_node, $context) { |
|
182 |
if (!module_exists('comment')) { |
|
183 |
return array(); |
|
184 |
} |
|
185 |
$row = array( |
|
186 |
'#name' => t('Comment setting'), |
|
187 |
'#states' => array(), |
|
188 |
'#weight' => -1, |
|
189 |
'#settings' => array(), |
|
190 |
); |
|
191 |
$options = array( |
|
192 |
COMMENT_NODE_OPEN => t('Open'), |
|
193 |
COMMENT_NODE_CLOSED => t('Closed'), |
|
194 |
COMMENT_NODE_HIDDEN => t('Hidden'), |
|
195 |
); |
|
196 |
|
|
197 |
foreach ($context['states'] as $state) { |
|
198 |
$row['#states'][$state] = array( |
|
199 |
'#old' => array($options[$old_node->comment]), |
|
200 |
'#new' => array($options[$new_node->comment]), |
|
201 |
); |
|
202 |
} |
|
203 |
return $row; |
|
107 | 204 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules