1: <?php
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: if (!defined('XOOPS_ROOT_PATH')) {
32: exit();
33: }
34: include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
35: require_once XOOPS_ROOT_PATH.'/class/xoopsobject.php';
36:
37: $root =& XCube_Root::getSingleton();
38: $root->mLanguageManager->loadPageTypeMessageCatalog('comment');
39:
40: class XoopsComments extends XoopsObject
41: {
42: var $ctable;
43: var $db;
44:
45: function XoopsComments($ctable, $id=null)
46: {
47: $this->ctable = $ctable;
48: $this->db =& Database::getInstance();
49: $this->XoopsObject();
50: $this->initVar('comment_id', XOBJ_DTYPE_INT, null, false);
51: $this->initVar('item_id', XOBJ_DTYPE_INT, null, false);
52: $this->initVar('order', XOBJ_DTYPE_INT, null, false);
53: $this->initVar('mode', XOBJ_DTYPE_OTHER, null, false);
54: $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, false, 255);
55: $this->initVar('comment', XOBJ_DTYPE_TXTAREA, null, false, null);
56: $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false);
57: $this->initVar('pid', XOBJ_DTYPE_INT, 0, false);
58: $this->initVar('date', XOBJ_DTYPE_INT, null, false);
59: $this->initVar('nohtml', XOBJ_DTYPE_INT, 1, false);
60: $this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false);
61: $this->initVar('noxcode', XOBJ_DTYPE_INT, 0, false);
62: $this->initVar('user_id', XOBJ_DTYPE_INT, null, false);
63: $this->initVar('icon', XOBJ_DTYPE_OTHER, null, false);
64: $this->initVar('prefix', XOBJ_DTYPE_OTHER, null, false);
65: if ( !empty($id) ) {
66: if ( is_array($id) ) {
67: $this->assignVars($id);
68: } else {
69: $this->load(intval($id));
70: }
71: }
72: }
73:
74: function load($id)
75: {
76: $sql = "SELECT * FROM ".$this->ctable." WHERE comment_id=".$id."";
77: $arr = $this->db->fetchArray($this->db->query($sql));
78: $this->assignVars($arr);
79: }
80:
81: function store()
82: {
83: if ( !$this->cleanVars() ) {
84: return false;
85: }
86: foreach ( $this->cleanVars as $k=>$v ) {
87: $$k = $v;
88: }
89: $isnew = false;
90: if ( empty($comment_id ) ) {
91: $isnew = true;
92: $comment_id = $this->db->genId($this->ctable."_comment_id_seq");
93: $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);
94: } else {
95: $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);
96: }
97: if ( !$result = $this->db->query($sql) ) {
98:
99: return false;
100: }
101: if ( empty($comment_id) ) {
102: $comment_id = $this->db->getInsertId();
103: }
104: if ( $isnew != false ) {
105: $sql = sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u", $this->db->prefix("users"), $user_id);
106: if (!$result = $this->db->query($sql)) {
107: echo "Could not update user posts.";
108: }
109: }
110: return $comment_id;
111: }
112:
113: function delete()
114: {
115: $sql = sprintf("DELETE FROM %s WHERE comment_id = %u", $this->ctable, $this->getVar('comment_id'));
116: if ( !$result = $this->db->query($sql) ) {
117: return false;
118: }
119: $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $this->getVar("user_id"));
120: if ( !$result = $this->db->query($sql) ) {
121: echo "Could not update user posts.";
122: }
123: $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
124: $arr = $mytree->getAllChild($this->getVar("comment_id"), "comment_id");
125: $size = count($arr);
126: if ( $size > 0 ) {
127: for ( $i = 0; $i < $size; $i++ ) {
128: $sql = sprintf("DELETE FROM %s WHERE comment_bid = %u", $this->ctable, $arr[$i]['comment_id']);
129: if ( !$result = $this->db->query($sql) ) {
130: echo "Could not delete comment.";
131: }
132: $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $arr[$i]['user_id']);
133: if ( !$result = $this->db->query($sql) ) {
134: echo "Could not update user posts.";
135: }
136: }
137: }
138: return ($size + 1);
139: }
140:
141: function &getCommentTree()
142: {
143: $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
144: $ret = array();
145: $tarray = $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id");
146: foreach ( $tarray as $ele ) {
147: $ret[] = new XoopsComments($this->ctable,$ele);
148: }
149: return $ret;
150: }
151:
152: function getAllComments($criteria=array(), $asobject=true, $orderby="comment_id ASC", $limit=0, $start=0)
153: {
154: $ret = array();
155: $where_query = "";
156: if ( is_array($criteria) && count($criteria) > 0 ) {
157: $where_query = " WHERE";
158: foreach ( $criteria as $c ) {
159: $where_query .= " $c AND";
160: }
161: $where_query = substr($where_query, 0, -4);
162: }
163: if ( !$asobject ) {
164: $sql = "SELECT comment_id FROM ".$this->ctable."$where_query ORDER BY $orderby";
165: $result = $this->db->query($sql,$limit,$start);
166: while ( $myrow = $this->db->fetchArray($result) ) {
167: $ret[] = $myrow['comment_id'];
168: }
169: } else {
170: $sql = "SELECT * FROM ".$this->ctable."".$where_query." ORDER BY $orderby";
171: $result = $this->db->query($sql,$limit,$start);
172: while ( $myrow = $this->db->fetchArray($result) ) {
173: $ret[] = new XoopsComments($this->ctable,$myrow);
174: }
175: }
176:
177: return $ret;
178: }
179:
180:
181: function printNavBar($item_id, $mode="flat", $order=1)
182: {
183: global $xoopsConfig, $xoopsUser;
184: 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'";
185: if ( $mode == "nocomments" ) {
186: echo " selected='selected'";
187: }
188: echo ">". _NOCOMMENTS ."</option><option value='flat'";
189: if ($mode == 'flat') {
190: echo " selected='selected'";
191: }
192: echo ">". _FLAT ."</option><option value='thread'";
193: if ( $mode == "thread" || $mode == "" ) {
194: echo " selected='selected'";
195: }
196: echo ">". _THREADED ."</option></select><select name='order'><option value='0'";
197: if ( $order != 1 ) {
198: echo " selected='selected'";
199: }
200: echo ">". _OLDESTFIRST ."</option><option value='1'";
201: if ( $order == 1 ) {
202: echo " selected='selected'";
203: }
204: echo ">". _NEWESTFIRST ."</option></select><input type='hidden' name='item_id' value='".intval($item_id)."' /><input type='submit' value='". _CM_REFRESH ."' />";
205: if ( $xoopsConfig['anonpost'] == 1 || $xoopsUser ) {
206: if ($mode != "flat" || $mode != "nocomments" || $mode != "thread" ) {
207: $mode = "flat";
208: }
209: echo " <input type='button' onclick='location=\"newcomment.php?item_id=".intval($item_id)."&order=".intval($order)."&mode=".$mode."\"' value='"._CM_POSTCOMMENT."' />";
210: }
211: echo "</td></tr></table></form>";
212: }
213:
214: function showThreadHead()
215: {
216: openThread();
217: }
218:
219: function showThreadPost($order, $mode, $adminview=0, $color_num=1)
220: {
221: global $xoopsConfig, $xoopsUser;
222: $edit_image = "";
223: $reply_image = "";
224: $delete_image = "";
225: $post_date = formatTimestamp($this->getVar("date"),"m");
226: if ( $this->getVar("user_id") != 0 ) {
227: $poster = new XoopsUser($this->getVar("user_id"));
228: if ( !$poster->isActive() ) {
229: $poster = 0;
230: }
231: } else {
232: $poster = 0;
233: }
234: if ( $this->getVar("icon") != null && $this->getVar("icon") != "" ) {
235: $subject_image = "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/subject/".$this->getVar("icon")."' alt='' />";
236: } else {
237: $subject_image = "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/icons/no_posticon.gif' alt='' />";
238: }
239: if ( $adminview ) {
240: $ip_image = "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='".$this->getVar("ip")."' />";
241: } else {
242: $ip_image = "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='' />";
243: }
244: if ( $adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid")) ) {
245: $edit_image = "<a href='editcomment.php?comment_id=".$this->getVar("comment_id")."&mode=".$mode."&order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/edit.gif' alt='"._EDIT."' /></a>";
246: }
247: if ( $xoopsConfig['anonpost'] || $xoopsUser ) {
248: $reply_image = "<a href='replycomment.php?comment_id=".$this->getVar("comment_id")."&mode=".$mode."&order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/reply.gif' alt='"._REPLY."' /></a>";
249: }
250: if ( $adminview ) {
251: $delete_image = "<a href='deletecomment.php?comment_id=".$this->getVar("comment_id")."&mode=".$mode."&order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/delete.gif' alt='"._DELETE."' /></a>";
252: }
253:
254: if ( $poster ) {
255: $text = $this->getVar("comment");
256: if ( $poster->getVar("attachsig") ) {
257: $text .= "<p><br />_________________<br />". $poster->user_sig()."</p>";
258: }
259: $reg_date = _CM_JOINED;
260: $reg_date .= formatTimestamp($poster->getVar("user_regdate"),"s");
261: $posts = _CM_POSTS;
262: $posts .= $poster->getVar("posts");
263: $user_from = _CM_FROM;
264: $user_from .= $poster->getVar("user_from");
265: $rank = $poster->rank();
266: if ( $rank['image'] != "" ) {
267: $rank['image'] = "<img src='".XOOPS_UPLOAD_URL."/".$rank['image']."' alt='' />";
268: }
269: $avatar_image = "<img src='".XOOPS_UPLOAD_URL."/".$poster->getVar("user_avatar")."' alt='' />";
270: if ( $poster->isOnline() ) {
271: $online_image = "<span style='color:#ee0000;font-weight:bold;'>"._ONLINE."</span>";
272: } else {
273: $online_image = "";
274: }
275: $profile_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/profile.gif' alt='"._PROFILE."' /></a>";
276: if ( $xoopsUser ) {
277: $pm_image = "<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/pmlite.php?send2=1&to_userid=".$poster->getVar("uid")."\",\"pmlite\",450,370);'><img src='".XOOPS_URL."/images/icons/pm.gif' alt='".sprintf(_SENDPMTO,$poster->getVar("uname", "E"))."' /></a>";
278: } else {
279: $pm_image = "";
280: }
281: if ( $poster->getVar("user_viewemail") ) {
282: $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>";
283: } else {
284: $email_image = "";
285: }
286: $posterurl = $poster->getVar("url");
287: if ( $posterurl != "" ) {
288: $www_image = "<a href='$posterurl' rel='external'><img src='".XOOPS_URL."/images/icons/www.gif' alt='"._VISITWEBSITE."' /></a>";
289: } else {
290: $www_image = "";
291: }
292: if ( $poster->getVar("user_icq") != "" ) {
293: $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>";
294: } else {
295: $icq_image = "";
296: }
297: if ( $poster->getVar("user_aim") != "" ) {
298: $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>";
299: } else {
300: $aim_image = "";
301: }
302: if ( $poster->getVar("user_yim") != "" ) {
303: $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>";
304: } else {
305: $yim_image = "";
306: }
307: if ( $poster->getVar("user_msnm") != "" ) {
308: $msnm_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/msnm.gif' alt='msnm' /></a>";
309: } else {
310: $msnm_image = "";
311: }
312: 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);
313: } else {
314: showThread($color_num, $subject_image, $this->getVar("subject"), $this->getVar("comment"), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']);
315: }
316: }
317:
318: function showThreadFoot()
319: {
320: closeThread();
321: }
322:
323: function showTreeHead($width="100%")
324: {
325: 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>";
326: }
327:
328: function showTreeItem($order, $mode, $color_num)
329: {
330: if ( $color_num == 1 ) {
331: $bg = 'even';
332: } else {
333: $bg = 'odd';
334: }
335: $prefix = str_replace(".", " ", $this->getVar("prefix"));
336: $date = formatTimestamp($this->getVar("date"),"m");
337: if ( $this->getVar("icon") != "" ) {
338: $icon = "subject/".$this->getVar("icon", "E");
339: } else {
340: $icon = "icons/no_posticon.gif";
341: }
342: echo "<tr class='$bg' align='left'><td>".$prefix."<img src='".XOOPS_URL."/images/".$icon."'> <a href='".xoops_getenv('PHP_SELF')."?item_id=".$this->getVar("item_id")."&comment_id=".$this->getVar("comment_id")."&mode=".$mode."&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>";
343: }
344:
345: function showTreeFoot()
346: {
347: echo "</table><br />";
348: }
349: }
350: ?>