|
1 <?php |
|
2 |
|
3 /* |
|
4 $Id: sitemap.php 175664 2009-11-20 21:21:09Z arnee $ |
|
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/ |
|
27 Description: This plugin will generate a sitemaps.org compatible sitemap of your WordPress blog which is supported by Ask.com, Google, MSN Search and YAHOO. <a href="options-general.php?page=sitemap.php">Configuration Page</a> |
|
28 Version: 3.2 |
|
29 Author: Arne Brachhold |
|
30 Author URI: http://www.arnebrachhold.de/ |
|
31 */ |
|
32 |
|
33 /** |
|
34 * Loader class for the Google Sitemap Generator |
|
35 * |
|
36 * This class takes care of the sitemap plugin and tries to load the different parts as late as possible. |
|
37 * On normal requests, only this small class is loaded. When the sitemap needs to be rebuild, the generator itself is loaded. |
|
38 * The last stage is the user interface which is loaded when the administration page is requested. |
|
39 */ |
|
40 class GoogleSitemapGeneratorLoader { |
|
41 /** |
|
42 * Enabled the sitemap plugin with registering all required hooks |
|
43 * |
|
44 * If the sm_command and sm_key GET params are given, the function will init the generator to rebuild the sitemap. |
|
45 */ |
|
46 function Enable() { |
|
47 |
|
48 //Register the sitemap creator to wordpress... |
|
49 add_action('admin_menu', array('GoogleSitemapGeneratorLoader', 'RegisterAdminPage')); |
|
50 |
|
51 //Nice icon for Admin Menu (requires Ozh Admin Drop Down Plugin) |
|
52 add_filter('ozh_adminmenu_icon', array('GoogleSitemapGeneratorLoader', 'RegisterAdminIcon')); |
|
53 |
|
54 //Additional links on the plugin page |
|
55 add_filter('plugin_row_meta', array('GoogleSitemapGeneratorLoader', 'RegisterPluginLinks'),10,2); |
|
56 |
|
57 //Existing posts was deleted |
|
58 add_action('delete_post', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
59 |
|
60 //Existing post was published |
|
61 add_action('publish_post', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
62 |
|
63 //Existing page was published |
|
64 add_action('publish_page', array('GoogleSitemapGeneratorLoader', 'CallCheckForAutoBuild'),9999,1); |
|
65 |
|
66 //WP Cron hook |
|
67 add_action('sm_build_cron', array('GoogleSitemapGeneratorLoader', 'CallBuildSitemap'),1,0); |
|
68 |
|
69 //External build hook |
|
70 add_action('sm_rebuild', array('GoogleSitemapGeneratorLoader', 'CallBuildNowRequest'),1,0); |
|
71 |
|
72 //Robots.txt request |
|
73 add_action('do_robots', array('GoogleSitemapGeneratorLoader', 'CallDoRobots'),100,0); |
|
74 |
|
75 //Help topics for context sensitive help |
|
76 add_filter('contextual_help_list', array('GoogleSitemapGeneratorLoader', 'CallHtmlShowHelpList'),9999,2); |
|
77 |
|
78 //Check if this is a BUILD-NOW request (key will be checked later) |
|
79 if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) { |
|
80 GoogleSitemapGeneratorLoader::CallCheckForManualBuild(); |
|
81 } |
|
82 |
|
83 //Check if the result of a ping request should be shown |
|
84 if(!empty($_GET["sm_ping_service"])) { |
|
85 GoogleSitemapGeneratorLoader::CallShowPingResult(); |
|
86 } |
|
87 } |
|
88 |
|
89 /** |
|
90 * Registers the plugin in the admin menu system |
|
91 */ |
|
92 function RegisterAdminPage() { |
|
93 |
|
94 if (function_exists('add_options_page')) { |
|
95 add_options_page(__('XML-Sitemap Generator','sitemap'), __('XML-Sitemap','sitemap'), 10, GoogleSitemapGeneratorLoader::GetBaseName(), array('GoogleSitemapGeneratorLoader','CallHtmlShowOptionsPage')); |
|
96 } |
|
97 } |
|
98 |
|
99 function RegisterAdminIcon($hook) { |
|
100 if ( $hook == GoogleSitemapGeneratorLoader::GetBaseName() && function_exists('plugins_url')) { |
|
101 return plugins_url('img/icon-arne.gif',GoogleSitemapGeneratorLoader::GetBaseName()); |
|
102 } |
|
103 return $hook; |
|
104 } |
|
105 |
|
106 function RegisterPluginLinks($links, $file) { |
|
107 $base = GoogleSitemapGeneratorLoader::GetBaseName(); |
|
108 if ($file == $base) { |
|
109 $links[] = '<a href="options-general.php?page=' . GoogleSitemapGeneratorLoader::GetBaseName() .'">' . __('Settings') . '</a>'; |
|
110 $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-faq/">' . __('FAQ') . '</a>'; |
|
111 $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-support/">' . __('Support') . '</a>'; |
|
112 $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-donate/">' . __('Donate') . '</a>'; |
|
113 } |
|
114 return $links; |
|
115 } |
|
116 |
|
117 /** |
|
118 * Invokes the HtmlShowOptionsPage method of the generator |
|
119 */ |
|
120 function CallHtmlShowOptionsPage() { |
|
121 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
122 $gs = GoogleSitemapGenerator::GetInstance(); |
|
123 $gs->HtmlShowOptionsPage(); |
|
124 } |
|
125 } |
|
126 |
|
127 /** |
|
128 * Invokes the CheckForAutoBuild method of the generator |
|
129 */ |
|
130 function CallCheckForAutoBuild($args) { |
|
131 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
132 $gs = GoogleSitemapGenerator::GetInstance(); |
|
133 $gs->CheckForAutoBuild($args); |
|
134 } |
|
135 } |
|
136 |
|
137 /** |
|
138 * Invokes the CheckForAutoBuild method of the generator |
|
139 */ |
|
140 function CallBuildNowRequest() { |
|
141 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
142 $gs = GoogleSitemapGenerator::GetInstance(); |
|
143 $gs->BuildNowRequest(); |
|
144 } |
|
145 } |
|
146 |
|
147 /** |
|
148 * Invokes the BuildSitemap method of the generator |
|
149 */ |
|
150 function CallBuildSitemap() { |
|
151 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
152 $gs = GoogleSitemapGenerator::GetInstance(); |
|
153 $gs->BuildSitemap(); |
|
154 } |
|
155 } |
|
156 |
|
157 /** |
|
158 * Invokes the CheckForManualBuild method of the generator |
|
159 */ |
|
160 function CallCheckForManualBuild() { |
|
161 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
162 $gs = GoogleSitemapGenerator::GetInstance(); |
|
163 $gs->CheckForManualBuild(); |
|
164 } |
|
165 } |
|
166 |
|
167 /** |
|
168 * Invokes the ShowPingResult method of the generator |
|
169 */ |
|
170 function CallShowPingResult() { |
|
171 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
172 $gs = GoogleSitemapGenerator::GetInstance(); |
|
173 $gs->ShowPingResult(); |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 function CallHtmlShowHelpList($filterVal,$screen) { |
|
179 if($screen == "settings_page_sitemap") { |
|
180 $links = array( |
|
181 __('Plugin Homepage','sitemap')=>'http://www.arnebrachhold.de/redir/sitemap-help-home/', |
|
182 __('Sitemap FAQ')=>'http://www.arnebrachhold.de/redir/sitemap-help-faq/' |
|
183 ); |
|
184 |
|
185 $filterVal["settings_page_sitemap"] = ''; |
|
186 |
|
187 $i=0; |
|
188 foreach($links AS $text=>$url) { |
|
189 $filterVal["settings_page_sitemap"].='<a href="' . $url . '">' . $text . '</a>' . ($i < (count($links)-1)?'<br />':'') ; |
|
190 $i++; |
|
191 } |
|
192 } |
|
193 return $filterVal; |
|
194 } |
|
195 |
|
196 function CallDoRobots() { |
|
197 if(GoogleSitemapGeneratorLoader::LoadPlugin()) { |
|
198 $gs = GoogleSitemapGenerator::GetInstance(); |
|
199 $gs->DoRobots(); |
|
200 } |
|
201 } |
|
202 |
|
203 /** |
|
204 * Loads the actual generator class and tries to raise the memory and time limits if not already done by WP |
|
205 * |
|
206 * @return boolean true if run successfully |
|
207 */ |
|
208 function LoadPlugin() { |
|
209 |
|
210 $mem = abs(intval(@ini_get('memory_limit'))); |
|
211 if($mem && $mem < 32) { |
|
212 @ini_set('memory_limit', '32M'); |
|
213 } |
|
214 |
|
215 $time = abs(intval(@ini_get("max_execution_time"))); |
|
216 if($time != 0 && $time < 120) { |
|
217 @set_time_limit(120); |
|
218 } |
|
219 |
|
220 if(!class_exists("GoogleSitemapGenerator")) { |
|
221 |
|
222 $path = trailingslashit(dirname(__FILE__)); |
|
223 |
|
224 if(!file_exists( $path . 'sitemap-core.php')) return false; |
|
225 require_once($path. 'sitemap-core.php'); |
|
226 } |
|
227 |
|
228 GoogleSitemapGenerator::Enable(); |
|
229 return true; |
|
230 } |
|
231 |
|
232 /** |
|
233 * Returns the plugin basename of the plugin (using __FILE__) |
|
234 * |
|
235 * @return string The plugin basename, "sitemap" for example |
|
236 */ |
|
237 function GetBaseName() { |
|
238 return plugin_basename(__FILE__); |
|
239 } |
|
240 |
|
241 /** |
|
242 * Returns the name of this loader script, using __FILE__ |
|
243 * |
|
244 * @return string The __FILE__ value of this loader script |
|
245 */ |
|
246 function GetPluginFile() { |
|
247 return __FILE__; |
|
248 } |
|
249 |
|
250 /** |
|
251 * Returns the plugin version |
|
252 * |
|
253 * Uses the WP API to get the meta data from the top of this file (comment) |
|
254 * |
|
255 * @return string The version like 3.1.1 |
|
256 */ |
|
257 function GetVersion() { |
|
258 if(!function_exists('get_plugin_data')) { |
|
259 if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); //2.3+ |
|
260 else if(file_exists(ABSPATH . 'wp-admin/admin-functions.php')) require_once(ABSPATH . 'wp-admin/admin-functions.php'); //2.1 |
|
261 else return "0.ERROR"; |
|
262 } |
|
263 $data = get_plugin_data(__FILE__); |
|
264 return $data['Version']; |
|
265 } |
|
266 |
|
267 |
|
268 } |
|
269 |
|
270 //Enable the plugin for the init hook, but only if WP is loaded. Calling this php file directly will do nothing. |
|
271 if(defined('ABSPATH') && defined('WPINC')) { |
|
272 add_action("init",array("GoogleSitemapGeneratorLoader","Enable"),1000,0); |
|
273 } |
|
274 ?> |