protected override void DoRender(HtmlTextWriter output)
        {
            Database      db      = Sitecore.Context.Database;
            StringBuilder sbOut   = new StringBuilder();
            StringBuilder sbError = new StringBuilder();

            //get the player
            long playerid = -1;

            //check to see if the guid is there
            if (long.TryParse(this.Attributes["player"], out playerid))
            {
                //get player obj
                PlayerItem p = PlayerLibraryItem.GetPlayer(playerid);
                if (p != null)
                {
                    //parse wmode
                    WMode wmode = WMode.Window;
                    try {
                        wmode = (WMode)Enum.Parse(wmode.GetType(), this.Attributes["wmode"], true);
                    }catch {}

                    //get background color
                    string bgcolor = this.Attributes["bgcolor"];
                    bgcolor = (bgcolor == "") ? "#ffffff" : bgcolor;

                    //parse autostart
                    bool autostart = false;
                    try {
                        bool.Parse(this.Attributes["autostart"]);
                    }catch {}

                    //determine which embed code to display
                    if (p.PlaylistType.Equals(PlayerPlaylistType.None))
                    {
                        //get the video id
                        long videoid = -1;
                        if (long.TryParse(this.Attributes["video"], out videoid))
                        {
                            //try parse the id and get the item
                            VideoItem v = VideoLibraryItem.GetVideo(videoid);
                            if (v != null)
                            {
                                sbOut.Append(p.GetEmbedCode(v, bgcolor, autostart, wmode));
                            }
                        }
                    }
                    else if (p.PlaylistType.Equals(PlayerPlaylistType.VideoList))
                    {
                        long videolist = -1;
                        if (long.TryParse(this.Attributes["videolist"], out videolist))
                        {
                            sbOut.Append(p.GetEmbedCode(videolist, bgcolor, autostart, wmode));
                        }
                    }
                    else if (p.PlaylistType.Equals(PlayerPlaylistType.ComboBox) || p.PlaylistType.Equals(PlayerPlaylistType.Tabbed))
                    {
                        //get both the lists and build a string list
                        string        tabs  = this.Attributes["playlisttabs"];
                        string        combo = this.Attributes["playlistcombo"];
                        List <string> t     = tabs.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        t.AddRange(combo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList());

                        //convert to a list of long
                        List <long> playlists = new List <long>();
                        foreach (string s in t)
                        {
                            long temp = -1;
                            if (long.TryParse(s, out temp))
                            {
                                playlists.Add(temp);
                            }
                        }

                        //get the embed code
                        sbOut.Append(p.GetEmbedCode(playlists, bgcolor, autostart, wmode));
                    }

                    //if nothing then just get embed for player with nothing
                    if (sbOut.Length.Equals(0))
                    {
                        sbOut.Append(p.GetEmbedCode(bgcolor, autostart, wmode));
                    }
                }
                else
                {
                    sbError.AppendLine("Player doesn't exist in Sitecore.");
                }
            }
            else
            {
                sbError.AppendLine("Player value is not a long.");
            }
            //determine if it's an error or not
            if (sbError.Length > 0)
            {
                output.WriteLine("<div style=\"display:none;\">" + sbError.ToString() + "</div>");
            }
            else
            {
                output.WriteLine(sbOut.ToString());
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);

            masterDB = Sitecore.Client.ContentDatabase;

            if (!Context.ClientPage.IsEvent)
            {
                this.Mode = WebUtil.GetQueryString("mo");

                VideoDataContext.GetFromQueryString();
                PlayerDataContext.GetFromQueryString();
                PlaylistDataContext.GetFromQueryString();

                //populate video from querystring
                long vidID = -1;
                if (long.TryParse(WebUtil.GetQueryString("video"), out vidID))
                {
                    VideoItem v = VideoLibraryItem.GetVideo(vidID, masterDB);
                    if (v != null)
                    {
                        VideoDataContext.Folder = v.videoItem.ID.ToString();
                    }
                }

                //populate player from querystring
                long playID = -1;
                if (long.TryParse(WebUtil.GetQueryString("player"), out playID))
                {
                    PlayerItem p = PlayerLibraryItem.GetPlayer(playID, masterDB);
                    if (p != null)
                    {
                        PlayerDataContext.Folder = p.playerItem.ID.ToString();
                    }
                }

                //populate playlists from querystring
                List <string> listIDs = WebUtil.GetQueryString("playlisttabs").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                listIDs.AddRange(WebUtil.GetQueryString("playlistcombo").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList());
                listIDs.Add(WebUtil.GetQueryString("videolist"));
                foreach (string listID in listIDs)
                {
                    long pID = -1;
                    if (long.TryParse(listID, out pID))
                    {
                        //set the folder so it's opened
                        PlaylistItem pl = PlaylistLibraryItem.GetPlaylist(pID, masterDB);
                        if (pl != null)
                        {
                            PlaylistDataContext.Folder = pl.playlistItem.ID.ToString();
                            //set selected items
                            PlaylistTreeview.SelectedIDs.Add(listID);
                        }
                    }
                }

                //setup the drop list of wmode
                Item   wmodeRoot = masterDB.Items[PlayerDataContext.Root + "/Settings/WMode"];
                string wmode     = WebUtil.GetQueryString("wmode");
                if (wmodeRoot != null)
                {
                    foreach (Item wmodeItem in wmodeRoot.Children)
                    {
                        ListItem listitem = new ListItem();
                        listitem.Header   = wmodeItem.Name;
                        listitem.Value    = wmodeItem.ID.ToString();
                        listitem.ID       = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("I");
                        listitem.Selected = (wmodeItem.DisplayName.ToLower().Equals(wmode.ToLower())) ? true : false;
                        WMode.Controls.Add(listitem);
                    }
                }

                //get and set the autostart
                string autostart = WebUtil.GetQueryString("autostart");
                try {
                    chkAutoStart.Checked = (autostart == "") ? false : bool.Parse(autostart);
                } catch { }

                //get and set the bgcolor
                string bgcolor = HttpUtility.UrlDecode(WebUtil.GetQueryString("bgcolor"));
                try {
                    txtBGColor.Value = (bgcolor == "") ? "#ffffff" : bgcolor;
                } catch { txtBGColor.Value = "#ffffff"; }
            }
        }
        protected override void DoRender(HtmlTextWriter output)
        {
            Database      db      = Sitecore.Context.Database;
            StringBuilder sbOut   = new StringBuilder();
            StringBuilder sbError = new StringBuilder();

            //get the player
            long playerid = -1;

            //check to see if the guid is there
            if (long.TryParse(this.Attributes["player"], out playerid))
            {
                //get player obj
                PlayerItem p = PlayerLibraryItem.GetPlayer(playerid);
                if (p != null)
                {
                    //parse wmode
                    WMode wmode = WMode.Window;
                    try {
                        wmode = (WMode)Enum.Parse(wmode.GetType(), this.Attributes["wmode"], true);
                    }catch {}

                    //get background color
                    string bgcolor = this.Attributes["bgcolor"];
                    bgcolor = (string.IsNullOrEmpty(bgcolor)) ? "#ffffff" : bgcolor;
                    if (!bgcolor.StartsWith("#"))
                    {
                        bgcolor = "#" + bgcolor;
                    }

                    string oparams = this.Attributes["oparams"];
                    Dictionary <string, string> objectParams = new Dictionary <string, string>();
                    if (!string.IsNullOrEmpty(oparams))
                    {
                        string[] keys = oparams.Split(',');
                        foreach (string k in keys)
                        {
                            string[] pair = k.Split('=');
                            if (pair.Length > 0)
                            {
                                objectParams.Add(pair[0], pair[1]);
                            }
                        }
                    }

                    //parse autostart
                    bool autostart = false;
                    try {
                        autostart = (this.Attributes["autostart"].Equals("true")) ? true : false;
                    }catch {}

                    //determine which embed code to display
                    if (p.PlaylistType.Equals(PlayerPlaylistType.None))
                    {
                        //get the video id
                        long videoid = -1;
                        if (long.TryParse(this.Attributes["video"], out videoid))
                        {
                            //try parse the id and get the item
                            VideoItem v = VideoLibraryItem.GetVideo(videoid);
                            if (v != null)
                            {
                                sbOut.Append(p.GetEmbedCode(v, bgcolor, autostart, wmode));
                            }
                        }
                    }
                    else if (p.PlaylistType.Equals(PlayerPlaylistType.VideoList))
                    {
                        long videolist = -1;
                        if (long.TryParse(this.Attributes["videolist"], out videolist))
                        {
                            sbOut.Append(p.GetEmbedCode(videolist, bgcolor, autostart, wmode));
                        }
                    }
                    else if (p.PlaylistType.Equals(PlayerPlaylistType.ComboBox) || p.PlaylistType.Equals(PlayerPlaylistType.Tabbed))
                    {
                        List <string> t = new List <string>();
                        //get both the lists and build a string list
                        if (p.PlaylistType.Equals(PlayerPlaylistType.ComboBox))
                        {
                            string combo = (this.Attributes["playlistcombo"] != null) ? this.Attributes["playlistcombo"] : "";
                            t.AddRange(combo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                        }
                        else if (p.PlaylistType.Equals(PlayerPlaylistType.Tabbed))
                        {
                            string tabs = (this.Attributes["playlisttabs"] != null) ? this.Attributes["playlisttabs"] : "";
                            t.AddRange(tabs.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                        }
                        //convert to a list of long
                        List <long> playlists = new List <long>();
                        foreach (string s in t)
                        {
                            long temp = -1;
                            if (long.TryParse(s, out temp))
                            {
                                playlists.Add(temp);
                            }
                        }
                        //get the embed code
                        sbOut.Append(p.GetEmbedCode(playlists, bgcolor, autostart, wmode, PlayerExtensions.CreateEmbedID(), objectParams));
                    }

                    //Notify the user
                    if (sbOut.Length < 1)
                    {
                        sbError.AppendLine("Player playlist type wasn't selected.");
                    }
                }
                else
                {
                    sbError.AppendLine("Player doesn't exist in Sitecore.");
                }
            }
            else
            {
                sbError.AppendLine("Player value is not a long.");
            }
            //determine if it's an error or not
            if (sbError.Length > 0)
            {
                output.WriteLine("<div style=\"display:none;\">" + sbError.ToString() + "</div>");
            }
            else
            {
                output.WriteLine(sbOut.ToString());
            }
        }