Add admin comments to guestbook

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
Marko
Posts: 65
Joined: Tue 2. Dec 2003, 23:58
Location: Finland

Add admin comments to guestbook

Post by Marko »

Well, this is actually something I needed and I just re-used Olivers code. I don't really know PHP that well, so I would appreciate if someone a bit nerdier than me could inspect my hacking... :?

Code: Select all

#
#---------------SQL----------------------------------------------------------------
#
ALTER TABLE `phpwcms_guestbook` ADD `guestbook_comment` TEXT AFTER `guestbook_url` ;
OPEN /INCLUDE/INC_ACT/ACT_GUESTBOOK.PHP

Code: Select all

#
#---------------FIND---------------------------------------------------------------
#
if(intval($_GET['del'])) {

	$sql  = "UPDATE ".DB_PREPEND."phpwcms_guestbook SET ";
	$sql .= "guestbook_trashed=9 WHERE guestbook_cid=";
	$sql .= intval($_GET['cid'])." AND guestbook_id=".intval($_GET['del']);
	$sql .= " LIMIT 1;";
	mysql_query($sql, $db);

}

#
#---------------ADD AFTER-------------------------------------------------------
#
if(isset($_POST["add_comment"])) {
		$sql  = "UPDATE ".DB_PREPEND."phpwcms_guestbook SET ";
		$sql .= "guestbook_comment='".getpostvar($_POST['cguestbook_comment'])."' WHERE guestbook_cid=";
		$sql .= intval($_POST['cid'])." AND guestbook_id=".intval($_POST['guestbook_id']);
		mysql_query($sql, $db);
}

#
#---------------FIND---------------------------------------------------------------
#
$sql .= intval($_GET['cid'])." AND guestbook_trashed=0 ORDER BY guestbook_created DESC;";

#
#---------------REPLACE WITH---------------------------------------------------
#
$sql .= intval($_GET['cid'])." AND guestbook_trashed=0 OR guestbook_cid=".intval($_POST['cid'])." AND guestbook_trashed=0 ORDER BY guestbook_created DESC;";

#
#---------------FIND---------------------------------------------------------------
#
if($row['guestbook_msg']) {
echo '<br />'.htmlspecialchars($row['guestbook_msg']);
}

#
#---------------ADD AFTER-------------------------------------------------------
#
	if($row['guestbook_comment']) {
		echo '<br /><form action="act_guestbook.php" method="post"><input type="hidden" name="add_comment" value="10"><input type="hidden" name="cid" value="'.$row['guestbook_cid'].'"><input type="hidden" name="guestbook_id" value="'.$row['guestbook_id'].'"><textarea rows="2" cols="40" name="cguestbook_comment" wrap="VIRTUAL">'.htmlspecialchars($row['guestbook_comment']).'</textarea><input type="image" src="../../img/button/edit_22x11.gif" value="submit"></form>';
	}
	else{
		echo '<br /><form action="act_guestbook.php" method="post"><input type="hidden" name="add_comment" value="1"><input type="hidden" name="cid" value="'.$row['guestbook_cid'].'"><input type="hidden" name="guestbook_id" value="'.$row['guestbook_id'].'"><textarea rows="2" cols="40" name="cguestbook_comment" wrap="VIRTUAL">'.htmlspecialchars($row['guestbook_comment']).'</textarea><input type="image" src="../../img/button/edit_22x11.gif" value="submit"></form>';
	}

SAVE THE FILE AND OPEN /INCLUDE/INC_FRONT/CONTENT/CNT18.ARTICLE.INC.PHP

Code: Select all


#
#---------------FIND---------------------------------------------------------------
#
$guestbook['c'] = str_replace('###URL###', html_specialchars($guestbook['row']['guestbook_url']), $guestbook['c']);

#
#---------------ADD AFTER-------------------------------------------------------
#
$guestbook['c'] = str_replace('###COMMENT###', html_specialchars($guestbook['row']['guestbook_comment']), $guestbook['c']);

$guestbook['comment_replace'] = ($guestbook['row']['guestbook_comment']) ? '<p style="margin-left:20px"><b>$1:</b> '.html_specialchars($guestbook['row']['guestbook_comment']).'</p>' : '';
$guestbook['c'] = preg_replace('/###COMMENT:(.*)###/', $guestbook['comment_replace'], $guestbook['c']);

After this you have to include either one of tags ###COMMENT### or ###COMMENT:html### (html meaning your own heading, just like URL:html tag) to your guestbook-content part section and off you go! You may see working example at http://www.kimifan.com/index.php?guestbook
Last edited by Marko on Tue 18. May 2004, 12:29, edited 3 times in total.
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

cool look forward to test it later today
http://www.studmed.dk Portal for doctors and medical students in Denmark
Post Reply