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
|
|
|
* @copyright XOOPS Project http://xoops.org/ |
14
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @author XOOPS Development Team |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* Prepares system prior to attempting to install module |
21
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
22
|
|
|
* |
23
|
|
|
* @return bool true if ready to install, false if not |
24
|
|
|
*/ |
25
|
|
|
function xoops_module_pre_install_extcal(XoopsModule $module) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
28
|
|
|
$className = ucfirst($moduleDirName) . 'Utilities'; |
29
|
|
|
if (!class_exists($className)) { |
30
|
|
|
xoops_load('utilities', $moduleDirName); |
31
|
|
|
} |
32
|
|
|
//check for minimum XOOPS version |
33
|
|
|
if (!$className::checkXoopsVer($module)) { |
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// check for minimum PHP version |
38
|
|
|
if (!$className::checkPhpVer($module)) { |
39
|
|
|
return false; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$mod_tables =& $module->getInfo('tables'); |
43
|
|
|
foreach ($mod_tables as $table) { |
44
|
|
|
$GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* Performs tasks required during installation of the module |
53
|
|
|
* @param XoopsModule $xoopsModule |
54
|
|
|
* @return bool true if installation successful, false if not |
55
|
|
|
* @internal param XoopsModule $module <a href='psi_element://XoopsModule'>XoopsModule</a> |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
function xoops_module_install_extcal(XoopsModule $xoopsModule) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
61
|
|
|
|
62
|
|
|
$moduleId = $xoopsModule->getVar('mid'); |
63
|
|
|
/** @var XoopsGroupPermHandler $groupPermissionHandler */ |
64
|
|
|
$groupPermissionHandler = xoops_getHandler('groupperm'); |
65
|
|
|
/** @var XoopsConfigHandler $configHandler */ |
66
|
|
|
$configHandler = xoops_getHandler('config'); |
67
|
|
|
|
68
|
|
|
/* |
69
|
|
|
* Default public category permission mask |
70
|
|
|
*/ |
71
|
|
|
|
72
|
|
|
// Access right |
73
|
|
|
$groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_ADMIN, $moduleId); |
74
|
|
|
$groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_USERS, $moduleId); |
75
|
|
|
$groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
76
|
|
|
|
77
|
|
|
// Can submit |
78
|
|
|
$groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 2, XOOPS_GROUP_ADMIN, $moduleId); |
79
|
|
|
|
80
|
|
|
// Auto approve |
81
|
|
|
$groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 4, XOOPS_GROUP_ADMIN, $moduleId); |
82
|
|
|
|
83
|
|
|
// $moduleDirName = $xoopsModule->getVar('dirname'); |
|
|
|
|
84
|
|
|
$configurator = include $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php'); |
85
|
|
|
|
86
|
|
|
$classUtilities = ucfirst($moduleDirName) . 'Utilities'; |
87
|
|
|
if (!class_exists($classUtilities)) { |
88
|
|
|
xoops_load('utilities', $moduleDirName); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (count($configurator['uploadFolders']) > 0) { |
92
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
93
|
|
|
foreach (array_keys($configurator['uploadFolders']) as $i) { |
94
|
|
|
$classUtilities::createFolder($configurator['uploadFolders'][$i]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
View Code Duplication |
if (count($configurator['copyFiles']) > 0) { |
|
|
|
|
98
|
|
|
$file = __DIR__ . '/../assets/images/blank.png'; |
99
|
|
|
foreach (array_keys($configurator['copyFiles']) as $i) { |
100
|
|
|
$dest = $configurator['copyFiles'][$i] . '/blank.png'; |
101
|
|
|
$classUtilities::copyFile($file, $dest); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return true; |
106
|
|
|
} |
107
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: