1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
<?php
/*
* A class corresponding to the color_shemes table.
*
* This file is part of Zoph.
*
* Zoph 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.
*
* Zoph 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 Zoph; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class comment extends zoph_table {
function comment($id = 0) {
parent::zoph_table("comments", array("comment_id"), array("subject"));
$this->set("comment_id", $id);
}
function insert() {
$this->set("comment_date", "now()");
$this->set("ipaddr", $_SERVER['REMOTE_ADDR']);
parent::insert();
$this->lookup();
}
function update() {
$this->set("timestamp","now()");
parent::update();
$this->lookup();
}
function delete() {
if(!$this->get("comment_id")) { return; }
parent::delete();
$sql = "delete from " . DB_PREFIX . "photo_comments where comment_id=";
$sql .= $this->get("comment_id");
mysql_query($sql) or die_with_mysql_error("Could not clean comment from photo: ", $sql);
}
function get_display_array($user = null) {
$date=$this->get("comment_date");
$changed=$this->get("timestamp");
if($changed != $date) { $updated=$changed; }
return array(
translate("subject") => $this->get("subject"),
translate("date") => $date,
translate("user") => $this->lookup_user(),
translate("IP address") => $user->is_admin() ? $this->get("ipaddr") : "<i>" . translate("only visible for admin users") . "</i>",
translate("comment") => str_replace("\n", "<br>", $this->get("comment")),
translate("updated") => $changed
);
}
function lookup_user() {
$comment_user = new user($this->get("user_id"));
$comment_user->lookup();
$user_name = $comment_user->get("user_name");
$comment_user->lookup_person();
$comment_person = $comment_user->person->get_name();
$comment_person_id = $comment_user->person->get("person_id");
$return = sprintf("<a href=\"user.php?user_id=%s\">%s</a> (<a href=person.php?person_id=%s>%s</a>)", $this->get("user_id"), $user_name, $comment_person_id, $comment_person);
return $return;
}
function get_photo() {
if(!$this->get("comment_id")) { return; }
$sql = "select photo_id from " . DB_PREFIX . "photo_comments" .
" where comment_id=" . $this->get("comment_id") .
" limit 1";
$result=get_records_from_query("photo", $sql);
if($result[0]) {
$result[0]->lookup();
return $result[0];
} else {
return null;
}
}
function add_comment_to_photo($photo_id) {
if (!$photo_id) { return; }
$sql = "insert into " . DB_PREFIX . "photo_comments values" .
"(" . $photo_id . ", " . $this->get("comment_id") . ")";
mysql_query($sql) or die_with_mysql_error("Failed to add comment:", $sql);
}
function is_owner($user) {
if($user->get(user_id)==$this->get("user_id")) {
return true;
} else {
return false;
}
}
function to_html($user, $thumbnail=null) {
$this->lookup();
$photo=$this->get_photo();
$html = "<div class=\"comment\">\n";
$html .= "<h3>\n";
if ($user->is_admin() || $this->is_owner($user)) {
$html .= "<span class=\"actionlink\">\n";
$html .= "<a href=\"comment.php?_action=display&comment_id=" .
$this->get("comment_id") . "\">\n";
$html .= translate("display") . "</a> | ";
$html .= "<a href=\"comment.php?_action=edit&comment_id=" .
$this->get("comment_id") . "\">";
$html .= translate("edit") . "</a> | ";
$html .= "<a href=\"comment.php?_action=delete&comment_id=" .
$this->get("comment_id") ."\">";
$html .= translate("delete") . "</a>\n";
$html .= "</span>\n";
}
$html .= $this->get("subject") . "</h3>\n";
$html .= "<div class=\"commentinfo\">\n";
$html .= $this->get("comment_date");
$html .= " " . translate("by",0) . " <b>" . $this->lookup_user() . "</b>";
$html .= "</div>\n";
if ($thumbnail) {
$html .= "<div class=\"thumbnail\">\n";
$html .= $photo->get_thumbnail_link();
$html .= "</div>\n";
}
$html .= str_replace("\n", "<br class=\"noclear\">\n", $this->get("comment"));
$html .= "<br></div>\n";
return $html;
}
}
function get_all_comments() {
return get_records_from_query("comment", "select comment_id from " . DB_PREFIX . "comments");
}
?>
|