This is a little script that generates a sitemap made of a unique chunk from the node data.

The script is not thought to be used contemporaneously with XML sitemap, although it has been developed to not create interferences with XML sitemap.
The script is also not thought for sites with a lot of nodes; it's a simple script that you can use in replacement of XML sitemap if it doesn't work for you.

How to use it

Copy it in the Drupal root directory, the same directory where you have cron.php, update.php, and index.php. You can add a line as RewriteRule ^sitemap.xml$ sitemap.php [L] in your .htaccess file, or you can use it like it is; in the latter case, you must advice the search engines that http://example.com/sitemap.php is your sitemap (replace example.com with your real domain name).

The attachment must be renamed from sitemap_090000_php.txt to sitemap.php.

Comments

avpaderno’s picture

StatusFileSize
new3.11 KB

I forgot a call to number_format() that should be used to format the priority value.

The attachment is the new version that fixed that.

bobighorus’s picture

I made a test on different Druapal 6 web sites; the result is a blank page or a php calling function error.
I made a watch on the code, too; there aren't any snippet related to multilanguage prefix, to url_aliases and to menu links.

avpaderno’s picture

there aren't any snippet related to multilanguage prefix, to url_aliases and to menu links

The language prefix, and the URL alias are handled by url(); there aren't menu links because the script add just node links, as clearly reported in this report (this is a little script that generates a sitemap made of a unique chunk from the node data).

The blank page is probably caused by a PHP script, which should occur when there are a lot of nodes.
The only functions called by the code are drupal_bootstrap(), number_format(), function_exists(), drupal_header(), db_query(), db_rewrite_sql(), set_time_limit(), db_result(), node_load(), url(), date(), xmlsitemap_sitemap_frequency(), max(); of those, 5 are functions defined from PHP, 6 are functions defined in Drupal include files, 1 function is defined in a core required module, and 1 function is defined in the script. The only function that could not be enabled, depending on the PHP configuration, is set_time_limit(); if that would be the case, it's enough to remove the line containing the call to that function.
I cannot be more precise, without to know which is the function that the error message reports to not be defined.

avpaderno’s picture

StatusFileSize
new3.11 KB

I got it; the error is caused by a reference to a function that Drupal doesn't define; drupal_header() should be drupal_set_header().

avpaderno’s picture

StatusFileSize
new3.11 KB

There are some extraneous characters that appear in the output: the string terminator, and the code line terminator.
This attached file is the version that resolve the problem.

bobighorus’s picture

Ok, I removed a bad closed string: "";" after every </url>. You can simply remove, it. And now I correctly see the output.
Maybe in the code you can add the prefix "/it/" for example, if it's present in the db: I think it's very useful!
About the language prefix I was refering, I have a question for you: I have specified many url_aliases for my not english language nodes, such as "it/il-mio-contenuto"; it's possible to write code in this script in order to catch this kind of url_rewrite? Maybe a match with the url_alias table? Thank you.

avpaderno’s picture

StatusFileSize
new3.11 KB
bobighorus’s picture

Maybe you can add this code to insert the prefix:

  	if ($node->language != "en")  	
    	$url = url($node->language. '/node/'. $node->nid, array('absolute' => TRUE));
    else 
     	$url = url('node/'. $node->nid, array('absolute' => TRUE));
bobighorus’s picture

bobighorus’s picture

Yes, it's true.

avpaderno’s picture

I removed a bad closed string

There isn't a bad closed string because the string is not delimited by apices, but from EOL;. The ", and the ; characters are simply included in the string, but they don't have any function in that string because PHP interprets all that is between <<, and EOL; as a string.

About the URL aliases they are added from the url() function that looks for them in the Drupal core table. There are some cases where a content not in the default language could not get assigned a URL alias, but that is caused by a bug in the code that should save the URL alias set for a Drupal normal path.

avpaderno’s picture

Maybe you can add this code

In that case, the language prefix would appear twice; then, the code is taking the assumption that English is the default language, which could not be true.

bobighorus’s picture

This can be useful:" language_default"...

avpaderno’s picture

