source: sitemap_xml.php @ 308

Revision 308, 2.7 KB checked in by francois.harvey, 2 years ago (diff)

Ajout du sitemap XML pour l'indexaction par les moteurs de recherche (Il reste a terminer la version non ajax pour google)

Line 
1<?php
2/**
3 * Build a indexable wiki index (For google and cie)
4 *
5 * PHP version 5
6 *
7 * LICENSE: Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
8 *
9 * @category   Handlers
10 * @package    WikiHelp
11 * @copyright  2010 Gestion medsécure
12 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
13 * @version    SVN: $Id$
14 * @link       http://medsecure.ca/trac/wikihelp/
15 */
16
17require_once("config.php");
18header("Content-Type: text/xml");
19echo '<?xml version="1.0" encoding="UTF-8" ?>
20<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
21echo "\n";
22try {
23        $lang = Request::get('lang','en');
24        $wiki = registry::get('wiki');
25} catch (Request_Param_Exception $ex) {         
26                die( '</urlset>' );
27}
28
29$sql = "SELECT node_id " .
30       "FROM wikixref " .
31           "WHERE wiki_id = ?";
32if (!$id = $db->GetOne($sql, array($wiki))) {
33        die('</urlset>');
34}
35
36
37function xmlencode($tag){
38        $tag = str_replace("&", "&amp;", $tag);
39        $tag = str_replace("<", "&lt;", $tag);
40        $tag = str_replace(">", "&gt;", $tag);
41        $tag = str_replace("'", "&apos;", $tag);
42        $tag = str_replace("\"", "&quot;", $tag);
43        return $tag;
44}
45
46function parseTree($node, $label = '', $xml = '', $child = true, $rt){
47        global $db;
48        global $lang;
49        global $wiki;
50        $label = xmlencode($label);
51       
52        $sql = "SELECT node.node_id,label, MAX(revision_time) as revision_time " .
53               "FROM node LEFT JOIN revision ON node.node_id = revision.node_id  " .
54                   "WHERE parent_id = ? " .
55                   "  AND node.wiki_id = ? " .
56                   "GROUP BY node.node_id, label " .
57                   "ORDER BY node_position";
58        $result = $db->Execute($sql, array($node, $wiki));
59
60        if ($result->RecordCount() == 0){               
61                $xml .= "<url>\n";
62            $xml .= "<loc>index.php#!{$node}</loc>\n";
63        $xml .= "<lastmod>{$rt}</lastmod>\n";       //          2005-06-04T00:00:00+00:00
64                $xml .= "<changefreq>daily</changefreq>\n";
65        $xml .= "<priority>1</priority>\n";
66                $xml .= "</url>\n";
67        }else{
68                foreach ($result as $row) {
69                        if ($lang != 'en') {
70                                if ( !$locale_label = $db->GetOne('SELECT label FROM node_lang WHERE node_id = ? and lang = ?', array($row['node_id'],$lang))) {
71                                        $locale_label =  $row['label'];                                 
72                                }
73                        } else {
74                                $locale_label =  $row['label'];
75                        }
76                        if (! $row['revision_time'] )   {
77                                $rt = date(DATE_ATOM);
78                        } else {
79                                $rt = $row['revision_time'];                           
80                        }
81                        $xml = parseTree($row['node_id'], $locale_label, $xml,true,$rt);
82                }
83        }       
84        return $xml;   
85}
86
87
88echo  parseTree($id, '', '',  false, date());
89echo "</urlset>\n";
Note: See TracBrowser for help on using the repository browser.