using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.Net; using System.IO; using System.Text.RegularExpressions; using System.Collections; public partial class _Default : System.Web.UI.Page { string serviceURL; string slyBlog; string tipOwner = ""; struct BlogUser { public string userHref; public string userPic; public string userName; public bool isDeleted; public bool isCommunity; public bool isSyndicated; } protected void Page_Load(object sender, EventArgs e) { serviceURL = System.Configuration.ConfigurationSettings.AppSettings.Get("serviceURL"); slyBlog = System.Configuration.ConfigurationSettings.AppSettings.Get("slyBlog"); if (Request["l"] != null) if (Request["l"].ToString() == "e") hidLang.Value = "Eng"; if (hidLang.Value == "Rus") { lblCopyright.Text = System.Configuration.ConfigurationManager.AppSettings["StranichkaRus"].ToString() + " © " + "«" + System.Configuration.ConfigurationManager.AppSettings["TechnologyRus"].ToString() + "»"; this.Title = System.Configuration.ConfigurationManager.AppSettings["HouseRus"].ToString(); lblMainText.Text = System.Configuration.ConfigurationManager.AppSettings["MainTextRus"].ToString(); lblMainText2.Text = System.Configuration.ConfigurationManager.AppSettings["MainText2Rus"].ToString(); lblUserName.Text = System.Configuration.ConfigurationManager.AppSettings["UserNameRus"].ToString(); cmdGo.Text = System.Configuration.ConfigurationManager.AppSettings["BuildRus"].ToString(); lblNoUser.Text = System.Configuration.ConfigurationManager.AppSettings["NoUserRus"].ToString(); lblUserHasNoFriends.Text = System.Configuration.ConfigurationManager.AppSettings["UserHasNoFriendsRus"].ToString(); lblNoService.Text = System.Configuration.ConfigurationManager.AppSettings["NoServiceRus"].ToString(); lblHTMLCode.Text = System.Configuration.ConfigurationManager.AppSettings["HTMLCodeRus"].ToString(); lblYourLink.Text = System.Configuration.ConfigurationManager.AppSettings["YourLinkRus"].ToString(); lblWhatNext.Text = System.Configuration.ConfigurationManager.AppSettings["WhatNextRus"].ToString(); lblLJnoid.Text = System.Configuration.ConfigurationManager.AppSettings["LJnoidRus"].ToString(); lblSpeed.Text = System.Configuration.ConfigurationManager.AppSettings["SpeedRus"].ToString(); lblComingSoon.Text = System.Configuration.ConfigurationManager.AppSettings["ComingSoonRus"].ToString(); lblLJtris.Text = System.Configuration.ConfigurationManager.AppSettings["LJtrisRus"].ToString(); tipOwner = System.Configuration.ConfigurationManager.AppSettings["tipOwnerRus"].ToString(); pnlOtherProjects.Visible = true; } else { lblCopyright.Text = System.Configuration.ConfigurationManager.AppSettings["StranichkaEng"].ToString() + " © " + "«" + System.Configuration.ConfigurationManager.AppSettings["TechnologyEng"].ToString() + "»"; this.Title = System.Configuration.ConfigurationManager.AppSettings["HouseEng"].ToString(); lblMainText.Text = System.Configuration.ConfigurationManager.AppSettings["MainTextEng"].ToString(); lblMainText2.Text = System.Configuration.ConfigurationManager.AppSettings["MainText2Eng"].ToString(); lblUserName.Text = System.Configuration.ConfigurationManager.AppSettings["UserNameEng"].ToString(); cmdGo.Text = System.Configuration.ConfigurationManager.AppSettings["BuildEng"].ToString(); lblNoUser.Text = System.Configuration.ConfigurationManager.AppSettings["NoUserEng"].ToString(); lblUserHasNoFriends.Text = System.Configuration.ConfigurationManager.AppSettings["UserHasNoFriendsEng"].ToString(); lblNoService.Text = System.Configuration.ConfigurationManager.AppSettings["NoServiceEng"].ToString(); lblHTMLCode.Text = System.Configuration.ConfigurationManager.AppSettings["HTMLCodeEng"].ToString(); lblYourLink.Text = System.Configuration.ConfigurationManager.AppSettings["YourLinkEng"].ToString(); lblWhatNext.Text = System.Configuration.ConfigurationManager.AppSettings["WhatNextEng"].ToString(); lblLJnoid.Text = System.Configuration.ConfigurationManager.AppSettings["LJnoidEng"].ToString(); lblSpeed.Text = System.Configuration.ConfigurationManager.AppSettings["SpeedEng"].ToString(); lblComingSoon.Text = System.Configuration.ConfigurationManager.AppSettings["ComingSoonEng"].ToString(); lblLJtris.Text = System.Configuration.ConfigurationManager.AppSettings["LJtrisEng"].ToString(); tipOwner = System.Configuration.ConfigurationManager.AppSettings["tipOwnerEng"].ToString(); pnlOtherProjects.Visible = false; } lblHeaderText.Text = this.Title; lnkLJnoid.Attributes["style"] = "cursor:hand;"; if (!Page.IsPostBack) { try { string passUser = Request["user"].ToString(); if (passUser != null && passUser.Length > 0) { txtUserName.Text = Server.UrlDecode(passUser); pnlHTML.Visible = true; List Users = GetAllPages(passUser); if (Users != null && Users.Count > 0) { BuildHiddenFields(Users); BuildPicture(Users, passUser); BuildHTML(passUser); pnlHTML.Visible = true; } else { pnlHTML.Visible = false; lblErrorUser.Visible = true; } } else { pnlHTML.Visible = false; txtUserName.Focus(); } } catch (Exception ex) { } txtUserName.Focus(); } } private void BuildHiddenFields(List Users) { string strUserNames = ""; string strUserPics = ""; string strUserHrefs = ""; foreach (BlogUser aUser in Users) { strUserNames += aUser.userName + ","; strUserPics += aUser.userPic + ","; strUserHrefs += aUser.userHref + ","; } strUserNames = strUserNames.Remove(strUserNames.Length - 1); // убрать последнюю запятую strUserPics = strUserPics.Remove(strUserPics.Length - 1); strUserHrefs = strUserHrefs.Remove(strUserHrefs.Length - 1); userNames.Value = strUserNames; userPics.Value = strUserPics; userHrefs.Value = strUserHrefs; } private List GetAllPages(string userName) { // получить первую страницу string ljPage1 = GetPageByURL("http://www.livejournal.com/tools/friendlist.bml?user=" + userName); if (ljPage1 == "") // тут должны быть все варианты проверки, что сервис не работает { lblNoService.Visible = true; txtUserName.Focus(); return null; } else { lblNoService.Visible = false; } if (ljPage1.IndexOf("Invalid user") > 0) { lblNoUser.Visible = true; txtUserName.Focus(); return null; } else { lblNoUser.Visible = false; } if (ljPage1.IndexOf("There are no users to display") > 0) { lblUserHasNoFriends.Visible = true; txtUserName.Focus(); return null; } else { lblUserHasNoFriends.Visible = false; } string strTotal = ljPage1.Substring(ljPage1.IndexOf(@"Total:")+ @"Total:".Length); strTotal = strTotal.Remove(strTotal.IndexOf(@"")); int totalFriends = Convert.ToInt32(strTotal.Trim()); List Users = GetUsers(ljPage1, userName, 1); if (Users == null) { if (hidLang.Value == "Rus") { lblErrorUser.Text = System.Configuration.ConfigurationManager.AppSettings["ErrorUserRus"].ToString(); lblErrorUser.Text += " " + userName + ". "; lblErrorUser.Text += System.Configuration.ConfigurationManager.AppSettings["ErrorSendRus"].ToString(); } else { lblErrorUser.Text = System.Configuration.ConfigurationManager.AppSettings["ErrorUserEng"].ToString(); lblErrorUser.Text += " " + userName + ". "; lblErrorUser.Text += System.Configuration.ConfigurationManager.AppSettings["ErrorSendEng"].ToString(); } lblErrorUser.Text += " " + System.Configuration.ConfigurationManager.AppSettings["slyBlog"].ToString() + ""; lblErrorUser.Visible = true; return null; } // Если френдов больше 100, значит остальные на следующих страницах if (totalFriends > 100) { List aUsers; // нужно всего totalPages страниц, где totalPages = totalFriends \ 100 int totalPages = totalFriends / 100; // если всего друзей 600, то на седьмой странице ничего нет, а если 620, на седьмой странице 20 юзеров, // а значит нам нужно totalPages + 1 страниц if (totalFriends % 100 > 0) totalPages++; for (int page = 2; page <= totalPages; page++) { // поспать минутку, чтобы ЖЖ не быковал System.Threading.Thread.Sleep(1100); // получить n-ю страницу string ljPage = GetPageByURL("http://www.livejournal.com/tools/friendlist.bml?page=" + page.ToString() + "&user=" + userName); // получить список юзеров с n-ной страницы aUsers = GetUsers(ljPage, userName, page); if (aUsers == null) { if (hidLang.Value == "Rus") { lblErrorUser.Text = System.Configuration.ConfigurationManager.AppSettings["ErrorUserRus"].ToString(); lblErrorUser.Text += " " + userName + ". "; lblErrorUser.Text += System.Configuration.ConfigurationManager.AppSettings["ErrorSendRus"].ToString(); } else { lblErrorUser.Text = System.Configuration.ConfigurationManager.AppSettings["ErrorUserEng"].ToString(); lblErrorUser.Text += " " + userName + ". "; lblErrorUser.Text += System.Configuration.ConfigurationManager.AppSettings["ErrorSendEng"].ToString(); } lblErrorUser.Text += " " + System.Configuration.ConfigurationManager.AppSettings["slyBlog"].ToString() + ""; lblErrorUser.Visible = true; return null; } // скопировать получившихся юзеров в List foreach (BlogUser justUser in aUsers) Users.Add(justUser); // очистить временный лист aUsers aUsers.Clear(); } } // теперь нужно удалить из списка всех юзеров у которых isDeleted = true int index = 0; while (index < Users.Count) { if (Users[index].isDeleted) Users.RemoveAt(index); else index++; } // А теперь то же самое для комьюнити у которых isCommunity = true index = 0; while (index < Users.Count) { if (Users[index].isCommunity) Users.RemoveAt(index); else index++; } // И для тех у которых isSyndicated = true index = 0; while (index < Users.Count) { if (Users[index].isSyndicated) Users.RemoveAt(index); else index++; } return Users; } private List GetUsers(string rawPage, string blogerName, int page) { try { rawPage = rawPage.Replace("\"", "'"); // удалить со страницы все кроме первой table - там все, голубчики, лежат // или во второй, если страниц несколько, тогда в первой - список страниц // в любом случае наша таблица начинается с "")); // удалить все, что начинается с "img src=" и заканчивается "alt='[info]'", это картинки головастиков. //rawPage = RemoveBetween("img src=", "alt=", rawPage, true, true); //// на всякий случай удалить дефолтные картинки для юзера и комьюнитей, они только мешают. //rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/community.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/userinfo.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/userinfo2.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/syndicated.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/openid-profile.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/newsinfo.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/partnercomm.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/user_ontd.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/facebook-profile.gif", ""); ////rawPage = rawPage.Replace("img src='http://p-stat.livejournal.com/img/twitter-profile.gif", ""); //rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/community.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/userinfo.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/userinfo2.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/syndicated.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/openid-profile.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/newsinfo.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/partnercomm.gif'", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/user_ontd.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/facebook-profile.gif", ""); ////rawPage = rawPage.Replace("img src='http://l-stat.livejournal.com/img/twitter-profile.gif", ""); rawPage = rawPage.Replace("img src='http://livejournal.com/img/newyearpic_1.gif", ""); rawPage = rawPage.Replace("img src='http://livejournal.com/img/userinfo.gif", ""); //// удалить идиотских кастомных головастиков //rawPage = rawPage.Replace("img src='http://pics.livejournal.com/", ""); //rawPage = rawPage.Replace("img src='http://files.livejournal.com/", ""); //rawPage = rawPage.Replace("img src='http://supcity.ru/", ""); //rawPage = rawPage.Replace("img src='http://www.supcity.ru/", ""); // пропарсить для имени юзера и начать новый List Users string strpat = @"lj:user='(.+?)'"; ArrayList users = FindMatches(rawPage, strpat); if (users.Count < 1) { return null; } List Users = new List(); foreach (string curUser in users) { BlogUser aUser = new BlogUser(); aUser.userName = curUser.Remove(0, 9); // убрать начало - lj:user=' aUser.userName = aUser.userName.Remove(aUser.userName.Length - 1); // убрать закрывающую кавчку - ' Users.Add(aUser); } // пропарсить для userpic //strpat = @""; ArrayList usersDirty = FindMatches(rawPage, strpat); users = RemoveWrongPicures(usersDirty); // стопить тут. Вот тут постоянно ошибка возникает ^^^^^^^ if (users.Count > Users.Count) // ошибка в парсинге userpic-ов, их получилось больше, чем самих юзеров - затесались посторонние картинки { try { string userIP = GetIp(Request).ToString(); string msgErr = @"User from " + userIP + "\n\r" + "HTTP_REFERER - " + Request.ServerVariables["HTTP_REFERER"].ToString() + "\n\r" + "HTTP_USER_AGENT - " + Request.ServerVariables["HTTP_USER_AGENT"].ToString() + "\n\r" + "Error parsing userpics for " + blogerName + " \n\r" + " on page " + page.ToString(); SendEmail("relay-hosting.secureserver.net", "blogavatars@sly2m.com", "sly2m@mail.ru", "Error in blogavatar", msgErr); } catch (Exception ex) { // не отправилось, ну и хрен с ним. } } int i = 0; BlogUser listUser; foreach (string curUser in users) { listUser = Users[i]; listUser.userPic = curUser.Remove(0, 10); // убрать начало - "; users = FindMatches(rawPage, strpat); i = 0; foreach (string curUser in users) { listUser = Users[i]; listUser.userHref = curUser.Remove(0, 13); // убрать начало - "; users = FindMatches(rawPage, strpat); i = 0; foreach (string curUser in users) { listUser = Users[i]; if (curUser.IndexOf("i-ljuser-deleted") > 0) listUser.isDeleted = true; else listUser.isDeleted = false; Users[i] = listUser; i++; } // пропарсить для сообществ //strpat = @""; users = FindMatches(rawPage, strpat); i = 0; foreach (string curUser in users) { listUser = Users[i]; if (curUser.IndexOf("community.gif") > 0) listUser.isCommunity = true; else listUser.isCommunity = false; Users[i] = listUser; i++; } // пропарсить для Syndicated strpat = @"lj:user=(.+?)"; users = FindMatches(rawPage, strpat); i = 0; foreach (string curUser in users) { listUser = Users[i]; if (curUser.IndexOf("syndicated.gif") > 0) listUser.isSyndicated = true; else listUser.isSyndicated = false; Users[i] = listUser; i++; } return Users; } catch (Exception ex) { return null; } } private string GetPageByURL(string strURL) { HttpWebRequest request = null; HttpWebResponse response = null; try { //strURL = "http://www.livejournal.com/to"; request = (HttpWebRequest) WebRequest.Create(strURL); response = (HttpWebResponse)request.GetResponse(); StreamReader resStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string ret = resStream.ReadToEnd(); return ret; } catch (Exception ex) { string userIP = GetIp(Request).ToString(); string msgErr = @"User from " + userIP + "\n\r" + "HTTP_REFERER - " + Request.ServerVariables["HTTP_REFERER"].ToString() + "\n\r" + "HTTP_USER_AGENT - " + Request.ServerVariables["HTTP_USER_AGENT"].ToString() + "\n\r" + "Error getting page for URL " + strURL + " \n\r" + "With error - " + ex.Message; SendEmail("relay-hosting.secureserver.net", "blogavatars@sly2m.com", "sly2m@mail.ru", "Error in blogavatar", msgErr); return ""; } } void BuildPicture(List Users, string userName) { //int pyrHight = 10; //if (Users.Count >= 121) // pyrHight = 11; //else // pyrHight = 10; int houseWidth = 12; // ширина дома в картинках + еще будут 2 крайние стенки int ostatok = Users.Count % houseWidth; // последний/первый неполный ряд будет содержать столько картинок TableRow aRow; TableCell aCell; string strOn = ""; string strFrom = ""; string strWithHelp = ""; string strAuthorBlog = ""; string strServiceLink = ""; if (hidLang.Value == "Rus") { strOn = System.Configuration.ConfigurationManager.AppSettings["OnRus"].ToString(); strFrom = System.Configuration.ConfigurationManager.AppSettings["FromRus"].ToString(); strWithHelp = System.Configuration.ConfigurationManager.AppSettings["WithHelpRus"].ToString(); strAuthorBlog = System.Configuration.ConfigurationManager.AppSettings["AuthorBlogRus"].ToString(); strServiceLink = serviceURL; } else { strOn = System.Configuration.ConfigurationManager.AppSettings["OnEng"].ToString(); strFrom = System.Configuration.ConfigurationManager.AppSettings["FromEng"].ToString(); strWithHelp = System.Configuration.ConfigurationManager.AppSettings["WithHelpEng"].ToString(); strAuthorBlog = System.Configuration.ConfigurationManager.AppSettings["AuthorBlogEng"].ToString(); strServiceLink = serviceURL + "?l=e"; } // крыша aRow = new TableRow(); for (int i = 0; i <= houseWidth + 3; i++) { if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == houseWidth - 2 || i == houseWidth - 1 || i == houseWidth || i == houseWidth + 1 || i == houseWidth + 2 || i == houseWidth + 3) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } else { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } } tblHouse.Rows.Add(aRow); aRow = new TableRow(); for (int i = 0; i <= houseWidth + 1; i++) { if (i == 0 || i == 1 || i == 2 || i == 3 || i == houseWidth - 1 || i == houseWidth || i == houseWidth + 1) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } else if (i == 7) { aCell = new TableCell(); aCell.Attributes.Add("background", serviceURL + "w.jpg"); //aCell.Text = ""; aCell.ColumnSpan = 2; aCell.RowSpan = 2; aRow.Cells.Add(aCell); } else { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } } tblHouse.Rows.Add(aRow); aRow = new TableRow(); for (int i = 0; i <= houseWidth + 1; i++) { if (i == 0 || i == 1 || i == houseWidth || i == houseWidth + 1) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } else { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } } tblHouse.Rows.Add(aRow); aRow = new TableRow(); for (int i = 0; i <= houseWidth + 3; i++) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } tblHouse.Rows.Add(aRow); // заголовок TableCell aHeaderCell = new TableCell(); aHeaderCell.Text = lblHeaderText.Text + " " + userName + " " + strOn + " " + DateTime.Now.Day.ToString("00") + "-" + DateTime.Today.Month.ToString("00") + "-" + DateTime.Today.Year.ToString(); aHeaderCell.Text += "
" + strWithHelp + "
" + lblHeaderText.Text + " " + strFrom + " sly2m"; //aHeaderCell.Text += @""; aHeaderCell.Attributes["style"] = "text-align:center;font-family:Verdana;font-size:large"; aHeaderCell.ColumnSpan = houseWidth; aRow = new TableRow(); aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); aRow.Cells.Add(aHeaderCell); aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); tblHouse.Rows.Add(aRow); int housePosition = 0; // полные ряды for (int j = 0; j <= Users.Count / houseWidth - 1; j++) { aRow = new TableRow(); for (int i = 0; i <= houseWidth + 3; i++) { // пустые if (i == 0 || i == houseWidth + 3) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } // кирпичи else if (i == 1 || i == houseWidth + 2) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } // юзерпики else { aCell = new TableCell(); aCell.Text = ""; if (Users[housePosition].userName == "sly2m") aCell.ToolTip = tipOwner; else aCell.ToolTip = Users[housePosition].userName; aRow.Cells.Add(aCell); housePosition++; } } tblHouse.Rows.Add(aRow); } // подвал if (ostatok != 0) { aRow = new TableRow(); // пустая aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); // кирпич aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); // короткий ряд for (int i = 0; i <= ostatok - 1; i++) { aCell = new TableCell(); aCell.Text = ""; aCell.ToolTip = Users[housePosition].userName; aRow.Cells.Add(aCell); housePosition++; } // дополнить ряд до конца кирпичами for (int i = ostatok; i <= houseWidth; i++) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } // пустая aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); tblHouse.Rows.Add(aRow); } // еще ряд кирпичей aRow = new TableRow(); for (int i = 0; i <= houseWidth + 3; i++) { aCell = new TableCell(); aCell.Text = ""; aRow.Cells.Add(aCell); } tblHouse.Rows.Add(aRow); //tblHouse.Attributes["border"] = "1"; //tblHouse.Attributes["text-align"] = "center"; } void BuildHTML(string anUser) { string strYourLink = ""; if (hidLang.Value == "Rus") { strYourLink = System.Configuration.ConfigurationManager.AppSettings["YourLinkRus"].ToString(); lblYourLink.Text = strYourLink + @" " + serviceURL + "?user=" + Server.UrlEncode(anUser) + ""; } else { strYourLink = System.Configuration.ConfigurationManager.AppSettings["YourLinkEng"].ToString(); lblYourLink.Text = strYourLink + @" " + serviceURL + "?user=" + Server.UrlEncode(anUser) + "&l=e"; } StringBuilder renderedOutput = new StringBuilder(); StringWriter strWriter = new StringWriter(renderedOutput); HtmlTextWriter tWriter = new HtmlTextWriter(strWriter); pnlHouse.RenderControl(tWriter); string txtHtmlBlog = tWriter.InnerWriter.ToString(); txtHtmlBlog = txtHtmlBlog.Replace("\n", ""); txtHtmlBlog = txtHtmlBlog.Replace("\r", ""); htmlBlog.Text = txtHtmlBlog.Replace("\t", ""); tWriter.Flush(); if (htmlBlog.Text.Length > 65535) { if (hidLang.Value == "Rus") { lblHTMLSize.Text = System.Configuration.ConfigurationManager.AppSettings["HTMLSizeRus"].ToString(); } else { lblHTMLSize.Text = System.Configuration.ConfigurationManager.AppSettings["HTMLSizeEng"].ToString(); } lblHTMLSize.Visible = true; } else lblHTMLSize.Visible = false; } private ArrayList FindMatches(string str, string strpat) { Regex pat = new Regex(strpat, RegexOptions.Singleline); MatchCollection matchcol = pat.Matches(str); ArrayList al = new ArrayList(); foreach (Match match in matchcol) al.Add(match.Value); return al; } private void UpdateUsersLog(string userName) { System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath(@"users.txt"), true, Encoding.GetEncoding(1251)); sw.Write("\n" + DateTime.Now.ToShortDateString() + " - " + Request.UserHostAddress + " : " + userName); sw.Close(); } protected void lnkLJnoid_Click(object sender, EventArgs e) { Server.Transfer("ljnoid.aspx"); } protected void cmdGo_Click(object sender, EventArgs e) { string anUser = txtUserName.Text.Trim(); if (anUser.Length > 0) { anUser = anUser.Replace('-', '_'); //GetLJSocket(anUser); List Users = GetAllPages(anUser); if (Users != null && Users.Count > 0) { BuildHiddenFields(Users); BuildPicture(Users, anUser); UpdateUsersLog(anUser); BuildHTML(anUser); pnlHTML.Visible = true; } } } protected void SendEmail(string smtpServer, string from, string to, string subj, string body) { System.Web.Mail.SmtpMail.SmtpServer = smtpServer; System.Web.Mail.SmtpMail.Send(from, to, subj, body); } private ArrayList RemoveWrongPicures(ArrayList users) { ArrayList outUsers = new ArrayList(); foreach (string auser in users) { if (auser.IndexOf("class='userpic-img'") > 0) outUsers.Add(auser); } return outUsers; } protected IPAddress GetIp(HttpRequest request) { string ipString; if (string.IsNullOrEmpty(request.ServerVariables["HTTP_X_FORWARDED_FOR"])) { ipString = request.ServerVariables["REMOTE_ADDR"]; } else { ipString = request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0]; } IPAddress result; if (!IPAddress.TryParse(ipString, out result)) { result = IPAddress.None; } return result; } private static List ExtractFromString( string text, string startString, string endString) { List matched = new List(); int indexStart = 0, indexEnd = 0; bool exit = false; while (!exit) { indexStart = text.IndexOf(startString); indexEnd = text.IndexOf(endString); if (indexStart != -1 && indexEnd != -1) { matched.Add(text.Substring(indexStart + startString.Length, indexEnd - indexStart - startString.Length)); text = text.Substring(indexEnd + endString.Length); } else exit = true; } return matched; } }