Location: PHPKode > scripts > Yet Another Link Directory > yald2/admin/submitmap.php
<?php
/******************************************************************************
* This file is part of Yet Another Link Directory.                            *
*                                                                             *
* Yet Another Link Directory 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.                                         *
*                                                                             *
* Yet Another Link Directory is distributed in the hope that it will be       *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with Yet Another Link Directory; if not, write to the Free Software   *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
******************************************************************************/

require('../inc/config.php');
require('../inc/functions.php');
mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
mysql_select_db($mysql['db']);

$settings = getSettings();

session_start();

if(!isset($_SESSION['yald_admin_logged_in'])){
	header('Location: login.php');
	exit;
}

$template = file_get_contents('template.html');

// automatically find the url to the sitemap
$sitemap = 'http://'.$_SERVER['SERVER_NAME'].str_replace('admin','',dirname($_SERVER['PHP_SELF'])).'sitemap.php';

function sendmap($engine){
	global $sitemap;

	$sent = array();

	foreach($engine as $engine){

		$split = explode(';',$engine);

		$parse = parse_url($split[1]);

		if(@$fp = fsockopen($parse['host'],80,$err_num,$err_msg,5)){

			fputs($fp, "GET ".$parse['path']."?sitemap=".urlencode($sitemap)." HTTP/1.1\r\n");
			fputs($fp, "Host: {$parse['host']}\r\n");
			fputs($fp, "Connection: close\r\n\r\n");

			$response = fgets($fp);

			eregi("^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$",$response,$matches);
			$status_code = $matches[1];

			if($status_code == '200'){
				$sent[] = $split[0];
			}

		}

	}

	return $sent;

}

$yald_body = '';
$yald_head = null;

if(isset($_POST['submit'])){
	if(isset($_POST['engine'])){
		$sent = sendmap($_POST['engine']);
		if(!empty($sent)){
			$error = 'Your sitemap was successfully submitted to ';
			for($i=0; $i<count($sent); $i++){
				if(count($sent) > 1 && $i != 0){
					if(count($sent)-1 == $i){
						$error .= ' and ';
					} else {
						$error .= ', ';
					}
				}
				$error .= $sent[$i];
			}
			$error .= '.';
		} else {
			$error = 'The sitemap could not be submitted to any of the selected search engines.';
		}
	} else {
		$error = 'No search engines were selected.';
	}
}

$yald_body = 'Use this page to upload your XML sitemap to search engines. This will allow them to index your site easier. It is suggested that you only submit when the directory has changed (i.e. when categories or links are added). More information about the sitemaps protocol can be found at <a href="http://www.sitemaps.org/" target="_blank">http://www.sitemaps.org/</a>.<br />';
if(!urlExists($sitemap)){
	$yald_body .= '<div align="center"><div class="errorbox"><b>The calculated URL to the sitemap could not be found ('.$sitemap.'). Either your server\'s settings do not allow this, or the calculated URL is incorrect.</b></div></div>';
}
if(isset($error)){
	$yald_body .= '<div align="center"><div class="errorbox"><b>'.$error.'</b></div></div>';
}
$yald_body .= '<br />
<form id="form1" name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'">
  <input type="checkbox" name="engine[]" id="yahoo" value="Yahoo;http://search.yahooapis.com/SiteExplorerService/V1/ping" />
  <label for="yahoo">Yahoo</label>
  <br />
  <input type="checkbox" name="engine[]" id="google" value="Google;http://www.google.com/ping" />
  <label for="google">Google</label>
  <br />
  <input type="checkbox" name="engine[]" id="ask.com" value="Ask.com;http://submissions.ask.com/ping" />
  <label for="ask.com">Ask.com</label>
  <br /><input type="hidden" name="submit" value="1" />
  <input type="submit" name="button" id="button" value="Send Sitemap" />
</form>';

$template = admin_output('stats');

print $template;
?>
Return current item: Yet Another Link Directory