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.php 583238 2012-08-08 21:10:26Z arnee $ |
136 | 5 |
|
6 |
Google XML Sitemaps Generator for WordPress |
|
7 |
============================================================================== |
|
8 |
|
|
9 |
This generator will create a sitemaps.org compliant sitemap of your WordPress blog. |
|
10 |
Currently homepage, posts, static pages, categories, archives and author pages are supported. |
|
11 |
|
|
12 |
The priority of a post depends on its comments. You can choose the way the priority |
|
13 |
is calculated in the options screen. |
|
14 |
|
|
15 |
Feel free to visit my website under www.arnebrachhold.de! |
|
16 |
||
17 |
For aditional details like installation instructions, please check the readme.txt and documentation.txt files. |
|
18 |
|
|
19 |
Have fun! |
|
20 |
Arne |
|
21 |
||
22 |
||
23 |
Info for WordPress: |
|
24 |
============================================================================== |
|
25 |
Plugin Name: Google XML Sitemaps |
|
26 |
Plugin URI: http://www.arnebrachhold.de/redir/sitemap-home/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
Description: This plugin will generate a special XML sitemap which will help search engines like Google, Yahoo, Bing and Ask.com to better index your blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
Version: 3.2.8 |
136 | 29 |
Author: Arne Brachhold |
30 |
Author URI: http://www.arnebrachhold.de/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
Text Domain: sitemap |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
32 |
Domain Path: /lang/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
|
136 | 34 |
*/ |
35 |
||
36 |
/** |
|
37 |
* Loader class for the Google Sitemap Generator |
|
38 |
* |
|
39 |
* This class takes care of the sitemap plugin and tries to load the different parts as late as possible. |
|
40 |
* On normal requests, only this small class is loaded. When the sitemap needs to be rebuild, the generator itself is loaded. |
|
41 |
* The last stage is the user interface which is loaded when the administration page is requested. |
|
42 |
*/ |
|
43 |
class GoogleSitemapGeneratorLoader { |
|
44 |
/** |
|
45 |
* Enabled the sitemap plugin with registering all required hooks |
|
46 |
* |
|
47 |
* If the sm_command and sm_key GET params are given, the function will init the generator to rebuild the sitemap. |
|
48 |
*/ |
|
49 |
function Enable() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
50 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
//Check for 3.0 multisite, NOT supported yet! |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
if((defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE) || (function_exists('is_multisite') && is_multisite())) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
if(function_exists('is_super_admin') && is_super_admin()) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
54 |
add_action('admin_notices', array('GoogleSitemapGeneratorLoader', 'AddMultisiteWarning')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
58 |
} |
136 | 59 |
|
60 |
//Register the sitemap creator to wordpress... |
|
61 |
add_action('admin_menu', array('GoogleSitemapGeneratorLoader', 'RegisterAdminPage')); |
|
62 |
||
63 |
//Nice icon for Admin Menu (requires Ozh Admin Drop Down Plugin) |
|
64 |
add_filter('ozh_adminmenu_icon', array('GoogleSitemapGeneratorLoader', 'RegisterAdminIcon')); |
|
65 |
||
66 |
//Additional links on the plugin page |
|
67 |
add_filter('plugin_row_meta', array('GoogleSitemapGeneratorLoader', 'RegisterPluginLinks'),10,2); |
|
68 |
||
69 |
//Existing posts was deleted |
|
70 |
add_action('delete_post', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
71 |
||
72 |
//Existing post was published |
|
73 |
add_action('publish_post', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
74 |
||
75 |
//Existing page was published |
|
76 |
add_action('publish_page', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
77 |
||
78 |
//WP Cron hook |
|
79 |
add_action('sm_build_cron', array('GoogleSitemapGeneratorLoader', 'CallBuildSitemap'),1,0); |
|
80 |
||
81 |
//External build hook |
|
82 |
add_action('sm_rebuild', array('GoogleSitemapGeneratorLoader', 'CallBuildNowRequest'),1,0); |
|
83 |
||
84 |
//Robots.txt request |
|
85 |
add_action('do_robots', array('GoogleSitemapGeneratorLoader', 'CallDoRobots'),100,0); |
|
86 |
||
87 |
//Help topics for context sensitive help |
|
88 |
add_filter('contextual_help_list', array('GoogleSitemapGeneratorLoader', 'CallHtmlShowHelpList'),9999,2); |
|
89 |
||
90 |
//Check if this is a BUILD-NOW request (key will be checked later) |
|
91 |
if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) { |
|
92 |
GoogleSitemapGeneratorLoader::CallCheckForManualBuild(); |
|
93 |
} |
|
94 |
||
95 |
//Check if the result of a ping request should be shown |
|
96 |
if(!empty($_GET["sm_ping_service"])) { |
|
97 |
GoogleSitemapGeneratorLoader::CallShowPingResult(); |
|
98 |
} |
|
99 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
101 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
102 |
* Outputs the warning bar if multisite mode is activated |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
103 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
104 |
function AddMultisiteWarning() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
105 |
echo "<div id='sm-multisite-warning' class='error fade'><p><strong>".__('This version of Google XML Sitemaps is not multisite compatible.','sitemap')."</strong><br /> ".sprintf(__('Unfortunately this version of the Google XML Sitemaps plugin was not tested with the multisite feature of WordPress 3.0 yet. <br />The plugin will not be active until you disable the multisite mode. <br />Or you can <a href="%1$s">try the new beta</a> which supports all the new WordPress features!','sitemap'), "http://www.arnebrachhold.de/redir/sitemap-info-beta/")."</p></div>"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
106 |
} |
136 | 107 |
|
108 |
/** |
|
109 |
* Registers the plugin in the admin menu system |
|
110 |
*/ |
|
111 |
function RegisterAdminPage() { |
|
112 |
||
113 |
if (function_exists('add_options_page')) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
114 |
add_options_page(__('XML-Sitemap Generator','sitemap'), __('XML-Sitemap','sitemap'), 'level_10', GoogleSitemapGeneratorLoader::GetBaseName(), array('GoogleSitemapGeneratorLoader','CallHtmlShowOptionsPage')); |
136 | 115 |
} |
116 |
} |
|
117 |
||
118 |
function RegisterAdminIcon($hook) { |
|
119 |
if ( $hook == GoogleSitemapGeneratorLoader::GetBaseName() && function_exists('plugins_url')) { |
|
120 |
return plugins_url('img/icon-arne.gif',GoogleSitemapGeneratorLoader::GetBaseName()); |
|
121 |
} |
|
122 |
return $hook; |
|
123 |
} |
|
124 |
||
125 |
function RegisterPluginLinks($links, $file) { |
|
126 |
$base = GoogleSitemapGeneratorLoader::GetBaseName(); |
|
127 |
if ($file == $base) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
128 |
$links[] = '<a href="options-general.php?page=' . GoogleSitemapGeneratorLoader::GetBaseName() .'">' . __('Settings','sitemap') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
$links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-faq/">' . __('FAQ','sitemap') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
$links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-support/">' . __('Support','sitemap') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
$links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-donate/">' . __('Donate','sitemap') . '</a>'; |
136 | 132 |
} |
133 |
return $links; |
|
134 |
} |
|
135 |
||
136 |
/** |
|
137 |
* Invokes the HtmlShowOptionsPage method of the generator |
|
138 |
*/ |
|
139 |
function CallHtmlShowOptionsPage() { |
|
140 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
141 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 142 |
$gs->HtmlShowOptionsPage(); |
143 |
} |
|
144 |
} |
|
145 |
||
146 |
/** |
|
147 |
* Invokes the CheckForAutoBuild method of the generator |
|
148 |
*/ |
|
149 |
function CallCheckForAutoBuild($args) { |
|
150 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 152 |
$gs->CheckForAutoBuild($args); |
153 |
} |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Invokes the CheckForAutoBuild method of the generator |
|
158 |
*/ |
|
159 |
function CallBuildNowRequest() { |
|
160 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 162 |
$gs->BuildNowRequest(); |
163 |
} |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Invokes the BuildSitemap method of the generator |
|
168 |
*/ |
|
169 |
function CallBuildSitemap() { |
|
170 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
171 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 172 |
$gs->BuildSitemap(); |
173 |
} |
|
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* Invokes the CheckForManualBuild method of the generator |
|
178 |
*/ |
|
179 |
function CallCheckForManualBuild() { |
|
180 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
181 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 182 |
$gs->CheckForManualBuild(); |
183 |
} |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Invokes the ShowPingResult method of the generator |
|
188 |
*/ |
|
189 |
function CallShowPingResult() { |
|
190 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
191 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 192 |
$gs->ShowPingResult(); |
193 |
} |
|
194 |
} |
|
195 |
||
196 |
||
197 |
function CallHtmlShowHelpList($filterVal,$screen) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
$id = get_plugin_page_hookname(GoogleSitemapGeneratorLoader::GetBaseName(),'options-general.php'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
if($screen == $id) { |
136 | 202 |
$links = array( |
203 |
__('Plugin Homepage','sitemap')=>'http://www.arnebrachhold.de/redir/sitemap-help-home/', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
__('My Sitemaps FAQ','sitemap')=>'http://www.arnebrachhold.de/redir/sitemap-help-faq/' |
136 | 205 |
); |
206 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
$filterVal[$id] = ''; |
136 | 208 |
|
209 |
$i=0; |
|
210 |
foreach($links AS $text=>$url) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
211 |
$filterVal[$id].='<a href="' . $url . '">' . $text . '</a>' . ($i < (count($links)-1)?'<br />':'') ; |
136 | 212 |
$i++; |
213 |
} |
|
214 |
} |
|
215 |
return $filterVal; |
|
216 |
} |
|
217 |
||
218 |
function CallDoRobots() { |
|
219 |
if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
$gs = &GoogleSitemapGenerator::GetInstance(); |
136 | 221 |
$gs->DoRobots(); |
222 |
} |
|
223 |
} |
|
224 |
||
225 |
/** |
|
226 |
* Loads the actual generator class and tries to raise the memory and time limits if not already done by WP |
|
227 |
* |
|
228 |
* @return boolean true if run successfully |
|
229 |
*/ |
|
230 |
function LoadPlugin() { |
|
231 |
||
232 |
$mem = abs(intval(@ini_get('memory_limit'))); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
if($mem && $mem < 64) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
234 |
@ini_set('memory_limit', '64M'); |
136 | 235 |
} |
236 |
||
237 |
$time = abs(intval(@ini_get("max_execution_time"))); |
|
238 |
if($time != 0 && $time < 120) { |
|
239 |
@set_time_limit(120); |
|
240 |
} |
|
241 |
||
242 |
if(!class_exists("GoogleSitemapGenerator")) { |
|
243 |
||
244 |
$path = trailingslashit(dirname(__FILE__)); |
|
245 |
||
246 |
if(!file_exists( $path . 'sitemap-core.php')) return false; |
|
247 |
require_once($path. 'sitemap-core.php'); |
|
248 |
} |
|
249 |
||
250 |
GoogleSitemapGenerator::Enable(); |
|
251 |
return true; |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Returns the plugin basename of the plugin (using __FILE__) |
|
256 |
* |
|
257 |
* @return string The plugin basename, "sitemap" for example |
|
258 |
*/ |
|
259 |
function GetBaseName() { |
|
260 |
return plugin_basename(__FILE__); |
|
261 |
} |
|
262 |
||
263 |
/** |
|
264 |
* Returns the name of this loader script, using __FILE__ |
|
265 |
* |
|
266 |
* @return string The __FILE__ value of this loader script |
|
267 |
*/ |
|
268 |
function GetPluginFile() { |
|
269 |
return __FILE__; |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
* Returns the plugin version |
|
274 |
* |
|
275 |
* Uses the WP API to get the meta data from the top of this file (comment) |
|
276 |
* |
|
277 |
* @return string The version like 3.1.1 |
|
278 |
*/ |
|
279 |
function GetVersion() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
if(!isset($GLOBALS["sm_version"])) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
281 |
if(!function_exists('get_plugin_data')) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); //2.3+ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
283 |
else if(file_exists(ABSPATH . 'wp-admin/admin-functions.php')) require_once(ABSPATH . 'wp-admin/admin-functions.php'); //2.1 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
284 |
else return "0.ERROR"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
285 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
286 |
$data = get_plugin_data(__FILE__, false, false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
287 |
$GLOBALS["sm_version"] = $data['Version']; |
136 | 288 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
289 |
return $GLOBALS["sm_version"]; |
136 | 290 |
} |
291 |
} |
|
292 |
||
293 |
//Enable the plugin for the init hook, but only if WP is loaded. Calling this php file directly will do nothing. |
|
294 |
if(defined('ABSPATH') && defined('WPINC')) { |
|
295 |
add_action("init",array("GoogleSitemapGeneratorLoader","Enable"),1000,0); |
|
296 |
} |
|
297 |
?> |