rendered paste body<?php //Main function $domain, $catalog, $number_of_pages) { //Get links from google $links = getPageLinks($domain, $catalog, $number_of_pages); foreach($links[1] as $link) { ob_start(); //Open the page and put the contents into string $page //Remove duplicate part numbers from the array $matches = array_unique($matches[0]); $matches = cleanArrayKeys($matches); //Create a new directory $dir = createDir("cat"); echo "Creating directory: $dir<br />"; @ob_flush(); @flush(); //Loop through the matches and create a page for each one echo "Creating pages in: $dir<br />"; @ob_flush(); @flush(); if($dir) { for($i = 0; $i < count($matches); $i++) { createPage($i, $matches, $dir); } } //Create the sitemap using the directory made, the array of matches and specified page priority echo "Creating sitemap for: $dir<br />"; @ob_flush(); @flush(); $sitemap = createSiteMap($dir, $matches, 0.9); //Update main sitemap of all sitemaps each with specified page priority echo "Updating main sitemap.xml. Adding: $sitemap</p>"; @ob_end_flush(); @flush(); updateMainSiteMap($sitemap); set_time_limit(20); } echo "<p>Script completed successfully.</p>"; } while(is_dir($prefix."_".$i)) { $i++; } if(mkdir($prefix."_".$i)) { return $prefix."_".$i; } else { return false; } } //This function fixes the array keys, since array_unique preserves the keys and unsets the duplicates, //leaving gaps in the keys. This shifts them back in order. function cleanArrayKeys($arr) { foreach($arr as $a) { if(isset($a)) { $result[] = $a; } } return $result; }"; for($i = 1; $i < 5; $i++) { $next = (($index) * 4 + $i) % count($matches); $page .= "<a href=\"$matches[$next].html\">$matches[$next]</a>\n"; } $page .="</body></html>"; $filename = $dir . "/" . urlencode($matches[$index]) . ".html"; if($filename == "output/.html") { echo $index."\n"; } $handle = fopen($filename, "w"); fwrite($handle, $page); fclose($handle); } //Build the xml sitemap with the corresponding filename function createSiteMap($dir, $matches, $priority) { if(!is_dir("sitemaps")) mkdir("sitemaps"); $filename = explode("_", $dir); $filename = "sitemaps/sitemap_" . $filename[count($filename) - 1] . ".xml"; $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"> <url>> <priority>1.000</priority> </url>\n"; foreach($matches as $match) { } $xml .= "</urlset>"; $handle = fopen($filename, "w"); fwrite($handle, $xml); fclose($handle); return $filename; } //Read in current sitemap.xml file, strip end tag, append new sitemap, add end tag, write to file. function updateMainSiteMap($path) { if(is_file("sitemap.xml")) { $file = file_get_contents("sitemap.xml"); $remove = "</sitemapindex>"; $file = substr($file, 0, -strlen($remove)); } else { $file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; }</sitemapindex>"; $handle = fopen("sitemap.xml", "w"); fwrite($handle, $file); fclose($handle); }?>