Location: PHPKode > projects > ZompLog > plugins/mailnotify/plugin.php
<?php
/*
This Zomplog plugin notifies the administrator (or anyone else) when a new post is submitted, or a comment to a post
created by Frank Hoek

version 1.4, March 24th 2007
- I rewrote the coding concerning automatic upgrading

version 1.3, November 12th 2006
 - automatic upgrade
 - strip tags from the post for better presentation in the email

version 1.2, November 11th 2006
 - distinct messages for new post and new comment

www.frankma.nl
*/

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 1. MAIN CONFIGURATION
$plugin_name = "mailnotify"; // note: this should be the same name as the name of the plugin-folder (lowercase)
$plugin_author = "<a href='http://www.frankma.nl' target='_blank'>frankma</a>";
$plugin_description = "this plugin sends an e-mail when a new post is submitted, or a comment to a post";
$this_plugin_version = "1.4";
$plugin_version = $this_plugin_version;

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 2. SHOW UPGRADE TEXT ON SCREEN
$query = "SELECT * FROM $prefix" . "_mailnotify LIMIT 1";
$result = mysql_query($query, $link);
$currentsetting = mysql_fetch_array($result);

// check if this plugin already is installed and display the appropriate text
if  (($result) AND ($currentsetting[version] !== $plugin_version)) {
	if ($currentsetting[version]) {
		$plugin_version = $this_plugin_version." - <strong>you are currently using version ".$currentsetting[version]."; <a href='../plugins/".$plugin_name."/install.php'>if that's an older version, you may now upgrade</a></strong>";
	} else {
		$plugin_version = $this_plugin_version." - <strong>you are currently using an older version; <a href='../plugins/".$plugin_name."/install.php'>you may now upgrade</a></strong>";
	}
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 3. FUNCTIONALITY
// plugins are integrated into Zomplog by using so called 'hooks'
//  NEW ENTRY
// hook this one to admin/newentry.php after a new post has been added; so use hook 'newentry-submit'
if ($hook == "newentry-submit") {
	// but only send a message when a new post is made and processed correctly
	$thename  = htmlspecialchars($_SESSION[login], ENT_QUOTES);            // name of submitter
	$thetitle = htmlspecialchars($_POST[title], ENT_QUOTES);               // title of the post
	$thepost  = strip_tags($_POST[text]);                                  // content of the post, without tags
		$y = substr($date,0,4);                                            // synthesize the postdate
		$m = substr($date,4,2);
		$d = substr($date,6,2);
		$h = substr($date,8,2);
		$min = substr($date,10,2);
	$thepostdate = ($y . "-" . $m . "-" . $d . ", " . $h . ":" . $min);    // the postdate
	// now compose the emailmessage
	$themessage = "
$currentsetting[entrytitle] $thetitle

$currentsetting[post]
$thepost

$currentsetting[name] $thename

$currentsetting[day] $thepostdate
	";
	mail($currentsetting[address],$currentsetting[entrysubj],$themessage); // and send it!
}

//  NEW COMMENT
// hook this one to content.php after the comment has been added (function newComment); so use hook 'blogentry-top'
if ($hook == "blogentry-top") {
	// but only send a message when a new comment is made and processed correctly
	if ($notice) {
		$thename = htmlspecialchars($_POST[name], ENT_QUOTES);             // name of submitter
		$thecomment = htmlspecialchars($_POST[comment], ENT_QUOTES);       // content of the comment
// check that both name and comment are existent, to prevent empty notifications, due to whatever spybot activity on the web
		if (($thename != "") AND ($thecomment != "")) {
			$y = substr($date,0,4);                                        // synthesize the postdate
			$m = substr($date,4,2);
			$d = substr($date,6,2);
			$h = substr($date,8,2);
			$min = substr($date,10,2);
		$thepostdate = ($y . "-" . $m . "-" . $d . ", " . $h . ":" . $min);// the postdate
	// now compose the emailmessage
		$themessage = "
$currentsetting[entrytitle] $entry[title]
		
$currentsetting[comment]
$thecomment
	
$currentsetting[name] $thename

$currentsetting[day] $thepostdate
		";
		mail($currentsetting[address],$currentsetting[commentsubj],$themessage); // and send it!
		}
	}
}

?>
Return current item: ZompLog