예제 #1
0
 /// <summary>
 /// 封装shtml请求,如果是主页,找到其频道Guid,找到其主页,否则直接调用请求
 /// </summary>
 public static void AnyShtmlHeadBody(string index, Stream ns)
 {
     if (Path.GetFileName(index) != ConstService.INDEXSHTML)
     {
         ShtmlHeadBody(index, ns);
     }
     else
     {
         string channelStr  = PathService.GetUrlPath(index);;
         string channelGuid = PathService.GetChannelGuid(channelStr);
         if (!string.IsNullOrEmpty(channelGuid))
         {
             string shtmlIndex = TmpltAndPageService.GetIndexPath(channelGuid);
             if (!string.IsNullOrEmpty(shtmlIndex))
             {
                 shtmlIndex = EncodingService.EncodingUTF8(shtmlIndex.Substring(1));
                 ShtmlHeadBody(shtmlIndex, ns);
             }
             else
             {
                 WrongHeadBody(ns);
             }
         }
         else
         {
             WrongHeadBody(ns);
         }
     }
 }
예제 #2
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);
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        private static void CssRequestHeadBody(string index, Stream putoutStream)
        {
            byte[]       bytesMsgBody = TmpltAndPageService.GetCssByte(index);
            HttpHeadInfo htx          = new HttpHeadInfo();

            htx.Content_Length = bytesMsgBody.Length.ToString();
            htx.Content_Type   = HttpRequestType.Css.MimeType;
            string strMsgHeadx = ConstService.OK + htx.GetHttpHead();

            byte[] bytesMsgHeadx = Encoding.UTF8.GetBytes(strMsgHeadx);
            byte[] bytesMsgAll   = new byte[bytesMsgHeadx.Length + bytesMsgBody.Length];
            Array.Copy(bytesMsgHeadx, 0, bytesMsgAll, 0, bytesMsgHeadx.Length);
            Array.Copy(bytesMsgBody, 0, bytesMsgAll, bytesMsgHeadx.Length, bytesMsgBody.Length);
            try
            {
                putoutStream.Write(bytesMsgAll, 0, bytesMsgAll.Length);
                putoutStream.Flush();
            }
            catch (Exception e)
            {
                ExceptionService.CreateException(e);
            }
            putoutStream.Close();
        }
예제 #5
0
        /// <summary>
        /// 获取Channel下子文件的内容
        /// </summary>
        internal static void ChannelHeadBody(string index, Stream ns)
        {
            string channelGuid = PathService.GetChannelGuid(index);

            if (string.IsNullOrEmpty(channelGuid))
            {
                WrongHeadBody(ns);
            }
            else
            {
                HttpHeadInfo ht    = new HttpHeadInfo();
                string       shtml = TmpltAndPageService.GetChannelContent(channelGuid);
                ht.Content_Type = "text/html";
                byte[] bytes = Encoding.UTF8.GetBytes(shtml);
                ht.Content_Length = bytes.Length.ToString();
                shtml             = ConstService.OK + ht.GetHttpHead() + shtml;
                bytes             = Encoding.UTF8.GetBytes(shtml);
                //string respose = ConstService.Redirect +"Location:" + index + "index.shtml\r\n"+ ht.GetHttpHead();
                //byte[] bytes = Encoding.ASCII.GetBytes(respose);
                ns.Write(bytes, 0, bytes.Length);
                ns.Flush();
                ns.Close();
            }
        }
예제 #6
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);
            }
        }
예제 #7
0
        public static string ChangeKeyList(string phpContent, string tmpltId, string pageId)
        {
            string snipList = TmpltAndPageService.GetKeywordListSnip(tmpltId, pageId);

            return(RegexService.ChangeKeyList(phpContent, snipList));
        }