Skip to content

Commit a11a782

Browse files
committed
corrections coderabbitai 2
1 parent be917c6 commit a11a782

21 files changed

Lines changed: 258 additions & 278 deletions

class/Common/DirectoryChecker.php

Lines changed: 14 additions & 12 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
/**
@@ -137,22 +141,20 @@ public static function dirExists($dir_path)
137141
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST')) {
138142
break;
139143
}
140-
$path = $_POST['path'];
141-
$redirect = $_POST['redirect'];
144+
$path = \Xmf\Request::getString('path', 'POST');
145+
$redirect = \Xmf\Request::getString('redirect', 'POST');
142146
$msg = DirectoryChecker::createDirectory($path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
143147
\redirect_header($redirect, 2, $msg . ': ' . $path);
144148
break;
145149
case 'setdirperm':
146-
if (\Xmf\Request::hasVar('path', 'POST')) {
147-
$path = $_POST['path'];
148-
}
149-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
150-
$redirect = $_POST['redirect'];
151-
}
152-
if (\Xmf\Request::hasVar('mode', 'POST')) {
153-
$mode = $_POST['mode'];
150+
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST') || !\Xmf\Request::hasVar('mode', 'POST')) {
151+
break;
154152
}
155-
$msg = DirectoryChecker::setDirectoryPermissions($path, (int)$mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
153+
$path = \Xmf\Request::getString('path', 'POST');
154+
$redirect = \Xmf\Request::getString('redirect', 'POST');
155+
$mode = \Xmf\Request::getInt('mode', 'POST');
156+
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
157+
156158
\redirect_header($redirect, 2, $msg . ': ' . $path);
157159
break;
158160
}

class/Common/TableChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function processSQL()
7676
if ($this::CHECKTYPE_UPDATE == $this->checktype || $this::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
7777
// create new table
7878
$sql = $tabledef['sql'];
79-
if ($this->result = $GLOBALS['xoopsDB']->queryF($sql)) {
79+
if ($GLOBALS['xoopsDB']->queryF($sql)) {
8080
$this->result[] = 'Table created:' . $table;
8181
} else {
8282
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);

class/Files/Blocks/BlocksFiles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ private function getBlocksShow($moduleDirname, $tableName, $tableFieldname, $tab
157157
}
158158
}
159159
if ('' !== $fieldStatus) {
160-
$constant = $this->xc->getXcGetConstants('STATUS_OFFLINE');
161-
$crit = $this->xc->getXcCriteria('', "'{$fieldStatus}'", $constant, "'>'", true);
160+
$constant = $this->xc->getXcGetConstants('STATUS_APPROVED');
161+
$crit = $this->xc->getXcCriteria('', "'{$fieldStatus}'", $constant, "'='", true);
162162
$func .= $this->pc->getPhpCodeCommentLine("Criteria for status field",'',"\t");
163163
$func .= $this->xc->getXcCriteriaAdd($critName, $crit, "\t");
164164
$func .= $this->pc->getPhpCodeBlankLine();

class/Files/Classes/ClassFiles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ private function getFunctionForm($module, $table, $fieldId, $fieldInForm, $field
340340
* @private function getPermissionsInForm
341341
*
342342
* @param string $moduleDirname
343-
* @param string $fieldId
343+
* @param string|null $fieldId
344344
*
345345
* @param $tableName
346346
* @return string
347347
*/
348-
private function getPermissionsInForm(string $moduleDirname, string $fieldId, $tableName)
348+
private function getPermissionsInForm(string $moduleDirname, ?string $fieldId, $tableName)
349349
{
350350
$permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
351351
$permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');

class/Files/CreateClone.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public static function cloneFileFolder($src_path, $dst_path, bool $replace_code
3939
{
4040
// open the source directory
4141
$dir = \opendir($src_path);
42+
if (false === $dir) {
43+
throw new \RuntimeException("Unable to open source directory: {$src_path}");
44+
}
4245
// Make the destination directory if not exist
43-
@\mkdir($dst_path);
46+
if (!\is_dir($dst_path) && !\mkdir($dst_path, 0755) && !\is_dir($dst_path)) {
47+
throw new \RuntimeException("Unable to create destination directory: {$dst_path}");
48+
}
49+
4450
// Loop through the files in source directory
4551
while ($file = \readdir($dir)) {
4652
if (($file != '.') && ($file != '..')) {

class/Files/CreateSmartyCode.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,18 @@ public function getSmartyConst(string $language, $const, string $t = '', string
143143
* @param string $t
144144
* @param string $n
145145
* @param string $default
146+
* @param string $escape
146147
* @return string
147148
*/
148-
public function getSmartySingleVar(string $var, string $t = '', string $n = '', string $default = 'false')
149+
public function getSmartySingleVar(string $var, string $t = '', string $n = '', string $default = 'false', string $escape = '')
149150
{
150151
$ret = "{$t}<{\${$var}";
151152
if ('' !== $default) {
152153
$ret .= '|default:' . $default;
153154
}
155+
if ('' !== $escape) {
156+
$ret .= '|escape:' . $escape;
157+
}
154158
$ret .= "}>{$n}";
155159

156160
return $ret;
@@ -162,11 +166,18 @@ public function getSmartySingleVar(string $var, string $t = '', string $n = '',
162166
* @param string $rightVar
163167
* @param string $t
164168
* @param string $n
169+
* @param string $default
170+
* @param string $escape
165171
* @return string
166172
*/
167-
public function getSmartyDoubleVar(string $leftVar, string $rightVar, string $t = '', string $n = '', $default = 'false')
173+
public function getSmartyDoubleVar(string $leftVar, string $rightVar, string $t = '', string $n = '', string $default = 'false', string $escape = '')
168174
{
169-
return "{$t}<{\${$leftVar}.{$rightVar}|default:{$default}}>{$n}";
175+
$ret = "{$t}<{\${$leftVar}.{$rightVar}|default:{$default}";
176+
if ('' !== $escape) {
177+
$ret .= '|escape:' . $escape;
178+
}
179+
$ret .= "}>{$n}";
180+
return $ret;
170181
}
171182

172183
/**

class/Files/CreateStructure.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function makeDir(string $dir): void
179179
*
180180
* @return bool
181181
*/
182-
public function isDirEmpty(string $dir)
182+
public function isDirEmpty(string $dir): bool
183183
{
184184
$handle = \opendir($dir);
185185
if (false === $handle) {
@@ -197,13 +197,13 @@ public function isDirEmpty(string $dir)
197197
}
198198

199199
/**
200-
* @public function addFolderPath
200+
* @private function addFolderPath
201201
*
202202
* @param string $folderName
203203
* @param bool|string $fileName
204204
* @return string
205205
*/
206-
private function addFolderPath(string $folderName, $fileName = false)
206+
private function addFolderPath(string $folderName, $fileName = false): string
207207
{
208208
$this->setFolderName($folderName);
209209
if ($fileName) {

0 commit comments

Comments
 (0)