|
From: mdw c. <myd...@li...> - 2001-09-20 21:24:17
|
MyDynaWeb CVS committal
Author : sukria
Project : mydynaweb
Module : htdocs
Dir : mydynaweb/htdocs
Modified Files:
add_comment.php comment.php save_coment.php
Log Message:
Adding a new little feature whiwh is asking guest for name and email when posting a comment on a news.
MDW then store the values (name & email) into a cookie and use them for next submission.
When displaying the comment, guest's name is displayed whith a link on his email.
BE CARREFUL :
There is a DB upgrade to do, on the comments table : we must add the field user_mail.
Launch sql/db_upgrade/from-0.3.5__to-0.3.6/alter-comments.sql on your db after cvs updating...
enjoy:)
Alexis.
===================================================================
RCS file: /cvsroot/mydynaweb/mydynaweb/htdocs/add_comment.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- add_comment.php 2001/06/08 23:45:20 1.2
+++ add_comment.php 2001/09/20 21:23:47 1.3
@@ -17,6 +17,12 @@
$UserID = 'anonymous';
}
+if (isset($DYNA_USER)) {
+ $frags = explode("__", $DYNA_USER);
+ $username = $frags[0];
+ $usermail = $frags[1];
+}
+
// we get every comment posted for that news (for creating the reply listbox)
$sql = "SELECT title
FROM comments
@@ -52,14 +58,23 @@
<input type='hidden' name='num_news' value='$num_news'>
-<table align=\"center\" width=\"480\" cellpadding=0 cellspacing=0 border=0>
+<table align=\"center\" width=\"480\" cellpadding=0 cellspacing=5 border=0>
+<tr>
+ <td align=\"left\"> ".translate("TITLE",$DBH)." : <input name=\"titre\" type=\"text\" size=\"30\">
+ </td>
+</tr>
<tr>
- <td align=\"left\"> <b>".translate("TITLE",$DBH)."</b> : <input name=\"titre\" type=\"text\" size=\"30\">
+ <td align=\"left\"> ".translate("YOUR_NAME",$DBH)." : <input name=\"username\" type=\"text\" value='$username' size=\"30\">
</td>
</tr>
<tr>
+ <td align=\"left\"> ".translate("YOUR_EMAIL",$DBH)." : <input name=\"usermail\" type=\"text\" value='$usermail' size=\"30\">
+ </td>
+</tr>
+
+<tr>
<td align=\"left\">
- <b>".translate('CHOOSE_REPLY', $DBH)."$REPLY_LIST
+ ".translate('CHOOSE_REPLY', $DBH)."$REPLY_LIST
</td>
</tr>
@@ -67,7 +82,7 @@
<tr>
<td>
- <b>".translate('COMMENT_HEAD', $DBH)."</b><br>
+ ".translate('COMMENT_HEAD', $DBH)."<br>
<textarea name=\"content\" wrap=\"virtual\" cols=\"50\" rows=\"20\"></textarea>
<br>
</td>
===================================================================
RCS file: /cvsroot/mydynaweb/mydynaweb/htdocs/comment.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- comment.php 2001/08/13 14:21:31 1.7
+++ comment.php 2001/09/20 21:23:47 1.8
@@ -37,7 +37,10 @@
// we get the comments
-$sql = "select title, content, user_name, date_ins from comments where _num_news = $news order by num_cmt desc";
+$sql = "select title, content, user_name, user_mail, date_ins
+ from comments
+ where _num_news = $news
+ order by num_cmt desc";
$rqt = new query($DBH);
$rqt->query($DBH, $sql);
@@ -50,8 +53,6 @@
$row['user_name'] = 'anonymous';
}
- $row["user"] = $row['user_name'];
-
$PAGE .= get_template(THEMES_PATH."/comment.html", $row);
}
===================================================================
RCS file: /cvsroot/mydynaweb/mydynaweb/htdocs/save_coment.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- save_coment.php 2001/08/13 14:24:55 1.6
+++ save_coment.php 2001/09/20 21:23:47 1.7
@@ -13,10 +13,17 @@
die();
}
- $aujourdhui = date( "Y-m-d", time() );
+
+// we store the name and the email of the surfer into a cookie
+if (!isset($DYNA_USER)) {
+ setcookie('DYNA_USER', ($username . "__" . $usermail), (time() + 60*60*24*365), '/');
+}
+
+
+$aujourdhui = date( "Y-m-d", time() );
- // we block HTML attacks (like </table> or such a HTML tag that could be bad)
+// we block HTML attacks (like </table> or such a HTML tag that could be bad)
$titre = ereg_replace("<", "<",$titre);
$titre = ereg_replace(">", ">",$titre);
@@ -43,8 +50,8 @@
// we insert the comment in the database
- $sql = "insert into comments (title, _num_news, date_ins, content, user_name)
- values ('$titre', $num_news, '$aujourdhui', '$content', '$UserID')";
+ $sql = "insert into comments (title, _num_news, date_ins, content, user_name, user_mail)
+ values ('$titre', $num_news, '$aujourdhui', '$content', '$username', '$usermail')";
$rqt = new query($DBH);
$rqt->query($DBH, $sql) or die($sql . $rqt->error());
|