[pLog-svn] r2271 - in plugins/trunk: . sitemap sitemap/class
sitemap/class/action sitemap/class/view sitemap/locale
sitemap/templates
pwestbro at devel.plogworld.net
pwestbro at devel.plogworld.net
Fri Jun 24 23:08:47 GMT 2005
Author: pwestbro
Date: 2005-06-24 23:08:46 +0000 (Fri, 24 Jun 2005)
New Revision: 2271
Added:
plugins/trunk/sitemap/
plugins/trunk/sitemap/class/
plugins/trunk/sitemap/class/action/
plugins/trunk/sitemap/class/action/adminsitemappluginsettingsaction.class.php
plugins/trunk/sitemap/class/action/adminsitemappluginupdatesettingsaction.class.php
plugins/trunk/sitemap/class/view/
plugins/trunk/sitemap/class/view/adminsitemappluginsettingsview.class.php
plugins/trunk/sitemap/locale/
plugins/trunk/sitemap/locale/locale_en_UK.php
plugins/trunk/sitemap/pluginsitemap.class.php
plugins/trunk/sitemap/readme.txt
plugins/trunk/sitemap/templates/
plugins/trunk/sitemap/templates/pluginsettings.template
Log:
Added Google sitemap plugin
Added: plugins/trunk/sitemap/class/action/adminsitemappluginsettingsaction.class.php
===================================================================
--- plugins/trunk/sitemap/class/action/adminsitemappluginsettingsaction.class.php 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/class/action/adminsitemappluginsettingsaction.class.php 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,31 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/sitemap/class/view/adminsitemappluginsettingsview.class.php" );
+
+ class AdminSiteMapPluginSettingsAction extends BlogOwnerAdminAction
+ {
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminSiteMapPluginSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ $this->_view = new AdminSiteMapPluginSettingsView( $this->_blogInfo );
+
+ $this->setCommonData();
+
+ // better to return true if everything fine
+ return true;
+ }
+ }
+?>
Added: plugins/trunk/sitemap/class/action/adminsitemappluginupdatesettingsaction.class.php
===================================================================
--- plugins/trunk/sitemap/class/action/adminsitemappluginupdatesettingsaction.class.php 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/class/action/adminsitemappluginupdatesettingsaction.class.php 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,68 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/sitemap/class/view/adminsitemappluginsettingsview.class.php" );
+
+ class AdminSiteMapPluginUpdateSettingsAction extends BlogOwnerAdminAction
+ {
+
+ var $_pluginEnabled;
+ var $_notifyGoogle;
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminSiteMapPluginUpdateSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+
+ $this->_notifyGoogle = $this->_request->getValue( "notifyGoogleEnabled" );
+ $this->_notifyGoogle = ($this->_notifyGoogle != "" );
+
+ return true;
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ // update the plugin configurations to blog setting
+ $blogSettings = $this->_blogInfo->getSettings();
+ $blogSettings->setValue( "plugin_sitemap_enabled", $this->_pluginEnabled );
+ $blogSettings->setValue( "plugin_sitemap_notify_google_enabled", $this->_notifyGoogle );
+ $this->_blogInfo->setSettings( $blogSettings );
+
+ // save the blogs settings
+ $blogs = new Blogs();
+ if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+ $this->_view = new AdminSiteMapPluginSettingsView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
+ $this->setCommonData();
+
+ return false;
+ }
+
+ // if everything went ok...
+ $this->_blogInfo->setSettings( $blogSettings );
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+
+ $this->_view = new AdminSiteMapPluginSettingsView( $this->_blogInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr("sitemap_settings_saved_ok"));
+ $this->setCommonData();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+ return true;
+ }
+ }
+?>
Added: plugins/trunk/sitemap/class/view/adminsitemappluginsettingsview.class.php
===================================================================
--- plugins/trunk/sitemap/class/view/adminsitemappluginsettingsview.class.php 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/class/view/adminsitemappluginsettingsview.class.php 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,30 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ /**
+ * implements the main view of the feed reader plugin
+ */
+ class AdminSiteMapPluginSettingsView extends AdminPluginTemplatedView
+ {
+
+ function AdminSiteMapPluginSettingsView( $blogInfo )
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "sitemap", "pluginsettings" );
+ }
+
+ function render()
+ {
+ // load some configuration settings
+ $blogSettings = $this->_blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_sitemap_enabled" );
+ $notifyGoogle = $blogSettings->getValue( "plugin_sitemap_notify_google_enabled" );
+
+ // create a view and export the settings to the template
+ $this->setValue( "pluginEnabled", $pluginEnabled );
+ $this->setValue( "notifyGoogleEnabled", $notifyGoogle );
+
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/sitemap/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/sitemap/locale/locale_en_UK.php 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/locale/locale_en_UK.php 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,15 @@
+<?php
+$messages["manageSettings"] = "Settings";
+$messages["sitemapPluginSettings"] = "Sitemaps";
+
+$messages["sitemap_plugin_enabled"] = "Enable this plugin";
+$messages["sitemap_plugin"] = "Sitemap Plugin";
+
+$messages["google_notification_enabled"] = "Notify Google automatically when the sitmap changes";
+
+$messages["sitemap_settings_saved_ok"] = "Sitemap settings saved successfully!";
+
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"] = "Enable";
+$messages["label_notify_google_enable"] = "Notify Google";
+?>
\ No newline at end of file
Added: plugins/trunk/sitemap/pluginsitemap.class.php
===================================================================
--- plugins/trunk/sitemap/pluginsitemap.class.php 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/pluginsitemap.class.php 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,159 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/http/httpclient.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
+
+ /**
+ * implements notification of
+ */
+ class PluginSiteMap extends PluginBase
+ {
+ var $pluginEnabled;
+ var $cacheFolder;
+
+ function PluginSiteMap()
+ {
+ $this->PluginBase();
+
+ $this->id = "sitemap";
+ $this->desc = "Generates Google Sitemap for all permalinks.";
+ $this->author = "Paul Westbrook";
+ $this->locales = Array( "en_UK" );
+
+ $this->init();
+ }
+
+ /**
+ * registers all the filters and actions that we're going to use
+ */
+ 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 );
+
+ // 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 );
+ }
+
+ function register()
+ {
+ $config =& Config::getConfig();
+ $this->cacheFolder = $config->getValue('temp_folder');
+ $this->cacheFolder = $this->cacheFolder.'/sitemap/'.$this->blogInfo->getId();
+ if( !File::exists( $this->cacheFolder )) {
+ File::createDir( $this->cacheFolder );
+ }
+
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_sitemap_enabled" );
+ }
+
+ function isEnabled()
+ {
+ return $this->pluginEnabled;
+ }
+
+ /**
+ * process the events that we have registered
+ *
+ * @see PluginBase::process
+ * @see PluginManager
+ */
+ function process( $eventType, $params )
+ {
+ // make sure we're processing the right event!
+ if( $eventType != EVENT_POST_POST_ADD &&
+ $eventType != EVENT_POST_POST_UPDATE &&
+ $eventType != EVENT_POST_POST_DELETE )
+ {
+ 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;
+
+ $list = $articles->getBlogArticles(
+ $this->blogInfo->getId(),
+ -1, // date
+ -1, // all articles
+ 0, // all categories
+ POST_STATUS_PUBLISHED // only published articles
+ );
+
+ $url = $this->blogInfo->getBlogRequestGenerator();
+
+ // Data from the xml file that needs to be there.
+ $xmlData = $xmlData . "<?xml version='1.0' encoding='UTF-8'?>\n".
"<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"\n".
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n".
"xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84\n".
"http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">\n";
+
+
+ // Iterate over the posts and create an entry for each.
+ foreach($list as $item)
+ {
+ $xmlData = $xmlData . "<url>\n";
+ $xmlData = $xmlData . "<loc>\n";
+ $xmlData = $xmlData . htmlspecialchars( $url->postPermalink( $item ) ) . "\n";
+ $xmlData = $xmlData . "</loc>\n";
+ $xmlData = $xmlData . "</url>\n";
+ }
+ $xmlData = $xmlData . "</urlset>\n";
+
+
+ $compressedFile = $this->cacheFolder."/sitemap.gz";
+
+ // Save this to a compressed file.
+ $gz = gzopen($compressedFile,'w9');
+ if ( $gz )
+ {
gzwrite($gz, $xmlData);
gzclose($gz);
+ }
+
+ $blogSettings = $this->blogInfo->getSettings();
+ if( $blogSettings->getValue( "plugin_sitemap_notify_google_enabled" ))
+ {
+ // 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 );
+ }
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/sitemap/readme.txt
===================================================================
--- plugins/trunk/sitemap/readme.txt 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/readme.txt 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,28 @@
+Plugin: SiteMap
+Author: paul at westbrooks.org
+Release Date: 2005/06/23
+Version: 1.0
+
+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 Google that this file has changed.
+
+In order for the site map to be accessible, change plog/tmp/.htacess to allow the sitemap folder to be read by a web browser
+<Files "*">
+ Order deny,allow
+ Deny from all
+</Files>
+
+<Files "sitemap">
+ Allow from all
+</files>
+
+Add the following lines to the plog/.htaccess
+
+<IfModule mod_rewrite.c>
+RewriteEngine On
+RewriteBase /
+
+# Point to the sitemap file that is local to the blog
+RewriteRule ^sitemap([0-9]+)\.gz$ tmp/sitemap/$1/sitemap.gz [L,NC]
+
+</IfModule>
+
Added: plugins/trunk/sitemap/templates/pluginsettings.template
===================================================================
--- plugins/trunk/sitemap/templates/pluginsettings.template 2005-06-23 18:21:39 UTC (rev 2270)
+++ plugins/trunk/sitemap/templates/pluginsettings.template 2005-06-24 23:08:46 UTC (rev 2271)
@@ -0,0 +1,31 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=sitemapPluginSettings title=$locale->tr("sitemap_plugin")}
+<form name="sitemapPluginSettings" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("label_configuration")}</legend>
+ {include file="$admintemplatepath/successmessage.template"}
+ {include file="$admintemplatepath/errormessage.template"}
+ <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")}
+ </div>
+ </div>
+
+ <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")}
+ </div>
+ </div>
+
+ </fieldset>
+
+ <div class="buttons">
+ <input type="hidden" name="op" value="sitemapPluginUpdateSettings" />
+ <input type="reset" name="{$locale->tr("reset")}" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
More information about the pLog-svn
mailing list