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