Skip to content

Commit 6bc7427

Browse files
committed
update modulbuilder itself - correction 1
1 parent 028e392 commit 6bc7427

24 files changed

Lines changed: 198 additions & 233 deletions

admin/fields.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@
202202
break;
203203
case 'order':
204204
// Initialize fields handler
205-
$fieldsObj = $helper->getHandler('Fields');
205+
$fieldsHandler = $helper->getHandler('Fields');
206206
if (isset($_POST['forder'])) {
207207
$i = 0;
208208
foreach ($_POST['forder'] as $order) {
209209
if ($order > 0) {
210-
$fieldOrder = $fieldsObj->get($order);
211-
$fieldOrder->setVar('field_order', $i);
212-
if (!$fieldsObj->insert()) {
210+
$fieldsObj = $fieldsHandler->get($order);
211+
$fieldsObj->setVar('field_order', $i);
212+
if ($fieldsHandler->insert($fieldsObj)) {
213213
$error = true;
214214
}
215215
++$i;

admin/logo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
$caption = \Xmf\Request::getString('caption', '', 'GET');
2828
if (\function_exists($funct)) {
2929
$ret = Modulebuilder\Logo::getInstance()->createLogo($iconName, $caption);
30-
phpFunction($ret);
30+
if (false !== $ret) {
31+
phpFunction($ret);
32+
}
3133
} else {
3234
\redirect_header('logo.php', 3, 'Method Not Exist');
3335
}

admin/tables.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@
238238
break;
239239
case 'order':
240240
// Initialize tables handler
241-
$tablesObj = $helper->getHandler('Tables');
241+
$tablesHandler = $helper->getHandler('Tables');
242242
if (isset($_POST['torder'])) {
243243
$i = 0;
244244
foreach ($_POST['torder'] as $order) {
245245
if ($order > 0) {
246-
$tableOrder = $tablesObj->get($order);
247-
$tableOrder->setVar('table_order', $i);
248-
if (!$tablesObj->insert()) {
246+
$tablesObj = $tablesHandler->get($order);
247+
$tablesObj->setVar('table_order', $i);
248+
if (!$tablesHandler->insert($tablesObj)) {
249249
$error = true;
250250
}
251251
++$i;

class/Common/Confirm.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
* @copyright 2020 XOOPS Project (https://xoops.org)
1919
* @license GPL 2.0 or later
20+
* @package Modulebuilder
2021
* @since 1.0
2122
* @min_xoops 2.5.9
2223
* @author Goffy - Email:<goffy@myxoops.org> - Website:<https://xoops.org>
@@ -39,21 +40,21 @@
3940
*/
4041
class Confirm
4142
{
42-
private $hiddens = [];
43-
private $action = '';
44-
private $title = '';
45-
private $label = '';
46-
private $object = '';
43+
private array $hiddens = [];
44+
private string $action = '';
45+
private string $title = '';
46+
private string $label = '';
47+
private string $object = '';
4748

4849
/**
4950
* @public function constructor class
50-
* @param $hiddens
51-
* @param $action
52-
* @param $object
51+
* @param array $hiddens
52+
* @param string $action
53+
* @param string $object
5354
* @param string $title
5455
* @param string $label
5556
*/
56-
public function __construct($hiddens, $action, $object, string $title = '', string $label = '')
57+
public function __construct(array $hiddens, string $action, string $object, string $title = '', string $label = '')
5758
{
5859
$this->hiddens = $hiddens;
5960
$this->action = $action;
@@ -66,9 +67,9 @@ public function __construct($hiddens, $action, $object, string $title = '', stri
6667
* @public function getFormConfirm
6768
* @return \XoopsThemeForm
6869
*/
69-
public function getFormConfirm()
70+
public function getFormConfirm(): \XoopsThemeForm
7071
{
71-
$moduleDirName = \basename(__DIR__);
72+
$moduleDirName = \basename(\dirname(__DIR__, 2));
7273
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
7374
//in order to be accessable from user and admin area this should be place in language common.php
7475
if (!\defined('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM')) {

class/Common/FileChecker.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FileChecker
4343
*
4444
* @return bool|string
4545
*/
46-
public static function getFileStatus(string $file_path, string $redirectFile, string $original_file_path = null)
46+
public static function getFileStatus(string $file_path, string $redirectFile, ?string $original_file_path = null)
4747
{
4848
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');
4949

@@ -151,9 +151,9 @@ public static function setFilePermissions($target, int $mode = 0777)
151151
|| !\Xmf\Request::hasVar('redirect', 'POST')) {
152152
return;
153153
}
154-
$original_file_path = $_POST['original_file_path'];
155-
$file_path = $_POST['file_path'];
156-
$redirect = $_POST['redirect'];
154+
$original_file_path = \Xmf\Request::getString('original_file_path');
155+
$file_path = \Xmf\Request::getString('file_path');
156+
$redirect =\Xmf\Request::getString('redirect');
157157
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
158158
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
159159
}

class/Common/Resizer.php

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
*/
2525
class Resizer
2626
{
27-
public $sourceFile = '';
28-
public $endFile = '';
29-
public $maxWidth = 0;
30-
public $maxHeight = 0;
31-
public $imageMimetype = '';
32-
public $jpgQuality = 90;
33-
public $mergeType = 0;
34-
public $mergePos = 0;
35-
public $degrees = 0;
36-
public $error = '';
27+
public string $sourceFile = '';
28+
public string $endFile = '';
29+
public int $maxWidth = 0;
30+
public int $maxHeight = 0;
31+
public string $imageMimetype = '';
32+
public int $jpgQuality = 90;
33+
public int $mergeType = 0;
34+
public int $mergePos = 0;
35+
public int $degrees = 0;
36+
public string $error = '';
3737

3838
/**
3939
* resize image if size exceed given width/height
@@ -45,15 +45,24 @@ public function resizeImage()
4545
switch ($this->imageMimetype) {
4646
case 'image/png':
4747
$img = \imagecreatefrompng($this->sourceFile);
48+
if (!$img) {
49+
return false;
50+
}
4851
break;
4952
case 'image/jpeg':
5053
$img = \imagecreatefromjpeg($this->sourceFile);
5154
if (!$img) {
5255
$img = \imagecreatefromstring(file_get_contents($this->sourceFile));
5356
}
57+
if (!$img) {
58+
return false;
59+
}
5460
break;
5561
case 'image/gif':
5662
$img = \imagecreatefromgif($this->sourceFile);
63+
if (!$img) {
64+
return false;
65+
}
5766
break;
5867
default:
5968
return 'Unsupported format';
@@ -83,12 +92,12 @@ public function resizeImage()
8392
}
8493

8594
// Create a new temporary image.
86-
$tmpimg = \imagecreatetruecolor($new_width, $new_height);
95+
$tmpimg = \imagecreatetruecolor((int)$new_width, (int)$new_height);
8796
\imagealphablending($tmpimg, false);
8897
\imagesavealpha($tmpimg, true);
8998

9099
// Copy and resize old image into new image.
91-
\imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
100+
\imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, (int)$new_width, (int)$new_height, (int)$width, (int)$height);
92101

93102
\unlink($this->endFile);
94103
//compressing the file
@@ -185,8 +194,17 @@ public function resizeAndCrop()
185194

186195
public function mergeImage(): void
187196
{
188-
$dest = \imagecreatefromjpeg($this->endFile);
189-
$src = \imagecreatefromjpeg($this->sourceFile);
197+
switch ($this->imageMimetype) {
198+
case 'image/png':
199+
$dest = \imagecreatefrompng($this->endFile);
200+
$src = \imagecreatefrompng($this->sourceFile);
201+
break;
202+
case 'image/jpeg':
203+
$dest = \imagecreatefromjpeg($this->endFile);
204+
$src = \imagecreatefromjpeg($this->sourceFile);
205+
break;
206+
// ... etc
207+
}
190208
if (4 == $this->mergeType) {
191209
$imgWidth = (int)\round($this->maxWidth / 2 - 1);
192210
$imgHeight = (int)\round($this->maxHeight / 2 - 1);

docs/changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h5>3.7.1 Alpha [2026-04-05]</h5> Dev: XOOPS 2.5.11 Stable, PHP 8.0
22
- updated creation code to generate module with no errors from coderabbitai (goffy)
3-
- checked modulebuilder code by PHPStorm > Inspect code (goffy)
3+
- reviewed modulebuilder code by PHPStorm > Inspect code (goffy)
44

55
<h5>3.7.0 RC1 [2024-02-01]</h5> Dev: XOOPS 2.5.11 Stable, PHP 8.0
66
- updated version check for XOOPS 2.5.11 Stable (goffy)

files/commonfiles/class/Common/Confirm.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class Confirm
4848

4949
/**
5050
* @public function constructor class
51-
* @param $hiddens
52-
* @param $action
53-
* @param $object
51+
* @param array $hiddens
52+
* @param string $action
53+
* @param string $object
5454
* @param string $title
5555
* @param string $label
5656
*/
57-
public function __construct($hiddens, $action, $object, string $title = '', string $label = '')
57+
public function __construct(array $hiddens, string $action, string $object, string $title = '', string $label = '')
5858
{
5959
$this->hiddens = $hiddens;
6060
$this->action = $action;

files/commonfiles/class/Common/DirectoryChecker.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ public static function createDirectory($target, int $mode = 0777)
104104
$target = \str_replace('..', '', $target);
105105

106106
// https://www.php.net/manual/en/function.mkdir.php
107-
return \is_dir($target) || (self::createDirectory(\dirname($target), $mode) && !\mkdir($target, $mode) && !\is_dir($target));
107+
return \is_dir($target)
108+
|| (
109+
self::createDirectory(\dirname($target), $mode)
110+
&& (\mkdir($target, $mode) || \is_dir($target))
111+
);
108112
}
109113

110114
/**
@@ -134,26 +138,23 @@ public static function dirExists($dir_path)
134138
$op = Request::getString('op', '', 'POST');
135139
switch ($op) {
136140
case 'createdir':
137-
if (\Xmf\Request::hasVar('path', 'POST')) {
138-
$path = $_POST['path'];
139-
}
140-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
141-
$redirect = $_POST['redirect'];
141+
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST')) {
142+
break;
142143
}
144+
$path = \Xmf\Request::getString('path','', 'POST');
145+
$redirect = \Xmf\Request::getString('redirect','', 'POST');
143146
$msg = DirectoryChecker::createDirectory($path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
144147
\redirect_header($redirect, 2, $msg . ': ' . $path);
145148
break;
146149
case 'setdirperm':
147-
if (\Xmf\Request::hasVar('path', 'POST')) {
148-
$path = $_POST['path'];
149-
}
150-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
151-
$redirect = $_POST['redirect'];
152-
}
153-
if (\Xmf\Request::hasVar('mode', 'POST')) {
154-
$mode = $_POST['mode'];
150+
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST') || !\Xmf\Request::hasVar('mode', 'POST')) {
151+
break;
155152
}
153+
$path = \Xmf\Request::getString('path','', 'POST');
154+
$redirect = \Xmf\Request::getString('redirect','', 'POST');
155+
$mode = \Xmf\Request::getInt('mode',0 , 'POST');
156156
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
157+
157158
\redirect_header($redirect, 2, $msg . ': ' . $path);
158159
break;
159160
}

files/commonfiles/class/Common/FileChecker.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ class FileChecker
3838
{
3939
/**
4040
* @param string $file_path
41-
* @param string|null $original_file_path
4241
* @param string $redirectFile
42+
* @param string|null $original_file_path
43+
*
4344
* @return bool|string
4445
*/
45-
public static function getFileStatus(string $file_path, string $original_file_path = null, string $redirectFile)
46+
public static function getFileStatus(string $file_path, string $redirectFile, ?string $original_file_path = null)
4647
{
4748
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');
4849

@@ -145,15 +146,14 @@ public static function setFilePermissions($target, int $mode = 0777)
145146

146147
$op = Request::getString('op', '', 'POST');
147148
if ($op == 'copyfile') {
148-
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
149-
$original_file_path = $_POST['original_file_path'];
150-
}
151-
if (\Xmf\Request::hasVar('file_path', 'POST')) {
152-
$file_path = $_POST['file_path'];
153-
}
154-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
155-
$redirect = $_POST['redirect'];
156-
}
149+
if (!\Xmf\Request::hasVar('original_file_path', 'POST')
150+
|| !\Xmf\Request::hasVar('file_path', 'POST')
151+
|| !\Xmf\Request::hasVar('redirect', 'POST')) {
152+
return;
153+
}
154+
$original_file_path = \Xmf\Request::getString('original_file_path');
155+
$file_path = \Xmf\Request::getString('file_path');
156+
$redirect =\Xmf\Request::getString('redirect');
157157
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
158158
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
159159
}

0 commit comments

Comments
 (0)