Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }