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
|
|
|
* animal module for xoops |
14
|
|
|
* |
15
|
|
|
* @package XoopsModules\Pedigree |
16
|
|
|
* @copyright The TXMod XOOPS Project https://sourceforge.net/projects/thmod/ |
17
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
18
|
|
|
* @license GPL 2.0 or later |
19
|
|
|
* @author XOOPS Development Team <https://xoops.org> |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use Xmf\Module\Helper\Permission; |
23
|
|
|
use XoopsModules\Pedigree\{ |
24
|
|
|
Common\Configurator, |
25
|
|
|
Constants, |
26
|
|
|
Helper, |
27
|
|
|
Utility |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
require \dirname(__DIR__) . '/preloads/autoloader.php'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Prepares system prior to attempting to install module |
34
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
35
|
|
|
* |
36
|
|
|
* @return bool true if ready to install, false if not |
37
|
|
|
*/ |
38
|
|
|
function xoops_module_pre_install_pedigree(\XoopsModule $module) |
39
|
|
|
{ |
40
|
|
|
//check for minimum XOOPS version |
41
|
|
|
$xoopsSuccess = Utility::checkVerXoops($module); |
42
|
|
|
|
43
|
|
|
// check for minimum PHP version |
44
|
|
|
$phpSuccess = Utility::checkVerPhp($module); |
45
|
|
|
|
46
|
|
|
// delete the SQL tables if they exist, check to make sure they were deleted (DROPPED) |
47
|
|
|
/** @TODO: use Xmf\Tables to handle dropping tables from dB */ |
48
|
|
|
$sqlSuccess = true; |
49
|
|
|
if (false !== $xoopsSuccess && false !== $phpSuccess) { |
50
|
|
|
$moduleTables = $module->getInfo('tables'); |
51
|
|
|
foreach ($moduleTables as $table) { |
52
|
|
|
$success = $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
53
|
|
|
$success = false === $success || true; |
54
|
|
|
$sqlSuccess = $sqlSuccess && $success; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $xoopsSuccess && $phpSuccess && $sqlSuccess; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Performs tasks required during installation of the module |
63
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
64
|
|
|
* |
65
|
|
|
* @return bool true if installation successful, false if not |
66
|
|
|
*/ |
67
|
|
|
function xoops_module_install_pedigree(\XoopsModule $module) |
68
|
|
|
{ |
69
|
|
|
$helper = Helper::getInstance(); |
70
|
|
|
$moduleDirName = $helper->getDirname(); |
71
|
|
|
$configurator = new Configurator(); |
72
|
|
|
|
73
|
|
|
// Load language files |
74
|
|
|
$helper->loadLanguage('admin'); |
75
|
|
|
$helper->loadLanguage('modinfo'); |
76
|
|
|
|
77
|
|
|
// default Permission Settings ---------------------- |
78
|
|
|
$mid = $module->getVar('mid'); |
|
|
|
|
79
|
|
|
|
80
|
|
|
// access rights ------------------------------------------ |
81
|
|
|
$permHandler = new Permission($moduleDirName); |
82
|
|
|
$permHandler->savePermissionForItem($moduleDirName . '_approve', 1, [XOOPS_GROUP_ADMIN]); |
83
|
|
|
$permHandler->savePermissionForItem($moduleDirName . '_submit', 1, [XOOPS_GROUP_ADMIN]); |
84
|
|
|
$permHandler->savePermissionForItem($moduleDirName . '_view', 1, [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]); |
85
|
|
|
|
86
|
|
|
//$moduleName = $module->getVar('name'); /** @var \XoopsGroupPermHandler $grouppermHandler */ |
87
|
|
|
/* |
88
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
89
|
|
|
// access rights ------------------------------------------ |
90
|
|
|
$grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
91
|
|
|
$grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
92
|
|
|
$grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
93
|
|
|
$grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
94
|
|
|
$grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
95
|
|
|
*/ |
96
|
|
|
// --- CREATE FOLDERS --------------- |
97
|
|
|
if (count($configurator->uploadFolders) > 0) { |
98
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
99
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
100
|
|
|
Utility::createFolder($configurator->uploadFolders[$i]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
// --- COPY blank.png FILES --------------- |
104
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
105
|
|
|
$file = $helper->path('assets/images/blank.png'); |
106
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
107
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
108
|
|
|
Utility::copyFile($file, $dest); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// --- COPY blank.png FILES --------------- |
113
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
114
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
115
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
116
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
117
|
|
|
Utility::copyFile($file, $dest); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
// --- COPY test folder files --------------- |
122
|
|
|
if (count($configurator->copyTestFolders) > 0) { |
123
|
|
|
//$file = \dirname(__DIR__) . '/testdata/images/'; |
124
|
|
|
foreach (array_keys($configurator->copyTestFolders) as $i) { |
125
|
|
|
$src = $configurator->copyTestFolders[$i][0]; |
126
|
|
|
$dest = $configurator->copyTestFolders[$i][1]; |
127
|
|
|
Utility::rcopy($src, $dest); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
//delete .html entries from the tpl table |
132
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $moduleDirName . "' AND `tpl_file` LIKE '%.html'"; |
133
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
134
|
|
|
|
135
|
|
|
return true; |
136
|
|
|
} |
137
|
|
|
|