1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: randomquote |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package randomquote |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <https://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xoopsmodules\randomquote; |
|
|
|
|
26
|
|
|
use Xoopsmodules\randomquote\common; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Prepares system prior to attempting to install module |
30
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
31
|
|
|
* |
32
|
|
|
* @return bool true if ready to install, false if not |
33
|
|
|
*/ |
34
|
|
|
function xoops_module_pre_install_randomquote(\XoopsModule $module) |
35
|
|
|
{ |
36
|
|
|
include __DIR__ . '/../preloads/autoloader.php'; |
37
|
|
|
/** @var randomquote\Utility $utility */ |
38
|
|
|
$utility = new randomquote\Utility(); |
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
|
|
|
if (false !== $xoopsSuccess && false !== $phpSuccess) { |
47
|
|
|
$moduleTables =& $module->getInfo('tables'); |
48
|
|
|
foreach ($moduleTables as $table) { |
49
|
|
|
$GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return $xoopsSuccess && $phpSuccess; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
* Performs tasks required during installation of the module |
58
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
59
|
|
|
* |
60
|
|
|
* @return bool true if installation successful, false if not |
61
|
|
|
*/ |
62
|
|
|
function xoops_module_install_randomquote(\XoopsModule $module) |
63
|
|
|
{ |
64
|
|
|
include __DIR__ . '/../preloads/autoloader.php'; |
65
|
|
|
|
66
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
67
|
|
|
|
68
|
|
|
/** @var randomquote\Helper $helper */ |
69
|
|
|
/** @var randomquote\Utility $utility */ |
70
|
|
|
/** @var common\Configurator $configurator */ |
71
|
|
|
$helper = randomquote\Helper::getInstance(); |
72
|
|
|
$utility = new randomquote\Utility(); |
73
|
|
|
$configurator = new common\Configurator(); |
74
|
|
|
|
75
|
|
|
// Load language files |
76
|
|
|
$helper->loadLanguage('admin'); |
77
|
|
|
$helper->loadLanguage('modinfo'); |
78
|
|
|
|
79
|
|
|
// default Permission Settings ---------------------- |
80
|
|
|
$moduleId = $module->getVar('mid'); |
81
|
|
|
$moduleId2 = $helper->getModule()->mid(); |
|
|
|
|
82
|
|
|
//$moduleName = $module->getVar('name'); |
83
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
84
|
|
|
// access rights ------------------------------------------ |
85
|
|
|
$gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
86
|
|
|
$gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
87
|
|
|
$gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
88
|
|
|
$gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
89
|
|
|
$gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
90
|
|
|
|
91
|
|
|
// --- CREATE FOLDERS --------------- |
92
|
|
View Code Duplication |
if (count($configurator->uploadFolders) > 0) { |
|
|
|
|
93
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
94
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
95
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
// --- COPY blank.png FILES --------------- |
99
|
|
View Code Duplication |
if (count($configurator->copyBlankFiles) > 0) { |
|
|
|
|
100
|
|
|
$file = __DIR__ . '/../assets/images/blank.png'; |
101
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
102
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
103
|
|
|
$utility::copyFile($file, $dest); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// --- COPY test folder files --------------- |
108
|
|
View Code Duplication |
if (count($configurator->copyTestFolders) > 0) { |
|
|
|
|
109
|
|
|
// $file = __DIR__ . '/../testdata/images/'; |
110
|
|
|
foreach (array_keys($configurator->copyTestFolders) as $i) { |
111
|
|
|
$src = $configurator->copyTestFolders[$i][0]; |
112
|
|
|
$dest = $configurator->copyTestFolders[$i][1]; |
113
|
|
|
$utility::xcopy($src, $dest); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
//delete .html entries from the tpl table |
118
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
119
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
120
|
|
|
|
121
|
|
|
return true; |
122
|
|
|
} |
123
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: