31 $this->ctable = $ctable;
32 $this->db =& Database::getInstance();
33 parent::__construct();
34 $this->
initVar(
'comment_id', XOBJ_DTYPE_INT,
null,
false);
35 $this->
initVar(
'item_id', XOBJ_DTYPE_INT,
null,
false);
36 $this->
initVar(
'order', XOBJ_DTYPE_INT,
null,
false);
37 $this->
initVar(
'mode', XOBJ_DTYPE_OTHER,
null,
false);
38 $this->
initVar(
'subject', XOBJ_DTYPE_TXTBOX,
null,
false, 191);
39 $this->
initVar(
'comment', XOBJ_DTYPE_TXTAREA,
null,
false,
null);
40 $this->
initVar(
'ip', XOBJ_DTYPE_OTHER,
null,
false);
41 $this->
initVar(
'pid', XOBJ_DTYPE_INT, 0,
false);
42 $this->
initVar(
'date', XOBJ_DTYPE_INT,
null,
false);
43 $this->
initVar(
'nohtml', XOBJ_DTYPE_INT, 1,
false);
44 $this->
initVar(
'nosmiley', XOBJ_DTYPE_INT, 0,
false);
45 $this->
initVar(
'noxcode', XOBJ_DTYPE_INT, 0,
false);
46 $this->
initVar(
'user_id', XOBJ_DTYPE_INT,
null,
false);
47 $this->
initVar(
'icon', XOBJ_DTYPE_OTHER,
null,
false);
48 $this->
initVar(
'prefix', XOBJ_DTYPE_OTHER,
null,
false);
53 $this->load((
int)$id);
58 public function load($id)
60 $sql =
'SELECT * FROM ' . $this->ctable .
' WHERE comment_id=' . $id .
'';
61 $arr = $this->db->fetchArray($this->db->query($sql));
65 public function store()
74 if (empty($comment_id)) {
76 $comment_id = $this->db->genId($this->ctable .
'_comment_id_seq');
77 $sql = sprintf(
"INSERT INTO %s (comment_id, pid, item_id, date, user_id, ip, subject, comment, nohtml, nosmiley, noxcode, icon) VALUES (%u, %u, %u, %u, %u, '%s', '%s', '%s', %u, %u, %u, '%s')", $this->ctable, $comment_id, $pid, $item_id, time(), $user_id, $ip, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon);
79 $sql = sprintf(
"UPDATE %s SET subject = '%s', comment = '%s', nohtml = %u, nosmiley = %u, noxcode = %u, icon = '%s' WHERE comment_id = %u", $this->ctable, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon, $comment_id);
81 if (!$result = $this->db->query($sql)) {
85 if (empty($comment_id)) {
86 $comment_id = $this->db->getInsertId();
88 if (
false !== $isnew) {
89 $sql = sprintf(
'UPDATE %s SET posts = posts+1 WHERE uid = %u', $this->db->prefix(
'users'), $user_id);
90 if (!$result = $this->db->query($sql)) {
91 echo
'Could not update user posts.';
97 public function delete()
99 $sql = sprintf(
'DELETE FROM %s WHERE comment_id = %u', $this->ctable, $this->
getVar(
'comment_id'));
100 if (!$result = $this->db->query($sql)) {
103 $sql = sprintf(
'UPDATE %s SET posts = posts-1 WHERE uid = %u', $this->db->prefix(
'users'), $this->getVar(
'user_id'));
104 if (!$result = $this->db->query($sql)) {
105 echo
'Could not update user posts.';
107 $mytree =
new XoopsTree($this->ctable,
'comment_id',
'pid');
108 $arr = $mytree->getAllChild($this->
getVar(
'comment_id'),
'comment_id');
111 foreach ($arr as $iValue) {
112 $sql = sprintf(
'DELETE FROM %s WHERE comment_bid = %u', $this->ctable, $iValue[
'comment_id']);
113 if (!$result = $this->db->query($sql)) {
114 echo
'Could not delete comment.';
116 $sql = sprintf(
'UPDATE %s SET posts = posts-1 WHERE uid = %u', $this->db->prefix(
'users'), $iValue[
'user_id']);
117 if (!$result = $this->db->query($sql)) {
118 echo
'Could not update user posts.';
125 public function &getCommentTree()
127 $mytree =
new XoopsTree($this->ctable,
'comment_id',
'pid');
129 $tarray = $mytree->getChildTreeArray($this->
getVar(
'comment_id'),
'comment_id');
130 foreach ($tarray as $ele) {
136 public function getAllComments($criteria= [], $asobject=
true, $orderby=
'comment_id ASC', $limit=0, $start=0)
140 if (is_array($criteria) && count($criteria) > 0) {
141 $where_query =
' WHERE';
142 foreach ($criteria as $c) {
143 $where_query .=
" $c AND";
145 $where_query = substr($where_query, 0, -4);
148 $sql =
'SELECT comment_id FROM ' . $this->ctable .
"$where_query ORDER BY $orderby";
149 $result = $this->db->query($sql, $limit, $start);
150 while ($myrow = $this->db->fetchArray($result)) {
151 $ret[] = $myrow[
'comment_id'];
154 $sql =
'SELECT * FROM ' . $this->ctable .
'' . $where_query .
" ORDER BY $orderby";
155 $result = $this->db->query($sql, $limit, $start);
156 while ($myrow = $this->db->fetchArray($result)) {
165 public function printNavBar($item_id, $mode=
'flat', $order=1)
167 global $xoopsConfig, $xoopsUser;
168 echo
"<form method='get' action='".xoops_getenv(
'PHP_SELF').
"'><table width='100%' border='0' cellspacing='1' cellpadding='2'><tr><td class='bg1' align='center'><select name='mode'><option value='nocomments'";
169 if (
'nocomments' == $mode) {
170 echo
" selected='selected'";
172 echo
'>' . _NOCOMMENTS .
"</option><option value='flat'";
173 if (
'flat' == $mode) {
174 echo
" selected='selected'";
176 echo
'>' . _FLAT .
"</option><option value='thread'";
177 if (
'thread' == $mode ||
'' == $mode) {
178 echo
" selected='selected'";
180 echo
'>' . _THREADED .
"</option></select><select name='order'><option value='0'";
182 echo
" selected='selected'";
184 echo
'>' . _OLDESTFIRST .
"</option><option value='1'";
186 echo
" selected='selected'";
188 echo
'>' . _NEWESTFIRST .
"</option></select><input type='hidden' name='item_id' value='" . (int)$item_id .
"' /><input type='submit' value='" . _CM_REFRESH .
"' />";
189 if (1 == $xoopsConfig[
'anonpost'] || $xoopsUser) {
190 if (
'flat' != $mode ||
'nocomments' != $mode ||
'thread' != $mode) {
193 echo
" <input type='button' onclick='location=\"newcomment.php?item_id=" . (int)$item_id .
'&order=' . (
int)$order .
'&mode=' . $mode .
"\"' value='" . _CM_POSTCOMMENT .
"' />";
195 echo
'</td></tr></table></form>';
198 public function showThreadHead()
203 public function showThreadPost($order, $mode, $adminview=0, $color_num=1)
205 global $xoopsConfig, $xoopsUser;
209 $post_date = formatTimestamp($this->
getVar(
'date'),
'm');
210 if (0 !== $this->
getVar(
'user_id')) {
212 if (!$poster->isActive()) {
218 if (
null !== $this->
getVar(
'icon') &&
'' !== $this->
getVar(
'icon')) {
219 $subject_image =
"<a name='".$this->getVar(
'comment_id') .
"' id='" . $this->
getVar(
'comment_id') .
"'></a><img src='" . XOOPS_URL .
'/images/subject/' . $this->
getVar(
'icon') .
"' alt=''>";
221 $subject_image =
"<a name='".$this->getVar(
'comment_id') .
"' id='" . $this->
getVar(
'comment_id') .
"'></a><img class='svg' src='" . XOOPS_URL .
"/images/icons/no_posticon.svg' alt=''>";
224 $ip_image =
"<img class='svg' src='".XOOPS_URL.
"/images/icons/ip-network.svg' alt='".$this->
getVar(
'ip') .
"'>";
226 $ip_image =
"<img class='svg' src='".XOOPS_URL.
"/images/icons/ip-network.svg' alt=''>";
228 if ($adminview || ($xoopsUser && $this->
getVar(
'user_id') == $xoopsUser->getVar(
'uid'))) {
229 $edit_image =
"<a href='editcomment.php?comment_id=".$this->getVar(
'comment_id') .
'&mode=' . $mode .
'&order=' . (int)$order .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/edit.svg' alt='" . _EDIT .
"'></a>";
231 if ($xoopsConfig[
'anonpost'] || $xoopsUser) {
232 $reply_image =
"<a href='replycomment.php?comment_id=".$this->getVar(
'comment_id') .
'&mode=' . $mode .
'&order=' . (int)$order .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/reply.svg' alt='" . _REPLY .
"'></a>";
235 $delete_image =
"<a href='deletecomment.php?comment_id=".$this->getVar(
'comment_id') .
'&mode=' . $mode .
'&order=' . (int)$order .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/delete.svg' alt='" . _DELETE .
"'></a>";
239 $text = $this->
getVar(
'comment');
240 if ($poster->getVar(
'attachsig')) {
241 $text .=
'<p><br>__________<br>' . $poster->user_sig() .
'</p>';
243 $reg_date = _CM_JOINED;
244 $reg_date .= formatTimestamp($poster->getVar(
'user_regdate'),
's');
246 $posts .= $poster->getVar(
'posts');
247 $user_from = _CM_FROM;
248 $user_from .= $poster->getVar(
'user_from');
249 $rank = $poster->rank();
250 if (
'' !== $rank[
'image']) {
251 $rank[
'image'] =
"<img class='svg' src='".XOOPS_UPLOAD_URL .
'/' . $rank[
'image'] .
"' alt=''>";
253 $avatar_image =
"<img src='".XOOPS_UPLOAD_URL .
'/' . $poster->getVar(
'user_avatar') .
"' alt=''>";
254 if ($poster->isOnline()) {
255 $online_image =
"<span class='user-online'>"._ONLINE .
'</span>';
259 $profile_image =
"<a href='".XOOPS_URL .
'/userinfo.php?uid=' . $poster->getVar(
'uid') .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/user.svg' alt='" . _PROFILE .
"'></a>";
261 $pm_image =
"<a href='javascript:openWithSelfMain(\"".XOOPS_URL .
'/pmlite.php?send2=1&to_userid=' . $poster->getVar(
'uid') .
"\",\"pmlite\",450,370);'><img class='svg' src='" . XOOPS_URL .
"/images/icons/mail.svg' alt='" . sprintf(_SENDPMTO, $poster->getVar(
'uname',
'E')) .
"'></a>";
265 if ($poster->getVar(
'user_viewemail')) {
266 $email_image =
"<a href='mailto:".$poster->getVar(
'email',
'E') .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/mail.svg' alt='" . sprintf(_SENDEMAILTO, $poster->getVar(
'uname',
'E')) .
"'></a>";
270 $posterurl = $poster->getVar(
'url');
271 if (
'' !== $posterurl) {
272 $www_image =
"<a href='$posterurl' rel='external'><img class='svg' src='".XOOPS_URL.
"/images/icons/web.svg' alt='"._VISITWEBSITE.
"'></a>";
276 if (
'' !== $poster->getVar(
'user_icq')) {
277 $icq_image =
"<a href='https://wwp.icq.com/scripts/search.dll?to=".$poster->getVar(
'user_icq',
'E') .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/icq.svg' alt='" . _ADD .
"'></a>";
281 if (
'' !== $poster->getVar(
'user_aim')) {
282 $aim_image =
"<a href='aim:goim?screenname=".$poster->getVar(
'user_aim',
'E') .
'&message=Hi+' . $poster->getVar(
'user_aim') .
"+Are+you+there?'><img class='svg' src='" . XOOPS_URL .
"/images/icons/aim.svg' alt='aim'></a>";
286 if (
'' !== $poster->getVar(
'user_yim')) {
287 $yim_image =
"<a href='https://edit.yahoo.com/config/send_webmesg?.target=".$poster->getVar(
'user_yim',
'E') .
"&.src=pg'><img class='svg' src='" . XOOPS_URL .
"/images/icons/yim.svg' alt='yim'></a>";
291 if (
'' !== $poster->getVar(
'user_msnm')) {
292 $msnm_image =
"<a href='".XOOPS_URL .
'/userinfo.php?uid=' . $poster->getVar(
'uid') .
"'><img class='svg' src='" . XOOPS_URL .
"/images/icons/msnm.svg' alt='msnm'></a>";
296 showThread($color_num, $subject_image, $this->
getVar(
'subject'), $text, $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $poster->getVar(
'uname'), $rank[
'title'], $rank[
'image'], $avatar_image, $reg_date, $posts, $user_from, $online_image, $profile_image, $pm_image, $email_image, $www_image, $icq_image, $aim_image, $yim_image, $msnm_image);
298 showThread($color_num, $subject_image, $this->
getVar(
'subject'), $this->
getVar(
'comment'), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig[
'anonymous']);
302 public function showThreadFoot()
307 public function showTreeHead($width=
'100%')
309 echo
"<table class='outer' width='$width'><tr><td colspan='3'>". _CM_REPLIES .
"</td></tr><tr class='bg3'><td width='60%' class='fg2'>". _CM_TITLE .
"</td><td width='20%' class='fg2'>". _CM_POSTER .
"</td><td class='fg2'>". _CM_POSTED .
'</td></tr>';
312 public function showTreeItem($order, $mode, $color_num)
314 if (1 == $color_num) {
319 $prefix = str_replace(
'.',
' ', $this->
getVar(
'prefix'));
320 $date = formatTimestamp($this->
getVar(
'date'),
'm');
321 if (
'' !== $this->
getVar(
'icon')) {
322 $icon =
'subject/' . $this->
getVar(
'icon',
'E');
324 $icon =
'icons/no_posticon.svg';
326 echo
"<tr class='$bg' align='left'><td>".$prefix.
"<img src='".XOOPS_URL .
'/images/'
327 . $icon .
"'> <a href='" . xoops_getenv(
'PHP_SELF') .
'?item_id='
328 . $this->
getVar(
'item_id') .
'&comment_id='
329 . $this->
getVar(
'comment_id') .
'&mode='
330 . $mode .
'&order='
332 . $this->
getVar(
'comment_id') .
"'>" . $this->
getVar(
'subject') .
"</a></td><td><a href='" . XOOPS_URL .
'/userinfo.php?uid='
334 . $date .
'</td></tr>';
337 public function showTreeFoot()