forked from craftsmancoding/modx_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.php
79 lines (67 loc) · 2.38 KB
/
sitemap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env php
<?php
/**
* Sitemap Submitter
*
* Use this script to submit your site maps automatically to:
* - Google
* - Bing.MSN
* - Ask
*
* Usage:
*
* php /path/to/this/sitemap.php http://siteone.com/sitemap.xml http://otheriste.com/sitemap.xml
*
* Any argument passed to this script should be a valid URL to your sitemap.xml.
*
* Reference in a Crontab:
# As a reference, here's your legend
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
0 2 * * 1 php /path/to/sitemap.php http://siteone.com/sitemap.xml http://otheriste.com/sitemap.xml >> /path/to/sitemap.log
* Adapted from
* http://www.benhallbenhall.com/2013/01/script-automatically-submit-sitemap-google-bing-yahoo-ask-etc/
* by everett@fireproofsocks.com May 2014
*/
if (php_sapi_name() !== 'cli') {
error_log('This CLI script can only be executed from the command line.');
die('CLI access only.');
}
// cUrl handler to ping the Sitemap submission URLs for Search Engines
function myCurl($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
echo "Starting site submission at ".date('Y-m-d H:i:s')."\n";
// $argv[0] contains the name of this script.
// We just want the args, so we skip the script name
array_shift($argv);
foreach ($argv as $s) {
if(filter_var($s, FILTER_VALIDATE_URL) === false) {
echo "Invalid URL: ".escapeshellarg($s)." -- skipping\n";
continue;
}
echo "Submitting $s\n";
//Google
$url = "http://www.google.com/webmasters/sitemaps/ping?sitemap=".$s;
$returnCode = myCurl($url);
echo "Google Sitemaps has been pinged (return code: {$returnCode}).\n";
//Bing / MSN
$url = "http://www.bing.com/webmaster/ping.aspx?siteMap=".$s;
myCurl($url);
echo "Bing / MSN Sitemaps has been pinged (return code: {$returnCode}).\n";
//ASK
$url = "http://submissions.ask.com/ping?sitemap=".$s;
myCurl($url);
echo "ASK.com Sitemaps has been pinged (return code: $returnCode).\n";
}
echo "Completed at ".date('Y-m-d H:i:s')."\n";