author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/* |
|
3 |
|
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4 |
$Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee $ |
136 | 5 |
|
6 |
*/ |
|
7 |
||
8 |
//Enable for dev! Good code doesn't generate any notices... |
|
9 |
//error_reporting(E_ALL); |
|
10 |
//ini_set("display_errors",1); |
|
11 |
||
12 |
/** |
|
13 |
* Represents the status (success and failures) of a building process |
|
14 |
* @author Arne Brachhold |
|
15 |
* @package sitemap |
|
16 |
* @since 3.0b5 |
|
17 |
*/ |
|
18 |
class GoogleSitemapGeneratorStatus { |
|
19 |
||
20 |
function GoogleSitemapGeneratorStatus() { |
|
21 |
$this->_startTime = $this->GetMicrotimeFloat(); |
|
22 |
||
23 |
$exists = get_option("sm_status"); |
|
24 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
if($exists === false) add_option("sm_status","",null,"no"); |
136 | 26 |
|
27 |
$this->Save(); |
|
28 |
} |
|
29 |
||
30 |
function Save() { |
|
31 |
update_option("sm_status",$this); |
|
32 |
} |
|
33 |
||
34 |
/** |
|
35 |
* Returns the last saved status object or null |
|
36 |
* |
|
37 |
* @return GoogleSitemapGeneratorStatus |
|
38 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
function &Load() { |
136 | 40 |
$status = @get_option("sm_status"); |
41 |
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status; |
|
42 |
else return null; |
|
43 |
} |
|
44 |
||
45 |
/** |
|
46 |
* @var float $_startTime The start time of the building process |
|
47 |
* @access private |
|
48 |
*/ |
|
49 |
var $_startTime = 0; |
|
50 |
||
51 |
/** |
|
52 |
* @var float $_endTime The end time of the building process |
|
53 |
* @access private |
|
54 |
*/ |
|
55 |
var $_endTime = 0; |
|
56 |
||
57 |
/** |
|
58 |
* @var bool $$_hasChanged Indicates if the sitemap content has changed |
|
59 |
* @access private |
|
60 |
*/ |
|
61 |
var $_hasChanged = true; |
|
62 |
||
63 |
/** |
|
64 |
* @var int $_memoryUsage The amount of memory used in bytes |
|
65 |
* @access private |
|
66 |
*/ |
|
67 |
var $_memoryUsage = 0; |
|
68 |
||
69 |
/** |
|
70 |
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts. |
|
71 |
* @access private |
|
72 |
*/ |
|
73 |
var $_lastPost = 0; |
|
74 |
||
75 |
/** |
|
76 |
* @var int $_lastTime The time when the last step-update occured. This value is updated every 50 posts. |
|
77 |
* @access private |
|
78 |
*/ |
|
79 |
var $_lastTime = 0; |
|
80 |
||
81 |
function End($hasChanged = true) { |
|
82 |
$this->_endTime = $this->GetMicrotimeFloat(); |
|
83 |
||
84 |
$this->SetMemoryUsage(); |
|
85 |
||
86 |
$this->_hasChanged = $hasChanged; |
|
87 |
||
88 |
$this->Save(); |
|
89 |
} |
|
90 |
||
91 |
function SetMemoryUsage() { |
|
92 |
if(function_exists("memory_get_peak_usage")) { |
|
93 |
$this->_memoryUsage = memory_get_peak_usage(true); |
|
94 |
} else if(function_exists("memory_get_usage")) { |
|
95 |
$this->_memoryUsage = memory_get_usage(true); |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
function GetMemoryUsage() { |
|
100 |
return round($this->_memoryUsage / 1024 / 1024,2); |
|
101 |
} |
|
102 |
||
103 |
function SaveStep($postCount) { |
|
104 |
$this->SetMemoryUsage(); |
|
105 |
$this->_lastPost = $postCount; |
|
106 |
$this->_lastTime = $this->GetMicrotimeFloat(); |
|
107 |
||
108 |
$this->Save(); |
|
109 |
} |
|
110 |
||
111 |
function GetTime() { |
|
112 |
return round($this->_endTime - $this->_startTime,2); |
|
113 |
} |
|
114 |
||
115 |
function GetStartTime() { |
|
116 |
return round($this->_startTime, 2); |
|
117 |
} |
|
118 |
||
119 |
function GetLastTime() { |
|
120 |
return round($this->_lastTime - $this->_startTime,2); |
|
121 |
} |
|
122 |
||
123 |
function GetLastPost() { |
|
124 |
return $this->_lastPost; |
|
125 |
} |
|
126 |
||
127 |
var $_usedXml = false; |
|
128 |
var $_xmlSuccess = false; |
|
129 |
var $_xmlPath = ''; |
|
130 |
var $_xmlUrl = ''; |
|
131 |
||
132 |
function StartXml($path,$url) { |
|
133 |
$this->_usedXml = true; |
|
134 |
$this->_xmlPath = $path; |
|
135 |
$this->_xmlUrl = $url; |
|
136 |
||
137 |
$this->Save(); |
|
138 |
} |
|
139 |
||
140 |
function EndXml($success) { |
|
141 |
$this->_xmlSuccess = $success; |
|
142 |
||
143 |
$this->Save(); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
var $_usedZip = false; |
|
148 |
var $_zipSuccess = false; |
|
149 |
var $_zipPath = ''; |
|
150 |
var $_zipUrl = ''; |
|
151 |
||
152 |
function StartZip($path,$url) { |
|
153 |
$this->_usedZip = true; |
|
154 |
$this->_zipPath = $path; |
|
155 |
$this->_zipUrl = $url; |
|
156 |
||
157 |
$this->Save(); |
|
158 |
} |
|
159 |
||
160 |
function EndZip($success) { |
|
161 |
$this->_zipSuccess = $success; |
|
162 |
||
163 |
$this->Save(); |
|
164 |
} |
|
165 |
||
166 |
var $_usedGoogle = false; |
|
167 |
var $_googleUrl = ''; |
|
168 |
var $_gooogleSuccess = false; |
|
169 |
var $_googleStartTime = 0; |
|
170 |
var $_googleEndTime = 0; |
|
171 |
||
172 |
function StartGooglePing($url) { |
|
173 |
$this->_googleUrl = $url; |
|
174 |
$this->_usedGoogle = true; |
|
175 |
$this->_googleStartTime = $this->GetMicrotimeFloat(); |
|
176 |
||
177 |
$this->Save(); |
|
178 |
} |
|
179 |
||
180 |
function EndGooglePing($success) { |
|
181 |
$this->_googleEndTime = $this->GetMicrotimeFloat(); |
|
182 |
$this->_gooogleSuccess = $success; |
|
183 |
||
184 |
$this->Save(); |
|
185 |
} |
|
186 |
||
187 |
function GetGoogleTime() { |
|
188 |
return round($this->_googleEndTime - $this->_googleStartTime,2); |
|
189 |
} |
|
190 |
||
191 |
var $_usedMsn = false; |
|
192 |
var $_msnUrl = ''; |
|
193 |
var $_msnSuccess = false; |
|
194 |
var $_msnStartTime = 0; |
|
195 |
var $_msnEndTime = 0; |
|
196 |
||
197 |
function StartMsnPing($url) { |
|
198 |
$this->_usedMsn = true; |
|
199 |
$this->_msnUrl = $url; |
|
200 |
$this->_msnStartTime = $this->GetMicrotimeFloat(); |
|
201 |
||
202 |
$this->Save(); |
|
203 |
} |
|
204 |
||
205 |
function EndMsnPing($success) { |
|
206 |
$this->_msnEndTime = $this->GetMicrotimeFloat(); |
|
207 |
$this->_msnSuccess = $success; |
|
208 |
||
209 |
$this->Save(); |
|
210 |
} |
|
211 |
||
212 |
function GetMsnTime() { |
|
213 |
return round($this->_msnEndTime - $this->_msnStartTime,2); |
|
214 |
} |
|
215 |
||
216 |
function GetMicrotimeFloat() { |
|
217 |
list($usec, $sec) = explode(" ", microtime()); |
|
218 |
return ((float)$usec + (float)$sec); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Represents an item in the page list |
|
224 |
* @author Arne Brachhold |
|
225 |
* @package sitemap |
|
226 |
* @since 3.0 |
|
227 |
*/ |
|
228 |
class GoogleSitemapGeneratorPage { |
|
229 |
||
230 |
/** |
|
231 |
* @var string $_url Sets the URL or the relative path to the blog dir of the page |
|
232 |
* @access private |
|
233 |
*/ |
|
234 |
var $_url; |
|
235 |
||
236 |
/** |
|
237 |
* @var float $_priority Sets the priority of this page |
|
238 |
* @access private |
|
239 |
*/ |
|
240 |
var $_priority; |
|
241 |
||
242 |
/** |
|
243 |
* @var string $_changeFreq Sets the chanfe frequency of the page. I want Enums! |
|
244 |
* @access private |
|
245 |
*/ |
|
246 |
var $_changeFreq; |
|
247 |
||
248 |
/** |
|
249 |
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp. |
|
250 |
* @access private |
|
251 |
*/ |
|
252 |
var $_lastMod; |
|
253 |
||
254 |
/** |
|
255 |
* Initialize a new page object |
|
256 |
* |
|
257 |
* @since 3.0 |
|
258 |
* @access public |
|
259 |
* @author Arne Brachhold |
|
260 |
* @param bool $enabled Should this page be included in thesitemap |
|
261 |
* @param string $url The URL or path of the file |
|
262 |
* @param float $priority The Priority of the page 0.0 to 1.0 |
|
263 |
* @param string $changeFreq The change frequency like daily, hourly, weekly |
|
264 |
* @param int $lastMod The last mod date as a unix timestamp |
|
265 |
*/ |
|
266 |
function GoogleSitemapGeneratorPage($url="",$priority=0.0,$changeFreq="never",$lastMod=0) { |
|
267 |
$this->SetUrl($url); |
|
268 |
$this->SetProprity($priority); |
|
269 |
$this->SetChangeFreq($changeFreq); |
|
270 |
$this->SetLastMod($lastMod); |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Returns the URL of the page |
|
275 |
* |
|
276 |
* @return string The URL |
|
277 |
*/ |
|
278 |
function GetUrl() { |
|
279 |
return $this->_url; |
|
280 |
} |
|
281 |
||
282 |
/** |
|
283 |
* Sets the URL of the page |
|
284 |
* |
|
285 |
* @param string $url The new URL |
|
286 |
*/ |
|
287 |
function SetUrl($url) { |
|
288 |
$this->_url=(string) $url; |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
* Returns the priority of this page |
|
293 |
* |
|
294 |
* @return float the priority, from 0.0 to 1.0 |
|
295 |
*/ |
|
296 |
function GetPriority() { |
|
297 |
return $this->_priority; |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* Sets the priority of the page |
|
302 |
* |
|
303 |
* @param float $priority The new priority from 0.1 to 1.0 |
|
304 |
*/ |
|
305 |
function SetProprity($priority) { |
|
306 |
$this->_priority=floatval($priority); |
|
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* Returns the change frequency of the page |
|
311 |
* |
|
312 |
* @return string The change frequncy like hourly, weekly, monthly etc. |
|
313 |
*/ |
|
314 |
function GetChangeFreq() { |
|
315 |
return $this->_changeFreq; |
|
316 |
} |
|
317 |
||
318 |
/** |
|
319 |
* Sets the change frequency of the page |
|
320 |
* |
|
321 |
* @param string $changeFreq The new change frequency |
|
322 |
*/ |
|
323 |
function SetChangeFreq($changeFreq) { |
|
324 |
$this->_changeFreq=(string) $changeFreq; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Returns the last mod of the page |
|
329 |
* |
|
330 |
* @return int The lastmod value in seconds |
|
331 |
*/ |
|
332 |
function GetLastMod() { |
|
333 |
return $this->_lastMod; |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Sets the last mod of the page |
|
338 |
* |
|
339 |
* @param int $lastMod The lastmod of the page |
|
340 |
*/ |
|
341 |
function SetLastMod($lastMod) { |
|
342 |
$this->_lastMod=intval($lastMod); |
|
343 |
} |
|
344 |
||
345 |
function Render() { |
|
346 |
||
347 |
if($this->_url == "/" || empty($this->_url)) return ''; |
|
348 |
||
349 |
$r=""; |
|
350 |
$r.= "\t<url>\n"; |
|
351 |
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n"; |
|
352 |
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n"; |
|
353 |
if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->_changeFreq . "</changefreq>\n"; |
|
354 |
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n"; |
|
355 |
$r.= "\t</url>\n"; |
|
356 |
return $r; |
|
357 |
} |
|
358 |
||
359 |
function EscapeXML($string) { |
|
360 |
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&' , '"', ''' , '<' , '>'), $string); |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
class GoogleSitemapGeneratorXmlEntry { |
|
365 |
||
366 |
var $_xml; |
|
367 |
||
368 |
function GoogleSitemapGeneratorXmlEntry($xml) { |
|
369 |
$this->_xml = $xml; |
|
370 |
} |
|
371 |
||
372 |
function Render() { |
|
373 |
return $this->_xml; |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry { |
|
378 |
||
379 |
function Render() { |
|
380 |
return "<!-- " . $this->_xml . " -->\n"; |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
/** |
|
385 |
* Base class for all priority providers |
|
386 |
* @author Arne Brachhold |
|
387 |
* @package sitemap |
|
388 |
* @since 3.0 |
|
389 |
*/ |
|
390 |
class GoogleSitemapGeneratorPrioProviderBase { |
|
391 |
||
392 |
/** |
|
393 |
* @var int $_totalComments The total number of comments of all posts |
|
394 |
* @access protected |
|
395 |
*/ |
|
396 |
var $_totalComments=0; |
|
397 |
||
398 |
/** |
|
399 |
* @var int $_totalComments The total number of posts |
|
400 |
* @access protected |
|
401 |
*/ |
|
402 |
var $_totalPosts=0; |
|
403 |
||
404 |
/** |
|
405 |
* Returns the (translated) name of this priority provider |
|
406 |
* |
|
407 |
* @since 3.0 |
|
408 |
* @access public |
|
409 |
* @author Arne Brachhold |
|
410 |
* @return string The translated name |
|
411 |
*/ |
|
412 |
function GetName() { |
|
413 |
return ""; |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Returns the (translated) description of this priority provider |
|
418 |
* |
|
419 |
* @since 3.0 |
|
420 |
* @access public |
|
421 |
* @author Arne Brachhold |
|
422 |
* @return string The translated description |
|
423 |
*/ |
|
424 |
function GetDescription() { |
|
425 |
return ""; |
|
426 |
} |
|
427 |
||
428 |
/** |
|
429 |
* Initializes a new priority provider |
|
430 |
* |
|
431 |
* @param $totalComments int The total number of comments of all posts |
|
432 |
* @param $totalPosts int The total number of posts |
|
433 |
* @since 3.0 |
|
434 |
* @access public |
|
435 |
* @author Arne Brachhold |
|
436 |
*/ |
|
437 |
function GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts) { |
|
438 |
$this->_totalComments=$totalComments; |
|
439 |
$this->_totalPosts=$totalPosts; |
|
440 |
||
441 |
} |
|
442 |
||
443 |
/** |
|
444 |
* Returns the priority for a specified post |
|
445 |
* |
|
446 |
* @param $postID int The ID of the post |
|
447 |
* @param $commentCount int The number of comments for this post |
|
448 |
* @since 3.0 |
|
449 |
* @access public |
|
450 |
* @author Arne Brachhold |
|
451 |
* @return int The calculated priority |
|
452 |
*/ |
|
453 |
function GetPostPriority($postID,$commentCount) { |
|
454 |
return 0; |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
/** |
|
459 |
* Priority Provider which calculates the priority based on the number of comments |
|
460 |
* @author Arne Brachhold |
|
461 |
* @package sitemap |
|
462 |
* @since 3.0 |
|
463 |
*/ |
|
464 |
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase { |
|
465 |
||
466 |
/** |
|
467 |
* Returns the (translated) name of this priority provider |
|
468 |
* |
|
469 |
* @since 3.0 |
|
470 |
* @access public |
|
471 |
* @author Arne Brachhold |
|
472 |
* @return string The translated name |
|
473 |
*/ |
|
474 |
function GetName() { |
|
475 |
return __("Comment Count",'sitemap'); |
|
476 |
} |
|
477 |
||
478 |
/** |
|
479 |
* Returns the (translated) description of this priority provider |
|
480 |
* |
|
481 |
* @since 3.0 |
|
482 |
* @access public |
|
483 |
* @author Arne Brachhold |
|
484 |
* @return string The translated description |
|
485 |
*/ |
|
486 |
function GetDescription() { |
|
487 |
return __("Uses the number of comments of the post to calculate the priority",'sitemap'); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
491 |
* Initializes a new priority provider which calculates the post priority based on the number of comments |
|
492 |
* |
|
493 |
* @param $totalComments int The total number of comments of all posts |
|
494 |
* @param $totalPosts int The total number of posts |
|
495 |
* @since 3.0 |
|
496 |
* @access public |
|
497 |
* @author Arne Brachhold |
|
498 |
*/ |
|
499 |
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) { |
|
500 |
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts); |
|
501 |
} |
|
502 |
||
503 |
/** |
|
504 |
* Returns the priority for a specified post |
|
505 |
* |
|
506 |
* @param $postID int The ID of the post |
|
507 |
* @param $commentCount int The number of comments for this post |
|
508 |
* @since 3.0 |
|
509 |
* @access public |
|
510 |
* @author Arne Brachhold |
|
511 |
* @return int The calculated priority |
|
512 |
*/ |
|
513 |
function GetPostPriority($postID,$commentCount) { |
|
514 |
$prio=0; |
|
515 |
if($this->_totalComments>0 && $commentCount>0) { |
|
516 |
$prio = round(($commentCount*100/$this->_totalComments)/100,1); |
|
517 |
} else { |
|
518 |
$prio = 0; |
|
519 |
} |
|
520 |
return $prio; |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Priority Provider which calculates the priority based on the average number of comments |
|
526 |
* @author Arne Brachhold |
|
527 |
* @package sitemap |
|
528 |
* @since 3.0 |
|
529 |
*/ |
|
530 |
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase { |
|
531 |
||
532 |
/** |
|
533 |
* @var int $_average The average number of comments per post |
|
534 |
* @access protected |
|
535 |
*/ |
|
536 |
var $_average=0.0; |
|
537 |
||
538 |
/** |
|
539 |
* Returns the (translated) name of this priority provider |
|
540 |
* |
|
541 |
* @since 3.0 |
|
542 |
* @access public |
|
543 |
* @author Arne Brachhold |
|
544 |
* @return string The translated name |
|
545 |
*/ |
|
546 |
function GetName() { |
|
547 |
return __("Comment Average",'sitemap'); |
|
548 |
} |
|
549 |
||
550 |
/** |
|
551 |
* Returns the (translated) description of this priority provider |
|
552 |
* |
|
553 |
* @since 3.0 |
|
554 |
* @access public |
|
555 |
* @author Arne Brachhold |
|
556 |
* @return string The translated description |
|
557 |
*/ |
|
558 |
function GetDescription() { |
|
559 |
return __("Uses the average comment count to calculate the priority",'sitemap'); |
|
560 |
} |
|
561 |
||
562 |
/** |
|
563 |
* Initializes a new priority provider which calculates the post priority based on the average number of comments |
|
564 |
* |
|
565 |
* @param $totalComments int The total number of comments of all posts |
|
566 |
* @param $totalPosts int The total number of posts |
|
567 |
* @since 3.0 |
|
568 |
* @access public |
|
569 |
* @author Arne Brachhold |
|
570 |
*/ |
|
571 |
function GoogleSitemapGeneratorPrioByAverageProvider($totalComments,$totalPosts) { |
|
572 |
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts); |
|
573 |
||
574 |
if($this->_totalComments>0 && $this->_totalPosts>0) { |
|
575 |
$this->_average= (double) $this->_totalComments / $this->_totalPosts; |
|
576 |
} |
|
577 |
} |
|
578 |
||
579 |
/** |
|
580 |
* Returns the priority for a specified post |
|
581 |
* |
|
582 |
* @param $postID int The ID of the post |
|
583 |
* @param $commentCount int The number of comments for this post |
|
584 |
* @since 3.0 |
|
585 |
* @access public |
|
586 |
* @author Arne Brachhold |
|
587 |
* @return int The calculated priority |
|
588 |
*/ |
|
589 |
function GetPostPriority($postID,$commentCount) { |
|
590 |
$prio = 0; |
|
591 |
//Do not divide by zero! |
|
592 |
if($this->_average==0) { |
|
593 |
if($commentCount>0) $prio = 1; |
|
594 |
else $prio = 0; |
|
595 |
} else { |
|
596 |
$prio = $commentCount/$this->_average; |
|
597 |
if($prio>1) $prio = 1; |
|
598 |
else if($prio<0) $prio = 0; |
|
599 |
} |
|
600 |
||
601 |
return round($prio,1); |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
/** |
|
606 |
* Priority Provider which calculates the priority based on the popularity by the PopularityContest Plugin |
|
607 |
* @author Arne Brachhold |
|
608 |
* @package sitemap |
|
609 |
* @since 3.0 |
|
610 |
*/ |
|
611 |
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase { |
|
612 |
||
613 |
/** |
|
614 |
* Returns the (translated) name of this priority provider |
|
615 |
* |
|
616 |
* @since 3.0 |
|
617 |
* @access public |
|
618 |
* @author Arne Brachhold |
|
619 |
* @return string The translated name |
|
620 |
*/ |
|
621 |
function GetName() { |
|
622 |
return __("Popularity Contest",'sitemap'); |
|
623 |
} |
|
624 |
||
625 |
/** |
|
626 |
* Returns the (translated) description of this priority provider |
|
627 |
* |
|
628 |
* @since 3.0 |
|
629 |
* @access public |
|
630 |
* @author Arne Brachhold |
|
631 |
* @return string The translated description |
|
632 |
*/ |
|
633 |
function GetDescription() { |
|
634 |
return str_replace("%4","index.php?page=popularity-contest.php",str_replace("%3","options-general.php?page=popularity-contest.php",str_replace("%2","http://www.alexking.org/",str_replace("%1","http://www.alexking.org/index.php?content=software/wordpress/content.php",__("Uses the activated <a href=\"%1\">Popularity Contest Plugin</a> from <a href=\"%2\">Alex King</a>. See <a href=\"%3\">Settings</a> and <a href=\"%4\">Most Popular Posts</a>",'sitemap'))))); |
|
635 |
} |
|
636 |
||
637 |
/** |
|
638 |
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin |
|
639 |
* |
|
640 |
* @param $totalComments int The total number of comments of all posts |
|
641 |
* @param $totalPosts int The total number of posts |
|
642 |
* @since 3.0 |
|
643 |
* @access public |
|
644 |
* @author Arne Brachhold |
|
645 |
*/ |
|
646 |
function GoogleSitemapGeneratorPrioByPopularityContestProvider($totalComments,$totalPosts) { |
|
647 |
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts); |
|
648 |
} |
|
649 |
||
650 |
/** |
|
651 |
* Returns the priority for a specified post |
|
652 |
* |
|
653 |
* @param $postID int The ID of the post |
|
654 |
* @param $commentCount int The number of comments for this post |
|
655 |
* @since 3.0 |
|
656 |
* @access public |
|
657 |
* @author Arne Brachhold |
|
658 |
* @return int The calculated priority |
|
659 |
*/ |
|
660 |
function GetPostPriority($postID,$commentCount) { |
|
661 |
//$akpc is the global instance of the Popularity Contest Plugin |
|
662 |
global $akpc,$posts; |
|
663 |
||
664 |
$res=0; |
|
665 |
//Better check if its there |
|
666 |
if(!empty($akpc) && is_object($akpc)) { |
|
667 |
//Is the method we rely on available? |
|
668 |
if(method_exists($akpc,"get_post_rank")) { |
|
669 |
if(!is_array($posts) || !$posts) $posts = array(); |
|
670 |
if(!isset($posts[$postID])) $posts[$postID] = get_post($postID); |
|
671 |
//popresult comes as a percent value |
|
672 |
$popresult=$akpc->get_post_rank($postID); |
|
673 |
if(!empty($popresult) && strpos($popresult,"%")!==false) { |
|
674 |
//We need to parse it to get the priority as an int (percent) |
|
675 |
$matches=null; |
|
676 |
preg_match("/([0-9]{1,3})\%/si",$popresult,$matches); |
|
677 |
if(!empty($matches) && is_array($matches) && count($matches)==2) { |
|
678 |
//Divide it so 100% = 1, 10% = 0.1 |
|
679 |
$res=round(intval($matches[1])/100,1); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
return $res; |
|
685 |
} |
|
686 |
} |
|
687 |
||
688 |
/** |
|
689 |
* Class to generate a sitemaps.org Sitemaps compliant sitemap of a WordPress blog. |
|
690 |
* |
|
691 |
* @package sitemap |
|
692 |
* @author Arne Brachhold |
|
693 |
* @since 3.0 |
|
694 |
*/ |
|
695 |
class GoogleSitemapGenerator { |
|
696 |
/** |
|
697 |
* @var Version of the generator in SVN |
|
698 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
699 |
var $_svnVersion = '$Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee $'; |
136 | 700 |
|
701 |
/** |
|
702 |
* @var array The unserialized array with the stored options |
|
703 |
*/ |
|
704 |
var $_options = array(); |
|
705 |
||
706 |
/** |
|
707 |
* @var array The saved additional pages |
|
708 |
*/ |
|
709 |
var $_pages = array(); |
|
710 |
||
711 |
/** |
|
712 |
* @var array The values and names of the change frequencies |
|
713 |
*/ |
|
714 |
var $_freqNames = array(); |
|
715 |
||
716 |
/** |
|
717 |
* @var array A list of class names which my be called for priority calculation |
|
718 |
*/ |
|
719 |
var $_prioProviders = array(); |
|
720 |
||
721 |
/** |
|
722 |
* @var bool True if init complete (options loaded etc) |
|
723 |
*/ |
|
724 |
var $_initiated = false; |
|
725 |
||
726 |
/** |
|
727 |
* @var string Holds the last error if one occurs when writing the files |
|
728 |
*/ |
|
729 |
var $_lastError=null; |
|
730 |
||
731 |
/** |
|
732 |
* @var int The last handled post ID |
|
733 |
*/ |
|
734 |
var $_lastPostID = 0; |
|
735 |
||
736 |
/** |
|
737 |
* @var bool Defines if the sitemap building process is active at the moment |
|
738 |
*/ |
|
739 |
var $_isActive = false; |
|
740 |
||
741 |
/** |
|
742 |
* @var bool Defines if the sitemap building process has been scheduled via Wp cron |
|
743 |
*/ |
|
744 |
var $_isScheduled = false; |
|
745 |
||
746 |
/** |
|
747 |
* @var object The file handle which is used to write the sitemap file |
|
748 |
*/ |
|
749 |
var $_fileHandle = null; |
|
750 |
||
751 |
/** |
|
752 |
* @var object The file handle which is used to write the zipped sitemap file |
|
753 |
*/ |
|
754 |
var $_fileZipHandle = null; |
|
755 |
||
756 |
/** |
|
757 |
* Holds the user interface object |
|
758 |
* |
|
759 |
* @since 3.1.1 |
|
760 |
* @var GoogleSitemapGeneratorUI |
|
761 |
*/ |
|
762 |
var $_ui = null; |
|
763 |
||
764 |
/** |
|
765 |
* Returns the path to the blog directory |
|
766 |
* |
|
767 |
* @since 3.0 |
|
768 |
* @access private |
|
769 |
* @author Arne Brachhold |
|
770 |
* @return string The full path to the blog directory |
|
771 |
*/ |
|
772 |
function GetHomePath() { |
|
773 |
||
774 |
$res=""; |
|
775 |
//Check if we are in the admin area -> get_home_path() is avaiable |
|
776 |
if(function_exists("get_home_path")) { |
|
777 |
$res = get_home_path(); |
|
778 |
} else { |
|
779 |
//get_home_path() is not available, but we can't include the admin |
|
780 |
//libraries because many plugins check for the "check_admin_referer" |
|
781 |
//function to detect if you are on an admin page. So we have to copy |
|
782 |
//the get_home_path function in our own... |
|
783 |
$home = get_option( 'home' ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
784 |
if ( $home != '' && $home != get_option( 'url' ) ) { |
136 | 785 |
$home_path = parse_url( $home ); |
786 |
$home_path = $home_path['path']; |
|
787 |
$root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); |
|
788 |
$home_path = trailingslashit( $root.$home_path ); |
|
789 |
} else { |
|
790 |
$home_path = ABSPATH; |
|
791 |
} |
|
792 |
||
793 |
$res = $home_path; |
|
794 |
} |
|
795 |
return $res; |
|
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Returns the path to the directory where the plugin file is located |
|
800 |
* @since 3.0b5 |
|
801 |
* @access private |
|
802 |
* @author Arne Brachhold |
|
803 |
* @return string The path to the plugin directory |
|
804 |
*/ |
|
805 |
function GetPluginPath() { |
|
806 |
$path = dirname(__FILE__); |
|
807 |
return trailingslashit(str_replace("\\","/",$path)); |
|
808 |
} |
|
809 |
||
810 |
/** |
|
811 |
* Returns the URL to the directory where the plugin file is located |
|
812 |
* @since 3.0b5 |
|
813 |
* @access private |
|
814 |
* @author Arne Brachhold |
|
815 |
* @return string The URL to the plugin directory |
|
816 |
*/ |
|
817 |
function GetPluginUrl() { |
|
818 |
||
819 |
//Try to use WP API if possible, introduced in WP 2.6 |
|
820 |
if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__)))); |
|
821 |
||
822 |
//Try to find manually... can't work if wp-content was renamed or is redirected |
|
823 |
$path = dirname(__FILE__); |
|
824 |
$path = str_replace("\\","/",$path); |
|
825 |
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/"))); |
|
826 |
return $path; |
|
827 |
} |
|
828 |
||
829 |
/** |
|
830 |
* Returns the URL to default XSLT style if it exists |
|
831 |
* @since 3.0b5 |
|
832 |
* @access private |
|
833 |
* @author Arne Brachhold |
|
834 |
* @return string The URL to the default stylesheet, empty string if not available. |
|
835 |
*/ |
|
836 |
function GetDefaultStyle() { |
|
837 |
$p = $this->GetPluginPath(); |
|
838 |
if(file_exists($p . "sitemap.xsl")) { |
|
839 |
$url = $this->GetPluginUrl(); |
|
840 |
//If called over the admin area using HTTPS, the stylesheet would also be https url, even if the blog frontend is not. |
|
841 |
if(substr(get_bloginfo('url'),0,5) !="https" && substr($url,0,5)=="https") $url="http" . substr($url,5); |
|
842 |
return $url . 'sitemap.xsl'; |
|
843 |
} |
|
844 |
return ''; |
|
845 |
} |
|
846 |
||
847 |
/** |
|
848 |
* Sets up the default configuration |
|
849 |
* |
|
850 |
* @since 3.0 |
|
851 |
* @access private |
|
852 |
* @author Arne Brachhold |
|
853 |
*/ |
|
854 |
function InitOptions() { |
|
855 |
||
856 |
$this->_options=array(); |
|
857 |
$this->_options["sm_b_prio_provider"]="GoogleSitemapGeneratorPrioByCountProvider"; //Provider for automatic priority calculation |
|
858 |
$this->_options["sm_b_filename"]="sitemap.xml"; //Name of the Sitemap file |
|
859 |
$this->_options["sm_b_debug"]=true; //Write debug messages in the xml file |
|
860 |
$this->_options["sm_b_xml"]=true; //Create a .xml file |
|
861 |
$this->_options["sm_b_gzip"]=true; //Create a gzipped .xml file(.gz) file |
|
862 |
$this->_options["sm_b_ping"]=true; //Auto ping Google |
|
863 |
$this->_options["sm_b_pingmsn"]=true; //Auto ping MSN |
|
864 |
$this->_options["sm_b_manual_enabled"]=false; //Allow manual creation of the sitemap via GET request |
|
865 |
$this->_options["sm_b_auto_enabled"]=true; //Rebuild sitemap when content is changed |
|
866 |
$this->_options["sm_b_auto_delay"]=true; //Use WP Cron to execute the building process in the background |
|
867 |
$this->_options["sm_b_manual_key"]=md5(microtime());//The secret key to build the sitemap via GET request |
|
868 |
$this->_options["sm_b_memory"] = ''; //Set Memory Limit (e.g. 16M) |
|
869 |
$this->_options["sm_b_time"] = -1; //Set time limit in seconds, 0 for unlimited, -1 for disabled |
|
870 |
$this->_options["sm_b_max_posts"] = -1; //Maximum number of posts, <= 0 for all |
|
871 |
$this->_options["sm_b_safemode"] = false; //Enable MySQL Safe Mode (doesn't use unbuffered results) |
|
872 |
$this->_options["sm_b_style_default"] = true; //Use default style |
|
873 |
$this->_options["sm_b_style"] = ''; //Include a stylesheet in the XML |
|
874 |
$this->_options["sm_b_robots"] = true; //Add sitemap location to WordPress' virtual robots.txt file |
|
875 |
$this->_options["sm_b_exclude"] = array(); //List of post / page IDs to exclude |
|
876 |
$this->_options["sm_b_exclude_cats"] = array(); //List of post / page IDs to exclude |
|
877 |
$this->_options["sm_b_location_mode"]="auto"; //Mode of location, auto or manual |
|
878 |
$this->_options["sm_b_filename_manual"]=""; //Manuel filename |
|
879 |
$this->_options["sm_b_fileurl_manual"]=""; //Manuel fileurl |
|
880 |
||
881 |
$this->_options["sm_in_home"]=true; //Include homepage |
|
882 |
$this->_options["sm_in_posts"]=true; //Include posts |
|
883 |
$this->_options["sm_in_posts_sub"]=false; //Include post pages (<!--nextpage--> tag) |
|
884 |
$this->_options["sm_in_pages"]=true; //Include static pages |
|
885 |
$this->_options["sm_in_cats"]=false; //Include categories |
|
886 |
$this->_options["sm_in_arch"]=false; //Include archives |
|
887 |
$this->_options["sm_in_auth"]=false; //Include author pages |
|
888 |
$this->_options["sm_in_tags"]=false; //Include tag pages |
|
889 |
$this->_options["sm_in_tax"]=array(); //Include additional taxonomies |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
890 |
$this->_options["sm_in_customtypes"]=array(); //Include custom post types |
136 | 891 |
$this->_options["sm_in_lastmod"]=true; //Include the last modification date |
892 |
||
893 |
$this->_options["sm_cf_home"]="daily"; //Change frequency of the homepage |
|
894 |
$this->_options["sm_cf_posts"]="monthly"; //Change frequency of posts |
|
895 |
$this->_options["sm_cf_pages"]="weekly"; //Change frequency of static pages |
|
896 |
$this->_options["sm_cf_cats"]="weekly"; //Change frequency of categories |
|
897 |
$this->_options["sm_cf_auth"]="weekly"; //Change frequency of author pages |
|
898 |
$this->_options["sm_cf_arch_curr"]="daily"; //Change frequency of the current archive (this month) |
|
899 |
$this->_options["sm_cf_arch_old"]="yearly"; //Change frequency of older archives |
|
900 |
$this->_options["sm_cf_tags"]="weekly"; //Change frequency of tags |
|
901 |
||
902 |
$this->_options["sm_pr_home"]=1.0; //Priority of the homepage |
|
903 |
$this->_options["sm_pr_posts"]=0.6; //Priority of posts (if auto prio is disabled) |
|
904 |
$this->_options["sm_pr_posts_min"]=0.2; //Minimum Priority of posts, even if autocalc is enabled |
|
905 |
$this->_options["sm_pr_pages"]=0.6; //Priority of static pages |
|
906 |
$this->_options["sm_pr_cats"]=0.3; //Priority of categories |
|
907 |
$this->_options["sm_pr_arch"]=0.3; //Priority of archives |
|
908 |
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages |
|
909 |
$this->_options["sm_pr_tags"]=0.3; //Priority of tags |
|
910 |
||
911 |
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :) |
|
912 |
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you.. |
|
913 |
$this->_options["sm_i_install_date"]=time(); //The installation date |
|
914 |
$this->_options["sm_i_hide_note"]=false; //Hide the note which appears after 30 days |
|
915 |
$this->_options["sm_i_hide_works"]=false; //Hide the "works?" message which appears after 15 days |
|
916 |
$this->_options["sm_i_hide_donors"]=false; //Hide the list of donations |
|
917 |
} |
|
918 |
||
919 |
/** |
|
920 |
* Loads the configuration from the database |
|
921 |
* |
|
922 |
* @since 3.0 |
|
923 |
* @access private |
|
924 |
* @author Arne Brachhold |
|
925 |
*/ |
|
926 |
function LoadOptions() { |
|
927 |
||
928 |
$this->InitOptions(); |
|
929 |
||
930 |
//First init default values, then overwrite it with stored values so we can add default |
|
931 |
//values with an update which get stored by the next edit. |
|
932 |
$storedoptions=get_option("sm_options"); |
|
933 |
if($storedoptions && is_array($storedoptions)) { |
|
934 |
foreach($storedoptions AS $k=>$v) { |
|
935 |
$this->_options[$k]=$v; |
|
936 |
} |
|
937 |
} else update_option("sm_options",$this->_options); //First time use, store default values |
|
938 |
} |
|
939 |
||
940 |
/** |
|
941 |
* Initializes a new Google Sitemap Generator |
|
942 |
* |
|
943 |
* @since 3.0 |
|
944 |
* @access private |
|
945 |
* @author Arne Brachhold |
|
946 |
*/ |
|
947 |
function GoogleSitemapGenerator() { |
|
948 |
||
949 |
||
950 |
||
951 |
||
952 |
} |
|
953 |
||
954 |
/** |
|
955 |
* Returns the version of the generator |
|
956 |
* |
|
957 |
* @since 3.0 |
|
958 |
* @access public |
|
959 |
* @author Arne Brachhold |
|
960 |
* @return int The version |
|
961 |
*/ |
|
962 |
function GetVersion() { |
|
963 |
return GoogleSitemapGeneratorLoader::GetVersion(); |
|
964 |
} |
|
965 |
||
966 |
/** |
|
967 |
* Returns all parent classes of a class |
|
968 |
* |
|
969 |
* @param $className string The name of the class |
|
970 |
* |
|
971 |
* @since 3.0 |
|
972 |
* @access private |
|
973 |
* @author Arne Brachhold |
|
974 |
* @return array An array which contains the names of the parent classes |
|
975 |
*/ |
|
976 |
function GetParentClasses($classname) { |
|
977 |
$parent = get_parent_class($classname); |
|
978 |
$parents = array(); |
|
979 |
if (!empty($parent)) { |
|
980 |
$parents = $this->GetParentClasses($parent); |
|
981 |
$parents[] = strtolower($parent); |
|
982 |
} |
|
983 |
return $parents; |
|
984 |
} |
|
985 |
||
986 |
/** |
|
987 |
* Returns if a class is a subclass of another class |
|
988 |
* |
|
989 |
* @param $className string The name of the class |
|
990 |
* @param $$parentName string The name of the parent class |
|
991 |
* |
|
992 |
* @since 3.0 |
|
993 |
* @access private |
|
994 |
* @author Arne Brachhold |
|
995 |
* @return bool true if the given class is a subclass of the other one |
|
996 |
*/ |
|
997 |
function IsSubclassOf($className, $parentName) { |
|
998 |
||
999 |
$className = strtolower($className); |
|
1000 |
$parentName = strtolower($parentName); |
|
1001 |
||
1002 |
if(empty($className) || empty($parentName) || !class_exists($className) || !class_exists($parentName)) return false; |
|
1003 |
||
1004 |
$parents=$this->GetParentClasses($className); |
|
1005 |
||
1006 |
return in_array($parentName,$parents); |
|
1007 |
} |
|
1008 |
||
1009 |
/** |
|
1010 |
* Loads up the configuration and validates the prioity providers |
|
1011 |
* |
|
1012 |
* This method is only called if the sitemaps needs to be build or the admin page is displayed. |
|
1013 |
* |
|
1014 |
* @since 3.0 |
|
1015 |
* @access private |
|
1016 |
* @author Arne Brachhold |
|
1017 |
*/ |
|
1018 |
function Initate() { |
|
1019 |
if(!$this->_initiated) { |
|
1020 |
||
1021 |
//Loading language file... |
|
1022 |
//load_plugin_textdomain('sitemap'); |
|
1023 |
//Hmm, doesn't work if the plugin file has its own directory. |
|
1024 |
//Let's make it our way... load_plugin_textdomain() searches only in the wp-content/plugins dir. |
|
1025 |
$currentLocale = get_locale(); |
|
1026 |
if(!empty($currentLocale)) { |
|
1027 |
$moFile = dirname(__FILE__) . "/lang/sitemap-" . $currentLocale . ".mo"; |
|
1028 |
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('sitemap', $moFile); |
|
1029 |
} |
|
1030 |
||
1031 |
$this->_freqNames = array( |
|
1032 |
"always"=>__("Always","sitemap"), |
|
1033 |
"hourly"=>__("Hourly","sitemap"), |
|
1034 |
"daily"=>__("Daily","sitemap"), |
|
1035 |
"weekly"=>__("Weekly","sitemap"), |
|
1036 |
"monthly"=>__("Monthly","sitemap"), |
|
1037 |
"yearly"=>__("Yearly","sitemap"), |
|
1038 |
"never"=>__("Never","sitemap") |
|
1039 |
); |
|
1040 |
||
1041 |
||
1042 |
$this->LoadOptions(); |
|
1043 |
$this->LoadPages(); |
|
1044 |
||
1045 |
//Register our own priority providers |
|
1046 |
add_filter("sm_add_prio_provider",array(&$this, 'AddDefaultPrioProviders')); |
|
1047 |
||
1048 |
//Let other plugins register their providers |
|
1049 |
$r = apply_filters("sm_add_prio_provider",$this->_prioProviders); |
|
1050 |
||
1051 |
//Check if no plugin return null |
|
1052 |
if($r != null) $this->_prioProviders = $r; |
|
1053 |
||
1054 |
$this->ValidatePrioProviders(); |
|
1055 |
||
1056 |
$this->_initiated = true; |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
/** |
|
1061 |
* Returns the instance of the Sitemap Generator |
|
1062 |
* |
|
1063 |
* @since 3.0 |
|
1064 |
* @access public |
|
1065 |
* @return GoogleSitemapGenerator The instance or null if not available. |
|
1066 |
* @author Arne Brachhold |
|
1067 |
*/ |
|
1068 |
function &GetInstance() { |
|
1069 |
if(isset($GLOBALS["sm_instance"])) { |
|
1070 |
return $GLOBALS["sm_instance"]; |
|
1071 |
} else return null; |
|
1072 |
} |
|
1073 |
||
1074 |
/** |
|
1075 |
* Returns if the sitemap building process is currently active |
|
1076 |
* |
|
1077 |
* @since 3.0 |
|
1078 |
* @access public |
|
1079 |
* @return bool true if active |
|
1080 |
* @author Arne Brachhold |
|
1081 |
*/ |
|
1082 |
function IsActive() { |
|
1083 |
$inst = &GoogleSitemapGenerator::GetInstance(); |
|
1084 |
return ($inst != null && $inst->_isActive); |
|
1085 |
} |
|
1086 |
||
1087 |
/** |
|
1088 |
* Returns if the compressed sitemap was activated |
|
1089 |
* |
|
1090 |
* @since 3.0b8 |
|
1091 |
* @access private |
|
1092 |
* @author Arne Brachhold |
|
1093 |
* @return true if compressed |
|
1094 |
*/ |
|
1095 |
function IsGzipEnabled() { |
|
1096 |
return ($this->GetOption("b_gzip")===true && function_exists("gzwrite")); |
|
1097 |
} |
|
1098 |
||
1099 |
/** |
|
1100 |
* Returns if this version of WordPress supports the new taxonomy system |
|
1101 |
* |
|
1102 |
* @since 3.0b8 |
|
1103 |
* @access private |
|
1104 |
* @author Arne Brachhold |
|
1105 |
* @return true if supported |
|
1106 |
*/ |
|
1107 |
function IsTaxonomySupported() { |
|
1108 |
return (function_exists("get_taxonomy") && function_exists("get_terms")); |
|
1109 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1110 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1111 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1112 |
* Returns if this version of WordPress supports custom post types |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1113 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1114 |
* @since 3.2.5 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1115 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1116 |
* @author Lee Willis |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1117 |
* @return true if supported |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1119 |
function IsCustomPostTypesSupported() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1120 |
return (function_exists("get_post_types") && function_exists("register_post_type")); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1121 |
} |
136 | 1122 |
|
1123 |
/** |
|
1124 |
* Returns the list of custom taxonies. These are basically all taxonomies without categories and post tags |
|
1125 |
* |
|
1126 |
* @since 3.1.7 |
|
1127 |
* @return array Array of names of user-defined taxonomies |
|
1128 |
*/ |
|
1129 |
function GetCustomTaxonomies() { |
|
1130 |
$taxonomies = get_object_taxonomies('post'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1131 |
return array_diff($taxonomies,array("category","post_tag","post_format")); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1132 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1133 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1134 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1135 |
* Returns the list of custom post types. These are all custome post types except post, page and attachment |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1136 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1137 |
* @since 3.2.5 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1138 |
* @author Lee Willis |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1139 |
* @return array Array of custom post types as per get_post_types |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1140 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1141 |
function GetCustomPostTypes() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1142 |
$post_types = get_post_types(array("public"=>1)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1143 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1144 |
$post_types = array_diff($post_types,array("post","page","attachment")); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1145 |
return $post_types; |
136 | 1146 |
} |
1147 |
||
1148 |
/** |
|
1149 |
* Enables the Google Sitemap Generator and registers the WordPress hooks |
|
1150 |
* |
|
1151 |
* @since 3.0 |
|
1152 |
* @access public |
|
1153 |
* @author Arne Brachhold |
|
1154 |
*/ |
|
1155 |
function Enable() { |
|
1156 |
if(!isset($GLOBALS["sm_instance"])) { |
|
1157 |
$GLOBALS["sm_instance"]=new GoogleSitemapGenerator(); |
|
1158 |
} |
|
1159 |
} |
|
1160 |
||
1161 |
/** |
|
1162 |
* Checks if sitemap building after content changed is enabled and rebuild the sitemap |
|
1163 |
* |
|
1164 |
* @param int $postID The ID of the post to handle. Used to avoid double rebuilding if more than one hook was fired. |
|
1165 |
* @param bool $external Added in 3.1.9. Skips checking of b_auto_enabled if set to true |
|
1166 |
* @since 3.0 |
|
1167 |
* @access public |
|
1168 |
* @author Arne Brachhold |
|
1169 |
*/ |
|
1170 |
function CheckForAutoBuild($postID, $external = false) { |
|
1171 |
global $wp_version; |
|
1172 |
$this->Initate(); |
|
1173 |
//Build one time per post and if not importing. |
|
1174 |
if((($this->GetOption("b_auto_enabled")===true && $this->_lastPostID != $postID) || $external) && (!defined('WP_IMPORTING') || WP_IMPORTING != true)) { |
|
1175 |
||
1176 |
//Build the sitemap directly or schedule it with WP cron |
|
1177 |
if($this->GetOption("b_auto_delay")==true && floatval($wp_version) >= 2.1) { |
|
1178 |
if(!$this->_isScheduled) { |
|
1179 |
//Schedule in 15 seconds, this should be enough to catch all changes. |
|
1180 |
//Clear all other existing hooks, so the sitemap is only built once. |
|
1181 |
wp_clear_scheduled_hook('sm_build_cron'); |
|
1182 |
wp_schedule_single_event(time()+15,'sm_build_cron'); |
|
1183 |
$this->_isScheduled = true; |
|
1184 |
} |
|
1185 |
} else { |
|
1186 |
//Build sitemap only once and never in bulk mode |
|
1187 |
if(!$this->_lastPostID && (!isset($_GET["delete"]) || count((array) $_GET['delete'])<=0)) { |
|
1188 |
$this->BuildSitemap(); |
|
1189 |
} |
|
1190 |
} |
|
1191 |
$this->_lastPostID = $postID; |
|
1192 |
} |
|
1193 |
} |
|
1194 |
||
1195 |
/** |
|
1196 |
* Builds the sitemap by external request, for example other plugins. |
|
1197 |
* |
|
1198 |
* @since 3.1.9 |
|
1199 |
* @return null |
|
1200 |
*/ |
|
1201 |
function BuildNowRequest() { |
|
1202 |
$this->CheckForAutoBuild(null, true); |
|
1203 |
} |
|
1204 |
||
1205 |
/** |
|
1206 |
* Checks if the rebuild request was send and starts to rebuilt the sitemap |
|
1207 |
* |
|
1208 |
* @since 3.0 |
|
1209 |
* @access public |
|
1210 |
* @author Arne Brachhold |
|
1211 |
*/ |
|
1212 |
function CheckForManualBuild() { |
|
1213 |
if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) { |
|
1214 |
$this->Initate(); |
|
1215 |
if($this->GetOption("b_manual_enabled")===true && $_GET["sm_command"]=="build" && $_GET["sm_key"]==$this->GetOption("b_manual_key")) { |
|
1216 |
$this->BuildSitemap(); |
|
1217 |
echo "DONE"; |
|
1218 |
exit; |
|
1219 |
} |
|
1220 |
} |
|
1221 |
} |
|
1222 |
||
1223 |
/** |
|
1224 |
* Validates all given Priority Providers by checking them for required methods and existence |
|
1225 |
* |
|
1226 |
* @since 3.0 |
|
1227 |
* @access private |
|
1228 |
* @author Arne Brachhold |
|
1229 |
*/ |
|
1230 |
function ValidatePrioProviders() { |
|
1231 |
$validProviders=array(); |
|
1232 |
||
1233 |
for($i=0; $i<count($this->_prioProviders); $i++) { |
|
1234 |
if(class_exists($this->_prioProviders[$i])) { |
|
1235 |
if($this->IsSubclassOf($this->_prioProviders[$i],"GoogleSitemapGeneratorPrioProviderBase")) { |
|
1236 |
array_push($validProviders,$this->_prioProviders[$i]); |
|
1237 |
} |
|
1238 |
} |
|
1239 |
} |
|
1240 |
$this->_prioProviders=$validProviders; |
|
1241 |
||
1242 |
if(!$this->GetOption("b_prio_provider")) { |
|
1243 |
if(!in_array($this->GetOption("b_prio_provider"),$this->_prioProviders,true)) { |
|
1244 |
$this->SetOption("b_prio_provider",""); |
|
1245 |
} |
|
1246 |
} |
|
1247 |
} |
|
1248 |
||
1249 |
/** |
|
1250 |
* Adds the default Priority Providers to the provider list |
|
1251 |
* |
|
1252 |
* @since 3.0 |
|
1253 |
* @access private |
|
1254 |
* @author Arne Brachhold |
|
1255 |
*/ |
|
1256 |
function AddDefaultPrioProviders($providers) { |
|
1257 |
array_push($providers,"GoogleSitemapGeneratorPrioByCountProvider"); |
|
1258 |
array_push($providers,"GoogleSitemapGeneratorPrioByAverageProvider"); |
|
1259 |
if(class_exists("ak_popularity_contest")) { |
|
1260 |
array_push($providers,"GoogleSitemapGeneratorPrioByPopularityContestProvider"); |
|
1261 |
} |
|
1262 |
return $providers; |
|
1263 |
} |
|
1264 |
||
1265 |
/** |
|
1266 |
* Loads the stored pages from the database |
|
1267 |
* |
|
1268 |
* @since 3.0 |
|
1269 |
* @access private |
|
1270 |
* @author Arne Brachhold |
|
1271 |
*/ |
|
1272 |
function LoadPages() { |
|
1273 |
global $wpdb; |
|
1274 |
||
1275 |
$needsUpdate=false; |
|
1276 |
||
1277 |
$pagesString=$wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'sm_cpages'"); |
|
1278 |
||
1279 |
//Class sm_page was renamed with 3.0 -> rename it in serialized value for compatibility |
|
1280 |
if(!empty($pagesString) && strpos($pagesString,"sm_page")!==false) { |
|
1281 |
$pagesString = str_replace("O:7:\"sm_page\"","O:26:\"GoogleSitemapGeneratorPage\"",$pagesString); |
|
1282 |
$needsUpdate=true; |
|
1283 |
} |
|
1284 |
||
1285 |
if(!empty($pagesString)) { |
|
1286 |
$storedpages=unserialize($pagesString); |
|
1287 |
$this->_pages=$storedpages; |
|
1288 |
} else { |
|
1289 |
$this->_pages=array(); |
|
1290 |
} |
|
1291 |
||
1292 |
if($needsUpdate) $this->SavePages(); |
|
1293 |
} |
|
1294 |
||
1295 |
/** |
|
1296 |
* Saved the additional pages back to the database |
|
1297 |
* |
|
1298 |
* @since 3.0 |
|
1299 |
* @access private |
|
1300 |
* @author Arne Brachhold |
|
1301 |
* @return true on success |
|
1302 |
*/ |
|
1303 |
function SavePages() { |
|
1304 |
$oldvalue = get_option("sm_cpages"); |
|
1305 |
if($oldvalue == $this->_pages) { |
|
1306 |
return true; |
|
1307 |
} else { |
|
1308 |
delete_option("sm_cpages"); |
|
1309 |
//Add the option, Note the autoload=false because when the autoload happens, our class GoogleSitemapGeneratorPage doesn't exist |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1310 |
add_option("sm_cpages",$this->_pages,null,"no"); |
136 | 1311 |
return true; |
1312 |
} |
|
1313 |
} |
|
1314 |
||
1315 |
||
1316 |
/** |
|
1317 |
* Returns the URL for the sitemap file |
|
1318 |
* |
|
1319 |
* @since 3.0 |
|
1320 |
* @access private |
|
1321 |
* @author Arne Brachhold |
|
1322 |
* @param bool $forceAuto Force the return value to the autodetected value. |
|
1323 |
* @return The URL to the Sitemap file |
|
1324 |
*/ |
|
1325 |
function GetXmlUrl($forceAuto=false) { |
|
1326 |
||
1327 |
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") { |
|
1328 |
return $this->GetOption("b_fileurl_manual"); |
|
1329 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1330 |
return trailingslashit(get_bloginfo('url')). $this->GetOption("b_filename"); |
136 | 1331 |
} |
1332 |
} |
|
1333 |
||
1334 |
/** |
|
1335 |
* Returns the URL for the gzipped sitemap file |
|
1336 |
* |
|
1337 |
* @since 3.0 |
|
1338 |
* @access private |
|
1339 |
* @author Arne Brachhold |
|
1340 |
* @param bool $forceAuto Force the return value to the autodetected value. |
|
1341 |
* @return The URL to the gzipped Sitemap file |
|
1342 |
*/ |
|
1343 |
function GetZipUrl($forceAuto=false) { |
|
1344 |
return $this->GetXmlUrl($forceAuto) . ".gz"; |
|
1345 |
} |
|
1346 |
||
1347 |
/** |
|
1348 |
* Returns the file system path to the sitemap file |
|
1349 |
* |
|
1350 |
* @since 3.0 |
|
1351 |
* @access private |
|
1352 |
* @author Arne Brachhold |
|
1353 |
* @param bool $forceAuto Force the return value to the autodetected value. |
|
1354 |
* @return The file system path; |
|
1355 |
*/ |
|
1356 |
function GetXmlPath($forceAuto=false) { |
|
1357 |
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") { |
|
1358 |
return $this->GetOption("b_filename_manual"); |
|
1359 |
} else { |
|
1360 |
return $this->GetHomePath() . $this->GetOption("b_filename"); |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
/** |
|
1365 |
* Returns the file system path to the gzipped sitemap file |
|
1366 |
* |
|
1367 |
* @since 3.0 |
|
1368 |
* @access private |
|
1369 |
* @author Arne Brachhold |
|
1370 |
* @param bool $forceAuto Force the return value to the autodetected value. |
|
1371 |
* @return The file system path; |
|
1372 |
*/ |
|
1373 |
function GetZipPath($forceAuto=false) { |
|
1374 |
return $this->GetXmlPath($forceAuto) . ".gz"; |
|
1375 |
} |
|
1376 |
||
1377 |
/** |
|
1378 |
* Returns the option value for the given key |
|
1379 |
* |
|
1380 |
* @since 3.0 |
|
1381 |
* @access private |
|
1382 |
* @author Arne Brachhold |
|
1383 |
* @param $key string The Configuration Key |
|
1384 |
* @return mixed The value |
|
1385 |
*/ |
|
1386 |
function GetOption($key) { |
|
1387 |
$key="sm_" . $key; |
|
1388 |
if(array_key_exists($key,$this->_options)) { |
|
1389 |
return $this->_options[$key]; |
|
1390 |
} else return null; |
|
1391 |
} |
|
1392 |
||
1393 |
/** |
|
1394 |
* Sets an option to a new value |
|
1395 |
* |
|
1396 |
* @since 3.0 |
|
1397 |
* @access private |
|
1398 |
* @author Arne Brachhold |
|
1399 |
* @param $key string The configuration key |
|
1400 |
* @param $value mixed The new object |
|
1401 |
*/ |
|
1402 |
function SetOption($key,$value) { |
|
1403 |
if(strstr($key,"sm_")!==0) $key="sm_" . $key; |
|
1404 |
||
1405 |
$this->_options[$key]=$value; |
|
1406 |
} |
|
1407 |
||
1408 |
/** |
|
1409 |
* Saves the options back to the database |
|
1410 |
* |
|
1411 |
* @since 3.0 |
|
1412 |
* @access private |
|
1413 |
* @author Arne Brachhold |
|
1414 |
* @return bool true on success |
|
1415 |
*/ |
|
1416 |
function SaveOptions() { |
|
1417 |
$oldvalue = get_option("sm_options"); |
|
1418 |
if($oldvalue == $this->_options) { |
|
1419 |
return true; |
|
1420 |
} else return update_option("sm_options",$this->_options); |
|
1421 |
} |
|
1422 |
||
1423 |
/** |
|
1424 |
* Retrieves the number of comments of a post in a asso. array |
|
1425 |
* The key is the postID, the value the number of comments |
|
1426 |
* |
|
1427 |
* @since 3.0 |
|
1428 |
* @access private |
|
1429 |
* @author Arne Brachhold |
|
1430 |
* @return array An array with postIDs and their comment count |
|
1431 |
*/ |
|
1432 |
function GetComments() { |
|
1433 |
global $wpdb; |
|
1434 |
$comments=array(); |
|
1435 |
||
1436 |
//Query comments and add them into the array |
|
1437 |
$commentRes=$wpdb->get_results("SELECT `comment_post_ID` as `post_id`, COUNT(comment_ID) as `comment_count` FROM `" . $wpdb->comments . "` WHERE `comment_approved`='1' GROUP BY `comment_post_ID`"); |
|
1438 |
if($commentRes) { |
|
1439 |
foreach($commentRes as $comment) { |
|
1440 |
$comments[$comment->post_id]=$comment->comment_count; |
|
1441 |
} |
|
1442 |
} |
|
1443 |
return $comments; |
|
1444 |
} |
|
1445 |
||
1446 |
/** |
|
1447 |
* Calculates the full number of comments from an sm_getComments() generated array |
|
1448 |
* |
|
1449 |
* @since 3.0 |
|
1450 |
* @access private |
|
1451 |
* @author Arne Brachhold |
|
1452 |
* @param $comments array The Array with posts and c0mment count |
|
1453 |
* @see sm_getComments |
|
1454 |
* @return The full number of comments |
|
1455 |
*/ |
|
1456 |
function GetCommentCount($comments) { |
|
1457 |
$commentCount=0; |
|
1458 |
foreach($comments AS $k=>$v) { |
|
1459 |
$commentCount+=$v; |
|
1460 |
} |
|
1461 |
return $commentCount; |
|
1462 |
} |
|
1463 |
||
1464 |
/** |
|
1465 |
* Adds a url to the sitemap. You can use this method or call AddElement directly. |
|
1466 |
* |
|
1467 |
* @since 3.0 |
|
1468 |
* @access public |
|
1469 |
* @author Arne Brachhold |
|
1470 |
* @param $loc string The location (url) of the page |
|
1471 |
* @param $lastMod int The last Modification time as a UNIX timestamp |
|
1472 |
* @param $changeFreq string The change frequenty of the page, Valid values are "always", "hourly", "daily", "weekly", "monthly", "yearly" and "never". |
|
1473 |
* @param $priorty float The priority of the page, between 0.0 and 1.0 |
|
1474 |
* @see AddElement |
|
1475 |
* @return string The URL node |
|
1476 |
*/ |
|
1477 |
function AddUrl($loc, $lastMod = 0, $changeFreq = "monthly", $priority = 0.5) { |
|
1478 |
//Strip out the last modification time if activated |
|
1479 |
if($this->GetOption('in_lastmod')===false) $lastMod = 0; |
|
1480 |
$page = new GoogleSitemapGeneratorPage($loc, $priority, $changeFreq, $lastMod); |
|
1481 |
||
1482 |
$this->AddElement($page); |
|
1483 |
} |
|
1484 |
||
1485 |
/** |
|
1486 |
* Adds an element to the sitemap |
|
1487 |
* |
|
1488 |
* @since 3.0 |
|
1489 |
* @access private |
|
1490 |
* @author Arne Brachhold |
|
1491 |
* @param $page The element |
|
1492 |
*/ |
|
1493 |
function AddElement(&$page) { |
|
1494 |
if(empty($page)) return; |
|
1495 |
||
1496 |
$s = $page->Render(); |
|
1497 |
||
1498 |
if($this->_fileZipHandle && $this->IsGzipEnabled()) { |
|
1499 |
gzwrite($this->_fileZipHandle,$s); |
|
1500 |
} |
|
1501 |
||
1502 |
if($this->_fileHandle && $this->GetOption("b_xml")) { |
|
1503 |
fwrite($this->_fileHandle,$s); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
/** |
|
1508 |
* Checks if a file is writable and tries to make it if not. |
|
1509 |
* |
|
1510 |
* @since 3.05b |
|
1511 |
* @access private |
|
1512 |
* @author VJTD3 <http://www.VJTD3.com> |
|
1513 |
* @return bool true if writable |
|
1514 |
*/ |
|
1515 |
function IsFileWritable($filename) { |
|
1516 |
//can we write? |
|
1517 |
if(!is_writable($filename)) { |
|
1518 |
//no we can't. |
|
1519 |
if(!@chmod($filename, 0666)) { |
|
1520 |
$pathtofilename = dirname($filename); |
|
1521 |
//Lets check if parent directory is writable. |
|
1522 |
if(!is_writable($pathtofilename)) { |
|
1523 |
//it's not writeable too. |
|
1524 |
if(!@chmod($pathtoffilename, 0666)) { |
|
1525 |
//darn couldn't fix up parrent directory this hosting is foobar. |
|
1526 |
//Lets error because of the permissions problems. |
|
1527 |
return false; |
|
1528 |
} |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} |
|
1532 |
//we can write, return 1/true/happy dance. |
|
1533 |
return true; |
|
1534 |
} |
|
1535 |
||
1536 |
/** |
|
1537 |
* Adds the sitemap to the virtual robots.txt file |
|
1538 |
* This function is executed by WordPress with the do_robots hook |
|
1539 |
* |
|
1540 |
* @since 3.1.2 |
|
1541 |
*/ |
|
1542 |
function DoRobots() { |
|
1543 |
$this->Initate(); |
|
1544 |
if($this->GetOption('b_robots') === true) { |
|
1545 |
||
1546 |
$smUrl = $this->GetXmlUrl(); |
|
1547 |
if($this->IsGzipEnabled()) { |
|
1548 |
$smUrl = $this->GetZipUrl(); |
|
1549 |
} |
|
1550 |
||
1551 |
echo "\nSitemap: " . $smUrl . "\n"; |
|
1552 |
} |
|
1553 |
} |
|
1554 |
||
1555 |
/** |
|
1556 |
* Builds the sitemap and writes it into a xml file. |
|
1557 |
* |
|
1558 |
* ATTENTION PLUGIN DEVELOPERS! DONT CALL THIS METHOD DIRECTLY! |
|
1559 |
* The method is probably not available, since it is only loaded when needed. |
|
1560 |
* Use do_action("sm_rebuild"); if you want to rebuild the sitemap. |
|
1561 |
* Please refer to the documentation.txt for more details. |
|
1562 |
* |
|
1563 |
* @since 3.0 |
|
1564 |
* @access public |
|
1565 |
* @author Arne Brachhold <himself [at] arnebrachhold [dot] de> |
|
1566 |
* @return array An array with messages such as failed writes etc. |
|
1567 |
*/ |
|
1568 |
function BuildSitemap() { |
|
1569 |
global $wpdb, $posts, $wp_version; |
|
1570 |
$this->Initate(); |
|
1571 |
||
1572 |
if($this->GetOption("b_memory")!='') { |
|
1573 |
@ini_set("memory_limit",$this->GetOption("b_memory")); |
|
1574 |
} |
|
1575 |
||
1576 |
if($this->GetOption("b_time")!=-1) { |
|
1577 |
@set_time_limit($this->GetOption("b_time")); |
|
1578 |
} |
|
1579 |
||
1580 |
//This object saves the status information of the script directly to the database |
|
1581 |
$status = new GoogleSitemapGeneratorStatus(); |
|
1582 |
||
1583 |
//Other plugins can detect if the building process is active |
|
1584 |
$this->_isActive = true; |
|
1585 |
||
1586 |
//$this->AddElement(new GoogleSitemapGeneratorXmlEntry()); |
|
1587 |
||
1588 |
//Debug mode? |
|
1589 |
$debug=$this->GetOption("b_debug"); |
|
1590 |
||
1591 |
if($this->GetOption("b_xml")) { |
|
1592 |
$fileName = $this->GetXmlPath(); |
|
1593 |
$status->StartXml($this->GetXmlPath(),$this->GetXmlUrl()); |
|
1594 |
||
1595 |
if($this->IsFileWritable($fileName)) { |
|
1596 |
||
1597 |
$this->_fileHandle = fopen($fileName,"w"); |
|
1598 |
if(!$this->_fileHandle) $status->EndXml(false,"Not openable"); |
|
1599 |
||
1600 |
} else $status->EndXml(false,"not writable"); |
|
1601 |
} |
|
1602 |
||
1603 |
//Write gzipped sitemap file |
|
1604 |
if($this->IsGzipEnabled()) { |
|
1605 |
$fileName = $this->GetZipPath(); |
|
1606 |
$status->StartZip($this->GetZipPath(),$this->GetZipUrl()); |
|
1607 |
||
1608 |
if($this->IsFileWritable($fileName)) { |
|
1609 |
||
1610 |
$this->_fileZipHandle = gzopen($fileName,"w1"); |
|
1611 |
if(!$this->_fileZipHandle) $status->EndZip(false,"Not openable"); |
|
1612 |
||
1613 |
} else $status->EndZip(false,"not writable"); |
|
1614 |
} |
|
1615 |
||
1616 |
if(!$this->_fileHandle && !$this->_fileZipHandle) { |
|
1617 |
$status->End(); |
|
1618 |
return; |
|
1619 |
} |
|
1620 |
||
1621 |
||
1622 |
//Content of the XML file |
|
1623 |
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>')); |
|
1624 |
||
1625 |
$styleSheet = ($this->GetDefaultStyle() && $this->GetOption('b_style_default')===true?$this->GetDefaultStyle():$this->GetOption('b_style')); |
|
1626 |
||
1627 |
if(!empty($styleSheet)) { |
|
1628 |
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $styleSheet . '"?' . '>')); |
|
1629 |
} |
|
1630 |
||
1631 |
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\"")); |
|
1632 |
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("sitemap-generator-url=\"http://www.arnebrachhold.de\" sitemap-generator-version=\"" . $this->GetVersion() . "\"")); |
|
1633 |
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generated-on=\"" . date(get_option("date_format") . " " . get_option("time_format")) . "\"")); |
|
1634 |
||
1635 |
//All comments as an asso. Array (postID=>commentCount) |
|
1636 |
$comments=($this->GetOption("b_prio_provider")!=""?$this->GetComments():array()); |
|
1637 |
||
1638 |
//Full number of comments |
|
1639 |
$commentCount=(count($comments)>0?$this->GetCommentCount($comments):0); |
|
1640 |
||
1641 |
if($debug && $this->GetOption("b_prio_provider")!="") { |
|
1642 |
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount)); |
|
1643 |
} |
|
1644 |
||
1645 |
//Go XML! |
|
1646 |
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')); |
|
1647 |
||
1648 |
$home = get_bloginfo('url'); |
|
1649 |
||
1650 |
$homePid = 0; |
|
1651 |
||
1652 |
//Add the home page (WITH a slash!) |
|
1653 |
if($this->GetOption("in_home")) { |
|
1654 |
if('page' == get_option('show_on_front') && get_option('page_on_front')) { |
|
1655 |
$pageOnFront = get_option('page_on_front'); |
|
1656 |
$p = get_page($pageOnFront); |
|
1657 |
if($p) { |
|
1658 |
$homePid = $p->ID; |
|
1659 |
$this->AddUrl(trailingslashit($home),$this->GetTimestampFromMySql(($p->post_modified_gmt && $p->post_modified_gmt!='0000-00-00 00:00:00'?$p->post_modified_gmt:$p->post_date_gmt)),$this->GetOption("cf_home"),$this->GetOption("pr_home")); |
|
1660 |
} |
|
1661 |
} else { |
|
1662 |
$this->AddUrl(trailingslashit($home),$this->GetTimestampFromMySql(get_lastpostmodified('GMT')),$this->GetOption("cf_home"),$this->GetOption("pr_home")); |
|
1663 |
} |
|
1664 |
} |
|
1665 |
||
1666 |
//Add the posts |
|
1667 |
if($this->GetOption("in_posts") || $this->GetOption("in_pages")) { |
|
1668 |
||
1669 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Postings")); |
|
1670 |
||
1671 |
//Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date |
|
1672 |
$wpCompat = (floatval($wp_version) < 2.1); |
|
1673 |
||
1674 |
$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet |
|
1675 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1676 |
$excludes = $this->GetOption('b_exclude'); //Excluded posts and pages (user enetered ID) |
136 | 1677 |
|
1678 |
$exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats |
|
1679 |
||
1680 |
if($exclCats && count($exclCats)>0 && $this->IsTaxonomySupported()) { |
|
1681 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1682 |
$excludedCatPosts = get_objects_in_term($exclCats,"category"); // Get all posts in excl. cats. Unforttunately this also gives us pages, revisions and so on... |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1683 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1684 |
//Remove the pages, revisions etc from the exclude by category list, because they are always in the uncategorized one. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1685 |
if(count($excludedCatPosts)>0) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1686 |
$exclPages = $wpdb->get_col("SELECT ID FROM `" . $wpdb->posts . "` WHERE post_type!='post' AND ID IN ('" . implode("','",$excludedCatPosts) . "')"); |
136 | 1687 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1688 |
$exclPages = array_map('intval', $exclPages); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1689 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1690 |
//Remove the pages from the exlusion list before |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1691 |
if(count($exclPages)>0) $excludedCatPosts = array_diff($excludedCatPosts, $exclPages); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1692 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1693 |
//Merge the category exclusion list with the users one |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1694 |
if(count($excludedCatPosts)>0) $excludes = array_merge($excludes, $excludedCatPosts); |
136 | 1695 |
} |
1696 |
} |
|
1697 |
||
1698 |
||
1699 |
$contentStmt = ''; |
|
1700 |
if($useQTransLate) { |
|
1701 |
$contentStmt.=', post_content '; |
|
1702 |
} |
|
1703 |
||
1704 |
$postPageStmt = ''; |
|
1705 |
||
1706 |
$inSubPages = ($this->GetOption('in_posts_sub')===true); |
|
1707 |
||
1708 |
if($inSubPages && $this->GetOption('in_posts')===true) { |
|
1709 |
$pageDivider='<!--nextpage-->'; |
|
1710 |
$postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '$pageDivider', ''))) / " . strlen($pageDivider) . " as postPages"; |
|
1711 |
} |
|
1712 |
||
1713 |
$sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` $postPageStmt $contentStmt FROM `" . $wpdb->posts . "` WHERE "; |
|
1714 |
||
1715 |
$where = '('; |
|
1716 |
||
1717 |
if($this->GetOption('in_posts')) { |
|
1718 |
//WP < 2.1: posts are post_status = publish |
|
1719 |
//WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future' |
|
1720 |
if($wpCompat) $where.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1721 |
else if ($this->IsCustomPostTypesSupported() && count($this->GetOption('in_customtypes'))>0) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1722 |
$where.=" (post_status = 'publish' AND (post_type in ('','post'"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1723 |
foreach ($this->GetOption('in_customtypes') as $customType) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1724 |
$where.= ",'$customType'"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1725 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1726 |
$where .= "))) "; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1727 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1728 |
$where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) "; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1729 |
} |
136 | 1730 |
} |
1731 |
||
1732 |
if($this->GetOption('in_pages')) { |
|
1733 |
if($this->GetOption('in_posts')) { |
|
1734 |
$where.=" OR "; |
|
1735 |
} |
|
1736 |
if($wpCompat) { |
|
1737 |
//WP < 2.1: posts have post_status = published, pages have post_status = static |
|
1738 |
$where.=" post_status='static' "; |
|
1739 |
} else { |
|
1740 |
//WP >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published. |
|
1741 |
$where.=" (post_status = 'publish' AND post_type = 'page') "; |
|
1742 |
} |
|
1743 |
} |
|
1744 |
||
1745 |
$where.=") "; |
|
1746 |
||
1747 |
||
1748 |
if(is_array($excludes) && count($excludes)>0) { |
|
1749 |
$where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')"; |
|
1750 |
} |
|
1751 |
||
1752 |
$where.=" AND post_password='' ORDER BY post_modified DESC"; |
|
1753 |
||
1754 |
$sql .= $where; |
|
1755 |
||
1756 |
if($this->GetOption("b_max_posts")>0) { |
|
1757 |
$sql.=" LIMIT 0," . $this->GetOption("b_max_posts"); |
|
1758 |
} |
|
1759 |
||
1760 |
$postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0)); |
|
1761 |
||
1762 |
//Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the WP connection |
|
1763 |
//Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :( |
|
1764 |
$con = $postRes = null; |
|
1765 |
||
1766 |
//In 2.2, a bug which prevented additional DB connections was fixed |
|
1767 |
if(floatval($wp_version) < 2.2) { |
|
1768 |
$this->SetOption("b_safemode",true); |
|
1769 |
} |
|
1770 |
||
1771 |
if($this->GetOption("b_safemode")===true) { |
|
1772 |
$postRes = mysql_query($sql,$wpdb->dbh); |
|
1773 |
if(!$postRes) { |
|
1774 |
trigger_error("MySQL query failed: " . mysql_error(),E_USER_NOTICE); //E_USER_NOTICE will be displayed on our debug mode |
|
1775 |
return; |
|
1776 |
} |
|
1777 |
} else { |
|
1778 |
$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true); |
|
1779 |
if(!$con) { |
|
1780 |
trigger_error("MySQL Connection failed: " . mysql_error(),E_USER_NOTICE); |
|
1781 |
return; |
|
1782 |
} |
|
1783 |
if(!mysql_select_db(DB_NAME,$con)) { |
|
1784 |
trigger_error("MySQL DB Select failed: " . mysql_error(),E_USER_NOTICE); |
|
1785 |
return; |
|
1786 |
} |
|
1787 |
$postRes = mysql_unbuffered_query($sql,$con); |
|
1788 |
||
1789 |
if(!$postRes) { |
|
1790 |
trigger_error("MySQL unbuffered query failed: " . mysql_error(),E_USER_NOTICE); |
|
1791 |
return; |
|
1792 |
} |
|
1793 |
} |
|
1794 |
||
1795 |
if($postRes) { |
|
1796 |
||
1797 |
//#type $prioProvider GoogleSitemapGeneratorPrioProviderBase |
|
1798 |
$prioProvider=NULL; |
|
1799 |
||
1800 |
if($this->GetOption("b_prio_provider") != '') { |
|
1801 |
$providerClass=$this->GetOption('b_prio_provider'); |
|
1802 |
$prioProvider = new $providerClass($commentCount,$postCount); |
|
1803 |
} |
|
1804 |
||
1805 |
//$posts is used by Alex King's Popularity Contest plugin |
|
1806 |
//if($posts == null || !is_array($posts)) { |
|
1807 |
// $posts = &$postRes; |
|
1808 |
//} |
|
1809 |
||
1810 |
$z = 1; |
|
1811 |
$zz = 1; |
|
1812 |
||
1813 |
//Default priorities |
|
1814 |
$default_prio_posts = $this->GetOption('pr_posts'); |
|
1815 |
$default_prio_pages = $this->GetOption('pr_pages'); |
|
1816 |
||
1817 |
//Change frequencies |
|
1818 |
$cf_pages = $this->GetOption('cf_pages'); |
|
1819 |
$cf_posts = $this->GetOption('cf_posts'); |
|
1820 |
||
1821 |
$minPrio=$this->GetOption('pr_posts_min'); |
|
1822 |
||
1823 |
||
1824 |
//Cycle through all posts and add them |
|
1825 |
while($post = mysql_fetch_object($postRes)) { |
|
1826 |
||
1827 |
//Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later. |
|
1828 |
$cache = array(&$post); |
|
1829 |
update_post_cache($cache); |
|
1830 |
||
1831 |
//Set the current working post for other plugins which depend on "the loop" |
|
1832 |
$GLOBALS['post'] = &$post; |
|
1833 |
||
1834 |
$permalink = get_permalink($post->ID); |
|
1835 |
if($permalink != $home && $post->ID != $homePid) { |
|
1836 |
||
1837 |
$isPage = false; |
|
1838 |
if($wpCompat) { |
|
1839 |
$isPage = ($post->post_status == 'static'); |
|
1840 |
} else { |
|
1841 |
$isPage = ($post->post_type == 'page'); |
|
1842 |
} |
|
1843 |
||
1844 |
||
1845 |
//Default Priority if auto calc is disabled |
|
1846 |
$prio = 0; |
|
1847 |
||
1848 |
if($isPage) { |
|
1849 |
//Priority for static pages |
|
1850 |
$prio = $default_prio_pages; |
|
1851 |
} else { |
|
1852 |
//Priority for normal posts |
|
1853 |
$prio = $default_prio_posts; |
|
1854 |
} |
|
1855 |
||
1856 |
//If priority calc. is enabled, calculate (but only for posts, not pages)! |
|
1857 |
if($prioProvider !== null && !$isPage) { |
|
1858 |
||
1859 |
//Comment count for this post |
|
1860 |
$cmtcnt = (isset($comments[$post->ID])?$comments[$post->ID]:0); |
|
1861 |
$prio = $prioProvider->GetPostPriority($post->ID, $cmtcnt, $post); |
|
1862 |
||
1863 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points')); |
|
1864 |
} |
|
1865 |
||
1866 |
if(!$isPage && $minPrio>0 && $prio<$minPrio) { |
|
1867 |
$prio = $minPrio; |
|
1868 |
} |
|
1869 |
||
1870 |
//Add it |
|
1871 |
$this->AddUrl($permalink,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); |
|
1872 |
||
1873 |
if($inSubPages) { |
|
1874 |
$subPage = ''; |
|
1875 |
for($p = 1; $p <= $post->postPages; $p++) { |
|
1876 |
if(get_option('permalink_structure') == '') { |
|
1877 |
$subPage = $permalink . '&page=' . ($p+1); |
|
1878 |
} else { |
|
1879 |
$subPage = trailingslashit($permalink) . user_trailingslashit($p+1, 'single_paged'); |
|
1880 |
} |
|
1881 |
||
1882 |
$this->AddUrl($subPage,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); |
|
1883 |
} |
|
1884 |
} |
|
1885 |
||
1886 |
// Multilingual Support with qTranslate, thanks to Qian Qin |
|
1887 |
if($useQTransLate) { |
|
1888 |
global $q_config; |
|
1889 |
foreach(qtrans_getEnabledLanguages($post->post_content) as $language) { |
|
1890 |
if($language!=$q_config['default_language']) { |
|
1891 |
$this->AddUrl(qtrans_convertURL($permalink,$language),$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); |
|
1892 |
} |
|
1893 |
} |
|
1894 |
} |
|
1895 |
} |
|
1896 |
||
1897 |
//Update the status every 100 posts and at the end. |
|
1898 |
//If the script breaks because of memory or time limit, |
|
1899 |
//we have a "last reponded" value which can be compared to the server settings |
|
1900 |
if($zz==100 || $z == $postCount) { |
|
1901 |
$status->SaveStep($z); |
|
1902 |
$zz=0; |
|
1903 |
} else $zz++; |
|
1904 |
||
1905 |
$z++; |
|
1906 |
||
1907 |
//Clean cache because it's incomplete |
|
1908 |
if(version_compare($wp_version,"2.5",">=")) { |
|
1909 |
//WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache |
|
1910 |
//so I've copied the function here until a patch arrives... |
|
1911 |
wp_cache_delete($post->ID, 'posts'); |
|
1912 |
wp_cache_delete($post->ID, 'post_meta'); |
|
1913 |
clean_object_term_cache($post->ID, 'post'); |
|
1914 |
} else { |
|
1915 |
clean_post_cache($post->ID); |
|
1916 |
} |
|
1917 |
} |
|
1918 |
unset($postRes); |
|
1919 |
unset($prioProvider); |
|
1920 |
||
1921 |
if($this->GetOption("b_safemode")!==true && $con) mysql_close($con); |
|
1922 |
} |
|
1923 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Postings")); |
|
1924 |
} |
|
1925 |
||
1926 |
//Add the cats |
|
1927 |
if($this->GetOption("in_cats")) { |
|
1928 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Cats")); |
|
1929 |
||
1930 |
$exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats |
|
1931 |
if($exclCats == null) $exclCats=array(); |
|
1932 |
||
1933 |
if(!$this->IsTaxonomySupported()) { |
|
1934 |
||
1935 |
$catsRes=$wpdb->get_results(" |
|
1936 |
SELECT |
|
1937 |
c.cat_ID AS ID, |
|
1938 |
MAX(p.post_modified_gmt) AS last_mod |
|
1939 |
FROM |
|
1940 |
`" . $wpdb->categories . "` c, |
|
1941 |
`" . $wpdb->post2cat . "` pc, |
|
1942 |
`" . $wpdb->posts . "` p |
|
1943 |
WHERE |
|
1944 |
pc.category_id = c.cat_ID |
|
1945 |
AND p.ID = pc.post_id |
|
1946 |
AND p.post_status = 'publish' |
|
1947 |
AND p.post_type='post' |
|
1948 |
GROUP |
|
1949 |
BY c.cat_id |
|
1950 |
"); |
|
1951 |
if($catsRes) { |
|
1952 |
foreach($catsRes as $cat) { |
|
1953 |
if($cat && $cat->ID && $cat->ID>0 && !in_array($cat->ID, $exclCats)) { |
|
1954 |
if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Cat-ID:" . $cat->ID)); |
|
1955 |
$this->AddUrl(get_category_link($cat->ID),$this->GetTimestampFromMySql($cat->last_mod),$this->GetOption("cf_cats"),$this->GetOption("pr_cats")); |
|
1956 |
} |
|
1957 |
} |
|
1958 |
} |
|
1959 |
} else { |
|
1960 |
$cats = get_terms("category",array("hide_empty"=>true,"hierarchical"=>false)); |
|
1961 |
if($cats && is_array($cats) && count($cats)>0) { |
|
1962 |
foreach($cats AS $cat) { |
|
1963 |
if(!in_array($cat->term_id, $exclCats)) $this->AddUrl(get_category_link($cat->term_id),0,$this->GetOption("cf_cats"),$this->GetOption("pr_cats")); |
|
1964 |
} |
|
1965 |
} |
|
1966 |
} |
|
1967 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats")); |
|
1968 |
} |
|
1969 |
||
1970 |
//Add the archives |
|
1971 |
if($this->GetOption("in_arch")) { |
|
1972 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Archive")); |
|
1973 |
$now = current_time('mysql'); |
|
1974 |
||
1975 |
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt |
|
1976 |
$arcresults = $wpdb->get_results(" |
|
1977 |
SELECT DISTINCT |
|
1978 |
YEAR(post_date_gmt) AS `year`, |
|
1979 |
MONTH(post_date_gmt) AS `month`, |
|
1980 |
MAX(post_date_gmt) as last_mod, |
|
1981 |
count(ID) as posts |
|
1982 |
FROM |
|
1983 |
$wpdb->posts |
|
1984 |
WHERE |
|
1985 |
post_date < '$now' |
|
1986 |
AND post_status = 'publish' |
|
1987 |
AND post_type = 'post' |
|
1988 |
" . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . " |
|
1989 |
GROUP BY |
|
1990 |
YEAR(post_date_gmt), |
|
1991 |
MONTH(post_date_gmt) |
|
1992 |
ORDER BY |
|
1993 |
post_date_gmt DESC"); |
|
1994 |
if ($arcresults) { |
|
1995 |
foreach ($arcresults as $arcresult) { |
|
1996 |
||
1997 |
$url = get_month_link($arcresult->year, $arcresult->month); |
|
1998 |
$changeFreq=""; |
|
1999 |
||
2000 |
//Archive is the current one |
|
2001 |
if($arcresult->month==date("n") && $arcresult->year==date("Y")) { |
|
2002 |
$changeFreq=$this->GetOption("cf_arch_curr"); |
|
2003 |
} else { // Archive is older |
|
2004 |
$changeFreq=$this->GetOption("cf_arch_old"); |
|
2005 |
} |
|
2006 |
||
2007 |
$this->AddUrl($url,$this->GetTimestampFromMySql($arcresult->last_mod),$changeFreq,$this->GetOption("pr_arch")); |
|
2008 |
} |
|
2009 |
} |
|
2010 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive")); |
|
2011 |
} |
|
2012 |
||
2013 |
//Add the author pages |
|
2014 |
if($this->GetOption("in_auth")) { |
|
2015 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Author pages")); |
|
2016 |
||
2017 |
$linkFunc = null; |
|
2018 |
||
2019 |
//get_author_link is deprecated in WP 2.1, try to use get_author_posts_url first. |
|
2020 |
if(function_exists('get_author_posts_url')) { |
|
2021 |
$linkFunc = 'get_author_posts_url'; |
|
2022 |
} else if(function_exists('get_author_link')) { |
|
2023 |
$linkFunc = 'get_author_link'; |
|
2024 |
} |
|
2025 |
||
2026 |
//Who knows what happens in later WP versions, so check again if it worked |
|
2027 |
if($linkFunc !== null) { |
|
2028 |
//Unfortunately there is no API function to get all authors, so we have to do it the dirty way... |
|
2029 |
//We retrieve only users with published and not password protected posts (and not pages) |
|
2030 |
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt |
|
2031 |
$sql = "SELECT DISTINCT |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2032 |
u.ID, |
136 | 2033 |
u.user_nicename, |
2034 |
MAX(p.post_modified_gmt) AS last_post |
|
2035 |
FROM |
|
2036 |
{$wpdb->users} u, |
|
2037 |
{$wpdb->posts} p |
|
2038 |
WHERE |
|
2039 |
p.post_author = u.ID |
|
2040 |
AND p.post_status = 'publish' |
|
2041 |
AND p.post_type = 'post' |
|
2042 |
AND p.post_password = '' |
|
2043 |
" . (floatval($wp_version) < 2.1?"AND p.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . " |
|
2044 |
GROUP BY |
|
2045 |
u.ID, |
|
2046 |
u.user_nicename"; |
|
2047 |
||
2048 |
$authors = $wpdb->get_results($sql); |
|
2049 |
||
2050 |
if($authors && is_array($authors)) { |
|
2051 |
foreach($authors as $author) { |
|
2052 |
if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID)); |
|
2053 |
$url = ($linkFunc=='get_author_posts_url'?get_author_posts_url($author->ID,$author->user_nicename):get_author_link(false,$author->ID,$author->user_nicename)); |
|
2054 |
$this->AddUrl($url,$this->GetTimestampFromMySql($author->last_post),$this->GetOption("cf_auth"),$this->GetOption("pr_auth")); |
|
2055 |
} |
|
2056 |
} |
|
2057 |
} else { |
|
2058 |
//Too bad, no author pages for you :( |
|
2059 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found")); |
|
2060 |
} |
|
2061 |
||
2062 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages")); |
|
2063 |
} |
|
2064 |
||
2065 |
//Add tag pages |
|
2066 |
if($this->GetOption("in_tags") && $this->IsTaxonomySupported()) { |
|
2067 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Tags")); |
|
2068 |
$tags = get_terms("post_tag",array("hide_empty"=>true,"hierarchical"=>false)); |
|
2069 |
if($tags && is_array($tags) && count($tags)>0) { |
|
2070 |
foreach($tags AS $tag) { |
|
2071 |
$this->AddUrl(get_tag_link($tag->term_id),0,$this->GetOption("cf_tags"),$this->GetOption("pr_tags")); |
|
2072 |
} |
|
2073 |
} |
|
2074 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags")); |
|
2075 |
} |
|
2076 |
||
2077 |
//Add custom taxonomy pages |
|
2078 |
if($this->GetOption("in_tax") && $this->IsTaxonomySupported()) { |
|
2079 |
||
2080 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start custom taxonomies")); |
|
2081 |
||
2082 |
$enabledTaxonomies = $this->GetOption("in_tax"); |
|
2083 |
||
2084 |
$taxList = array(); |
|
2085 |
||
2086 |
foreach ($enabledTaxonomies as $taxName) { |
|
2087 |
$taxonomy = get_taxonomy($taxName); |
|
2088 |
if($taxonomy) $taxList[] = $wpdb->escape($taxonomy->name); |
|
2089 |
} |
|
2090 |
||
2091 |
if(count($taxList)>0) { |
|
2092 |
//We're selecting all term information (t.*) plus some additional fields |
|
2093 |
//like the last mod date and the taxonomy name, so WP doesnt need to make |
|
2094 |
//additional queries to build the permalink structure. |
|
2095 |
//This does NOT work for categories and tags yet, because WP uses get_category_link |
|
2096 |
//and get_tag_link internally and that would cause one additional query per term! |
|
2097 |
$sql=" |
|
2098 |
SELECT |
|
2099 |
t.*, |
|
2100 |
tt.taxonomy AS _taxonomy, |
|
2101 |
UNIX_TIMESTAMP(MAX(post_date_gmt)) as _mod_date |
|
2102 |
FROM |
|
2103 |
{$wpdb->posts} p , |
|
2104 |
{$wpdb->term_relationships} r, |
|
2105 |
{$wpdb->terms} t, |
|
2106 |
{$wpdb->term_taxonomy} tt |
|
2107 |
WHERE |
|
2108 |
p.ID = r.object_id |
|
2109 |
AND p.post_status = 'publish' |
|
2110 |
AND p.post_type = 'post' |
|
2111 |
AND p.post_password = '' |
|
2112 |
AND r.term_taxonomy_id = t.term_id |
|
2113 |
AND t.term_id = tt.term_id |
|
2114 |
AND tt.count > 0 |
|
2115 |
AND tt.taxonomy IN ('" . implode("','",$taxList) . "') |
|
2116 |
GROUP BY |
|
2117 |
t.term_id"; |
|
2118 |
||
2119 |
$termInfo = $wpdb->get_results($sql); |
|
2120 |
||
2121 |
foreach($termInfo AS $term) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2122 |
$this->AddUrl(get_term_link($term->slug,$term->_taxonomy),$term->_mod_date ,$this->GetOption("cf_tags"),$this->GetOption("pr_tags")); |
136 | 2123 |
} |
2124 |
} |
|
2125 |
||
2126 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End custom taxonomies")); |
|
2127 |
} |
|
2128 |
||
2129 |
//Add the custom pages |
|
2130 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Custom Pages")); |
|
2131 |
if($this->_pages && is_array($this->_pages) && count($this->_pages)>0) { |
|
2132 |
//#type $page GoogleSitemapGeneratorPage |
|
2133 |
foreach($this->_pages AS $page) { |
|
2134 |
$this->AddUrl($page->GetUrl(),$page->getLastMod(),$page->getChangeFreq(),$page->getPriority()); |
|
2135 |
} |
|
2136 |
} |
|
2137 |
||
2138 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages")); |
|
2139 |
||
2140 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start additional URLs")); |
|
2141 |
||
2142 |
do_action('sm_buildmap'); |
|
2143 |
||
2144 |
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End additional URLs")); |
|
2145 |
||
2146 |
$this->AddElement(new GoogleSitemapGeneratorXmlEntry("</urlset>")); |
|
2147 |
||
2148 |
||
2149 |
$pingUrl=''; |
|
2150 |
||
2151 |
if($this->GetOption("b_xml")) { |
|
2152 |
if($this->_fileHandle && fclose($this->_fileHandle)) { |
|
2153 |
$this->_fileHandle = null; |
|
2154 |
$status->EndXml(true); |
|
2155 |
$pingUrl=$this->GetXmlUrl(); |
|
2156 |
} else $status->EndXml(false,"Could not close the sitemap file."); |
|
2157 |
} |
|
2158 |
||
2159 |
if($this->IsGzipEnabled()) { |
|
2160 |
if($this->_fileZipHandle && fclose($this->_fileZipHandle)) { |
|
2161 |
$this->_fileZipHandle = null; |
|
2162 |
$status->EndZip(true); |
|
2163 |
$pingUrl=$this->GetZipUrl(); |
|
2164 |
} else $status->EndZip(false,"Could not close the zipped sitemap file"); |
|
2165 |
} |
|
2166 |
||
2167 |
//Ping Google |
|
2168 |
if($this->GetOption("b_ping") && !empty($pingUrl)) { |
|
2169 |
$sPingUrl="http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); |
|
2170 |
$status->StartGooglePing($sPingUrl); |
|
2171 |
$pingres=$this->RemoteOpen($sPingUrl); |
|
2172 |
||
2173 |
if($pingres==NULL || $pingres===false) { |
|
2174 |
$status->EndGooglePing(false,$this->_lastError); |
|
2175 |
trigger_error("Failed to ping Google: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE); |
|
2176 |
} else { |
|
2177 |
$status->EndGooglePing(true); |
|
2178 |
} |
|
2179 |
} |
|
2180 |
||
2181 |
||
2182 |
//Ping Bing |
|
2183 |
if($this->GetOption("b_pingmsn") && !empty($pingUrl)) { |
|
2184 |
$sPingUrl="http://www.bing.com/webmaster/ping.aspx?siteMap=" . urlencode($pingUrl); |
|
2185 |
$status->StartMsnPing($sPingUrl); |
|
2186 |
$pingres=$this->RemoteOpen($sPingUrl); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2187 |
//Bing returns ip/country-based success messages, so there is no way to check the content. Rely on HTTP 500 only then... |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2188 |
if($pingres==NULL || $pingres===false || strpos($pingres," ")===false) { |
136 | 2189 |
trigger_error("Failed to ping Bing: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE); |
2190 |
$status->EndMsnPing(false,$this->_lastError); |
|
2191 |
} else { |
|
2192 |
$status->EndMsnPing(true); |
|
2193 |
} |
|
2194 |
} |
|
2195 |
||
2196 |
$status->End(); |
|
2197 |
||
2198 |
||
2199 |
$this->_isActive = false; |
|
2200 |
||
2201 |
//done... |
|
2202 |
return $status; |
|
2203 |
} |
|
2204 |
||
2205 |
/** |
|
2206 |
* Tries to ping a specific service showing as much as debug output as possible |
|
2207 |
* @since 3.1.9 |
|
2208 |
* @return null |
|
2209 |
*/ |
|
2210 |
function ShowPingResult() { |
|
2211 |
||
2212 |
check_admin_referer('sitemap'); |
|
2213 |
||
2214 |
if(!current_user_can("administrator")) { |
|
2215 |
echo '<p>Please log in as admin</p>'; |
|
2216 |
return; |
|
2217 |
} |
|
2218 |
||
2219 |
$service = !empty($_GET["sm_ping_service"])?$_GET["sm_ping_service"]:null; |
|
2220 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2221 |
$status = &GoogleSitemapGeneratorStatus::Load(); |
136 | 2222 |
|
2223 |
if(!$status) die("No build status yet. Build the sitemap first."); |
|
2224 |
||
2225 |
$url = null; |
|
2226 |
||
2227 |
switch($service) { |
|
2228 |
case "google": |
|
2229 |
$url = $status->_googleUrl; |
|
2230 |
break; |
|
2231 |
case "msn": |
|
2232 |
$url = $status->_msnUrl; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2233 |
break; |
136 | 2234 |
} |
2235 |
||
2236 |
if(empty($url)) die("Invalid ping url"); |
|
2237 |
||
2238 |
echo '<html><head><title>Ping Test</title>'; |
|
2239 |
if(function_exists('wp_admin_css')) wp_admin_css('css/global',true); |
|
2240 |
echo '</head><body><h1>Ping Test</h1>'; |
|
2241 |
||
2242 |
echo '<p>Trying to ping: <a href="' . $url . '">' . $url . '</a>. The sections below should give you an idea whats going on.</p>'; |
|
2243 |
||
2244 |
//Try to get as much as debug / error output as possible |
|
2245 |
$errLevel = error_reporting(E_ALL); |
|
2246 |
$errDisplay = ini_set("display_errors",1); |
|
2247 |
if(!defined('WP_DEBUG')) define('WP_DEBUG',true); |
|
2248 |
||
2249 |
echo '<h2>Errors, Warnings, Notices:</h2>'; |
|
2250 |
||
2251 |
if(WP_DEBUG == false) echo "<i>WP_DEBUG was set to false somewhere before. You might not see all debug information until you remove this declaration!</i><br />"; |
|
2252 |
if(ini_get("display_errors")!=1) echo "<i>Your display_errors setting currently prevents the plugin from showing errors here. Please check your webserver logfile instead.</i><br />"; |
|
2253 |
||
2254 |
$res = $this->RemoteOpen($url); |
|
2255 |
||
2256 |
echo '<h2>Result (text only):</h2>'; |
|
2257 |
||
2258 |
echo wp_kses($res,array('a' => array('href' => array()),'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array())); |
|
2259 |
||
2260 |
echo '<h2>Result (HTML):</h2>'; |
|
2261 |
||
2262 |
echo htmlspecialchars($res); |
|
2263 |
||
2264 |
//Revert back old values |
|
2265 |
error_reporting($errLevel); |
|
2266 |
ini_set("display_errors",$errDisplay); |
|
2267 |
echo '</body></html>'; |
|
2268 |
exit; |
|
2269 |
} |
|
2270 |
||
2271 |
/** |
|
2272 |
* Opens a remote file using the WordPress API or Snoopy |
|
2273 |
* @since 3.0 |
|
2274 |
* @param $url The URL to open |
|
2275 |
* @param $method get or post |
|
2276 |
* @param $postData An array with key=>value paris |
|
2277 |
* @param $timeout Timeout for the request, by default 10 |
|
2278 |
* @return mixed False on error, the body of the response on success |
|
2279 |
*/ |
|
2280 |
function RemoteOpen($url,$method = 'get', $postData = null, $timeout = 10) { |
|
2281 |
global $wp_version; |
|
2282 |
||
2283 |
//Before WP 2.7, wp_remote_fopen was quite crappy so Snoopy was favoured. |
|
2284 |
if(floatval($wp_version) < 2.7) { |
|
2285 |
if(!file_exists(ABSPATH . 'wp-includes/class-snoopy.php')) { |
|
2286 |
trigger_error('Snoopy Web Request failed: Snoopy not found.',E_USER_NOTICE); |
|
2287 |
return false; //Hoah? |
|
2288 |
} |
|
2289 |
||
2290 |
require_once( ABSPATH . 'wp-includes/class-snoopy.php'); |
|
2291 |
||
2292 |
$s = new Snoopy(); |
|
2293 |
||
2294 |
$s->read_timeout = $timeout; |
|
2295 |
||
2296 |
if($method == 'get') { |
|
2297 |
$s->fetch($url); |
|
2298 |
} else { |
|
2299 |
$s->submit($url,$postData); |
|
2300 |
} |
|
2301 |
||
2302 |
if($s->status != "200") { |
|
2303 |
trigger_error('Snoopy Web Request failed: Status: ' . $s->status . "; Content: " . htmlspecialchars($s->results),E_USER_NOTICE); |
|
2304 |
} |
|
2305 |
||
2306 |
return $s->results; |
|
2307 |
||
2308 |
} else { |
|
2309 |
||
2310 |
$options = array(); |
|
2311 |
$options['timeout'] = $timeout; |
|
2312 |
||
2313 |
if($method == 'get') { |
|
2314 |
$response = wp_remote_get( $url, $options ); |
|
2315 |
} else { |
|
2316 |
$response = wp_remote_post($url, array_merge($options,array('body'=>$postData))); |
|
2317 |
} |
|
2318 |
||
2319 |
if ( is_wp_error( $response ) ) { |
|
2320 |
$errs = $response->get_error_messages(); |
|
2321 |
$errs = htmlspecialchars(implode('; ', $errs)); |
|
2322 |
trigger_error('WP HTTP API Web Request failed: ' . $errs,E_USER_NOTICE); |
|
2323 |
return false; |
|
2324 |
} |
|
2325 |
||
2326 |
return $response['body']; |
|
2327 |
} |
|
2328 |
||
2329 |
return false; |
|
2330 |
} |
|
2331 |
||
2332 |
/** |
|
2333 |
* Echos option fields for an select field containing the valid change frequencies |
|
2334 |
* |
|
2335 |
* @since 3.0 |
|
2336 |
* @access private |
|
2337 |
* @author Arne Brachhold |
|
2338 |
* @param $currentVal The value which should be selected |
|
2339 |
* @return all valid change frequencies as html option fields |
|
2340 |
*/ |
|
2341 |
function HtmlGetFreqNames($currentVal) { |
|
2342 |
||
2343 |
foreach($this->_freqNames AS $k=>$v) { |
|
2344 |
echo "<option value=\"$k\" " . $this->HtmlGetSelected($k,$currentVal) .">" . $v . "</option>"; |
|
2345 |
} |
|
2346 |
} |
|
2347 |
||
2348 |
/** |
|
2349 |
* Echos option fields for an select field containing the valid priorities (0- 1.0) |
|
2350 |
* |
|
2351 |
* @since 3.0 |
|
2352 |
* @access private |
|
2353 |
* @author Arne Brachhold |
|
2354 |
* @param $currentVal string The value which should be selected |
|
2355 |
* @return 0.0 - 1.0 as html option fields |
|
2356 |
*/ |
|
2357 |
function HtmlGetPriorityValues($currentVal) { |
|
2358 |
$currentVal=(float) $currentVal; |
|
2359 |
for($i=0.0; $i<=1.0; $i+=0.1) { |
|
2360 |
$v = number_format($i,1,".",""); |
|
2361 |
//number_format_i18n is there since WP 2.3 |
|
2362 |
$t = function_exists('number_format_i18n')?number_format_i18n($i,1):number_format($i,1); |
|
2363 |
echo "<option value=\"" . $v . "\" " . $this->HtmlGetSelected("$i","$currentVal") .">"; |
|
2364 |
echo $t; |
|
2365 |
echo "</option>"; |
|
2366 |
} |
|
2367 |
} |
|
2368 |
||
2369 |
/** |
|
2370 |
* Returns the checked attribute if the given values match |
|
2371 |
* |
|
2372 |
* @since 3.0 |
|
2373 |
* @access private |
|
2374 |
* @author Arne Brachhold |
|
2375 |
* @param $val string The current value |
|
2376 |
* @param $equals string The value to match |
|
2377 |
* @return The checked attribute if the given values match, an empty string if not |
|
2378 |
*/ |
|
2379 |
function HtmlGetChecked($val,$equals) { |
|
2380 |
if($val==$equals) return $this->HtmlGetAttribute("checked"); |
|
2381 |
else return ""; |
|
2382 |
} |
|
2383 |
||
2384 |
/** |
|
2385 |
* Returns the selected attribute if the given values match |
|
2386 |
* |
|
2387 |
* @since 3.0 |
|
2388 |
* @access private |
|
2389 |
* @author Arne Brachhold |
|
2390 |
* @param $val string The current value |
|
2391 |
* @param $equals string The value to match |
|
2392 |
* @return The selected attribute if the given values match, an empty string if not |
|
2393 |
*/ |
|
2394 |
function HtmlGetSelected($val,$equals) { |
|
2395 |
if($val==$equals) return $this->HtmlGetAttribute("selected"); |
|
2396 |
else return ""; |
|
2397 |
} |
|
2398 |
||
2399 |
/** |
|
2400 |
* Returns an formatted attribute. If the value is NULL, the name will be used. |
|
2401 |
* |
|
2402 |
* @since 3.0 |
|
2403 |
* @access private |
|
2404 |
* @author Arne Brachhold |
|
2405 |
* @param $attr string The attribute name |
|
2406 |
* @param $value string The attribute value |
|
2407 |
* @return The formatted attribute |
|
2408 |
*/ |
|
2409 |
function HtmlGetAttribute($attr,$value=NULL) { |
|
2410 |
if($value==NULL) $value=$attr; |
|
2411 |
return " " . $attr . "=\"" . $value . "\" "; |
|
2412 |
} |
|
2413 |
||
2414 |
/** |
|
2415 |
* Returns an array with GoogleSitemapGeneratorPage objects which is generated from POST values |
|
2416 |
* |
|
2417 |
* @since 3.0 |
|
2418 |
* @see GoogleSitemapGeneratorPage |
|
2419 |
* @access private |
|
2420 |
* @author Arne Brachhold |
|
2421 |
* @return array An array with GoogleSitemapGeneratorPage objects |
|
2422 |
*/ |
|
2423 |
function HtmlApplyPages() { |
|
2424 |
// Array with all page URLs |
|
2425 |
$pages_ur=(!isset($_POST["sm_pages_ur"]) || !is_array($_POST["sm_pages_ur"])?array():$_POST["sm_pages_ur"]); |
|
2426 |
||
2427 |
//Array with all priorities |
|
2428 |
$pages_pr=(!isset($_POST["sm_pages_pr"]) || !is_array($_POST["sm_pages_pr"])?array():$_POST["sm_pages_pr"]); |
|
2429 |
||
2430 |
//Array with all change frequencies |
|
2431 |
$pages_cf=(!isset($_POST["sm_pages_cf"]) || !is_array($_POST["sm_pages_cf"])?array():$_POST["sm_pages_cf"]); |
|
2432 |
||
2433 |
//Array with all lastmods |
|
2434 |
$pages_lm=(!isset($_POST["sm_pages_lm"]) || !is_array($_POST["sm_pages_lm"])?array():$_POST["sm_pages_lm"]); |
|
2435 |
||
2436 |
//Array where the new pages are stored |
|
2437 |
$pages=array(); |
|
2438 |
//Loop through all defined pages and set their properties into an object |
|
2439 |
if(isset($_POST["sm_pages_mark"]) && is_array($_POST["sm_pages_mark"])) { |
|
2440 |
for($i=0; $i<count($_POST["sm_pages_mark"]); $i++) { |
|
2441 |
//Create new object |
|
2442 |
$p=new GoogleSitemapGeneratorPage(); |
|
2443 |
if(substr($pages_ur[$i],0,4)=="www.") $pages_ur[$i]="http://" . $pages_ur[$i]; |
|
2444 |
$p->SetUrl($pages_ur[$i]); |
|
2445 |
$p->SetProprity($pages_pr[$i]); |
|
2446 |
$p->SetChangeFreq($pages_cf[$i]); |
|
2447 |
//Try to parse last modified, if -1 (note ===) automatic will be used (0) |
|
2448 |
$lm=(!empty($pages_lm[$i])?strtotime($pages_lm[$i],time()):-1); |
|
2449 |
if($lm===-1) $p->setLastMod(0); |
|
2450 |
else $p->setLastMod($lm); |
|
2451 |
//Add it to the array |
|
2452 |
array_push($pages,$p); |
|
2453 |
} |
|
2454 |
} |
|
2455 |
||
2456 |
return $pages; |
|
2457 |
} |
|
2458 |
||
2459 |
/** |
|
2460 |
* Converts a mysql datetime value into a unix timestamp |
|
2461 |
* |
|
2462 |
* @param The value in the mysql datetime format |
|
2463 |
* @return int The time in seconds |
|
2464 |
*/ |
|
2465 |
function GetTimestampFromMySql($mysqlDateTime) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2466 |
list($date, $hours) = explode(' ', $mysqlDateTime); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2467 |
list($year,$month,$day) = explode('-',$date); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2468 |
list($hour,$min,$sec) = explode(':',$hours); |
136 | 2469 |
return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year)); |
2470 |
} |
|
2471 |
||
2472 |
/** |
|
2473 |
* Returns a link pointing to a spcific page of the authors website |
|
2474 |
* |
|
2475 |
* @since 3.0 |
|
2476 |
* @param The page to link to |
|
2477 |
* @return string The full url |
|
2478 |
*/ |
|
2479 |
function GetRedirectLink($redir) { |
|
2480 |
return trailingslashit("http://www.arnebrachhold.de/redir/" . $redir); |
|
2481 |
} |
|
2482 |
||
2483 |
/** |
|
2484 |
* Returns a link pointing back to the plugin page in WordPress |
|
2485 |
* |
|
2486 |
* @since 3.0 |
|
2487 |
* @return string The full url |
|
2488 |
*/ |
|
2489 |
function GetBackLink() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2490 |
global $wp_version; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2491 |
$url = ''; |
136 | 2492 |
//admin_url was added in WP 2.6.0 |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2493 |
if(function_exists("admin_url")) $url = admin_url("options-general.php?page=" . GoogleSitemapGeneratorLoader::GetBaseName()); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2494 |
else $url = $_SERVER['PHP_SELF'] . "?page=" . GoogleSitemapGeneratorLoader::GetBaseName(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2495 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2496 |
//Some browser cache the page... great! So lets add some no caching params depending on the WP and plugin version |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2497 |
$url.='&sm_wpv=' . $wp_version . '&sm_pv=' . GoogleSitemapGeneratorLoader::GetVersion(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2498 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2499 |
return $url; |
136 | 2500 |
} |
2501 |
||
2502 |
/** |
|
2503 |
* Shows the option page of the plugin. Before 3.1.1, this function was basically the UI, afterwards the UI was outsourced to another class |
|
2504 |
* |
|
2505 |
* @see GoogleSitemapGeneratorUI |
|
2506 |
* @since 3.0 |
|
2507 |
* @return bool |
|
2508 |
*/ |
|
2509 |
function HtmlShowOptionsPage() { |
|
2510 |
||
2511 |
$ui = $this->GetUI(); |
|
2512 |
if($ui) { |
|
2513 |
$ui->HtmlShowOptionsPage(); |
|
2514 |
return true; |
|
2515 |
} |
|
2516 |
||
2517 |
return false; |
|
2518 |
} |
|
2519 |
||
2520 |
/** |
|
2521 |
* Includes the user interface class and intializes it |
|
2522 |
* |
|
2523 |
* @since 3.1.1 |
|
2524 |
* @see GoogleSitemapGeneratorUI |
|
2525 |
* @return GoogleSitemapGeneratorUI |
|
2526 |
*/ |
|
2527 |
function GetUI() { |
|
2528 |
||
2529 |
global $wp_version; |
|
2530 |
||
2531 |
if($this->_ui === null) { |
|
2532 |
||
2533 |
$className='GoogleSitemapGeneratorUI'; |
|
2534 |
$fileName='sitemap-ui.php'; |
|
2535 |
||
2536 |
if(!class_exists($className)) { |
|
2537 |
||
2538 |
$path = trailingslashit(dirname(__FILE__)); |
|
2539 |
||
2540 |
if(!file_exists( $path . $fileName)) return false; |
|
2541 |
require_once($path. $fileName); |
|
2542 |
} |
|
2543 |
||
2544 |
$this->_ui = new $className($this); |
|
2545 |
||
2546 |
} |
|
2547 |
||
2548 |
return $this->_ui; |
|
2549 |
} |
|
2550 |
||
2551 |
function HtmlShowHelp() { |
|
2552 |
||
2553 |
||
2554 |
} |
|
2555 |
} |