01 <?php
02     $_VARIABLE{'$BaseURL'} = "http://www.(userdomain)/";
03     $_VARIABLE{'$BasePath'} = "/home/(username)/";
04 
05     function ExtractSiteLinks($SiteFileName) {
06         global $_VARIABLE;
07 
08         if(!$SitemapFileHandle = fopen($SiteFileName, "r")) {
09             die("fopen(ERROR): $SiteFileName");
10         }
11 
12         while ($line = fgets($SitemapFileHandle)) {
13             if(preg_match('/<loc>(.+)<\/loc>/i', $line, $match)) {
14                 $match[1] = preg_replace('/\/$/', '/index.php', $match[1]);
15                 $match[1] = preg_replace("/" . preg_quote($_VARIABLE{'$BaseURL'}, '/') . "/", $_VARIABLE{'$BasePath'}, $match[1]);
16                 $SiteLinks[] = $match[1];
17             }
18         }
19 
20         fclose($SitemapFileHandle);
21 
22         printf("<div>found %d links.</div>\n", count($SiteLinks));
23 
24         return $SiteLinks;
25     }
26 
27     function CompressFile($FileName) {
28 
29     }
30 
31     $SiteFileName = "/home/(username)/blog/sitemaps.xml";
32 
33     $SiteLinks = ExtractSiteLinks($SiteFileName);
34 
35     $cnt = 0;
36     foreach ($SiteLinks as $sitelink) {
37         if(CompressFile($sitelink)) {
38             $cnt++;
39         }
40     }
41 
42     printf("<div>compress %d links.</div>\n", $cnt);
43 ?>