author | cavaliet@caf4f556-3d62-0410-8435-a86758001935 |
Fri, 21 Aug 2009 16:26:26 +0000 | |
branch | drupal |
changeset 74 | 0ff3ba646492 |
permissions | -rw-r--r-- |
74
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
1 |
<?php |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
2 |
// $Id: xmlsitemap.pages.inc,v 1.1.4.4 2009/07/02 14:20:24 earnie Exp $ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
3 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
4 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
5 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
6 |
* @file |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
7 |
* XML sitemap page callbacks. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
8 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
9 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
10 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
11 |
* @addtogroup xmlsitemap |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
12 |
* @{ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
13 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
14 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
15 |
/***************************************************************************** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
16 |
* Menu callbacks / form builders, submit/validate functions. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
17 |
****************************************************************************/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
18 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
19 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
20 |
* Menu callback; display the sitemap. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
21 |
* |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
22 |
* @param $chunk |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
23 |
* An integer specifying which chunk of the sitemap is being requested. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
24 |
* If not set and there is more than one chunk, display the sitemap index. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
25 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
26 |
function xmlsitemap_output($chunk = NULL) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
27 |
global $user; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
28 |
$chunk_size = variable_get('xmlsitemap_chunk_size', XMLSITEMAP_DEFAULT_SITEMAP_LINKS); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
29 |
$link_count = xmlsitemap_link_count(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
30 |
$chunk_count = xmlsitemap_chunk_count(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
31 |
// A sitemap may only have a set number of index links (links to other sitemap |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
32 |
// files) and a set number of site links in each of the "other" sitemap files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
33 |
// This code adjusts the number of site links specified by the user if the |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
34 |
// set number of index links has been reached but will not set that number |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
35 |
// greater than the set number of site links in a file. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
36 |
if ($chunk_count > XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS && |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
37 |
$chunk_size < XMLSITEMAP_MAX_SITEMAP_LINKS) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
38 |
// Determine the number of chunks we are over the maximum index links. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
39 |
$chunk_adjust = $chunk_count - XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
40 |
// Determine the number of links to adjust the chunk size. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
41 |
$chunk_adjust = $chunk_adjust * $chunk_size; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
42 |
if (($chunk_size + $chunk_adjust) <= XMLSITEMAP_MAX_SITEMAP_LINKS) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
43 |
$chunk_size += $chunk_adjust; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
44 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
45 |
else { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
46 |
$chunk_size = XMLSITEMAP_MAX_SITEMAP_LINKS; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
47 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
48 |
variable_set('xmlsitemap_chunk_size', $chunk_size); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
49 |
watchdog('xmlsitemap', 'Chunk size has been updated to @chunk-size.', array('@chunk-size' => $chunk_size)); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
50 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
51 |
elseif($chunk_count > XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
52 |
watchdog('xmlsitemap', 'The maximum number of allowed links has been reached.', NULL, WATCHDOG_ERROR); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
53 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
54 |
if (isset($chunk) && !is_numeric($chunk)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
55 |
drupal_not_found(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
56 |
exit(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
57 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
58 |
$id = xmlsitemap_language_id(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
59 |
if (variable_get('xmlsitemap_sitemap_needs_update', FALSE)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
60 |
variable_set('xmlsitemap_update_timestamp', REQUEST_TIME); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
61 |
db_query("DELETE FROM {xmlsitemap} WHERE type ='frontpage'"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
62 |
$row = new stdClass(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
63 |
$row->module = 'xmlsitemap'; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
64 |
$row->type = 'frontpage'; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
65 |
$changefreq = variable_get('xmlsitemap_front_page_changefreq', 3600); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
66 |
$row->changed = REQUEST_TIME - $changefreq; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
67 |
$row->changefreq = $changefreq; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
68 |
$row->priority = variable_get('xmlsitemap_front_page_priority', 1); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
69 |
drupal_write_record('xmlsitemap', $row); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
70 |
module_invoke_all('xmlsitemap_links'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
71 |
variable_set('xmlsitemap_sitemap_needs_update', FALSE); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
72 |
$result = _xmlsitemap_create_cache_files(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
73 |
if (variable_get("xmlsitemap_create_cache_result_$id", -1) !== $result) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
74 |
variable_set("xmlsitemap_create_cache_result_$id", $result); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
75 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
76 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
77 |
elseif (_xmlsitemap_check_cache_files()) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
78 |
$result = _xmlsitemap_create_cache_files(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
79 |
if (variable_get("xmlsitemap_create_cache_result_$id", -1) !== $result) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
80 |
variable_set("xmlsitemap_create_cache_result_$id", $result); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
81 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
82 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
83 |
if (!isset($chunk)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
84 |
if (($chunks = (integer) $link_count / $chunk_size) != variable_get('xmlsitemap_previous_chunks_count', -1)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
85 |
variable_set('xmlsitemap_previous_chunks_count', $chunks); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
86 |
if (!variable_get('menu_rebuild_needed', FALSE)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
87 |
variable_set('menu_rebuild_needed', TRUE); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
88 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
89 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
90 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
91 |
if (isset($result) && !$result) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
92 |
drupal_not_found(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
93 |
exit(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
94 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
95 |
$parent_directory = variable_get('xmlsitemap_cache_directory', file_directory_path() .'/xmlsitemap'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
96 |
$headers = array("Content-type: text/xml; charset=utf-8"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
97 |
if (isset($chunk)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
98 |
if ($chunk < $link_count / $chunk_size) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
99 |
file_transfer("$parent_directory/xsm-$id-$chunk.xml", $headers); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
100 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
101 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
102 |
else { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
103 |
file_transfer("$parent_directory/xsm-$id.xml", $headers); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
104 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
105 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
106 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
107 |
/***************************************************************************** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
108 |
* Private functions. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
109 |
****************************************************************************/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
110 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
111 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
112 |
* Check the cache files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
113 |
* |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
114 |
* @return |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
115 |
* TRUE if the cache files must be updated / created, FALSE otherwise. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
116 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
117 |
function _xmlsitemap_check_cache_files() { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
118 |
$chunk_size = variable_get('xmlsitemap_chunk_size', 1000); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
119 |
$link_count = xmlsitemap_link_count(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
120 |
$id = xmlsitemap_language_id(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
121 |
$parent_directory = variable_get('xmlsitemap_cache_directory', file_directory_path() .'/xmlsitemap'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
122 |
// If the directory that should contains the cache files doesn't exist, then |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
123 |
// the cache files must be created. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
124 |
if (!file_check_directory($parent_directory, FILE_CREATE_DIRECTORY)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
125 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
126 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
127 |
$update_timestamp = variable_get('xmlsitemap_update_timestamp', REQUEST_TIME); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
128 |
// If the cache files creation has failed last time, the cache files must be |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
129 |
// created. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
130 |
if (variable_get("xmlsitemap_create_cache_result_$id", -1) !== TRUE) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
131 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
132 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
133 |
// If the main cache file doesn't exist, then the cache files must be |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
134 |
// created. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
135 |
if (!file_exists($parent_directory ."/xsm-$id.xml")) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
136 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
137 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
138 |
// If the main cache file has been created before the sitemap content has |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
139 |
// been updated, then the cache files must be updated. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
140 |
if (filemtime($parent_directory ."/xsm-$id.xml") < $update_timestamp) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
141 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
142 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
143 |
// Check also the other cache files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
144 |
if ($link_count > $chunk_size) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
145 |
for ($chunk = 0; $chunk < $link_count / $chunk_size; ++$chunk) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
146 |
if (!file_exists($parent_directory ."/xsm-$id-$chunk.xml")) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
147 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
148 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
149 |
if (filemtime($parent_directory ."/xsm-$id-$chunk.xml") < $update_timestamp) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
150 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
151 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
152 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
153 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
154 |
return FALSE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
155 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
156 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
157 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
158 |
* Create a sitemap chunk cache file. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
159 |
* |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
160 |
* @param $fp |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
161 |
* A file resource used to write in. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
162 |
* @param $chunk_size |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
163 |
* The number of links the chunk must cointain. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
164 |
* @param $chunk |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
165 |
* The progressive number associated with the sitemap chunk (starting from |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
166 |
* 0). |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
167 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
168 |
function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
169 |
fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
170 |
if ($xsl = _xmlsitemap_xsl()) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
171 |
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . $xsl . '" ?>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
172 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
173 |
fwrite($fp, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
174 |
fwrite($fp, ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
175 |
fwrite($fp, ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
176 |
fwrite($fp, ' http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
177 |
$start = $chunk * $chunk_size; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
178 |
$links = db_query_range("SELECT xsm.loc, xsm.module, xsm.type, xsm.id, xsm.sid, xsm.changed, xsm.changefreq, xsm.priority". xmlsitemap_sitemap_query() ."ORDER BY xsm.priority DESC, xsm.changed DESC, xsm.changefreq, xsm.loc", $start, $chunk_size); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
179 |
while ($link = db_fetch_object($links)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
180 |
if ($link->type == 'frontpage') { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
181 |
$url = url(NULL, array('absolute' => TRUE)); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
182 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
183 |
else { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
184 |
$url = url($link->loc, array('absolute' => TRUE)); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
185 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
186 |
$link->url = $url; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
187 |
if ($link->module && function_exists($link->module .'_xmlsitemap_link_status')) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
188 |
$function = $link->module .'_xmlsitemap_link_status'; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
189 |
$link->status = $function($link->type, $link->id, $link->sid); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
190 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
191 |
else { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
192 |
$link->status = 0; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
193 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
194 |
drupal_alter('xmlsitemap_data', $link); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
195 |
if (($link->status & XMLSITEMAP_LINK_DISABLED) != XMLSITEMAP_LINK_DISABLED) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
196 |
fwrite($fp, ' <url>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
197 |
fwrite($fp, ' <loc>'. check_url($link->url) .'</loc>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
198 |
fwrite($fp, ' <lastmod>'. gmdate(DATE_W3C, $link->changed) .'</lastmod>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
199 |
fwrite($fp, ' <changefreq>'. xmlsitemap_sitemap_frequency($link->changefreq) .'</changefreq>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
200 |
fwrite($fp, ' <priority>'. number_format($link->priority, 1) .'</priority>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
201 |
fwrite($fp, ' </url>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
202 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
203 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
204 |
fwrite($fp, '</urlset>'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
205 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
206 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
207 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
208 |
* Determine path for a xml stylesheet. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
209 |
* |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
210 |
* @return |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
211 |
* - The stylesheet path or FALSE. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
212 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
213 |
function _xmlsitemap_xsl() { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
214 |
if (variable_get('xmlsitemap_use_stylesheet', FALSE)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
215 |
$paths = array( |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
216 |
variable_get('xmlsitemap_cache_directory', file_directory_path() . '/xmlsitemap') . '/gss.xsl', |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
217 |
drupal_get_path('module', 'xmlsitemap') . '/gss/gss.xsl', |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
218 |
); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
219 |
foreach ($paths as $path) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
220 |
if (file_exists($path)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
221 |
return base_path() . $path; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
222 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
223 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
224 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
225 |
return FALSE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
226 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
227 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
228 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
229 |
* Create the cache files containing the sitemap. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
230 |
* |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
231 |
* @return |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
232 |
* TRUE if the operation has been successfull, FALSE otherwise. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
233 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
234 |
function _xmlsitemap_create_cache_files() { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
235 |
$chunk_size = variable_get('xmlsitemap_chunk_size', 1000); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
236 |
$link_count = xmlsitemap_link_count(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
237 |
$id = xmlsitemap_language_id(); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
238 |
$parent_directory = variable_get('xmlsitemap_cache_directory', file_directory_path() .'/xmlsitemap'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
239 |
// If the directory doesn't exist, then create it. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
240 |
if (!file_check_directory($parent_directory, FILE_CREATE_DIRECTORY)) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
241 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
242 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
243 |
if ($link_count > $chunk_size) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
244 |
if (!$fp = fopen($parent_directory ."/xsm-$id.xml", 'wb')) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
245 |
watchdog('xmlsitemap', 'Could not create the cache file @file.', array('@file' => $parent_directory ."/xsm-$id.xml"), WATCHDOG_ERROR); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
246 |
return FALSE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
247 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
248 |
fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
249 |
if ($xsl = _xmlsitemap_xsl()) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
250 |
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . $xsl . '" ?>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
251 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
252 |
fwrite($fp, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
253 |
fwrite($fp, ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
254 |
fwrite($fp, ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
255 |
fwrite($fp, ' http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd">' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
256 |
for ($chunk = 0; $chunk < $link_count / $chunk_size; ++$chunk) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
257 |
fwrite($fp, ' <sitemap>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
258 |
fwrite($fp, ' <loc>'. url("sitemap$chunk.xml", array('absolute' => TRUE)) .'</loc>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
259 |
$from = $chunk * $chunk_size; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
260 |
$changed = db_result(db_query_range("SELECT xsm.changed". xmlsitemap_sitemap_query() ."ORDER BY xsm.priority DESC, xsm.changed DESC", $from, $chunk_size)); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
261 |
fwrite($fp, ' <lastmod>'. gmdate(DATE_W3C, $changed) .'</lastmod>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
262 |
fwrite($fp, ' </sitemap>' . "\n"); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
263 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
264 |
fwrite($fp, '</sitemapindex>'); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
265 |
fclose($fp); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
266 |
// Set standard file permissions for webserver-generated files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
267 |
@chmod($parent_directory ."/xsm-$id.xml", 0664); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
268 |
for ($chunk = 0; $chunk < $link_count / $chunk_size; ++$chunk) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
269 |
if (!$fp = fopen($parent_directory ."/xsm-$id-$chunk.xml", 'wb')) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
270 |
watchdog('xmlsitemap', 'Could not create the cache file @file.', array('@file' => $parent_directory ."/xsm-$id-$chunk.xml"), WATCHDOG_ERROR); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
271 |
return FALSE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
272 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
273 |
_xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
274 |
fclose($fp); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
275 |
// Set standard file permissions for webserver-generated files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
276 |
@chmod($parent_directory ."/xsm-$id-$chunk.xml", 0664); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
277 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
278 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
279 |
else { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
280 |
if (!$fp = fopen($parent_directory ."/xsm-$id.xml", 'wb')) { |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
281 |
watchdog('xmlsitemap', 'Could not create the cache file @file.', array('@file' => $parent_directory ."/xsm-$id.xml"), WATCHDOG_ERROR); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
282 |
return FALSE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
283 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
284 |
_xmlsitemap_create_cache_chunk($fp, $chunk_size); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
285 |
fclose($fp); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
286 |
// Set standard file permissions for webserver-generated files. |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
287 |
@chmod($parent_directory ."/xsm-$id.xml", 0664); |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
288 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
289 |
return TRUE; |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
290 |
} |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
291 |
|
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
292 |
/** |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
293 |
* @} End of "addtogroup xmlsitemap". |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
294 |
*/ |
0ff3ba646492
Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff
changeset
|
295 |