Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions class/Building.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Building
/**
* @static function getInstance
*
* @param null
*
* @return Building
*/
public static function getInstance()
Expand All @@ -48,11 +46,11 @@ public static function getInstance()
}

/**
* @param bool $action
* @param string|bool $action
*
* @return \XoopsThemeForm
*/
public function getForm($action = false)
public function getForm(string|bool $action = false)
{
$helper = Modulebuilder\Helper::getInstance();
if (false === $action) {
Expand Down Expand Up @@ -85,7 +83,7 @@ public function getForm($action = false)
* @param string $dir
* @param string $pattern
*/
public function clearDir($dir, $pattern = '*'): void
public function clearDir(string $dir, string $pattern = '*'): void
{
// Find all files and folders matching pattern
$files = glob($dir . "/$pattern");
Expand Down Expand Up @@ -121,7 +119,7 @@ public function clearDir($dir, $pattern = '*'): void
* @param string $src
* @param string $dst
*/
public function copyDir($src, $dst): void
public function copyDir(string $src, string $dst): void
{
$dir = \opendir($src);
if (!\mkdir($dst) && !\is_dir($dst)) {
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct()
* @param string $title
* @param string $link
*/
public function addLink($title = '', $link = ''): void
public function addLink(string $title = '', string $link = ''): void
{
$this->bread[] = [
'link' => $link,
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Confirm
* @param string $title
* @param string $label
*/
public function __construct($hiddens, $action, $object, $title = '', $label = '')
public function __construct($hiddens, $action, $object, string $title = '', string $label = '')
{
$this->hiddens = $hiddens;
$this->action = $action;
Expand Down
35 changes: 18 additions & 17 deletions class/Common/DirectoryChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DirectoryChecker
*
* @return bool|string
*/
public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
public static function getDirectoryStatus($path, int $mode = 0777, $redirectFile = null)
{
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');

Expand Down Expand Up @@ -99,12 +99,16 @@ public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = n
*
* @return bool
*/
public static function createDirectory($target, $mode = 0777)
public static function createDirectory($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

// https://www.php.net/manual/en/function.mkdir.php
return \is_dir($target) || (self::createDirectory(\dirname($target), $mode) && !\mkdir($target, $mode) && !\is_dir($target));
return \is_dir($target)
|| (
self::createDirectory(\dirname($target), $mode)
&& (\mkdir($target, $mode) || \is_dir($target))
);
}

/**
Expand All @@ -113,7 +117,7 @@ public static function createDirectory($target, $mode = 0777)
*
* @return bool
*/
public static function setDirectoryPermissions($target, $mode = 0777)
public static function setDirectoryPermissions($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

Expand All @@ -134,26 +138,23 @@ public static function dirExists($dir_path)
$op = Request::getString('op', '', 'POST');
switch ($op) {
case 'createdir':
if (\Xmf\Request::hasVar('path', 'POST')) {
$path = $_POST['path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST')) {
break;
}
$path = \Xmf\Request::getString('path', 'POST');
$redirect = \Xmf\Request::getString('redirect', 'POST');
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
$msg = DirectoryChecker::createDirectory($path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
\redirect_header($redirect, 2, $msg . ': ' . $path);
break;
case 'setdirperm':
if (\Xmf\Request::hasVar('path', 'POST')) {
$path = $_POST['path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
}
if (\Xmf\Request::hasVar('mode', 'POST')) {
$mode = $_POST['mode'];
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST') || !\Xmf\Request::hasVar('mode', 'POST')) {
break;
}
$path = \Xmf\Request::getString('path', 'POST');
$redirect = \Xmf\Request::getString('redirect', 'POST');
$mode = \Xmf\Request::getInt('mode', 'POST');
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');

\redirect_header($redirect, 2, $msg . ': ' . $path);
break;
}
32 changes: 15 additions & 17 deletions class/Common/FileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
class FileChecker
{
/**
* @param string $file_path
* @param string $file_path
* @param string $redirectFile
* @param string|null $original_file_path
* @param string $redirectFile
*
* @return bool|string
*/
public static function getFileStatus($file_path, $original_file_path = null, $redirectFile)
public static function getFileStatus(string $file_path, string $redirectFile, string $original_file_path = null)
{
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');

Expand Down Expand Up @@ -135,7 +136,7 @@ public static function fileExists($file_path)
*
* @return bool
*/
public static function setFilePermissions($target, $mode = 0777)
public static function setFilePermissions($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

Expand All @@ -144,18 +145,15 @@ public static function setFilePermissions($target, $mode = 0777)
}

$op = Request::getString('op', '', 'POST');
switch ($op) {
case 'copyfile':
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
$original_file_path = $_POST['original_file_path'];
}
if (\Xmf\Request::hasVar('file_path', 'POST')) {
$file_path = $_POST['file_path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
if ($op == 'copyfile') {
if (!\Xmf\Request::hasVar('original_file_path', 'POST')
|| !\Xmf\Request::hasVar('file_path', 'POST')
|| !\Xmf\Request::hasVar('redirect', 'POST')) {
return;
}
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
break;
$original_file_path = $_POST['original_file_path'];
$file_path = $_POST['file_path'];
$redirect = $_POST['redirect'];
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
}
2 changes: 1 addition & 1 deletion class/Common/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function changePrefix(): void
* @param string $tableName table to convert
* @param string $columnName column with IP address
*/
private function convertIPAddresses($tableName, $columnName): void
protected function convertIPAddresses(string $tableName, string $columnName): void
{
if ($this->tableHandler->useTable($tableName)) {
$attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);
Expand Down
8 changes: 3 additions & 5 deletions class/Common/ModuleFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ class ModuleFeedback extends \XoopsObject

/**
* Constructor
*
* @param null
*/
public function __construct()
{
}

/**
* @static function &getInstance
*
* @param null
*/
public static function getInstance(): void
{
Expand All @@ -70,7 +66,9 @@ public function getFormFeedback()
$form = new \XoopsThemeForm(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true);
$form->setExtra('enctype="multipart/form-data"');

$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
$xoopsModule = $GLOBALS['xoopsModule'] ?? null;
$authorMail = $xoopsModule ? (string)$xoopsModule->getInfo('author_mail') : '';
$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $authorMail);
$recipient->setExtra('disabled="disabled"');
$form->addElement($recipient);
$your_name = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);
Expand Down
4 changes: 2 additions & 2 deletions class/Common/ModuleStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ trait ModuleStats
{
/**
* @param \XoopsModules\Modulebuilder\Common\Configurator $configurator
* @param array $moduleStats
* @param array $moduleStats
* @return array
*/
public static function getModuleStats($configurator, $moduleStats)
public static function getModuleStats(Configurator $configurator, array $moduleStats)
{
if (\count($configurator->moduleStats) > 0) {
foreach (\array_keys($configurator->moduleStats) as $i) {
Expand Down
14 changes: 7 additions & 7 deletions class/Common/SysUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public static function getInstance()
* www.cakephp.org
*
* @param string $text String to truncate.
* @param int $length Length of returned string, including ellipsis.
* @param int $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param bool $exact If false, $text will not be cut mid-word
* @param bool $considerHtml If true, HTML tags would be handled correctly
* @param bool $exact If false, $text will not be cut mid-word
* @param bool $considerHtml If true, HTML tags would be handled correctly
*
* @return string Trimmed string.
*/
public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true)
public static function truncateHtml(string $text, int $length = 100, string $ending = '...', bool $exact = false, bool $considerHtml = true)
{
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
Expand Down Expand Up @@ -161,11 +161,11 @@ public static function truncateHtml($text, $length = 100, $ending = '...', $exac
}

/**
* @param \Xmf\Module\Helper $helper
* @param array|null $options
* @param \Xmf\Module\Helper|null $helper
* @param array|null $options
* @return \XoopsFormDhtmlTextArea|\XoopsFormEditor
*/
public static function getEditor($helper = null, $options = null)
public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null)
{
/** @var Helper $helper */
if (null === $options) {
Expand Down
22 changes: 10 additions & 12 deletions class/Common/TableChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
public const CHECKTYPE_UPDATE_REPORT = 2; //update and report

/**
* @param \XoopsModules\Modulebuilder\Common\TableChecker|null
* @param mixed $mydirname
* @param mixed $checktype
*/
Expand All @@ -72,12 +71,12 @@
if ($numRows) {
//table exist
$this->result[] = 'Table exist:' . $table;
$ret = $this->checkTableFields($table, $tabledef['fields']);
$this->checkTableFields($table, $tabledef['fields']);
} else {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if ($this::CHECKTYPE_UPDATE == $this->checktype || $this::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
// create new table
$sql = $tabledef['sql'];
if ($this->result = $GLOBALS['xoopsDB']->queryF($sql)) {
if ($GLOBALS['xoopsDB']->queryF($sql)) {
$this->result[] = 'Table created:' . $table;
} else {
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
Expand All @@ -92,6 +91,8 @@
if (self::CHECKTYPE_REPORT == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
return $this->result;
}

return [];
}

private function readSQLFile()
Expand Down Expand Up @@ -156,11 +157,9 @@
{
//todo: split string into single keys
$needle = '(';
$key_text = \substr($line, \strpos($line, $needle, 0) + 1);
$key_text = \substr($line, \strpos($line, $needle) + 1);
$needle = ')';
$key_text = \substr($key_text, 0, \strpos($key_text, $needle, 0));

return $key_text;
return \substr($key_text, 0, \strpos($key_text, $needle));
}

private function extractField($line)
Expand Down Expand Up @@ -191,7 +190,7 @@
if (\count($params) > $counter) {
if ('default' == \mb_strtolower($params[$counter])) {
$field['default'] = $params[$counter] . ' ' . $params[$counter + 1];
$counter = $counter + 2;
//$counter = $counter + 2;

Check warning on line 193 in class/Common/TableChecker.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=XoopsModules25x_modulebuilder&issues=AZ1n-0s0jlhxMrVTDax2&open=AZ1n-0s0jlhxMrVTDax2&pullRequest=173
}
}

Expand All @@ -211,15 +210,15 @@
$numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
if ($numRows) {
//field exist
$this->checkField($table, $field);
$this->checkField($field);
} else {
if (self::CHECKTYPE_UPDATE == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
// create new field
$sql = "ALTER TABLE `$table` ADD " . $field['sql'];
if ('' !== (string)$field['after']) {
$sql .= ' AFTER `' . $field['after'] . '`;';
}
if ($result = $GLOBALS['xoopsDB']->queryF($sql)) {
if ($GLOBALS['xoopsDB']->queryF($sql)) {
$this->result[] = 'Field added:' . $fieldname;
} else {
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
Expand All @@ -234,11 +233,10 @@
return true;
}

private function checkField($table, $field)
private function checkField($field): void
{
//to be created
$this->result[] = 'Field exist:' . $field['name'] . ' - no changes';

return true;
}
}
8 changes: 4 additions & 4 deletions class/Common/TestdataButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestdataButtons
*
* @return void
*/
public static function loadButtonConfig($adminObject): void
public static function loadButtonConfig(\Xmf\Module\Admin $adminObject): void
{
$moduleDirName = \basename(\dirname(__DIR__, 2));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
Expand All @@ -52,13 +52,13 @@ public static function loadButtonConfig($adminObject): void

if (self::SHOW_BUTTONS == $displaySampleButton) {
\xoops_loadLanguage('admin/modulesadmin', 'system');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'));
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'));
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
// $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
} else {
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons');
// $displaySampleButton = $config['displaySampleButton'];
}
}
Expand Down
Loading