コード例 #1
0
        public ActionResult SBApp(string profileType, string url, string content, string imageUrl, string name, string userImage, string screenName, string tweet, string tweetId, string type)
        {
            Domain.Socioboard.Helper.PluginData _PluginData = new Domain.Socioboard.Helper.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;

            if (Session["User"] != null)
            {
                if (!string.IsNullOrEmpty(url) && profileType != "pinterest")
                {
                    Domain.Socioboard.Helper.ThumbnailDetails plugindata = PluginHelper.CreateThumbnail(url);
                    _PluginData._ThumbnailDetails = plugindata;
                }

                ViewBag.plugin = _PluginData;
                //Dictionary<string, object> dict_TeamMember = new Dictionary<string, object>();
                List <Domain.Socioboard.Helper.PluginProfile> lstsb = new List <Domain.Socioboard.Helper.PluginProfile>();
                lstsb = SBUtils.GetProfilesForPlugin();
                return(View("RMain", lstsb));
            }
            return(View("Rlogin"));
        }
コード例 #2
0
        public static Domain.Socioboard.Helper.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.Helper.ThumbnailDetails _ThumbnailDetails = new Domain.Socioboard.Helper.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);
        }
コード例 #3
0
        public static Domain.Socioboard.Helper.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.Helper.ThumbnailDetails _ThumbnailDetails = new Domain.Socioboard.Helper.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;
        }