Yes, it could be useful. The fact is that url() already handles the path aliases; there is no reason to duplicate code that already exist.

bobighorus’s picture

What I can try to say is that there's a need to output the language path and the url alias if it's specified, like this way "/it/il-mio-contenuto-con-url-personalizzato"...

avpaderno’s picture

I understood what you mean. The problem is that this is a bug in Drupal.

In my case, I get this is my test site:

<urlset>
  <url>
    <loc>http://localhost:8888/dr61/node/21002</loc>
    <lastmod>2009-05-16T17:49:05Z</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>
  <url>
    <loc>http://localhost:8888/dr61/node-21003-devel_content</loc>
    <lastmod>2009-05-16T17:49:05Z</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>
[..]
</urlset>

The first node shown has a path alias that is set to node-21002-devel_content-la for the Latin language; if I change the path alias and I associate it to any languages, then the path alias is used, but there is no language prefix.
This happens when the default language is set to English, and there is another enabled language for the site (which, in my case is Latin, but that doesn't make any differences).

I am investigating on this, because maybe it's the same problem XML sitemap has, and that doesn't allow to the module to completely support multilingual sites.

bobighorus’s picture

Ok. I finally understand what is the cause of the incomprension: because of the "bug" of the internalization system in Drupal I've previously modified the module i18n for my need and so my site is able to catch the url prefix, for example "/it" and then translate the entire interface in the relative language.
This is the reason why I asked several time for getting the prefix in the url.
I hope I was clear.
If you are interested in this stuff let me know.
Thank you.

avpaderno’s picture

StatusFileSize
new3.41 KB

I created a different version that adds the language prefix to the node links. This version works only on sites where each language is associated to a different language prefix; it doesn't work for sites where each language is associated to a different domain.

avpaderno’s picture

StatusFileSize
new3.34 KB

I also slightly changed the normal script.

bobighorus’s picture

Thank you kiam; only two things about your great last script for language prefix : I think that prefix language would be excluded for the default langauge; and, as I wrote above, is there a way to obtain the url alias specified in the url_alias db table? Is it possible, according to you?
Thanks in advance.

avpaderno’s picture

I think that prefix language would be excluded for the default langauge

That is indifferent; you can exclude the language prefix for the default language, or you can include it. If English is the default language, a node is visible both at http://example.com/node/2, and http://example.com/en/node/2; the same is true for any language set as default one.

Is there a way to obtain the url alias specified in the url_alias db table? Is it possible, according to you?

The point is that to get a URL from a Drupal path that is correct in all cases, you need to call url(); that function calls drupal_get_path_alias(), which is the function that returns the alias of a path. If that function is not able to find the correct alias, I can only think to a system to try to force it to find the right alias.
url() accepts an array as second parameter, and in that array you can pass a language object to specify the language for the path alias. I guess that if the function is not able to find the correct path alias, maybe it needs a help.
I will check this out.

PS: My script is not great at all; it's simply plain Drupal PHP for a simple task. The most important thing is that it's the correct way to do it in Drupal.

bobighorus’s picture

That is indifferent; you can exclude the language prefix for the default language, or you can include it. If English is the default language, a node is visible both at http://example.com/node/2, and http://example.com/en/node/2; the same is true for any language set as default one.

I think it's not a secondary question: generating a xml sitemap is a practice for good SEO, as you know, but having different url such as http://example.com/node/2, and http://example.com/en/node/2 pointing at the same content is a bad mistake, 'cause it means to obtain duplicate content, a not good SEO practice.

avpaderno’s picture

generating a xml sitemap is a practice for good SEO, as you know, but having different url such as http://example.com/node/2, and http://example.com/en/node/2 pointing at the same content is a bad mistake, 'cause it means to obtain duplicate content, a not good SEO practice.

I didn't say it was a secondary question. I said that both the links take to the same page; therefore, both the links are equivalent, which means that at least the sitemap contains links that doesn't cause any 404 error messages.
I was not referring to the fact that is better to not use the language prefix for the default language.

avpaderno’s picture

Assigned: avpaderno » Unassigned
Status: Active » Closed (fixed)