Ejemplo n.º 1
0
        /// <summary>
        /// 获取后台红人用户头像,1:大头像(400*400),2:中头像(300*300),3:小头像(200*200)
        /// </summary>
        /// <param name="imgURL">头像地址</param>
        /// <param name="type">1:大头像(400*400),2:中头像(300*300),3:小头像(200*200)</param>
        /// <returns></returns>
        public static string Get_Upload_User_Head(string imgURL, int type)
        {
            string typeName = "";

            if (type == 1)
            {
                typeName = "large_";
            }
            else if (type == 2)
            {
                typeName = "middle_";
            }
            else if (type == 3)
            {
                typeName = "small_";
            }
            else
            {
                typeName = "";
            }

            string cur_img_url = imgURL;

            if (imgURL == "")
            {
                cur_img_url = "";
            }
            else
            {
                cur_img_url = ImgHelper.GetCofigShowUrl() + imgURL.Substring(0, imgURL.LastIndexOf("/") + 1) + typeName + imgURL.Substring(imgURL.LastIndexOf("/") + 1);
            }

            return(cur_img_url);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取用户头像,1:大头像,2:中头像,3:小头像
        /// </summary>
        /// <param name="imgURL">头像地址</param>
        /// <param name="type">1:大头像,2:中头像,3:小头像</param>
        /// <returns></returns>
        public static string Return_User_Head(string imgURL, int type)
        {
            string typeName = "";

            if (type == 1)
            {
                typeName = "large_";
            }
            else if (type == 2)
            {
                typeName = "middle_";
            }
            else if (type == 3)
            {
                typeName = "small_";
            }
            else
            {
                typeName = "";
            }

            string cur_img_url = imgURL;

            if (imgURL.IndexOf("/") < 0)
            {
                cur_img_url = "/template/img/default_head/" + typeName + imgURL;
            }
            else
            {
                cur_img_url = ImgHelper.GetCofigShowUrl() + imgURL.Substring(0, imgURL.LastIndexOf("/") + 1) + typeName + imgURL.Substring(imgURL.LastIndexOf("/") + 1);
            }

            return(cur_img_url);
        }
Ejemplo n.º 3
0
        public static string[] GetArticleInfo(string article_url, string encod, string Detail_Need_Start_HTML, string Detail_Need_End_HTML, string start_title, string end_title, string start_content, string end_content, string start_tag, string end_tag)
        {
            string html = "";

            html = getHtmlString(article_url, encod).Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\\", "");
            Detail_Need_Start_HTML = Detail_Need_Start_HTML.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\\", "");
            Detail_Need_End_HTML   = Detail_Need_End_HTML.Replace("\r", "").Replace("\n", "").Replace("\t", "");
            html = GetNeedHTML(html, Detail_Need_Start_HTML, Detail_Need_End_HTML);
            string title = "", content = "";

            string[] article_content = new string[3];
            title = GetNeedHTML(html, start_title, end_title);
            article_content[0] = title;
            html = Regex.Replace(html, "\\s{2,}", "");
            //content = GetNeedHTML(html, start_content, end_content);
            int a = html.IndexOf(start_content.Replace("\\", ""));
            int b = html.IndexOf(end_content.Replace("\\", "")) - html.IndexOf(start_content.Replace("\\", ""));

            content = html.Substring(a, b);
            content = Regex.Replace(content, @"<a[^>]*?>", "", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, @"</a>", "", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, @"<div[^>]*?>", "", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, @"</div>", "", RegexOptions.IgnoreCase);
            string tags = "";

            if (!string.IsNullOrEmpty(start_tag))
            {
                tags = GetNeedHTML(html, start_tag, end_tag);
                tags = GetTagStrList(tags);
            }
            article_content[2] = tags;

            string imgFile;
            string righthtml = content;

            imgFile = GetImgUrl(content).Replace('"', ' ').Replace(" ", "");
            if (imgFile != "")
            {
                #region     循环照图片
                bool abc = true;
                //处理图片, 并把新的图片名称,覆盖到现有的,处理完,继续寻找
                while (GetImgUrl(righthtml).Replace('"', ' ').Replace(" ", "").Length > 0 || abc)
                {
                    abc     = false;
                    imgFile = GetImgUrl(righthtml).Replace('"', ' ').Replace(" ", "");

                    string Articleimg = content.Substring(content.IndexOf(imgFile));
                    Articleimg = Articleimg.Substring(0, Articleimg.IndexOf('"'));

                    string upext      = GetFileExt(Articleimg);
                    string folder     = DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd");//userguid;//DateTime.Now.ToString("yyyyMM");
                    string new_folder = ImgHelper.GetImg_Use_Pre(3);
                    if (new_folder.IndexOf("/") >= 0)
                    {
                        new_folder = new_folder.Substring(new_folder.IndexOf("/") + 1);
                    }
                    folder = new_folder + folder;
                    string path = ImgHelper.GetCofigUploadUrl();
                    //如果文件夹不存在,则创建
                    if (!Directory.Exists(path + folder))
                    {
                        Directory.CreateDirectory(path + folder);
                    }


                    string strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff"); //取得时间字符串
                    Random ran         = new Random();
                    string strRan      = Convert.ToString(ran.Next(100, 999));     //生成三位随机数
                    string saveName    = strDateTime + strRan + upext;

                    //保存到数据库中的文件路径

                    string file_url = folder + "/" + saveName;

                    string filename  = new_folder + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/" + DateTime.Now.ToString("yyMMddhhmmssfff") + "." + upext;
                    string saveToUrl = path + filename;
                    string newUrl    = ImgHelper.GetCofigShowUrl() + filename;

                    if (!imgFile.Contains("http"))
                    {
                        imgFile = "http://www.trjcn.com" + imgFile;
                    }
                    byte[] byte_img = null;
                    try
                    {
                        byte_img = new System.Net.WebClient().DownloadData(imgFile);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }

                    WriteResponse(saveToUrl, byte_img);
                    newUrl = newUrl.Replace("\\", "/");
                    int    index    = content.IndexOf(Articleimg);
                    string lefthtml = content;
                    lefthtml  = lefthtml.Substring(0, index);
                    righthtml = content.Substring(index + Articleimg.Length);
                    content   = lefthtml + newUrl + righthtml;
                }
                #endregion
            }
            else
            {
            }
            article_content[1] = content;
            //Response.Write(title+"</br>"+content);
            return(article_content);
        }