Esempio n. 1
0
function handleHtmlFormatting($content, $isMsgBox, $nErrLevel, $action)
{
    $splStr = '';
    $s = '';
    $tempS = '';
    $lCaseS = '';
    $c = '';
    $left4Str = '';
    $left5Str = '';
    $left6Str = '';
    $left7Str = '';
    $left8Str = '';
    $nLevel = '';
    //级别
    $elseS = '';
    $elseLable = '';
    $levelArray = aspArray(299);
    $keyWord = '';
    $lableName = '';
    //标签名称
    $isJavascript = '';
    //为javascript
    $isTextarea = '';
    //为表单文本域<textarea
    $isPre = '';
    //为pre
    $isJavascript = false;
    //默认javascript为假
    $isTextarea = false;
    //表单文件域为假
    $isPre = false;
    //默认pre为假
    $nLevel = 0;
    //级别数
    $action = '|' . $action . '|';
    //动作
    $splStr = aspSplit($content, vbCrlf());
    foreach ($splStr as $key => $s) {
        $tempS = $s;
        $elseS = $s;
        $s = TrimVbCrlf($s);
        $lCaseS = lCase($s);
        //判断于20150710
        if ((left($lCaseS, 8) == '<script ' || left($lCaseS, 8) == '<script>') && inStr($s, '</script>') == false && $isJavascript == false) {
            $isJavascript = true;
            $c = $c . PHPTrim($tempS) . vbCrlf();
        } else {
            if ($isJavascript == true) {
                if (left($lCaseS, 9) == '</script>') {
                    $isJavascript = false;
                    $c = $c . PHPTrim($tempS) . vbCrlf();
                    //最后清除两边空格
                } else {
                    $c = $c . $tempS . vbCrlf();
                    //为js则显示原文本  不处理清空两边空格phptrim(tempS)
                }
                //表单文本域判断于20151019
            } else {
                if ((left($lCaseS, 10) == '<textarea ' || left($lCaseS, 10) == '<textarea>') && inStr($s, '</textarea>') == false && $isTextarea == false) {
                    $isTextarea = true;
                    $c = $c . PHPTrim($tempS) . vbCrlf();
                } else {
                    if ($isTextarea == true) {
                        $c = $c . PHPTrim($tempS) . vbCrlf();
                        if (left($lCaseS, 11) == '</textarea>') {
                            $isTextarea = false;
                        }
                        //表单文本域判断于20151019
                    } else {
                        if ((left($lCaseS, 5) == '<pre ' || left($lCaseS, 5) == '<pre>') && inStr($s, '</pre>') == false && $isPre == false) {
                            $isPre = true;
                            $c = $c . PHPTrim($tempS) . vbCrlf();
                        } else {
                            if ($isPre == true) {
                                $c = $c . $tempS . vbCrlf();
                                if (left($lCaseS, 6) == '</pre>') {
                                    $isPre = false;
                                }
                            } else {
                                if ($s != '' && $isJavascript == false && $isTextarea == false) {
                                    $left4Str = '|' . left($lCaseS, 4) . '|';
                                    $left5Str = '|' . left($lCaseS, 5) . '|';
                                    $left6Str = '|' . left($lCaseS, 6) . '|';
                                    $left7Str = '|' . left($lCaseS, 7) . '|';
                                    $left8Str = '|' . left($lCaseS, 8) . '|';
                                    $keyWord = '';
                                    //关键词初始清空
                                    $lableName = '';
                                    //标签名称
                                    if (inStr('|<ul>|<ul |<li>|<li |<dt>|<dt |<dl>|<dl |<dd>|<dd |<tr>|<tr |<td>|<td |', $left4Str) > 0) {
                                        $keyWord = $left4Str;
                                        $lableName = mid($left4Str, 3, 2);
                                    } else {
                                        if (inStr('|<div>|<div |', $left5Str) > 0) {
                                            $keyWord = $left5Str;
                                            $lableName = mid($left5Str, 3, 3);
                                        } else {
                                            if (inStr('|<span>|<span |<form>|<form |', $left6Str) > 0) {
                                                $keyWord = $left6Str;
                                                $lableName = mid($left6Str, 3, 4);
                                            } else {
                                                if (inStr('|<table>|<table |<tbody>|<tbody |', $left7Str) > 0) {
                                                    $keyWord = $left7Str;
                                                    $lableName = mid($left7Str, 3, 5);
                                                } else {
                                                    if (inStr('|<center>|<center |', $left8Str) > 0) {
                                                        $keyWord = $left8Str;
                                                        $lableName = mid($left8Str, 3, 6);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    $keyWord = aspTrim(replace(replace($keyWord, '<', ''), '>', ''));
                                    //call echo(KeyWord,lableName)
                                    //开始
                                    if ($keyWord != '') {
                                        $s = copyStr('    ', $nLevel) . $s;
                                        if (right($lCaseS, 3 + len($lableName)) != '</' . $lableName . '>' && inStr($lCaseS, '</' . $lableName . '>') == false) {
                                            $nLevel = $nLevel + 1;
                                            if ($nLevel >= 0) {
                                                $levelArray[$nLevel] = $keyWord;
                                            }
                                        }
                                    } else {
                                        if (inStr('|</ul>|</li>|</dl>|</dt>|</dd>|</tr>|</td>|', '|' . left($lCaseS, 5) . '|') > 0 || inStr('|</div>|', '|' . left($lCaseS, 6) . '|') > 0 || inStr('|</span>|</form>|', '|' . left($lCaseS, 7) . '|') > 0 || inStr('|</table>|</tbody>|', '|' . left($lCaseS, 8) . '|') > 0 || inStr('|</center>|', '|' . left($lCaseS, 9) . '|') > 0) {
                                            $nLevel = $nLevel - 1;
                                            $s = copyStr('    ', $nLevel) . $s;
                                        } else {
                                            $s = copyStr('    ', $nLevel) . $s;
                                            //最后是结束标签则减一级
                                            if (right($lCaseS, 6) == '</div>') {
                                                if (checkHtmlFormatting($lCaseS) == false) {
                                                    $s = left($s, len($s) - 6);
                                                    $nLevel = $nLevel - 1;
                                                    $s = $s . vbCrlf() . copyStr('    ', $nLevel) . '</div>';
                                                }
                                            } else {
                                                if (right($lCaseS, 7) == '</span>') {
                                                    if (checkHtmlFormatting($lCaseS) == false) {
                                                        $s = left($s, len($s) - 7);
                                                        $nLevel = $nLevel - 1;
                                                        $s = $s . vbCrlf() . copyStr('    ', $nLevel) . '</span>';
                                                    }
                                                } else {
                                                    if (inStr('|</ul>|</dt>|<dl>|<dd>|', $left5Str) > 0) {
                                                        $s = left($s, len($s) - 5);
                                                        $nLevel = $nLevel - 1;
                                                        $s = $s . vbCrlf() . copyStr('    ', $nLevel) . right($lCaseS, 5);
                                                    }
                                                }
                                            }
                                            //对   aaa</li>   这种进处理   20160106
                                            $elseS = PHPTrim(lCase($elseS));
                                            if (inStr($elseS, '</') > 0) {
                                                $elseLable = mid($elseS, inStr($elseS, '</'), -1);
                                                if (inStr('|</ul>|</li>|</dl>|</dt>|</dd>|</tr>|</td>|</div>|</span>|<form>|', '|' . $elseLable . '|') > 0 && $nLevel > 0) {
                                                    $nLevel = $nLevel - 1;
                                                }
                                            }
                                            //call echo("s",replace(s,"<","&lt;"))
                                        }
                                    }
                                    //call echo("",ShowHtml(temps)
                                    $c = $c . $s . vbCrlf();
                                } else {
                                    if ($s == '') {
                                        if (inStr($action, '|delblankline|') == false && inStr($action, '|删除空行|') == false) {
                                            //删除空行
                                            $c = $c . vbCrlf();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $handleHtmlFormatting = $c;
    $nErrLevel = $nLevel;
    //获得错误级别
    if ($nLevel != 0 && (lCase($isMsgBox) == '1' || lCase($isMsgBox) == 'true')) {
        aspEcho('HTML标签有错误', $nLevel);
    }
    //Call Echo("nLevel",nLevel & "," & levelArray(nLevel))                '显示错误标题20150212
    return @$handleHtmlFormatting;
}
Esempio n. 2
0
function copyHtmlToWeb()
{
    $webDir = '';
    $toWebDir = '';
    $toFilePath = '';
    $filePath = '';
    $fileName = '';
    $fileList = '';
    $splStr = '';
    $content = '';
    $s = '';
    $s1 = '';
    $c = '';
    $webImages = '';
    $webCss = '';
    $webJs = '';
    $splJs = '';
    $webFolderName = '';
    $jsFileList = '';
    $setFileCode = '';
    $nErrLevel = '';
    $jsFilePath = '';
    $url = '';
    $setFileCode = @$_REQUEST['setcode'];
    //设置文件保存编码
    handlePower('复制生成HTML页面');
    //管理权限处理
    writeSystemLog('', '复制生成HTML页面');
    //系统日志
    $webFolderName = $GLOBALS['cfg_webTemplate'];
    if (left($webFolderName, 1) == '/') {
        $webFolderName = mid($webFolderName, 2, -1);
    }
    if (right($webFolderName, 1) == '/') {
        $webFolderName = mid($webFolderName, 1, len($webFolderName) - 1);
    }
    if (inStr($webFolderName, '/') > 0) {
        $webFolderName = mid($webFolderName, inStr($webFolderName, '/') + 1, -1);
    }
    $webDir = '/htmladmin/' . $webFolderName . '/';
    $toWebDir = '/htmlw' . 'eb/viewweb/';
    CreateDirFolder($toWebDir);
    $toWebDir = $toWebDir . pinYin2($webFolderName) . '/';
    deleteFolder($toWebDir);
    //删除
    CreateFolder('/htmlweb/web');
    //创建文件夹 防止web文件夹不存在20160504
    deleteFolder($webDir);
    CreateDirFolder($webDir);
    $webImages = $webDir . 'Images/';
    $webCss = $webDir . 'Css/';
    $webJs = $webDir . 'Js/';
    copyFolder($GLOBALS['cfg_webImages'], $webImages);
    copyFolder($GLOBALS['cfg_webCss'], $webCss);
    CreateFolder($webJs);
    //创建Js文件夹
    //处理Js文件夹
    $splJs = aspSplit(getDirJsList($webJs), vbCrlf());
    foreach ($splJs as $key => $filePath) {
        if ($filePath != '') {
            $toFilePath = $webJs . getFileName($filePath);
            aspEcho('js', $filePath);
            moveFile($filePath, $toFilePath);
        }
    }
    //处理Css文件夹
    $splStr = aspSplit(getDirCssList($webCss), vbCrlf());
    foreach ($splStr as $key => $filePath) {
        if ($filePath != '') {
            $content = getFText($filePath);
            $content = replace($content, $GLOBALS['cfg_webImages'], '../images/');
            $content = deleteCssNote($content);
            $content = PHPTrim($content);
            //设置为utf-8编码 20160527
            if (lCase($setFileCode) == 'utf-8') {
                $content = replace($content, 'gb2312', 'utf-8');
            }
            WriteToFile($filePath, $content, $setFileCode);
            aspEcho('css', $GLOBALS['cfg_webImages']);
        }
    }
    //复制栏目HTML
    $GLOBALS['isMakeHtml'] = true;
    $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'webcolumn where isonhtml=true');
    while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) {
        $GLOBALS['glb_filePath'] = replace(getColumnUrl($rss['columnname'], 'name'), $GLOBALS['cfg_webSiteUrl'] . '/', '');
        if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') {
            $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html';
        }
        if (right($GLOBALS['glb_filePath'], 5) == '.html') {
            if (right($GLOBALS['glb_filePath'], 11) == '/index.html') {
                $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf();
            } else {
                $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList;
            }
            $fileName = replace($GLOBALS['glb_filePath'], '/', '_');
            $toFilePath = $webDir . $fileName;
            copyFile($GLOBALS['glb_filePath'], $toFilePath);
            aspEcho('导航', $GLOBALS['glb_filePath']);
        }
    }
    //复制文章HTML
    $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'articledetail where isonhtml=true');
    while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) {
        $GLOBALS['glb_url'] = getHandleRsUrl($rss['filename'], $rss['customaurl'], '/detail/detail' . $rss['id']);
        $GLOBALS['glb_filePath'] = replace($GLOBALS['glb_url'], $GLOBALS['cfg_webSiteUrl'] . '/', '');
        if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') {
            $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html';
        }
        if (right($GLOBALS['glb_filePath'], 5) == '.html') {
            if (right($GLOBALS['glb_filePath'], 11) == '/index.html') {
                $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf();
            } else {
                $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList;
            }
            $fileName = replace($GLOBALS['glb_filePath'], '/', '_');
            $toFilePath = $webDir . $fileName;
            copyFile($GLOBALS['glb_filePath'], $toFilePath);
            aspEcho('文章' . $rss['title'], $GLOBALS['glb_filePath']);
        }
    }
    //复制单面HTML
    $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'onepage where isonhtml=true');
    while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) {
        $GLOBALS['glb_url'] = getHandleRsUrl($rss['filename'], $rss['customaurl'], '/page/page' . $rss['id']);
        $GLOBALS['glb_filePath'] = replace($GLOBALS['glb_url'], $GLOBALS['cfg_webSiteUrl'] . '/', '');
        if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') {
            $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html';
        }
        if (right($GLOBALS['glb_filePath'], 5) == '.html') {
            if (right($GLOBALS['glb_filePath'], 11) == '/index.html') {
                $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf();
            } else {
                $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList;
            }
            $fileName = replace($GLOBALS['glb_filePath'], '/', '_');
            $toFilePath = $webDir . $fileName;
            copyFile($GLOBALS['glb_filePath'], $toFilePath);
            aspEcho('单页' . $rss['title'], $GLOBALS['glb_filePath']);
        }
    }
    //批量处理html文件列表
    //call echo(cfg_webSiteUrl,cfg_webTemplate)
    //call rwend(fileList)
    $sourceUrl = '';
    $replaceUrl = '';
    $splStr = aspSplit($fileList, vbCrlf());
    foreach ($splStr as $key => $filePath) {
        if ($filePath != '') {
            $filePath = $webDir . replace($filePath, '/', '_');
            aspEcho('filePath', $filePath);
            $content = getFText($filePath);
            foreach ($splStr as $key => $s) {
                $s1 = $s;
                if (right($s1, 11) == '/index.html') {
                    $s1 = left($s1, len($s1) - 11) . '/';
                }
                $sourceUrl = $GLOBALS['cfg_webSiteUrl'] . $s1;
                $replaceUrl = $GLOBALS['cfg_webSiteUrl'] . replace($s, '/', '_');
                //Call echo(sourceUrl, replaceUrl) 							'屏蔽  否则大量显示20160613
                $content = replace($content, $sourceUrl, $replaceUrl);
            }
            $content = replace($content, $GLOBALS['cfg_webSiteUrl'], '');
            //删除网址
            $content = replace($content, $GLOBALS['cfg_webTemplate'] . '/', '');
            //删除模板路径 记
            //content=nullLinkAddDefaultName(content)
            foreach ($splJs as $key => $s) {
                if ($s != '') {
                    $fileName = getFileName($s);
                    $content = replace($content, 'Images/' . $fileName, 'js/' . $fileName);
                }
            }
            if (inStr($content, '/Jquery/Jquery.Min.js') > 0) {
                $content = replace($content, '/Jquery/Jquery.Min.js', 'js/Jquery.Min.js');
                copyFile('/Jquery/Jquery.Min.js', $webJs . '/Jquery.Min.js');
            }
            $content = replace($content, '<a href="" ', '<a href="index.html" ');
            //让首页加index.html
            createFileGBK($filePath, $content);
        }
    }
    //把复制网站夹下的images/文件夹下的js移到js/文件夹下  20160315
    $htmlFileList = '';
    $splHtmlFile = '';
    $splJsFile = '';
    $htmlFilePath = '';
    $jsFileName = '';
    $jsFileList = getDirJsNameList($webImages);
    $htmlFileList = getDirHtmlList($webDir);
    $splHtmlFile = aspSplit($htmlFileList, vbCrlf());
    $splJsFile = aspSplit($jsFileList, vbCrlf());
    foreach ($splHtmlFile as $key => $htmlFilePath) {
        $content = getFText($htmlFilePath);
        foreach ($splJsFile as $key => $jsFileName) {
            $content = regExp_Replace($content, 'Images/' . $jsFileName, 'js/' . $jsFileName);
        }
        $nErrLevel = 0;
        $content = handleHtmlFormatting($content, false, $nErrLevel, '|删除空行|');
        //|删除空行|
        $content = handleCloseHtml($content, true, '');
        //闭合标签
        $nErrLevel = checkHtmlFormatting($content);
        if (checkHtmlFormatting($content) == false) {
            echoRed($htmlFilePath . '(格式化错误)', $nErrLevel);
            //注意
        }
        //设置为utf-8编码
        if (lCase($setFileCode) == 'utf-8') {
            $content = replace($content, '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
        }
        $content = PHPTrim($content);
        WriteToFile($htmlFilePath, $content, $setFileCode);
    }
    //images下js移动到js下
    foreach ($splJsFile as $key => $jsFileName) {
        $jsFilePath = $webImages . $jsFileName;
        $content = getFText($jsFilePath);
        $content = PHPTrim($content);
        WriteToFile($webJs . $jsFileName, $content, $setFileCode);
        DeleteFile($jsFilePath);
    }
    copyFolder($webDir, $toWebDir);
    //使htmlWeb文件夹用php压缩
    if (@$_REQUEST['isMakeZip'] == '1') {
        makeHtmlWebToZip($webDir);
    }
    //使网站用xml打包20160612
    if (@$_REQUEST['isMakeXml'] == '1') {
        makeHtmlWebToXmlZip('/htmladmin/', $webFolderName);
    }
    //浏览地址
    $url = 'http://10.10.10.57/' . $toWebDir;
    aspEcho('浏览', '<a href=\'' . $url . '\' target=\'_blank\'>' . $url . '</a>');
}