Please note that these files do not function under PHP5 without major modifications.

For future reference, please be aware of the following:

  1. While these directions are intended for the use of those using Fahim Farook's Blog, these scripts can be adapted to any blog format but that is outside the scope of this document.
  2. Blog.php (file created by Blog with your current blog entries) is located in the blog directory "/blog" (url would be www.somesite.com/blog).  Note that the only requirement is that you know exactly where the files are stored.
  3. The files comments.php and annotate.php are located in the blog directory "/blog".
  4. Comment files are stored in the "/blog/archive/comments/" directory.
  5. The directory where the files will be stored must be write enabled (chmod 775).
  6. The page containing your blog entries must have a php extension so the PHP code will be processed.
  7. Your web server should support PHP4.
  8. These scripts will run under PHP3 but that is beyond the scope of this document.
  9. I did not create these scripts but merely modified those found here.  The original script uses javascript which I have replaced with the target attribute of the A HREF tag.

Place the following function in the head of blog.php.  This function counts the number of comments in any given comments file.

<?php
	function countlines($list,$ctr) {
		clearstatcache();	
		if (file_exists($list)) {
			$lines = file($list);
			while(list($key, $val) = each($lines))	{
				if (stristr ($val, "<!-- comment -->")){
					$ctr++;
				}
			}
		}
		if ($ctr > 0) return("[".$ctr."]");
	}
?>
		

The next portion is a complicated looking A HREF tag.  While it's complicated looking, it's fairly easy to use, note that I've stripped out all the optional attributes for this tag.  The href attribute points to my comments.php file (see assumptions 2 and 3 above) and passes it two parameters:  dir and comment.  The dir parameter is the subdirectory that contains my comments directory (see assumption 4 above).  The comment parameter is the name of the comment file, I simply have Blog insert the entry number and use that as the name for my comment file.  Next is the target attribute, this will open a new browser window; note that some users find this annoying so use at your own discretion.  The next portion is the link text "What do you think?" followed by a php script.  The script passes the path to the comment file as a parameter to the countlines function above.

<a 
	href="/blog/comments.php?&amp;dir=archive&&comment=<$BlogID>"target="_comment">
What do you think?
<?php $commentfile = $DOCUMENT_ROOT . 
	"/blog/archive/comments/<$BlogID>.comment"; echo countlines("$commentfile",0); ?>
</a>
		

The heart of this comment system is two files:  comments.txt 1KB and annotate.txt 2KB (you'll want to save the links instead of actually opening them - right click|save as).  They too have configureable parameters but I will only show the lines in question with a line number as they are long and tedious files.  Note that you'll have to change the extension from .txt to .php for these files to actually function (thanks to Greg Miller for pointing out that the original files actually processed instead of simply downloading).

Comments.php sets a cookie on your viewer's computer if they post a comment.  The cookie is not vital to the script and may safely be omitted if you choose.

Comments.php lines 30 and 34 can be changed to whatever title you feel is appropriate.

30  <title>What Do You Think?</title>
.
.
.
34  <h1>What Do You Think?</h1>

Annotate.php lines 18, 24, 30, 38, 44 (the commented comment on 44 MUST remain intact) and the form details can all be edited, but I'll leave that up to you to review as practice in working in PHP.



If you have any problems with these scripts, feel free to contact me.

Rated with ICRA Valid XHTML 1.0! Valid CSS!




Last Modified
16:01 02/11/2008
GMT