diff --git a/admin/codecleaning.php b/admin/codecleaning.php deleted file mode 100644 index c9628c62..00000000 --- a/admin/codecleaning.php +++ /dev/null @@ -1,272 +0,0 @@ - - * - */ - -use Xmf\Request; - -$moduleDirName = \basename(\dirname(\dirname(__DIR__))); -$moduleDirNameUpper = \mb_strtoupper($moduleDirName); - -// Define main template -$templateMain = $moduleDirName . '_index.tpl'; - -include __DIR__ . '/header.php'; -// Recovered value of argument op in the URL $ -$op = Request::getString('op', 'list'); - -$src_path = \constant($moduleDirNameUpper . '_PATH'); -$dst_path = \constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/codecleaned'; - -$patKeys = []; -$patValues = []; -cloneFileFolder($src_path, $dst_path, $patKeys, $patValues); - -function_qualifier($dst_path); - -include __DIR__ . '/footer.php'; - - - -function function_qualifier($dst_path) { - - $sources = []; - - //php functions - $sources[0] = [ - 'array_diff', - 'array_filter', - 'array_key_exists', - 'array_keys', - 'array_search', - 'array_slice', - 'array_unshift', - 'array_values', - 'assert', - 'basename', - 'boolval', - 'call_user_func', - 'call_user_func_array', - 'chr', - 'class_exists', - 'closedir', - 'constant', - 'copy', - 'count', - 'curl_close', - 'curl_error', - 'curl_exec', - 'curl_file_create', - 'curl_getinfo', - 'curl_init', - 'curl_setopt', - 'define', - 'defined', - 'dirname', - 'doubleval', - 'explode', - 'extension_loaded', - 'file_exists', - 'finfo_open', - 'floatval', - 'floor', - 'formatTimestamp', - 'func_get_args', - 'func_num_args', - 'function_exists', - 'get_called_class', - 'get_class', - 'getimagesize', - 'gettype', - 'imagecopyresampled', - 'imagecreatefromgif', - 'imagecreatefromjpeg', - 'imagecreatefrompng', - 'imagecreatefromstring', - 'imagecreatetruecolor', - 'imagedestroy', - 'imagegif', - 'imagejpeg', - 'imagepng', - 'imagerotate', - 'imagesx', - 'imagesy', - 'implode', - 'in_array', - 'ini_get', - 'intval', - 'is_array', - 'is_bool', - 'is_callable', - 'is_dir', - 'is_double', - 'is_float', - 'is_int', - 'is_integer', - 'is_link', - 'is_long', - 'is_null', - 'is_object', - 'is_real', - 'is_resource', - 'is_string', - 'json_decode', - 'json_encode', - 'mime_content_type', - 'mkdir', - 'opendir', - 'ord', - 'pathinfo', - 'preg_match', - 'preg_match_all', - 'preg_replace', - 'readdir', - 'readlink', - 'redirect_header', - 'rename', - 'rmdir', - 'round', - 'scandir', - 'sprintf', - 'str_replace', - 'strip_tags', - 'strlen', - 'strpos', - 'strtotime', - 'strval', - 'substr', - 'symlink', - 'time', - 'trigger_error', - 'trim', - 'ucfirst', - 'unlink', - 'version_compare', - 'mb_strtoupper', - 'mb_strtolower', - 'mb_strpos', - 'mb_strlen', - 'mb_strrpos', - ]; - - // xoops functions - $sources[1] = [ - 'xoops_getHandler', - 'xoops_load', - 'xoops_loadLanguage', - ]; - - // repair known errors - $errors = [ - 'mb_\strlen(' => 'mb_strlen(', - 'mb_\substr(' => 'mb_substr(', - 'x\copy' => 'xcopy', - 'r\rmdir' => 'rrmdir', - 'r\copy' => 'rcopy', - '\dirname()' => 'dirname()', - 'assw\ord' => 'assword', - 'mb_\strpos' => 'mb_strpos', - 'image\copy(' => 'imagecopy(', - '<{if \count(' => '<{if count(', - ]; - - $patterns = []; - foreach ($sources as $source) { - //reset existing in order to avoid double \\ - foreach ($source as $item) { - $patterns['\\' . $item . '('] = $item . '('; - } - //apply now for all - foreach ($source as $item) { - $patterns[$item . '('] = '\\' . $item . '('; - } - } - - //add errors - foreach ($errors as $key => $value) { - $patterns[$key] = $value; - } - - $patKeys = \array_keys($patterns); - $patValues = \array_values($patterns); - cloneFileFolder($dst_path, $dst_path, $patKeys, $patValues); - -} - -// recursive cloning script -/** - * @param $src_path - * @param $dst_path - * @param array $patKeys - * @param array $patValues - */ -function cloneFileFolder($src_path, $dst_path, $patKeys = [], $patValues =[]) -{ - // open the source directory - $dir = \opendir($src_path); - // Make the destination directory if not exist - @\mkdir($dst_path); - // Loop through the files in source directory - while( $file = \readdir($dir) ) { - if (( $file != '.' ) && ( $file != '..' )) { - if ( \is_dir($src_path . '/' . $file) ) { - // Recursively calling custom copy function for sub directory - cloneFileFolder($src_path . '/' . $file, $dst_path . '/' . $file, $patKeys, $patValues); - } else { - cloneFile($src_path . '/' . $file, $dst_path . '/' . $file, $patKeys, $patValues); - } - } - } - \closedir($dir); -} - -/** - * @param $src_file - * @param $dst_file - * @param array $patKeys - * @param array $patValues - */ -function cloneFile($src_file, $dst_file, $patKeys = [], $patValues =[]) -{ - $replace_code = false; - $changeExtensions = ['php']; - if (\in_array(\mb_strtolower(\pathinfo($src_file, PATHINFO_EXTENSION)), $changeExtensions)) { - $replace_code = true; - } - if (\strpos( $dst_file, basename(__FILE__)) > 0) { - //skip myself - $replace_code = false; - } - if ($replace_code) { - // file, read it and replace text - $content = \file_get_contents($src_file); - $content = \str_replace($patKeys, $patValues, $content); - //check file name whether it contains replace code - $path_parts = \pathinfo($dst_file); - $path = $path_parts['dirname']; - $file = $path_parts['basename']; - $dst_file = $path . '/' . \str_replace($patKeys, $patValues, $file); - \file_put_contents($dst_file, $content); - } else { - \copy($src_file, $dst_file); - } -} diff --git a/admin/devtools.php b/admin/devtools.php index e250b1d0..4207a443 100644 --- a/admin/devtools.php +++ b/admin/devtools.php @@ -56,23 +56,22 @@ $src_path = XOOPS_ROOT_PATH . '/modules/' . $clModuleName . '/language/english/'; $langfiles = []; foreach (scandir($src_path) as $scan) { - if (is_file($src_path . $scan) && 'index.html' !== $scan && 'common.php' !== $scan) { + if (is_file($src_path . $scan) && 'index.html' !== $scan) { $langfiles[] = $src_path . $scan; } } $moduleConstants = []; - if (file_exists($src_path . 'common.php')) { - // include common.php first - $constantsBeforeInclude = getUserDefinedConstants(); - include_once($src_path . 'common.php'); - $constantsAfterInclude = getUserDefinedConstants(); - $moduleConstants[$src_path . 'common.php'] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude); - } foreach ($langfiles as $langfile) { - $constantsBeforeInclude = getUserDefinedConstants(); - include_once($langfile); - $constantsAfterInclude = getUserDefinedConstants(); - $moduleConstants[$langfile] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude); + //$constantsBeforeInclude = getUserDefinedConstants(); + require_once($langfile); + //$constantsAfterInclude = getUserDefinedConstants(); + //$moduleConstants[$langfile] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude); + } + $constantsAfterInclude = getUserDefinedConstants(); + foreach ($constantsAfterInclude as $constKey => $constValue) { + if (strpos($constKey, '_' . $clModuleNameUpper . '_') > 0) { + $moduleConstants[$constKey] = $constKey; + } } //get all php and tpl files from module @@ -90,37 +89,70 @@ } //check all constants in all files - $resultsList = []; - foreach ($moduleConstants as $keyFile => $constFile) { - $resultCheck = []; - foreach ($constFile as $constKey => $constValue) { - $found = 0; - $first = ''; - //search for complete string + $resultCheck = []; + foreach ($moduleConstants as $constKey) { + $foundMod = 0; + $first = ''; + $foundLang = 'not defined'; + //search for complete string + foreach($modfiles as $modfile) { + if( strpos(file_get_contents($modfile),$constKey) !== false) { + $foundMod = 1; + $first = $modfile; + break; + } + } + if (0 == $foundMod) { + //search for concatenated string + $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_", $constKey); + foreach($modfiles as $modfile) { + if( strpos(file_get_contents($modfile),$needle) !== false) { + $foundMod = 1; + $first = $modfile; + break; + } + } + } + if (0 == $foundMod) { + //search for concatenated string + $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_' . '", $constKey); foreach($modfiles as $modfile) { - if( strpos(file_get_contents($modfile),$constKey) !== false) { - $found = 1; + if( strpos(file_get_contents($modfile),$needle) !== false) { + $foundMod = 1; $first = $modfile; break; } } - if (0 == $found) { - //search for concatenated string - $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_", $constKey); - foreach($modfiles as $modfile) { - if( strpos(file_get_contents($modfile),$needle) !== false) { - $found = 1; - $first = $modfile; - break; - } + } + foreach($langfiles as $langfile) { + if( strpos(file_get_contents($langfile),$constKey) !== false) { + $foundLang = $langfile; + break; + } + } + if ('' == $foundLang) { + //search for concatenated string + $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_", $constKey); + foreach($langfiles as $langfile) { + if( strpos(file_get_contents($langfile),$needle) !== false) { + $foundLang = $langfile; + break; + } + } + } + if ('' == $foundLang) { + //search for concatenated string + $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_' . '", $constKey); + foreach($langfiles as $langfile) { + if( strpos(file_get_contents($langfile),$needle) !== false) { + $foundLang = $langfile; + break; } } - $resultCheck[] = ['define' => $constKey, 'found' => $found, 'first' => $first]; } - $resultsList[] = ['file' => $keyFile, 'result' => $resultCheck]; + $resultCheck[\basename($foundLang)][] = ['define' => $constKey, 'found' => $foundMod, 'first' => $first]; } - - $GLOBALS['xoopsTpl']->assign('clresults', $resultsList); + $GLOBALS['xoopsTpl']->assign('clresults', $resultCheck); $GLOBALS['xoopsTpl']->assign('modPathIcon16', TDMC_URL . '/' . $modPathIcon16); break; diff --git a/class/Form/ThemeForm.php b/class/Form/ThemeForm.php new file mode 100644 index 00000000..cc005ed7 --- /dev/null +++ b/class/Form/ThemeForm.php @@ -0,0 +1,72 @@ + + * + */ +defined('XOOPS_ROOT_PATH') || die('Restricted access'); + +\XoopsLoad::load('XoopsFormLoader'); + +/** + * Form that will output as a theme-enabled HTML table. + * + * Also adds JavaScript to validate required fields + */ +class ThemeForm extends \XoopsForm +{ + /** + * create HTML to output the form as a theme-enabled table with validation. + * + * YOU SHOULD AVOID TO USE THE FOLLOWING Nocolspan METHOD, IT WILL BE REMOVED + * + * To use the noColspan simply use the following example: + * + * $colspan = new \XoopsFormDhtmlTextArea( '', 'key', $value, '100%', '100%' ); + * $colspan->setNocolspan(); + * $form->addElement( $colspan ); + * + * @return string + */ + public function render() + { + $ele_name = $this->getName(); + //$ret = ($this->getTitle() ? '
<{$clresultfile.file}>
+<{$smarty.const._AM_MODULEBUILDER_DEVTOOLS_CL_RESULT_LEGEND}>
+
+
+ <{$smarty.const._AM_MODULEBUILDER_DEVTOOLS_CL_RESULT_SUCCESS}> <{$smarty.const._AM_MODULEBUILDER_DEVTOOLS_CL_RESULT_SUCCESS_DESCR}>
+
+
+ <{$smarty.const._AM_MODULEBUILDER_DEVTOOLS_CL_RESULT_FAILED}>
+
<{$smarty.const._AM_MODULEBUILDER_DEVTOOLS_CL_FILE}> <{$key}>