<?php
/*
* buzzword
* Copyright (c) 2003 Jon Tai
*
* $Id: image-comment.inc 271 2004-03-29 20:07:26Z bradt $
*
* This file is part of buzzword.
*
* buzzword 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.
*
* buzzword 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 buzzword; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
function get_gallery_image_comments($image) {
$comments = array();
$sql = 'SELECT comment_key ';
$sql .= 'FROM '.DB_PREFIX.'gallery_images_comments ';
$sql .= "WHERE image_key = {$image->image_key} ";
if (!defined('ADMIN_LOGGED_IN')) {
$sql .= "AND is_private = 'N' ";
}
$sql .= 'ORDER BY created ';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
$comments[] = new gallery_image_comment($image, $row['comment_key']);
return $comments;
}
class gallery_image_comment {
function gallery_image_comment($image, $comment_key) {
$this->image = $image;
$this->comment_key = $comment_key;
$sql = 'SELECT UNIX_TIMESTAMP(created) AS created, is_private, ';
$sql .= 'title, body, author, email, email_is_private ';
$sql .= 'FROM '.DB_PREFIX.'gallery_images_comments ';
$sql .= "WHERE comment_key = {$this->comment_key} ";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$this->exists = is_array($row);
$this->is_private = ($row) ? ($row['is_private'] == 'Y') : FALSE;
$this->created = ($row) ? $row['created'] : 0;
$this->title = ($row) ? $row['title'] : 'comment';
$this->body = ($row) ? $row['body'] : '';
$this->author = ($row) ? $row['author'] : 'anonymous';
$this->email = ($row) ? $row['email'] : '';
$this->email_is_private = ($row) ? ($row['email_is_private'] == 'Y') : TRUE;
$this->is_accessible = (defined('ADMIN_LOGGED_IN')) ? TRUE : !$this->is_private;
mysql_free_result($result);
}
function create() {
if (empty($this->body))
return;
$comment_key = $this->comment_key;
$image_key = $this->image->image_key;
$created = mysql_quote_string(date('Y-m-d H:i:s', $this->created));
$is_private = mysql_quote_string(($this->is_private) ? 'Y' : 'N');
$title = mysql_quote_string($this->title);
$body = mysql_quote_string($this->body);
$author = mysql_quote_string($this->author);
$email = mysql_quote_string($this->email);
$email_is_private = mysql_quote_string(($this->email_is_private) ? 'Y' : 'N');
$sql = 'INSERT INTO '.DB_PREFIX.'gallery_images_comments ';
$sql .= '(comment_key, image_key, created, is_private, title, body, author, email, email_is_private) VALUES ';
$sql .= "($comment_key, $image_key, $created, $is_private, $title, $body, $author, $email, $email_is_private)";
mysql_query($sql);
$this->exists = TRUE;
}
function destroy() {
$sql = 'DELETE FROM '.DB_PREFIX.'gallery_images_comments ';
$sql .= "WHERE comment_key = {$this->comment_key} ";
mysql_query($sql);
$this->exists = FALSE;
}
// whether or not the comment exists
function exists() {
return ($this->is_accessible) ? $this->exists : FALSE;
}
function get_display_restrictions() {
if ($this->is_private)
return 'private';
return 'no restrictions';
}
function get_display_title() {
return htmlspecialchars($this->title);
}
function get_display_body() {
return longtext_hook(nl2p(htmlspecialchars($this->body)));
}
function get_display_author() {
return get_display_author(htmlspecialchars($this->author), $this->email, $this->email_is_private);
}
function get_display_date_created() {
return date(get_pref('buzzword_date_format'), $this->created);
}
function get_display_time_created() {
return date(get_pref('buzzword_time_format'), $this->created);
}
}
?>