Add comments modification

skicrave

Joined: 2002-10-25
Posts: 89
Posted: Tue, 2002-12-31 21:49

I've compiled a coupld of modifications that relate to adding comments to a photo.

Included in this mod is the hack by djkammer to only let logged in users add comments. This is a great mod, and really helps increase the community feeling of your site. It also includes the email notification mod to send an email to a user when a comment is left in their gallery.

If you're using this, then there is no reason the user should have to enter their username when commenting, as they must be logged in. The second part of the mod that I've added addresses this. Basically, it gets the logged in users name, and populates the form field automatically when the add_comment.php window is opened.

Here is the code for add_comment.php that I'm currently using:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> <?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2002 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
?>
<?php
// Hack prevention.
if (!empty($HTTP_GET_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_POST_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_COOKIE_VARS["GALLERY_BASEDIR"])) {
print "Security violation
";
exit;
}
?>
<?php require($GALLERY_BASEDIR . "init.php"); ?>
<?php
// Hack check

if (strcmp($gallery->album->fields["public_comments"], "yes")) {
exit;
}

$error_text = "";

if (!strcmp($submit, "Save")) {
if ($commenter_name &amp;&amp; $comment_text) {
$comment_text = removeTags($comment_text);
$text_url = urlencode($text);
$commenter_name = removeTags($commenter_name);
$gallery->album->addComment($index, stripslashes($comment_text), $IPNumber, $commenter_name);
$gallery->album->save();

/*mail for post control of comment in gallery*/
$email_admin="admin@yoursite.com";
$email_postmaster="postmaster@yoursite.com";
$headers="Return-Path: ".$email_postmaster."rn";
$headers="From: MalibuBoatOwners.comrn";
$subject="A comment has been added to your MalibuBoatOwners.com gallery.";
$owner = $gallery->album->getOwner();
$owner_email = $owner->getEmail();
$owner_name = $owner->getFullName();

$date = date("d/m/Y");
$time = time("B / D d / j-m-Y / H:i:s");
$temps = getdate($time);
$dns = gethostbyaddr($REMOTE_ADDR);

$contents="

Hello ${owner_name}-

$commenter_name has added the following comment to your MalibuBoatOwners.com Gallery.

--------------------
$comment_text

$text_url
--------------------

If you find the comment offensive, it may be removed by clicking the delete comment link next to it.

Thanks for using MBO Owner Galleries!";

mail("$owner_email", $subject, $contents, $headers);

dismissAndReload();
return;
} else {
$error_text = "Name and Comment are both required to save a new comment!";
}
}

if ($gallery->user->isLoggedIn()) {
$displayName = $gallery->user->getFullname();
}

?>
<html>
<head>
<title>Add Comment</title>
<?php echo getStyleSheetLink() ?>
</head>
<body>

<center>
Enter your comment for this picture in the text
box below.
<br><br>
<?php echo $gallery->album->getThumbnailTag($index) ?>
<?php
if ($error_text) {
?>
<br><br>
<span class=error><?php echo $error_text?></span>
<br><br>
<?php
}
?>

<?php echo makeFormIntro("add_comment.php", array("name" => "theform", "method" => "POST")); ?>
<input type=hidden name="index" value="<?php echo $index ?>">
<input type=hidden name="IPNumber" value="<?php echo $HTTP_SERVER_VARS['REMOTE_ADDR'] ?>">
<table border=0 cellpadding=5>
<tr>
<!-- <td>Name or email:</td> -->
<td><input type="hidden" name="commenter_name" value="<?php echo $displayName?>" size=30></td>
</tr>
<tr>
<td colspan=2><textarea name="comment_text" rows=5 cols=40><?php echo $comment_text?></textarea></td>
</tr>
</table>
<br>
<input type=submit name="submit" value="Save">
<input type=button value="Cancel" onclick='parent.close()'>

</form>

<script language="javascript1.2">
<!--
// position cursor in top form field
document.theform.comment_text.focus();
//-->
</script>

</body>
</html> </TD></TR></TABLE><!-- BBCode End -->

I make no promises about this working in your environment, but it is working fine in mine. Let me know if you would like a download with instructions on how to add the mods your add_comment.php.

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Wed, 2003-01-01 14:08

This is great. We do a smilar thing, and the users love it. Because our community is mailing list based, we make the from address the person who wrote the comment:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
$from='"'.$gallery->user->fullname.'" <'.$gallery->user->email.'>';
</TD></TR></TABLE><!-- BBCode End -->
Note if you do this, add a phrase like "This is an automatically generated email" so the recipient understands what is going on.

It's nice to be able to respond directly to a comment, if that seems appropriate. It depends on the community.

We also include the url of the commented image <!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> makeAlbumUrl($gallery->session->albumName, $id) </TD></TR></TABLE><!-- BBCode End -->

What are the $text and $text_url variables?

joan

 
MysticGirl
MysticGirl's picture

