XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
xoopscomments.php
1<?php
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17include_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
18require_once XOOPS_ROOT_PATH.'/class/xoopsobject.php';
19
20$root =& XCube_Root::getSingleton();
21$root->mLanguageManager->loadPageTypeMessageCatalog('comment');
22
23
25{
26 public $ctable;
27 public $db;
28
29 public function __construct($ctable, $id=null)
30 {
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);
49 if (!empty($id)) {
50 if (is_array($id)) {
51 $this->assignVars($id);
52 } else {
53 $this->load((int)$id);
54 }
55 }
56 }
57
58 public function load($id)
59 {
60 $sql = 'SELECT * FROM ' . $this->ctable . ' WHERE comment_id=' . $id . '';
61 $arr = $this->db->fetchArray($this->db->query($sql));
62 $this->assignVars($arr);
63 }
64
65 public function store()
66 {
67 if (!$this->cleanVars()) {
68 return false;
69 }
70 foreach ($this->cleanVars as $k=>$v) {
71 $$k = $v;
72 }
73 $isnew = false;
74 if (empty($comment_id)) {
75 $isnew = true;
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);
78 } else {
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);
80 }
81 if (!$result = $this->db->query($sql)) {
82 //echo $sql;
83 return false;
84 }
85 if (empty($comment_id)) {
86 $comment_id = $this->db->getInsertId();
87 }
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.';
92 }
93 }
94 return $comment_id;
95 }
96
97 public function delete()
98 {
99 $sql = sprintf('DELETE FROM %s WHERE comment_id = %u', $this->ctable, $this->getVar('comment_id'));
100 if (!$result = $this->db->query($sql)) {
101 return false;
102 }
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.';
106 }
107 $mytree = new XoopsTree($this->ctable, 'comment_id', 'pid');
108 $arr = $mytree->getAllChild($this->getVar('comment_id'), 'comment_id');
109 $size = count($arr);
110 if ($size > 0) {
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.';
115 }
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.';
119 }
120 }
121 }
122 return ($size + 1);
123 }
124
125 public function &getCommentTree()
126 {
127 $mytree = new XoopsTree($this->ctable, 'comment_id', 'pid');
128 $ret = [];
129 $tarray = $mytree->getChildTreeArray($this->getVar('comment_id'), 'comment_id');
130 foreach ($tarray as $ele) {
131 $ret[] = new XoopsComments($this->ctable, $ele);
132 }
133 return $ret;
134 }
135
136 public function getAllComments($criteria= [], $asobject=true, $orderby= 'comment_id ASC', $limit=0, $start=0)
137 {
138 $ret = [];
139 $where_query = '';
140 if (is_array($criteria) && count($criteria) > 0) {
141 $where_query = ' WHERE';
142 foreach ($criteria as $c) {
143 $where_query .= " $c AND";
144 }
145 $where_query = substr($where_query, 0, -4);
146 }
147 if (!$asobject) {
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'];
152 }
153 } else {
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)) {
157 $ret[] = new XoopsComments($this->ctable, $myrow);
158 }
159 }
160 //echo $sql;
161 return $ret;
162 }
163
164 /* Methods below will be moved to maybe another class? */
165 public function printNavBar($item_id, $mode= 'flat', $order=1)
166 {
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'";
171 }
172 echo '>' . _NOCOMMENTS . "</option><option value='flat'";
173 if ('flat' == $mode) {
174 echo " selected='selected'";
175 }
176 echo '>' . _FLAT . "</option><option value='thread'";
177 if ('thread' == $mode || '' == $mode) {
178 echo " selected='selected'";
179 }
180 echo '>' . _THREADED . "</option></select><select name='order'><option value='0'";
181 if (1 !== $order) {
182 echo " selected='selected'";
183 }
184 echo '>' . _OLDESTFIRST . "</option><option value='1'";
185 if (1 == $order) {
186 echo " selected='selected'";
187 }
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) {
191 $mode = 'flat';
192 }
193 echo "&nbsp;<input type='button' onclick='location=\"newcomment.php?item_id=" . (int)$item_id . '&amp;order=' . (int)$order . '&amp;mode=' . $mode . "\"' value='" . _CM_POSTCOMMENT . "' />";
194 }
195 echo '</td></tr></table></form>';
196 }
197
198 public function showThreadHead()
199 {
200 openThread();
201 }
202
203 public function showThreadPost($order, $mode, $adminview=0, $color_num=1)
204 {
205 global $xoopsConfig, $xoopsUser;
206 $edit_image = '';
207 $reply_image = '';
208 $delete_image = '';
209 $post_date = formatTimestamp($this->getVar('date'), 'm');
210 if (0 !== $this->getVar('user_id')) {
211 $poster = new XoopsUser($this->getVar('user_id'));
212 if (!$poster->isActive()) {
213 $poster = 0;
214 }
215 } else {
216 $poster = 0;
217 }
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=''>";
220 } else {
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=''>";
222 }
223 if ($adminview) {
224 $ip_image = "<img class='svg' src='".XOOPS_URL."/images/icons/ip-network.svg' alt='".$this->getVar('ip') . "'>";
225 } else {
226 $ip_image = "<img class='svg' src='".XOOPS_URL."/images/icons/ip-network.svg' alt=''>";
227 }
228 if ($adminview || ($xoopsUser && $this->getVar('user_id') == $xoopsUser->getVar('uid'))) {
229 $edit_image = "<a href='editcomment.php?comment_id=".$this->getVar('comment_id') . '&amp;mode=' . $mode . '&amp;order=' . (int)$order . "'><img class='svg' src='" . XOOPS_URL . "/images/icons/edit.svg' alt='" . _EDIT . "'></a>";
230 }
231 if ($xoopsConfig['anonpost'] || $xoopsUser) {
232 $reply_image = "<a href='replycomment.php?comment_id=".$this->getVar('comment_id') . '&amp;mode=' . $mode . '&amp;order=' . (int)$order . "'><img class='svg' src='" . XOOPS_URL . "/images/icons/reply.svg' alt='" . _REPLY . "'></a>";
233 }
234 if ($adminview) {
235 $delete_image = "<a href='deletecomment.php?comment_id=".$this->getVar('comment_id') . '&amp;mode=' . $mode . '&amp;order=' . (int)$order . "'><img class='svg' src='" . XOOPS_URL . "/images/icons/delete.svg' alt='" . _DELETE . "'></a>";
236 }
237
238 if ($poster) {
239 $text = $this->getVar('comment');
240 if ($poster->getVar('attachsig')) {
241 $text .= '<p><br>__________<br>' . $poster->user_sig() . '</p>';
242 }
243 $reg_date = _CM_JOINED;
244 $reg_date .= formatTimestamp($poster->getVar('user_regdate'), 's');
245 $posts = _CM_POSTS;
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=''>";
252 }
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>';
256 } else {
257 $online_image = '';
258 }
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>";
260 if ($xoopsUser) {
261 $pm_image = "<a href='javascript:openWithSelfMain(\"".XOOPS_URL . '/pmlite.php?send2=1&amp;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>";
262 } else {
263 $pm_image = '';
264 }
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>";
267 } else {
268 $email_image = '';
269 }
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>";
273 } else {
274 $www_image = '';
275 }
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>";
278 } else {
279 $icq_image = '';
280 }
281 if ('' !== $poster->getVar('user_aim')) {
282 $aim_image = "<a href='aim:goim?screenname=".$poster->getVar('user_aim', 'E') . '&amp;message=Hi+' . $poster->getVar('user_aim') . "+Are+you+there?'><img class='svg' src='" . XOOPS_URL . "/images/icons/aim.svg' alt='aim'></a>";
283 } else {
284 $aim_image = '';
285 }
286 if ('' !== $poster->getVar('user_yim')) {
287 $yim_image = "<a href='https://edit.yahoo.com/config/send_webmesg?.target=".$poster->getVar('user_yim', 'E') . "&amp;.src=pg'><img class='svg' src='" . XOOPS_URL . "/images/icons/yim.svg' alt='yim'></a>";
288 } else {
289 $yim_image = '';
290 }
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>";
293 } else {
294 $msnm_image = '';
295 }
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);
297 } else {
298 showThread($color_num, $subject_image, $this->getVar('subject'), $this->getVar('comment'), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']);
299 }
300 }
301
302 public function showThreadFoot()
303 {
304 closeThread();
305 }
306
307 public function showTreeHead($width= '100%')
308 {
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>';
310 }
311
312 public function showTreeItem($order, $mode, $color_num)
313 {
314 if (1 == $color_num) {
315 $bg = 'even';
316 } else {
317 $bg = 'odd';
318 }
319 $prefix = str_replace('.', '&nbsp;&nbsp;&nbsp;&nbsp;', $this->getVar('prefix'));
320 $date = formatTimestamp($this->getVar('date'), 'm');
321 if ('' !== $this->getVar('icon')) {
322 $icon = 'subject/' . $this->getVar('icon', 'E');
323 } else {
324 $icon = 'icons/no_posticon.svg';
325 }
326 echo "<tr class='$bg' align='left'><td>".$prefix."<img src='".XOOPS_URL . '/images/'
327 . $icon . "'>&nbsp;<a href='" . xoops_getenv('PHP_SELF') . '?item_id='
328 . $this->getVar('item_id') . '&amp;comment_id='
329 . $this->getVar('comment_id') . '&amp;mode='
330 . $mode . '&amp;order='
331 . $order . '#'
332 . $this->getVar('comment_id') . "'>" . $this->getVar('subject') . "</a></td><td><a href='" . XOOPS_URL . '/userinfo.php?uid='
333 . $this->getVar('user_id') . "'>" . XoopsUser::getUnameFromId($this->getVar('user_id')) . '</a></td><td>'
334 . $date . '</td></tr>';
335 }
336
337 public function showTreeFoot()
338 {
339 echo '</table><br>';
340 }
341}
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206
& getVar($key, $format='s')
Definition object.php:317
assignVars($var_arr)
Definition object.php:232
static getUnameFromId($userid, $usereal=0)
Definition user.php:125