Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20836
Modified Files:
index.php serendipity_config.inc.php
serendipity_functions.inc.php comment.php
Log Message:
Preview comments.
Fixed bug that removed ALL cookies when not checking "remember comment
details".
Fixed/Changed the redirection code, made comment posting for article view
easier and avoid the ugly empty window after making a comment. May need some
CSS cleanup.
PLEASE TEST! [works for me on my live-blog]
Index: index.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/index.php,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- index.php 5 Feb 2004 17:38:06 -0000 1.31
+++ index.php 25 Feb 2004 10:50:41 -0000 1.32
@@ -71,6 +71,24 @@
echo $data;
} else if (preg_match('@/(\d+)_\w*\.html@i', $uri, $matches)) {
+ if (!empty($serendipity['POST']['submit'])) {
+ $comment['url'] = $serendipity['POST']['url'];
+ $comment['comment'] = trim($serendipity['POST']['comment']);
+ $comment['name'] = $serendipity['POST']['name'];
+ $comment['email'] = $serendipity['POST']['email'];
+ $comment['subscribe'] = $serendipity['POST']['subscribe'];
+ if (!empty($comment['comment'])) {
+ if (serendipity_saveComment($serendipity['POST']['entry_id'], $comment, 'NORMAL')) {
+ header('Location: ' . $_SERVER['REQUEST_URI'] . (strstr($_SERVER['REQUEST_URI'], '?') ? '&' : '?') . 'serendipity[csuccess]=true');
+ exit;
+ } else {
+ $serendipity['messagestack']['comments'][] = COMMENT_NOT_ADDED;
+ }
+ } else {
+ $serendipity['messagestack']['comments'][] = sprintf(EMPTY_COMMENT, '', '');
+ }
+ }
+
header('Content-Type: text/html; charset=ISO-8859-1');
$id = $matches[1];
@@ -80,6 +98,8 @@
$_GET['serendipity']['action'] = 'read';
$_GET['serendipity']['id'] = $id;
+ serendipity_rememberComment();
+
$title = serendipity_db_query("SELECT title FROM {$serendipity['dbPrefix']}entries " .
'WHERE id=' . serendipity_db_escape_string($id), true);
$title = $title[0];
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- serendipity_config.inc.php 16 Feb 2004 08:58:55 -0000 1.51
+++ serendipity_config.inc.php 25 Feb 2004 10:50:41 -0000 1.52
@@ -11,9 +11,10 @@
include_once('compat.php');
ini_set('session.use_trans_sid', 0);
-$serendipity['version'] = '0.5.1-CVS';
-$serendipity['production'] = 1;
-$serendipity['rewrite'] = 'none';
+$serendipity['version'] = '0.5.1-CVS';
+$serendipity['production'] = 1;
+$serendipity['rewrite'] = 'none';
+$serendipity['messagestack'] = array();
if ( $serendipity['production'] == 1 ) {
error_reporting(E_ALL & ~E_NOTICE);
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.215
retrieving revision 1.216
diff -u -d -r1.215 -r1.216
--- serendipity_functions.inc.php 23 Feb 2004 07:27:44 -0000 1.215
+++ serendipity_functions.inc.php 25 Feb 2004 10:50:41 -0000 1.216
@@ -204,28 +204,27 @@
?>
<div class="serendipityCommentForm">
- <form <?php echo ($serendipity['XHTML11'] ? 'id' : 'name'); ?>="serendipity_comment" action="<?php echo $serendipity['serendipityHTTPPath']; ?>comment.php" method="post" onsubmit="if (this.serendipity_remember.checked) rememberMe(this, '<?php echo $_SERVER['HTTP_HOST']; ?>')">
+ <form <?php echo ($serendipity['XHTML11'] ? 'id' : 'name'); ?>="serendipity_comment" action="?" method="post" onsubmit="if (this.serendipity_remember.checked) rememberMe(this, '<?php echo $_SERVER['HTTP_HOST']; ?>')">
<div><input type="hidden" name="serendipity[entry_id]" value="<?php echo $id; ?>" /></div>
-
<table border="0" width="100%" cellpadding="3">
<tr>
<td class="serendipity_commentsLabel"><?php echo NAME; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[name]" value="<?php echo $serendipity['COOKIE']['name'] ; ?>" size="30" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[name]" value="<?php echo ($serendipity['POST']['name'] ? $serendipity['POST']['name'] : $serendipity['COOKIE']['name']); ?>" size="30" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo EMAIL; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[email]" value="<?php echo $serendipity['COOKIE']['email'] ; ?>" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[email]" value="<?php echo ($serendipity['POST']['email'] ? $serendipity['POST']['email'] : $serendipity['COOKIE']['email']); ?>" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo HOMEPAGE; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[url]" value="<?php echo $serendipity['COOKIE']['url'] ; ?>" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[url]" value="<?php echo ($serendipity['POST']['url'] ? $serendipity['POST']['url'] : $serendipity['COOKIE']['url']); ?>" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo COMMENT; ?></td>
- <td class="serendipity_commentsValue"><textarea rows="10" cols="40" name="serendipity[comment]"></textarea></td>
+ <td class="serendipity_commentsValue"><textarea rows="10" cols="40" name="serendipity[comment]"><?php echo $serendipity['POST']['comment']; ?></textarea></td>
</tr>
<tr>
<td> </td>
@@ -235,7 +234,7 @@
if ($serendipity['allowSubscriptions']) {
?>
<br />
- <input id="checkbox_subscribe" type="checkbox" name="serendipity[subscribe]" /><label for="checkbox_subscribe"> <?php echo SUBSCRIBE_TO_THIS_ENTRY; ?></label>
+ <input id="checkbox_subscribe" type="checkbox" name="serendipity[subscribe]" <?php echo ($serendipity['POST']['subscribe'] ? 'checked="checked"' : ''); ?> /><label for="checkbox_subscribe"> <?php echo SUBSCRIBE_TO_THIS_ENTRY; ?></label>
<?php
}
?>
@@ -243,7 +242,7 @@
</tr>
<tr>
<td> </td>
- <td><input type="submit" value="<?php echo SUBMIT_COMMENT; ?>" /></td>
+ <td><input type="submit" name="serendipity[submit]" value="<?php echo SUBMIT_COMMENT; ?>" /> <input type="submit" name="serendipity[preview]" value="<?php echo PREVIEW; ?>" /></td>
</tr>
</table>
</form>
@@ -255,24 +254,42 @@
global $serendipity;
setcookie("serendipity[$name]", $value, time()+60*60*24*30, $serendipity['serendipityHTTPPath']);
$_COOKIE[$name] = $value;
+ $serendipity['COOKIE'][$name] = $value;
}
function serendipity_deleteCookie($name) {
setcookie("serendipity[$name]", '', time()-4000);
unset($_COOKIE[$name]);
+ unset($serendipity['COOKIE'][$name]);
+}
+
+function serendipity_rememberComment() {
+ if (isset($serendipity['POST']['remember'])) {
+ serendipity_rememberCommentDetails(
+ array(
+ 'url' => $serendipity['POST']['url'],
+ 'name' => $serendipity['POST']['name'],
+ 'email' => $serendipity['POST']['email'],
+ 'remember' => 'checked="checked"'
+ )
+ );
+ } elseif (isset($serendipity['POST']['comment'])) {
+ serendipity_forgetCommentDetails(array('url', 'name', 'email'));
+ }
}
function serendipity_rememberCommentDetails($details) {
- foreach ( $details as $n=>$v ) {
+ foreach ($details as $n => $v) {
serendipity_setCookie($n, $v);
}
}
-function serendipity_forgetCommentDetails() {
+function serendipity_forgetCommentDetails($keys) {
global $serendipity;
- if(!$serendipity['COOKIE']) {
+ if (!$serendipity['COOKIE']) {
return;
}
- foreach ($serendipity['COOKIE'] as $n => $v) {
+
+ foreach ($keys AS $n) {
serendipity_deleteCookie($n);
}
}
@@ -859,9 +876,37 @@
echo '<div align="center" style="color: #FF0000; font-weight: bold;">'. sprintf(UNSUBSCRIBE_OK, urldecode($res[1])) .'</div><br />';
}
-
echo serendipity_printComments(serendipity_fetchComments($entry['id']), (isset($entry['allow_comments']) ? $entry['allow_comments'] : true));
- if (serendipity_db_bool($entry['allow_comments']) || !isset($entry['allow_comments'])) {
+
+ if (!empty($serendipity['POST']['preview'])) {
+ serendipity_printComments(
+ array(
+ array(
+ 'email' => $serendipity['POST']['email'],
+ 'author' => $serendipity['POST']['name'],
+ 'body' => $serendipity['POST']['comment'],
+ 'url' => $serendipity['POST']['url'],
+ 'timestamp' => time()
+ )
+ ),
+ false,
+ false
+ );
+ }
+
+ if (isset($serendipity['messagestack']['comments'])) {
+?>
+ <br />
+ <div class="serendipity_commentsTitle"><?php echo implode('<br />', $serendipity['messagestack']['comments']); ?></div>
+<?php
+ }
+
+ if ($serendipity['GET']['csuccess'] == 'true') {
+?>
+ <br />
+ <div class="serendipity_commentsTitle"><?php echo COMMENT_ADDED; ?></div>
+<?php
+ } elseif (serendipity_db_bool($entry['allow_comments']) || !isset($entry['allow_comments'])) {
?>
<br />
<div class="serendipity_commentsTitle"><?php echo ADD_COMMENT; ?></div>
@@ -993,7 +1038,7 @@
return $comments;
}
-function serendipity_printComments($comments, $allow_comments = true)
+function serendipity_printComments($comments, $allow_comments = true, $show_admin = true)
{
global $serendipity;
?>
@@ -1024,21 +1069,21 @@
<a href="#c<?php echo $comment['id']; ?>" title="<?php echo LINK_TO_COMMENT . $x; ?>">#<?php echo $x ; ?></a>
<?php
/* Link to the user's email */
- if ( !empty($comment['email']) ) {
+ if (!empty($comment['email'])) {
echo '<a href="mailto:' . htmlentities($comment['email']) . '" title="' . SEND_MAIL_TO . ' ' . htmlentities($name) . ' (' . $comment['email'] . ')">' . htmlentities($name) . '</a>';
} else {
echo htmlentities($name);
}
/* Link to the user's website, if the URL is valid */
- if ( $comment['type'] != 'trackback' && !empty($comment['url']) && $comment['url'] != 'http://' && eregi('^http://', $comment['url']) ) {
+ if ($comment['type'] != 'trackback' && !empty($comment['url']) && $comment['url'] != 'http://' && eregi('^http://', $comment['url'])) {
echo ' (<a href="' . str_replace('"', '"', $comment['url']) . '" ' . serendipity_xhtml_target('_blank') . ' title="' . htmlentities($comment['url']) . '">Link</a>)';
}
/* Show when the entry was made */
echo ' ' . ON . ' ' . ucfirst(strftime('%b %e %Y, %H:%M', $comment['timestamp']));
- if ($_SESSION['serendipityAuthedUser'] === true) {
+ if ($show_admin && $_SESSION['serendipityAuthedUser'] === true) {
echo ' (<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[delete]=' . $comment['id'] . '&serendipity[entry]=' . $comment['entry_id'] . '&serendipity[type]=comments">' . DELETE . '</a>)';
}
?>
@@ -1049,7 +1094,7 @@
<?php
}
- if ($_SESSION['serendipityAuthedUser'] === true) {
+ if ($show_admin && $_SESSION['serendipityAuthedUser'] === true) {
if (serendipity_db_bool($allow_comments)) {
echo '<div class="serendipity_comment_source">(<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[switch]=disable&serendipity[entry]=' . $comment['entry_id'] . '">' . COMMENTS_DISABLE . '</a>)</div>';
} else {
Index: comment.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/comment.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- comment.php 2 Feb 2004 08:39:40 -0000 1.28
+++ comment.php 25 Feb 2004 10:50:41 -0000 1.29
@@ -13,18 +13,7 @@
serendipity_allowCommentsToggle($serendipity['GET']['entry'], $serendipity['GET']['switch']);
}
-/* It's time to finally check if we need to remember the entered information,
- the reason we are doing this up here, is because we want to send cookie-headers */
-if ( isset($serendipity['POST']['remember']) ) {
- $details['url'] = $serendipity['POST']['url'];
- $details['name'] = $serendipity['POST']['name'];
- $details['email'] = $serendipity['POST']['email'];
- $details['remember'] = 'checked';
- serendipity_rememberCommentDetails($details);
-} elseif ( isset($serendipity['POST']['comment']) ) {
- serendipity_forgetCommentDetails();
-}
-
+serendipity_rememberComment();
if (!($type = @$_REQUEST['type'])) {
$type = 'normal';
@@ -51,7 +40,8 @@
report_pingback_failure();
}
} else {
- $id = $serendipity['GET']['entry_id'];
+ $id = (!empty($serendipity['POST']['entry_id']) ? $serendipity['POST']['entry_id'] : $serendipity['GET']['entry_id']);
+
$html_header = '';
if ($serendipity['XHTML11']) {
@@ -69,14 +59,14 @@
if (isset($_GET['success']) && $_GET['success'] == 'true') {
echo $html_header;
printf(
- COMMENT_ADDED,
+ COMMENT_ADDED . COMMENT_ADDED_CLICK,
- '<a href="' . $_GET['url'] . '">',
+ '<a href="' . $_GET['url'] . '&serendipity[entry_id]=' . $_GET['entry_id'] . '">',
'</a>',
'<a href="#" onclick="self.close()">',
'</a>'
);
- } else if (!isset($serendipity['POST']['comment'])) {
+ } else if (!isset($serendipity['POST']['submit'])) {
echo $html_header;
if ($serendipity['GET']['type'] == 'trackbacks') {
$tbu = $serendipity['baseURL'] . 'comment.php?type=trackback&entry_id=' . $serendipity['GET']['entry_id'];
@@ -107,9 +97,24 @@
serendipity_printComments(serendipity_fetchComments($id), (isset($ca['allow_comments']) ? $ca['allow_comments'] : true));
+ if ($serendipity['POST']['preview']) {
+ serendipity_printComments(
+ array(
+ array(
+ 'email' => $serendipity['POST']['email'],
+ 'author' => $serendipity['POST']['name'],
+ 'body' => $serendipity['POST']['comment'],
+ 'url' => $serendipity['POST']['url'],
+ 'timestamp' => time()
+ )
+ ),
+ false,
+ false
+ );
+ }
+
if (serendipity_db_bool($ca['allow_comments']) || !is_array($ca)) {
?>
-
<div class="serendipity_commentsTitle"><?php echo ADD_COMMENT; ?></div>
<?php
serendipity_displayCommentForm($id);
@@ -121,14 +126,14 @@
$comment['name'] = $serendipity['POST']['name'];
$comment['email'] = $serendipity['POST']['email'];
$comment['subscribe'] = $serendipity['POST']['subscribe'];
- if ( !empty($comment['comment']) ) {
+ if (!empty($comment['comment'])) {
if (serendipity_saveComment($serendipity['POST']['entry_id'], $comment, 'NORMAL')) {
- header('Location: ' . $serendipity['baseURL'] . 'comment.php?success=true&url=' . urlencode($_SERVER['HTTP_REFERER']));
+ header('Location: ' . $serendipity['baseURL'] . 'comment.php?entry_id=' . $serendipity['POST']['entry_id'] . '&success=true&url=' . urlencode($_SERVER['HTTP_REFERER']));
exit;
} else {
echo $html_header;
printf(
- COMMENT_NOT_ADDED,
+ COMMENT_NOT_ADDED . COMMENT_NOT_ADDED_CLICK,
'<a href="' . $_SERVER['HTTP_REFERER'] . '">',
'</a>',
|