[pLog-svn] r3829 - in plugins/trunk/tagcloud: . class/action
pwestbro at devel.lifetype.net
pwestbro at devel.lifetype.net
Tue Aug 1 06:12:51 GMT 2006
Author: pwestbro
Date: 2006-08-01 06:12:50 +0000 (Tue, 01 Aug 2006)
New Revision: 3829
Modified:
plugins/trunk/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php
plugins/trunk/tagcloud/plugintagcloud.class.php
Log:
Changed the tagcloud plugin to not run the query to build the cloud on every
http request, but to do it only when an article is added, deleted or updated.
Modified: plugins/trunk/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php
===================================================================
--- plugins/trunk/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php 2006-07-31 13:21:38 UTC (rev 3828)
+++ plugins/trunk/tagcloud/class/action/plugintagcloudupdateconfigaction.class.php 2006-08-01 06:12:50 UTC (rev 3829)
@@ -76,6 +76,11 @@
$this->_view = new PluginTagCloudConfigView( $this->_blogInfo );
$this->_view->setSuccessMessage( $this->_locale->tr("tagcloud_settings_saved_ok"));
$this->setCommonData();
+
+ $plugins = $this->_pm->getPlugins();
+
+ $plugin = $plugins["tagcloud"];
+ $plugin->createCloud();
// clear the cache
CacheControl::resetBlogCache( $this->_blogInfo->getId());
Modified: plugins/trunk/tagcloud/plugintagcloud.class.php
===================================================================
--- plugins/trunk/tagcloud/plugintagcloud.class.php 2006-07-31 13:21:38 UTC (rev 3828)
+++ plugins/trunk/tagcloud/plugintagcloud.class.php 2006-08-01 06:12:50 UTC (rev 3829)
@@ -9,6 +9,9 @@
class PluginTagCloud extends PluginBase
{
+ var $pluginEnabled;
+ var $cacheFolder;
+
/*
* Constructor
*/
@@ -35,6 +38,13 @@
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 );
+
+
+
$this->registerAdminAction( "tagcloud", "PluginTagCloudConfigAction" );
$this->registerAdminAction( "updateTagCloudConfig", "PluginTagCloudUpdateConfigAction" );
@@ -43,20 +53,74 @@
$this->addMenuEntry( "/menu/controlCenter", "manageAppearancePlugins", "", "", true, false );
$this->addMenuEntry( "/menu/controlCenter/manageAppearancePlugins", "TagCloud", "?op=tagcloud", "" );
}
+
+ function register()
+ {
+ $config =& Config::getConfig();
+ $this->cacheFolder = $config->getValue('temp_folder');
+ $this->cacheFolder = $this->cacheFolder.'/tagcloud/'.$this->blogInfo->getId();
+ if( !File::exists( $this->cacheFolder )) {
+ File::createDir( $this->cacheFolder, 0755 );
+ }
+
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_tagcloud_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();
+
+ // make sure that the plugin is enabled
+ if( !$this->isEnabled())
+ {
+ return true;
+ }
+
+ // Update the Blogtime png
+ $this->createCloud();
+
+ return true;
+ }
+
+
+
/*
* Return cloud of the latest articles
*/
- function getTagCloud(){
+ function createCloud(){
$this->_prefix = Db::getPrefix();
$blogId = $this->blogInfo->getId();
-
+
+
$blogSettings = $this->blogInfo->getSettings();
$pluginEnabled = $blogSettings->getValue( "plugin_tagcloud_enabled" );
if (!$pluginEnabled) {
- return "";
+ return;
}
$MaxArticles = $blogSettings->getValue( "plugin_tagcloud_max_articles" );
@@ -143,6 +207,35 @@
$Cloud .= "<a href=\"{$baseUrl}?searchTerms=$k&op=Search&blogId={$blogId}\" style=\"font-size: {$size}em; font-weight: {$weight}\" title=\"$k\">$k</a> \n";
}
+ $saveFile = $this->cacheFolder."/tagcloud";
+
+ $fh = fopen( $saveFile, "w");
+ if ($fh)
+ {
+ fwrite($fh, $Cloud);
+ fclose($fh);
+ File::chMod($saveFile, 0644);
+ }
+
+ }
+
+ /*
+ * Return cloud of the latest articles
+ */
+ function getTagCloud(){
+
+ $saveFile = $this->cacheFolder."/tagcloud";
+
+ $Cloud = '';
+
+ $fh = fopen( $saveFile, "r");
+ if ($fh)
+ {
+ $Cloud = fread($fh, filesize($saveFile));
+ fclose($fh);
+ }
+
+
return $Cloud;
}
More information about the pLog-svn
mailing list