[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | /*
|
---|
| 4 | $Id: sitemap.php 150611 2009-08-30 21:12:33Z 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.1.6
|
---|
| 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 | //Robots.txt request
|
---|
| 70 | add_action('do_robots', array('GoogleSitemapGeneratorLoader', 'CallDoRobots'),100,0);
|
---|
| 71 |
|
---|
| 72 | //Help topics for context sensitive help
|
---|
| 73 | add_filter('contextual_help_list', array('GoogleSitemapGeneratorLoader', 'CallHtmlShowHelpList'),9999,2);
|
---|
| 74 |
|
---|
| 75 | //Check if this is a BUILD-NOW request (key will be checked later)
|
---|
| 76 | if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) {
|
---|
| 77 | GoogleSitemapGeneratorLoader::CallCheckForManualBuild();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
| 82 | * Registers the plugin in the admin menu system
|
---|
| 83 | */
|
---|
| 84 | function RegisterAdminPage() {
|
---|
| 85 |
|
---|
| 86 | if (function_exists('add_options_page')) {
|
---|
| 87 | add_options_page(__('XML-Sitemap Generator','sitemap'), __('XML-Sitemap','sitemap'), 10, 'sitemap.php', array('GoogleSitemapGeneratorLoader','CallHtmlShowOptionsPage'));
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | function RegisterAdminIcon($hook) {
|
---|
| 92 | if ( $hook == 'sitemap.php' && function_exists('plugins_url')) {
|
---|
| 93 | return plugins_url('img/icon-arne.gif',GoogleSitemapGeneratorLoader::GetBaseName());
|
---|
| 94 | }
|
---|
| 95 | return $hook;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | function RegisterPluginLinks($links, $file) {
|
---|
| 99 | $base = GoogleSitemapGeneratorLoader::GetBaseName();
|
---|
| 100 | if ($file == $base) {
|
---|
| 101 | $links[] = '<a href="options-general.php?page=sitemap.php">' . __('Settings') . '</a>';
|
---|
| 102 | $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-faq/">' . __('FAQ') . '</a>';
|
---|
| 103 | $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-support/">' . __('Support') . '</a>';
|
---|
| 104 | $links[] = '<a href="http://www.arnebrachhold.de/redir/sitemap-plist-donate/">' . __('Donate') . '</a>';
|
---|
| 105 | }
|
---|
| 106 | return $links;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * Invokes the HtmlShowOptionsPage method of the generator
|
---|
| 111 | */
|
---|
| 112 | function CallHtmlShowOptionsPage() {
|
---|
| 113 | if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
|
---|
| 114 | $gs = GoogleSitemapGenerator::GetInstance();
|
---|
| 115 | $gs->HtmlShowOptionsPage();
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
| 120 | * Invokes the CheckForAutoBuild method of the generator
|
---|
| 121 | */
|
---|
| 122 | function CallCheckForAutoBuild($args) {
|
---|
| 123 | if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
|
---|
| 124 | $gs = GoogleSitemapGenerator::GetInstance();
|
---|
| 125 | $gs->CheckForAutoBuild($args);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | /**
|
---|
| 130 | * Invokes the BuildSitemap method of the generator
|
---|
| 131 | */
|
---|
| 132 | function CallBuildSitemap() {
|
---|
| 133 | if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
|
---|
| 134 | $gs = GoogleSitemapGenerator::GetInstance();
|
---|
| 135 | $gs->BuildSitemap();
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Invokes the CheckForManualBuild method of the generator
|
---|
| 141 | */
|
---|
| 142 | function CallCheckForManualBuild() {
|
---|
| 143 | if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
|
---|
| 144 | $gs = GoogleSitemapGenerator::GetInstance();
|
---|
| 145 | $gs->CheckForManualBuild();
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | function CallHtmlShowHelpList($filterVal,$screen) {
|
---|
| 151 | if($screen == "settings_page_sitemap") {
|
---|
| 152 | $links = array(
|
---|
| 153 | __('Plugin Homepage','sitemap')=>'http://www.arnebrachhold.de/redir/sitemap-help-home/',
|
---|
| 154 | __('Sitemap FAQ')=>'http://www.arnebrachhold.de/redir/sitemap-help-faq/'
|
---|
| 155 | );
|
---|
| 156 |
|
---|
| 157 | $filterVal["settings_page_sitemap"] = '';
|
---|
| 158 |
|
---|
| 159 | $i=0;
|
---|
| 160 | foreach($links AS $text=>$url) {
|
---|
| 161 | $filterVal["settings_page_sitemap"].='<a href="' . $url . '">' . $text . '</a>' . ($i < (count($links)-1)?'<br />':'') ;
|
---|
| 162 | $i++;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | return $filterVal;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | function CallDoRobots() {
|
---|
| 169 | if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
|
---|
| 170 | $gs = GoogleSitemapGenerator::GetInstance();
|
---|
| 171 | $gs->DoRobots();
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /**
|
---|
| 176 | * Loads the actual generator class and tries to raise the memory and time limits if not already done by WP
|
---|
| 177 | *
|
---|
| 178 | * @return boolean true if run successfully
|
---|
| 179 | */
|
---|
| 180 | function LoadPlugin() {
|
---|
| 181 |
|
---|
| 182 | $mem = abs(intval(@ini_get('memory_limit')));
|
---|
| 183 | if($mem && $mem < 32) {
|
---|
| 184 | @ini_set('memory_limit', '32M');
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | $time = abs(intval(@ini_get("max_execution_time")));
|
---|
| 188 | if($time != 0 && $time < 120) {
|
---|
| 189 | @set_time_limit(120);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | if(!class_exists("GoogleSitemapGenerator")) {
|
---|
| 193 |
|
---|
| 194 | $path = trailingslashit(dirname(__FILE__));
|
---|
| 195 |
|
---|
| 196 | if(!file_exists( $path . 'sitemap-core.php')) return false;
|
---|
| 197 | require_once($path. 'sitemap-core.php');
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | GoogleSitemapGenerator::Enable();
|
---|
| 201 | return true;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | /**
|
---|
| 205 | * Returns the plugin basename of the plugin (using __FILE__)
|
---|
| 206 | *
|
---|
| 207 | * @return string The plugin basename, "sitemap" for example
|
---|
| 208 | */
|
---|
| 209 | function GetBaseName() {
|
---|
| 210 | return plugin_basename(__FILE__);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /**
|
---|
| 214 | * Returns the name of this loader script, using __FILE__
|
---|
| 215 | *
|
---|
| 216 | * @return string The __FILE__ value of this loader script
|
---|
| 217 | */
|
---|
| 218 | function GetPluginFile() {
|
---|
| 219 | return __FILE__;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | /**
|
---|
| 223 | * Returns the plugin version
|
---|
| 224 | *
|
---|
| 225 | * Uses the WP API to get the meta data from the top of this file (comment)
|
---|
| 226 | *
|
---|
| 227 | * @return string The version like 3.1.1
|
---|
| 228 | */
|
---|
| 229 | function GetVersion() {
|
---|
| 230 | if(!function_exists('get_plugin_data')) {
|
---|
| 231 | if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); //2.3+
|
---|
| 232 | else if(file_exists(ABSPATH . 'wp-admin/admin-functions.php')) require_once(ABSPATH . 'wp-admin/admin-functions.php'); //2.1
|
---|
| 233 | else return "0.ERROR";
|
---|
| 234 | }
|
---|
| 235 | $data = get_plugin_data(__FILE__);
|
---|
| 236 | return $data['Version'];
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | //Enable the plugin for the init hook, but only if WP is loaded. Calling this php file directly will do nothing.
|
---|
| 243 | if(defined('ABSPATH') && defined('WPINC')) {
|
---|
| 244 | add_action("init",array("GoogleSitemapGeneratorLoader","Enable"),1000,0);
|
---|
| 245 | }
|
---|
| 246 | ?>
|
---|