/// <summary> /// 处理php请求 /// </summary> public static void PhpHeadBody(string index, Stream ns) { string tmpltId = PathService.GetAnyUrlGuid(index); if (TmpltAndPageService.IsContentElement(tmpltId)) { string phpContent = TmpltAndPageService.GetTmpltContent(tmpltId); //利用正则表达式替换php中的标题等 phpContent = RegexService.ChangePhpTag(phpContent); string content = PhpBody(phpContent, tmpltId); if (!string.IsNullOrEmpty(content)) { HttpHeadInfo ht = new HttpHeadInfo(); content = ConstService.PUBlISHDTD + content; int length = Encoding.UTF8.GetByteCount(content); ht.Content_Length = length.ToString(); ht.Content_Type = "text/html"; string strMsgHead = ConstService.OK + ht.GetHttpHead() + content; byte[] bytes = Encoding.UTF8.GetBytes(strMsgHead); ns.Write(bytes, 0, bytes.Length); ns.Flush(); ns.Close(); } else { WrongHeadBody(ns); } } else { WrongHeadBody(ns); } }
/// <summary> /// 替换模板中的所有页面片 /// </summary> private static string PhpBody(string phpString, string tmpltId) { List <string> listIncloude = RegexService.GetIncloudeList(phpString); foreach (string incloude in listIncloude) { string snipId = PathService.GetIncludeHtmlGuid(incloude); string replaceHtml = TmpltAndPageService.GetSnipContent(tmpltId, snipId); try { phpString = phpString.Replace(incloude, replaceHtml); } catch (Exception e) { ExceptionService.CreateException(e); } } return(phpString); }
/// <summary> /// 替换 include Get /// </summary> static public string ChangeContent(string strContent, string strChange) { Regex contentRegex = new Regex(StrPhpContent, RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.IgnoreCase); Match m = contentRegex.Match(strContent); try { if (!string.IsNullOrEmpty(m.Value)) { strContent = strContent.Replace(m.Value, strChange); } else { strContent = RegexService.ChangeNoContentPage(strContent, strChange); } } catch (Exception e) { ExceptionService.CreateException(e); } return(strContent); }
/// <summary> /// 处理shtml请求 /// </summary> public static void ShtmlHeadBody(string index, Stream ns) { try { string pageId = PathService.GetPageGuid(index); if (!string.IsNullOrEmpty(pageId)) { string shtmlContent = TmpltAndPageService.GetPageContent(pageId); //获取shtml中include所有内容 string strInclude = RegexService.GetShtmlInclude(shtmlContent); //获取引号中所有内容 string quoMarkContent = StringService.GetQuotationMarkComment(strInclude); HttpHeadInfo ht = new HttpHeadInfo(); string content = ConstService.PUBlISHDTD; ht.Content_Type = "text/html"; string path = StringService.DeleteQuest(quoMarkContent); string tmpltId = PathService.GetAnyUrlGuid(path); content += TmpltAndPageService.GetTmpltContent(tmpltId); content = RegexService.ChangeShtmlTag(content, quoMarkContent); if (quoMarkContent.Contains("keywordList=")) { content = ChangeKeyList(content, tmpltId, pageId); } //判断其页面是否含有正文 if (quoMarkContent.Contains("content=")) { string contentId = RegexService.GetContentId(quoMarkContent); //string contentId = PathService.GetContentId(contentPath); //将正文型内容插到模板中 if (TmpltAndPageService.IsContentElement(contentId)) { string strChange = TmpltAndPageService.GetContentPageContent(contentId); //先运行将正文部分替换 content = RegexService.ChangeContent(content, strChange); } //再将其他页面片替换 content = PhpBody(content, tmpltId); } else { content = PhpBody(content, tmpltId); content += ConstService.HTMLUTF8END; } int leng = Encoding.UTF8.GetByteCount(content); ht.Content_Length = leng.ToString(); string shtmlHeadBody = ConstService.OK + ht.GetHttpHead() + content; byte[] shtmlBytes = Encoding.UTF8.GetBytes(shtmlHeadBody); ns.Write(shtmlBytes, 0, shtmlBytes.Length); ns.Flush(); ns.Close(); } else { WrongHeadBody(ns); } } catch (Exception e) { ExceptionService.CreateException(e); } }
public static string ChangeKeyList(string phpContent, string tmpltId, string pageId) { string snipList = TmpltAndPageService.GetKeywordListSnip(tmpltId, pageId); return(RegexService.ChangeKeyList(phpContent, snipList)); }