'index.php?xml_sitemap=params=$matches[2]', 'sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$' => 'index.php?xml_sitemap=params=$matches[2];zip=true', 'sitemap(-+([a-zA-Z0-9_-]+))?\.html$' => 'index.php?xml_sitemap=params=$matches[2];html=true', 'sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$' => 'index.php?xml_sitemap=params=$matches[2];html=true;zip=true' ); return array_merge($smRules,$wpRules); } /** * Returns the rules required for Nginx permalinks * * @return string[] */ public static function GetNginXRules() { return array( 'rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;', 'rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;', 'rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;', 'rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;' ); } /** * Adds the filters for wp rewrite rule adding * * @since 4.0 * @uses add_filter() */ public static function SetupRewriteHooks() { add_filter('rewrite_rules_array', array(__CLASS__, 'AddRewriteRules'), 1, 1); } /** * Flushes the rewrite rules * * @since 4.0 * @global $wp_rewrite WP_Rewrite * @uses WP_Rewrite::flush_rules() */ public static function ActivateRewrite() { /** @var $wp_rewrite WP_Rewrite */ global $wp_rewrite; $wp_rewrite->flush_rules(false); update_option("sm_rewrite_done", self::$svnVersion); } /** * Handled the plugin activation on installation * * @uses GoogleSitemapGeneratorLoader::ActivateRewrite * @since 4.0 */ public static function ActivatePlugin() { self::SetupRewriteHooks(); self::ActivateRewrite(); if(self::LoadPlugin()) { $gsg = GoogleSitemapGenerator::GetInstance(); if($gsg->OldFileExists()) { $gsg->DeleteOldFiles(); } } } /** * Handled the plugin deactivation * * @uses GoogleSitemapGeneratorLoader::ActivateRewrite * @since 4.0 */ public static function DeactivatePlugin() { delete_option("sm_rewrite_done"); wp_clear_scheduled_hook('sm_ping_daily'); } /** * Handles the plugin output on template redirection if the xml_sitemap query var is present. * * @since 4.0 */ public static function DoTemplateRedirect() { /** @var $wp_query WP_Query */ global $wp_query; if(!empty($wp_query->query_vars["xml_sitemap"])) { $wp_query->is_404 = false; $wp_query->is_feed = true; self::CallShowSitemap($wp_query->query_vars["xml_sitemap"]); } } /** * Registers the plugin in the admin menu system * * @uses add_options_page() */ public static function RegisterAdminPage() { add_options_page(__('XML-Sitemap Generator', 'sitemap'), __('XML-Sitemap', 'sitemap'), 'administrator', self::GetBaseName(), array(__CLASS__, 'CallHtmlShowOptionsPage')); } /** * Returns a nice icon for the Ozh Admin Menu if the {@param $hook} equals to the sitemap plugin * * @param string $hook The hook to compare * @return string The path to the icon */ public static function RegisterAdminIcon($hook) { if($hook == self::GetBaseName() && function_exists('plugins_url')) { return plugins_url('img/icon-arne.gif', self::GetBaseName()); } return $hook; } /** * Registers additional links for the sitemap plugin on the WP plugin configuration page * * Registers the links if the $file param equals to the sitemap plugin * @param $links Array An array with the existing links * @param $file string The file to compare to * @return string[] */ public static function RegisterPluginLinks($links, $file) { $base = self::GetBaseName(); if($file == $base) { $links[] = '' . __('Settings', 'sitemap') . ''; $links[] = '' . __('FAQ', 'sitemap') . ''; $links[] = '' . __('Support', 'sitemap') . ''; $links[] = '' . __('Donate', 'sitemap') . ''; } return $links; } /** * @param $new_status string The new post status * @param $old_status string The old post status * @param $post WP_Post The post object */ public static function SchedulePingOnStatusChange($new_status, $old_status, $post ) { if($new_status == 'publish') { set_transient('sm_ping_post_id', $post->ID, 120); wp_schedule_single_event(time() + 5, 'sm_ping'); } } /** * Invokes the HtmlShowOptionsPage method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::HtmlShowOptionsPage() */ public static function CallHtmlShowOptionsPage() { if(self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->HtmlShowOptionsPage(); } } /** * Invokes the ShowPingResult method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::ShowPingResult() */ public static function CallShowPingResult() { if(self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->ShowPingResult(); } } /** * Invokes the SendPing method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::SendPing() */ public static function CallSendPing() { if(self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->SendPing(); } } /** * Invokes the SendPingDaily method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::SendPingDaily() */ public static function CallSendPingDaily() { if (self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->SendPingDaily(); } } /** * Invokes the ShowSitemap method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::ShowSitemap() */ public static function CallShowSitemap($options) { if(self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->ShowSitemap($options); } } /** * Invokes the DoRobots method of the generator * @uses GoogleSitemapGeneratorLoader::LoadPlugin() * @uses GoogleSitemapGenerator::DoRobots() */ public static function CallDoRobots() { if(self::LoadPlugin()) { GoogleSitemapGenerator::GetInstance()->DoRobots(); } } /** * Displays the help links in the upper Help Section of WordPress * * @return Array The new links */ public static function CallHtmlShowHelpList() { $screen = get_current_screen(); $id = get_plugin_page_hookname(self::GetBaseName(), 'options-general.php'); if(is_object($screen) && $screen->id == $id) { /* load_plugin_textdomain('sitemap',false,dirname( plugin_basename( __FILE__ ) ) . '/lang'); $links = array( __('Plugin Homepage', 'sitemap') => 'http://www.arnebrachhold.de/redir/sitemap-help-home/', __('My Sitemaps FAQ', 'sitemap') => 'http://www.arnebrachhold.de/redir/sitemap-help-faq/' ); $filterVal[$id] = ''; $i = 0; foreach($links AS $text => $url) { $filterVal[$id] .= '' . $text . '' . ($i < (count($links) - 1) ? ' | ' : ''); $i++; } $screen->add_help_tab( array( 'id' => 'sitemap-links', 'title' => __('My Sitemaps FAQ', 'sitemap'), 'content' => '

' . __('dsf dsf sd f', 'sitemap') . '

', )); */ } //return $filterVal; } /** * Loads the actual generator class and tries to raise the memory and time limits if not already done by WP * * @uses GoogleSitemapGenerator::Enable() * @return boolean true if run successfully */ public static function LoadPlugin() { if(!class_exists("GoogleSitemapGenerator")) { $mem = abs(intval(@ini_get('memory_limit'))); if($mem && $mem < 128) { @ini_set('memory_limit', '128M'); } $time = abs(intval(@ini_get("max_execution_time"))); if($time != 0 && $time < 120) { @set_time_limit(120); } $path = trailingslashit(dirname(__FILE__)); if(!file_exists($path . 'sitemap-core.php')) return false; require_once($path . 'sitemap-core.php'); } GoogleSitemapGenerator::Enable(); return true; } /** * Returns the plugin basename of the plugin (using __FILE__) * * @return string The plugin basename, "sitemap" for example */ public static function GetBaseName() { return plugin_basename(sm_GetInitFile()); } /** * Returns the name of this loader script, using sm_GetInitFile * * @return string The sm_GetInitFile value */ public static function GetPluginFile() { return sm_GetInitFile(); } /** * Returns the plugin version * * Uses the WP API to get the meta data from the top of this file (comment) * * @return string The version like 3.1.1 */ public static function GetVersion() { if(!isset($GLOBALS["sm_version"])) { if(!function_exists('get_plugin_data')) { if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) { require_once(ABSPATH . 'wp-admin/includes/plugin.php'); } else return "0.ERROR"; } $data = get_plugin_data(self::GetPluginFile(), false, false); $GLOBALS["sm_version"] = $data['Version']; } return $GLOBALS["sm_version"]; } public static function GetSvnVersion() { return self::$svnVersion; } } //Enable the plugin for the init hook, but only if WP is loaded. Calling this php file directly will do nothing. if(defined('ABSPATH') && defined('WPINC')) { add_action("init", array("GoogleSitemapGeneratorLoader", "Enable"), 15, 0); register_activation_hook(sm_GetInitFile(), array('GoogleSitemapGeneratorLoader', 'ActivatePlugin')); register_deactivation_hook(sm_GetInitFile(), array('GoogleSitemapGeneratorLoader', 'DeactivatePlugin')); //Set up hooks for adding permalinks, query vars. //Don't wait until init with this, since other plugins might flush the rewrite rules in init already... GoogleSitemapGeneratorLoader::SetupQueryVars(); GoogleSitemapGeneratorLoader::SetupRewriteHooks(); }