| 1 |
<?php |
<?php |
| 2 |
// $Id: xmlsitemap.module,v 1.20.2.43 2008/12/26 10:22:54 kiam Exp $ |
// $Id: xmlsitemap.module,v 1.20.2.44 2008/12/27 15:09:19 kiam Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 78 |
case 'admin/settings/xmlsitemap/engines': |
case 'admin/settings/xmlsitemap/engines': |
| 79 |
$output = t('Configure the behavior for search engines.'); |
$output = t('Configure the behavior for search engines.'); |
| 80 |
break; |
break; |
| 81 |
|
case 'admin/settings/xmlsitemap/tools/update': |
| 82 |
|
$output = t('Update the XML Sitemap database tables.'); |
| 83 |
|
break; |
| 84 |
case 'admin/help#xmlsitemap': |
case 'admin/help#xmlsitemap': |
| 85 |
$output = '<p>'. t('XML Sitemap automatically creates a site map that conforms to the <a href="@sitemaps.org">sitemaps.org specification</a>. This helps search engines keep their search results up to date.', array('@sitemaps.org' => 'http://www.sitemaps.org')) .'</p>'; |
$output = '<p>'. t('XML Sitemap automatically creates a site map that conforms to the <a href="@sitemaps.org">sitemaps.org specification</a>. This helps search engines keep their search results up to date.', array('@sitemaps.org' => 'http://www.sitemaps.org')) .'</p>'; |
| 86 |
$output .= '<h3>'. t('Supporting modules') .'</h3>'; |
$output .= '<h3>'. t('Supporting modules') .'</h3>'; |
| 124 |
$access_content = array('access content'); |
$access_content = array('access content'); |
| 125 |
$items['admin/settings/xmlsitemap'] = array( |
$items['admin/settings/xmlsitemap'] = array( |
| 126 |
'title' => 'XML Sitemap', |
'title' => 'XML Sitemap', |
| 127 |
'description' => 'Configure the site map.', |
'description' => 'Configure the XML site map.', |
| 128 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 129 |
'page arguments' => array('xmlsitemap_settings_sitemap'), |
'page arguments' => array('xmlsitemap_settings_sitemap'), |
| 130 |
'access arguments' => $access_config, |
'access arguments' => $access_config, |
|
'file' => 'includes/xmlsitemap.admin.inc', |
|
| 131 |
); |
); |
| 132 |
$items['admin/settings/xmlsitemap/sitemap'] = array( |
$items['admin/settings/xmlsitemap/sitemap'] = array( |
| 133 |
'title' => 'Site map', |
'title' => 'Site map', |
| 134 |
'description' => 'Configure the XML site map.', |
'description' => 'Configure the XML site map.', |
| 135 |
'weight' => -1, |
'weight' => -1, |
| 136 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
'file' => 'includes/xmlsitemap.admin.inc', |
|
| 137 |
); |
); |
| 138 |
$items['admin/settings/xmlsitemap/engines'] = array( |
$items['admin/settings/xmlsitemap/engines'] = array( |
| 139 |
'title' => 'Search engines', |
'title' => 'Search engines', |
| 142 |
'page arguments' => array('xmlsitemap_settings_engines'), |
'page arguments' => array('xmlsitemap_settings_engines'), |
| 143 |
'access arguments' => $access_config, |
'access arguments' => $access_config, |
| 144 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 145 |
'file' => 'includes/xmlsitemap.admin.inc', |
); |
| 146 |
|
$items['admin/settings/xmlsitemap/tools'] = array( |
| 147 |
|
'title' => 'Tools', |
| 148 |
|
'page callback' => 'drupal_get_form', |
| 149 |
|
'page arguments' => array('xmlsitemap_tools_update_database'), |
| 150 |
|
'access arguments' => $access_config, |
| 151 |
|
'type' => MENU_LOCAL_TASK, |
| 152 |
|
); |
| 153 |
|
$items['admin/settings/xmlsitemap/tools/update'] = array( |
| 154 |
|
'title' => 'Database update', |
| 155 |
|
'description' => 'Update the XML Sitemap database tables.', |
| 156 |
|
'page callback' => 'drupal_get_form', |
| 157 |
|
'page arguments' => array('xmlsitemap_tools_update_database'), |
| 158 |
|
'access arguments' => $access_config, |
| 159 |
|
'weight' => -1, |
| 160 |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 161 |
); |
); |
| 162 |
$items['sitemap.xml'] = array( |
$items['sitemap.xml'] = array( |
| 163 |
'title' => 'Site map index', |
'title' => 'Site map index', |
| 164 |
'page callback' => 'xmlsitemap_output', |
'page callback' => 'xmlsitemap_output', |
| 165 |
'access arguments' => $access_content, |
'access arguments' => $access_content, |
| 166 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
|
'file' => 'includes/xmlsitemap.pages.inc', |
|
| 167 |
); |
); |
| 168 |
$chunk_size = variable_get('xmlsitemap_chunk_size', 50000); |
$chunk_size = variable_get('xmlsitemap_chunk_size', 50000); |
| 169 |
$link_count = _xmlsitemap_link_count(); |
$link_count = _xmlsitemap_link_count(); |
| 173 |
'title' => 'Site map !number', |
'title' => 'Site map !number', |
| 174 |
'title arguments' => array('!number' => $chunk), |
'title arguments' => array('!number' => $chunk), |
| 175 |
'page callback' => 'xmlsitemap_output', |
'page callback' => 'xmlsitemap_output', |
| 176 |
'page arguments' => array((string)$chunk), |
'page arguments' => array((string) $chunk), |
| 177 |
'access arguments' => $access_content, |
'access arguments' => $access_content, |
| 178 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
|
'file' => 'includes/xmlsitemap.pages.inc', |
|
| 179 |
); |
); |
| 180 |
} |
} |
| 181 |
} |
} |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
/***************************************************************************** |
/***************************************************************************** |
| 186 |
|
* Menu callbacks / form builders, submit/validate functions. |
| 187 |
|
****************************************************************************/ |
| 188 |
|
|
| 189 |
|
/** |
| 190 |
|
* Menu callback; display the site map. |
| 191 |
|
* @param $chunk |
| 192 |
|
* An integer specifying which chunk of the site map is being requested. |
| 193 |
|
* If not set and there is more than one chunk, display the site map index. |
| 194 |
|
*/ |
| 195 |
|
function xmlsitemap_output($chunk = NULL) { |
| 196 |
|
if (variable_get('xmlsitemap_update', FALSE)) { |
| 197 |
|
_xmlsitemap_update(); |
| 198 |
|
} |
| 199 |
|
drupal_set_header('Content-type: text/xml; charset=utf-8'); |
| 200 |
|
$chunk_size = variable_get('xmlsitemap_chunk_size', 50000); |
| 201 |
|
if (isset($chunk)) { |
| 202 |
|
$link_count = _xmlsitemap_link_count(); |
| 203 |
|
if ($chunk < $link_count / $chunk_size) { |
| 204 |
|
_xmlsitemap_output_chunk($chunk); |
| 205 |
|
} |
| 206 |
|
else { |
| 207 |
|
drupal_not_found(); |
| 208 |
|
} |
| 209 |
|
} |
| 210 |
|
else { |
| 211 |
|
if ($link_count > $chunk_size) { |
| 212 |
|
_xmlsitemap_output_index(); |
| 213 |
|
} |
| 214 |
|
else { |
| 215 |
|
_xmlsitemap_output_chunk(); |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
drupal_page_footer(); |
| 219 |
|
exit; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
/** |
| 223 |
|
* Menu callback; return the search engine settings form. |
| 224 |
|
*/ |
| 225 |
|
function xmlsitemap_settings_engines() { |
| 226 |
|
$form['submission'] = array( |
| 227 |
|
'#type' => 'fieldset', |
| 228 |
|
'#title' => t('Submission settings'), |
| 229 |
|
'#collapsible' => TRUE, |
| 230 |
|
); |
| 231 |
|
$form['submission']['xmlsitemap_submit'] = array( |
| 232 |
|
'#type' => 'checkbox', |
| 233 |
|
'#title' => t('Submit the site map when updated.'), |
| 234 |
|
'#default_value' => variable_get('xmlsitemap_submit', FALSE), |
| 235 |
|
'#description' => t('If enabled, the search engines will be notified of changes to the site map each time it is updated.'), |
| 236 |
|
); |
| 237 |
|
$form['submission']['xmlsitemap_cron_submit'] = array( |
| 238 |
|
'#type' => 'checkbox', |
| 239 |
|
'#title' => t('Submit the site map on cron run.'), |
| 240 |
|
'#default_value' => variable_get('xmlsitemap_cron_submit', FALSE), |
| 241 |
|
'#description' => t('If enabled, the search engines will be notified of changes to the site map each time cron is run.'), |
| 242 |
|
); |
| 243 |
|
$form['submission']['xmlsitemap_log_access'] = array( |
| 244 |
|
'#type' => 'checkbox', |
| 245 |
|
'#title' => t('Log access.'), |
| 246 |
|
'#default_value' => variable_get('xmlsitemap_log_access', FALSE), |
| 247 |
|
'#description' => t('If enabled, a watchdog entry will be made each time the site map is accessed, containing information about the requestor.'), |
| 248 |
|
); |
| 249 |
|
drupal_alter('xmlsitemap_engine_settings', $form); |
| 250 |
|
$form = system_settings_form($form); |
| 251 |
|
array_unshift($form['#submit'], 'xmlsitemap_settings_engines_submit'); |
| 252 |
|
return $form; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
/** |
| 256 |
|
* Submit the search engine settings form. |
| 257 |
|
*/ |
| 258 |
|
function xmlsitemap_settings_engines_submit($form, &$form_state) { |
| 259 |
|
menu_rebuild(); |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
/** |
| 263 |
|
* Menu callback; return the site map settings form. |
| 264 |
|
*/ |
| 265 |
|
function xmlsitemap_settings_sitemap() { |
| 266 |
|
$form['xmlsitemap_chunk_size'] = array( |
| 267 |
|
'#type' => 'textfield', |
| 268 |
|
'#title' => t('Chunk size'), |
| 269 |
|
'#default_value' => variable_get('xmlsitemap_chunk_size', 50000), |
| 270 |
|
'#size' => 10, |
| 271 |
|
'#maxlength' => 5, |
| 272 |
|
'#description' => t('This is the number of links to include in one site map. Values can range between 1 and 50,000. If the total number of links exceeds the chunk size, multiple site maps will be generated.'), |
| 273 |
|
'#weight' => -1, |
| 274 |
|
); |
| 275 |
|
$form['xmlsitemap_front_page_priority'] = array( |
| 276 |
|
'#type' => 'select', |
| 277 |
|
'#title' => t('Front page priority'), |
| 278 |
|
'#default_value' => variable_get('xmlsitemap_front_page_priority', 1), |
| 279 |
|
'#options' => xmlsitemap_priority_options(), |
| 280 |
|
'#description' => t('This is the absolute priority for the front page.'), |
| 281 |
|
'#weight' => -1, |
| 282 |
|
); |
| 283 |
|
drupal_alter('xmlsitemap_sitemap_settings', $form); |
| 284 |
|
$form = system_settings_form($form); |
| 285 |
|
$form['#submit'][] = 'xmlsitemap_settings_sitemap_submit'; |
| 286 |
|
return $form; |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
/** |
| 290 |
|
* Validate the site map settings form. |
| 291 |
|
*/ |
| 292 |
|
function xmlsitemap_settings_sitemap_validate($form, &$form_state) { |
| 293 |
|
if ($form_state['values']['xmlsitemap_chunk_size'] > 50000) { |
| 294 |
|
form_set_error('xmlsitemap_chunk_size', t('The number of links in a site map cannot be higher than 50,000.')); |
| 295 |
|
} |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
/** |
| 299 |
|
* Menu callback; return the update database form. |
| 300 |
|
*/ |
| 301 |
|
function xmlsitemap_tools_update_database() { |
| 302 |
|
$options = array(); |
| 303 |
|
foreach (module_implements('xmlsitemap_database_batch_operation') as $module) { |
| 304 |
|
$options[$module] = $module .'.module'; |
| 305 |
|
} |
| 306 |
|
if (empty($options)) { |
| 307 |
|
$form['xmlsitemap_description'] = array( |
| 308 |
|
'#prefix' => '<div>', |
| 309 |
|
'#suffix' => '</div>', |
| 310 |
|
'#value' => t('There is no module which implements the required code to update its own internal database tables.'), |
| 311 |
|
); |
| 312 |
|
} |
| 313 |
|
else { |
| 314 |
|
$form['xmlsitemap_database_modules'] = array( |
| 315 |
|
'#type' => 'select', |
| 316 |
|
'#title' => t('XML Sitemap modules'), |
| 317 |
|
'#options' => $options, |
| 318 |
|
'#description' => t('The drop-down menu lists all the modules which save links in the site map, and which implement the required code to update their own database tables; select the module that needs to update its database tables.'), |
| 319 |
|
); |
| 320 |
|
$form['submit'] = array( |
| 321 |
|
'#type' => 'submit', |
| 322 |
|
'#value' => t('Continue'), |
| 323 |
|
); |
| 324 |
|
} |
| 325 |
|
return $form; |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
function xmlsitemap_tools_update_database_submit($form, &$form_state) { |
| 329 |
|
$module = $form_state['values']['xmlsitemap_database_modules']; |
| 330 |
|
$function = $module .'_xmlsitemap_database_batch_operation'; |
| 331 |
|
if (function_exists($function)) { |
| 332 |
|
$database_batch = $function(); |
| 333 |
|
if (isset($database_batch['update function'])) { |
| 334 |
|
$batch['operations'][] = array($database_batch['update function'], array()); |
| 335 |
|
} |
| 336 |
|
$batch['operations'][] = array($database_batch['add function'], array()); |
| 337 |
|
$batch['file'] = drupal_get_path('module', $module) .'/'. $database_batch['file']; |
| 338 |
|
if (isset($database_batch['final callback'])) { |
| 339 |
|
$final_callback = $database_batch['final callback']; |
| 340 |
|
} |
| 341 |
|
else { |
| 342 |
|
$final_callback = 'xmlsitemap_database_update_finished'; |
| 343 |
|
} |
| 344 |
|
$batch['finished'] = $final_callback; |
| 345 |
|
batch_set($batch); |
| 346 |
|
|
| 347 |
|
} |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
/***************************************************************************** |
| 351 |
* Public functions. |
* Public functions. |
| 352 |
****************************************************************************/ |
****************************************************************************/ |
| 353 |
|
|
| 354 |
/** |
/** |
| 355 |
|
* Function called when the database batch is finished. |
| 356 |
|
* @param $success |
| 357 |
|
* TRUE if the batch operation has been concluded sucessfully, FALSE otherwise. |
| 358 |
|
* @param $results |
| 359 |
|
* The values returned from the batch function(s). |
| 360 |
|
* @param $operations |
| 361 |
|
* The array of operations that remained unprocessed. |
| 362 |
|
*/ |
| 363 |
|
function xmlsitemap_database_update_finished($success, $results, $operations) { |
| 364 |
|
if ($success) { |
| 365 |
|
if (!empty($results['add'])) { |
| 366 |
|
drupal_set_message( |
| 367 |
|
format_plural($results['add'], 'Added 1 row.', 'Added @count rows.') |
| 368 |
|
); |
| 369 |
|
} |
| 370 |
|
if (!empty($results['update'])) { |
| 371 |
|
drupal_set_message( |
| 372 |
|
format_plural($results['update'], 'Updated 1 row.', 'Updated @count rows.') |
| 373 |
|
); |
| 374 |
|
} |
| 375 |
|
} |
| 376 |
|
else { |
| 377 |
|
$error_operation = reset($operations); |
| 378 |
|
$message = 'An error occurred while processing '. $error_operation[0] .' with arguments :'. print_r($error_operation[0], TRUE); |
| 379 |
|
drupal_set_message($message); |
| 380 |
|
} |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
/** |
| 384 |
* Determine the frequency of updates to a link. |
* Determine the frequency of updates to a link. |
| 385 |
* @param $interval |
* @param $interval |
| 386 |
* The number of seconds since the last change, or the number of seconds |
* The number of seconds since the last change, or the number of seconds |