Location: PHPKode > projects > Anantasoft Gazelle CMS > comments.php
<?php
// commenting functionality on articles
$comments = "";
if ($article == 1) { // we're seeing an article, so we can show the comments and the add comment form
	if ($content{'allowcomments'} == 1) { // comments are allowed
		if (!empty($_POST) && !isset($_POST["loginform"])) {
			if (isset($_POST["number"]) && $_POST["number"]) {
				include_once("admin/sql/delete.php"); // remove comment (only admin can do)
			} else {
				include_once("admin/sql/insert.php"); // add comment (registered users with permissions to see article can post)
			}
		}
		$comments = "<a name=\"comments\"></a><div class=\"commentscontainer\">";
		$commentscounter = 0;
		$showcommentsper = 10;
		$page = 1;
		if (isset($_GET) && isset($_GET["page"]) && $_GET["page"]) {
			$page = $_GET["page"];
		}
		$even = "even";
		$allcomments = mysql_query("select number, user, content, time from ".$tableprefix."comments where parent='".$content{'number'}."' order by number desc");
		while ($comm = mysql_fetch_array($allcomments, MYSQL_ASSOC)) {
			$commentscounter++; // show only X comments per page
			if ($even == "even") { // make even/odd class, so they can be styled differently
				$even = "odd";
			} else {
				$even = "even";
			}
			$allusers = mysql_query("select name from ".$tableprefix."users where number='".$comm{'user'}."'");
			while ($usr = mysql_fetch_array($allusers, MYSQL_ASSOC)) {
				if (($commentscounter >= ($page*$showcommentsper-$showcommentsper + 1) && $commentscounter <= $page * $showcommentsper) || $showcommentsper == 0) {
					$comments = $comments."<div class=\"comment ".$even."\"><div class=\"commentuser\">Posted by <a href=\"user.php?user=".$usr{'name'}."\">".$usr{'name'}."</a> on ".date('Y-m-d (H:i)', strtotime($comm{'time'})).":</div><div class=\"commentcontent\">".$comm{'content'}."</div></div>"; // show the comment
					if ($auth[2] == 1) { // user is admin, add a 'delete comment' button
						$comments = $comments."<form method=\"post\" action=\"".$curpage."\"><fieldset>
							<input type=\"submit\" name=\"save\" value=\"Delete\" class=\"button\" />
							<input type=\"hidden\" name=\"table\" value=\"comments\" />
							<input type=\"hidden\" name=\"number\" value=\"".$comm{'number'}."\" />
							</fieldset></form>";
					}
				}
			}
		}
		$pagecontrol = "";
		if ($commentscounter > $showcommentsper && $showcommentsper <> 0) {
			if ($page == 1) { // first
				$pagecontrol .= "<span>&lt;&lt;</span>";
			} else {
				$pagecontrol .= "<span><a href=\"".$curpage."&amp;page=1\">&lt;&lt;</a></span>";
			}
			if ($page == 1) { // previous
				$pagecontrol .= "<span>&lt;</span>";
			} else {
				$pagecontrol .= "<span><a href=\"".$curpage."&amp;page=".($page-1)."\">&lt;</a></span>";
			}
			for ($pages = 0; $pages < ceil($commentscounter / $showcommentsper); $pages++) { // pagenumbers
				if ($pages + 1 == $page) {
					$pagecontrol .= "<span>".($pages + 1)."</span>";
				} else {
					$pagecontrol .= "<span><a href=\"".$curpage."&amp;page=".($pages + 1)."\">".($pages + 1)."</a></span>";
				}
			}
			if ($commentscounter >= ($page * $showcommentsper - $showcommentsper + 1) && $commentscounter <= $page * $showcommentsper) { // next
				$pagecontrol .= "<span>&gt;</span>";
			} else {
				$pagecontrol .= "<span><a href=\"".$curpage."&amp;page=".($page + 1)."\">&gt;</a></span>";
			}
			if ($page == ceil($commentscounter / $showcommentsper)) { // last
				$pagecontrol .= "<span>&gt;&gt;</span>";
			} else {
				$pagecontrol .= "<span><a href=\"".$curpage."&amp;page=".ceil($commentscounter / $showcommentsper)."\">&gt;&gt;</a></span>";
			}
		}
		if ($pagecontrol) {
			$comments = $comments."<div class=\"pagecontrol\">".$pagecontrol."</div>";
		}
		if (isset($_SESSION["name"]) && $_SESSION["name"]) { // 'add comment'-form
			$allusers = mysql_query("select number from ".$tableprefix."users where name='".$_SESSION["name"]."'");
			while ($usr = mysql_fetch_array($allusers, MYSQL_ASSOC)) {
				$comments = $comments."<div class=\"addcomment\">
				<form id=\"frm\" method=\"post\" action=\"".$curpage."\">
					<fieldset>
						<label for=\"cnt\">Add a comment: </label>
						<textarea id=\"cnt\" name=\"content\" rows=\"7\" cols=\"20\"></textarea>
						<br />
						<br />
						<input type=\"submit\" name=\"save\" value=\"Add\" class=\"button\" />
						<input type=\"hidden\" name=\"table\" value=\"comments\" />
						<input type=\"hidden\" name=\"user\" value=\"".$usr{'number'}."\" />
						<input type=\"hidden\" name=\"parent\" value=\"".$content{'number'}."\" />
						<input type=\"hidden\" name=\"time\" value=\"".date('Y-m-d H:i:s')."\" />
					</fieldset>
				</form></div>";
			}
		} else {
			$comments = $comments."<div class=\"addcomment\"><div class=\"noauth\">Please login to add comments...<br />".$mod_Login."</div></div>";
		}
		$comments = $comments."</div>";
	}
} else { // we're watching the menu, add a link to the comments
	if ($content{'allowcomments'} == 1) {
		$allcomments = mysql_query("select number, user, content, time from ".$tableprefix."comments where parent='".$content{'number'}."' order by number desc");
		$totalcomm = 0;
		while ($comm = mysql_fetch_array($allcomments, MYSQL_ASSOC)) {
			$totalcomm++;
		}
		$comments = "<span class=\"comments\"><a href=\"".str_replace("index.php", "article.php", $curpage)."/".$content{'title'}."#comments\">Comments (".$totalcomm.")</a></span>";
	}
}

return $comments;
?>
Return current item: Anantasoft Gazelle CMS