public MediaShare AddCragYouTubeMovie(Guid cragID, string url, string title, string description)
        {
            MediaShare media = new MediaShare
            {
                MessageBoardID    = InsertNewMessageBoard(),
                ID                = Guid.NewGuid(),
                SubmittedByUserID = CurrentClimber.ID,
                Uri               = url,
                Name              = title,
                Description       = description,
                SubmittedDateTime = DateTime.Now,
                Type              = (int)MediaType.YouTubeVideo
            };

            return(new MediaShareDA().InsertCragMedia(media, cragID));
        }
        void Page_LoadComplete(object sender, EventArgs e)
        {
            DataTable allStats = MediaShare.GetStats();

            foreach (DataRow row in allStats.Rows)
            {
                string mediaRedirect;
                string shareRedirect;
                switch (row[6].ToString().Trim())
                {
                case "image":
                    mediaRedirect = "view?id=";
                    shareRedirect = "view?share=";
                    break;

                default:
                    mediaRedirect = "view?id=";
                    shareRedirect = "view?share=";
                    break;
                }
                var myRow = new TableRow();

                var titleCell = new TableCell();
                titleCell.Controls.Add(new LiteralControl(
                                           string.Format("<a href={0}>{1}</a>", mediaRedirect + row[0].ToString(), row[1].ToString())));

                myRow.Cells.Add(titleCell);

                var userCell = new TableCell();
                userCell.Controls.Add(new LiteralControl(
                                          string.Format("<a href={0}>{1}</a>", "manage_users?id=" + row[7].ToString(), row[3].ToString())));
                myRow.Cells.Add(userCell);

                var timesUsedCell = new TableCell();
                timesUsedCell.Controls.Add(new LiteralControl(
                                               string.Format("<a href={0}>{1}</a>", shareRedirect + row[5].ToString(), row[4].ToString())));
                myRow.Cells.Add(timesUsedCell);


                Table_Stats.Rows.Add(myRow);
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var tagParam     = Request.QueryString["tag"];
            var userTagParam = Request.QueryString["user"];
            var Search       = Request.QueryString["search"];

            Login();

            GetMedia(); //CheckPermissions() is dependent on this for CreatedByUserId

            NewMenu.LoggedInUser = myUser;
            NewMenu.HighlightButtonsForPage(PageIndex.Tag, "Edit");

            MediaTag OriginalTag = string.IsNullOrEmpty(tagParam) ? null : new MediaTag(Convert.ToInt32(tagParam));

            GetOriginalRedirect();

            CheckPermissions();

            string id = Request.QueryString["id"];

            if (!string.IsNullOrEmpty(id))
            {
                //REQUIRED TO VIEW POSTBACK
                form1.Action = Request.RawUrl;

                if (Request.QueryString["delete"] != null)
                {
                    DoDeleteMedia();

                    Response.Redirect(OriginalAlbumRedirect);
                }

                CheckForThumbnailUpload();

                PopulateTags();

                PopulateTagDropDowns();

                DisplayMediaAttributes();

                if (!IsPostBack)
                {
                    InputTitleTwo.Focus();
                }
            }
            else
            {
                Response.Redirect("home");
            }

            void Login()
            {
                myUser = Account.SecurePage(this, Data.DeviceType);

                NewMenu.SelectedPage = PageIndex.EditMedia;
                NewMenu.LoggedInUser = myUser;
                NewMenu.Share        = true;

                if (Request.QueryString["removetag"] == "true")
                {
                    MediaTagPair.Delete(new MediaId(Request.QueryString["id"]), Convert.ToInt32(Request.QueryString["tag"]));
                    if (Request.QueryString["tag"] == null)
                    {
                        Response.Redirect($"edit?id={Request.QueryString["id"]}");
                    }
                    else
                    {
                        Response.Redirect($"edit?id={Request.QueryString["id"]}&tag={Request.QueryString["tag"]}");
                    }
                }
                else if (Request.QueryString["removeusertag"] == "true")
                {
                    MediaUserPair.Delete(new MediaId(Request.QueryString["id"]), Convert.ToInt32(Request.QueryString["userid"]));
                    if (Request.QueryString["userid"] == null)
                    {
                        Response.Redirect($"edit?id={Request.QueryString["id"]}");
                    }
                    else
                    {
                        Response.Redirect($"edit?id={Request.QueryString["id"]}&userid={Request.QueryString["userid"]}");
                    }
                }
            }

            void GetMedia()
            {
                if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
                {
                    MyYoutubeVideo = ParsnipData.Media.Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    if (MyYoutubeVideo == null)
                    {
                        MyVideo = ParsnipData.Media.Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    }

                    if (MyYoutubeVideo == null && MyVideo == null)
                    {
                        MyImage = ParsnipData.Media.Image.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    }
                }

                if (MyYoutubeVideo != null)
                {
                    MyYoutubeVideo = Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    MediaShare myMediaShare = MyYoutubeVideo.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyYoutubeVideo.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    thumbnail.Src = MyYoutubeVideo.Compressed;
                    input_date_media_captured.Value = MyYoutubeVideo.DateTimeCaptured.ToString();
                    a_play_video.HRef    = string.Format("../../view?id={0}", MyYoutubeVideo.Id);
                    a_play_video.Visible = true;
                    Page.Title           = "Edit Youtube Video";
                }
                else if (MyVideo != null)
                {
                    MyVideo = Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    MediaShare myMediaShare = MyVideo.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyVideo.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    thumbnail.Src = MyVideo.Compressed;
                    input_date_media_captured.Value = MyVideo.DateTimeCaptured.ToString();
                    a_play_video.HRef    = string.Format("../../view?id={0}", MyVideo.Id);
                    a_play_video.Visible = true;
                    Page.Title           = "Edit Video";
                    if (MyVideo.Thumbnails.Count() > 0)
                    {
                        ThumbnailSelectorContainer.Visible = true;
                        foreach (var control in VideoThumbnailControl.GetVideoAsVideoThumbnailControls(MyVideo))
                        {
                            control.VideoThumbnailClick += new EventHandler(VideoThumbnail_ButtonClick);
                            ThumbnailSelector.Controls.Add(control);
                        }
                    }
                }
                else if (MyImage != null)
                {
                    myMediaShare = MyImage.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyImage.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    ImagePreview.ImageUrl           = MyImage.Compressed;
                    input_date_media_captured.Value = MyImage.DateTimeCaptured.ToString();
                    ImagePreviewContainer.HRef      = string.Format("../../view?id={0}", MyImage.Id);
                    ImagePreviewContainer.Visible   = true;
                    Page.Title = "Edit Image";
                }
                else
                {
                    Response.Redirect("myuploads");
                }
            }

            void PopulateTags()
            {
                Page httpHandler = (Page)HttpContext.Current.Handler;

                foreach (MediaTagPair mediaTagPair in MyMedia.MediaTagPairs)
                {
                    MediaTagPairControl mediaTagPairControl = (MediaTagPairControl)httpHandler.LoadControl("~/Custom_Controls/Media/MediaTagPairControl.ascx");
                    mediaTagPairControl.MyMedia = MyMedia;
                    mediaTagPairControl.MyPair  = mediaTagPair;
                    MediaTagContainer.Controls.Add(mediaTagPairControl);
                }
                foreach (MediaUserPair mediaUserPair in MyMedia.MediaUserPairs)
                {
                    MediaUserPairControl mediaUserPairControl = (MediaUserPairControl)httpHandler.LoadControl("~/Custom_Controls/Media/MediaUserPairControl.ascx");
                    mediaUserPairControl.MyMedia = MyMedia;
                    mediaUserPairControl.MyPair  = mediaUserPair;
                    UserTagContainer.Controls.Add(mediaUserPairControl);
                }
            }

            void GetOriginalRedirect()
            {
                if (OriginalTag == null && tagParam == null && userTagParam == null && MyMedia.AlbumId == default && MyMedia.MediaTagPairs.Count == default && !string.IsNullOrEmpty(OriginalAlbumRedirect))
                {
                    OriginalAlbumRedirect = "myuploads?focus=" + MyMedia.Id.ToString();
                }
                else if (!string.IsNullOrEmpty(Search))
                {
                    OriginalAlbumRedirect = $"search?text={Search}&focus={MyMedia.Id}";
                }
                else if (OriginalTag != null)
                {
                    switch (OriginalTag.Id)
                    {
                    case (int)Data.MediaTagIds.Photos:
                        OriginalAlbumRedirect = "photos?focus=" + MyMedia.Id.ToString();
                        break;

                    case (int)Data.MediaTagIds.Memes:
                        OriginalAlbumRedirect = "memes?focus=" + MyMedia.Id.ToString();
                        break;

                    case (int)Data.MediaTagIds.Krakow:
                        OriginalAlbumRedirect = "krakow?focus=" + MyMedia.Id.ToString();
                        break;

                    case (int)Data.MediaTagIds.Videos:
                        OriginalAlbumRedirect = "videos?focus=" + MyMedia.Id.ToString();
                        break;

                    case (int)Data.MediaTagIds.Portugal:
                        OriginalAlbumRedirect = "portugal?focus=" + MyMedia.Id.ToString();
                        break;

                    case (int)Data.MediaTagIds.Amsterdam:
                        OriginalAlbumRedirect = "amsterdam?focus=" + MyMedia.Id.ToString();
                        break;

                    case default(int):
                        Debug.WriteLine(string.Format("The album id {0} was not recognised!",
                                                      MyMedia.AlbumId));
                        OriginalAlbumRedirect = "home?error=nomediaalbum4";
                        break;

                    default:
                        OriginalAlbumRedirect = $"tag?id={OriginalTag.Id}&focus={MyMedia.Id}";
                        break;
                    }
                }
                else
                {
                    if (userTagParam != null)
                    {
                        OriginalAlbumRedirect = $"tag?user={userTagParam}&focus={MyMedia.Id}";
                    }
                    else if (tagParam != null)
                    {
                        OriginalAlbumRedirect = $"tag?id={tagParam}&focus={MyMedia.Id}";
                    }
                    else
                    {
                        OriginalAlbumRedirect = $"myuploads?focus={MyMedia.Id}";
                    }
                    //else if (MyMedia.MediaTagPairs.Count != default)
                    //    OriginalAlbumRedirect = $"tag?id={MyMedia.MediaTagPairs[0].MediaTag.Id}&focus={MyMedia.Id}";
                }
            }

            void PopulateTagDropDowns()
            {
                NewAlbumsDropDown.Items.Clear();
                NewAlbumsDropDown.Items.Add(new ListItem()
                {
                    Value = "0", Text = "(No tag selected)"
                });
                foreach (MediaTag tempMediaTag in MediaTag.GetAllTags())
                {
                    NewAlbumsDropDown.Items.Add(new ListItem()
                    {
                        Value = Convert.ToString(tempMediaTag.Id),
                        Text  = tempMediaTag.Name
                    });
                }

                DropDown_SelectUser.Items.Clear();
                foreach (User user in ParsnipData.Accounts.User.GetAllUsers())
                {
                    DropDown_SelectUser.Items.Add(new ListItem()
                    {
                        Value = Convert.ToString(user.Id),
                        Text  = user.FullName
                    });
                }
            }

            void DoDeleteMedia()
            {
                bool deleteSuccess;

                if (myUser.AccountType == "admin")
                {
                    MyMedia.Delete();
                    deleteSuccess = true;
                }
                else
                {
                    new LogEntry(Log.General)
                    {
                        Text = string.Format("{0} tried to delete media called \"{1}\", but {2} was not allowed " +
                                             "because {2} is not an admin", myUser.FullName, MyMedia.Title,
                                             myUser.SubjectiveGenderPronoun)
                    };
                    deleteSuccess = false;
                }
            }

            void CheckPermissions()
            {
                if (MyMedia.CreatedById.ToString() != myUser.Id.ToString())
                {
                    if (myUser.AccountType == "admin" || myUser.AccountType == "media")
                    {
                        string accountType = myUser.AccountType == "admin" ? "admin" : "approved media editor";
                        new LogEntry(Log.General)
                        {
                            Text = string.Format("{0} started editing media called \"{1}\". {2} does not own the " +
                                                 "media but {3} is allowed since {3} is an {4}", myUser.FullName, MyMedia.Title,
                                                 myUser.SubjectiveGenderPronoun.First().ToString().ToUpper() +
                                                 myUser.SubjectiveGenderPronoun.Substring(1), myUser.SubjectiveGenderPronoun, accountType)
                        };
                    }
                    else
                    {
                        new LogEntry(Log.General)
                        {
                            Text = string.Format("{0} attempted to edit media called \"{1}\" which {2} " +
                                                 "did not own. Access was DENIED!", myUser.FullName, MyMedia.Title, myUser.SubjectiveGenderPronoun)
                        };

                        Response.Redirect($"{OriginalAlbumRedirect}&alert=P100");
                    }
                }
            }

            void DisplayMediaAttributes()
            {
                if (MyMedia.Title != null && !string.IsNullOrEmpty(MyMedia.Title) && !string.IsNullOrWhiteSpace(MyMedia.Title))
                {
                    InputTitleTwo.Text = MyMedia.Title;
                }

                if (myUser.AccountType == "admin")
                {
                    btn_AdminDelete.Visible = true;
                }

                if (MyMedia.SearchTerms != null && !string.IsNullOrEmpty(MyMedia.SearchTerms) && !string.IsNullOrWhiteSpace(MyMedia.SearchTerms))
                {
                    SearchTerms_Input.Text = MyMedia.SearchTerms;
                }
            }

            void CheckForThumbnailUpload()
            {
                if (MyVideo != null)
                {
                    if (ThumbnailUpload.PostedFile != null && ThumbnailUpload.PostedFile.ContentLength > 0)
                    {
                        var thumbnail = new VideoThumbnail(MyVideo, myUser, ThumbnailUpload.PostedFile);
                        thumbnail.Insert();
                        Response.Redirect(Page.Request.Url.ToString(), true);
                    }

                    if (MyVideo.Thumbnails.Count > 0 || !MyVideo.Status.Equals(MediaStatus.Complete))
                    {
                        ThumbnailUploadControl.Visible = true;

                        if (MyVideo.Thumbnails.Count == 0)
                        {
                            ThumbnailsAreProcessing.Visible = true;
                        }
                    }
                }
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Data.DeviceType))
            {
                Response.Redirect($"get_device_info?url={Request.Url.PathAndQuery.Substring(1)}");
            }
            //If there is an access token, get the token & it's data.
            //If there is no access token, check that the user is logged in.
            var mediaShareId = Request.QueryString["share"];

            mediaView            = new MediaView();
            NewMenu.SelectedPage = PageIndex.View;
            NewMenu.Share        = true;

            if (Request.QueryString["id"] == null)
            {
                if (Request.QueryString["share"] == null)
                {
                    Response.Redirect("home");
                }
                else
                {
                    myMediaShare = new MediaShare(new MediaShareId(Request.QueryString["share"].ToString()));
                    shareId      = myMediaShare.Id;
                    try
                    {
                        myMediaShare.Select();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (myMediaShare.MediaId == null)
                    {
                        if (Request.QueryString["alert"] == null)
                        {
                            Response.Redirect($"view?share={mediaShareId}&alert=P101");
                        }
                    }

                    myUser = Account.PublicPage(this, myMediaShare, mediaView, Data.DeviceType);
                }
            }
            else
            {
                myUser = Account.SecurePage(this, Data.DeviceType, Request, mediaView);
                if (myUser != null)
                {
                    if (mediaView.Media != null)
                    {
                        if (mediaView.Media.MyMediaShare != null)
                        {
                            myMediaShare = mediaView.Media.MyMediaShare;

                            if (myMediaShare == null)
                            {
                                myMediaShare = new MediaShare(mediaView.Media.Id, myUser.Id);
                                myMediaShare.Insert();
                            }
                        }

                        mediaView.Media.View(myUser);
                    }
                }
            }

            if (mediaView.Media == null)
            {
                if (Request.QueryString["alert"] == null)
                {
                    Response.Redirect($"view?id={Request.QueryString["id"]}&alert=P101");
                }
                else
                {
                    MediaContainer.Visible    = false;
                    MediaTagContainer.Visible = false;
                }
            }
            else
            {
                viewCount.InnerText = $"{mediaView.Media.ViewCount} view(s)";
                ShareLink.Value     = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
            }

            NewMenu.LoggedInUser = myUser;
            NewMenu.HighlightButtonsForPage(PageIndex.Tag, "View");

            //Get the image which the user is trying to access, and display it on the screen.
            if (mediaView.Media == null || string.IsNullOrEmpty(mediaView.Media.Compressed))
            {
                //ShareLinkContainer.Visible = false;
                Button_ViewAlbum.Visible = false;
                if (ShareUserSuspendedError.Visible == false)
                {
                    UploadUserSuspendedError.Visible = true;
                }
            }
            else
            {
                List <ViewTagControl> ViewTagControls = new List <ViewTagControl>();
                Page httpHandler = (Page)HttpContext.Current.Handler;
                foreach (MediaTagPair mediaTagPair in mediaView.Media.MediaTagPairs)
                {
                    ViewTagControl mediaTagPairViewControl = (ViewTagControl)httpHandler.LoadControl("~/Custom_Controls/Media/ViewTagControl.ascx");
                    mediaTagPairViewControl.MyMedia   = mediaView.Media;
                    mediaTagPairViewControl.MyTagPair = mediaTagPair;
                    mediaTagPairViewControl.UpdateLink();
                    ViewTagControls.Add(mediaTagPairViewControl);
                }

                foreach (MediaUserPair mediaUserPair in mediaView.Media.MediaUserPairs)
                {
                    ViewTagControl mediaUserPairViewControl = (ViewTagControl)httpHandler.LoadControl("~/Custom_Controls/Media/ViewTagControl.ascx");
                    mediaUserPairViewControl.MyMedia    = mediaView.Media;
                    mediaUserPairViewControl.MyUserPair = mediaUserPair;
                    mediaUserPairViewControl.UpdateLink();
                    ViewTagControls.Add(mediaUserPairViewControl);
                }

                foreach (ViewTagControl control in ViewTagControls.OrderBy(x => x.Name))
                {
                    MediaTagContainer.Controls.Add(control);
                }

                if (mediaView.Media.AlbumId == 0)
                {
                    Button_ViewAlbum.Visible = false;
                }

                ImageTitle.InnerText = mediaView.Media.Title;
                Page.Title           = mediaView.Media.Title;

                if (mediaView.Media.Type == "image")
                {
                    ImagePreview.Src = mediaView.Media.Compressed;
                }

                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:title\" content=\"{0}\" />", mediaView.Media.Title)));
                //This will break youtube videos which have not had their thumbnail regenerated
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:image\" content=\"{0}\" />", mediaView.Media.Compressed.Contains("https://lh3.googleusercontent.com") ? mediaView.Media.Compressed : string.Format("{0}/{1}", Request.Url.GetLeftPart(UriPartial.Authority), mediaView.Media.Compressed))));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"og:type\" content=\"website\" />"));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:url\" content=\"{0}\" />", Request.Url.ToString())));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:description\" content=\"{0}\" />", mediaView.Media.Description)));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:alt\" content=\"{0}\" />", mediaView.Media.Alt)));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"fb:app_id\" content=\"521313871968697\" />"));

                if (Request.QueryString["share"] == null)
                {
                    Button_ViewAlbum.Visible = false;

                    MediaShare myMediaShare;


                    myMediaShare = mediaView.Media.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(mediaView.Media.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                }
            }

            if (mediaView.Video != null)
            {
                if (mediaView.Video.VideoData.XScale != default && mediaView.Video.VideoData.YScale != default && mediaView.Video.IsPortrait())
                {
                    video_container.Attributes.Remove("class");
                    video_container.Attributes.Add("class", "media-viewer-portrait");

                    TitleContainer.Attributes.Remove("class");
                    TitleContainer.Attributes.Add("class", "media-viewer-title-portrait background-lightest");
                    //TitleContainer.Attributes.Add("class", "background-lightest");
                }
            }

            if (mediaView.Image != null)
            {
                if (mediaView.Image.IsPortrait())
                {
                    ImagePreview.Attributes.Remove("class");
                    ImagePreview.Attributes.Add("class", "media-viewer-portrait");

                    //MediaContainer.Attributes.Remove("class");
                    //MediaContainer.Attributes.Add("class", "media-viewer-portrait");

                    TitleContainer.Attributes.Remove("class");
                    TitleContainer.Attributes.Add("class", "media-viewer-title-portrait background-lightest");
                    //TitleContainer.Attributes.Add("class", "background-lightest");
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //REQUIRED TO VIEW POSTBACK
            form1.Action = Request.RawUrl;

            if (Request.QueryString["id"] == null)
            {
                myUser = Account.SecurePage("edit_media", this, Data.DeviceType);
            }
            else if (Request.QueryString["tag"] == null)
            {
                myUser = Account.SecurePage($"edit_media?id={Request.QueryString["id"]}", this, Data.DeviceType);
            }
            else
            {
                myUser = Account.SecurePage($"edit_media?id={Request.QueryString["id"]}&tag={Request.QueryString["tag"]}", this, Data.DeviceType);
            }

            if (Request.QueryString["removetag"] == "true")
            {
                MediaTagPair.Delete(new MediaId(Request.QueryString["id"]), Convert.ToInt32(Request.QueryString["tag"]));
                if (Request.QueryString["tag"] == null)
                {
                    Response.Redirect($"edit_media?id={Request.QueryString["id"]}");
                }
                else
                {
                    Response.Redirect($"edit_media?id={Request.QueryString["id"]}&tag={Request.QueryString["tag"]}");
                }
            }
            else if (Request.QueryString["removeusertag"] == "true")
            {
                MediaUserPair.Delete(new MediaId(Request.QueryString["id"]), Convert.ToInt32(Request.QueryString["userid"]));
                if (Request.QueryString["userid"] == null)
                {
                    Response.Redirect($"edit_media?id={Request.QueryString["id"]}");
                }
                else
                {
                    Response.Redirect($"edit_media?id={Request.QueryString["id"]}&userid={Request.QueryString["userid"]}");
                }
            }

            if (!IsPostBack)
            {
                InputTitleTwo.Focus();
            }

            if (Request.QueryString["id"] != null)
            {
                string id = Request.QueryString["id"];

                MyYoutubeVideo = ParsnipData.Media.Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                if (MyYoutubeVideo == null)
                {
                    MyVideo = ParsnipData.Media.Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                }

                if (MyYoutubeVideo == null && MyVideo == null)
                {
                    MyImage = ParsnipData.Media.Image.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                }

                if (MyYoutubeVideo != null)
                {
                    MyYoutubeVideo = Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    MediaShare myMediaShare = MyYoutubeVideo.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyYoutubeVideo.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    input_date_media_captured.Value = MyYoutubeVideo.DateTimeCaptured.ToString();
                    youtube_video.Attributes.Add("data-id", MyYoutubeVideo.DataId);
                    youtube_video_container.Visible = true;
                    Page.Title = "Edit Youtube Video";
                }
                else if (MyVideo != null)
                {
                    MyVideo = Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                    MediaShare myMediaShare = MyVideo.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyVideo.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    thumbnail.Src = MyVideo.Compressed;
                    input_date_media_captured.Value = MyVideo.DateTimeCaptured.ToString();
                    a_play_video.HRef    = string.Format("../../view?id={0}", MyVideo.Id);
                    a_play_video.Visible = true;
                    Page.Title           = "Edit Video";
                }
                else if (MyImage != null)
                {
                    myMediaShare = MyImage.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyImage.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                    ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                                      myMediaShare.Id;
                    ImagePreview.ImageUrl           = MyImage.Compressed;
                    input_date_media_captured.Value = MyImage.DateTimeCaptured.ToString();
                    ImagePreview.Visible            = true;
                    Page.Title = "Edit Image";
                }
                else
                {
                    Response.Redirect("home");
                }

                Page httpHandler = (Page)HttpContext.Current.Handler;
                foreach (MediaTagPair mediaTagPair in MyMedia.MediaTagPairs)
                {
                    MediaTagPairControl mediaTagPairControl = (MediaTagPairControl)httpHandler.LoadControl("~/Custom_Controls/Media/MediaTagPairControl.ascx");
                    mediaTagPairControl.MyMedia = MyMedia;
                    mediaTagPairControl.MyPair  = mediaTagPair;
                    MediaTagContainer.Controls.Add(mediaTagPairControl);
                }

                var      tagParam     = Request.QueryString["tag"];
                var      userTagParam = Request.QueryString["user"];
                MediaTag OriginalTag  = string.IsNullOrEmpty(tagParam) ? null : new MediaTag(Convert.ToInt32(tagParam));

                if (OriginalTag == null && userTagParam == null)
                {
                    OriginalAlbumRedirect = "home?focus=" + MyMedia.Id.ToString();
                }
                else if (userTagParam == null)
                {
                    switch (OriginalTag.Id)
                    {
                    case default(int):
                        Debug.WriteLine(string.Format("The album id {0} was not recognised!",
                                                      MyMedia.AlbumId));
                        OriginalAlbumRedirect = "home?error=nomediaalbum4";
                        break;

                    default:
                        OriginalAlbumRedirect = $"tag?id={OriginalTag.Id}&focus={MyMedia.Id}";
                        break;
                    }
                }
                else
                {
                    OriginalAlbumRedirect = $"tag?user={userTagParam}&focus={MyMedia.Id}";
                }
                NewAlbumsDropDown.Items.Clear();
                if (myUser.AccountType == "admin")
                {
                    NewAlbumsDropDown.Items.Add(new ListItem()
                    {
                        Value = "0", Text = "(No tag selected)"
                    });
                }
                foreach (MediaTag tempMediaTag in MediaTag.GetAllTags())
                {
                    NewAlbumsDropDown.Items.Add(new ListItem()
                    {
                        Value = Convert.ToString(tempMediaTag.Id),
                        Text  = tempMediaTag.Name
                    });
                }

                var AlbumIds = MyMedia.SelectMediaTagIds();

                if (Request.QueryString["delete"] != null)
                {
                    bool deleteSuccess;

                    if (myUser.AccountType == "admin")
                    {
                        MyMedia.Delete();
                        deleteSuccess = true;
                    }
                    else
                    {
                        new LogEntry(Log.General)
                        {
                            text = string.Format("{0} tried to delete media called \"{1}\", but {2} was not allowed " +
                                                 "because {2} is not an admin", myUser.FullName, MyMedia.Title,
                                                 myUser.SubjectiveGenderPronoun)
                        };
                        deleteSuccess = false;
                    }

                    string Redirect;

                    switch (Convert.ToInt16(NewAlbumsDropDown.SelectedValue))
                    {
                    case default(int):
                        Debug.WriteLine("No album selected. Must be none! Redirecting to manage photos...");
                        Redirect = "home";
                        break;

                    default:
                        Redirect = $"tag?id={OriginalTag.Id}&focus={MyMedia.Id}";
                        break;
                    }
                    if (deleteSuccess)
                    {
                        new LogEntry(Log.General)
                        {
                            text = string.Format("{0} deleted media called \"{1}\"",
                                                 myUser.FullName, MyMedia.Title)
                        };
                        Response.Redirect(Redirect);
                    }
                    else
                    {
                        if (Redirect.Contains("?"))
                        {
                            Response.Redirect(Redirect + "&error=access");
                        }
                        else
                        {
                            Response.Redirect(Redirect + "?error=access");
                        }
                    }
                }

                if (MyMedia.Title != null && !string.IsNullOrEmpty(MyMedia.Title) &&
                    !string.IsNullOrWhiteSpace(MyMedia.Title))
                {
                    Debug.WriteLine("Updating title from media object: " + MyMedia.Title);
                    InputTitleTwo.Text = MyMedia.Title;
                }

                if (myUser.AccountType == "admin")
                {
                    DateCapturedDiv.Visible = true;
                    btn_AdminDelete.Visible = true;
                }

                if (MyMedia.CreatedById.ToString() != myUser.Id.ToString())
                {
                    if (myUser.AccountType == "admin" || myUser.AccountType == "media")
                    {
                        string accountType = myUser.AccountType == "admin" ? "admin" : "approved media editor";
                        new LogEntry(Log.General)
                        {
                            text = string.Format("{0} started editing media called \"{1}\". {2} does not own the " +
                                                 "media but {3} is allowed since {3} is an {4}", myUser.FullName, MyMedia.Title,
                                                 myUser.SubjectiveGenderPronoun.First().ToString().ToUpper() +
                                                 myUser.SubjectiveGenderPronoun.Substring(1), myUser.SubjectiveGenderPronoun, accountType)
                        };
                    }
                    else
                    {
                        new LogEntry(Log.General)
                        {
                            text = string.Format("{0} attempted to edit media called \"{1}\" which {2} " +
                                                 "did not own. Access was DENIED!", myUser.FullName, MyMedia.Title, myUser.SubjectiveGenderPronoun)
                        };

                        Response.Redirect(OriginalAlbumRedirect + "&error=0");
                    }
                }
                Debug.WriteLine("Setting media directory to: " + MyMedia.Compressed);
            }
            else
            {
                Response.Redirect("home");
            }
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //If there is an access token, get the token & it's data.
            //If there is no access token, check that the user is logged in.
            var accessToken = Request.QueryString["share"];



            if (Request.QueryString["id"] == null)
            {
                if (Request.QueryString["share"] == null)
                {
                    Response.Redirect("home");
                }
                else
                {
                    myUser       = ParsnipData.Accounts.User.LogIn();
                    myMediaShare = new MediaShare(new MediaShareId(Request.QueryString["share"].ToString()));
                    shareId      = myMediaShare.Id;
                    try
                    {
                        myMediaShare.Select();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (string.IsNullOrEmpty(myMediaShare.MediaId.ToString()))
                    {
                        new LogEntry(Log.Debug)
                        {
                            text = $"Someone tried to access share {myMediaShare.Id}. Access was denied because the person who created this link has been suspended."
                        };
                        ShareUserSuspendedError.Visible = true;
                    }
                    else
                    {
                        if (!IsPostBack)
                        {
                            myMediaShare.TimesUsed++;
                            myMediaShare.View(myUser);
                        }

                        User createdBy = ParsnipData.Accounts.User.Select(myMediaShare.UserId);

                        var myUserId = myUser == null ? default : myUser.Id;
                                       myImage        = ParsnipData.Media.Image.Select(myMediaShare.MediaId, myUserId);
                                       myVideo        = Video.Select(myMediaShare.MediaId, myUserId);
                                       myYoutubeVideo = Youtube.Select(myMediaShare.MediaId, myUserId);


                                       new LogEntry(Log.Debug)
                                       {
                                           text = string.Format("{0}'s link to {1} got another hit! Now up to {2}", createdBy.FullName, MyMedia.Title, myMediaShare.TimesUsed)
                                       };
                    }
                }
            }
            else
            {
                myUser = Account.SecurePage("view?id=" + Request.QueryString["id"], this, Data.DeviceType);

                myVideo        = Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                myYoutubeVideo = Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);

                myImage = ParsnipData.Media.Image.Select(new MediaId(Request.QueryString["id"].ToString()), myUser == null ? default : myUser.Id);


                if (MyMedia != null && MyMedia.MyMediaShare != null)
                {
                    myMediaShare = MyMedia.MyMediaShare;

                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyMedia.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                }
            }

            ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                              myMediaShare.Id;



            //Get the image which the user is trying to access, and display it on the screen.
            if (MyMedia == null || string.IsNullOrEmpty(MyMedia.Compressed))
            {
                //ShareLinkContainer.Visible = false;
                if (ShareUserSuspendedError.Visible == false)
                {
                    UploadUserSuspendedError.Visible = true;
                }
            }
            else
            {
                ImageTitle.InnerText = MyMedia.Title;
                Page.Title           = MyMedia.Title;

                if (MyMedia.Type == "image")
                {
                    ImagePreview.Src = MyMedia.Compressed;
                }

                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:title\" content=\"{0}\" />", MyMedia.Title)));
                //This will break youtube videos which have not had their thumbnail regenerated
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:image\" content=\"{0}\" />", MyMedia.Compressed.Contains("https://lh3.googleusercontent.com") ? MyMedia.Compressed : string.Format("{0}/{1}", Request.Url.GetLeftPart(UriPartial.Authority), MyMedia.Compressed))));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"og:type\" content=\"website\" />"));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:url\" content=\"{0}\" />", Request.Url.ToString())));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:description\" content=\"{0}\" />", MyMedia.Description)));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:alt\" content=\"{0}\" />", MyMedia.Alt)));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"fb:app_id\" content=\"521313871968697\" />"));

                if (Request.QueryString["share"] == null)
                {
                    MediaShare myMediaShare;


                    myMediaShare = MyMedia.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyMedia.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                }
            }
        }