[pLog-svn] r1152 - plugins/trunk/blogtimes

mark at devel.plogworld.net mark at devel.plogworld.net
Mon Feb 21 07:54:20 GMT 2005


Author: mark
Date: 2005-02-21 07:54:20 +0000 (Mon, 21 Feb 2005)
New Revision: 1152

Modified:
   plugins/trunk/blogtimes/pluginblogtimes.class.php
   plugins/trunk/blogtimes/readme.txt
Log:
Blogtimes works!! But remaining one issue to solve. I create my own cahce tmp under /tmp/blogtimes/x.
That means when I need to handle this folder by myself, include resetCache() ...:(
This issue also exist in flickr and authimage plugins.

Modified: plugins/trunk/blogtimes/pluginblogtimes.class.php
===================================================================
--- plugins/trunk/blogtimes/pluginblogtimes.class.php	2005-02-21 04:02:43 UTC (rev 1151)
+++ plugins/trunk/blogtimes/pluginblogtimes.class.php	2005-02-21 07:54:20 UTC (rev 1152)
@@ -5,9 +5,6 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
 
-    define( "BLOGTIMES_PATH", "/blogtimes/" );
-    define( "BLOGTIMES_FILE", "blogtimes.png" );
-    
     /**
      * Plugin that offers blogtimes for current blog
      * Original Author: Matt Mullenweg http://photomatt.net
@@ -24,7 +21,10 @@
         var $borderColor;
         var $tickColor;
         var $title;
+        var $width;
+        var $height;
         var $lastDays;
+        var $cacheFolder;
     
         function PluginBlogTimes()
         {
@@ -35,6 +35,9 @@
             $this->desc = "This plugin offers you to show the blogtimes image in your blog.";
   
             $this->prefix = Db::getPrefix();
+            $this->db =& Db::getDb();
+            $config =& Config::getConfig();
+            $this->cacheFolder = $config->getValue('temp_folder');            
             
             $this->locales = Array( "en_UK" , "zh_TW" );
             
@@ -54,6 +57,12 @@
 
 		function register()
 		{
+			$this->cacheFolder = $this->cacheFolder.'/blogtimes/'.$this->blogInfo->getId();
+			if( !File::exists( $this->cacheFolder )) {
+			    $this->log->debug( "creating temporary folder".$this->cacheFolder );
+				File::createDir( $this->cacheFolder );
+			}
+
 		    $blogSettings = $this->blogInfo->getSettings();
 		    $this->pluginEnabled = $blogSettings->getValue( "plugin_blogtimes_enabled" );
 		    $this->backColor = $blogSettings->getValue( "plugin_blogtimes_backcolor" );
@@ -63,6 +72,8 @@
 		    $this->borderColor = $blogSettings->getValue( "plugin_blogtimes_bordercolor" );
 		    $this->tickColor = $blogSettings->getValue( "plugin_blogtimes_tickcolor" );
 		    $this->title = $blogSettings->getValue( "plugin_blogtimes_title" );
+		    $this->width = $blogSettings->getValue( "plugin_blogtimes_width" );
+		    $this->height = $blogSettings->getValue( "plugin_blogtimes_height" );
 		    $this->lastDays = $blogSettings->getValue( "plugin_blogtimes_lastdays" );
 	    }
 	    
@@ -71,47 +82,49 @@
 	        return $this->pluginEnabled;
 	    }        
 
-        function show($title='Blog Post Times', $last_x_days = 30) {
-   			$rg = new RequestGenerator();
-            $this->updateBlogTimePNG($last_x_days, 480, 65, 5, 5, 1, $title);
-            $blogtimesTag = "<div align=\"center\"><img src=\"".$rg->getUrl( BLOGTIMES_PATH.BLOGTIMES_FILE)."\" /></div>";
+        function show() {
+            $saveFile = $this->cacheFolder."/blogtimes.png";
+   			$rg =& RequestGenerator::getRequestGenerator( $this->blogInfo );
+            $this->updateBlogTimePNG();
+            $blogtimesTag = "<div align=\"center\"><img src=\"".$rg->getUrl($saveFile)."\" /></div>";
             return $blogtimesTag;                    
         }
         
-        function updateBlogTimePNG($last_x_days = 30,
-                                   $width = 480, $height = 65, $horzpadding = 5, $vertpadding = 5,
-                                   $show_ticks = 1,
-                                   $title = "Blog Post Times")
+        function updateBlogTimePNG()
         {
-        	if (!$saveFile) $saveFile = PLOG_CLASS_PATH . BLOGTIMES_PATH . BLOGTIMES_FILE;
+        	$saveFile = $this->cacheFolder."/blogtimes.png";  
+            
             // constants defining image
-            $fontheight = ImageFontHeight(2);
-            $fontwidth  = ImageFontWidth(2);
-            $monthtext = "Last $last_x_days days";
-            $unitname = "hour of day";
-            $show_units = 1;
-        
+            $width = $this->width;
+            $height = $this->height;
+            $title = $this->title;
+            $lastDays = $this->lastDays;
+            $fontHeight = ImageFontHeight(2);
+            $fontWidth  = ImageFontWidth(2);
+            $horzPadding = 5;
+            $vertPadding = 5;
+            $footerText = "Last $lastDays days";
+            $unitText = "Hour of Day";
+            
             // create the basic image
-            $im = @ImageCreate ($width, $height)
-               or die ('Cannot create a new GD image.');
+            $im = @ImageCreate ($width, $height) or die ('Cannot create a new GD image.');
         
-            // generate some colors, format: RED, GREEN, BLUE
-            $white      = ImageColorAllocate ($im, 255,255,255);
-            $black      = ImageColorAllocate ($im, 0,0,0);
-            $beige      = ImageColorAllocate ($im, 238,238,238);
-            $blue       = ImageColorAllocate ($im, 102,102,102);
-            $silver     = ImageColorAllocate ($im, 0xE0,0xE0,0xE0);
-        
             // define what color to use where
-            $back_color = $white;    # this is background of entire image (text & all)
-            $box_color  = $blue;     # this is background of just the posts box
-            $text_color = $black;
-            $line_color = $white;    # this is color of lines for each post
-            $border_color = $blue;
-            $tick_color = $blue;
-        
+            $color = $this->convertToHexRGB($this->backColor);
+            $backColor = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+            $color = $this->convertToHexRGB($this->boxColor);
+            $boxColor  = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+            $color = $this->convertToHexRGB($this->textColor);
+            $textColor = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+            $color = $this->convertToHexRGB($this->lineColor);
+            $lineColor = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+            $color = $this->convertToHexRGB($this->borderColor);
+            $borderColor = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+            $color = $this->convertToHexRGB($this->tickColor);
+            $tickColor = ImageColorAllocate($im, $color['R'], $color['G'], $color['B']);
+
             # query the db and build the list
-            $posttimes = $this->getPostTimes($last_x_days);
+            $postTimes = $this->getPostTimes($lastDays);
         
             # calculate how many intervals to show
             $intervals = floor( ($width / 40) );
@@ -125,23 +138,24 @@
             else $i_mod = 24;
         
             # fill the image with the background color
-            ImageFill($im, 0, 0, $back_color);
+            ImageFill($im, 0, 0, $backColor);
         
             # create a filled  rectangle with a solid border
-            $left = $horzpadding; $right = $width - $horzpadding;
-            $top = $fontheight + $vertpadding;
-            $bottom = $height - $vertpadding - $fontheight;
+            $left = $horzPadding; 
+            $right = $width - $horzPadding;
+            $top = $fontHeight + $vertPadding;
+            $bottom = $height - $vertPadding - $fontHeight;
         
-            if ($show_units)
-                $bottom -= $fontheight;
+            // Show Unit of Measure
+            $bottom -= $fontHeight;
         
-            ImageFilledRectangle($im, $left,$top,$right,$bottom, $box_color);
-            ImageRectangle($im, $left,$top,$right,$bottom, $border_color);
+            ImageFilledRectangle($im, $left,$top,$right,$bottom, $boxColor);
+            ImageRectangle($im, $left,$top,$right,$bottom, $borderColor);
         
             # write title and monthtext
-            ImageString($im, 2, $left, 0, $title,$text_color);
-            $txtwidth = strlen($monthtext) * $fontwidth;
-            ImageString($im, 2, $right - $txtwidth, 0,$monthtext,$text_color);
+            ImageString($im, 2, $left, 0, $title, $textColor);
+            $txtWidth = strlen($footerText) * $fontWidth;
+            ImageString($im, 2, $right - $txtWidth, 0, $footerText, $textColor);
         
             # add the legend on the bottom
             for ($i = 0; $i <= 23; $i=$i+1)
@@ -152,52 +166,49 @@
                     if ($i > 9) {$strX = $curX - 5;}
                     else        {$strX = $curX - 2;}
         
-                    ImageString($im, 2, $strX , $bottom, $i, $text_color);
-                    if ($show_ticks)
-                        ImageLine($im, $curX, $bottom, $curX, $bottom - 5, $tick_color);
+                    ImageString($im, 2, $strX , $bottom, $i, $textColor);
+                    // Show Ticks
+                    ImageLine($im, $curX, $bottom, $curX, $bottom - 5, $tickColor);
                 }
             }
-            ImageString($im, 2, $right - 5, $bottom,  0, $text_color);
-            if ($show_units) {
-                $curX = ($right + $left) / 2 - ($fontwidth * strlen($unitname)/2);
-                $curY = $bottom + $fontheight + 2;
-                ImageString($im, 2, $curX, $curY, $unitname, $text_color);
-            }
+            ImageString($im, 2, $right - 5, $bottom,  0, $textColor);
+            
+            // Show Unit of Measure
+            $curX = ($right + $left) / 2 - ($fontWidth * strlen($unitText)/2);
+            $curY = $bottom + $fontHeight + 2;
+            ImageString($im, 2, $curX, $curY, $unitText, $textColor);
         
             # now we draw the lines for each post
             # the post times should be in terms of # of minutes since midnight
-            $arrcount = count($posttimes);
-            for ($i = 0; $i < $arrcount; $i++)
+            $arrCount = count($postTimes);
+            for ($i = 0; $i < $arrCount; $i++)
             {
                 # make sure postTime is between 0 and 1439
-                $curPostTime = abs($posttimes[$i]) % 1440; 
+                $curPostTime = abs($postTimes[$i]) % 1440; 
                 
                 # calculate the horz pos inside box              
                 $curX = $left + ($right - $left)/1440 * $curPostTime;    # 1440 minutes per day
         
                 # draw the post line
-                ImageLine($im, $curX, $bottom, $curX, $top, $line_color);
+                ImageLine($im, $curX, $bottom, $curX, $top, $lineColor);
             }
         
             # save the file to disk in PNG format 
-            ImageColorTransparent($im, $back_color);
+            ImageColorTransparent($im, $backColor);
             ImagePNG ($im,$saveFile);
         }
         
         # This function will query the db for all the posts in last x days
         # and build an array of # of minutes since midnight for each post
-        function getPostTimes($last_x_days = 30)
+        function getPostTimes($lastDays = 30)
         {
-            $config = new Config();
-            $prefix = $config->getValue('db_prefix');
             $blogId = $this->blogInfo->getId();
 
-        	$query = "SELECT HOUR(date)*60+MINUTE(date) AS totmins FROM ".$prefix."articles";
-        	$query .= " WHERE blog_id = ".$blogId." AND status = 'PUBLISHED'";
-           	$query .= " AND (TO_DAYS(CURRENT_DATE) - TO_DAYS(date)) <= '$last_x_days'";
+        	$query = "SELECT HOUR(date)*60+MINUTE(date) AS totmins FROM ".$this->prefix."articles";
+        	$query .= " WHERE blog_id = ".$blogId." AND status = 1";
+           	$query .= " AND (TO_DAYS(CURRENT_DATE) - TO_DAYS(date)) <= '$lastDays'";
             $query .= " ORDER BY date ASC";
 
-            $this->connectDb();
             $result = $this->db->Execute( $query );
 
             if( !$result )
@@ -210,6 +221,17 @@
             
             return $postTimes;
         }
-
+        
+        function convertToHexRGB( $colorCode )
+        {
+            sscanf($colorCode, "#%2x%2x%2x", $red, $green, $blue);
+            
+            $color = Array();
+            $color['R'] = $red;
+            $color['G'] = $green;
+            $color['B'] = $blue;
+            
+            return $color;
+        }
     }
 ?>
\ No newline at end of file

Modified: plugins/trunk/blogtimes/readme.txt
===================================================================
--- plugins/trunk/blogtimes/readme.txt	2005-02-21 04:02:43 UTC (rev 1151)
+++ plugins/trunk/blogtimes/readme.txt	2005-02-21 07:54:20 UTC (rev 1152)
@@ -1,6 +1,28 @@
-Plugin: Blog Times
+Plugin: Article Referers
 Author: Mark Wu
 Release Date: 2005/01/23
 Version: 1.0
 
-Under Development
\ No newline at end of file
+This plugin offers you to get the referers of the specific article. Usage as followed:
+
+You can use:
+1. $articlereferers->isEnabled() to check the plugin is enabled or not. 
+2. $articlereferers->getArticleReferers( $articleId, $maxReferers , $sortByField ) to get the article referers. 
+
+Where:
+1. $articleId is the specific ariticle id
+2. $maxReferers is the the max referers you want to show. 0 means show all referers. Default is 10.
+3. $sortByField is the order of referers. 1 means sort by hits, and 2 means order by last visit date. Default is 1 
+
+Example:
+Add the following code to postandcomments.template:
+{if $articlereferers->isEnabled()}
+<p>
+<h3>{$locale->tr("referers")}</h3>
+{assign var=postid value=$post->getId()}
+{assign var=referers value=$articlereferers->getArticleReferers($postid)}
+{foreach from=$referers item=referer}
+<li><a href="{$referer->getUrl()}">{$referer->getUrl()|truncate:60:"..."|escape}</a> ({$referer->getCount()})</li>
+{/foreach}
+</p>
+{/if}
\ No newline at end of file




More information about the pLog-svn mailing list