|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
6
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
7
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
8
|
|
|
* @since 4.00 |
|
9
|
|
|
* @package module::newbb |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use XoopsModules\Newbb; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
defined('NEWBB_FUNCTIONS_INI') || require __DIR__ . '/functions.ini.php'; |
|
17
|
|
|
define('NEWBB_FUNCTIONS_STATS_LOADED', true); |
|
18
|
|
|
|
|
19
|
|
|
if (!defined('NEWBB_FUNCTIONS_STATS')) { |
|
20
|
|
|
define('NEWBB_FUNCTIONS_STATS', 1); |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return mixed |
|
24
|
|
|
*/ |
|
25
|
|
|
function newbbGetStats() |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var Newbb\StatsHandler $statsHandler */ |
|
28
|
|
|
$statsHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Stats'); |
|
29
|
|
|
$stats = $statsHandler->getStats(); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
return $stats; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param $id |
|
36
|
|
|
* @param $type |
|
37
|
|
|
* @param int $increment |
|
38
|
|
|
* @return mixed |
|
39
|
|
|
*/ |
|
40
|
|
|
function newbbUpdateStats($id, $type, $increment = 1) |
|
41
|
|
|
{ |
|
42
|
|
|
/** @var Newbb\StatsHandler $statsHandler */ |
|
43
|
|
|
$statsHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Stats'); |
|
44
|
|
|
|
|
45
|
|
|
return $statsHandler->update($id, $type, $increment); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/* |
|
49
|
|
|
* Gets the total number of topics in a form |
|
50
|
|
|
*/ |
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $forum_id |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
function getTotalTopics($forum_id = '') |
|
56
|
|
|
{ |
|
57
|
|
|
/** @var Newbb\TopicHandler $topicHandler */ |
|
58
|
|
|
$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic'); |
|
59
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('approved', 0, '>')); |
|
60
|
|
|
if ($forum_id) { |
|
61
|
|
|
$criteria->add(new \Criteria('forum_id', (int)$forum_id)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $topicHandler->getCount($criteria); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/* |
|
68
|
|
|
* Returns the total number of posts in the whole system, a forum, or a topic |
|
69
|
|
|
* Also can return the number of users on the system. |
|
70
|
|
|
*/ |
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @param string $type |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
function getTotalPosts($id = 0, $type = 'all') |
|
77
|
|
|
{ |
|
78
|
|
|
/** @var Newbb\PostHandler $postHandler */ |
|
79
|
|
|
$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post'); |
|
80
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('approved', 0, '>')); |
|
81
|
|
|
switch ($type) { |
|
82
|
|
|
case 'forum': |
|
83
|
|
|
if ($id > 0) { |
|
84
|
|
|
$criteria->add(new \Criteria('forum_id', (int)$id)); |
|
85
|
|
|
} |
|
86
|
|
|
break; |
|
87
|
|
|
case 'topic': |
|
88
|
|
|
if ($id > 0) { |
|
89
|
|
|
$criteria->add(new \Criteria('topic_id', (int)$id)); |
|
90
|
|
|
} |
|
91
|
|
|
break; |
|
92
|
|
|
case 'all': |
|
93
|
|
|
default: |
|
94
|
|
|
break; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $postHandler->getCount($criteria); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return null |
|
102
|
|
|
*/ |
|
103
|
|
|
function getTotalViews() |
|
104
|
|
|
{ |
|
105
|
|
|
$sql = 'SELECT sum(topic_views) FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . ' '; |
|
106
|
|
|
if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
|
107
|
|
|
return null; |
|
108
|
|
|
} |
|
109
|
|
|
list($total) = $GLOBALS['xoopsDB']->fetchRow($result); |
|
110
|
|
|
|
|
111
|
|
|
return $total; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.