1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Pathauto integration for core modules. |
---|
6 | * |
---|
7 | * @ingroup pathauto |
---|
8 | */ |
---|
9 | |
---|
10 | /** |
---|
11 | * Implements hook_pathauto(). |
---|
12 | */ |
---|
13 | function _node_pathauto($op) { |
---|
14 | switch ($op) { |
---|
15 | case 'settings': |
---|
16 | $settings = array(); |
---|
17 | $settings['module'] = 'node'; |
---|
18 | $settings['token_type'] = 'node'; |
---|
19 | $settings['groupheader'] = t('Node paths'); |
---|
20 | $settings['patterndescr'] = t('Default path pattern (applies to all node types with blank patterns below)'); |
---|
21 | $settings['patterndefault'] = 'content/[title-raw]'; |
---|
22 | $settings['batch_update_callback'] = 'node_pathauto_bulk_update_batch_process'; |
---|
23 | $settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc'; |
---|
24 | |
---|
25 | $languages = array(); |
---|
26 | if (module_exists('locale')) { |
---|
27 | $languages = array('' => t('language neutral')) + locale_language_list('name'); |
---|
28 | } |
---|
29 | |
---|
30 | foreach (node_get_types('names') as $node_type => $node_name) { |
---|
31 | if (count($languages) && variable_get('language_content_type_'. $node_type, 0)) { |
---|
32 | $settings['patternitems'][$node_type] = t('Default path pattern for @node_type (applies to all @node_type node types with blank patterns below)', array('@node_type' => $node_name)); |
---|
33 | foreach ($languages as $lang_code => $lang_name) { |
---|
34 | $settings['patternitems'][$node_type . '_' . $lang_code] = t('Pattern for all @language @node_type paths', array('@node_type' => $node_name, '@language' => $lang_name)); |
---|
35 | } |
---|
36 | } |
---|
37 | else { |
---|
38 | $settings['patternitems'][$node_type] = t('Pattern for all @node_type paths', array('@node_type' => $node_name)); |
---|
39 | } |
---|
40 | } |
---|
41 | return (object) $settings; |
---|
42 | default: |
---|
43 | break; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Batch processing callback; Generate aliases for nodes. |
---|
49 | */ |
---|
50 | function node_pathauto_bulk_update_batch_process(&$context) { |
---|
51 | if (!isset($context['sandbox']['current'])) { |
---|
52 | $context['sandbox']['count'] = 0; |
---|
53 | $context['sandbox']['current'] = 0; |
---|
54 | } |
---|
55 | |
---|
56 | $concat = _pathauto_sql_concat("'node/'", 'n.nid'); |
---|
57 | $sql = "SELECT n.nid FROM {node} n LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND n.nid > %d ORDER BY n.nid"; |
---|
58 | $args = array($context['sandbox']['current']); |
---|
59 | |
---|
60 | // Get the total amount of items to process. |
---|
61 | if (!isset($context['sandbox']['total'])) { |
---|
62 | $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args)); |
---|
63 | |
---|
64 | // If there are no nodes to update, the stop immediately. |
---|
65 | if (!$context['sandbox']['total']) { |
---|
66 | $context['finished'] = 1; |
---|
67 | return; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | $query = db_query_range($sql, $args, 0, 25); |
---|
72 | $nids = array(); |
---|
73 | while ($nid = db_result($query)) { |
---|
74 | $nids[] = $nid; |
---|
75 | } |
---|
76 | |
---|
77 | pathauto_node_update_alias_multiple($nids, 'bulkupdate'); |
---|
78 | $context['sandbox']['count'] += count($nids); |
---|
79 | $context['sandbox']['current'] = max($nids); |
---|
80 | $context['message'] = t('Updated alias for node @nid.', array('@nid' => end($nids))); |
---|
81 | |
---|
82 | if ($context['sandbox']['count'] >= $context['sandbox']['total']) { |
---|
83 | $context['finished'] = 1; |
---|
84 | } |
---|
85 | else { |
---|
86 | $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total']; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Implements hook_pathauto(). |
---|
92 | */ |
---|
93 | function _taxonomy_pathauto($op) { |
---|
94 | switch ($op) { |
---|
95 | case 'settings': |
---|
96 | $settings = array(); |
---|
97 | $settings['module'] = 'taxonomy'; |
---|
98 | $settings['token_type'] = 'taxonomy'; |
---|
99 | $settings['groupheader'] = t('Taxonomy term paths'); |
---|
100 | $settings['patterndescr'] = t('Default path pattern (applies to all vocabularies with blank patterns below)'); |
---|
101 | $settings['patterndefault'] = '[vocab-raw]/[catpath-raw]'; |
---|
102 | $settings['batch_update_callback'] = 'taxonomy_pathauto_bulk_update_batch_process'; |
---|
103 | $settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc'; |
---|
104 | |
---|
105 | $vocabularies = taxonomy_get_vocabularies(); |
---|
106 | if (count($vocabularies)) { |
---|
107 | $settings['patternitems'] = array(); |
---|
108 | foreach ($vocabularies as $vid => $vocabulary) { |
---|
109 | if ($vid == variable_get('forum_nav_vocabulary', '')) { |
---|
110 | // Skip the forum vocabulary. |
---|
111 | continue; |
---|
112 | } |
---|
113 | $settings['patternitems'][$vid] = t('Pattern for all %vocab-name paths', array('%vocab-name' => $vocabulary->name)); |
---|
114 | } |
---|
115 | } |
---|
116 | return (object) $settings; |
---|
117 | default: |
---|
118 | break; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * Batch processing callback; Generate aliases for taxonomy terms. |
---|
124 | */ |
---|
125 | function taxonomy_pathauto_bulk_update_batch_process(&$context) { |
---|
126 | if (!isset($context['sandbox']['current'])) { |
---|
127 | $context['sandbox']['count'] = 0; |
---|
128 | $context['sandbox']['current'] = 0; |
---|
129 | } |
---|
130 | |
---|
131 | $concat = _pathauto_sql_concat("'taxonomy/term/'", 't.tid'); |
---|
132 | $forum_vid = variable_get('forum_nav_vocabulary', ''); |
---|
133 | $sql = "SELECT t.tid FROM {term_data} t LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND t.tid > %d AND t.vid <> %d ORDER BY t.tid"; |
---|
134 | $args = array($context['sandbox']['current'], $forum_vid); |
---|
135 | |
---|
136 | // Get the total amount of items to process. |
---|
137 | if (!isset($context['sandbox']['total'])) { |
---|
138 | $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args)); |
---|
139 | |
---|
140 | // If there are no nodes to update, the stop immediately. |
---|
141 | if (!$context['sandbox']['total']) { |
---|
142 | $context['finished'] = 1; |
---|
143 | return; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | $query = db_query_range($sql, $args, 0, 25); |
---|
148 | $tids = array(); |
---|
149 | while ($tid = db_result($query)) { |
---|
150 | $tids[] = $tid; |
---|
151 | } |
---|
152 | |
---|
153 | pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate'); |
---|
154 | $context['sandbox']['count'] += count($tids); |
---|
155 | $context['sandbox']['current'] = max($tids); |
---|
156 | $context['message'] = t('Updated alias for term @tid.', array('@tid' => end($tids))); |
---|
157 | |
---|
158 | if ($context['sandbox']['count'] >= $context['sandbox']['total']) { |
---|
159 | $context['finished'] = 1; |
---|
160 | } |
---|
161 | else { |
---|
162 | $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total']; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * Implements hook_pathauto() for forum module. |
---|
168 | */ |
---|
169 | function _forum_pathauto($op) { |
---|
170 | switch ($op) { |
---|
171 | case 'settings': |
---|
172 | $settings = array(); |
---|
173 | $settings['module'] = 'forum'; |
---|
174 | $settings['token_type'] = 'taxonomy'; |
---|
175 | $settings['groupheader'] = t('Forum paths'); |
---|
176 | $settings['patterndescr'] = t('Pattern for forums and forum containers'); |
---|
177 | $settings['patterndefault'] = '[vocab-raw]/[catpath-raw]'; |
---|
178 | $settings['batch_update_callback'] = 'forum_pathauto_bulk_update_batch_process'; |
---|
179 | $settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc'; |
---|
180 | return (object) $settings; |
---|
181 | default: |
---|
182 | break; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * Batch processing callback; Generate aliases for forums. |
---|
188 | */ |
---|
189 | function forum_pathauto_bulk_update_batch_process(&$context) { |
---|
190 | if (!isset($context['sandbox']['current'])) { |
---|
191 | $context['sandbox']['count'] = 0; |
---|
192 | $context['sandbox']['current'] = 0; |
---|
193 | } |
---|
194 | |
---|
195 | $concat = _pathauto_sql_concat("'forum/'", 't.tid'); |
---|
196 | $forum_vid = variable_get('forum_nav_vocabulary', ''); |
---|
197 | $sql = "SELECT t.tid FROM {term_data} t LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND t.tid > %d AND t.vid = %d ORDER BY t.tid"; |
---|
198 | $args = array($context['sandbox']['current'], $forum_vid); |
---|
199 | |
---|
200 | // Get the total amount of items to process. |
---|
201 | if (!isset($context['sandbox']['total'])) { |
---|
202 | $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args)); |
---|
203 | |
---|
204 | // If there are no nodes to update, the stop immediately. |
---|
205 | if (!$context['sandbox']['total']) { |
---|
206 | $context['finished'] = 1; |
---|
207 | return; |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | $query = db_query_range($sql, $args, 0, 25); |
---|
212 | $tids = array(); |
---|
213 | while ($tid = db_result($query)) { |
---|
214 | $tids[] = $tid; |
---|
215 | } |
---|
216 | |
---|
217 | pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate'); |
---|
218 | $context['sandbox']['count'] += count($tids); |
---|
219 | $context['sandbox']['current'] = max($tids); |
---|
220 | $context['message'] = t('Updated alias for forum @tid.', array('@tid' => end($tids))); |
---|
221 | |
---|
222 | if ($context['sandbox']['count'] >= $context['sandbox']['total']) { |
---|
223 | $context['finished'] = 1; |
---|
224 | } |
---|
225 | else { |
---|
226 | $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total']; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | /** |
---|
231 | * Implements hook_pathauto(). |
---|
232 | */ |
---|
233 | function _user_pathauto($op) { |
---|
234 | switch ($op) { |
---|
235 | case 'settings': |
---|
236 | $settings = array(); |
---|
237 | $settings['module'] = 'user'; |
---|
238 | $settings['token_type'] = 'user'; |
---|
239 | $settings['groupheader'] = t('User paths'); |
---|
240 | $settings['patterndescr'] = t('Pattern for user account page paths'); |
---|
241 | $settings['patterndefault'] = 'users/[user-raw]'; |
---|
242 | $settings['batch_update_callback'] = 'user_pathauto_bulk_update_batch_process'; |
---|
243 | $settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc'; |
---|
244 | return (object) $settings; |
---|
245 | default: |
---|
246 | break; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | /** |
---|
251 | * Batch processing callback; Generate aliases for users. |
---|
252 | */ |
---|
253 | function user_pathauto_bulk_update_batch_process(&$context) { |
---|
254 | if (!isset($context['sandbox']['current'])) { |
---|
255 | $context['sandbox']['count'] = 0; |
---|
256 | $context['sandbox']['current'] = 0; |
---|
257 | } |
---|
258 | |
---|
259 | $concat = _pathauto_sql_concat("'user/'", 'u.uid'); |
---|
260 | $sql = "SELECT u.uid FROM {users} u LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND u.uid > %d ORDER BY u.uid"; |
---|
261 | $args = array($context['sandbox']['current']); |
---|
262 | |
---|
263 | // Get the total amount of items to process. |
---|
264 | if (!isset($context['sandbox']['total'])) { |
---|
265 | $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args)); |
---|
266 | |
---|
267 | // If there are no nodes to update, the stop immediately. |
---|
268 | if (!$context['sandbox']['total']) { |
---|
269 | $context['finished'] = 1; |
---|
270 | return; |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | $query = db_query_range($sql, $args, 0, 25); |
---|
275 | $uids = array(); |
---|
276 | while ($uid = db_result($query)) { |
---|
277 | $uids[] = $uid; |
---|
278 | } |
---|
279 | |
---|
280 | pathauto_user_update_alias_multiple($uids, 'bulkupdate', array('alias blog' => FALSE)); |
---|
281 | $context['sandbox']['count'] += count($uids); |
---|
282 | $context['sandbox']['current'] = max($uids); |
---|
283 | $context['message'] = t('Updated alias for user @uid.', array('@uid' => end($uids))); |
---|
284 | |
---|
285 | if ($context['sandbox']['count'] >= $context['sandbox']['total']) { |
---|
286 | $context['finished'] = 1; |
---|
287 | } |
---|
288 | else { |
---|
289 | $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total']; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * Implements hook_pathauto(). |
---|
295 | */ |
---|
296 | function _blog_pathauto($op) { |
---|
297 | switch ($op) { |
---|
298 | case 'settings': |
---|
299 | $settings = array(); |
---|
300 | $settings['module'] = 'blog'; |
---|
301 | $settings['token_type'] = 'user'; |
---|
302 | $settings['groupheader'] = t('Blog paths'); |
---|
303 | $settings['patterndescr'] = t('Pattern for blog page paths'); |
---|
304 | $settings['patterndefault'] = 'blogs/[user-raw]'; |
---|
305 | $settings['batch_update_callback'] = 'blog_pathauto_bulk_update_batch_process'; |
---|
306 | $settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc'; |
---|
307 | return (object) $settings; |
---|
308 | default: |
---|
309 | break; |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | /** |
---|
314 | * Batch processing callback; Generate aliases for blogs. |
---|
315 | */ |
---|
316 | function blog_pathauto_bulk_update_batch_process(&$context) { |
---|
317 | if (!isset($context['sandbox']['current'])) { |
---|
318 | $context['sandbox']['count'] = 0; |
---|
319 | $context['sandbox']['current'] = 0; |
---|
320 | } |
---|
321 | |
---|
322 | $concat = _pathauto_sql_concat("'blog/'", 'u.uid'); |
---|
323 | $sql = "SELECT u.uid FROM {users} u LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND u.uid > %d ORDER BY u.uid"; |
---|
324 | $args = array($context['sandbox']['current']); |
---|
325 | |
---|
326 | // Get the total amount of items to process. |
---|
327 | if (!isset($context['sandbox']['total'])) { |
---|
328 | $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args)); |
---|
329 | |
---|
330 | // If there are no nodes to update, the stop immediately. |
---|
331 | if (!$context['sandbox']['total']) { |
---|
332 | $context['finished'] = 1; |
---|
333 | return; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | $query = db_query_range($sql, $args, 0, 25); |
---|
338 | $uids = array(); |
---|
339 | while ($uid = db_result($query)) { |
---|
340 | $uids[] = $uid; |
---|
341 | $account = user_load($uid); |
---|
342 | pathauto_blog_update_alias($account, 'bulkupdate'); |
---|
343 | } |
---|
344 | |
---|
345 | $context['sandbox']['count'] += count($uids); |
---|
346 | $context['sandbox']['current'] = max($uids); |
---|
347 | $context['message'] = t('Updated alias for blog user @uid.', array('@uid' => end($uids))); |
---|
348 | |
---|
349 | if ($context['sandbox']['count'] >= $context['sandbox']['total']) { |
---|
350 | $context['finished'] = 1; |
---|
351 | } |
---|
352 | else { |
---|
353 | $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total']; |
---|
354 | } |
---|
355 | } |
---|