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
|
<?php // $Id: xoopstopic.php,v 1.8 2003/03/27 14:56:17 okazu 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";
class XoopsTopic { var $table; var $topic_id; var $topic_pid; var $topic_title; var $topic_imgurl; var $prefix; // only used in topic tree var $use_permission=false; var $mid; // module id used for setting permission
function XoopsTopic($table, $topicid=0) { $this->db =& Database::getInstance(); $this->table = $table; if ( is_array($topicid) ) { $this->makeTopic($topicid); } elseif ( $topicid != 0 ) { $this->getTopic(intval($topicid)); } else { $this->topic_id = $topicid; } }
function setTopicTitle($value) { $this->topic_title = $value; }
function setTopicImgurl($value) { $this->topic_imgurl = $value; }
function setTopicPid($value) { $this->topic_pid = $value; }
function getTopic($topicid) { $sql = "SELECT * FROM ".$this->table." WHERE topic_id=".$topicid.""; $array = $this->db->fetchArray($this->db->query($sql)); $this->makeTopic($array); }
function makeTopic($array) { foreach($array as $key=>$value){ $this->$key = $value; } }
function usePermission($mid) { $this->mid = $mid; $this->use_permission = true; }
function store() { $myts =& MyTextSanitizer::getInstance(); $title = ""; $imgurl = ""; if ( isset($this->topic_title) && $this->topic_title != "" ) { $title = $myts->makeTboxData4Save($this->topic_title); } if ( isset($this->topic_imgurl) && $this->topic_imgurl != "" ) { $imgurl = $myts->makeTboxData4Save($this->topic_imgurl); } if ( !isset($this->topic_pid) || !is_numeric($this->topic_pid) ) { $this->topic_pid = 0; } if ( empty($this->topic_id) ) { $this->topic_id = $this->db->genId($this->table."_topic_id_seq"); $sql = sprintf("INSERT INTO %s (topic_id, topic_pid, topic_imgurl, topic_title) VALUES (%u, %u, '%s', '%s')", $this->table, $this->topic_id, $this->topic_pid, $imgurl, $title); } else { $sql = sprintf("UPDATE %s SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id); } if ( !$result = $this->db->query($sql) ) { ErrorHandler::show('0022'); } if ( $this->use_permission == true ) { if ( empty($this->topic_id) ) { $this->topic_id = $this->db->getInsertId(); } $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $parent_topics = $xt->getAllParentId($this->topic_id); if ( !empty($this->m_groups) && is_array($this->m_groups) ){ foreach ( $this->m_groups as $m_g ) { $moderate_topics = XoopsPerms::getPermitted($this->mid, "ModInTopic", $m_g); $add = true; // only grant this permission when the group has this permission in all parent topics of the created topic foreach($parent_topics as $p_topic){ if ( !in_array($p_topic, $moderate_topics) ) { $add = false; continue; } } if ( $add == true ) { $xp = new XoopsPerms(); $xp->setModuleId($this->mid); $xp->setName("ModInTopic"); $xp->setItemId($this->topic_id); $xp->store(); $xp->addGroup($m_g); } } } if ( !empty($this->s_groups) && is_array($this->s_groups) ){ foreach ( $s_groups as $s_g ) { $submit_topics = XoopsPerms::getPermitted($this->mid, "SubmitInTopic", $s_g); $add = true; foreach($parent_topics as $p_topic){ if ( !in_array($p_topic, $submit_topics) ) { $add = false; continue; } } if ( $add == true ) { $xp = new XoopsPerms(); $xp->setModuleId($this->mid); $xp->setName("SubmitInTopic"); $xp->setItemId($this->topic_id); $xp->store(); $xp->addGroup($s_g); } } } if ( !empty($this->r_groups) && is_array($this->r_groups) ){ foreach ( $r_groups as $r_g ) { $read_topics = XoopsPerms::getPermitted($this->mid, "ReadInTopic", $r_g); $add = true; foreach($parent_topics as $p_topic){ if ( !in_array($p_topic, $read_topics) ) { $add = false; continue; } } if ( $add == true ) { $xp = new XoopsPerms(); $xp->setModuleId($this->mid); $xp->setName("ReadInTopic"); $xp->setItemId($this->topic_id); $xp->store(); $xp->addGroup($r_g); } } } } return true; }
function delete() { $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->table, $this->topic_id); $this->db->query($sql); }
function topic_id() { return $this->topic_id; }
function topic_pid() { return $this->topic_pid; }
function topic_title($format="S") { $myts =& MyTextSanitizer::getInstance(); switch($format){ case "S": $title = $myts->makeTboxData4Show($this->topic_title); break; case "E": $title = $myts->makeTboxData4Edit($this->topic_title); break; case "P": $title = $myts->makeTboxData4Preview($this->topic_title); break; case "F": $title = $myts->makeTboxData4PreviewInForm($this->topic_title); break; } return $title; }
function topic_imgurl($format="S") { $myts =& MyTextSanitizer::getInstance(); switch($format){ case "S": $imgurl= $myts->makeTboxData4Show($this->topic_imgurl); break; case "E": $imgurl = $myts->makeTboxData4Edit($this->topic_imgurl); break; case "P": $imgurl = $myts->makeTboxData4Preview($this->topic_imgurl); break; case "F": $imgurl = $myts->makeTboxData4PreviewInForm($this->topic_imgurl); break; } return $imgurl; }
function prefix() { if ( isset($this->prefix) ) { return $this->prefix; } }
function getFirstChildTopics() { $ret = array(); $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $topic_arr = $xt->getFirstChild($this->topic_id, "topic_title"); if ( is_array($topic_arr) && count($topic_arr) ) { foreach($topic_arr as $topic){ $ret[] = new XoopsTopic($this->table, $topic); } } return $ret; }
function getAllChildTopics() { $ret = array(); $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $topic_arr = $xt->getAllChild($this->topic_id, "topic_title"); if ( is_array($topic_arr) && count($topic_arr) ) { foreach($topic_arr as $topic){ $ret[] = new XoopsTopic($this->table, $topic); } } return $ret; }
function getChildTopicsTreeArray() { $ret = array(); $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $topic_arr = $xt->getChildTreeArray($this->topic_id, "topic_title"); if ( is_array($topic_arr) && count($topic_arr) ) { foreach($topic_arr as $topic){ $ret[] = new XoopsTopic($this->table, $topic); } } return $ret; }
function makeTopicSelBox($none=0, $seltopic=-1, $selname="", $onchange="") { $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); if ( $seltopic != -1 ) { $xt->makeMySelBox("topic_title", "topic_title", $seltopic, $none, $selname, $onchange); } elseif ( !empty($this->topic_id) ) { $xt->makeMySelBox("topic_title", "topic_title", $this->topic_id, $none, $selname, $onchange); } else { $xt->makeMySelBox("topic_title", "topic_title", 0, $none, $selname, $onchange); } }
//generates nicely formatted linked path from the root id to a given id function getNiceTopicPathFromId($funcURL) { $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $ret = $xt->getNicePathFromId($this->topic_id, "toppic_title", $funcURL); return $ret; }
function getAllChildTopicsId() { $xt = new XoopsTree($this->table, "topic_id", "topic_pid"); $ret = $xt->getAllChildId($this->topic_id, "toppic_title"); return $ret; }
function &getTopicsList() { $result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM '.$this->table); $ret = array(); $myts =& MyTextSanitizer::getInstance(); while ($myrow = $this->db->fetchArray($result)) { $ret[$myrow['topic_id']] = array('title' => $myts->htmlspecialchars($myrow['topic_title']), 'pid' => $myrow['topic_pid']); } return $ret; }
function topicExists($pid, $title) { $sql = "SELECT COUNT(*) from ".$this->table." WHERE topic_pid = ".intval($pid)." AND topic_title = '".trim($title)."'"; $rs = $this->db->query($sql); list($count) = $this->db->fetchRow($rs); if ($count > 0) { return true; } else { return false; } } } ?>
|