-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathxmlsitemap.api.php
337 lines (315 loc) · 9.57 KB
/
xmlsitemap.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* @file
* Hooks provided by the XML sitemap module.
*
* @ingroup xmlsitemap
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Provide information on the type of links this module provides.
*
* @see hook_entity_info()
* @see hook_entity_info_alter()
*/
function hook_xmlsitemap_link_info() {
return array(
'mymodule' => array(
'label' => 'My module',
'base table' => 'mymodule',
'entity keys' => array(
// Primary ID key on {base table}.
'id' => 'myid',
// Subtype key on {base table}.
'bundle' => 'mysubtype',
),
'path callback' => 'mymodule_path',
'bundle label' => t('Subtype name'),
'bundles' => array(
'mysubtype1' => array(
'label' => t('My subtype 1'),
'admin' => array(
'real path' => 'admin/settings/mymodule/mysubtype1/edit',
'access arguments' => array('administer mymodule'),
),
'xmlsitemap' => array(
'status' => XMLSITEMAP_STATUS_DEFAULT,
'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
),
),
),
'xmlsitemap' => array(
// Callback function to take an array of IDs and save them as sitemap
// links.
'process callback' => '',
// Callback function used in batch API for rebuilding all links.
'rebuild callback' => '',
// Callback function called from the XML sitemap settings page.
'settings callback' => '',
),
),
);
}
/**
* Act on a sitemap link being inserted or updated.
*
* This hook is currently invoked from xmlsitemap_node_node_update() before
* the node sitemap link is saved to the database with revoked access until
* the node permissions are checked in the cron.
*
* @param array $link
* An array with the data of the sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*/
function hook_xmlsitemap_link_presave_alter(array &$link, array $context) {
if ($link['type'] == 'mymodule') {
$link['priority'] += 0.5;
}
}
/**
* Alter the data of a sitemap link before the link is saved.
*
* @param array $link
* An array with the data of the sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*/
function hook_xmlsitemap_link_alter(array &$link, array $context) {
if ($link['type'] == 'mymodule') {
$link['priority'] += 0.5;
}
}
/**
* Inform modules that an XML sitemap link has been created.
*
* @param array $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
* An optional context array containing data related to the link.
*
* @see hook_xmlsitemap_link_update()
*/
function hook_xmlsitemap_link_insert(array $link, array $context) {
db_insert('mytable')
->fields(array(
'link_type' => $link['type'],
'link_id' => $link['id'],
'link_status' => $link['status'],
))
->execute();
}
/**
* Inform modules that an XML sitemap link has been updated.
*
* @param array $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
* An optional context array containing data related to the link.
*
* @see hook_xmlsitemap_link_insert()
*/
function hook_xmlsitemap_link_update(array $link, array $context) {
db_update('mytable')
->fields(array(
'link_type' => $link['type'],
'link_id' => $link['id'],
'link_status' => $link['status'],
))
->execute();
}
/**
* Respond to XML sitemap link clearing and rebuilding.
*
* @param array $types
* An array of link types that are being rebuilt.
* @param bool $save_custom
* If links with overridden status and/or priority are being removed or not.
*/
function hook_xmlsitemap_rebuild_clear(array $types, $save_custom) {
db_delete('mytable')
->condition('link_type', $types, 'IN')
->execute();
}
/**
* Respond to XML sitemap regeneration.
*/
function hook_xmlsitemap_regenerate_finished() {
}
/**
* Index links for the XML sitemaps.
*/
function hook_xmlsitemap_index_links($limit) {
}
/**
* Provide information about contexts available to XML sitemap.
*
* @see hook_xmlsitemap_context_info_alter()
*/
function hook_xmlsitemap_context_info() {
$info['vocabulary'] = array(
'label' => t('Vocabulary'),
'summary callback' => 'mymodule_xmlsitemap_vocabulary_context_summary',
'default' => 0,
);
return $info;
}
/**
* Alter XML sitemap context info.
*
* @see hook_xmlsitemap_context_info()
*/
function hook_xmlsitemap_context_info_alter(&$info) {
$info['vocabulary']['label'] = t('Site vocabularies');
}
/**
* Provide information about the current context on the site.
*
* @see hook_xmlsitemap_context_alter()
*/
function hook_xmlsitemap_context() {
$context = array();
if ($vid = mymodule_get_current_vocabulary()) {
$context['vocabulary'] = $vid;
}
return $context;
}
/**
* Alter the current context information.
*
* @see hook_xmlsitemap_context()
*/
function hook_xmlsitemap_context_alter(&$context) {
if (user_access('administer taxonomy')) {
unset($context['vocabulary']);
}
}
/**
* Provide options for the url() function based on an XML sitemap context.
*/
function hook_xmlsitemap_context_url_options(array $context) {
}
/**
* Alter the url() options based on an XML sitemap context.
*/
function hook_xmlsitemap_context_url_options_alter(array &$options, array $context) {
}
/**
* Alter the content added to an XML sitemap for an individual element.
*
* This hooks is called when the module is generating the XML content for the
* sitemap and allows other modules to alter existing or add additional XML data
* for any element by adding additional key value paris to the $element array.
*
* The key in the element array is then used as the name of the XML child
* element to add and the value is the value of that element. For example:
*
* @code $element['video:title'] = 'Big Ponycorn'; @endcode
*
* Would result in a child element like <video:title>Big Ponycorn</video:title>
* being added to the sitemap for this particular link.
*
* @param array $element
* The element that will be converted to XML for the link.
* @param array $link
* An array of properties providing context about the link that we are
* generating an XML element for.
* @param object $sitemap
* The sitemap that is currently being generated.
*/
function hook_xmlsitemap_element_alter(array &$element, array $link, $sitemap) {
if ($link['subtype'] === 'video') {
$node = node_load($link['id']);
$element['video:video'] = array(
'video:title' => check_plain($node->title),
'video:description' => isset($node->body[LANGUAGE_NONE][0]['summary']) ? check_plain($node->body[LANGUAGE_NONE][0]['summary']) : check_plain($node->body[LANGUAGE_NONE][0]['value']),
'video:live' => 'no',
);
}
}
/**
* Alter the attributes used for the root element of the XML sitemap.
*
* For example add an xmlns:video attribute:
*
* @code
* <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
* xmlns:video="https://www.google.com/schemas/sitemap-video/1.1">
* @endcode
*
* @param array $attributes
* An associative array of attributes to use in the root element of an XML
* sitemap.
* @param object $sitemap
* The sitemap that is currently being generated.
*/
function hook_xmlsitemap_root_attributes_alter(array &$attributes, $sitemap) {
$attributes['xmlns:video'] = 'https://www.google.com/schemas/sitemap-video/1.1';
}
/**
* Alter the query selecting data from {xmlsitemap} during sitemap generation.
*
* @param QueryAlterableInterface $query
* A Query object describing the composite parts of a SQL query.
*
* @see hook_query_TAG_alter()
*/
function hook_query_xmlsitemap_generate_alter(QueryAlterableInterface $query) {
$sitemap = $query->getMetaData('sitemap');
if (!empty($sitemap->context['vocabulary'])) {
$node_condition = db_and();
$node_condition->condition('type', 'taxonomy_term');
$node_condition->condition('subtype', $sitemap->context['vocabulary']);
$normal_condition = db_and();
$normal_condition->condition('type', 'taxonomy_term', '<>');
$condition = db_or();
$condition->condition($node_condition);
$condition->condition($normal_condition);
$query->condition($condition);
}
}
/**
* Provide information about XML sitemap bulk operations.
*/
function hook_xmlsitemap_sitemap_operations() {
}
/**
* Alter the edit link for users to include or exclude an entity.
*
* @param array $link
* The link to alter.
* ['href'] - The URI the user is sent to when clicking the link.
* ['title'] - The title of the link.
* ['modal'] - Whether or not the edit link shows up in a modal.
* ['query'] - A destination query parameter to send user back to after
* updating the entity settings.
*/
function hook_xmlsitemap_operation_link_alter(array &$link) {
// The XML Sitemap settings for the user entity are stored in a different
// place than entity_get_info() returns.
if ($link['href'] === 'admin/config/search/xmlsitemap/settings/user/user') {
$link['href'] = 'admin/config/people/settings';
}
}
/**
* Respond to XML sitemap deletion.
*
* This hook is invoked from xmlsitemap_sitemap_delete_multiple() after the XML
* sitemap has been removed from the table in the database.
*
* @param object $sitemap
* The XML sitemap object that was deleted.
*/
function hook_xmlsitemap_sitemap_delete(stdClass $sitemap) {
db_delete('mytable')
->condition('smid', $sitemap->smid, '=')
->execute();
}
/**
* @} End of "addtogroup hooks".
*/