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