[pLog-svn] r5316 - in plugins/branches/lifetype-1.2/sitemap: . locale templates
mark at devel.lifetype.net
mark at devel.lifetype.net
Tue Apr 17 06:11:52 EDT 2007
Author: mark
Date: 2007-04-17 06:11:52 -0400 (Tue, 17 Apr 2007)
New Revision: 5316
Added:
plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_CN.php
plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_TW.php
Modified:
plugins/branches/lifetype-1.2/sitemap/locale/locale_de_DE.php
plugins/branches/lifetype-1.2/sitemap/locale/locale_en_UK.php
plugins/branches/lifetype-1.2/sitemap/pluginsitemap.class.php
plugins/branches/lifetype-1.2/sitemap/readme.txt
plugins/branches/lifetype-1.2/sitemap/templates/pluginsettings.template
Log:
Some changes to sitemap plugins:
1. Add zh_TW and zh_CN locales
2. Refactor the code
3. Add curl and native PHP httpclient as an alternative option when we ping the google site map manager. It is very useful when web hosting does not support allow_url_fopen.
4. Change the rewrite rules. Now, the sitemap url will follow the request format.
- Normal Request mode, the url looks like
http://yourdomain/sitemap1.gz
- Others Request mode, the url will looks like
http://yourblogdomain/sitemap1.gz.
yourblogdomain here is depens on what you set in url setting. So, it may looks like http://yourdomain/yourblogname/sitemap1.gz
still under tesing, don't use this commit for production site.
Modified: plugins/branches/lifetype-1.2/sitemap/locale/locale_de_DE.php
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/locale/locale_de_DE.php 2007-04-16 21:07:55 UTC (rev 5315)
+++ plugins/branches/lifetype-1.2/sitemap/locale/locale_de_DE.php 2007-04-17 10:11:52 UTC (rev 5316)
@@ -1,5 +1,4 @@
<?php
-$messages["manageSettings"] = "Einstellungen";
$messages["sitemapPluginSettings"] = "Sitemaps";
$messages["sitemap_plugin_enabled"] = "Diese Plugin aktivieren.";
Modified: plugins/branches/lifetype-1.2/sitemap/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/locale/locale_en_UK.php 2007-04-16 21:07:55 UTC (rev 5315)
+++ plugins/branches/lifetype-1.2/sitemap/locale/locale_en_UK.php 2007-04-17 10:11:52 UTC (rev 5316)
@@ -1,5 +1,4 @@
<?php
-$messages["manageSettings"] = "Settings";
$messages["sitemapPluginSettings"] = "Sitemaps";
$messages["sitemap_plugin_enabled"] = "Enable this plugin";
Added: plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_CN.php
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_CN.php (rev 0)
+++ plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_CN.php 2007-04-17 10:11:52 UTC (rev 5316)
@@ -0,0 +1,16 @@
+<?php
+$messages["sitemapPluginSettings"] = "网站地图设置";
+
+$messages["sitemap_plugin_enabled"] = "启动外挂程式";
+$messages["sitemap_plugin"] = "网站地图外挂程式";
+
+$messages["google_notification_enabled"] = "当你的网站地图更新时,自动发送讯息通知 Google。";
+
+$messages["sitemap_settings_saved_ok"] = "网站地图设置储存成功。";
+
+$messages["label_configuration"] = "设置";
+$messages["label_enable"] = "启动";
+$messages["label_notify_google_enable"] = "通知 Google";
+
+$messages["link_to_sitemap"] = "你的网站地图网址:";
+?>
\ No newline at end of file
Added: plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_TW.php
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_TW.php (rev 0)
+++ plugins/branches/lifetype-1.2/sitemap/locale/locale_zh_TW.php 2007-04-17 10:11:52 UTC (rev 5316)
@@ -0,0 +1,16 @@
+<?php
+$messages["sitemapPluginSettings"] = "網站地圖設定";
+
+$messages["sitemap_plugin_enabled"] = "啟動外掛程式";
+$messages["sitemap_plugin"] = "網站地圖外掛程式";
+
+$messages["google_notification_enabled"] = "當你的網站地圖更新時,自動發送訊息通知 Google。";
+
+$messages["sitemap_settings_saved_ok"] = "網站地圖設定儲存成功。";
+
+$messages["label_configuration"] = "設定";
+$messages["label_enable"] = "啟動";
+$messages["label_notify_google_enable"] = "通知 Google";
+
+$messages["link_to_sitemap"] = "你的網站地圖網址:";
+?>
\ No newline at end of file
Modified: plugins/branches/lifetype-1.2/sitemap/pluginsitemap.class.php
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/pluginsitemap.class.php 2007-04-16 21:07:55 UTC (rev 5315)
+++ plugins/branches/lifetype-1.2/sitemap/pluginsitemap.class.php 2007-04-17 10:11:52 UTC (rev 5316)
@@ -1,198 +1,228 @@
<?php
+ lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
- lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
- // TODO: httpclient isn't used?
- lt_include( PLOG_CLASS_PATH."class/net/http/httpclient.class.php" );
-
-
- /**
- * implements notification of
- */
- class PluginSiteMap extends PluginBase
- {
- var $pluginEnabled;
- var $cacheFolder;
+ define( 'GOOGLE_SITEMAP_PING_URL', 'http://www.google.com/webmasters/sitemaps/ping?sitemap=' );
+ /**
+ * implements notification of
+ */
+ class PluginSiteMap extends PluginBase
+ {
+ var $pluginEnabled;
+ var $cacheFolder;
- function PluginSiteMap( $source = "" )
- {
- $this->PluginBase( $source );
-
- $this->id = "sitemap";
- $this->desc = "Generates Google Sitemap for all permalinks.";
- $this->author = "Paul Westbrook";
- $this->locales = Array( "en_UK", "de_DE" );
- $this->version = "20070301";
-
+ function PluginSiteMap( $source = "" )
+ {
+ $this->PluginBase( $source );
+
+ $this->id = "sitemap";
+ $this->desc = "Generates Google Sitemap for all permalinks.";
+ $this->author = "Paul Westbrook";
+ $this->locales = Array( "en_UK", "de_DE", "zh_TW", "zh_CN" );
+ $this->version = "20070417";
+
if( $source == "admin" )
$this->initAdmin();
else
$this->init();
- }
+ }
- function init()
- {
- // register the events we want
- $this->registerNotification( EVENT_POST_POST_ADD );
- $this->registerNotification( EVENT_POST_POST_UPDATE );
- $this->registerNotification( EVENT_POST_POST_DELETE );
-
- }
+ function init()
+ {
+ // register the events we want
+ $this->registerNotification( EVENT_POST_POST_ADD );
+ $this->registerNotification( EVENT_POST_POST_UPDATE );
+ $this->registerNotification( EVENT_POST_POST_DELETE );
+ }
- function initAdmin()
- {
- $this->init();
+ function initAdmin()
+ {
+ $this->init();
- if (defined( "EVENT_POST_ADMIN_PURGE_TEMP_FOLDER" )) {
- // register the events we want
- $this->registerNotification( EVENT_POST_ADMIN_PURGE_TEMP_FOLDER );
- }
+ if (defined( "EVENT_POST_ADMIN_PURGE_TEMP_FOLDER" )) {
+ // register the events we want
+ $this->registerNotification( EVENT_POST_ADMIN_PURGE_TEMP_FOLDER );
+ }
- // register an action that will allow users to see which comments have not been
- // accepted yet
- $this->registerAdminAction( "sitemapPluginSettings", "AdminSiteMapPluginSettingsAction" );
- $this->registerAdminAction( "sitemapPluginUpdateSettings", "AdminSiteMapPluginUpdateSettingsAction" );
-
- // add a menu entry
- $menu =& Menu::getMenu();
- if( !$menu->entryExists( "/menu/controlCenter/manageSettings" ))
- $this->addMenuEntry( "/menu/controlCenter", "manageSettings", "", "", true, false );
- $this->addMenuEntry( "/menu/controlCenter/manageSettings", "sitemapPluginSettings", "admin.php?op=sitemapPluginSettings", "", true, false );
- }
+ // register an action that will allow users to see which comments have not been
+ // accepted yet
+ $this->registerAdminAction( "sitemapPluginSettings", "AdminSiteMapPluginSettingsAction" );
+ $this->registerAdminAction( "sitemapPluginUpdateSettings", "AdminSiteMapPluginUpdateSettingsAction" );
- function register()
- {
- $config =& Config::getConfig();
+ // add a menu entry
+ $menu =& Menu::getMenu();
+ if( !$menu->entryExists( "/menu/controlCenter/manageSettings" ))
+ $this->addMenuEntry( "/menu/controlCenter", "manageSettings", "", "", true, false );
+ $this->addMenuEntry( "/menu/controlCenter/manageSettings", "sitemapPluginSettings", "admin.php?op=sitemapPluginSettings", "", true, false );
+ }
- $this->cacheFolder = $config->getValue('temp_folder');
- $this->cacheFolder = $this->cacheFolder.'/sitemap/'.$this->blogInfo->getId();
- if( !File::exists( $this->cacheFolder )) {
- File::createDir( $this->cacheFolder );
- }
+ function register()
+ {
+ $config =& Config::getConfig();
- $blogSettings = $this->blogInfo->getSettings();
- $this->pluginEnabled = $blogSettings->getValue( "plugin_sitemap_enabled" );
- }
+ $this->cacheFolder = $config->getValue('temp_folder');
+ $this->cacheFolder = $this->cacheFolder.'/sitemap/'.$this->blogInfo->getId();
+ if( !File::exists( $this->cacheFolder )) {
+ File::createDir( $this->cacheFolder, 0755 );
+ }
- function isEnabled()
- {
- return $this->pluginEnabled;
- }
-
- /**
- * process the events that we have registered
- *
- * @see PluginBase::process
- * @see PluginManager
- */
- function process( $eventType, $params )
- {
- $validEvent = false;
-
- // Looking for EVENT_POST_POST_ADD, EVENT_POST_POST_UPDATE, EVENT_POST_POST_DELETE
- // or EVENT_POST_ADMIN_PURGE_TEMP_FOLDER (if defined)
- if ( $eventType == EVENT_POST_POST_ADD ||
- $eventType == EVENT_POST_POST_UPDATE ||
- $eventType == EVENT_POST_POST_DELETE ||
- (defined( "EVENT_POST_ADMIN_PURGE_TEMP_FOLDER" ) && $eventType == EVENT_POST_ADMIN_PURGE_TEMP_FOLDER) ) {
- $validEvent = true;
- }
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_sitemap_enabled" );
+ }
- // make sure we're processing the right event!
- if( $validEvent == false)
- {
- return true;
- }
-
- // Load all of the settings for this blog
- $this->register();
-
- // do nothing if the plugin is not enabled!
- $blogSettings = $this->blogInfo->getSettings();
- if( !$blogSettings->getValue( "plugin_sitemap_enabled" ))
- {
- // error_log( "plugin not enabled" );
- return true;
- }
-
- $this->GenerateSiteMap( );
-
- return true;
- }
-
- /**
- * Turns on notification for the specified article
- *
- */
-
- function GenerateSiteMap( )
- {
- // articles object
- $articles = new Articles;
+ function isEnabled()
+ {
+ return $this->pluginEnabled;
+ }
- $list = $articles->getBlogArticles(
- $this->blogInfo->getId(),
- -1, // date
- -1, // all articles
- 0, // all categories
- POST_STATUS_PUBLISHED // only published articles
- );
+ /**
+ * process the events that we have registered
+ *
+ * @see PluginBase::process
+ * @see PluginManager
+ */
+ function process( $eventType, $params )
+ {
+ $validEvent = false;
- $url = $this->blogInfo->getBlogRequestGenerator();
+ // Looking for EVENT_POST_POST_ADD, EVENT_POST_POST_UPDATE, EVENT_POST_POST_DELETE
+ // or EVENT_POST_ADMIN_PURGE_TEMP_FOLDER (if defined)
+ if ( $eventType == EVENT_POST_POST_ADD ||
+ $eventType == EVENT_POST_POST_UPDATE ||
+ $eventType == EVENT_POST_POST_DELETE ||
+ (defined( "EVENT_POST_ADMIN_PURGE_TEMP_FOLDER" ) && $eventType == EVENT_POST_ADMIN_PURGE_TEMP_FOLDER) ) {
+ $validEvent = true;
+ }
+ // make sure we're processing the right event!
+ if( $validEvent == false)
+ {
+ return true;
+ }
- $compressedFile = $this->cacheFolder."/sitemap.gz";
-
- // Save this to a compressed file.
- $gz = gzopen($compressedFile,'w9');
+ // Load all of the settings for this blog
+ $this->register();
- if ( $gz )
- {
+ // do nothing if the plugin is not enabled!
+ $blogSettings = $this->blogInfo->getSettings();
+ if( !$blogSettings->getValue( "plugin_sitemap_enabled" ))
+ {
+ // error_log( "plugin not enabled" );
+ return true;
+ }
- // Data from the xml file that needs to be there.
- $xmlData = "<?xml version='1.0' encoding='UTF-8'?>\n".
- "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
-
- gzwrite($gz, $xmlData);
-
- // Iterate over the posts and create an entry for each.
- foreach($list as $item)
- {
- gzwrite($gz, "<url>\n");
- gzwrite($gz, "<loc>\n");
- gzwrite($gz, htmlspecialchars( $url->postPermalink( $item ) ) . "\n");
- gzwrite($gz, "</loc>\n");
- gzwrite($gz, "</url>\n");
- }
- gzwrite($gz, "</urlset>\n");
- gzclose($gz);
- }
-
- $blogSettings = $this->blogInfo->getSettings();
- if( $blogSettings->getValue( "plugin_sitemap_notify_google_enabled" ))
- {
- lt_include( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
+ $this->GenerateSiteMap( );
- // Send the request to google
- $rg =& RequestGenerator::getRequestGenerator( $this->blogInfo );
- $rewriteFile = "/sitemap" . $this->blogInfo->getId() . ".gz";
- $rewriteFileUrl = $rg->getUrl($rewriteFile);
-
- $pingUrl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($rewriteFileUrl);
-
- $handle = fopen( $pingUrl, "r" );
- fclose( $handle );
+ return true;
+ }
- }
- }
+ /**
+ * Turns on notification for the specified article
+ *
+ */
- function getPluginConfigurationKeys()
+ function GenerateSiteMap( )
{
- return( Array(
- Array( "name" => "plugin_sitemap_enabled", "type" => "boolean" ),
- Array( "name" => "plugin_sitemap_notify_google_enabled", "type" => "boolean" ),
- ));
+ // articles object
+ $articles = new Articles;
+
+ $list = $articles->getBlogArticles(
+ $this->blogInfo->getId(),
+ -1, // date
+ -1, // all articles
+ 0, // all categories
+ POST_STATUS_PUBLISHED // only published articles
+ );
+
+ $url = $this->blogInfo->getBlogRequestGenerator();
+
+ // Save this to a compressed file.
+ $compressedFile = $this->cacheFolder."/sitemap.gz";
+ $gz = gzopen($compressedFile,'w9');
+
+ if ( $gz )
+ {
+ // Data from the xml file that needs to be there.
+ $xmlData = "<?xml version='1.0' encoding='UTF-8'?>\n";
+ $xmlData .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
+
+ gzwrite( $gz, $xmlData );
+
+ // Iterate over the posts and create an entry for each.
+ foreach( $list as $item )
+ {
+ gzwrite( $gz, "<url>\n" );
+ gzwrite( $gz, "<loc>\n" );
+ gzwrite( $gz, htmlspecialchars( $url->postPermalink( $item ) ) . "\n" );
+ gzwrite( $gz, "</loc>\n" );
+ gzwrite( $gz, "</url>\n" );
+ }
+ gzwrite( $gz, "</urlset>\n" );
+ gzclose( $gz );
+ }
+
+ if( File::isReadable( $compressedFile ) )
+ File::chMod( $compressedFile, 0644 );
+
+ $blogSettings = $this->blogInfo->getSettings();
+ if( $blogSettings->getValue( "plugin_sitemap_notify_google_enabled" ))
+ {
+ $siteMapUrl = $this->getSiteMapUrl();
+ $this->pingGoogleSiteMapManager( $siteMapUrl );
+ }
}
- }
+ funcrion getSiteMapUrl()
+ {
+ $rg =& $this->blogInfo->getBlogRequestGenerator();
+ $config =& Config::getConfig();
+ $siteMapFile = "/sitemap" . $this->blogInfo->getId() . ".gz";
+
+ if( $config->getValue( "request_format_mode" ) == NORMAL_REQUEST_MODE )
+ $siteMapUrl = $rg->getUrl($siteMapFile);
+ else
+ $siteMapUrl = $rg->getBlogLink().$siteMapFile;
+
+ return $siteMapUrl;
+ }
+
+ function pingGoogleSiteMapManager( $siteMapUrl )
+ {
+ $pingUrl = GOOGLE_SITEMAP_PING_URL . urlencode( $siteMapUrl );
+
+ // Some web hosting does not allow url fopen to open url
+ // So, here we try fopen first, then curl, then the native httpclient
+ if( ini_get( 'allow_url_fopen' ) )
+ {
+ $handle = fopen( $pingUrl, "r" );
+ fclose( $handle );
+ }
+ elseif( function_exists( 'curl_init' ) )
+ {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $pingUrl);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_exec($ch);
+ curl_close($ch);
+ }
+ else
+ {
+ lt_include( PLOG_CLASS_PATH."class/net/http/httpclient.class.php" );
+ $httpClient = new HttpClient();
+ $httpClient->fetch( $pingUrl );
+ }
+ }
+
+ function getPluginConfigurationKeys()
+ {
+ return (Array(
+ Array("name" => "plugin_sitemap_enabled",
+ "type" => "boolean"),
+ Array("name" => "plugin_sitemap_notify_google_enabled",
+ "type" => "boolean")
+ )
+ );
+ }
+
+ }
?>
\ No newline at end of file
Modified: plugins/branches/lifetype-1.2/sitemap/readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/readme.txt 2007-04-16 21:07:55 UTC (rev 5315)
+++ plugins/branches/lifetype-1.2/sitemap/readme.txt 2007-04-17 10:11:52 UTC (rev 5316)
@@ -1,7 +1,7 @@
Plugin: SiteMap
Author: paul at westbrooks.org
-Release Date: 2005/06/23
-Version: 1.2
+Release Date: 20070417
+Version: 20070417
Creates Google Sitemap for a blog. This plugin adds all of the permalinks from
a given blog to a site map file. It can also optionally automatically notify
@@ -19,23 +19,17 @@
Allow from all
</files>
-
-
Add the following lines to the lifetype/.htaccess
-
-
<IfModule mod_rewrite.c>
RewriteEngine On
+RewriteBase /
- RewriteBase /
-
+# Point to the sitemap file that is local to the blog if user use NORMAL_REQUEST_MODE
+RewriteRule ^sitemap([0-9]+)\.gz$ tmp/sitemap/$1/sitemap.gz [L,NC]
- # Point to the sitemap file that is local to the blog
-RewriteRule
- ^sitemap([0-9]+)\.gz$ tmp/sitemap/$1/sitemap.gz [L,NC]
-
+# Point to the sitemap file that is local to the blog if user use OTHER REQUEST MODE
+RewriteRule ^/(.*)/sitemap([0-9]+)\.gz$ tmp/sitemap/$2/sitemap.gz [L,NC]
-</IfModule>
-
+</IfModule>
\ No newline at end of file
Modified: plugins/branches/lifetype-1.2/sitemap/templates/pluginsettings.template
===================================================================
--- plugins/branches/lifetype-1.2/sitemap/templates/pluginsettings.template 2007-04-16 21:07:55 UTC (rev 5315)
+++ plugins/branches/lifetype-1.2/sitemap/templates/pluginsettings.template 2007-04-17 10:11:52 UTC (rev 5316)
@@ -8,14 +8,24 @@
<div class="field">
<label for="pluginEnabled">{$locale->tr("label_enable")}</label>
<div class="formHelp">
- <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" />{$locale->tr("sitemap_plugin_enabled")}
+ <input class="checkbox" type="checkbox" name="pluginEnabled"
+ id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if}
+ {user_cannot_override
+ key=sitemap_plugin_enabled}disabled="disabled"
+ {/user_cannot_override}
+ value="1" />{$locale->tr("sitemap_plugin_enabled")}
</div>
</div>
- <div class="field">
+ <div class="field">
<label for="sendGoogleNotificationEnabled">{$locale->tr("label_notify_google_enable")}</label>
<div class="formHelp">
- <input class="checkbox" type="checkbox" name="notifyGoogleEnabled" id="notifyGoogleEnabled" {if $notifyGoogleEnabled} checked="checked" {/if} value="1" />{$locale->tr("google_notification_enabled")}
+ <input class="checkbox" type="checkbox" name="notifyGoogleEnabled"
+ id="notifyGoogleEnabled" {if $notifyGoogleEnabled} checked="checked" {/if}
+ {user_cannot_override
+ key=google_notification_enabled}disabled="disabled"
+ {/user_cannot_override}
+ value="1" />{$locale->tr("google_notification_enabled")}
</div>
</div>
More information about the pLog-svn
mailing list