示例#1
0
 protected void LinkButton3_Click(object sender, EventArgs e)
 {
     _data = YouTubeWidgetData.LoadFromSettings(WidgetHost.GetHost(this).WidgetInfo.Settings);
     _data.YouTubeFeedCount--;
     WidgetHost.GetHost(this).Save(_data.ToXml());
     MainView();
 }
示例#2
0
    protected void MainView()
    {
        try
        {
            _data = YouTubeWidgetData.LoadFromSettings(_host.WidgetInfo.Settings);
            if (!_data.YouTubeFeedURL.Equals(""))
            {
                List<YouTubeWidgetRepeaterData> dataItems = new List<YouTubeWidgetRepeaterData>();
                XmlDocument xmldoc = new XmlDocument();
                int count = 0;

                lblData.Text = @"<style>.YouTube img{max-width:100%;} .YouTube embed{max-width:100%;}</style>";
                WebRequest request;
                if (_data.YouTubeFeedTitle == "Search") //search URL already has parameter using ? so &max-result has to be used.
                {
                    request = WebRequest.Create(_data.YouTubeFeedURL + @"&max-results=" + _data.YouTubeFeedCount.ToString());
                }
                else
                {
                    request = WebRequest.Create(_data.YouTubeFeedURL + @"?max-results=" + _data.YouTubeFeedCount.ToString());
                }

                _host.Title = "YouTube : " + _data.YouTubeFeedTitle;
                request.Timeout = 5000;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream resStream = response.GetResponseStream();
                xmldoc.Load(resStream);
                XmlNode root = xmldoc.FirstChild;
                while (root.LocalName != "feed")
                {
                    root = root.NextSibling;
                }
                XmlNodeList feedNodes = root.ChildNodes;
                foreach (XmlNode tempNode in feedNodes)
                {
                    if (tempNode.Name.Equals("entry"))
                    {
                        YouTubeWidgetRepeaterData temp = new YouTubeWidgetRepeaterData();
                        XmlNodeList entryNodes = tempNode.ChildNodes;
                        foreach (XmlNode entryItem in entryNodes)
                        {
                            if (entryItem.Name.Equals("content"))
                            {
                                string contentFeed = entryItem.InnerText;

                                // truncate the feed by x number of words
                                string[] truncateTheFeed = contentFeed.Split(' ');
                                string truncatedContentFeed = "";
                                int x = 0;

                                foreach (string s in truncateTheFeed)
                                {
                                    if (x < 20)
                                    {
                                        truncatedContentFeed += " " + s;
                                        x++;
                                    }
                                }

                                //then shorten any URLs found in the feed
                                string pattern = "c";

                                if (Regex.IsMatch(truncatedContentFeed, pattern))
                                {
                                    foreach (Match match in Regex.Matches(truncatedContentFeed, pattern))
                                    {
                                        if (match.Length > 20)
                                        {
                                            string newmatch = "<a href=\"" + match + "\">" + match.ToString().Substring(0, 20) + "...</a>";
                                            truncatedContentFeed = truncatedContentFeed.Replace(match.ToString(), newmatch);
                                        }
                                    }
                                }

                                temp.content = truncatedContentFeed + "...";
                            }
                            else if (entryItem.Name.Equals("summary"))
                            {
                                temp.summary = entryItem.InnerText;
                            }
                            else if (entryItem.Name.Equals("title"))
                            {
                                temp.contentTitle = entryItem.InnerText;
                            }
                            else if (entryItem.Name.Equals("media:group"))
                            {
                                XmlNodeList mediaNodes = entryItem.ChildNodes;
                                bool foundMediaSrc = false;
                                foreach (XmlNode media in mediaNodes)
                                {
                                    if (media.Name.Equals("media:content") && !foundMediaSrc)
                                    {
                                        XmlAttributeCollection attrs = media.Attributes;
                                        string tempSrc = "";
                                        foreach (XmlAttribute attr in attrs)
                                        {
                                            if (attr.Name.Equals("url"))
                                            {
                                                tempSrc = attr.Value;
                                            }
                                            else if (attr.Name.Equals("type") && attr.Value.Equals("application/x-shockwave-flash"))
                                            {
                                                foundMediaSrc = true;
                                            }
                                        }
                                        if (foundMediaSrc)
                                        {
                                            temp.mediaSrc = tempSrc;
                                        }
                                    }
                                }
                            }
                            else if (entryItem.Name.Equals("link"))
                            {
                                XmlAttributeCollection atts = entryItem.Attributes;
                                string tempUrl = "";
                                bool isCorrectUrl = false;
                                foreach (XmlAttribute att in atts)
                                {
                                    if (att.Name.Equals("href"))
                                    {
                                        tempUrl = att.Value;
                                    }
                                    if (att.Name.Equals("rel") && att.Value.Equals("alternate"))
                                    {
                                        isCorrectUrl = true;
                                    }
                                }
                                if (isCorrectUrl)
                                {
                                    temp.url = tempUrl;
                                }
                            }
                        }
                        if (temp.content == string.Empty)
                        {
                            temp.content = temp.summary;
                        }
                        if (!temp.mediaSrc.Equals(""))
                        {
                            temp.content += @"<object id=""youtube" + _host.WidgetInfo.ID.ToString() + @"widget" + count.ToString() + @""" classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"" width=""100%"" id=""movie"" align=""""><param name=""movie"" value=""" + temp.mediaSrc + @".swf""><embed quality=""high"" width=""100%"" name=""movie"" align="""" type=""application/x-shockwave-flash"" src=""" + temp.mediaSrc + @".swf"" plug inspage=""http://www.macromedia.com/go/getflashplayer""></object>";
                        }
                        temp.hostid = _host.WidgetInfo.ID.ToString();
                        temp.count = count.ToString();
                        dataItems.Add(temp);
                        count++;
                    }
                }
                Repeater1.DataSource = dataItems.ToArray();
                Repeater1.DataBind();
                Repeater1.Visible = true;
                if (_data.YouTubeFeedCount <= 1)
                {
                    LinkButton3.Visible = false;
                }
                else
                {
                    LinkButton3.Visible = true;
                }
                LinkButton2.Visible = true;
            }
            else
            {
                lblData.Text = "No YouTube Feed Selected";
                LinkButton2.Visible = false;
                LinkButton3.Visible = false;
            }
        }
        catch
        {
            lblData.Text = "YouTube Feed Error";
            Repeater1.Visible = false;
        }

        if (_data.YouTubeFeedCount <= 1)
        {
            LinkButton3.Visible = false;
        }
        ViewSet.SetActiveView(View);
    }
示例#3
0
    public static YouTubeWidgetData LoadFromSettings(string settings)
    {
        XmlSerializer xmlSerializer = new XmlSerializer(typeof(YouTubeWidgetData));
        YouTubeWidgetData retVal;
        byte[] data = ASCIIEncoding.Default.GetBytes(settings);
        using (MemoryStream memStream = new MemoryStream(data))
        {
            try
            {
                retVal = (YouTubeWidgetData)xmlSerializer.Deserialize(memStream);
            }
            catch
            {
                retVal = new YouTubeWidgetData();
            }
        }

        return retVal;
    }
示例#4
0
    protected void Repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            GenerateFeedList();
            _data = YouTubeWidgetData.LoadFromSettings(WidgetHost.GetHost(this).WidgetInfo.Settings);
            _data.YouTubeFeedURL = feeds[e.Item.ItemIndex].FeedUrl;
            _data.YouTubeFeedTitle = feeds[e.Item.ItemIndex].FeedName;

            WidgetHost.GetHost(this).Save(_data.ToXml());
            MainView();
        }
        catch
        {
            ViewSet.SetActiveView(View);
        }
    }