Joined: 2003-01-06
Posts: 81
Posted: Mon, 2003-01-06 18:45

Thank you very much for posting your code skicrave. This is just what I was looking for. Is there a way to change the error message that comes up when someone who is not logged in tries to comment? Right now, it just says that the name and comment are required to post, so they don't know why they can't post their comment. Also, I would like to have the poster's name link to their album. I'm new to php, so if someone could point me in the right direction, I would really appreciate it.

 
MysticGirl
MysticGirl's picture

Joined: 2003-01-06
Posts: 81
Posted: Mon, 2003-01-06 19:32

Okay, I'm still going through the archives, and I found a mini hack that will add a line to the bottom of the comments (well, after I edited it). The link to the original<!-- BBCode Start --><A HREF="http://gallery.menalto.com/modules.php?op=modload&amp;name=phpBB_14&amp;file=index&amp;action=viewtopic&amp;topic=1085&amp;8" TARGET="_blank">code</A><!-- BBCode End --> is here. I used the code posted in by recouk. I tweaked this part a little from:

Quote:
print "<b>TO LEAVE COMMENTS ON THIS PHOTO, YOU NEED TO LOGIN/REGISTER!</b>";

to

Quote:
print "<tr align=center><td colspan=3><br><br>To leave comments on this photo, you need to Login/Register!<br><br></td></tr>";

-just because I liked the look of that better, that's totally optional. I'm using this in conjunction with the code posted by skicrave. Though, I'm not sure if I need everything in there since I just replaced the code in add_comment.php. I'm still looking to see if I can find a way to add the link to the person's album when they post a comment.

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Tue, 2003-01-07 18:22

Hey MysticGirl, here is an even better option that I should have included in my first post.

In view_photo.php, find around line 454:

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> <span class="caption"><?php echo viewComments($index) ?></span> </TD></TR></TABLE><!-- BBCode End -->

and replace with:

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> <!-- HACK - prevent non-users from leaving comments -->
<?php
if( $gallery->user->isLoggedIn() )
{
echo viewComments($index);
}
else {
echo "<style='font-family: verdana; font-size: 8pt'><center>Hello <b>Guest</b>, in order to leave comments you must either
<a href='http://www.yourdomain.com/login'>login</a>, or
<a href='http://www.yourdomain/register'>register</a>.</center></style>";
}
?>
<!-- END OF HACK --> </TD></TR></TABLE><!-- BBCode End -->

Now all comments that have been left, and the add comments link will only show up to logged in users. Anyone that is not logged in will see, "Hello Guest, in order to leave comments you must either login or register."

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Tue, 2003-01-07 20:04

Joan- Your code only fetches the name of the album the comment was left in, is there any way to get the url of the actual image? It would be great if the owner could click the link sent in the email and be taken to the gallery page that contains the photo in question, along with the comments.

The variables you questioned are leftover from 1.3.1 that I forgot to trim out after upgrading. Thanks for bringing them to my attention! :smile:

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Tue, 2003-01-07 21:25
Quote:
Joan- Your code only fetches the name of the album the comment was left in, is there any way to get the url of the actual image? It would be great if the owner could click the link sent in the email and be taken to the gallery page that contains the photo in question, along with the comments.

That's what the line does. My users get a link back to their photo with every comment. The optional $id parameter in makeAlbumURL generates the URL of the photopage.

Problem is, that $id is not set in the standard version of add_comments.php. Try adding the following line immediately above.

$id=$gallery->album->getPhotoId($index);

You'll have to test it, but it something like this.

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Tue, 2003-01-07 21:38

In classses/Album.php I did this:

function addComment($index, $comment, $IPNumber, $name) {
$photo = &amp;$this->getPhoto($index);
$photo->addComment($comment, $IPNumber, $name);
$photoURL = makeAlbumUrl($this->fields['name'], $photo->image->name);
$to = ""; // your email here
$subject = "comment added to gallery";
$body = "$photoURLn";
$body .= "By: $name $IPNumbern";
$body .= "Message: $comment";
mail($to, $subject , $body);
}

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Tue, 2003-01-07 22:25

Thanks Joan, that did the trick!

jmullan- The way you did is a great global solution.

 
smiled
smiled's picture

Joined: 2003-02-22
Posts: 5
Posted: Sat, 2003-02-22 01:35

I would like to use this on my page, but I'm using phpbb port, and noen of my users have real name saved in the db, how could I change the the code so it would take uname not name ?

Any help would be great.

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Sat, 2003-02-22 03:58

I assume you're worried because you're using the phpBB database, and not the Gallery flat files. I'm running Gallery under InvisionBoard and the mod works fine.

Have you tried installing it? I don't think you'll have any problems with it working, so give it a try and let us know if it doesn't work.

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Sat, 2003-02-22 10:59
Quote:
I would like to use this on my page, but I'm using phpbb port, and noen of my users have real name saved in the db, how could I change the the code so it would take uname not name ?

