芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/cloud.pulsehost.co.uk/dev/process_config_comments.php
$arr) { if (!is_array($arr)) { continue; } foreach ($keysToUnset as $keyToUnset) { if (array_key_exists($keyToUnset, $associativeArray)) { unset($associativeArray[$keyToUnset]); } } $associativeArray[$key] = $arr; } return $associativeArray; } $sModulesPath = "../modules/"; $sModulesCopyPath = "../modules_configs/"; $aModulesList = array_diff(scandir($sModulesPath), array('..', '.')); // Modules list for debug // $aModulesList = ["Core"]; // $aModulesList = glob('./modules_configs/*', GLOB_ONLYDIR); $contentHtml = ""; $mainHtml = ""; foreach ($aModulesList as $sModuleName) { if (!is_dir($sModulesPath . $sModuleName)) { continue; } echo "Processing " . $sModuleName . " module\n"; $sFileContent = file_get_contents($sModulesPath . $sModuleName . "/config.json"); $aParametersList = json_decode($sFileContent, true); $aNewParametersList = []; $bCommentAdded = false; if ($aParametersList !== null && json_last_error() === JSON_ERROR_NONE) { foreach ($aParametersList as $sParamName => $aParamValue) { switch (true) { //both parameter and comment are exist case (substr($sParamName, -12) === '_Description' && isset($aParametersList[substr($sParamName, 0, -12)])): $aNewParametersList[substr($sParamName, 0, -12)] = $aParametersList[substr($sParamName, 0, -12)]; $aNewParametersList[$sParamName] = $aParamValue; break; //got a param without a comment case (substr($sParamName, -12) !== '_Description'): $sParamCommentName = $sParamName.'_Description'; $bCommentExists = isset($aParametersList[$sParamCommentName]); if (!$bCommentExists) { $aNewParametersList[$sParamName] = $aParamValue; $aNewParametersList[$sParamCommentName] = ["", "string"]; $bCommentAdded = true; } break; //removing orphan comment case (substr($sParamName, -12) === '_Description'): // $bParamExists = isset($aParametersList[substr($sParamName, 0, -8)]); break; } } if ($bCommentAdded) { echo "Modified " . $sModuleName . " module's config\n"; } // ksort($aParametersList); $output = json_encode($aNewParametersList, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT); // replace duplicated spaces and tabs in descriptions $output = preg_replace('/(?<=\S)(\h{1,})(?=.*\")/', ' ', $output); // $output = preg_replace('/(?\n"; $mainHtml .= "
".$sModuleName."
\n"; $mainHtml .= "
\n"; $contentHtml .= "\t
".$sModuleName."
\n"; // $sFileContent = file_get_contents($sModulesPath . $sModuleName . "/config.json"); // $aParametersList = json_decode($sFileContent, true); $aNewParametersListHTML = [ 'Disabled' => $aNewParametersList['Disabled'], 'Disabled_Description' => $aNewParametersList['Disabled_Description'] ]; $aNewParametersList = $aNewParametersListHTML + removeKeysFromAssociativeArray($aNewParametersList, ['Disabled', 'Disabled_Description']); foreach ($aNewParametersList as $sParamName => $aParamValue) { if (substr($sParamName, -12) === '_Description') { $mainHtml .= "\t
".substr($sParamName, 0, -12)."
\n"; $mainHtml .= "\t
".$aParamValue[0]."
\n"; } } $mainHtml .= "\n"; } else { echo 'ERROR in '.$sModuleName.': ' . json_last_error_msg(); } $sConfigCopyName = $sModulesCopyPath . $sModuleName . "/config" . ($bCommentAdded ? "_modifiled" : "") . ".json"; $result = file_force_contents($sConfigCopyName, $output); } else { echo 'ERROR parsing ' . $sModuleName . ': ' . json_last_error_msg(); } } $outputHtml = "\n"; $outputHtml .= "\n"; $outputHtml .= "
\n"; $outputHtml .= "\n"; $outputHtml .= "
\n" . $contentHtml . "
\n"; $outputHtml .= $mainHtml; $outputHtml .= ""; $result = file_force_contents($sModulesCopyPath . "configs.html", $outputHtml);