public async Task <IActionResult> SBApp(string profileType, string url, string content, string imageUrl, string name, string userImage, string screenName, string tweet, string tweetId, string type) { Domain.Socioboard.Helpers.PluginData _PluginData = new Domain.Socioboard.Helpers.PluginData(); _PluginData.profileType = profileType; _PluginData.content = content; _PluginData.imageUrl = imageUrl; _PluginData.name = name; _PluginData.screenName = screenName; _PluginData.tweet = tweet; _PluginData.tweetId = tweetId; _PluginData.url = url; _PluginData.userImage = userImage; _PluginData.type = type; Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User"); if (user != null) { if (!string.IsNullOrEmpty(url) && profileType != "pinterest") { Domain.Socioboard.Helpers.ThumbnailDetails plugindata = PluginHelper.CreateThumbnail(url); _PluginData._ThumbnailDetails = plugindata; } ViewBag.plugin = _PluginData; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); parameters.Add(new KeyValuePair <string, string>("userId", user.Id.ToString())); HttpResponseMessage _response = await WebApiReq.GetReq("/api/GroupProfiles/GetPluginProfile?userId=" + user.Id.ToString(), "", "", _appSettings.ApiDomain); if (_response.IsSuccessStatusCode) { try { List <Domain.Socioboard.Helpers.PluginProfile> lstsb = new List <Domain.Socioboard.Helpers.PluginProfile>(); lstsb = await _response.Content.ReadAsAsync <List <Domain.Socioboard.Helpers.PluginProfile> >(); return(View("RMain", lstsb)); } catch { } } } return(View("Rlogin")); }
//public static Domain.Socioboard.Domain.PluginInfo CreateThumbnail(string Url) //{ // #region UrlIformation // string description = ""; // string imgurl = ""; // Domain.Socioboard.Domain.PluginInfo _plugininfo = new Domain.Socioboard.Domain.PluginInfo(); // if (!Url.Contains("socioboard")) // { // string pagesource = GetHtml(Url); // if (pagesource.Contains("<img") && !string.IsNullOrEmpty(pagesource)) // { // string[] atrr = Regex.Split(pagesource, "<img"); // foreach (var item in atrr) // { // if (item.Contains("src") && !item.Contains("<!DOCTYPE html>")) // { // string url = ""; // try // { // url = getBetween(item, "src=\"", "alt=").Replace("\"", string.Empty); // } // catch (Exception ex) // { // url = getBetween(item, "src=\"", "\"").Replace("\"", string.Empty); // } // imgurl = url + ":" + imgurl; // } // } // } // if (pagesource.Contains("<meta")) // { // string[] metatag = Regex.Split(pagesource, "<meta"); // foreach (var item in metatag) // { // if (item.Contains("description")) // { // description = getBetween(item, "content=", ">").Replace("\"", "").Replace("/", ""); // } // } // } // } // else // { // string pagesource = GetHtml(Url); // if (pagesource.Contains("<img") && !string.IsNullOrEmpty(pagesource)) // { // string[] atrr = Regex.Split(pagesource, "<img"); // foreach (var item in atrr) // { // if (item.Contains("src") && !item.Contains("<!DOCTYPE")) // { // string url = ""; // if (item.Contains("/Themes")) // { // url = getBetween(item, "src=", "alt=").Replace("\"", string.Empty); // url = "https://www.socioboard.com" + url; // } // else // { // url = getBetween(item, "src=", "class=").Replace("\"", string.Empty); // } // imgurl = url + ":" + imgurl; // } // } // } // if (pagesource.Contains("<meta")) // { // string[] metatag = Regex.Split(pagesource, "<meta"); // foreach (var item in metatag) // { // if (item.Contains("description")) // { // description = getBetween(item, "content=", ">").Replace("\"", "").Replace("/", ""); // } // } // } // } // _plugininfo.imageurl = imgurl; // _plugininfo.url = Url; // _plugininfo.description = description; // return _plugininfo; // #endregion //} //public static Chilkat.Http http = new Chilkat.Http(); //public static string GetHtml(string URL) //{ // string response = string.Empty; // //ChangeProxy(); // if (!http.UnlockComponent("THEBACHttp_b3C9o9QvZQ06")) // { // } // ///Save Cookies... // http.CookieDir = "memory"; // //http.CookieDir = Application.StartupPath + "\\cookies"; // http.SendCookies = true; // http.SaveCookies = true; // http.SetRequestHeader("Accept-Encoding", "gzip,deflate"); // http.SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); // http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36"); // http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // //http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // //http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // http.SetRequestHeader("Connection", "keep-alive"); // http.AllowGzip = true; // response = http.QuickGetStr(URL); // if (string.IsNullOrEmpty(response)) // { // response = http.QuickGetStr(URL); // } // if (string.IsNullOrEmpty(response)) // { // response = http.QuickGetStr(URL); // } // return response; //} //public static string getBetween(string strSource, string strStart, string strEnd) //{ // int Start, End; // if (strSource.Contains(strStart) && strSource.Contains(strEnd)) // { // Start = strSource.IndexOf(strStart, 0) + strStart.Length; // End = strSource.IndexOf(strEnd, Start); // return strSource.Substring(Start, End - Start); // } // else // { // return ""; // } //} public static Domain.Socioboard.Helpers.ThumbnailDetails CreateThumbnail(string url) { string title = string.Empty; string description = string.Empty; string image = string.Empty; string _url = string.Empty; List <string> imageurls = new List <string>(); HtmlAttribute haDescription; HtmlAttribute haTitle; HtmlAttribute haImage; HtmlAttribute haUrl; string location = HttpUtility.UrlDecode(url); Domain.Socioboard.Helpers.ThumbnailDetails _ThumbnailDetails = new Domain.Socioboard.Helpers.ThumbnailDetails(); string html = string.Empty; string _html = string.Empty; _url = location; while (!string.IsNullOrWhiteSpace(location)) { if (!_url.Contains("twitter.com/i/notifications")) { _url = location; if (_url.Contains("dashboard.unhookme.com")) { _url = _url.Replace("statCounter", "Login"); } if (_url.Contains("https://contest.edumongoose.com")) { _url = "https://contest.edumongoose.com/home.htm"; } } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url.Replace("i/notifications", "")); request.AllowAutoRedirect = false; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"; try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { location = response.GetResponseHeader("Location"); if (response.StatusCode == HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); StreamReader readStream = null; if (response.CharacterSet == null) { readStream = new StreamReader(receiveStream); } else { readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); } html = readStream.ReadToEnd(); readStream.Close(); } else if (response.StatusCode == HttpStatusCode.Found) { var uri = new Uri(_url); location = uri.GetLeftPart(System.UriPartial.Authority); } } } catch (Exception ex) { html = ""; } } HtmlDocument hdoc = new HtmlDocument(); if (!string.IsNullOrEmpty(html)) { hdoc.LoadHtml(html); HtmlNode nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//meta[@name='description']"); if (nodeDescrption == null) { nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:description']"); if (nodeDescrption == null) { nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//p"); if (nodeDescrption != null) { try { description = nodeDescrption.InnerText; nodeDescrption = null; } catch (Exception ex) { nodeDescrption = null; } } } } if (nodeDescrption != null) { haDescription = nodeDescrption.Attributes["content"]; description = haDescription.Value; } else { } HtmlNode nodeTitle = hdoc.DocumentNode.SelectSingleNode("//meta[@name='title']"); if (nodeTitle == null) { nodeTitle = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:title']"); if (nodeTitle == null) { nodeTitle = hdoc.DocumentNode.SelectSingleNode("//title"); } } if (nodeTitle != null) { try { haTitle = nodeTitle.Attributes["content"]; title = haTitle.Value; title = title.Replace(" & ", "&").Replace("nnn#8211", "").Replace("'s", "").Replace("–", ""); //title = Regex.Replace(title, @"(\s+|@|&|'|\(|\)|<|>|#)", ""); } catch (Exception ex) { try { title = nodeTitle.InnerText.Replace(" & ", "&").Replace("nnn#8211", "").Replace("'s", "").Replace("–", ""); //title= Regex.Replace(title, @"(\s+|@|&|'|\(|\)|<|>|#)", ""); } catch (Exception exx) { title = ""; } } } HtmlNodeCollection nodeimgs = new HtmlNodeCollection(hdoc.DocumentNode.ParentNode); nodeimgs = hdoc.DocumentNode.SelectNodes("//img"); if (nodeimgs != null) { foreach (HtmlNode img in nodeimgs) { try { HtmlAttribute src = img.Attributes["src"]; if (src.Value.Contains("https") || src.Value.Contains("https")) { imageurls.Add(src.Value); } } catch (Exception ex) { } } } HtmlNode nodeImage = hdoc.DocumentNode.SelectSingleNode("//meta[@name='image']"); if (nodeImage == null) { nodeImage = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:image']"); if (nodeImage == null) { try { nodeImage = hdoc.DocumentNode.SelectSingleNode("//img"); if (nodeImage != null) { haImage = nodeImage.Attributes["src"]; image = haImage.Value; nodeImage = null; } } catch { nodeImage = null; } } } if (nodeImage != null) { haImage = nodeImage.Attributes["content"]; image = haImage.Value; } HtmlNode nodeUrl = hdoc.DocumentNode.SelectSingleNode("//meta[@name='url']"); if (nodeUrl == null) { nodeUrl = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:url']"); } if (nodeUrl != null) { haUrl = nodeUrl.Attributes["content"]; _url = haUrl.Value; } _ThumbnailDetails.description = description; _ThumbnailDetails.image = image; _ThumbnailDetails.title = title; _ThumbnailDetails.url = _url; _ThumbnailDetails.imageurls = imageurls; } else { _ThumbnailDetails.description = ""; _ThumbnailDetails.image = ""; _ThumbnailDetails.title = ""; _ThumbnailDetails.url = _url; _ThumbnailDetails.imageurls = new List <string>(); } return(_ThumbnailDetails); }
//public static Domain.Socioboard.Domain.PluginInfo CreateThumbnail(string Url) //{ // #region UrlIformation // string description = ""; // string imgurl = ""; // Domain.Socioboard.Domain.PluginInfo _plugininfo = new Domain.Socioboard.Domain.PluginInfo(); // if (!Url.Contains("socioboard")) // { // string pagesource = GetHtml(Url); // if (pagesource.Contains("<img") && !string.IsNullOrEmpty(pagesource)) // { // string[] atrr = Regex.Split(pagesource, "<img"); // foreach (var item in atrr) // { // if (item.Contains("src") && !item.Contains("<!DOCTYPE html>")) // { // string url = ""; // try // { // url = getBetween(item, "src=\"", "alt=").Replace("\"", string.Empty); // } // catch (Exception ex) // { // url = getBetween(item, "src=\"", "\"").Replace("\"", string.Empty); // } // imgurl = url + ":" + imgurl; // } // } // } // if (pagesource.Contains("<meta")) // { // string[] metatag = Regex.Split(pagesource, "<meta"); // foreach (var item in metatag) // { // if (item.Contains("description")) // { // description = getBetween(item, "content=", ">").Replace("\"", "").Replace("/", ""); // } // } // } // } // else // { // string pagesource = GetHtml(Url); // if (pagesource.Contains("<img") && !string.IsNullOrEmpty(pagesource)) // { // string[] atrr = Regex.Split(pagesource, "<img"); // foreach (var item in atrr) // { // if (item.Contains("src") && !item.Contains("<!DOCTYPE")) // { // string url = ""; // if (item.Contains("/Themes")) // { // url = getBetween(item, "src=", "alt=").Replace("\"", string.Empty); // url = "https://www.socioboard.com" + url; // } // else // { // url = getBetween(item, "src=", "class=").Replace("\"", string.Empty); // } // imgurl = url + ":" + imgurl; // } // } // } // if (pagesource.Contains("<meta")) // { // string[] metatag = Regex.Split(pagesource, "<meta"); // foreach (var item in metatag) // { // if (item.Contains("description")) // { // description = getBetween(item, "content=", ">").Replace("\"", "").Replace("/", ""); // } // } // } // } // _plugininfo.imageurl = imgurl; // _plugininfo.url = Url; // _plugininfo.description = description; // return _plugininfo; // #endregion //} //public static Chilkat.Http http = new Chilkat.Http(); //public static string GetHtml(string URL) //{ // string response = string.Empty; // //ChangeProxy(); // if (!http.UnlockComponent("THEBACHttp_b3C9o9QvZQ06")) // { // } // ///Save Cookies... // http.CookieDir = "memory"; // //http.CookieDir = Application.StartupPath + "\\cookies"; // http.SendCookies = true; // http.SaveCookies = true; // http.SetRequestHeader("Accept-Encoding", "gzip,deflate"); // http.SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); // http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36"); // http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // //http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // //http.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // http.SetRequestHeader("Connection", "keep-alive"); // http.AllowGzip = true; // response = http.QuickGetStr(URL); // if (string.IsNullOrEmpty(response)) // { // response = http.QuickGetStr(URL); // } // if (string.IsNullOrEmpty(response)) // { // response = http.QuickGetStr(URL); // } // return response; //} //public static string getBetween(string strSource, string strStart, string strEnd) //{ // int Start, End; // if (strSource.Contains(strStart) && strSource.Contains(strEnd)) // { // Start = strSource.IndexOf(strStart, 0) + strStart.Length; // End = strSource.IndexOf(strEnd, Start); // return strSource.Substring(Start, End - Start); // } // else // { // return ""; // } //} public static Domain.Socioboard.Helpers.ThumbnailDetails CreateThumbnail(string url) { string title = string.Empty; string description = string.Empty; string image = string.Empty; string _url = string.Empty; HtmlAttribute haDescription; HtmlAttribute haTitle; HtmlAttribute haImage; HtmlAttribute haUrl; string location = HttpUtility.UrlDecode(url); Domain.Socioboard.Helpers.ThumbnailDetails _ThumbnailDetails = new Domain.Socioboard.Helpers.ThumbnailDetails(); string html = string.Empty; string _html = string.Empty; while (!string.IsNullOrWhiteSpace(location)) { _url = location; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url); request.AllowAutoRedirect = false; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"; try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { location = response.GetResponseHeader("Location"); if (response.StatusCode == HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); StreamReader readStream = null; if (response.CharacterSet == null) { readStream = new StreamReader(receiveStream); } else { readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); } html = readStream.ReadToEnd(); readStream.Close(); } else if (response.StatusCode == HttpStatusCode.Found) { var uri = new Uri(_url); location = uri.GetLeftPart(System.UriPartial.Authority); } } } catch (Exception ex) { html = ""; } } HtmlDocument hdoc = new HtmlDocument(); if (!string.IsNullOrEmpty(html)) { hdoc.LoadHtml(html); HtmlNode nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//meta[@name='description']"); if (nodeDescrption == null) { nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:description']"); if (nodeDescrption == null) { nodeDescrption = hdoc.DocumentNode.SelectSingleNode("//p"); if (nodeDescrption != null) { try { description = nodeDescrption.InnerText; nodeDescrption = null; } catch (Exception ex) { nodeDescrption = null; } } } } if (nodeDescrption != null) { haDescription = nodeDescrption.Attributes["content"]; description = haDescription.Value; } else { } HtmlNode nodeTitle = hdoc.DocumentNode.SelectSingleNode("//meta[@name='title']"); if (nodeTitle == null) { nodeTitle = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:title']"); if (nodeTitle == null) { nodeTitle = hdoc.DocumentNode.SelectSingleNode("//title"); } } if (nodeTitle != null) { try { haTitle = nodeTitle.Attributes["content"]; title = haTitle.Value; } catch (Exception ex) { try { title = nodeTitle.InnerText; } catch (Exception exx) { title = ""; } } } HtmlNode nodeImage = hdoc.DocumentNode.SelectSingleNode("//meta[@name='image']"); if (nodeImage == null) { nodeImage = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:image']"); if (nodeImage == null) { try { nodeImage = hdoc.DocumentNode.SelectSingleNode("//img"); if (nodeImage != null) { haImage = nodeImage.Attributes["src"]; image = haImage.Value; nodeImage = null; } } catch { nodeImage = null; } } } if (nodeImage != null) { haImage = nodeImage.Attributes["content"]; image = haImage.Value; } HtmlNode nodeUrl = hdoc.DocumentNode.SelectSingleNode("//meta[@name='url']"); if (nodeUrl == null) { nodeUrl = hdoc.DocumentNode.SelectSingleNode("//meta[@property='og:url']"); } if (nodeUrl != null) { haUrl = nodeUrl.Attributes["content"]; _url = haUrl.Value; } _ThumbnailDetails.description = description; _ThumbnailDetails.image = image; _ThumbnailDetails.title = title; _ThumbnailDetails.url = _url; } else { _ThumbnailDetails.description = ""; _ThumbnailDetails.image = ""; _ThumbnailDetails.title = ""; _ThumbnailDetails.url = _url; } return(_ThumbnailDetails); }
public async Task <IActionResult> SBApp(string profileType, string url, string content, string imageUrl, string name, string userImage, string screenName, string tweet, string tweetId, string type, string EmailId) { string password = ""; Domain.Socioboard.Helpers.PluginData _PluginData = new Domain.Socioboard.Helpers.PluginData(); _PluginData.profileType = profileType; _PluginData.content = content; _PluginData.imageUrl = imageUrl; _PluginData.name = name; _PluginData.screenName = screenName; _PluginData.tweet = tweet; _PluginData.tweetId = tweetId; _PluginData.url = url; _PluginData.userImage = userImage; _PluginData.type = type; Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User"); if (user == null) { if (Request.Cookies["socioboardpluginemailId"] != null) { EmailId = Request.Cookies["socioboardpluginemailId"].ToString(); EmailId = PluginHelper.Base64Decode(EmailId); } if (Request.Cookies["socioboardpluginToken"] != null) { password = Request.Cookies["socioboardpluginToken"].ToString(); password = PluginHelper.Base64Decode(password); } if (!string.IsNullOrEmpty(EmailId) && !string.IsNullOrEmpty(password)) { List <KeyValuePair <string, string> > Parameters = new List <KeyValuePair <string, string> >(); Parameters.Add(new KeyValuePair <string, string>("UserName", EmailId)); Parameters.Add(new KeyValuePair <string, string>("Password", password)); HttpResponseMessage _response = await WebApiReq.PostReq("/api/User/CheckUserLogin", Parameters, "", "", _appSettings.ApiDomain); if (_response.IsSuccessStatusCode) { try { user = await _response.Content.ReadAsAsync <Domain.Socioboard.Models.User>(); HttpContext.Session.SetObjectAsJson("User", user); } catch { } } else { ViewBag.User = "******"; return(View("Rlogin")); } } } if (user != null) { if (!string.IsNullOrEmpty(url) && profileType != "pinterest") { Domain.Socioboard.Helpers.ThumbnailDetails plugindata = PluginHelper.CreateThumbnail(url); _PluginData._ThumbnailDetails = plugindata; } ViewBag.plugin = _PluginData; ViewBag.emailId = user.EmailId; ViewBag.password = user.Password; HttpResponseMessage response = await WebApiReq.GetReq("/api/Groups/GetUserGroups?userId=" + user.Id, "", "", _appSettings.ApiDomain); if (response.IsSuccessStatusCode) { try { List <Domain.Socioboard.Models.Groups> groups = await response.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groups> >(); long selectedGroupId = groups.FirstOrDefault(t => t.groupName == Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName).id; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); parameters.Add(new KeyValuePair <string, string>("userId", user.Id.ToString())); HttpResponseMessage _response = await WebApiReq.GetReq("/api/GroupProfiles/GetPluginProfile?groupId=" + selectedGroupId, "", "", _appSettings.ApiDomain); if (_response.IsSuccessStatusCode) { try { List <Domain.Socioboard.Helpers.PluginProfile> lstsb = new List <Domain.Socioboard.Helpers.PluginProfile>(); lstsb = await _response.Content.ReadAsAsync <List <Domain.Socioboard.Helpers.PluginProfile> >(); return(View("RMain", lstsb)); } catch { } } } catch { } } } return(View("Rlogin")); }