Any help would be great.

This is what I use:

$commenter_name=$gallery->user->fullname . " (".$gallery->user->username.")";

 
smiled
smiled's picture

Joined: 2003-02-22
Posts: 5
Posted: Sun, 2003-02-23 12:09
Quote:
This is what I use:

$commenter_name=$gallery->user->fullname . " (".$gallery->user->username.")";

Thanx, just wat I want'ed :roll:

 
MysticGirl
MysticGirl's picture

Joined: 2003-01-06
Posts: 81
Posted: Sun, 2003-02-23 12:35

Where would you put that line?

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Sun, 2003-02-23 13:09
Quote:
Where would you put that line?

replace
$displayName = $gallery->user->getFullname();
with
$displayName = $gallery->user->fullname . " (".$gallery->user->username.")";

 
MysticGirl
MysticGirl's picture

Joined: 2003-01-06
Posts: 81
Posted: Sun, 2003-02-23 22:01

Oh cool, thanks. Now, if I could just figure out how to make their name link to their gallery, I'll be in heaven.

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Sun, 2003-02-23 22:56

I'm sure there is a way to do that, but I don't know what it is. I chose to have it link to their discussion board profile page.

 
MysticGirl
MysticGirl's picture

Joined: 2003-01-06
Posts: 81
Posted: Sun, 2003-02-23 23:08

How did you add the link? I could just add a link that is the default gallery url with their username on the end - the galleries are named by their usernames......though I might have a problem with capitalization.

 
skicrave

Joined: 2002-10-25
Posts: 89
Posted: Mon, 2003-02-24 03:57

Because I'm running Gallery under Invision board, the member ID is available.

 
Drrrl

Joined: 2003-02-02
Posts: 23
Posted: Thu, 2003-03-13 21:57

Hello skicrave,

the effect of your modification is that unloggeged i.e. guest user cannot add comments, but he also cannot see existing comments. I wanted also to prohibit guest users from adding comments, but I wanted them to be available to read comments added by gallery members - just because comment sometimes contain some interesting information about the photo.
On the other hand I'm not interested in "mail" part of this thread, so my modification proposal does not contain the mailing code - sorry.

I made a modification to viewComments() function. The idea was to check if user is logged in after all comment were displayed but before "Add comments" link was displayed. The modification should be made in util.php file at about line 82:

original:

Quote:
function viewComments($index) {
global $gallery;
global $GALLERY_BASEDIR;

// get number of comments to use as counter for display loop
$numComments = $gallery->album->numComments($index);
$borderColor = $gallery->app->default["bordercolor"];
for ($i=1; $i <= $numComments; $i++) {
// get comments in this loop and then use layout/commentdraw.inc to display
$comment = $gallery->album->getComment($index, $i);
$commentdraw["comment"] = $comment->getCommentText();
$commentdraw["IPNumber"] = $comment->getIPNumber();
$commentdraw["datePosted"] = $comment->getDatePosted();
$commentdraw["name"] = $comment->getName();
$commentdraw["UID"] = $comment->getUID();
$commentdraw["bordercolor"] = $borderColor;
include($GALLERY_BASEDIR . "layout/commentdraw.inc");
}
$url = "add_comment.php?set_albumName={$gallery->album->fields[name]}&amp;index=$index";
$buf = "<span class=editlink>";
$buf .= '<a href="#" onClick="' . popup($url) . '">[add comment]</a>';
$buf .= "</span>";
echo "<tr align=center><td colspan=3>$buf<br><br></td></tr>";
}

modified version:

Quote:
function viewComments($index) {
global $gallery;
global $GALLERY_BASEDIR;

// get number of comments to use as counter for display loop
$numComments = $gallery->album->numComments($index);
$borderColor = $gallery->app->default["bordercolor"];
for ($i=1; $i <= $numComments; $i++) {
// get comments in this loop and then use layout/commentdraw.inc to display
$comment = $gallery->album->getComment($index, $i);
$commentdraw["comment"] = nl2br($comment->getCommentText());
$commentdraw["IPNumber"] = $comment->getIPNumber();
$commentdraw["datePosted"] = $comment->getDatePosted();
$commentdraw["name"] = $comment->getName();
$commentdraw["UID"] = $comment->getUID();
$commentdraw["bordercolor"] = $borderColor;
include($GALLERY_BASEDIR . "layout/commentdraw.inc");
}
if ( $gallery->user->isLoggedIn() )
{
$url = "add_comment.php?set_albumName={$gallery->album->fields[name]}&amp;index=$index";
$buf = "<span class=editlink>";
$buf .= '<a href="#" onClick="' . popup($url) . '">[add comment]</a>';
$buf .= "</span>";
echo "<tr align=center><td colspan=3>$buf<br><br></td></tr>";
}

}

Enjoy, Grzes