27 public $use_permission=
false;
30 public function __construct($table, $topicid=0)
32 $this->db =& Database::getInstance();
33 $this->table = $table;
34 if (is_array($topicid)) {
35 $this->makeTopic($topicid);
36 } elseif (0 !== $topicid) {
37 $this->getTopic((
int)$topicid);
39 $this->topic_id = $topicid;
42 public function XoopsTopic($table, $topicid=0)
44 return $this->__construct($table, $topicid);
47 public function setTopicTitle($value)
49 $this->topic_title = $value;
52 public function setTopicImgurl($value)
54 $this->topic_imgurl = $value;
57 public function setTopicPid($value)
59 $this->topic_pid = $value;
62 public function getTopic($topicid)
64 $sql =
'SELECT * FROM ' . $this->table .
' WHERE topic_id=' . $topicid .
'';
65 $array = $this->db->fetchArray($this->db->query($sql));
66 $this->makeTopic($array);
69 public function makeTopic($array)
71 foreach ($array as $key=>$value) {
76 public function usePermission($mid)
79 $this->use_permission =
true;
82 public function store()
87 if (isset($this->topic_title) &&
'' !== $this->topic_title) {
88 $title = $myts->makeTboxData4Save($this->topic_title);
90 if (isset($this->topic_imgurl) &&
'' !== $this->topic_imgurl) {
91 $imgurl = $myts->makeTboxData4Save($this->topic_imgurl);
93 if (!isset($this->topic_pid) || !is_numeric($this->topic_pid)) {
96 if (empty($this->topic_id)) {
97 $this->topic_id = $this->db->genId($this->table .
'_topic_id_seq');
98 $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);
100 $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);
102 if (!$result = $this->db->query($sql)) {
103 (
new ErrorHandler)->show(
'0022');
105 if (
true == $this->use_permission) {
106 if (empty($this->topic_id)) {
107 $this->topic_id = $this->db->getInsertId();
109 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
110 $parent_topics = $xt->getAllParentId($this->topic_id);
111 if (!empty($this->m_groups) && is_array($this->m_groups)) {
112 foreach ($this->m_groups as $m_g) {
113 $moderate_topics = XoopsPerms::getPermitted($this->mid,
'ModInTopic', $m_g);
116 foreach ($parent_topics as $p_topic) {
117 if (!in_array($p_topic, $moderate_topics,
true)) {
123 $xp =
new XoopsPerms();
124 $xp->setModuleId($this->mid);
125 $xp->setName(
'ModInTopic');
126 $xp->setItemId($this->topic_id);
132 if (!empty($this->s_groups) && is_array($this->s_groups)) {
133 foreach ($s_groups as $s_g) {
134 $submit_topics = XoopsPerms::getPermitted($this->mid,
'SubmitInTopic', $s_g);
136 foreach ($parent_topics as $p_topic) {
137 if (!in_array($p_topic, $submit_topics,
true)) {
143 $xp =
new XoopsPerms();
144 $xp->setModuleId($this->mid);
145 $xp->setName(
'SubmitInTopic');
146 $xp->setItemId($this->topic_id);
152 if (!empty($this->r_groups) && is_array($this->r_groups)) {
153 foreach ($r_groups as $r_g) {
154 $read_topics = XoopsPerms::getPermitted($this->mid,
'ReadInTopic', $r_g);
156 foreach ($parent_topics as $p_topic) {
157 if (!in_array($p_topic, $read_topics,
true)) {
163 $xp =
new XoopsPerms();
164 $xp->setModuleId($this->mid);
165 $xp->setName(
'ReadInTopic');
166 $xp->setItemId($this->topic_id);
176 public function delete()
178 $sql = sprintf(
'DELETE FROM %s WHERE topic_id = %u', $this->table, $this->topic_id);
179 $this->db->query($sql);
182 public function topic_id()
184 return $this->topic_id;
187 public function topic_pid()
189 return $this->topic_pid;
192 public function topic_title($format=
'S')
197 $title = $myts->makeTboxData4Show($this->topic_title);
200 $title = $myts->makeTboxData4Edit($this->topic_title);
203 $title = $myts->makeTboxData4Preview($this->topic_title);
206 $title = $myts->makeTboxData4PreviewInForm($this->topic_title);
212 public function topic_imgurl($format=
'S')
217 $imgurl= $myts->makeTboxData4Show($this->topic_imgurl);
220 $imgurl = $myts->makeTboxData4Edit($this->topic_imgurl);
223 $imgurl = $myts->makeTboxData4Preview($this->topic_imgurl);
226 $imgurl = $myts->makeTboxData4PreviewInForm($this->topic_imgurl);
232 public function prefix()
234 if (isset($this->prefix)) {
235 return $this->prefix;
239 public function getFirstChildTopics()
242 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
243 $topic_arr = $xt->getFirstChild($this->topic_id,
'topic_title');
244 if (is_array($topic_arr) && count($topic_arr)) {
245 foreach ($topic_arr as $topic) {
246 $ret[] =
new XoopsTopic($this->table, $topic);
252 public function getAllChildTopics()
255 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
256 $topic_arr = $xt->getAllChild($this->topic_id,
'topic_title');
257 if (is_array($topic_arr) && count($topic_arr)) {
258 foreach ($topic_arr as $topic) {
259 $ret[] =
new XoopsTopic($this->table, $topic);
265 public function getChildTopicsTreeArray()
268 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
269 $topic_arr = $xt->getChildTreeArray($this->topic_id,
'topic_title');
270 if (is_array($topic_arr) && count($topic_arr)) {
271 foreach ($topic_arr as $topic) {
272 $ret[] =
new XoopsTopic($this->table, $topic);
278 public function makeTopicSelBox($none=0, $seltopic=-1, $selname=
'', $onchange=
'')
280 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
281 if (-1 !== $seltopic) {
282 $xt->makeMySelBox(
'topic_title',
'topic_title', $seltopic, $none, $selname, $onchange);
283 } elseif (!empty($this->topic_id)) {
284 $xt->makeMySelBox(
'topic_title',
'topic_title', $this->topic_id, $none, $selname, $onchange);
286 $xt->makeMySelBox(
'topic_title',
'topic_title', 0, $none, $selname, $onchange);
291 public function getNiceTopicPathFromId($funcURL)
293 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
294 $ret = $xt->getNicePathFromId($this->topic_id,
'toppic_title', $funcURL);
298 public function getAllChildTopicsId()
300 $xt =
new XoopsTree($this->table,
'topic_id',
'topic_pid');
301 $ret = $xt->getAllChildId($this->topic_id,
'toppic_title');
305 public function &getTopicsList()
307 $result = $this->db->query(
'SELECT topic_id, topic_pid, topic_title FROM '.$this->table);
310 while ($myrow = $this->db->fetchArray($result)) {
311 $ret[$myrow[
'topic_id']] = [
'title' => $myts->htmlSpecialChars($myrow[
'topic_title']),
'pid' => $myrow[
'topic_pid']];
316 public function topicExists($pid, $title)
318 $sql =
'SELECT COUNT(*) from ' . $this->table .
' WHERE topic_pid = ' . (int)$pid .
" AND topic_title = '" . trim($title) .
"'";
319 $rs = $this->db->query($sql);
320 list($count) = $this->db->fetchRow($rs);