1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000-2016 XOOPS.org // |
6
|
|
|
// <https://xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
// Author: phppp (D.J., [email protected]) // |
28
|
|
|
// URL: https://xoops.org // |
29
|
|
|
// Project: Article Project // |
30
|
|
|
// ------------------------------------------------------------------------ // |
31
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
32
|
|
|
|
33
|
|
|
use XoopsModules\Newbb; |
34
|
|
|
|
35
|
|
|
if (defined('XOOPS_MODULE_NEWBB_FUCTIONS')) { |
36
|
|
|
exit(); |
37
|
|
|
} |
38
|
|
|
define('XOOPS_MODULE_NEWBB_FUCTIONS', 1); |
39
|
|
|
|
40
|
|
|
include_once $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php'); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param XoopsModule $module |
44
|
|
|
* @param null $oldversion |
|
|
|
|
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
function xoops_module_update_newbb(\XoopsModule $module, $oldversion = null) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$cacheHelper = new \Xmf\Module\Helper\Cache('newbb'); |
|
|
|
|
50
|
|
|
$cacheHelper->delete('config'); |
51
|
|
|
|
52
|
|
|
$newbbConfig = newbbLoadConfig(); |
53
|
|
|
|
54
|
|
|
// remove old html template files |
55
|
|
|
// create an array with all folders, and then run this once |
56
|
|
|
|
57
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/'); |
58
|
|
|
$template_list = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
59
|
|
|
foreach ($template_list as $k => $v) { |
60
|
|
|
$fileinfo = new \SplFileInfo($templateDirectory . $v); |
61
|
|
|
if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) { |
62
|
|
|
@unlink($templateDirectory . $v); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/blocks'); |
66
|
|
|
$template_list = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
67
|
|
|
foreach ($template_list as $k => $v) { |
68
|
|
|
$fileinfo = new \SplFileInfo($templateDirectory . $v); |
69
|
|
|
if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) { |
70
|
|
|
@unlink($templateDirectory . $v); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
// Load class XoopsFile |
74
|
|
|
xoops_load('xoopsfile'); |
|
|
|
|
75
|
|
|
//remove /images directory |
76
|
|
|
$imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
77
|
|
|
$folderHandler = \XoopsFile::getHandler('folder', $imagesDirectory); |
|
|
|
|
78
|
|
|
$folderHandler->delete($imagesDirectory); |
79
|
|
|
|
80
|
|
|
//remove old changelogs |
81
|
|
|
array_map('unlink', glob(dirname(__DIR__) . '/docs/changelog-rev*.txt')); |
82
|
|
|
|
83
|
|
|
if (!empty($newbbConfig['syncOnUpdate'])) { |
84
|
|
|
include_once __DIR__ . '/../include/functions.recon.php'; |
85
|
|
|
newbbSynchronization(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param XoopsModule $module |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
function xoops_module_pre_update_newbb(\XoopsModule $module) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
XoopsLoad::load('migrate', 'newbb'); |
|
|
|
|
98
|
|
|
$newbbMigrate = new Newbb\Migrate(); |
99
|
|
|
$newbbMigrate->synchronizeSchema(); |
100
|
|
|
|
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param XoopsModule $module |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
function xoops_module_pre_install_newbb(\XoopsModule $module) |
109
|
|
|
{ |
110
|
|
|
$mod_tables =& $module->getInfo('tables'); |
111
|
|
|
foreach ($mod_tables as $table) { |
112
|
|
|
$GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return true; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param XoopsModule $module |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
function xoops_module_install_newbb(\XoopsModule $module) |
123
|
|
|
{ |
124
|
|
|
/* Create a test category */ |
125
|
|
|
/** @var Newbb\CategoryHandler $categoryHandler */ |
126
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
127
|
|
|
$category = $categoryHandler->create(); |
128
|
|
|
$category->setVar('cat_title', _MI_NEWBB_INSTALL_CAT_TITLE, true); |
129
|
|
|
$category->setVar('cat_image', '', true); |
130
|
|
|
$category->setVar('cat_description', _MI_NEWBB_INSTALL_CAT_DESC, true); |
131
|
|
|
$category->setVar('cat_url', 'https://xoops.org XOOPS Project', true); |
132
|
|
|
if (!$cat_id = $categoryHandler->insert($category)) { |
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/* Create a forum for test */ |
137
|
|
|
/** @var Newbb\ForumHandler $forumHandler */ |
138
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
139
|
|
|
$forum = $forumHandler->create(); |
140
|
|
|
$forum->setVar('forum_name', _MI_NEWBB_INSTALL_FORUM_NAME, true); |
141
|
|
|
$forum->setVar('forum_desc', _MI_NEWBB_INSTALL_FORUM_DESC, true); |
142
|
|
|
$forum->setVar('forum_moderator', []); |
143
|
|
|
$forum->setVar('parent_forum', 0); |
144
|
|
|
$forum->setVar('cat_id', $cat_id); |
145
|
|
|
$forum->setVar('attach_maxkb', 100); |
146
|
|
|
$forum->setVar('attach_ext', 'zip|jpg|gif|png'); |
147
|
|
|
$forum->setVar('hot_threshold', 20); |
148
|
|
|
$forum_id = $forumHandler->insert($forum); |
149
|
|
|
|
150
|
|
|
/* Set corresponding permissions for the category and the forum */ |
151
|
|
|
$module_id = $module->getVar('mid'); |
152
|
|
|
/** @var XoopsGroupPermHandler $gpermHandler */ |
153
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
154
|
|
|
$groups_view = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]; |
|
|
|
|
155
|
|
|
$groups_post = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS]; |
156
|
|
|
// irmtfan bug fix: html and signature permissions, add: pdf and print permissions |
157
|
|
|
$post_items = [ |
158
|
|
|
'post', |
159
|
|
|
'reply', |
160
|
|
|
'edit', |
161
|
|
|
'delete', |
162
|
|
|
'addpoll', |
163
|
|
|
'vote', |
164
|
|
|
'attach', |
165
|
|
|
'noapprove', |
166
|
|
|
'type', |
167
|
|
|
'html', |
168
|
|
|
'signature', |
169
|
|
|
'pdf', |
170
|
|
|
'print' |
171
|
|
|
]; |
172
|
|
|
foreach ($groups_view as $group_id) { |
173
|
|
|
$gpermHandler->addRight('category_access', $cat_id, $group_id, $module_id); |
174
|
|
|
$gpermHandler->addRight('forum_access', $forum_id, $group_id, $module_id); |
175
|
|
|
$gpermHandler->addRight('forum_view', $forum_id, $group_id, $module_id); |
176
|
|
|
} |
177
|
|
|
foreach ($groups_post as $group_id) { |
178
|
|
|
foreach ($post_items as $item) { |
179
|
|
|
$gpermHandler->addRight('forum_' . $item, $forum_id, $group_id, $module_id); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/* Create a test post */ |
184
|
|
|
include_once __DIR__ . '/functions.user.php'; |
185
|
|
|
/** @var Newbb\PostHandler $postHandler */ |
186
|
|
|
$postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
187
|
|
|
/** @var $forumpost */ |
188
|
|
|
$forumpost = $postHandler->create(); |
189
|
|
|
$forumpost->setVar('poster_ip', \Xmf\IPAddress::fromRequest()->asReadable()); |
|
|
|
|
190
|
|
|
$forumpost->setVar('uid', $GLOBALS['xoopsUser']->getVar('uid')); |
191
|
|
|
$forumpost->setVar('approved', 1); |
192
|
|
|
$forumpost->setVar('forum_id', $forum_id); |
193
|
|
|
$forumpost->setVar('subject', _MI_NEWBB_INSTALL_POST_SUBJECT, true); |
194
|
|
|
$forumpost->setVar('dohtml', 1); |
195
|
|
|
$forumpost->setVar('dosmiley', 1); |
196
|
|
|
$forumpost->setVar('doxcode', 1); |
197
|
|
|
$forumpost->setVar('dobr', 1); |
198
|
|
|
$forumpost->setVar('icon', '', true); |
199
|
|
|
$forumpost->setVar('attachsig', 1); |
200
|
|
|
$forumpost->setVar('post_time', time()); |
201
|
|
|
$forumpost->setVar('post_text', _MI_NEWBB_INSTALL_POST_TEXT, true); |
202
|
|
|
$postid = $postHandler->insert($forumpost); |
|
|
|
|
203
|
|
|
|
204
|
|
|
return true; |
205
|
|
|
} |
206
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.