← Back
Editing: smap.php
<? /* +---------------------------------------------------------------------------+ | // smap v 1.01 | | ========== | | | | Copyright (c) 2008 Vladd44.com vladd44@vladd44.com | | For details, visit: http://forum.vladd44.com/php-scripts-f17.html | | | | This program is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | | the Free Software Foundation; either version 2 of the License, or | | (at your option) any later version. | | | | This program is distributed in the desire that it be useful, but | | WITHOUT ANY WARRANTY; without even an implied warranty of USE | | or PURPOSE. See the GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this script; If not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | +---------------------------------------------------------------------------+ */ // user variables session_start(); global $lc; $password ='4aa1e7414849577e6d4c076c08782d3a'; // enter pw here $url = 'http://'.$_SERVER['HTTP_HOST'].'/smap.php'; $cache_time = 86400; // in seconds $cmap = "sitemap.txt"; $auto_exclude = 'cgi-bin css phpbb2 phpbb3 forum cache scache images yahoo.php robots.txt smap.php temp tmp files twatch twatch_include files'; $accept="(\.html$)|(\.htm$)|(\.php$)|(\.txt$)|(\.shtml$)|(\.asp$)|(\.jsp$)|(\.cgi$)"; //valid file extensions $rid = "avoid.php"; $email =''; // add email address here if you wish to be emailed when google sitemap adds or removes pages (suggested) // functions function out_xml($file, $dir, $domain, $priority, $freq, $dates) { global $lc; $cdate = time(); $fc.=' '.$file; $priority = '0.5'; if ($dir){ $file = $dir.'/'.$file; } if (preg_match("/\bindex./i", $file) && !strrchr($file, '/')) { $priority = '1.0'; } $dates = date("Y-m-d",filemtime($file)); $numdate = date(filemtime($file)); $freq = 'Monthly'; if ($cdate-$numdate<86400){ $freq = 'Daily'; } elseif ($cdate-$numdate<604800) { $freq = 'Weekly'; } $file = str_replace("&","&",$file); $lc++; echo "<url> <loc>http://$domain/$file</loc> <lastmod>$dates</lastmod> <changefreq>$freq</changefreq> <priority>$priority</priority> </url> "; } $cdate = time(); // add password...force if empty if (!$password && !$_POST["pass"]){ echo 'Leaving the password blank is not an option<form action="smap.php" method="post"><br>'; echo 'What would you like your password to be : <input type="text" name="pass"><br>'; echo '<input type="submit" value="Submit"></form>'; exit; } elseif (!$password && $_POST["pass"]){ $epass = md5(htmlspecialchars($_POST["pass"])); echo 'Please enter '.$epass.' in the place provided in line 27. This is the md5 encryption for the password of your choice nd upload this script again. <b>'.htmlspecialchars($_POST["pass"]).'</b>'; exit; } // print out sitemap if no login if (file_exists($cmap)) { $exdate = $cdate-date(filemtime($cmap)); } if (!$_GET["login"] && file_exists($cmap)){ $cfile = fopen($cmap, 'r'); $themap = fread($cfile, filesize($cmap)); fclose($cfile); if ($exdate<$cache_time){ header("Content-Type: text/xml;charset=iso-8859-1"); echo $themap; exit; } // if file does not exist } elseif (!$_GET["login"] && !file_exists($cmap) && !file_exists($rid)){ echo 'Parameters not set, <a href="smap.php?login=1"> Please Login</a>'; exit; } //get session pw if exists if ($_GET["login"] && md5($_POST["pword"])<>$password && $_SESSION['pw'] ){ $_POST["pword"] = $_SESSION['pw']; } // if login pw is empty or incorrect if ($_GET["login"] && md5($_POST["pword"])<>$password){ echo "<form name=\"input\" action=\"smap.php?login=1\" method=\"post\">Please enter your password for access<br>"; echo "<input name=\"pword\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"; exit; } $_SESSION['pw'] = $_POST["pword"]; if ( $_POST["fofi"]){ $avoid = implode(' ', $_POST["fofi"]); // get post data for files to be avoided. } if (($_POST["finished"] || $exdate>($cache_time-1)) || (file_exists($rid) && !file_exists($cmap))){ $domain = $_SERVER['HTTP_HOST']; // get cached avoid values from file if (!$_POST["fofi"] && filesize($rid)>0 ) { $rfile = fopen($rid, 'r'); $avoid = fread($rfile, filesize($rid)); fclose($rfile); } // output xml for export etc ob_start(); echo '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> '; // go through root and included folders if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir($file) && !preg_match("/\b$file\b/i", $avoid )) { //dir $dc.=' '.$file; // folder get the files $dir =$file; $dh = opendir($dir); while (($file = readdir($dh)) !== false) { if(eregi($accept, $file) && !preg_match("/\b$file\b/i", $avoid)) { //if this file is a valid file out_xml($file, $dir, $domain, $priority, $freq, $dates); }} closedir($dh); unset($dir); } elseif(eregi($accept, $file) && !preg_match("/\b$file\b/i", $avoid)) { //if this file is a valid file out_xml($file, $dir, $domain, $priority, $freq, $dates); }}} closedir($handle); } echo ' </urlset>'; $new_map = ob_get_contents(); ob_end_clean(); // output cache to file $fi = fopen($cmap, 'w') or die("Can't open file"); fwrite($fi, $new_map); fclose($fi); if ($themap<> $new_map) { // send email if email address setup if ($email) { mail($email, $_SERVER['HTTP_HOST'].' Sitemap changed', "smap.php has updated and now includes $lc Pages in your sitemap"); } // ping google if sitemap changed if( $frep=@fsockopen('www.google.com', 80) ) { $request = 'GET /webmasters/tools/ping?sitemap=' . urlencode( $url ) . " HTTP/1.1\r\n" . "Host: www.google.com\r\n" . "User-Agent: Mozilla/5.0 (compatible; " . PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" . "Connection: Close\r\n\r\n"; fwrite( $frep, $request ); fclose( $frep ); }} if (!$_POST["finished"]){ // if sitemap was deleted, but avoid.php exists header("Content-Type: text/xml;charset=iso-8859-1"); echo $new_map; exit; } // output files/dirs to be avoided to file if ($_POST["finished"]){ $fi = fopen($rid, 'w') or die("Can't open file"); fwrite($fi, $avoid); fclose($fi); echo "Google Sitemap complete!! with a total of $lc Links <br><br><a href=\"smap.php\">Click here to view New Sitemap</a>"; session_destroy(); exit; } elseif ($exdate>($cache_time-1)) { header("Content-Type: text/xml;charset=iso-8859-1"); echo $new_map; } // end of sitemap output } else { if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir($file)) { //dir $dc.=' '.$file; } elseif(eregi($accept, $file)) { //if this file is a valid file $fc.=' '.$file; }}} closedir($handle); } // output $al = $dc.' '.$fc; $allz = explode(' ',$al); echo "Step 1. Please check the first box for each folder you do not wish to include in sitemap. <br><br><form name=\"input\" action=\"smap.php?login=1\" method=\"post\">"; for ($sc=1; $sc<count($allz); $sc++){ $checked =''; $c1=''; $c2=''; $glvoid = "$avoid $auto_exclude"; if (preg_match("/\b$allz[$sc]\b/i", $glvoid)) { $checked ='checked'; $c1 ='<font color="red">'; $c2='</font>'; } if ($allz[$sc]){ echo "$c1<input type=\"checkbox\" name=\"fofi[]\" value=\"$allz[$sc]\" $checked> $allz[$sc] $c2<br>"; }} // add textbox for filenames to exclude echo '<br><br><input type="checkbox" name="finished" value="1">5. <b>Check Box when Finished.</b><br><input type="submit" value="Submit" /></form><br>Submitting without checking the finished box will highlight the currently checked choices, making it easier to verify what is checked and what is not.'; } ?>
Save File
Cancel