1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * Users Manager
14: *
15: * @category Xoops\Core
16: * @package users
17: * @author Kazumi Ono (AKA onokazu)
18: * @author Richard Griffith <richard@geekwright.com>
19: * @copyright 2002-2013 XOOPS Project (http://xoops.org)
20: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
21: * @version Release: 2.6.0
22: * @link http://xoops.org
23: * @since 1.0
24: */
25:
26: // Get main instance
27: $xoops = Xoops::getInstance();
28:
29: // Check users rights
30: if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
31: exit(XoopsLocale::E_NO_ACCESS_PERMISSION);
32: }
33:
34: // Check is active
35: if (!$xoops->getModuleConfig('active_users', 'system')) {
36: $xoops->redirect('admin.php', 2, XoopsLocale::E_SECTION_NOT_ACTIVE);
37: }
38:
39: /*********************************************************/
40: /* Users Functions */
41: /*********************************************************/
42: /**
43: * synchronize number of posts credited to user
44: *
45: * @param int $uid uid of user row
46: * @param string $type type of processing, 'user' for one user, 'all users' for all
47: *
48: * @return void
49: */
50: function synchronize($uid, $type)
51: {
52: $xoops = Xoops::getInstance();
53: $db = $xoops->db();
54:
55: switch ($type) {
56: case 'user':
57: $total_posts = 0;
58: /* @var $plugin SystemPluginInterface */
59: $plugins = \Xoops\Module\Plugin::getPlugins();
60: foreach ($plugins as $plugin) {
61: if ($res = $plugin->userPosts($uid)) {
62: $total_posts += $res;
63: }
64: }
65:
66: $query = $db->createXoopsQueryBuilder()
67: ->updatePrefix('system_user')
68: ->set('posts', ':posts')
69: ->where('uid = :uid')
70: ->setParameter(':posts', $total_posts)
71: ->setParameter(':uid', $uid);
72:
73: $result = $query->execute();
74: //if (!$result) {
75: // $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_NOT_UPDATED);
76: //}
77: break;
78:
79: case 'all users':
80: $sql = $db->createXoopsQueryBuilder()
81: ->select('uid')
82: ->fromPrefix('system_user', 'u');
83:
84: $result = $sql->execute();
85: if (!$result) {
86: $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_ID_NOT_FETCHED);
87: }
88: $rows = $result->fetchAll();
89: foreach ($rows as $row) {
90: synchronize($row['uid'], "user");
91: }
92: break;
93: }
94: }
95: