|
1
|
|
|
<?php |
|
2
|
|
|
/*************************************************************************** |
|
3
|
|
|
* For license information see doc/license.txt |
|
4
|
|
|
***************************************************************************/ |
|
5
|
|
|
|
|
6
|
|
|
namespace OcLegacy\Cronjobs; |
|
7
|
|
|
|
|
8
|
|
|
use OcLegacy\Util\SiteMapXml; |
|
9
|
|
|
|
|
10
|
|
|
class SiteMaps |
|
11
|
|
|
{ |
|
12
|
|
|
public $name = 'sitemaps'; |
|
13
|
|
|
public $interval = 604800; // once a week |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var SiteMapXml |
|
17
|
|
|
*/ |
|
18
|
|
|
public $oSiteMapXml; |
|
19
|
|
|
|
|
20
|
|
|
public function run() |
|
21
|
|
|
{ |
|
22
|
|
|
global $opt; |
|
23
|
|
|
if ($opt['cron']['sitemaps']['generate'] === true) { |
|
24
|
|
|
$this->oSiteMapXml = new SiteMapXml(); |
|
25
|
|
|
|
|
26
|
|
|
$page = $opt['page']; |
|
27
|
|
|
|
|
28
|
|
|
$this->oSiteMapXml->open( |
|
29
|
|
|
$opt['rootpath'], |
|
30
|
|
|
$page['https']['mode'] == HTTPS_ENFORCED ? $page['absolute_https_url'] : $page['absolute_http_url'] |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
$this->oSiteMapXml->write('index.php', time(), 'always', 1.0); |
|
34
|
|
|
$this->oSiteMapXml->write('tops.php', time() - 24 * 60 * 60, 'daily', 0.5); |
|
35
|
|
|
$this->oSiteMapXml->write('newcachesrest.php', time() - 24 * 60 * 60, 'daily', 0.5); |
|
36
|
|
|
$this->writeViewGeocacheUrls(); |
|
37
|
|
|
$this->writeNewGeocacheUrls(); |
|
38
|
|
|
|
|
39
|
|
|
$this->oSiteMapXml->close(); |
|
40
|
|
|
|
|
41
|
|
|
if ($opt['cron']['sitemaps']['submit'] === true) { |
|
42
|
|
|
$this->pingSearchEngines(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function pingSearchEngines() |
|
48
|
|
|
{ |
|
49
|
|
|
global $opt; |
|
50
|
|
|
|
|
51
|
|
|
$page = $opt['page']; |
|
52
|
|
|
$url = ($page['https']['mode'] == HTTPS_ENFORCED ? $page['absolute_https_url'] : $page['absolute_http_url']); |
|
53
|
|
|
|
|
54
|
|
|
$url = urlencode($url. 'sitemap.xml'); |
|
55
|
|
|
|
|
56
|
|
|
$this->pingSearchEngine('http://www.google.com/webmasters/ping?sitemap=' . $url); |
|
57
|
|
|
$this->pingSearchEngine( |
|
58
|
|
|
'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=USERID&url=' . $url |
|
59
|
|
|
); |
|
60
|
|
|
$this->pingSearchEngine('http://submissions.ask.com/ping?sitemap=' . $url); |
|
61
|
|
|
$this->pingSearchEngine('http://www.bing.com/webmaster/ping.aspx?siteMap=' . $url); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param string $url |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public function pingSearchEngine($url) |
|
69
|
|
|
{ |
|
70
|
|
|
$curl = curl_init($url); |
|
71
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
72
|
|
|
curl_exec($curl); |
|
73
|
|
|
|
|
74
|
|
|
if (curl_errno($curl) != 0) { |
|
75
|
|
|
curl_close($curl); |
|
76
|
|
|
|
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$respCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
81
|
|
|
if ($respCode != 200) { |
|
82
|
|
|
curl_close($curl); |
|
83
|
|
|
|
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
curl_close($curl); |
|
88
|
|
|
|
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function writeNewGeocacheUrls() |
|
93
|
|
|
{ |
|
94
|
|
|
$nCount = sql_value('SELECT COUNT(*) FROM `caches` WHERE `caches`.`status`=1', 0); |
|
95
|
|
|
$nIndex = 0; |
|
96
|
|
|
while ($nIndex < $nCount) { |
|
97
|
|
|
$this->oSiteMapXml->write('newcaches.php?startat=' . $nIndex, time(), 'always', 0.7); |
|
98
|
|
|
$nIndex += 100; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function writeArticleUrls() |
|
103
|
|
|
{ |
|
104
|
|
|
$rs = sql("SELECT `href` FROM `sys_menu` WHERE `href` LIKE 'articles.php?page=%'"); |
|
105
|
|
|
while ($r = sql_fetch_assoc($rs)) { |
|
106
|
|
|
$this->oSiteMapXml->write($r['href'], time() - 31 * 24 * 60 * 60, 0.3); |
|
107
|
|
|
} |
|
108
|
|
|
sql_free_result($rs); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function writeViewGeocacheUrls() |
|
112
|
|
|
{ |
|
113
|
|
|
$rs = sql( |
|
114
|
|
|
'SELECT SQL_BUFFER_RESULT `caches`.`wp_oc`, `caches`.`cache_id`, `cache_desc`.`language` |
|
115
|
|
|
FROM `caches` |
|
116
|
|
|
INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id` |
|
117
|
|
|
INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` |
|
118
|
|
|
WHERE `cache_status`.`allow_user_view`=1' |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
while ($r = sql_fetch_assoc($rs)) { |
|
122
|
|
|
$dLastMod = sql_value( |
|
123
|
|
|
"SELECT MAX(`last_modified`) `last_modified` FROM |
|
124
|
|
|
(SELECT `listing_last_modified` AS `last_modified` FROM `caches` WHERE `cache_id` ='&1' UNION |
|
125
|
|
|
SELECT MAX(`last_modified`) AS `last_modified` FROM `cache_logs` WHERE `cache_id` ='&1') `tmp_result`", |
|
126
|
|
|
time(), |
|
127
|
|
|
$r['cache_id'] |
|
128
|
|
|
); |
|
129
|
|
|
$this->oSiteMapXml->write( |
|
130
|
|
|
'viewcache.php?wp=' . $r['wp_oc'] . '&desclang=' . $r['language'], |
|
131
|
|
|
strtotime($dLastMod), |
|
132
|
|
|
0.6 |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
sql_free_result($rs); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|