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