1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
// |
6
|
|
|
// ------------------------------------------------------------------------ // |
7
|
|
|
// XOOPS - PHP Content Management System // |
8
|
|
|
// Copyright (c) 2000-2020 XOOPS.org // |
9
|
|
|
// <https://xoops.org> // |
10
|
|
|
// ------------------------------------------------------------------------ // |
11
|
|
|
// This program is free software; you can redistribute it and/or modify // |
12
|
|
|
// it under the terms of the GNU General Public License as published by // |
13
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
14
|
|
|
// (at your option) any later version. // |
15
|
|
|
// // |
16
|
|
|
// You may not change or alter any portion of this comment or credits // |
17
|
|
|
// of supporting developers from this source code or any supporting // |
18
|
|
|
// source code which is considered copyrighted (c) material of the // |
19
|
|
|
// original comment or credit authors. // |
20
|
|
|
// // |
21
|
|
|
// This program is distributed in the hope that it will be useful, // |
22
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
23
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
24
|
|
|
// GNU General Public License for more details. // |
25
|
|
|
// // |
26
|
|
|
// You should have received a copy of the GNU General Public License // |
27
|
|
|
// along with this program; if not, write to the Free Software // |
28
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
29
|
|
|
// ------------------------------------------------------------------------ // |
30
|
|
|
// Author: phppp (D.J., [email protected]) // |
31
|
|
|
// URL: https://xoops.org // |
32
|
|
|
// Project: Article Project // |
33
|
|
|
// ------------------------------------------------------------------------ // |
34
|
|
|
|
35
|
|
|
use XoopsModules\Newbb; |
36
|
|
|
|
37
|
|
|
require_once __DIR__ . '/Read.php'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* A handler for read/unread handling |
41
|
|
|
* |
42
|
|
|
* @package newbb |
43
|
|
|
* |
44
|
|
|
* @author D.J. (phppp, http://xoopsforge.com) |
45
|
|
|
* @copyright copyright (c) 2005 XOOPS.org |
46
|
|
|
*/ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Class ReadforumHandler |
50
|
|
|
*/ |
51
|
|
|
class ReadforumHandler extends Newbb\ReadHandler |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* @param \XoopsDatabase|null $db |
55
|
|
|
*/ |
56
|
|
|
public function __construct(\XoopsDatabase $db = null) |
57
|
|
|
{ |
58
|
|
|
parent::__construct($db, 'forum'); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* clean orphan items from database |
63
|
|
|
* |
64
|
|
|
* @param string $table_link |
65
|
|
|
* @param string $field_link |
66
|
|
|
* @param string $field_object |
67
|
|
|
* @return bool true on success |
68
|
|
|
*/ |
69
|
|
|
public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
70
|
|
|
{ |
71
|
|
|
parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
72
|
|
|
|
73
|
|
|
return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param int $status |
78
|
|
|
* @param null $uid |
|
|
|
|
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function setReadItems($status = 0, $uid = null) |
82
|
|
|
{ |
83
|
|
|
if (empty($this->mode)) { |
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (1 == $this->mode) { |
88
|
|
|
return $this->setReadItemsCookie($status); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $this->setReadItemsDb($status, $uid); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param $status |
96
|
|
|
* @param $items |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function setReadItemsCookie($status, $items) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$cookie_name = 'LF'; |
102
|
|
|
$items = []; |
103
|
|
|
if (!empty($status)) { |
104
|
|
|
/** @var Newbb\ForumHandler $itemHandler */ |
105
|
|
|
$itemHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
106
|
|
|
$items_id = $itemHandler->getIds(); |
107
|
|
|
foreach ($items_id as $key) { |
108
|
|
|
$items[$key] = \time(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
\newbbSetCookie($cookie_name, $items); |
112
|
|
|
|
113
|
|
|
return true; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param $status |
118
|
|
|
* @param $uid |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public function setReadItemsDb($status, $uid) |
122
|
|
|
{ |
123
|
|
|
if (empty($uid)) { |
124
|
|
|
if (\is_object($GLOBALS['xoopsUser'])) { |
125
|
|
|
$uid = $GLOBALS['xoopsUser']->getVar('uid'); |
126
|
|
|
} else { |
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
if (empty($status)) { |
131
|
|
|
$this->deleteAll(new \Criteria('uid', $uid)); |
132
|
|
|
|
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** @var Newbb\ForumHandler $itemHandler */ |
137
|
|
|
$itemHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
138
|
|
|
$itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']); |
139
|
|
|
foreach (\array_keys($itemsObject) as $key) { |
140
|
|
|
$this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid); |
141
|
|
|
} |
142
|
|
|
unset($itemsObject); |
143
|
|
|
|
144
|
|
|
return true; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return bool|void |
149
|
|
|
*/ |
150
|
|
|
public function synchronization() |
151
|
|
|
{ |
152
|
|
|
// return; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|