C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RU7MSUA\html\class\xoopscomments.php


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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
// $Id: xoopscomments.php,v 1.13.6.4 2005/07/19 18:14:30 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program 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.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program 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 this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
    exit();
}
include_once 
XOOPS_ROOT_PATH."/class/xoopstree.php";
require_once 
XOOPS_ROOT_PATH.'/class/xoopsobject.php';
include_once 
XOOPS_ROOT_PATH.'/language/'.$GLOBALS['xoopsConfig']['language'].'/comment.php';

class 
XoopsComments extends XoopsObject
{
    var 
$ctable;
    var 
$db;

    function 
XoopsComments($ctable$id=null)
    {
        
$this->ctable $ctable;
        
$this->db =& Database::getInstance();
        
$this->XoopsObject();
        
$this->initVar('comment_id'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('item_id'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('order'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('mode'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('subject'XOBJ_DTYPE_TXTBOXnullfalse255);
        
$this->initVar('comment'XOBJ_DTYPE_TXTAREAnullfalsenull);
        
$this->initVar('ip'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('pid'XOBJ_DTYPE_INT0false);
        
$this->initVar('date'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('nohtml'XOBJ_DTYPE_INT1false);
        
$this->initVar('nosmiley'XOBJ_DTYPE_INT0false);
        
$this->initVar('noxcode'XOBJ_DTYPE_INT0false);
        
$this->initVar('user_id'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('icon'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('prefix'XOBJ_DTYPE_OTHERnullfalse);
        if ( !empty(
$id) ) {
            if ( 
is_array($id) ) {
                
$this->assignVars($id);
            } else {
                
$this->load(intval($id));
            }
        }
    }

    function 
load($id)
    {
        
$sql "SELECT * FROM ".$this->ctable." WHERE comment_id=".$id."";
        
$arr $this->db->fetchArray($this->db->query($sql));
        
$this->assignVars($arr);
    }

    function 
store()
    {
        if ( !
$this->cleanVars() ) {
            return 
false;
        }
        foreach ( 
$this->cleanVars as $k=>$v ) {
            $
$k $v;
        }
        
$isnew false;
        if ( empty(
$comment_id ) ) {
            
$isnew true;
            
$comment_id $this->db->genId($this->ctable."_comment_id_seq");
            
$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_idtime(), $user_id$ip$subject$comment$nohtml$nosmiley$noxcode$icon);
        } else {
            
$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);
        }
        if ( !
$result $this->db->query($sql) ) {
            
//echo $sql;
            
return false;
        }
        if ( empty(
$comment_id) ) {
            
$comment_id $this->db->getInsertId();
        }
        if ( 
$isnew != false ) {
            
$sql sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u"$this->db->prefix("users"), $user_id);
            if (!
$result $this->db->query($sql)) {
                echo 
"Could not update user posts.";
            }
        }
        return 
$comment_id;
    }

    function 
delete()
    {
        
$sql sprintf("DELETE FROM %s WHERE comment_id = %u"$this->ctable$this->getVar('comment_id'));
        if ( !
$result $this->db->query($sql) ) {
            return 
false;
        }
        
$sql sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u"$this->db->prefix("users"), $this->getVar("user_id"));
        if ( !
$result $this->db->query($sql) ) {
            echo 
"Could not update user posts.";
        }
        
$mytree = new XoopsTree($this->ctable"comment_id""pid");
        
$arr $mytree->getAllChild($this->getVar("comment_id"), "comment_id");
        
$size count($arr);
        if ( 
$size ) {
            for ( 
$i 0$i $size$i++ ) {
                
$sql sprintf("DELETE FROM %s WHERE comment_bid = %u"$this->ctable$arr[$i]['comment_id']);
                if ( !
$result $this->db->query($sql) ) {
                    echo 
"Could not delete comment.";
                }
                
$sql sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u"$this->db->prefix("users"), $arr[$i]['user_id']);
                if ( !
$result $this->db->query($sql) ) {
                    echo 
"Could not update user posts.";
                }
            }
        }
        return (
$size 1);
    }

    function &
getCommentTree()
    {
        
$mytree = new XoopsTree($this->ctable"comment_id""pid");
        
$ret = array();
        
$tarray $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id");
        foreach ( 
$tarray as $ele ) {
            
$ret[] = new XoopsComments($this->ctable,$ele);
        }
        return 
$ret;
    }

    function 
getAllComments($criteria=array(), $asobject=true$orderby="comment_id ASC"$limit=0$start=0)
    {
        
$ret = array();
        
$where_query "";
        if ( 
is_array($criteria) && count($criteria) > ) {
            
$where_query " WHERE";
            foreach ( 
$criteria as $c ) {
                
$where_query .= $c AND";
            }
            
$where_query substr($where_query0, -4);
        }
        if ( !
$asobject ) {
            
$sql "SELECT comment_id FROM ".$this->ctable."$where_query ORDER BY $orderby";
            
$result $this->db->query($sql,$limit,$start);
            while ( 
$myrow $this->db->fetchArray($result) ) {
                
$ret[] = $myrow['comment_id'];
            }
        } else {
            
$sql "SELECT * FROM ".$this->ctable."".$where_query." ORDER BY $orderby";
            
$result $this->db->query($sql,$limit,$start);
            while ( 
$myrow $this->db->fetchArray($result) ) {
                
$ret[] = new XoopsComments($this->ctable,$myrow);
            }
        }
        
//echo $sql;
        
return $ret;
    }

    
/* Methods below will be moved to maybe another class? */
    
function printNavBar($item_id$mode="flat"$order=1)
    {
        global 
$xoopsConfig$xoopsUser;
        
$url parse_url($_SERVER['REQUEST_URI']);
        echo 
"<form method='get' action='".$url['path']."'><table width='100%' border='0' cellspacing='1' cellpadding='2'><tr><td class='bg1' align='center'><select name='mode'><option value='nocomments'";
        if ( 
$mode == "nocomments" ) {
            echo 
" selected='selected'";
        }
        echo 
">"_NOCOMMENTS ."</option><option value='flat'";
        if (
$mode == 'flat') {
            echo 
" selected='selected'";
        }
        echo 
">"_FLAT ."</option><option value='thread'";
        if ( 
$mode == "thread" || $mode == "" ) {
            echo 
" selected='selected'";
        }
        echo 
">"_THREADED ."</option></select><select name='order'><option value='0'";
        if ( 
$order != ) {
            echo 
" selected='selected'";
        }
        echo 
">"_OLDESTFIRST ."</option><option value='1'";
        if ( 
$order == ) {
            echo 
" selected='selected'";
        }
        echo 
">"_NEWESTFIRST ."</option></select><input type='hidden' name='item_id' value='".intval($item_id)."' /><input type='submit' value='"_CM_REFRESH ."' />";
        if ( 
$xoopsConfig['anonpost'] == || $xoopsUser ) {
            if (
$mode != "flat" || $mode != "nocomments" || $mode != "thread" ) {
                
$mode "flat";
            }
            echo 
"&nbsp;<input type='button' onclick='location=\"newcomment.php?item_id=".intval($item_id)."&amp;order=".intval($order)."&amp;mode=".$mode."\"' value='"._CM_POSTCOMMENT."' />";
        }
        echo 
"</td></tr></table></form>";
    }

    function 
showThreadHead()
    {
        
openThread();
    }

    function 
showThreadPost($order$mode$adminview=0$color_num=1)
    {
        global 
$xoopsConfig$xoopsUser;
        
$edit_image "";
        
$reply_image "";
        
$delete_image "";
        
$post_date formatTimestamp($this->getVar("date"),"m");
        if ( 
$this->getVar("user_id") != ) {
            
$poster = new XoopsUser($this->getVar("user_id"));
            if ( !
$poster->isActive() ) {
                
$poster 0;
            }
        } else {
            
$poster 0;
        }
        if ( 
$this->getVar("icon") != null && $this->getVar("icon") != "" ) {
            
$subject_image "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/subject/".$this->getVar("icon")."' alt='' />";
        } else {
            
$subject_image =  "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/icons/no_posticon.gif' alt='' />";
        }
        if ( 
$adminview ) {
            
$ip_image "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='".$this->getVar("ip")."' />";
        } else {
            
$ip_image "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='' />";
        }
        if ( 
$adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid")) ) {
            
$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>";
        }
        if ( 
$xoopsConfig['anonpost'] || $xoopsUser ) {
            
$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>";
        }
        if ( 
$adminview ) {
            
$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>";
        }

        if ( 
$poster ) {
            
$text $this->getVar("comment");
            if ( 
$poster->getVar("attachsig") ) {
                
$text .= "<p><br />_________________<br />"$poster->user_sig()."</p>";
            }
            
$reg_date _CM_JOINED;
            
$reg_date .= formatTimestamp($poster->getVar("user_regdate"),"s");
            
$posts _CM_POSTS;
            
$posts .= $poster->getVar("posts");
            
$user_from _CM_FROM;
            
$user_from .= $poster->getVar("user_from");
            
$rank $poster->rank();
            if ( 
$rank['image'] != "" ) {
                
$rank['image'] = "<img src='".XOOPS_UPLOAD_URL."/".$rank['image']."' alt='' />";
            }
            
$avatar_image "<img src='".XOOPS_UPLOAD_URL."/".$poster->getVar("user_avatar")."' alt='' />";
            if ( 
$poster->isOnline() ) {
                
$online_image "<span style='color:#ee0000;font-weight:bold;'>"._ONLINE."</span>";
            } else {
                
$online_image "";
            }
            
$profile_image "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/profile.gif' alt='"._PROFILE."' /></a>";
            if ( 
$xoopsUser ) {
                
$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>";
            } else {
                
$pm_image "";
            }
               if ( 
$poster->getVar("user_viewemail") ) {
                
$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>";
            } else {
                
$email_image "";
            }
            
$posterurl $poster->getVar("url");
               if ( 
$posterurl != "" ) {
                
$www_image "<a href='$posterurl' target='_blank'><img src='".XOOPS_URL."/images/icons/www.gif' alt='"._VISITWEBSITE."' /></a>";
            } else {
                
$www_image "";
            }
               if ( 
$poster->getVar("user_icq") != "" ) {
                
$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>";
            } else {
                
$icq_image "";
            }
            if ( 
$poster->getVar("user_aim") != "" ) {
                
$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>";
            } else {
                
$aim_image "";
            }
               if ( 
$poster->getVar("user_yim") != "" ) {
                
$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>";
            } else {
                
$yim_image "";
            }
            if ( 
$poster->getVar("user_msnm") != "" ) {
                
$msnm_image "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/msnm.gif' alt='msnm' /></a>";
            } else {
                
$msnm_image "";
            }
            
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);
        } else {
            
showThread($color_num$subject_image$this->getVar("subject"), $this->getVar("comment"), $post_date$ip_image$reply_image$edit_image$delete_image$xoopsConfig['anonymous']);
        }
    }

    function 
showThreadFoot()
    {
        
closeThread();
    }

    function 
showTreeHead($width="100%")
    {
        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>";
    }

    function 
showTreeItem($order$mode$color_num)
    {
        if ( 
$color_num == ) {
            
$bg 'even';
        } else {
            
$bg 'odd';
        }
        
$prefix str_replace(".""&nbsp;&nbsp;&nbsp;&nbsp;"$this->getVar("prefix"));
        
$date formatTimestamp($this->getVar("date"),"m");
        if ( 
$this->getVar("icon") != "" ) {
            
$icon "subject/".$this->getVar("icon""E");
        } else {
            
$icon "icons/no_posticon.gif";
        }
        
$url parse_url($_SERVER['REQUEST_URI']);
        echo 
"<tr class='$bg' align='left'><td>".$prefix."<img src='".XOOPS_URL."/images/".$icon."'>&nbsp;<a href='".$url['path']."?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>";
    }

    function 
showTreeFoot()
    {
        echo 
"</table><br />";
    }
}
?>