#

Listato 5

Il generatore della sitemap
 
<?php
header("Content-Type: text/xml; charset=UTF-8");
$out = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
                xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
EOT
;
print("$out\n");

include("php5/tutorial2.php");

writeUrl("index.php");
writeUrl("pubblicazioni.php");
writeUrl("guestbook.php");
writeUrl("licenza.php");
writeUrl("robertoceccarelli-fotografia-informatica.php");
writeUrl("thestrawberryfield-fotografia-informatica.php");
writeUrl("radioserva.php");
processToc("fq");
processToc("creare_dvd_video");
processToc("creare_dvd_video","listati");
processToc("blog");
processToc("blog","listati");
processToc("30_anni_casasoft");
processToc("30_anni_casasoft","listati");
processToc("ne");
processToc("raspberry");
processToc("storie_foto");

print('</urlset>');

// --- utilities ----

function processToc($dir, $name="toc") {
        $doc = new DOMDocument();
        $doc->load("$dir/$name.xml");
        $pages = $doc->getElementsByTagName("tocitem");  
        foreach($pages as $page) {
                $link = getString($page,"link");
                writeUrl("$dir/$link", $name != "toc");
        }
}

function writeUrl($url, $noimages = false) {
        $data = date("Y-m-d");
        $url="https://strawberryfield.altervista.org/$url";
        $out = <<<EOT
        <url>
                <loc>$url</loc>
                <lastmod>$data</lastmod>
EOT
;
        print("$out\n");
        if($noimages == false) {
                writeImgs($url);
        }
        print("\t</url>\n");
}

function writeImgs($url) {
        $htmlpage = file_get_contents($url);
        $path = dirname($url);
        $doc = new DOMDocument();
        $doc->loadHTML($htmlpage);
        $imgs = $doc->getElementsByTagName('img');
        foreach ($imgs as $img) {
                $src = $img->getAttribute("src");
                if (strpos($src, 'style/') === false) {
                        if(strpos($src, "http") === false) {
                                $src = "$path/$src";
                        }
                        $alt = str_replace("&", "&amp;", $img->getAttribute("alt"));
                        $out = <<<EOT
                <image:image>
                        <image:loc>$src</image:loc>
                        <image:caption>$alt</image:caption>
                        <image:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</image:license>
                </image:image> 
EOT
;
                print("$out\n");
                }
        }
}
?>
Inizio pagina
Home page
 
Creative Commons  License BY-NC-SA
Ove non diversamente specificato i contenuti del sito sono rilasciati con licenza Creative Commons BY-NC-SA 4.0 

Copyright © 2007-2020 The Strawberry Field - Roberto Ceccarelli