1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/../include/config.php'; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class MyalbumUtilities |
7
|
|
|
*/ |
8
|
|
|
class ExtgalleryUtilities extends XoopsObject |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
12
|
|
|
* |
13
|
|
|
* @param string $folder The full path of the directory to check |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
public static function createFolder($folder) |
18
|
|
|
{ |
19
|
|
|
try { |
20
|
|
|
if (!file_exists($folder)) { |
21
|
|
|
if (!mkdir($folder) && !is_dir($folder)) { |
22
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
23
|
|
|
} else { |
24
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
catch (Exception $e) { |
29
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>'; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $file |
35
|
|
|
* @param $folder |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
public static function copyFile($file, $folder) |
39
|
|
|
{ |
40
|
|
|
return copy($file, $folder); |
41
|
|
|
// try { |
42
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
43
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
44
|
|
|
// } else { |
|
|
|
|
45
|
|
|
// return copy($file, $folder); |
|
|
|
|
46
|
|
|
// } |
47
|
|
|
// } catch (Exception $e) { |
|
|
|
|
48
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>"; |
|
|
|
|
49
|
|
|
// } |
50
|
|
|
// return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $src |
55
|
|
|
* @param $dst |
56
|
|
|
*/ |
57
|
|
|
public static function recurseCopy($src, $dst) |
58
|
|
|
{ |
59
|
|
|
$dir = opendir($src); |
60
|
|
|
// @mkdir($dst); |
61
|
|
|
while (false !== ($file = readdir($dir))) { |
62
|
|
|
if (($file !== '.') && ($file !== '..')) { |
63
|
|
|
if (is_dir($src . '/' . $file)) { |
64
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
65
|
|
|
} else { |
66
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
closedir($dir); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
76
|
|
|
* @static |
77
|
|
|
* @param XoopsModule $module |
78
|
|
|
* |
79
|
|
|
* @return bool true if meets requirements, false if not |
80
|
|
|
*/ |
81
|
|
|
public static function checkXoopsVer(XoopsModule $module) |
82
|
|
|
{ |
83
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
84
|
|
|
//check for minimum XOOPS version |
85
|
|
|
$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
86
|
|
|
$currArray = explode('.', $currentVer); |
87
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
88
|
|
|
$reqArray = explode('.', $requiredVer); |
89
|
|
|
$success = true; |
90
|
|
|
foreach ($reqArray as $k => $v) { |
91
|
|
|
if (isset($currArray[$k])) { |
92
|
|
|
if ($currArray[$k] > $v) { |
93
|
|
|
break; |
94
|
|
|
} elseif ($currArray[$k] == $v) { |
95
|
|
|
continue; |
96
|
|
|
} else { |
97
|
|
|
$success = false; |
98
|
|
|
break; |
99
|
|
|
} |
100
|
|
|
} else { |
101
|
|
|
if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
102
|
|
|
$success = false; |
103
|
|
|
break; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (!$success) { |
109
|
|
|
$module->setErrors(sprintf(_AM_TAG_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $success; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* |
117
|
|
|
* Verifies PHP version meets minimum requirements for this module |
118
|
|
|
* @static |
119
|
|
|
* @param XoopsModule $module |
120
|
|
|
* |
121
|
|
|
* @return bool true if meets requirements, false if not |
122
|
|
|
*/ |
123
|
|
|
public static function checkPhpVer(XoopsModule $module) |
124
|
|
|
{ |
125
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
126
|
|
|
// check for minimum PHP version |
127
|
|
|
$success = true; |
128
|
|
|
$verNum = phpversion(); |
129
|
|
|
$reqVer =& $module->getInfo('min_php'); |
130
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
131
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
132
|
|
|
$module->setErrors(sprintf(_AM_TAG_ERROR_BAD_PHP, $reqVer, $verNum)); |
133
|
|
|
$success = false; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $success; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
public static function getModuleOption($option) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
global $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
143
|
|
|
static $tbloptions = array(); |
144
|
|
|
if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) { |
145
|
|
|
return $tbloptions[$option]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$retval = false; |
149
|
|
|
if (isset($xoopsModuleConfig) |
150
|
|
|
&& (is_object($xoopsModule) && $xoopsModule->getVar('dirname') === 'extgallery' |
151
|
|
|
&& $xoopsModule->getVar('isactive')) |
152
|
|
|
) { |
153
|
|
|
if (isset($xoopsModuleConfig[$option])) { |
154
|
|
|
$retval = $xoopsModuleConfig[$option]; |
155
|
|
|
} |
156
|
|
|
} else { |
157
|
|
|
/** @var XoopsModuleHandler $moduleHandler */ |
158
|
|
|
$moduleHandler = xoops_getHandler('module'); |
159
|
|
|
$module = $moduleHandler->getByDirname('extgallery'); |
160
|
|
|
|
161
|
|
|
/** @var XoopsConfigHandler $configHandler */ |
162
|
|
|
$configHandler = xoops_getHandler('config'); |
163
|
|
|
if ($module) { |
164
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
165
|
|
|
if (isset($moduleConfig[$option])) { |
166
|
|
|
$retval = $moduleConfig[$option]; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
$tbloptions[$option] = $retval; |
171
|
|
|
|
172
|
|
|
return $retval; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param $caption |
177
|
|
|
* @param $name |
178
|
|
|
* @param $value |
179
|
|
|
* @param $rows |
180
|
|
|
* @param $cols |
181
|
|
|
* @param $width |
182
|
|
|
* @param $height |
183
|
|
|
* @param $supplemental |
184
|
|
|
* |
185
|
|
|
* @return bool|XoopsFormEditor |
186
|
|
|
*/ |
187
|
|
View Code Duplication |
public static function getWysiwygForm($caption, $name, $value, $rows, $cols, $width, $height, $supplemental) |
|
|
|
|
188
|
|
|
{ |
189
|
|
|
$editor_option = strtolower(static::getModuleOption('form_options')); |
190
|
|
|
$editor = false; |
|
|
|
|
191
|
|
|
$editor_configs = array(); |
192
|
|
|
$editor_configs['name'] = $name; |
193
|
|
|
$editor_configs['value'] = $value; |
194
|
|
|
$editor_configs['rows'] = $rows; |
195
|
|
|
$editor_configs['cols'] = $cols; |
196
|
|
|
$editor_configs['width'] = $width; |
197
|
|
|
$editor_configs['height'] = $height; |
198
|
|
|
$editor_configs['editor'] = $editor_option; |
199
|
|
|
|
200
|
|
|
$editor = new XoopsFormEditor($caption, $name, $editor_configs); |
201
|
|
|
|
202
|
|
|
return $editor; |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
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.