Note sparse

#

Listato 5

la libreria del generatore di sitemap
 
<?php
function sitemapHeader() {
        header("Content-Type: application/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");
}

function processToc($dir, $name="toc") {
        $doc = new DOMDocument();
        $doc->load("$dir/$name.xml");
        $pages = $doc->getElementsByTagName("tocitem");  
        foreach($pages as $page) {
                if(gebtn($page, "nositemap") == null) {
                        $noimages = gebtn($page, "noimages") != null;
                        $link = getString($page,"link");
                        if($link == "" && $name == "listati") {
                                $id = $page->attributes->item(0)->nodeValue;
                                $link = "listato.php?id=$id";
                        }
                        $lastmod = getString($page,"date");
                        writeUrl("$dir/$link", substr($link,0,3) == "toc" || $noimages, $lastmod < "2021-06-19" ? "2021-06-19" : $lastmod);
                }
        }
}

function writeUrl($url, $noimages = false, $lastmod = "2021-06-19") {
        $data = date("Y-m-d");
        $url="https://strawberryfield.altervista.org/$url";
        $out = <<<EOT
        <url>
                <loc>$url</loc>
                <lastmod>$lastmod</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');
        if($imgs->length==0) {
                return;
        }
        foreach ($imgs as $img) {
                $src = $img->getAttribute("src");
                if (strpos($src, 'style/') === false) {
                        if(strpos($src, "http") === false) {
                                $src = "$path/$src";
                        }
                        if (strpos($src, "https://strawberryfield") === false) { continue; }
                        $alt = str_replace("&", "&amp;", $img->getAttribute("alt"));
                        $alt = str_replace("<", "&lt;", $alt);
                        $alt = str_replace(">", "&gt;", $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