@@ -17,60 +17,60 @@ |
||
17 | 17 | */ |
18 | 18 | trait VersionChecks |
19 | 19 | { |
20 | - /** |
|
21 | - * |
|
22 | - * Verifies XOOPS version meets minimum requirements for this module |
|
23 | - * @static |
|
24 | - * @param \XoopsModule $module |
|
25 | - * |
|
26 | - * @param null|string $requiredVer |
|
27 | - * @return bool true if meets requirements, false if not |
|
28 | - */ |
|
29 | - public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
30 | - { |
|
31 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
32 | - if (null === $module) { |
|
33 | - $module = \XoopsModule::getByDirname($moduleDirName); |
|
34 | - } |
|
35 | - xoops_loadLanguage('admin', $moduleDirName); |
|
20 | + /** |
|
21 | + * |
|
22 | + * Verifies XOOPS version meets minimum requirements for this module |
|
23 | + * @static |
|
24 | + * @param \XoopsModule $module |
|
25 | + * |
|
26 | + * @param null|string $requiredVer |
|
27 | + * @return bool true if meets requirements, false if not |
|
28 | + */ |
|
29 | + public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
30 | + { |
|
31 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
32 | + if (null === $module) { |
|
33 | + $module = \XoopsModule::getByDirname($moduleDirName); |
|
34 | + } |
|
35 | + xoops_loadLanguage('admin', $moduleDirName); |
|
36 | 36 | |
37 | - //check for minimum XOOPS version |
|
38 | - $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
39 | - if (null === $requiredVer) { |
|
40 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
41 | - } |
|
42 | - $success = true; |
|
37 | + //check for minimum XOOPS version |
|
38 | + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
39 | + if (null === $requiredVer) { |
|
40 | + $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
41 | + } |
|
42 | + $success = true; |
|
43 | 43 | |
44 | - if (version_compare($currentVer, $requiredVer, '<')) { |
|
45 | - $success = false; |
|
46 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
47 | - } |
|
44 | + if (version_compare($currentVer, $requiredVer, '<')) { |
|
45 | + $success = false; |
|
46 | + $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
47 | + } |
|
48 | 48 | |
49 | - return $success; |
|
50 | - } |
|
49 | + return $success; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * |
|
54 | - * Verifies PHP version meets minimum requirements for this module |
|
55 | - * @static |
|
56 | - * @param \XoopsModule $module |
|
57 | - * |
|
58 | - * @return bool true if meets requirements, false if not |
|
59 | - */ |
|
60 | - public static function checkVerPhp(\XoopsModule $module) |
|
61 | - { |
|
62 | - xoops_loadLanguage('admin', $module->dirname()); |
|
63 | - // check for minimum PHP version |
|
64 | - $success = true; |
|
65 | - $verNum = PHP_VERSION; |
|
66 | - $reqVer =& $module->getInfo('min_php'); |
|
67 | - if (false !== $reqVer && '' !== $reqVer) { |
|
68 | - if (version_compare($verNum, $reqVer, '<')) { |
|
69 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
70 | - $success = false; |
|
71 | - } |
|
72 | - } |
|
52 | + /** |
|
53 | + * |
|
54 | + * Verifies PHP version meets minimum requirements for this module |
|
55 | + * @static |
|
56 | + * @param \XoopsModule $module |
|
57 | + * |
|
58 | + * @return bool true if meets requirements, false if not |
|
59 | + */ |
|
60 | + public static function checkVerPhp(\XoopsModule $module) |
|
61 | + { |
|
62 | + xoops_loadLanguage('admin', $module->dirname()); |
|
63 | + // check for minimum PHP version |
|
64 | + $success = true; |
|
65 | + $verNum = PHP_VERSION; |
|
66 | + $reqVer =& $module->getInfo('min_php'); |
|
67 | + if (false !== $reqVer && '' !== $reqVer) { |
|
68 | + if (version_compare($verNum, $reqVer, '<')) { |
|
69 | + $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
70 | + $success = false; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - return $success; |
|
75 | - } |
|
74 | + return $success; |
|
75 | + } |
|
76 | 76 | } |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | //check for minimum XOOPS version |
38 | 38 | $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
39 | 39 | if (null === $requiredVer) { |
40 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
40 | + $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string |
|
41 | 41 | } |
42 | - $success = true; |
|
42 | + $success = true; |
|
43 | 43 | |
44 | 44 | if (version_compare($currentVer, $requiredVer, '<')) { |
45 | - $success = false; |
|
46 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
45 | + $success = false; |
|
46 | + $module->setErrors(sprintf(constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | return $success; |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | // check for minimum PHP version |
64 | 64 | $success = true; |
65 | 65 | $verNum = PHP_VERSION; |
66 | - $reqVer =& $module->getInfo('min_php'); |
|
66 | + $reqVer = & $module->getInfo('min_php'); |
|
67 | 67 | if (false !== $reqVer && '' !== $reqVer) { |
68 | 68 | if (version_compare($verNum, $reqVer, '<')) { |
69 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
69 | + $module->setErrors(sprintf(constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
70 | 70 | $success = false; |
71 | 71 | } |
72 | 72 | } |
@@ -31,48 +31,48 @@ |
||
31 | 31 | */ |
32 | 32 | class Breadcrumb |
33 | 33 | { |
34 | - public $dirname; |
|
35 | - private $bread = []; |
|
34 | + public $dirname; |
|
35 | + private $bread = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - */ |
|
40 | - public function __construct() |
|
41 | - { |
|
42 | - $this->dirname = basename(dirname(__DIR__)); |
|
43 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + */ |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + $this->dirname = basename(dirname(__DIR__)); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Add link to breadcrumb |
|
47 | - * |
|
48 | - * @param string $title |
|
49 | - * @param string $link |
|
50 | - */ |
|
51 | - public function addLink($title = '', $link = '') |
|
52 | - { |
|
53 | - $this->bread[] = [ |
|
54 | - 'link' => $link, |
|
55 | - 'title' => $title |
|
56 | - ]; |
|
57 | - } |
|
45 | + /** |
|
46 | + * Add link to breadcrumb |
|
47 | + * |
|
48 | + * @param string $title |
|
49 | + * @param string $link |
|
50 | + */ |
|
51 | + public function addLink($title = '', $link = '') |
|
52 | + { |
|
53 | + $this->bread[] = [ |
|
54 | + 'link' => $link, |
|
55 | + 'title' => $title |
|
56 | + ]; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Render Pedigree BreadCrumb |
|
61 | - * |
|
62 | - */ |
|
63 | - public function render() |
|
64 | - { |
|
65 | - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
66 | - require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
67 | - $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
|
68 | - } |
|
59 | + /** |
|
60 | + * Render Pedigree BreadCrumb |
|
61 | + * |
|
62 | + */ |
|
63 | + public function render() |
|
64 | + { |
|
65 | + if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
66 | + require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
67 | + $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
|
68 | + } |
|
69 | 69 | |
70 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
71 | - $breadcrumbTpl = new \XoopsTpl(); |
|
72 | - $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
73 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
74 | - unset($breadcrumbTpl); |
|
70 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
71 | + $breadcrumbTpl = new \XoopsTpl(); |
|
72 | + $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
73 | + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
74 | + unset($breadcrumbTpl); |
|
75 | 75 | |
76 | - return $html; |
|
77 | - } |
|
76 | + return $html; |
|
77 | + } |
|
78 | 78 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | require_once $GLOBALS['xoops']->path('class/template.php'); |
71 | 71 | $breadcrumbTpl = new \XoopsTpl(); |
72 | 72 | $breadcrumbTpl->assign('breadcrumb', $this->bread); |
73 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
73 | + $html = $breadcrumbTpl->fetch('db:'.$this->dirname.'_common_breadcrumb.tpl'); |
|
74 | 74 | unset($breadcrumbTpl); |
75 | 75 | |
76 | 76 | return $html; |
@@ -17,229 +17,229 @@ |
||
17 | 17 | */ |
18 | 18 | trait FilesManagement |
19 | 19 | { |
20 | - /** |
|
21 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | - * |
|
23 | - * @param string $folder The full path of the directory to check |
|
24 | - * |
|
25 | - * @return void |
|
26 | - * @throws \RuntimeException |
|
27 | - */ |
|
28 | - public static function createFolder($folder) |
|
29 | - { |
|
30 | - try { |
|
31 | - if (!file_exists($folder)) { |
|
32 | - if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
33 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | - } |
|
35 | - |
|
36 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | - } |
|
38 | - } catch (\Exception $e) { |
|
39 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param $file |
|
45 | - * @param $folder |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function copyFile($file, $folder) |
|
49 | - { |
|
50 | - return copy($file, $folder); |
|
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 | - if (!mkdir($dst) && !is_dir($dst)) { |
|
62 | - while (false !== ($file = readdir($dir))) { |
|
63 | - if (('.' !== $file) && ('..' !== $file)) { |
|
64 | - if (is_dir($src . '/' . $file)) { |
|
65 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
66 | - } else { |
|
67 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - closedir($dir); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * |
|
77 | - * Remove files and (sub)directories |
|
78 | - * |
|
79 | - * @param string $src source directory to delete |
|
80 | - * |
|
81 | - * @uses \Xmf\Module\Helper::getHelper() |
|
82 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
83 | - * |
|
84 | - * @return bool true on success |
|
85 | - */ |
|
86 | - public static function deleteDirectory($src) |
|
87 | - { |
|
88 | - // Only continue if user is a 'global' Admin |
|
89 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
90 | - return false; |
|
91 | - } |
|
92 | - |
|
93 | - $success = true; |
|
94 | - // remove old files |
|
95 | - $dirInfo = new \SplFileInfo($src); |
|
96 | - // validate is a directory |
|
97 | - if ($dirInfo->isDir()) { |
|
98 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
99 | - foreach ($fileList as $k => $v) { |
|
100 | - $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
101 | - if ($fileInfo->isDir()) { |
|
102 | - // recursively handle subdirectories |
|
103 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
104 | - break; |
|
105 | - } |
|
106 | - } else { |
|
107 | - // delete the file |
|
108 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
109 | - break; |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - // now delete this (sub)directory if all the files are gone |
|
114 | - if ($success) { |
|
115 | - $success = rmdir($dirInfo->getRealPath()); |
|
116 | - } |
|
117 | - } else { |
|
118 | - // input is not a valid directory |
|
119 | - $success = false; |
|
120 | - } |
|
121 | - return $success; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * |
|
126 | - * Recursively remove directory |
|
127 | - * |
|
128 | - * @todo currently won't remove directories with hidden files, should it? |
|
129 | - * |
|
130 | - * @param string $src directory to remove (delete) |
|
131 | - * |
|
132 | - * @return bool true on success |
|
133 | - */ |
|
134 | - public static function rrmdir($src) |
|
135 | - { |
|
136 | - // Only continue if user is a 'global' Admin |
|
137 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - // If source is not a directory stop processing |
|
142 | - if (!is_dir($src)) { |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - $success = true; |
|
147 | - |
|
148 | - // Open the source directory to read in files |
|
149 | - $iterator = new \DirectoryIterator($src); |
|
150 | - foreach ($iterator as $fObj) { |
|
151 | - if ($fObj->isFile()) { |
|
152 | - $filename = $fObj->getPathname(); |
|
153 | - $fObj = null; // clear this iterator object to close the file |
|
154 | - if (!unlink($filename)) { |
|
155 | - return false; // couldn't delete the file |
|
156 | - } |
|
157 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
158 | - // Try recursively on directory |
|
159 | - self::rrmdir($fObj->getPathname()); |
|
160 | - } |
|
161 | - } |
|
162 | - $iterator = null; // clear iterator Obj to close file/directory |
|
163 | - return rmdir($src); // remove the directory & return results |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Recursively move files from one directory to another |
|
168 | - * |
|
169 | - * @param string $src - Source of files being moved |
|
170 | - * @param string $dest - Destination of files being moved |
|
171 | - * |
|
172 | - * @return bool true on success |
|
173 | - */ |
|
174 | - public static function rmove($src, $dest) |
|
175 | - { |
|
176 | - // Only continue if user is a 'global' Admin |
|
177 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
178 | - return false; |
|
179 | - } |
|
180 | - |
|
181 | - // If source is not a directory stop processing |
|
182 | - if (!is_dir($src)) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - // If the destination directory does not exist and could not be created stop processing |
|
187 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - // Open the source directory to read in files |
|
192 | - $iterator = new \DirectoryIterator($src); |
|
193 | - foreach ($iterator as $fObj) { |
|
194 | - if ($fObj->isFile()) { |
|
195 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
196 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
197 | - // Try recursively on directory |
|
198 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
199 | - // rmdir($fObj->getPath()); // now delete the directory |
|
200 | - } |
|
201 | - } |
|
202 | - $iterator = null; // clear iterator Obj to close file/directory |
|
203 | - return rmdir($src); // remove the directory & return results |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Recursively copy directories and files from one directory to another |
|
208 | - * |
|
209 | - * @param string $src - Source of files being moved |
|
210 | - * @param string $dest - Destination of files being moved |
|
211 | - * |
|
212 | - * @uses \Xmf\Module\Helper::getHelper() |
|
213 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
214 | - * |
|
215 | - * @return bool true on success |
|
216 | - */ |
|
217 | - public static function rcopy($src, $dest) |
|
218 | - { |
|
219 | - // Only continue if user is a 'global' Admin |
|
220 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - // If source is not a directory stop processing |
|
225 | - if (!is_dir($src)) { |
|
226 | - return false; |
|
227 | - } |
|
228 | - |
|
229 | - // If the destination directory does not exist and could not be created stop processing |
|
230 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - // Open the source directory to read in files |
|
235 | - $iterator = new \DirectoryIterator($src); |
|
236 | - foreach ($iterator as $fObj) { |
|
237 | - if ($fObj->isFile()) { |
|
238 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
239 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
240 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
241 | - } |
|
242 | - } |
|
243 | - return true; |
|
244 | - } |
|
20 | + /** |
|
21 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | + * |
|
23 | + * @param string $folder The full path of the directory to check |
|
24 | + * |
|
25 | + * @return void |
|
26 | + * @throws \RuntimeException |
|
27 | + */ |
|
28 | + public static function createFolder($folder) |
|
29 | + { |
|
30 | + try { |
|
31 | + if (!file_exists($folder)) { |
|
32 | + if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
33 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | + } |
|
35 | + |
|
36 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | + } |
|
38 | + } catch (\Exception $e) { |
|
39 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param $file |
|
45 | + * @param $folder |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function copyFile($file, $folder) |
|
49 | + { |
|
50 | + return copy($file, $folder); |
|
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 | + if (!mkdir($dst) && !is_dir($dst)) { |
|
62 | + while (false !== ($file = readdir($dir))) { |
|
63 | + if (('.' !== $file) && ('..' !== $file)) { |
|
64 | + if (is_dir($src . '/' . $file)) { |
|
65 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
66 | + } else { |
|
67 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + closedir($dir); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * |
|
77 | + * Remove files and (sub)directories |
|
78 | + * |
|
79 | + * @param string $src source directory to delete |
|
80 | + * |
|
81 | + * @uses \Xmf\Module\Helper::getHelper() |
|
82 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
83 | + * |
|
84 | + * @return bool true on success |
|
85 | + */ |
|
86 | + public static function deleteDirectory($src) |
|
87 | + { |
|
88 | + // Only continue if user is a 'global' Admin |
|
89 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
90 | + return false; |
|
91 | + } |
|
92 | + |
|
93 | + $success = true; |
|
94 | + // remove old files |
|
95 | + $dirInfo = new \SplFileInfo($src); |
|
96 | + // validate is a directory |
|
97 | + if ($dirInfo->isDir()) { |
|
98 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
99 | + foreach ($fileList as $k => $v) { |
|
100 | + $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
101 | + if ($fileInfo->isDir()) { |
|
102 | + // recursively handle subdirectories |
|
103 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
104 | + break; |
|
105 | + } |
|
106 | + } else { |
|
107 | + // delete the file |
|
108 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
109 | + break; |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + // now delete this (sub)directory if all the files are gone |
|
114 | + if ($success) { |
|
115 | + $success = rmdir($dirInfo->getRealPath()); |
|
116 | + } |
|
117 | + } else { |
|
118 | + // input is not a valid directory |
|
119 | + $success = false; |
|
120 | + } |
|
121 | + return $success; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * |
|
126 | + * Recursively remove directory |
|
127 | + * |
|
128 | + * @todo currently won't remove directories with hidden files, should it? |
|
129 | + * |
|
130 | + * @param string $src directory to remove (delete) |
|
131 | + * |
|
132 | + * @return bool true on success |
|
133 | + */ |
|
134 | + public static function rrmdir($src) |
|
135 | + { |
|
136 | + // Only continue if user is a 'global' Admin |
|
137 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + // If source is not a directory stop processing |
|
142 | + if (!is_dir($src)) { |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + $success = true; |
|
147 | + |
|
148 | + // Open the source directory to read in files |
|
149 | + $iterator = new \DirectoryIterator($src); |
|
150 | + foreach ($iterator as $fObj) { |
|
151 | + if ($fObj->isFile()) { |
|
152 | + $filename = $fObj->getPathname(); |
|
153 | + $fObj = null; // clear this iterator object to close the file |
|
154 | + if (!unlink($filename)) { |
|
155 | + return false; // couldn't delete the file |
|
156 | + } |
|
157 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
158 | + // Try recursively on directory |
|
159 | + self::rrmdir($fObj->getPathname()); |
|
160 | + } |
|
161 | + } |
|
162 | + $iterator = null; // clear iterator Obj to close file/directory |
|
163 | + return rmdir($src); // remove the directory & return results |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Recursively move files from one directory to another |
|
168 | + * |
|
169 | + * @param string $src - Source of files being moved |
|
170 | + * @param string $dest - Destination of files being moved |
|
171 | + * |
|
172 | + * @return bool true on success |
|
173 | + */ |
|
174 | + public static function rmove($src, $dest) |
|
175 | + { |
|
176 | + // Only continue if user is a 'global' Admin |
|
177 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
178 | + return false; |
|
179 | + } |
|
180 | + |
|
181 | + // If source is not a directory stop processing |
|
182 | + if (!is_dir($src)) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + // If the destination directory does not exist and could not be created stop processing |
|
187 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + // Open the source directory to read in files |
|
192 | + $iterator = new \DirectoryIterator($src); |
|
193 | + foreach ($iterator as $fObj) { |
|
194 | + if ($fObj->isFile()) { |
|
195 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
196 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
197 | + // Try recursively on directory |
|
198 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
199 | + // rmdir($fObj->getPath()); // now delete the directory |
|
200 | + } |
|
201 | + } |
|
202 | + $iterator = null; // clear iterator Obj to close file/directory |
|
203 | + return rmdir($src); // remove the directory & return results |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Recursively copy directories and files from one directory to another |
|
208 | + * |
|
209 | + * @param string $src - Source of files being moved |
|
210 | + * @param string $dest - Destination of files being moved |
|
211 | + * |
|
212 | + * @uses \Xmf\Module\Helper::getHelper() |
|
213 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
214 | + * |
|
215 | + * @return bool true on success |
|
216 | + */ |
|
217 | + public static function rcopy($src, $dest) |
|
218 | + { |
|
219 | + // Only continue if user is a 'global' Admin |
|
220 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + // If source is not a directory stop processing |
|
225 | + if (!is_dir($src)) { |
|
226 | + return false; |
|
227 | + } |
|
228 | + |
|
229 | + // If the destination directory does not exist and could not be created stop processing |
|
230 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + // Open the source directory to read in files |
|
235 | + $iterator = new \DirectoryIterator($src); |
|
236 | + foreach ($iterator as $fObj) { |
|
237 | + if ($fObj->isFile()) { |
|
238 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
239 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
240 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
241 | + } |
|
242 | + } |
|
243 | + return true; |
|
244 | + } |
|
245 | 245 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
34 | 34 | } |
35 | 35 | |
36 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
36 | + file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>'); |
|
37 | 37 | } |
38 | 38 | } catch (\Exception $e) { |
39 | 39 | echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | if (!mkdir($dst) && !is_dir($dst)) { |
62 | 62 | while (false !== ($file = readdir($dir))) { |
63 | 63 | if (('.' !== $file) && ('..' !== $file)) { |
64 | - if (is_dir($src . '/' . $file)) { |
|
65 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
64 | + if (is_dir($src.'/'.$file)) { |
|
65 | + self::recurseCopy($src.'/'.$file, $dst.'/'.$file); |
|
66 | 66 | } else { |
67 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
67 | + copy($src.'/'.$file, $dst.'/'.$file); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | self::rrmdir($fObj->getPathname()); |
160 | 160 | } |
161 | 161 | } |
162 | - $iterator = null; // clear iterator Obj to close file/directory |
|
162 | + $iterator = null; // clear iterator Obj to close file/directory |
|
163 | 163 | return rmdir($src); // remove the directory & return results |
164 | 164 | } |
165 | 165 | |
@@ -192,14 +192,14 @@ discard block |
||
192 | 192 | $iterator = new \DirectoryIterator($src); |
193 | 193 | foreach ($iterator as $fObj) { |
194 | 194 | if ($fObj->isFile()) { |
195 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | + rename($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
196 | 196 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
197 | 197 | // Try recursively on directory |
198 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
198 | + self::rmove($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
199 | 199 | // rmdir($fObj->getPath()); // now delete the directory |
200 | 200 | } |
201 | 201 | } |
202 | - $iterator = null; // clear iterator Obj to close file/directory |
|
202 | + $iterator = null; // clear iterator Obj to close file/directory |
|
203 | 203 | return rmdir($src); // remove the directory & return results |
204 | 204 | } |
205 | 205 | |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | $iterator = new \DirectoryIterator($src); |
236 | 236 | foreach ($iterator as $fObj) { |
237 | 237 | if ($fObj->isFile()) { |
238 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
238 | + copy($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
239 | 239 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
240 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | + self::rcopy($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | return true; |
@@ -6,9 +6,9 @@ |
||
6 | 6 | * Licence: GNU |
7 | 7 | */ |
8 | 8 | |
9 | -require_once __DIR__ . '/header.php'; |
|
10 | -require_once SMARTOBJECT_ROOT_PATH . 'class/smartloader.php'; |
|
11 | -require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
9 | +require_once __DIR__.'/header.php'; |
|
10 | +require_once SMARTOBJECT_ROOT_PATH.'class/smartloader.php'; |
|
11 | +require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
12 | 12 | |
13 | 13 | $xoopsTpl = new \XoopsTpl(); |
14 | 14 | $myts = \MyTextSanitizer::getInstance(); |
@@ -13,253 +13,253 @@ |
||
13 | 13 | */ |
14 | 14 | class XoopsCaptcha |
15 | 15 | { |
16 | - public $active = true; |
|
17 | - public $mode = 'text'; // potential values: image, text |
|
18 | - public $config = []; |
|
19 | - |
|
20 | - public $message = []; // Logging error messages |
|
21 | - |
|
22 | - /** |
|
23 | - * XoopsCaptcha constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - // Loading default preferences |
|
28 | - $this->config = @include __DIR__ . '/config.php'; |
|
29 | - |
|
30 | - $this->setMode($this->config['mode']); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return XoopsCaptcha |
|
35 | - */ |
|
36 | - public static function getInstance() |
|
37 | - { |
|
38 | - static $instance; |
|
39 | - if (null === $instance) { |
|
40 | - $instance = new static(); |
|
41 | - } |
|
42 | - |
|
43 | - return $instance; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @param $name |
|
48 | - * @param $val |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function setConfig($name, $val) |
|
52 | - { |
|
53 | - if ('mode' === $name) { |
|
54 | - $this->setMode($val); |
|
55 | - } elseif (isset($this->$name)) { |
|
56 | - $this->$name = $val; |
|
57 | - } else { |
|
58 | - $this->config[$name] = $val; |
|
59 | - } |
|
60 | - |
|
61 | - return true; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Set CAPTCHA mode |
|
66 | - * |
|
67 | - * For future possible modes, right now force to use text or image |
|
68 | - * |
|
69 | - * @param string $mode if no mode is set, just verify current mode |
|
70 | - */ |
|
71 | - public function setMode($mode = null) |
|
72 | - { |
|
73 | - if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
74 | - $this->mode = $mode; |
|
75 | - |
|
76 | - if ('image' !== $this->mode) { |
|
77 | - return; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - // Disable image mode |
|
82 | - if (!extension_loaded('gd')) { |
|
83 | - $this->mode = 'text'; |
|
84 | - } else { |
|
85 | - $required_functions = [ |
|
86 | - 'imagecreatetruecolor', |
|
87 | - 'imagecolorallocate', |
|
88 | - 'imagefilledrectangle', |
|
89 | - 'imagejpeg', |
|
90 | - 'imagedestroy', |
|
91 | - 'imageftbbox' |
|
92 | - ]; |
|
93 | - foreach ($required_functions as $func) { |
|
94 | - if (!function_exists($func)) { |
|
95 | - $this->mode = 'text'; |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Initializing the CAPTCHA class |
|
104 | - * @param string $name |
|
105 | - * @param null $skipmember |
|
106 | - * @param null $num_chars |
|
107 | - * @param null $fontsize_min |
|
108 | - * @param null $fontsize_max |
|
109 | - * @param null $background_type |
|
110 | - * @param null $background_num |
|
111 | - */ |
|
112 | - public function init( |
|
113 | - $name = 'xoopscaptcha', |
|
114 | - $skipmember = null, |
|
115 | - $num_chars = null, |
|
116 | - $fontsize_min = null, |
|
117 | - $fontsize_max = null, |
|
118 | - $background_type = null, |
|
119 | - $background_num = null |
|
120 | - ) { |
|
121 | - // Loading RUN-TIME settings |
|
122 | - foreach (array_keys($this->config) as $key) { |
|
123 | - if (isset(${$key}) && null !== ${$key}) { |
|
124 | - $this->config[$key] = ${$key}; |
|
125 | - } |
|
126 | - } |
|
127 | - $this->config['name'] = $name; |
|
128 | - |
|
129 | - // Skip CAPTCHA for member if set |
|
130 | - if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
131 | - $this->active = false; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Verify user submission |
|
137 | - * @param null $skipMember |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function verify($skipMember = null) |
|
141 | - { |
|
142 | - $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
143 | - $skipMember = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
144 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | - |
|
146 | - $is_valid = false; |
|
147 | - |
|
148 | - // Skip CAPTCHA for member if set |
|
149 | - if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
150 | - $is_valid = true; |
|
151 | - // Kill too many attempts |
|
152 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
153 | - $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
154 | - |
|
155 | - // Verify the code |
|
156 | - } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
157 | - $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
158 | - $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
159 | - } |
|
160 | - |
|
161 | - if (!empty($maxAttempts)) { |
|
162 | - if (!$is_valid) { |
|
163 | - // Increase the attempt records on failure |
|
164 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
165 | - // Log the error message |
|
166 | - $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
167 | - } else { |
|
168 | - |
|
169 | - // reset attempt records on success |
|
170 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
171 | - } |
|
172 | - } |
|
173 | - $this->destroyGarbage(true); |
|
174 | - |
|
175 | - return $is_valid; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return mixed|string |
|
180 | - */ |
|
181 | - public function getCaption() |
|
182 | - { |
|
183 | - return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function getMessage() |
|
190 | - { |
|
191 | - return implode('<br>', $this->message); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Destory historical stuff |
|
196 | - * @param bool $clearSession |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function destroyGarbage($clearSession = false) |
|
200 | - { |
|
201 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
203 | - $captchaHandler = new $class(); |
|
204 | - if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
205 | - $captchaHandler->loadConfig($this->config); |
|
206 | - $captchaHandler->destroyGarbage(); |
|
207 | - } |
|
208 | - |
|
209 | - if ($clearSession) { |
|
210 | - $_SESSION['XoopsCaptcha_name'] = null; |
|
211 | - $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
212 | - $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
213 | - $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
214 | - } |
|
215 | - |
|
216 | - return true; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return mixed|string |
|
221 | - */ |
|
222 | - public function render() |
|
223 | - { |
|
224 | - $form = ''; |
|
225 | - |
|
226 | - if (!$this->active || empty($this->config['name'])) { |
|
227 | - return $form; |
|
228 | - } |
|
229 | - |
|
230 | - $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
231 | - $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
232 | - $maxAttempts = $this->config['maxattempt']; |
|
233 | - $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
234 | - /* |
|
16 | + public $active = true; |
|
17 | + public $mode = 'text'; // potential values: image, text |
|
18 | + public $config = []; |
|
19 | + |
|
20 | + public $message = []; // Logging error messages |
|
21 | + |
|
22 | + /** |
|
23 | + * XoopsCaptcha constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + // Loading default preferences |
|
28 | + $this->config = @include __DIR__ . '/config.php'; |
|
29 | + |
|
30 | + $this->setMode($this->config['mode']); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return XoopsCaptcha |
|
35 | + */ |
|
36 | + public static function getInstance() |
|
37 | + { |
|
38 | + static $instance; |
|
39 | + if (null === $instance) { |
|
40 | + $instance = new static(); |
|
41 | + } |
|
42 | + |
|
43 | + return $instance; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @param $name |
|
48 | + * @param $val |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function setConfig($name, $val) |
|
52 | + { |
|
53 | + if ('mode' === $name) { |
|
54 | + $this->setMode($val); |
|
55 | + } elseif (isset($this->$name)) { |
|
56 | + $this->$name = $val; |
|
57 | + } else { |
|
58 | + $this->config[$name] = $val; |
|
59 | + } |
|
60 | + |
|
61 | + return true; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Set CAPTCHA mode |
|
66 | + * |
|
67 | + * For future possible modes, right now force to use text or image |
|
68 | + * |
|
69 | + * @param string $mode if no mode is set, just verify current mode |
|
70 | + */ |
|
71 | + public function setMode($mode = null) |
|
72 | + { |
|
73 | + if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
74 | + $this->mode = $mode; |
|
75 | + |
|
76 | + if ('image' !== $this->mode) { |
|
77 | + return; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + // Disable image mode |
|
82 | + if (!extension_loaded('gd')) { |
|
83 | + $this->mode = 'text'; |
|
84 | + } else { |
|
85 | + $required_functions = [ |
|
86 | + 'imagecreatetruecolor', |
|
87 | + 'imagecolorallocate', |
|
88 | + 'imagefilledrectangle', |
|
89 | + 'imagejpeg', |
|
90 | + 'imagedestroy', |
|
91 | + 'imageftbbox' |
|
92 | + ]; |
|
93 | + foreach ($required_functions as $func) { |
|
94 | + if (!function_exists($func)) { |
|
95 | + $this->mode = 'text'; |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Initializing the CAPTCHA class |
|
104 | + * @param string $name |
|
105 | + * @param null $skipmember |
|
106 | + * @param null $num_chars |
|
107 | + * @param null $fontsize_min |
|
108 | + * @param null $fontsize_max |
|
109 | + * @param null $background_type |
|
110 | + * @param null $background_num |
|
111 | + */ |
|
112 | + public function init( |
|
113 | + $name = 'xoopscaptcha', |
|
114 | + $skipmember = null, |
|
115 | + $num_chars = null, |
|
116 | + $fontsize_min = null, |
|
117 | + $fontsize_max = null, |
|
118 | + $background_type = null, |
|
119 | + $background_num = null |
|
120 | + ) { |
|
121 | + // Loading RUN-TIME settings |
|
122 | + foreach (array_keys($this->config) as $key) { |
|
123 | + if (isset(${$key}) && null !== ${$key}) { |
|
124 | + $this->config[$key] = ${$key}; |
|
125 | + } |
|
126 | + } |
|
127 | + $this->config['name'] = $name; |
|
128 | + |
|
129 | + // Skip CAPTCHA for member if set |
|
130 | + if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
131 | + $this->active = false; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Verify user submission |
|
137 | + * @param null $skipMember |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function verify($skipMember = null) |
|
141 | + { |
|
142 | + $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
143 | + $skipMember = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
144 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | + |
|
146 | + $is_valid = false; |
|
147 | + |
|
148 | + // Skip CAPTCHA for member if set |
|
149 | + if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
150 | + $is_valid = true; |
|
151 | + // Kill too many attempts |
|
152 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
153 | + $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
154 | + |
|
155 | + // Verify the code |
|
156 | + } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
157 | + $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
158 | + $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
159 | + } |
|
160 | + |
|
161 | + if (!empty($maxAttempts)) { |
|
162 | + if (!$is_valid) { |
|
163 | + // Increase the attempt records on failure |
|
164 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
165 | + // Log the error message |
|
166 | + $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
167 | + } else { |
|
168 | + |
|
169 | + // reset attempt records on success |
|
170 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
171 | + } |
|
172 | + } |
|
173 | + $this->destroyGarbage(true); |
|
174 | + |
|
175 | + return $is_valid; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return mixed|string |
|
180 | + */ |
|
181 | + public function getCaption() |
|
182 | + { |
|
183 | + return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getMessage() |
|
190 | + { |
|
191 | + return implode('<br>', $this->message); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Destory historical stuff |
|
196 | + * @param bool $clearSession |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function destroyGarbage($clearSession = false) |
|
200 | + { |
|
201 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
203 | + $captchaHandler = new $class(); |
|
204 | + if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
205 | + $captchaHandler->loadConfig($this->config); |
|
206 | + $captchaHandler->destroyGarbage(); |
|
207 | + } |
|
208 | + |
|
209 | + if ($clearSession) { |
|
210 | + $_SESSION['XoopsCaptcha_name'] = null; |
|
211 | + $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
212 | + $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
213 | + $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
214 | + } |
|
215 | + |
|
216 | + return true; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return mixed|string |
|
221 | + */ |
|
222 | + public function render() |
|
223 | + { |
|
224 | + $form = ''; |
|
225 | + |
|
226 | + if (!$this->active || empty($this->config['name'])) { |
|
227 | + return $form; |
|
228 | + } |
|
229 | + |
|
230 | + $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
231 | + $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
232 | + $maxAttempts = $this->config['maxattempt']; |
|
233 | + $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
234 | + /* |
|
235 | 235 | if (!empty($maxAttempts)) { |
236 | 236 | $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts; |
237 | 237 | } |
238 | 238 | */ |
239 | 239 | |
240 | - // Fail on too many attempts |
|
241 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
242 | - $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
243 | - // Load the form element |
|
244 | - } else { |
|
245 | - $form = $this->loadForm(); |
|
246 | - } |
|
247 | - |
|
248 | - return $form; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return mixed |
|
253 | - */ |
|
254 | - public function loadForm() |
|
255 | - { |
|
256 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
258 | - $captchaHandler = new $class(); |
|
259 | - $captchaHandler->loadConfig($this->config); |
|
260 | - |
|
261 | - $form = $captchaHandler->render(); |
|
262 | - |
|
263 | - return $form; |
|
264 | - } |
|
240 | + // Fail on too many attempts |
|
241 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
242 | + $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
243 | + // Load the form element |
|
244 | + } else { |
|
245 | + $form = $this->loadForm(); |
|
246 | + } |
|
247 | + |
|
248 | + return $form; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return mixed |
|
253 | + */ |
|
254 | + public function loadForm() |
|
255 | + { |
|
256 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
258 | + $captchaHandler = new $class(); |
|
259 | + $captchaHandler->loadConfig($this->config); |
|
260 | + |
|
261 | + $form = $captchaHandler->render(); |
|
262 | + |
|
263 | + return $form; |
|
264 | + } |
|
265 | 265 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | class XoopsCaptcha |
15 | 15 | { |
16 | 16 | public $active = true; |
17 | - public $mode = 'text'; // potential values: image, text |
|
17 | + public $mode = 'text'; // potential values: image, text |
|
18 | 18 | public $config = []; |
19 | 19 | |
20 | 20 | public $message = []; // Logging error messages |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct() |
26 | 26 | { |
27 | 27 | // Loading default preferences |
28 | - $this->config = @include __DIR__ . '/config.php'; |
|
28 | + $this->config = @include __DIR__.'/config.php'; |
|
29 | 29 | |
30 | 30 | $this->setMode($this->config['mode']); |
31 | 31 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $sessionName = @$_SESSION['XoopsCaptcha_name']; |
143 | 143 | $skipMember = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
144 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
144 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | 145 | |
146 | 146 | $is_valid = false; |
147 | 147 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
150 | 150 | $is_valid = true; |
151 | 151 | // Kill too many attempts |
152 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
152 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) { |
|
153 | 153 | $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
154 | 154 | |
155 | 155 | // Verify the code |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | if (!empty($maxAttempts)) { |
162 | 162 | if (!$is_valid) { |
163 | 163 | // Increase the attempt records on failure |
164 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
164 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++; |
|
165 | 165 | // Log the error message |
166 | 166 | $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
167 | 167 | } else { |
168 | 168 | |
169 | 169 | // reset attempt records on success |
170 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
170 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | $this->destroyGarbage(true); |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function destroyGarbage($clearSession = false) |
200 | 200 | { |
201 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
201 | + require_once __DIR__.'/'.$this->mode.'.php'; |
|
202 | + $class = 'XoopsCaptcha'.ucfirst($this->mode); |
|
203 | 203 | $captchaHandler = new $class(); |
204 | 204 | if (method_exists($captchaHandler, 'destroyGarbage')) { |
205 | 205 | $captchaHandler->loadConfig($this->config); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | |
240 | 240 | // Fail on too many attempts |
241 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
241 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config['name']] > $maxAttempts) { |
|
242 | 242 | $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
243 | 243 | // Load the form element |
244 | 244 | } else { |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function loadForm() |
255 | 255 | { |
256 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
256 | + require_once __DIR__.'/'.$this->mode.'.php'; |
|
257 | + $class = 'XoopsCaptcha'.ucfirst($this->mode); |
|
258 | 258 | $captchaHandler = new $class(); |
259 | 259 | $captchaHandler->loadConfig($this->config); |
260 | 260 |
@@ -38,60 +38,60 @@ |
||
38 | 38 | */ |
39 | 39 | class XoopsFormCaptcha extends \XoopsFormElement |
40 | 40 | { |
41 | - public $_captchaHandler; |
|
41 | + public $_captchaHandler; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
45 | - * @param string $name Name for the input box |
|
46 | - * @param boolean $skipmember Skip CAPTCHA check for members |
|
47 | - * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
48 | - * @param int $minfontsize Minimum font-size of characters in image mode |
|
49 | - * @param int $maxfontsize Maximum font-size of characters in image mode |
|
50 | - * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
51 | - * @param int $backgroundnum Number of background images in image mode |
|
52 | - * |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - $caption = '', |
|
56 | - $name = 'xoopscaptcha', |
|
57 | - $skipmember = null, |
|
58 | - $numchar = null, |
|
59 | - $minfontsize = null, |
|
60 | - $maxfontsize = null, |
|
61 | - $backgroundtype = null, |
|
62 | - $backgroundnum = null |
|
63 | - ) { |
|
64 | - if (!class_exists('XoopsCaptcaha')) { |
|
65 | - require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
66 | - } |
|
43 | + /** |
|
44 | + * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
45 | + * @param string $name Name for the input box |
|
46 | + * @param boolean $skipmember Skip CAPTCHA check for members |
|
47 | + * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
48 | + * @param int $minfontsize Minimum font-size of characters in image mode |
|
49 | + * @param int $maxfontsize Maximum font-size of characters in image mode |
|
50 | + * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
51 | + * @param int $backgroundnum Number of background images in image mode |
|
52 | + * |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + $caption = '', |
|
56 | + $name = 'xoopscaptcha', |
|
57 | + $skipmember = null, |
|
58 | + $numchar = null, |
|
59 | + $minfontsize = null, |
|
60 | + $maxfontsize = null, |
|
61 | + $backgroundtype = null, |
|
62 | + $backgroundnum = null |
|
63 | + ) { |
|
64 | + if (!class_exists('XoopsCaptcaha')) { |
|
65 | + require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
66 | + } |
|
67 | 67 | |
68 | - $this->_captchaHandler = XoopsCaptcha::getInstance(); |
|
69 | - $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
70 | - if (!$this->_captchaHandler->active) { |
|
71 | - $this->setHidden(); |
|
72 | - } else { |
|
73 | - $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
74 | - $this->setCaption($caption); |
|
75 | - } |
|
76 | - } |
|
68 | + $this->_captchaHandler = XoopsCaptcha::getInstance(); |
|
69 | + $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
70 | + if (!$this->_captchaHandler->active) { |
|
71 | + $this->setHidden(); |
|
72 | + } else { |
|
73 | + $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
74 | + $this->setCaption($caption); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param $name |
|
80 | - * @param $val |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - public function setConfig($name, $val) |
|
84 | - { |
|
85 | - return $this->_captchaHandler->setConfig($name, $val); |
|
86 | - } |
|
78 | + /** |
|
79 | + * @param $name |
|
80 | + * @param $val |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + public function setConfig($name, $val) |
|
84 | + { |
|
85 | + return $this->_captchaHandler->setConfig($name, $val); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return mixed|string |
|
90 | - */ |
|
91 | - public function render() |
|
92 | - { |
|
93 | - if (!$this->isHidden()) { |
|
94 | - return $this->_captchaHandler->render(); |
|
95 | - } |
|
96 | - } |
|
88 | + /** |
|
89 | + * @return mixed|string |
|
90 | + */ |
|
91 | + public function render() |
|
92 | + { |
|
93 | + if (!$this->isHidden()) { |
|
94 | + return $this->_captchaHandler->render(); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
15 | 15 | |
16 | -require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php'; |
|
16 | +require_once XOOPS_ROOT_PATH.'/class/xoopsform/formelement.php'; |
|
17 | 17 | |
18 | 18 | /* |
19 | 19 | * Usage |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $backgroundnum = null |
63 | 63 | ) { |
64 | 64 | if (!class_exists('XoopsCaptcaha')) { |
65 | - require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
65 | + require_once SMARTOBJECT_ROOT_PATH.'/include/captcha/captcha.php'; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $this->_captchaHandler = XoopsCaptcha::getInstance(); |
@@ -19,62 +19,62 @@ |
||
19 | 19 | |
20 | 20 | function getConfig() |
21 | 21 | { |
22 | - $moduleDirName = basename(dirname(__DIR__)); |
|
23 | - $moduleDirNameUpper = strtoupper($moduleDirName); |
|
24 | - return (object)[ |
|
25 | - 'name' => strtoupper($moduleDirName) . ' Module Configurator', |
|
26 | - 'paths' => [ |
|
27 | - 'dirname' => $moduleDirName, |
|
28 | - 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', |
|
29 | - 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, |
|
30 | - 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, |
|
31 | - 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, |
|
32 | - 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, |
|
33 | - ], |
|
34 | - 'uploadFolders' => [ |
|
35 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
36 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
37 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
38 | - //XOOPS_UPLOAD_PATH . '/flags' |
|
39 | - ], |
|
40 | - 'copyBlankFiles' => [ |
|
41 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
42 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
43 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
44 | - //XOOPS_UPLOAD_PATH . '/flags' |
|
45 | - ], |
|
22 | + $moduleDirName = basename(dirname(__DIR__)); |
|
23 | + $moduleDirNameUpper = strtoupper($moduleDirName); |
|
24 | + return (object)[ |
|
25 | + 'name' => strtoupper($moduleDirName) . ' Module Configurator', |
|
26 | + 'paths' => [ |
|
27 | + 'dirname' => $moduleDirName, |
|
28 | + 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', |
|
29 | + 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, |
|
30 | + 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, |
|
31 | + 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, |
|
32 | + 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, |
|
33 | + ], |
|
34 | + 'uploadFolders' => [ |
|
35 | + constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
36 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
37 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
38 | + //XOOPS_UPLOAD_PATH . '/flags' |
|
39 | + ], |
|
40 | + 'copyBlankFiles' => [ |
|
41 | + constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
42 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
43 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
44 | + //XOOPS_UPLOAD_PATH . '/flags' |
|
45 | + ], |
|
46 | 46 | |
47 | - 'copyTestFolders' => [ |
|
48 | - // constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
49 | - //[ |
|
50 | - // constant($moduleDirNameUpper . '_PATH') . '/testdata/images', |
|
51 | - // constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/images', |
|
52 | - //] |
|
53 | - ], |
|
47 | + 'copyTestFolders' => [ |
|
48 | + // constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
49 | + //[ |
|
50 | + // constant($moduleDirNameUpper . '_PATH') . '/testdata/images', |
|
51 | + // constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/images', |
|
52 | + //] |
|
53 | + ], |
|
54 | 54 | |
55 | - 'templateFolders' => [ |
|
56 | - '/templates/', |
|
57 | - '/templates/blocks/', |
|
58 | - '/templates/admin/' |
|
55 | + 'templateFolders' => [ |
|
56 | + '/templates/', |
|
57 | + '/templates/blocks/', |
|
58 | + '/templates/admin/' |
|
59 | 59 | |
60 | - ], |
|
61 | - 'oldFiles' => [ |
|
62 | - '/class/request.php', |
|
63 | - '/class/registry.php', |
|
64 | - '/class/utilities.php', |
|
65 | - '/class/util.php', |
|
66 | - '/include/constants.php', |
|
67 | - '/include/functions.php', |
|
68 | - '/ajaxrating.txt', |
|
69 | - ], |
|
70 | - 'oldFolders' => [ |
|
71 | - '/images', |
|
72 | - '/css', |
|
73 | - '/js', |
|
74 | - '/tcpdf', |
|
75 | - '/images', |
|
76 | - ], |
|
77 | - 'modCopyright' => "<a href='https://xoops.org' title='XOOPS Project' target='_blank'> |
|
60 | + ], |
|
61 | + 'oldFiles' => [ |
|
62 | + '/class/request.php', |
|
63 | + '/class/registry.php', |
|
64 | + '/class/utilities.php', |
|
65 | + '/class/util.php', |
|
66 | + '/include/constants.php', |
|
67 | + '/include/functions.php', |
|
68 | + '/ajaxrating.txt', |
|
69 | + ], |
|
70 | + 'oldFolders' => [ |
|
71 | + '/images', |
|
72 | + '/css', |
|
73 | + '/js', |
|
74 | + '/tcpdf', |
|
75 | + '/images', |
|
76 | + ], |
|
77 | + 'modCopyright' => "<a href='https://xoops.org' title='XOOPS Project' target='_blank'> |
|
78 | 78 | <img src='" . constant($moduleDirNameUpper . '_AUTHOR_LOGOIMG') . '\' alt=\'XOOPS Project\' /></a>', |
79 | - ]; |
|
79 | + ]; |
|
80 | 80 | } |
@@ -21,26 +21,26 @@ discard block |
||
21 | 21 | { |
22 | 22 | $moduleDirName = basename(dirname(__DIR__)); |
23 | 23 | $moduleDirNameUpper = strtoupper($moduleDirName); |
24 | - return (object)[ |
|
25 | - 'name' => strtoupper($moduleDirName) . ' Module Configurator', |
|
24 | + return (object) [ |
|
25 | + 'name' => strtoupper($moduleDirName).' Module Configurator', |
|
26 | 26 | 'paths' => [ |
27 | 27 | 'dirname' => $moduleDirName, |
28 | - 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', |
|
29 | - 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, |
|
30 | - 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, |
|
31 | - 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, |
|
32 | - 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, |
|
28 | + 'admin' => XOOPS_ROOT_PATH.'/modules/'.$moduleDirName.'/admin', |
|
29 | + 'modPath' => XOOPS_ROOT_PATH.'/modules/'.$moduleDirName, |
|
30 | + 'modUrl' => XOOPS_URL.'/modules/'.$moduleDirName, |
|
31 | + 'uploadPath' => XOOPS_UPLOAD_PATH.'/'.$moduleDirName, |
|
32 | + 'uploadUrl' => XOOPS_UPLOAD_URL.'/'.$moduleDirName, |
|
33 | 33 | ], |
34 | 34 | 'uploadFolders' => [ |
35 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
36 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
37 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
35 | + constant($moduleDirNameUpper.'_UPLOAD_PATH'), |
|
36 | + constant($moduleDirNameUpper.'_UPLOAD_PATH').'/category', |
|
37 | + constant($moduleDirNameUpper.'_UPLOAD_PATH').'/screenshots', |
|
38 | 38 | //XOOPS_UPLOAD_PATH . '/flags' |
39 | 39 | ], |
40 | 40 | 'copyBlankFiles' => [ |
41 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
42 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
43 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
41 | + constant($moduleDirNameUpper.'_UPLOAD_PATH'), |
|
42 | + constant($moduleDirNameUpper.'_UPLOAD_PATH').'/category', |
|
43 | + constant($moduleDirNameUpper.'_UPLOAD_PATH').'/screenshots', |
|
44 | 44 | //XOOPS_UPLOAD_PATH . '/flags' |
45 | 45 | ], |
46 | 46 | |
@@ -75,6 +75,6 @@ discard block |
||
75 | 75 | '/images', |
76 | 76 | ], |
77 | 77 | 'modCopyright' => "<a href='https://xoops.org' title='XOOPS Project' target='_blank'> |
78 | - <img src='" . constant($moduleDirNameUpper . '_AUTHOR_LOGOIMG') . '\' alt=\'XOOPS Project\' /></a>', |
|
78 | + <img src='" . constant($moduleDirNameUpper.'_AUTHOR_LOGOIMG').'\' alt=\'XOOPS Project\' /></a>', |
|
79 | 79 | ]; |
80 | 80 | } |
@@ -8,7 +8,6 @@ |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | use XoopsModules\Wfdownloads; |
11 | -use XoopsModules\Smartobject; |
|
12 | 11 | |
13 | 12 | require_once __DIR__ . '/admin_header.php'; |
14 | 13 | require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
@@ -21,188 +21,188 @@ discard block |
||
21 | 21 | // ========================================================================================= |
22 | 22 | function update_tables_to_300() |
23 | 23 | { |
24 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
24 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
25 | 25 | |
26 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
27 | - // Create table wfdownloads_meta |
|
28 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
29 | - $table->setStructure("CREATE TABLE `%s` ( |
|
26 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
27 | + // Create table wfdownloads_meta |
|
28 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
29 | + $table->setStructure("CREATE TABLE `%s` ( |
|
30 | 30 | metakey varchar(50) NOT NULL default '', |
31 | 31 | metavalue varchar(255) NOT NULL default '', |
32 | 32 | PRIMARY KEY (metakey)) |
33 | 33 | ENGINE=MyISAM;"); |
34 | 34 | |
35 | - $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
36 | - if ($dbupdater->updateTable($table)) { |
|
37 | - echo 'wfdownloads_meta table created<br>'; |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - $download_fields = [ |
|
42 | - 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
43 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
44 | - 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
45 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
46 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
47 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
48 | - 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
49 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
50 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
51 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
52 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
53 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
54 | - 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
55 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
56 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
57 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
58 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
59 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
60 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
61 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
62 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
63 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
64 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
65 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
66 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
67 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
68 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
69 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
70 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
71 | - 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
72 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
73 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
74 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
75 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
76 | - 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
77 | - 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
78 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
79 | - ]; |
|
80 | - |
|
81 | - $renamed_fields = [ |
|
82 | - 'logourl' => 'screenshot' |
|
83 | - ]; |
|
84 | - |
|
85 | - echo '<br><b>Checking Download table</b><br>'; |
|
86 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
87 | - $downloadHandler = $helperWfdownloads->getHandler('Download'); |
|
88 | - $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
89 | - $fields = get_table_info($downloadHandler->table, $download_fields); |
|
90 | - // Check for renamed fields |
|
91 | - rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
92 | - update_table($download_fields, $fields, $download_table); |
|
93 | - if ($dbupdater->updateTable($download_table)) { |
|
94 | - echo 'Downloads table updated<br>'; |
|
95 | - } |
|
96 | - unset($fields); |
|
97 | - |
|
98 | - $mod_fields = [ |
|
99 | - 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
100 | - 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
101 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
102 | - 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
103 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
104 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
105 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
106 | - 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
107 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
108 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
109 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
110 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
111 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
112 | - 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
113 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
114 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
115 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
116 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
117 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
118 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
119 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
120 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
121 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
122 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
123 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
124 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
125 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
126 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
127 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
128 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
129 | - 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
130 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
131 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
132 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
133 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
134 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
135 | - 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
136 | - 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
137 | - ]; |
|
138 | - |
|
139 | - $renamed_fields = [ |
|
140 | - 'logourl' => 'screenshot' |
|
141 | - ]; |
|
142 | - |
|
143 | - echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
35 | + $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
36 | + if ($dbupdater->updateTable($table)) { |
|
37 | + echo 'wfdownloads_meta table created<br>'; |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + $download_fields = [ |
|
42 | + 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
43 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
44 | + 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
45 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
46 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
47 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
48 | + 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
49 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
50 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
51 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
52 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
53 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
54 | + 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
55 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
56 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
57 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
58 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
59 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
60 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
61 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
62 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
63 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
64 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
65 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
66 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
67 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
68 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
69 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
70 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
71 | + 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
72 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
73 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
74 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
75 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
76 | + 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
77 | + 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
78 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
79 | + ]; |
|
80 | + |
|
81 | + $renamed_fields = [ |
|
82 | + 'logourl' => 'screenshot' |
|
83 | + ]; |
|
84 | + |
|
85 | + echo '<br><b>Checking Download table</b><br>'; |
|
86 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
87 | + $downloadHandler = $helperWfdownloads->getHandler('Download'); |
|
88 | + $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
89 | + $fields = get_table_info($downloadHandler->table, $download_fields); |
|
90 | + // Check for renamed fields |
|
91 | + rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
92 | + update_table($download_fields, $fields, $download_table); |
|
93 | + if ($dbupdater->updateTable($download_table)) { |
|
94 | + echo 'Downloads table updated<br>'; |
|
95 | + } |
|
96 | + unset($fields); |
|
97 | + |
|
98 | + $mod_fields = [ |
|
99 | + 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
100 | + 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
101 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
102 | + 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
103 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
104 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
105 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
106 | + 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
107 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
108 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
109 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
110 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
111 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
112 | + 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
113 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
114 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
115 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
116 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
117 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
118 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
119 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
120 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
121 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
122 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
123 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
124 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
125 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
126 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
127 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
128 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
129 | + 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
130 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
131 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
132 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
133 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
134 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
135 | + 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
136 | + 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
137 | + ]; |
|
138 | + |
|
139 | + $renamed_fields = [ |
|
140 | + 'logourl' => 'screenshot' |
|
141 | + ]; |
|
142 | + |
|
143 | + echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
144 | 144 | // $moduleHandler = xoops_getModuleHandler('modification', 'wfdownloads'); |
145 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
146 | - $moduleHandler = $helperWfdownloads->getHandler('Modification'); |
|
147 | - $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
148 | - $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
149 | - rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
150 | - update_table($mod_fields, $fields, $mod_table); |
|
151 | - if ($dbupdater->updateTable($mod_table)) { |
|
152 | - echo 'Modified Downloads table updated <br>'; |
|
153 | - } |
|
154 | - unset($fields); |
|
155 | - |
|
156 | - $cat_fields = [ |
|
157 | - 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
158 | - 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
159 | - 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
160 | - 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
161 | - 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
162 | - 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
163 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
164 | - 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
165 | - 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
166 | - 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
167 | - 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
168 | - 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
169 | - 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
170 | - 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
171 | - 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
172 | - ]; |
|
173 | - echo '<br><b>Checking Category table</b><br>'; |
|
145 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
146 | + $moduleHandler = $helperWfdownloads->getHandler('Modification'); |
|
147 | + $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
148 | + $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
149 | + rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
150 | + update_table($mod_fields, $fields, $mod_table); |
|
151 | + if ($dbupdater->updateTable($mod_table)) { |
|
152 | + echo 'Modified Downloads table updated <br>'; |
|
153 | + } |
|
154 | + unset($fields); |
|
155 | + |
|
156 | + $cat_fields = [ |
|
157 | + 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
158 | + 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
159 | + 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
160 | + 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
161 | + 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
162 | + 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
163 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
164 | + 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
165 | + 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
166 | + 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
167 | + 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
168 | + 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
169 | + 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
170 | + 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
171 | + 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
172 | + ]; |
|
173 | + echo '<br><b>Checking Category table</b><br>'; |
|
174 | 174 | // $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
175 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
176 | - $catHandler = $helperWfdownloads->getHandler('Report'); |
|
177 | - |
|
178 | - $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
179 | - $fields = get_table_info($catHandler->table, $cat_fields); |
|
180 | - update_table($cat_fields, $fields, $cat_table); |
|
181 | - if ($dbupdater->updateTable($cat_table)) { |
|
182 | - echo 'Category table updated<br>'; |
|
183 | - } |
|
184 | - unset($fields); |
|
185 | - |
|
186 | - $broken_fields = [ |
|
187 | - 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
188 | - 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
189 | - 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
190 | - 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
191 | - 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
192 | - 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
193 | - 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
194 | - ]; |
|
195 | - echo '<br><b>Checking Broken Report table</b><br>'; |
|
196 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
197 | - $brokenHandler = $helperWfdownloads->getHandler('Report'); |
|
175 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
176 | + $catHandler = $helperWfdownloads->getHandler('Report'); |
|
177 | + |
|
178 | + $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
179 | + $fields = get_table_info($catHandler->table, $cat_fields); |
|
180 | + update_table($cat_fields, $fields, $cat_table); |
|
181 | + if ($dbupdater->updateTable($cat_table)) { |
|
182 | + echo 'Category table updated<br>'; |
|
183 | + } |
|
184 | + unset($fields); |
|
185 | + |
|
186 | + $broken_fields = [ |
|
187 | + 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
188 | + 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
189 | + 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
190 | + 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
191 | + 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
192 | + 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
193 | + 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
194 | + ]; |
|
195 | + echo '<br><b>Checking Broken Report table</b><br>'; |
|
196 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
197 | + $brokenHandler = $helperWfdownloads->getHandler('Report'); |
|
198 | 198 | // $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads'); |
199 | - $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
200 | - $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
201 | - update_table($broken_fields, $fields, $broken_table); |
|
202 | - if ($dbupdater->updateTable($broken_table)) { |
|
203 | - echo 'Broken Reports table updated<br>'; |
|
204 | - } |
|
205 | - unset($fields); |
|
199 | + $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
200 | + $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
201 | + update_table($broken_fields, $fields, $broken_table); |
|
202 | + if ($dbupdater->updateTable($broken_table)) { |
|
203 | + echo 'Broken Reports table updated<br>'; |
|
204 | + } |
|
205 | + unset($fields); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // ========================================================================================= |
@@ -215,49 +215,49 @@ discard block |
||
215 | 215 | */ |
216 | 216 | function invert_nohtm_dohtml_values() |
217 | 217 | { |
218 | - $ret = []; |
|
219 | - global $xoopsDB; |
|
220 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
221 | - $catHandler = $helperWfdownloads->getHandler('Category'); |
|
222 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
223 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
224 | - $fields[$existing_field['field']] = $existing_field['type']; |
|
225 | - } |
|
226 | - if (in_array('nohtml', array_keys($fields))) { |
|
227 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
228 | - //Invert column values |
|
229 | - // alter options in wfdownloads_cat |
|
230 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
231 | - $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
232 | - $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
233 | - $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
234 | - $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
235 | - $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
236 | - |
|
237 | - //inverting values no=1 <=> do=0 |
|
238 | - // have to store teporarly as value = 2 to |
|
239 | - // avoid putting everithing to same value |
|
240 | - // if you change 1 to 0, then 0 to one, |
|
241 | - // every value will be 1, follow me? |
|
242 | - $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
243 | - $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
244 | - $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
245 | - |
|
246 | - $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
247 | - $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
248 | - $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
249 | - |
|
250 | - $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
251 | - $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
252 | - $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
253 | - |
|
254 | - $table->addUpdatedWhere('doimage', 2, '=1'); |
|
255 | - $table->addUpdatedWhere('doimage', 1, '=0'); |
|
256 | - $table->addUpdatedWhere('doimage', 0, '=2'); |
|
257 | - $ret = $dbupdater->updateTable($table); |
|
258 | - } |
|
259 | - |
|
260 | - return $ret; |
|
218 | + $ret = []; |
|
219 | + global $xoopsDB; |
|
220 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
221 | + $catHandler = $helperWfdownloads->getHandler('Category'); |
|
222 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
223 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
224 | + $fields[$existing_field['field']] = $existing_field['type']; |
|
225 | + } |
|
226 | + if (in_array('nohtml', array_keys($fields))) { |
|
227 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
228 | + //Invert column values |
|
229 | + // alter options in wfdownloads_cat |
|
230 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
231 | + $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
232 | + $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
233 | + $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
234 | + $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
235 | + $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
236 | + |
|
237 | + //inverting values no=1 <=> do=0 |
|
238 | + // have to store teporarly as value = 2 to |
|
239 | + // avoid putting everithing to same value |
|
240 | + // if you change 1 to 0, then 0 to one, |
|
241 | + // every value will be 1, follow me? |
|
242 | + $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
243 | + $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
244 | + $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
245 | + |
|
246 | + $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
247 | + $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
248 | + $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
249 | + |
|
250 | + $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
251 | + $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
252 | + $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
253 | + |
|
254 | + $table->addUpdatedWhere('doimage', 2, '=1'); |
|
255 | + $table->addUpdatedWhere('doimage', 1, '=0'); |
|
256 | + $table->addUpdatedWhere('doimage', 0, '=2'); |
|
257 | + $ret = $dbupdater->updateTable($table); |
|
258 | + } |
|
259 | + |
|
260 | + return $ret; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -270,22 +270,22 @@ discard block |
||
270 | 270 | */ |
271 | 271 | function update_table($new_fields, $existing_fields, &$table) |
272 | 272 | { |
273 | - foreach ($new_fields as $field => $fieldinfo) { |
|
274 | - $type = $fieldinfo['Type']; |
|
275 | - if (!in_array($field, array_keys($existing_fields))) { |
|
276 | - //Add field as it is missing |
|
277 | - $table->addNewField($field, $type); |
|
278 | - //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
279 | - //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
280 | - } elseif ($existing_fields[$field] != $type) { |
|
281 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
282 | - // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
283 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
284 | - //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
285 | - } else { |
|
286 | - //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
287 | - } |
|
288 | - } |
|
273 | + foreach ($new_fields as $field => $fieldinfo) { |
|
274 | + $type = $fieldinfo['Type']; |
|
275 | + if (!in_array($field, array_keys($existing_fields))) { |
|
276 | + //Add field as it is missing |
|
277 | + $table->addNewField($field, $type); |
|
278 | + //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
279 | + //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
280 | + } elseif ($existing_fields[$field] != $type) { |
|
281 | + $table->addAlteredField($field, $field . ' ' . $type); |
|
282 | + // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
283 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
284 | + //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
285 | + } else { |
|
286 | + //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
287 | + } |
|
288 | + } |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -298,22 +298,22 @@ discard block |
||
298 | 298 | */ |
299 | 299 | function get_table_info($table, $default_fields) |
300 | 300 | { |
301 | - global $xoopsDB; |
|
302 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
303 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
304 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
305 | - if ('YES' !== $existing_field['Null']) { |
|
306 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
307 | - } |
|
308 | - if ($existing_field['Extra']) { |
|
309 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
310 | - } |
|
311 | - if ($default_fields[$existing_field['Field']]['Default']) { |
|
312 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - return $fields; |
|
301 | + global $xoopsDB; |
|
302 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
303 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
304 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
305 | + if ('YES' !== $existing_field['Null']) { |
|
306 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
307 | + } |
|
308 | + if ($existing_field['Extra']) { |
|
309 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
310 | + } |
|
311 | + if ($default_fields[$existing_field['Field']]['Default']) { |
|
312 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + return $fields; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -327,60 +327,60 @@ discard block |
||
327 | 327 | */ |
328 | 328 | function rename_fields(&$table, $renamed_fields, &$fields, $new_fields) |
329 | 329 | { |
330 | - foreach (array_keys($fields) as $field) { |
|
331 | - if (in_array($field, array_keys($renamed_fields))) { |
|
332 | - $new_field_name = $renamed_fields[$field]; |
|
333 | - $new_field_type = $new_fields[$new_field_name]['Type']; |
|
334 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
335 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
336 | - //echo $field." Renamed to ".$new_field_name."<br>"; |
|
337 | - $fields[$new_field_name] = $new_field_type; |
|
338 | - } |
|
339 | - } |
|
340 | - //return $fields; |
|
330 | + foreach (array_keys($fields) as $field) { |
|
331 | + if (in_array($field, array_keys($renamed_fields))) { |
|
332 | + $new_field_name = $renamed_fields[$field]; |
|
333 | + $new_field_type = $new_fields[$new_field_name]['Type']; |
|
334 | + $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
335 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
336 | + //echo $field." Renamed to ".$new_field_name."<br>"; |
|
337 | + $fields[$new_field_name] = $new_field_type; |
|
338 | + } |
|
339 | + } |
|
340 | + //return $fields; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $op = \Xmf\Request::getInt('op', 0, 'REQUEST'); |
344 | 344 | switch ($op) { |
345 | - case 1: |
|
346 | - // Make sure that nohtml is properly changed to dohtml |
|
347 | - invert_nohtm_dohtml_values(); |
|
348 | - // Ensure that the proper tables are present |
|
349 | - update_tables_to_300(); |
|
350 | - // Import data from MyDownloads |
|
351 | - import_mydownloads_to_wfdownloads(); |
|
352 | - break; |
|
353 | - |
|
354 | - case 2: |
|
355 | - // Update WF-Downloads |
|
356 | - $log = invert_nohtm_dohtml_values(); |
|
357 | - update_tables_to_300(); |
|
358 | - break; |
|
359 | - |
|
360 | - default: |
|
361 | - //ask what to do |
|
362 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
363 | - $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
364 | - |
|
365 | - //Is MyDownloads installed? |
|
366 | - /** @var XoopsModuleHandler $moduleHandler */ |
|
367 | - $moduleHandler = xoops_getHandler('module'); |
|
368 | - $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
369 | - if (is_object($mydownloadsModule)) { |
|
370 | - $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
371 | - $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
372 | - $form->addElement($mydownloadsButton); |
|
373 | - } |
|
374 | - |
|
375 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
376 | - $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
377 | - $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
378 | - $form->addElement($updateButton); |
|
379 | - } |
|
380 | - |
|
381 | - $form->addElement(new \XoopsFormHidden('op', 0)); |
|
382 | - $form->display(); |
|
383 | - break; |
|
345 | + case 1: |
|
346 | + // Make sure that nohtml is properly changed to dohtml |
|
347 | + invert_nohtm_dohtml_values(); |
|
348 | + // Ensure that the proper tables are present |
|
349 | + update_tables_to_300(); |
|
350 | + // Import data from MyDownloads |
|
351 | + import_mydownloads_to_wfdownloads(); |
|
352 | + break; |
|
353 | + |
|
354 | + case 2: |
|
355 | + // Update WF-Downloads |
|
356 | + $log = invert_nohtm_dohtml_values(); |
|
357 | + update_tables_to_300(); |
|
358 | + break; |
|
359 | + |
|
360 | + default: |
|
361 | + //ask what to do |
|
362 | + include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
363 | + $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
364 | + |
|
365 | + //Is MyDownloads installed? |
|
366 | + /** @var XoopsModuleHandler $moduleHandler */ |
|
367 | + $moduleHandler = xoops_getHandler('module'); |
|
368 | + $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
369 | + if (is_object($mydownloadsModule)) { |
|
370 | + $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
371 | + $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
372 | + $form->addElement($mydownloadsButton); |
|
373 | + } |
|
374 | + |
|
375 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
376 | + $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
377 | + $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
378 | + $form->addElement($updateButton); |
|
379 | + } |
|
380 | + |
|
381 | + $form->addElement(new \XoopsFormHidden('op', 0)); |
|
382 | + $form->display(); |
|
383 | + break; |
|
384 | 384 | } |
385 | 385 | //wfdownloads_modFooter(); |
386 | 386 | //xoops_cp_footer(); |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use XoopsModules\Wfdownloads; |
11 | 11 | use XoopsModules\Smartobject; |
12 | 12 | |
13 | -require_once __DIR__ . '/admin_header.php'; |
|
14 | -require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
|
13 | +require_once __DIR__.'/admin_header.php'; |
|
14 | +require_once SMARTCONTENT_ROOT_PATH.'class/dbupdater.php'; |
|
15 | 15 | |
16 | 16 | smartcontent_xoops_cp_header(); |
17 | 17 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | global $xoopsDB; |
220 | 220 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
221 | 221 | $catHandler = $helperWfdownloads->getHandler('Category'); |
222 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
222 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$catHandler->table); |
|
223 | 223 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
224 | 224 | $fields[$existing_field['field']] = $existing_field['type']; |
225 | 225 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
279 | 279 | //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
280 | 280 | } elseif ($existing_fields[$field] != $type) { |
281 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
281 | + $table->addAlteredField($field, $field.' '.$type); |
|
282 | 282 | // check $fields[$field]['type'] for things like "int(10) unsigned" |
283 | 283 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
284 | 284 | //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
@@ -299,17 +299,17 @@ discard block |
||
299 | 299 | function get_table_info($table, $default_fields) |
300 | 300 | { |
301 | 301 | global $xoopsDB; |
302 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
302 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$table); |
|
303 | 303 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
304 | 304 | $fields[$existing_field['Field']] = $existing_field['Type']; |
305 | 305 | if ('YES' !== $existing_field['Null']) { |
306 | 306 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
307 | 307 | } |
308 | 308 | if ($existing_field['Extra']) { |
309 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
309 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
310 | 310 | } |
311 | 311 | if ($default_fields[$existing_field['Field']]['Default']) { |
312 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
312 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if (in_array($field, array_keys($renamed_fields))) { |
332 | 332 | $new_field_name = $renamed_fields[$field]; |
333 | 333 | $new_field_type = $new_fields[$new_field_name]['Type']; |
334 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
334 | + $table->addAltered($field, $new_field_name.' '.$new_field_type); |
|
335 | 335 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
336 | 336 | //echo $field." Renamed to ".$new_field_name."<br>"; |
337 | 337 | $fields[$new_field_name] = $new_field_type; |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | default: |
361 | 361 | //ask what to do |
362 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
362 | + include XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
363 | 363 | $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
364 | 364 | |
365 | 365 | //Is MyDownloads installed? |
@@ -384,4 +384,4 @@ discard block |
||
384 | 384 | } |
385 | 385 | //wfdownloads_modFooter(); |
386 | 386 | //xoops_cp_footer(); |
387 | -require_once __DIR__ . '/admin_footer.php'; |
|
387 | +require_once __DIR__.'/admin_footer.php'; |
@@ -164,7 +164,7 @@ |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * @param $field |
|
167 | + * @param string $field |
|
168 | 168 | * @return bool |
169 | 169 | */ |
170 | 170 | public function fieldExists($field) |
@@ -25,7 +25,6 @@ discard block |
||
25 | 25 | * Contains the classes for updating database tables |
26 | 26 | * |
27 | 27 | * @license GNU |
28 | - |
|
29 | 28 | */ |
30 | 29 | /** |
31 | 30 | * SmartDbTable class |
@@ -38,7 +37,7 @@ discard block |
||
38 | 37 | */ |
39 | 38 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
40 | 39 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
40 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
42 | 41 | } |
43 | 42 | /** |
44 | 43 | * Include the language constants for the SmartObjectDBUpdater |
@@ -46,7 +45,7 @@ discard block |
||
46 | 45 | global $xoopsConfig; |
47 | 46 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
48 | 47 | if (!file_exists($common_file)) { |
49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
48 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
50 | 49 | } |
51 | 50 | include $common_file; |
52 | 51 | |
@@ -55,501 +54,501 @@ discard block |
||
55 | 54 | */ |
56 | 55 | class DbTable |
57 | 56 | { |
58 | - /** |
|
59 | - * @var string $_name name of the table |
|
60 | - */ |
|
61 | - public $_name; |
|
62 | - /** |
|
63 | - * @var string $_structure structure of the table |
|
64 | - */ |
|
65 | - public $_structure; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var array $_data containing valued of each records to be added |
|
69 | - */ |
|
70 | - public $_data; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var array $_alteredFields containing fields to be altered |
|
74 | - */ |
|
75 | - public $_alteredFields; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var array $_newFields containing new fields to be added |
|
79 | - */ |
|
80 | - public $_newFields; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var array $_droppedFields containing fields to be dropped |
|
84 | - */ |
|
85 | - public $_droppedFields; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var array $_flagForDrop flag table to drop it |
|
89 | - */ |
|
90 | - public $_flagForDrop = false; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var array $_updatedFields containing fields which values will be updated |
|
94 | - */ |
|
95 | - public $_updatedFields; |
|
96 | - |
|
97 | - /** |
|
98 | - * @var array $_updatedFields containing fields which values will be updated |
|
99 | - */ //felix |
|
100 | - public $_updatedWhere; |
|
101 | - |
|
102 | - public $_existingFieldsArray = false; |
|
103 | - |
|
104 | - /** |
|
105 | - * Constructor |
|
106 | - * |
|
107 | - * @param string $name name of the table |
|
108 | - * |
|
109 | - */ |
|
110 | - public function __construct($name) |
|
111 | - { |
|
112 | - $this->_name = $name; |
|
113 | - $this->_data = []; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the table name, prefixed with site table prefix |
|
118 | - * |
|
119 | - * @return string table name |
|
120 | - * |
|
121 | - */ |
|
122 | - public function name() |
|
123 | - { |
|
124 | - global $xoopsDB; |
|
125 | - |
|
126 | - return $xoopsDB->prefix($this->_name); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Checks if the table already exists in the database |
|
131 | - * |
|
132 | - * @return bool TRUE if it exists, FALSE if not |
|
133 | - * |
|
134 | - */ |
|
135 | - public function exists() |
|
136 | - { |
|
137 | - return Smartobject\Utility::isTable($this->_name); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getExistingFieldsArray() |
|
144 | - { |
|
145 | - global $xoopsDB; |
|
146 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
147 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
148 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
149 | - if ('YES' !== $existing_field['Null']) { |
|
150 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
151 | - } |
|
152 | - if ($existing_field['Extra']) { |
|
153 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
154 | - } |
|
155 | - if (!(null === $existing_field['Default']) |
|
156 | - && ($existing_field['Default'] |
|
157 | - || '' === $existing_field['Default'] |
|
158 | - || 0 == $existing_field['Default'])) { |
|
159 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - return $fields; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param $field |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function fieldExists($field) |
|
171 | - { |
|
172 | - $existingFields = $this->getExistingFieldsArray(); |
|
173 | - |
|
174 | - return isset($existingFields[$field]); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Set the table structure |
|
179 | - * |
|
180 | - * Example: |
|
181 | - * |
|
182 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
183 | - * `date` int(11) NOT NULL default '0', |
|
184 | - * `status` int(1) NOT NULL default '-1', |
|
185 | - * `itemid` int(11) NOT NULL default '0', |
|
186 | - * `uid` int(11) NOT NULL default '0', |
|
187 | - * `price` float NOT NULL default '0', |
|
188 | - * `currency` varchar(100) NOT NULL default '', |
|
189 | - * PRIMARY KEY (`transactionid`)"); |
|
190 | - * |
|
191 | - * @param string $structure table structure |
|
192 | - * |
|
193 | - */ |
|
194 | - public function setStructure($structure) |
|
195 | - { |
|
196 | - $this->_structure = $structure; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Return the table structure |
|
201 | - * |
|
202 | - * @return string table structure |
|
203 | - * |
|
204 | - */ |
|
205 | - public function getStructure() |
|
206 | - { |
|
207 | - return sprintf($this->_structure, $this->name()); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Add values of a record to be added |
|
212 | - * |
|
213 | - * @param string $data values of a record |
|
214 | - * |
|
215 | - */ |
|
216 | - public function setData($data) |
|
217 | - { |
|
218 | - $this->_data[] = $data; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get the data array |
|
223 | - * |
|
224 | - * @return array containing the records values to be added |
|
225 | - * |
|
226 | - */ |
|
227 | - public function getData() |
|
228 | - { |
|
229 | - return $this->_data; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Use to insert data in a table |
|
234 | - * |
|
235 | - * @return bool true if success, false if an error occured |
|
236 | - * |
|
237 | - */ |
|
238 | - public function addData() |
|
239 | - { |
|
240 | - global $xoopsDB; |
|
241 | - foreach ($this->getData() as $data) { |
|
242 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
243 | - $ret = $xoopsDB->query($query); |
|
244 | - if (!$ret) { |
|
245 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
246 | - } else { |
|
247 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - return $ret; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Add a field to be added |
|
256 | - * |
|
257 | - * @param string $name name of the field |
|
258 | - * @param string $properties properties of the field |
|
259 | - * @param bool $newname |
|
260 | - * @param bool $showerror |
|
261 | - */ |
|
262 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
263 | - { |
|
264 | - $field['name'] = $name; |
|
265 | - $field['properties'] = $properties; |
|
266 | - $field['showerror'] = $showerror; |
|
267 | - $field['newname'] = $newname; |
|
268 | - $this->_alteredFields[] = $field; |
|
269 | - } |
|
270 | - /** |
|
271 | - * Invert values 0 to 1 and 1 to 0 |
|
272 | - * |
|
273 | - * @param string $name name of the field |
|
274 | - * @param $newValue |
|
275 | - * @param $oldValue |
|
276 | - * @internal param string $old old propertie |
|
277 | - * @internal param string $new new propertie |
|
278 | - */ //felix |
|
279 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
280 | - { |
|
281 | - $field['name'] = $name; |
|
282 | - $field['value'] = $newValue; |
|
283 | - $field['where'] = $oldValue; |
|
284 | - $this->_updatedWhere[] = $field; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Add new field of a record to be added |
|
289 | - * |
|
290 | - * @param string $name name of the field |
|
291 | - * @param string $properties properties of the field |
|
292 | - * |
|
293 | - */ |
|
294 | - public function addNewField($name, $properties) |
|
295 | - { |
|
296 | - $field['name'] = $name; |
|
297 | - $field['properties'] = $properties; |
|
298 | - $this->_newFields[] = $field; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Get fields that need to be altered |
|
303 | - * |
|
304 | - * @return array fields that need to be altered |
|
305 | - * |
|
306 | - */ |
|
307 | - public function getAlteredFields() |
|
308 | - { |
|
309 | - return $this->_alteredFields; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Add field for which the value will be updated |
|
314 | - * |
|
315 | - * @param string $name name of the field |
|
316 | - * @param string $value value to be set |
|
317 | - * |
|
318 | - */ |
|
319 | - public function addUpdatedField($name, $value) |
|
320 | - { |
|
321 | - $field['name'] = $name; |
|
322 | - $field['value'] = $value; |
|
323 | - $this->_updatedFields[] = $field; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Get new fields to be added |
|
328 | - * |
|
329 | - * @return array fields to be added |
|
330 | - * |
|
331 | - */ |
|
332 | - public function getNewFields() |
|
333 | - { |
|
334 | - return $this->_newFields; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get fields which values need to be updated |
|
339 | - * |
|
340 | - * @return array fields which values need to be updated |
|
341 | - * |
|
342 | - */ |
|
343 | - public function getUpdatedFields() |
|
344 | - { |
|
345 | - return $this->_updatedFields; |
|
346 | - } |
|
347 | - /** |
|
348 | - * Get fields which values need to be updated |
|
349 | - * |
|
350 | - * @return array fields which values need to be updated |
|
351 | - * |
|
352 | - */ //felix |
|
353 | - public function getUpdatedWhere() |
|
354 | - { |
|
355 | - return $this->_updatedWhere; |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Add values of a record to be added |
|
360 | - * |
|
361 | - * @param string $name name of the field |
|
362 | - * |
|
363 | - */ |
|
364 | - public function addDroppedField($name) |
|
365 | - { |
|
366 | - $this->_droppedFields[] = $name; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Get fields that need to be dropped |
|
371 | - * |
|
372 | - * @return array fields that need to be dropped |
|
373 | - * |
|
374 | - */ |
|
375 | - public function getDroppedFields() |
|
376 | - { |
|
377 | - return $this->_droppedFields; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Set the flag to drop the table |
|
382 | - * |
|
383 | - */ |
|
384 | - public function setFlagForDrop() |
|
385 | - { |
|
386 | - $this->_flagForDrop = true; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Use to create a table |
|
391 | - * |
|
392 | - * @return bool true if success, false if an error occured |
|
393 | - * |
|
394 | - */ |
|
395 | - public function createTable() |
|
396 | - { |
|
397 | - global $xoopsDB; |
|
398 | - $query = $this->getStructure(); |
|
399 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
400 | - //xoops_debug($query); |
|
401 | - $ret = $xoopsDB->query($query); |
|
402 | - if (!$ret) { |
|
403 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
404 | - } else { |
|
405 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
406 | - } |
|
407 | - |
|
408 | - return $ret; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Use to drop a table |
|
413 | - * |
|
414 | - * @return bool true if success, false if an error occured |
|
415 | - * |
|
416 | - */ |
|
417 | - public function dropTable() |
|
418 | - { |
|
419 | - global $xoopsDB; |
|
420 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
421 | - $ret = $xoopsDB->query($query); |
|
422 | - if (!$ret) { |
|
423 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
424 | - |
|
425 | - return false; |
|
426 | - } else { |
|
427 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
428 | - |
|
429 | - return true; |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Use to alter a table |
|
435 | - * |
|
436 | - * @return bool true if success, false if an error occured |
|
437 | - * |
|
438 | - */ |
|
439 | - public function alterTable() |
|
440 | - { |
|
441 | - global $xoopsDB; |
|
442 | - $ret = true; |
|
443 | - |
|
444 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
445 | - if (!$alteredField['newname']) { |
|
446 | - $alteredField['newname'] = $alteredField['name']; |
|
447 | - } |
|
448 | - |
|
449 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
450 | - $ret = $ret && $xoopsDB->query($query); |
|
451 | - if ($alteredField['showerror']) { |
|
452 | - if (!$ret) { |
|
453 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
454 | - } else { |
|
455 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
456 | - } |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - return $ret; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Use to add new fileds in the table |
|
465 | - * |
|
466 | - * @return bool true if success, false if an error occured |
|
467 | - * |
|
468 | - */ |
|
469 | - public function addNewFields() |
|
470 | - { |
|
471 | - global $xoopsDB; |
|
472 | - $ret = true; |
|
473 | - foreach ($this->getNewFields() as $newField) { |
|
474 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
475 | - //echo $query; |
|
476 | - $ret = $ret && $xoopsDB->query($query); |
|
477 | - if (!$ret) { |
|
478 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
479 | - } else { |
|
480 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
481 | - } |
|
482 | - } |
|
483 | - |
|
484 | - return $ret; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Use to update fields values |
|
489 | - * |
|
490 | - * @return bool true if success, false if an error occured |
|
491 | - * |
|
492 | - */ |
|
493 | - public function updateFieldsValues() |
|
494 | - { |
|
495 | - global $xoopsDB; |
|
496 | - $ret = true; |
|
497 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
498 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
499 | - $ret = $ret && $xoopsDB->query($query); |
|
500 | - if (!$ret) { |
|
501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
502 | - } else { |
|
503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - return $ret; |
|
508 | - } |
|
509 | - /** |
|
510 | - * Use to update fields values |
|
511 | - * |
|
512 | - * @return bool true if success, false if an error occured |
|
513 | - * |
|
514 | - */ //felix |
|
515 | - public function updateWhereValues() |
|
516 | - { |
|
517 | - global $xoopsDB; |
|
518 | - $ret = true; |
|
519 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
520 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
521 | - //echo $query."<br>"; |
|
522 | - $ret = $ret && $xoopsDB->query($query); |
|
523 | - if (!$ret) { |
|
524 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
525 | - } else { |
|
526 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - return $ret; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Use to drop fields |
|
535 | - * |
|
536 | - * @return bool true if success, false if an error occured |
|
537 | - * |
|
538 | - */ |
|
539 | - public function dropFields() |
|
540 | - { |
|
541 | - global $xoopsDB; |
|
542 | - $ret = true; |
|
543 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
544 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
545 | - $ret = $ret && $xoopsDB->query($query); |
|
546 | - if (!$ret) { |
|
547 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
548 | - } else { |
|
549 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - return $ret; |
|
554 | - } |
|
57 | + /** |
|
58 | + * @var string $_name name of the table |
|
59 | + */ |
|
60 | + public $_name; |
|
61 | + /** |
|
62 | + * @var string $_structure structure of the table |
|
63 | + */ |
|
64 | + public $_structure; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var array $_data containing valued of each records to be added |
|
68 | + */ |
|
69 | + public $_data; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var array $_alteredFields containing fields to be altered |
|
73 | + */ |
|
74 | + public $_alteredFields; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var array $_newFields containing new fields to be added |
|
78 | + */ |
|
79 | + public $_newFields; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var array $_droppedFields containing fields to be dropped |
|
83 | + */ |
|
84 | + public $_droppedFields; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var array $_flagForDrop flag table to drop it |
|
88 | + */ |
|
89 | + public $_flagForDrop = false; |
|
90 | + |
|
91 | + /** |
|
92 | + * @var array $_updatedFields containing fields which values will be updated |
|
93 | + */ |
|
94 | + public $_updatedFields; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var array $_updatedFields containing fields which values will be updated |
|
98 | + */ //felix |
|
99 | + public $_updatedWhere; |
|
100 | + |
|
101 | + public $_existingFieldsArray = false; |
|
102 | + |
|
103 | + /** |
|
104 | + * Constructor |
|
105 | + * |
|
106 | + * @param string $name name of the table |
|
107 | + * |
|
108 | + */ |
|
109 | + public function __construct($name) |
|
110 | + { |
|
111 | + $this->_name = $name; |
|
112 | + $this->_data = []; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Return the table name, prefixed with site table prefix |
|
117 | + * |
|
118 | + * @return string table name |
|
119 | + * |
|
120 | + */ |
|
121 | + public function name() |
|
122 | + { |
|
123 | + global $xoopsDB; |
|
124 | + |
|
125 | + return $xoopsDB->prefix($this->_name); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Checks if the table already exists in the database |
|
130 | + * |
|
131 | + * @return bool TRUE if it exists, FALSE if not |
|
132 | + * |
|
133 | + */ |
|
134 | + public function exists() |
|
135 | + { |
|
136 | + return Smartobject\Utility::isTable($this->_name); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + public function getExistingFieldsArray() |
|
143 | + { |
|
144 | + global $xoopsDB; |
|
145 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
146 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
147 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
148 | + if ('YES' !== $existing_field['Null']) { |
|
149 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
150 | + } |
|
151 | + if ($existing_field['Extra']) { |
|
152 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
153 | + } |
|
154 | + if (!(null === $existing_field['Default']) |
|
155 | + && ($existing_field['Default'] |
|
156 | + || '' === $existing_field['Default'] |
|
157 | + || 0 == $existing_field['Default'])) { |
|
158 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + return $fields; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @param $field |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function fieldExists($field) |
|
170 | + { |
|
171 | + $existingFields = $this->getExistingFieldsArray(); |
|
172 | + |
|
173 | + return isset($existingFields[$field]); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Set the table structure |
|
178 | + * |
|
179 | + * Example: |
|
180 | + * |
|
181 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
182 | + * `date` int(11) NOT NULL default '0', |
|
183 | + * `status` int(1) NOT NULL default '-1', |
|
184 | + * `itemid` int(11) NOT NULL default '0', |
|
185 | + * `uid` int(11) NOT NULL default '0', |
|
186 | + * `price` float NOT NULL default '0', |
|
187 | + * `currency` varchar(100) NOT NULL default '', |
|
188 | + * PRIMARY KEY (`transactionid`)"); |
|
189 | + * |
|
190 | + * @param string $structure table structure |
|
191 | + * |
|
192 | + */ |
|
193 | + public function setStructure($structure) |
|
194 | + { |
|
195 | + $this->_structure = $structure; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Return the table structure |
|
200 | + * |
|
201 | + * @return string table structure |
|
202 | + * |
|
203 | + */ |
|
204 | + public function getStructure() |
|
205 | + { |
|
206 | + return sprintf($this->_structure, $this->name()); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Add values of a record to be added |
|
211 | + * |
|
212 | + * @param string $data values of a record |
|
213 | + * |
|
214 | + */ |
|
215 | + public function setData($data) |
|
216 | + { |
|
217 | + $this->_data[] = $data; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Get the data array |
|
222 | + * |
|
223 | + * @return array containing the records values to be added |
|
224 | + * |
|
225 | + */ |
|
226 | + public function getData() |
|
227 | + { |
|
228 | + return $this->_data; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Use to insert data in a table |
|
233 | + * |
|
234 | + * @return bool true if success, false if an error occured |
|
235 | + * |
|
236 | + */ |
|
237 | + public function addData() |
|
238 | + { |
|
239 | + global $xoopsDB; |
|
240 | + foreach ($this->getData() as $data) { |
|
241 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
242 | + $ret = $xoopsDB->query($query); |
|
243 | + if (!$ret) { |
|
244 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
245 | + } else { |
|
246 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + return $ret; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Add a field to be added |
|
255 | + * |
|
256 | + * @param string $name name of the field |
|
257 | + * @param string $properties properties of the field |
|
258 | + * @param bool $newname |
|
259 | + * @param bool $showerror |
|
260 | + */ |
|
261 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
262 | + { |
|
263 | + $field['name'] = $name; |
|
264 | + $field['properties'] = $properties; |
|
265 | + $field['showerror'] = $showerror; |
|
266 | + $field['newname'] = $newname; |
|
267 | + $this->_alteredFields[] = $field; |
|
268 | + } |
|
269 | + /** |
|
270 | + * Invert values 0 to 1 and 1 to 0 |
|
271 | + * |
|
272 | + * @param string $name name of the field |
|
273 | + * @param $newValue |
|
274 | + * @param $oldValue |
|
275 | + * @internal param string $old old propertie |
|
276 | + * @internal param string $new new propertie |
|
277 | + */ //felix |
|
278 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
279 | + { |
|
280 | + $field['name'] = $name; |
|
281 | + $field['value'] = $newValue; |
|
282 | + $field['where'] = $oldValue; |
|
283 | + $this->_updatedWhere[] = $field; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Add new field of a record to be added |
|
288 | + * |
|
289 | + * @param string $name name of the field |
|
290 | + * @param string $properties properties of the field |
|
291 | + * |
|
292 | + */ |
|
293 | + public function addNewField($name, $properties) |
|
294 | + { |
|
295 | + $field['name'] = $name; |
|
296 | + $field['properties'] = $properties; |
|
297 | + $this->_newFields[] = $field; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Get fields that need to be altered |
|
302 | + * |
|
303 | + * @return array fields that need to be altered |
|
304 | + * |
|
305 | + */ |
|
306 | + public function getAlteredFields() |
|
307 | + { |
|
308 | + return $this->_alteredFields; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Add field for which the value will be updated |
|
313 | + * |
|
314 | + * @param string $name name of the field |
|
315 | + * @param string $value value to be set |
|
316 | + * |
|
317 | + */ |
|
318 | + public function addUpdatedField($name, $value) |
|
319 | + { |
|
320 | + $field['name'] = $name; |
|
321 | + $field['value'] = $value; |
|
322 | + $this->_updatedFields[] = $field; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Get new fields to be added |
|
327 | + * |
|
328 | + * @return array fields to be added |
|
329 | + * |
|
330 | + */ |
|
331 | + public function getNewFields() |
|
332 | + { |
|
333 | + return $this->_newFields; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Get fields which values need to be updated |
|
338 | + * |
|
339 | + * @return array fields which values need to be updated |
|
340 | + * |
|
341 | + */ |
|
342 | + public function getUpdatedFields() |
|
343 | + { |
|
344 | + return $this->_updatedFields; |
|
345 | + } |
|
346 | + /** |
|
347 | + * Get fields which values need to be updated |
|
348 | + * |
|
349 | + * @return array fields which values need to be updated |
|
350 | + * |
|
351 | + */ //felix |
|
352 | + public function getUpdatedWhere() |
|
353 | + { |
|
354 | + return $this->_updatedWhere; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Add values of a record to be added |
|
359 | + * |
|
360 | + * @param string $name name of the field |
|
361 | + * |
|
362 | + */ |
|
363 | + public function addDroppedField($name) |
|
364 | + { |
|
365 | + $this->_droppedFields[] = $name; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Get fields that need to be dropped |
|
370 | + * |
|
371 | + * @return array fields that need to be dropped |
|
372 | + * |
|
373 | + */ |
|
374 | + public function getDroppedFields() |
|
375 | + { |
|
376 | + return $this->_droppedFields; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Set the flag to drop the table |
|
381 | + * |
|
382 | + */ |
|
383 | + public function setFlagForDrop() |
|
384 | + { |
|
385 | + $this->_flagForDrop = true; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Use to create a table |
|
390 | + * |
|
391 | + * @return bool true if success, false if an error occured |
|
392 | + * |
|
393 | + */ |
|
394 | + public function createTable() |
|
395 | + { |
|
396 | + global $xoopsDB; |
|
397 | + $query = $this->getStructure(); |
|
398 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
399 | + //xoops_debug($query); |
|
400 | + $ret = $xoopsDB->query($query); |
|
401 | + if (!$ret) { |
|
402 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
403 | + } else { |
|
404 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
405 | + } |
|
406 | + |
|
407 | + return $ret; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Use to drop a table |
|
412 | + * |
|
413 | + * @return bool true if success, false if an error occured |
|
414 | + * |
|
415 | + */ |
|
416 | + public function dropTable() |
|
417 | + { |
|
418 | + global $xoopsDB; |
|
419 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
420 | + $ret = $xoopsDB->query($query); |
|
421 | + if (!$ret) { |
|
422 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
423 | + |
|
424 | + return false; |
|
425 | + } else { |
|
426 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
427 | + |
|
428 | + return true; |
|
429 | + } |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Use to alter a table |
|
434 | + * |
|
435 | + * @return bool true if success, false if an error occured |
|
436 | + * |
|
437 | + */ |
|
438 | + public function alterTable() |
|
439 | + { |
|
440 | + global $xoopsDB; |
|
441 | + $ret = true; |
|
442 | + |
|
443 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
444 | + if (!$alteredField['newname']) { |
|
445 | + $alteredField['newname'] = $alteredField['name']; |
|
446 | + } |
|
447 | + |
|
448 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
449 | + $ret = $ret && $xoopsDB->query($query); |
|
450 | + if ($alteredField['showerror']) { |
|
451 | + if (!$ret) { |
|
452 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
453 | + } else { |
|
454 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + return $ret; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Use to add new fileds in the table |
|
464 | + * |
|
465 | + * @return bool true if success, false if an error occured |
|
466 | + * |
|
467 | + */ |
|
468 | + public function addNewFields() |
|
469 | + { |
|
470 | + global $xoopsDB; |
|
471 | + $ret = true; |
|
472 | + foreach ($this->getNewFields() as $newField) { |
|
473 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
474 | + //echo $query; |
|
475 | + $ret = $ret && $xoopsDB->query($query); |
|
476 | + if (!$ret) { |
|
477 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
478 | + } else { |
|
479 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
480 | + } |
|
481 | + } |
|
482 | + |
|
483 | + return $ret; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Use to update fields values |
|
488 | + * |
|
489 | + * @return bool true if success, false if an error occured |
|
490 | + * |
|
491 | + */ |
|
492 | + public function updateFieldsValues() |
|
493 | + { |
|
494 | + global $xoopsDB; |
|
495 | + $ret = true; |
|
496 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
497 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
498 | + $ret = $ret && $xoopsDB->query($query); |
|
499 | + if (!$ret) { |
|
500 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
501 | + } else { |
|
502 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + return $ret; |
|
507 | + } |
|
508 | + /** |
|
509 | + * Use to update fields values |
|
510 | + * |
|
511 | + * @return bool true if success, false if an error occured |
|
512 | + * |
|
513 | + */ //felix |
|
514 | + public function updateWhereValues() |
|
515 | + { |
|
516 | + global $xoopsDB; |
|
517 | + $ret = true; |
|
518 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
519 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
520 | + //echo $query."<br>"; |
|
521 | + $ret = $ret && $xoopsDB->query($query); |
|
522 | + if (!$ret) { |
|
523 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
524 | + } else { |
|
525 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + return $ret; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Use to drop fields |
|
534 | + * |
|
535 | + * @return bool true if success, false if an error occured |
|
536 | + * |
|
537 | + */ |
|
538 | + public function dropFields() |
|
539 | + { |
|
540 | + global $xoopsDB; |
|
541 | + $ret = true; |
|
542 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
543 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
544 | + $ret = $ret && $xoopsDB->query($query); |
|
545 | + if (!$ret) { |
|
546 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
547 | + } else { |
|
548 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + return $ret; |
|
553 | + } |
|
555 | 554 | } |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | */ |
39 | 39 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
40 | 40 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
41 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
42 | 42 | } |
43 | 43 | /** |
44 | 44 | * Include the language constants for the SmartObjectDBUpdater |
45 | 45 | */ |
46 | 46 | global $xoopsConfig; |
47 | -$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
|
47 | +$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php'; |
|
48 | 48 | if (!file_exists($common_file)) { |
49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
49 | + $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php'; |
|
50 | 50 | } |
51 | 51 | include $common_file; |
52 | 52 | |
@@ -143,20 +143,20 @@ discard block |
||
143 | 143 | public function getExistingFieldsArray() |
144 | 144 | { |
145 | 145 | global $xoopsDB; |
146 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
146 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name()); |
|
147 | 147 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
148 | 148 | $fields[$existing_field['Field']] = $existing_field['Type']; |
149 | 149 | if ('YES' !== $existing_field['Null']) { |
150 | 150 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
151 | 151 | } |
152 | 152 | if ($existing_field['Extra']) { |
153 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
153 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
154 | 154 | } |
155 | 155 | if (!(null === $existing_field['Default']) |
156 | 156 | && ($existing_field['Default'] |
157 | 157 | || '' === $existing_field['Default'] |
158 | 158 | || 0 == $existing_field['Default'])) { |
159 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
159 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
243 | 243 | $ret = $xoopsDB->query($query); |
244 | 244 | if (!$ret) { |
245 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
245 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>'; |
|
246 | 246 | } else { |
247 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
247 | + echo ' '.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>'; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | { |
397 | 397 | global $xoopsDB; |
398 | 398 | $query = $this->getStructure(); |
399 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
399 | + $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
400 | 400 | //xoops_debug($query); |
401 | 401 | $ret = $xoopsDB->query($query); |
402 | 402 | if (!$ret) { |
403 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
403 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
404 | 404 | } else { |
405 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
405 | + echo ' '.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>'; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return $ret; |
@@ -420,11 +420,11 @@ discard block |
||
420 | 420 | $query = sprintf('DROP TABLE %s', $this->name()); |
421 | 421 | $ret = $xoopsDB->query($query); |
422 | 422 | if (!$ret) { |
423 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
423 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
424 | 424 | |
425 | 425 | return false; |
426 | 426 | } else { |
427 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
427 | + echo ' '.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>'; |
|
428 | 428 | |
429 | 429 | return true; |
430 | 430 | } |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | $ret = $ret && $xoopsDB->query($query); |
451 | 451 | if ($alteredField['showerror']) { |
452 | 452 | if (!$ret) { |
453 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
453 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
454 | 454 | } else { |
455 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
455 | + echo ' '.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>'; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | //echo $query; |
476 | 476 | $ret = $ret && $xoopsDB->query($query); |
477 | 477 | if (!$ret) { |
478 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
478 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>'; |
|
479 | 479 | } else { |
480 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
480 | + echo ' '.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>'; |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
499 | 499 | $ret = $ret && $xoopsDB->query($query); |
500 | 500 | if (!$ret) { |
501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
501 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
502 | 502 | } else { |
503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
503 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
@@ -521,9 +521,9 @@ discard block |
||
521 | 521 | //echo $query."<br>"; |
522 | 522 | $ret = $ret && $xoopsDB->query($query); |
523 | 523 | if (!$ret) { |
524 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
524 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
525 | 525 | } else { |
526 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
526 | + echo ' '.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>'; |
|
527 | 527 | } |
528 | 528 | } |
529 | 529 | |
@@ -544,9 +544,9 @@ discard block |
||
544 | 544 | $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
545 | 545 | $ret = $ret && $xoopsDB->query($query); |
546 | 546 | if (!$ret) { |
547 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
547 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>'; |
|
548 | 548 | } else { |
549 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
549 | + echo ' '.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>'; |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 |