function create_sitemap($site_id, $url) { global $db_con, $mysql_table_prefix, $smap_dir, $smap_unique, $debug, $clear; error_reporting(E_ALL & ~E_DEPRECATED & ~E_WARNING & ~E_NOTICE & ~E_STRICT); $changefreq = "monthly"; // individualize this variable $priority = "0.50"; // individualize this variable // Only change something, if you are sure to remain compatible to http://www.sitemaps.org/schemas/sitemap/0.9 $date = date("Y-m-d"); $time = date("h:i:s"); $modtime = "T{$time}+01:00"; $version = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $urlset = "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">"; $copyright = "<!-- Generated by Sphider-plus created by Tec (v.1.3 rev.2) -->"; $update = "<!-- Last update of this sitemap: {$date} / {$time} -->"; $all_links = ''; mysqltest(); $sql_query = "SELECT * from " . $mysql_table_prefix . "links where site_id = {$site_id}"; $res = $db_con->query($sql_query); if ($debug && $db_con->errno) { $err_row = __LINE__ - 2; printf("<p><span class='red'> MySQL failure: %s \n<br /></span></p>", $db_con->error); if (__FUNCTION__) { printf("<p><span class='red'> Found in script: " . __FILE__ . " row: {$err_row} in function(): " . __FUNCTION__ . " <br /></span></p>"); } else { printf("<p><span class='red'> Found in script: " . __FILE__ . " row: {$err_row} <br /></span></p>"); } printf("<p><span class='red'> Script execution aborted. <br /></span>"); printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>"); echo "<p> {$sql_query} </p>"; exit; } $num_rows = $res->num_rows; // Get all links of the current domain if ($num_rows) { while ($this_link = $res->fetch_array(MYSQLI_ASSOC)) { $links[] = $this_link; } for ($i = 0; $i < $num_rows; $i++) { // Create individual rows for XML-file $link = $links["{$i}"]['url']; $link = str_replace("&", "&", $link); // URL should become XML conform $all_links .= "<url><loc>{$link}</loc><lastmod>{$date}{$modtime}</lastmod><changefreq>{$changefreq}</changefreq><priority>{$priority}</priority></url>\n"; } } $name = parse_addr($url); // Create filename and open file $hostname = $name[host]; if ($hostname == 'localhost') { // if we run a localhost system extract the domain $pathname = $name[path]; // get path, domain and filename $pos = strpos($pathname, "/", 1); // extract domain from path and forget first / by +1 offset $pathname = substr($pathname, $pos + 1); // suppress /localhost/ $pos = strrpos($pathname, "/"); if ($pos) { $pathname = substr(str_replace("/", "_", $pathname), 0, $pos); // if exists, suppress folder, filename and suffix } if (!is_dir($smap_dir)) { mkdir($smap_dir, 0766); // if new, create directory } if ($smap_unique == '0') { // different names for every sitemap file $filename = "./{$smap_dir}/sitemap_localhost_{$pathname}.xml"; } else { $filename = "./{$smap_dir}/sitemap.xml"; } if (!($handle = fopen($filename, "w"))) { printInvalidFile($filename); die; } } else { // if we run in the wild if (!is_dir($smap_dir)) { mkdir($smap_dir, 0766); // if new, create directory } if ($smap_unique == '0') { // different names for every sitemap file $filename = "./{$smap_dir}/sitemap_{$hostname}.xml"; } else { $filename = "./{$smap_dir}/sitemap.xml"; } if (!($handle = fopen($filename, "w"))) { printInvalidFile($filename); die(''); } } // Now write all to XML-file if (!fwrite($handle, "{$version}\n{$urlset}\n{$copyright}\n{$update}\n{$all_links}</urlset>\n")) { printInvalidFile($filename); die(''); } fclose($handle); // sitemap.xml done! Now final printout printSitemapCreated($filename); }
function create_sitemap($site_id, $url) { global $mysql_table_prefix, $smap_dir; $changefreq = "monthly"; // individualize this variable $priority = "0.50"; // individualize this variable // Below this only change something, if you are sure to remain compatible to http://www.sitemaps.org/schemas/sitemap/0.9 $date = date("Y-m-d"); $time = date("h:i:s"); $modtime = "T{$time}+01:00"; $version = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $urlset = "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">"; $copyright = "<!-- Generated by Sphider-plus created by Tec (v.1.2 rev.3) -->"; $update = "<!-- Last update of this sitemap: {$date} / {$time} -->"; $all_links = ''; $res = mysql_query("select * from " . $mysql_table_prefix . "links where site_id = {$site_id}"); echo mysql_error(); $num_rows = mysql_num_rows($res); // Get all links of the current domain for ($i = 0; $i < $num_rows; $i++) { // Create individual rows for XML-file $link = mysql_result($res, $i, "url"); $link = str_replace("&", "&", $link); // URL should become XML conform $all_links = "{$all_links}<url><loc>{$link}</loc><lastmod>{$date}{$modtime}</lastmod><changefreq>{$changefreq}</changefreq><priority>{$priority}</priority></url>\n"; } clean_resource($res); $name = parse_url($url); // Create filename and open file $hostname = $name[host]; if ($hostname == 'localhost') { // if we run a localhost system extract the domain $pathname = $name[path]; // get path, domain and filename $pos = strpos($pathname, "/", 1); // extract domain from path and forget first / by +1 offset $pathname = substr($pathname, $pos + 1); // suppress /localhost/ $pos = strrpos($pathname, "/"); if ($pos) { $pathname = substr(str_replace("/", "_", $pathname), 0, $pos); // if exists, suppress folder, filename and suffix } if (!is_dir($smap_dir)) { mkdir($smap_dir, 0766); // if new, create directory } $filename = "./{$smap_dir}/sitemap_localhost_{$pathname}.xml"; if (!($handle = fopen($filename, "w"))) { printInvalidFile($filename); die; } } else { // if we run in the wild if (!is_dir($smap_dir)) { mkdir($smap_dir, 0766); // if new, create directory } $filename = "./{$smap_dir}/sitemap_{$hostname}.xml"; if (!($handle = fopen($filename, "w"))) { printInvalidFile($filename); die(''); } } // Now write all to XML-file if (!fwrite($handle, "{$version}\n{$urlset}\n{$copyright}\n{$update}\n{$all_links}</urlset>\n")) { printInvalidFile($filename); die(''); } fclose($handle); // sitemap.xml done! Now final printout printSitemapCreated($filename); }