XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopscomments.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
22 include_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
23 require_once XOOPS_ROOT_PATH . '/class/xoopsobject.php';
24 include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/comment.php';
25 
26 $GLOBALS['xoopsLogger']->addDeprecated("'/class/xoopscommments.php' is deprecated since XOOPS 2.5.4, please use 'kernel/comment.php' instead.");
27 
40 {
41  var $ctable;
42  var $db;
43 
44  function XoopsComments($ctable, $id = null)
45  {
46  $this->ctable = $ctable;
48  $this->XoopsObject();
49  $this->initVar('comment_id', XOBJ_DTYPE_INT, null, false);
50  $this->initVar('item_id', XOBJ_DTYPE_INT, null, false);
51  $this->initVar('order', XOBJ_DTYPE_INT, null, false);
52  $this->initVar('mode', XOBJ_DTYPE_OTHER, null, false);
53  $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, false, 255);
54  $this->initVar('comment', XOBJ_DTYPE_TXTAREA, null, false, null);
55  $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false);
56  $this->initVar('pid', XOBJ_DTYPE_INT, 0, false);
57  $this->initVar('date', XOBJ_DTYPE_INT, null, false);
58  $this->initVar('nohtml', XOBJ_DTYPE_INT, 1, false);
59  $this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false);
60  $this->initVar('noxcode', XOBJ_DTYPE_INT, 0, false);
61  $this->initVar('user_id', XOBJ_DTYPE_INT, null, false);
62  $this->initVar('icon', XOBJ_DTYPE_OTHER, null, false);
63  $this->initVar('prefix', XOBJ_DTYPE_OTHER, null, false);
64  if (!empty($id)) {
65  if (is_array($id)) {
66  $this->assignVars($id);
67  } else {
68  $this->load(intval($id));
69  }
70  }
71  }
72 
78  function load($id)
79  {
80  $id = intval($id);
81  $sql = "SELECT * FROM " . $this->ctable . " WHERE comment_id=" . $id;
82  $arr = $this->db->fetchArray($this->db->query($sql));
83  $this->assignVars($arr);
84  }
85 
91  function store()
92  {
93  if (!$this->cleanVars()) {
94  return false;
95  }
96  foreach ($this->cleanVars as $k => $v) {
97  $$k = $v;
98  }
99  $isnew = false;
100  if (empty($comment_id)) {
101  $isnew = true;
102  $comment_id = $this->db->genId($this->ctable . "_comment_id_seq");
103  $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);
104  } else {
105  $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);
106  }
107  if (! $result = $this->db->query($sql)) {
108  //echo $sql;
109  return false;
110  }
111  if (empty($comment_id)) {
112  $comment_id = $this->db->getInsertId();
113  }
114  if ($isnew != false) {
115  $sql = sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u", $this->db->prefix("users"), $user_id);
116  if (!$result = $this->db->query($sql)) {
117  echo "Could not update user posts.";
118  }
119  }
120  return $comment_id;
121  }
122 
128  function delete()
129  {
130  $sql = sprintf("DELETE FROM %s WHERE comment_id = %u", $this->ctable, $this->getVar('comment_id'));
131  if (!$result = $this->db->query($sql)) {
132  return false;
133  }
134  $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $this->getVar("user_id"));
135  if (!$result = $this->db->query($sql)) {
136  echo "Could not update user posts.";
137  }
138  $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
139  $arr = $mytree->getAllChild($this->getVar("comment_id"), "comment_id");
140  $size = count($arr);
141  if ($size > 0) {
142  for ($i = 0; $i < $size; $i++) {
143  $sql = sprintf("DELETE FROM %s WHERE comment_bid = %u", $this->ctable, $arr[$i]['comment_id']);
144  if (!$result = $this->db->query($sql)) {
145  echo "Could not delete comment.";
146  }
147  $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $arr[$i]['user_id']);
148  if (!$result = $this->db->query($sql)) {
149  echo "Could not update user posts.";
150  }
151  }
152  }
153  return ($size + 1);
154  }
155 
161  function getCommentTree()
162  {
163  $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
164  $ret = array();
165  $tarray = $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id");
166  foreach ($tarray as $ele) {
167  $ret[] = new XoopsComments($this->ctable, $ele);
168  }
169  return $ret;
170  }
171 
182  function getAllComments($criteria = array(), $asobject = true, $orderby = "comment_id ASC", $limit = 0, $start = 0)
183  {
184  $ret = array();
185  $where_query = "";
186  if (is_array($criteria) && count($criteria) > 0) {
187  $where_query = " WHERE";
188  foreach ($criteria as $c) {
189  $where_query .= " $c AND";
190  }
191  $where_query = substr($where_query, 0, - 4);
192  }
193  if (!$asobject) {
194  $sql = "SELECT comment_id FROM " . $this->ctable . "$where_query ORDER BY $orderby";
195  $result = $this->db->query($sql, $limit, $start);
196  while ($myrow = $this->db->fetchArray($result)) {
197  $ret[] = $myrow['comment_id'];
198  }
199  } else {
200  $sql = "SELECT * FROM " . $this->ctable . "" . $where_query . " ORDER BY $orderby";
201  $result = $this->db->query($sql, $limit, $start);
202  while ($myrow = $this->db->fetchArray($result)) {
203  $ret[] = new XoopsComments($this->ctable, $myrow);
204  }
205  }
206  //echo $sql;
207  return $ret;
208  }
209 
217  function printNavBar($item_id, $mode = "flat", $order = 1)
218  {
219  global $xoopsConfig, $xoopsUser;
220  echo "<form method='get' action='" . $_SERVER['PHP_SELF'] . "'><table width='100%' border='0' cellspacing='1' cellpadding='2'><tr><td class='bg1' align='center'><select name='mode'><option value='nocomments'";
221  if ($mode == "nocomments") {
222  echo " selected='selected'";
223  }
224  echo ">" . _NOCOMMENTS . "</option><option value='flat'";
225  if ($mode == 'flat') {
226  echo " selected='selected'";
227  }
228  echo ">" . _FLAT . "</option><option value='thread'";
229  if ($mode == "thread" || $mode == "") {
230  echo " selected='selected'";
231  }
232  echo ">" . _THREADED . "</option></select><select name='order'><option value='0'";
233  if ($order != 1) {
234  echo " selected='selected'";
235  }
236  echo ">" . _OLDESTFIRST . "</option><option value='1'";
237  if ($order == 1) {
238  echo " selected='selected'";
239  }
240  echo ">" . _NEWESTFIRST . "</option></select><input type='hidden' name='item_id' value='" . intval($item_id) . "' /><input type='submit' value='" . _CM_REFRESH . "' />";
241  if ($xoopsConfig['anonpost'] == 1 || $xoopsUser) {
242  if ($mode != "flat" || $mode != "nocomments" || $mode != "thread") {
243  $mode = "flat";
244  }
245  echo "&nbsp;<input type='button' onclick='location=\"newcomment.php?item_id=" . intval($item_id) . "&amp;order=" . intval($order) . "&amp;mode=" . $mode . "\"' value='" . _CM_POSTCOMMENT . "' />";
246  }
247  echo "</td></tr></table></form>";
248  }
249 
254  function showThreadHead()
255  {
256  openThread();
257  }
258 
267  function showThreadPost($order, $mode, $adminview = 0, $color_num = 1)
268  {
269  global $xoopsConfig, $xoopsUser;
270  $edit_image = "";
271  $reply_image = "";
272  $delete_image = "";
273  $post_date = formatTimestamp($this->getVar("date"), "m");
274  if ($this->getVar("user_id") != 0) {
275  $poster = new XoopsUser($this->getVar("user_id"));
276  if (!$poster->isActive()) {
277  $poster = 0;
278  }
279  } else {
280  $poster = 0;
281  }
282  if ($this->getVar("icon") != null && $this->getVar("icon") != "") {
283  $subject_image = "<a name='" . $this->getVar("comment_id") . "' id='" . $this->getVar("comment_id") . "'></a><img src='" . XOOPS_URL . "/images/subject/" . $this->getVar("icon") . "' alt='' />";
284  } else {
285  $subject_image = "<a name='" . $this->getVar("comment_id") . "' id='" . $this->getVar("comment_id") . "'></a><img src='" . XOOPS_URL . "/images/icons/no_posticon.gif' alt='' />";
286  }
287  if ($adminview) {
288  $ip_image = "<img src='" . XOOPS_URL . "/images/icons/ip.gif' alt='" . $this->getVar("ip") . "' />";
289  } else {
290  $ip_image = "<img src='" . XOOPS_URL . "/images/icons/ip.gif' alt='' />";
291  }
292  if ($adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid"))) {
293  $edit_image = "<a href='editcomment.php?comment_id=" . $this->getVar("comment_id") . "&amp;mode=" . $mode . "&amp;order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/edit.gif' alt='" . _EDIT . "' /></a>";
294  }
295  if ($xoopsConfig['anonpost'] || $xoopsUser) {
296  $reply_image = "<a href='replycomment.php?comment_id=" . $this->getVar("comment_id") . "&amp;mode=" . $mode . "&amp;order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/reply.gif' alt='" . _REPLY . "' /></a>";
297  }
298  if ($adminview) {
299  $delete_image = "<a href='deletecomment.php?comment_id=" . $this->getVar("comment_id") . "&amp;mode=" . $mode . "&amp;order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/delete.gif' alt='" . _DELETE . "' /></a>";
300  }
301 
302  if ($poster) {
303  $text = $this->getVar("comment");
304  if ($poster->getVar("attachsig")) {
305  $text .= "<p><br />_________________<br />" . $poster->user_sig() . "</p>";
306  }
307  $reg_date = _CM_JOINED;
308  $reg_date .= formatTimestamp($poster->getVar("user_regdate"), "s");
309  $posts = _CM_POSTS;
310  $posts .= $poster->getVar("posts");
311  $user_from = _CM_FROM;
312  $user_from .= $poster->getVar("user_from");
313  $rank = $poster->rank();
314  if ($rank['image'] != "") {
315  $rank['image'] = "<img src='" . XOOPS_UPLOAD_URL . "/" . $rank['image'] . "' alt='' />";
316  }
317  $avatar_image = "<img src='" . XOOPS_UPLOAD_URL . "/" . $poster->getVar("user_avatar") . "' alt='' />";
318  if ($poster->isOnline()) {
319  $online_image = "<span style='color:#ee0000;font-weight:bold;'>" . _ONLINE . "</span>";
320  } else {
321  $online_image = "";
322  }
323  $profile_image = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poster->getVar("uid") . "'><img src='" . XOOPS_URL . "/images/icons/profile.gif' alt='" . _PROFILE . "' /></a>";
324  if ($xoopsUser) {
325  $pm_image = "<a href='javascript:openWithSelfMain(\"" . XOOPS_URL . "/pmlite.php?send2=1&amp;to_userid=" . $poster->getVar("uid") . "\",\"pmlite\",450,370);'><img src='" . XOOPS_URL . "/images/icons/pm.gif' alt='" . sprintf(_SENDPMTO, $poster->getVar("uname", "E")) . "' /></a>";
326  } else {
327  $pm_image = "";
328  }
329  if ($poster->getVar("user_viewemail")) {
330  $email_image = "<a href='mailto:" . $poster->getVar("email", "E") . "'><img src='" . XOOPS_URL . "/images/icons/email.gif' alt='" . sprintf(_SENDEMAILTO, $poster->getVar("uname", "E")) . "' /></a>";
331  } else {
332  $email_image = "";
333  }
334  $posterurl = $poster->getVar("url");
335  if ($posterurl != "") {
336  $www_image = "<a href='$posterurl' rel='external'><img src='" . XOOPS_URL . "/images/icons/www.gif' alt='" . _VISITWEBSITE . "' /></a>";
337  } else {
338  $www_image = "";
339  }
340  if ($poster->getVar("user_icq") != "") {
341  $icq_image = "<a href='http://wwp.icq.com/scripts/search.dll?to=" . $poster->getVar("user_icq", "E") . "'><img src='" . XOOPS_URL . "/images/icons/icq_add.gif' alt='" . _ADD . "' /></a>";
342  } else {
343  $icq_image = "";
344  }
345  if ($poster->getVar("user_aim") != "") {
346  $aim_image = "<a href='aim:goim?screenname=" . $poster->getVar("user_aim", "E") . "&message=Hi+" . $poster->getVar("user_aim") . "+Are+you+there?'><img src='" . XOOPS_URL . "/images/icons/aim.gif' alt='aim' /></a>";
347  } else {
348  $aim_image = "";
349  }
350  if ($poster->getVar("user_yim") != "") {
351  $yim_image = "<a href='http://edit.yahoo.com/config/send_webmesg?.target=" . $poster->getVar("user_yim", "E") . "&.src=pg'><img src='" . XOOPS_URL . "/images/icons/yim.gif' alt='yim' /></a>";
352  } else {
353  $yim_image = "";
354  }
355  if ($poster->getVar("user_msnm") != "") {
356  $msnm_image = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poster->getVar("uid") . "'><img src='" . XOOPS_URL . "/images/icons/msnm.gif' alt='msnm' /></a>";
357  } else {
358  $msnm_image = "";
359  }
360  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);
361  } else {
362  showThread($color_num, $subject_image, $this->getVar("subject"), $this->getVar("comment"), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']);
363  }
364  }
365 
370  function showThreadFoot()
371  {
372  closeThread();
373  }
374 
380  function showTreeHead($width = "100%")
381  {
382  echo "<table border='0' class='outer' cellpadding='0' cellspacing='0' align='center' width='$width'><tr class='bg3' align='center'><td colspan='3'>" . _CM_REPLIES . "</td></tr><tr class='bg3' align='left'><td width='60%' class='fg2'>" . _CM_TITLE . "</td><td width='20%' class='fg2'>" . _CM_POSTER . "</td><td class='fg2'>" . _CM_POSTED . "</td></tr>";
383  }
384 
392  function showTreeItem($order, $mode, $color_num)
393  {
394  if ($color_num == 1) {
395  $bg = 'even';
396  } else {
397  $bg = 'odd';
398  }
399  $prefix = str_replace(".", "&nbsp;&nbsp;&nbsp;&nbsp;", $this->getVar("prefix"));
400  $date = formatTimestamp($this->getVar("date"), "m");
401  if ($this->getVar("icon") != "") {
402  $icon = "subject/" . $this->getVar("icon", "E");
403  } else {
404  $icon = "icons/no_posticon.gif";
405  }
406  echo "<tr class='$bg' align='left'><td>" . $prefix . "<img src='" . XOOPS_URL . "/images/" . $icon . "'>&nbsp;<a href='" . $_SERVER['PHP_SELF'] . "?item_id=" . $this->getVar("item_id") . "&amp;comment_id=" . $this->getVar("comment_id") . "&amp;mode=" . $mode . "&amp;order=" . $order . "#" . $this->getVar("comment_id") . "'>" . $this->getVar("subject") . "</a></td><td><a href='" . XOOPS_URL . "/userinfo.php?uid=" . $this->getVar("user_id") . "'>" . XoopsUser::getUnameFromId($this->getVar("user_id")) . "</a></td><td>" . $date . "</td></tr>";
407  }
408 
413  function showTreeFoot()
414  {
415  echo "</table><br />";
416  }
417 }
418 
419 ?>