예제 #1
0
        void AccountDisplayPic_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            if (core.Http.Files["photo-file"].ContentLength == 0)
            {
                int vcrop = core.Functions.FormInt("vcrop", 0);

                if (LoggedInMember.UserInfo.CoverPhotoId > 0)
                {
                    GalleryItem coverItem = new GalleryItem(core, LoggedInMember.UserInfo.CoverPhotoId);
                    coverItem.CropPositionVertical = vcrop;
                    coverItem.Update();

                    SetRedirectUri(BuildUri());
                    core.Display.ShowMessage("Cover photo set", "You have successfully uploaded a new cover photo.");
                    return;
                }
            }
            else
            {
                string meSlug = "cover-photos";

                BoxSocial.Applications.Gallery.Gallery profileGallery;
                try
                {
                    profileGallery = new BoxSocial.Applications.Gallery.Gallery(core, LoggedInMember, meSlug);
                }
                catch (InvalidGalleryException)
                {
                    BoxSocial.Applications.Gallery.Gallery root = new BoxSocial.Applications.Gallery.Gallery(core, LoggedInMember);
                    profileGallery = BoxSocial.Applications.Gallery.Gallery.Create(core, LoggedInMember, root, "Cover Photos", ref meSlug, "All my uploaded cover photos");
                }

                if (profileGallery != null)
                {
                    string title = "";
                    string description = "";
                    string slug = "";

                    try
                    {
                        slug = core.Http.Files["photo-file"].FileName;
                    }
                    catch
                    {
                        DisplayGenericError();
                        return;
                    }

                    try
                    {
                        MemoryStream stream = new MemoryStream();
                        core.Http.Files["photo-file"].InputStream.CopyTo(stream);

                        db.BeginTransaction();

                        GalleryItem galleryItem = GalleryItem.Create(core, LoggedInMember, profileGallery, title, ref slug, core.Http.Files["photo-file"].FileName, core.Http.Files["photo-file"].ContentType, (ulong)core.Http.Files["photo-file"].ContentLength, description, 0, Classifications.Everyone, stream, false);

                        db.UpdateQuery(string.Format("UPDATE user_info SET user_cover = {0} WHERE user_id = {1}",
                            galleryItem.Id, LoggedInMember.UserId));

                        //db.CommitTransaction();
                        stream.Close();

                        SetRedirectUri(BuildUri());
                        core.Display.ShowMessage("Cover photo set", "You have successfully uploaded a new cover photo.");
                        return;
                    }
                    catch (GalleryItemTooLargeException)
                    {
                        SetError("The photo you have attempted to upload is too big, you can upload photos up to 1.2 MiB in size.");
                        return;
                    }
                    catch (GalleryQuotaExceededException)
                    {
                        SetError("You do not have enough quota to upload this photo. Try resizing the image before uploading or deleting images you no-longer need. Smaller images use less quota.");
                        return;
                    }
                    catch (InvalidGalleryItemTypeException)
                    {
                        SetError("You have tried to upload a file type that is not a picture. You are allowed to upload PNG and JPEG images.");
                        return;
                    }
                    catch (InvalidGalleryFileNameException)
                    {
                        core.Display.ShowMessage("Submission failed", "Submission failed, try uploading with a different file name.");
                        return;
                    }
                }
                else
                {
                    DisplayGenericError();
                    return;
                }
            }
        }
예제 #2
0
        public override bool ExecuteJob(Job job)
        {
            if (job.ItemId == 0)
            {
                return true;
            }

            switch (job.Function)
            {
                case "notifyGalleryComment":
                    Gallery.NotifyGalleryComment(core, job);
                    return true;
                case "notifyGalleryItemComment":
                    GalleryItem.NotifyGalleryItemComment(core, job);
                    return true;
                case "create_ultra":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.UltraExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Ultra || gi.ItemHeight > (int)PictureScale.Ultra)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.UltraPrefix, (int)PictureScale.Ultra, (int)PictureScale.Ultra))
                            {
                                gi.UltraExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_full":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.FullExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Full || gi.ItemHeight > (int)PictureScale.Full)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.FullPrefix, (int)PictureScale.Full, (int)PictureScale.Full))
                            {
                                gi.FullExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_display":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.DisplayExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Display || gi.ItemHeight > (int)PictureScale.Display)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.DisplayPrefix, (int)PictureScale.Display, (int)PictureScale.Display))
                            {
                                gi.DisplayExists = true;
                                gi.Update();
                            }
                        }
                        else
                        {
                            // This strips all uploaded images of EXIF data
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.DisplayPrefix, gi.ItemWidth, gi.ItemHeight))
                            {
                                gi.DisplayExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_mobile":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.MobileExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Mobile || gi.ItemHeight > (int)PictureScale.Mobile)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.MobilePrefix, (int)PictureScale.Mobile, (int)PictureScale.Mobile))
                            {
                                gi.MobileExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_thumb":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.ThumbnailExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Thumbnail || gi.ItemHeight > (int)PictureScale.Thumbnail)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.ThumbnailPrefix, (int)PictureScale.Thumbnail, (int)PictureScale.Thumbnail))
                            {
                                gi.ThumbnailExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_tiny":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TinyExists) return true;

                        if (gi.ItemWidth > (int)PictureScale.Tiny || gi.ItemHeight > (int)PictureScale.Tiny)
                        {
                            if (GalleryItem.CreateScaleWithRatioPreserved(core, gi, gi.StoragePath, GalleryItem.TinyPrefix, (int)PictureScale.Tiny, (int)PictureScale.Tiny))
                            {
                                gi.TinyExists = true;
                                gi.Update();
                            }
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_high":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TinyExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.HighPrefix, (int)PictureScale.High, (int)PictureScale.High))
                        {
                            gi.TinyExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_square":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.SquareExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.SquarePrefix, (int)PictureScale.Square, (int)PictureScale.Square))
                        {
                            gi.SquareExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_tile":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.TileExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.TilePrefix, (int)PictureScale.Tile, (int)PictureScale.Tile))
                        {
                            gi.TileExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
                case "create_icon":
                    try
                    {
                        GalleryItem gi = new GalleryItem(core, job.ItemId);

                        if (gi.IconExists) return true;

                        if (GalleryItem.CreateScaleWithSquareRatio(core, gi, gi.StoragePath, GalleryItem.IconPrefix, (int)PictureScale.Icon, (int)PictureScale.Icon))
                        {
                            gi.IconExists = true;
                            gi.Update();
                        }
                    }
                    catch (GalleryItemNotFoundException)
                    {
                        return true; // no big deal if this job fails
                    }
                    return true;
            }

            return false;
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void Show(object sender, ShowPPageEventArgs e)
        {
            e.Template.SetTemplate("Gallery", "viewphoto");

            char[] trimStartChars = { '.', '/' };

            try
            {
                GalleryItem galleryItem = new GalleryItem(e.Core, e.Page.Owner, e.Slug);
                Gallery gallery = null;

                if (galleryItem.parentId > 0)
                {
                    gallery = new Gallery(e.Core, galleryItem.parentId);
                }
                else
                {
                    gallery = new Gallery(e.Core, e.Page.Owner);
                }

                if (!gallery.Access.Can("VIEW_ITEMS"))
                {
                    e.Core.Functions.Generate403();
                    return;
                }

                if (gallery.Access.Can("EDIT_ITEMS"))
                {
                    e.Template.Parse("S_CAN_EDIT", "TRUE");
                }

                if (gallery.Access.Can("DELETE_ITEMS"))
                {
                    e.Template.Parse("S_CAN_DELETE", "TRUE");
                }

                /* pages */
                e.Core.Display.ParsePageList(e.Page.Owner, true);

                galleryItem.Viewed(e.Core.Session.LoggedInMember);
                ItemView.LogView(e.Core, galleryItem);

                /* check gallery item has width and height information saved */

                if (galleryItem.ItemWidth <= 0 || galleryItem.ItemHeight <= 0)
                {
                    Stream fs = e.Core.Storage.RetrieveFile(e.Core.Storage.PathCombine(e.Core.Settings.StorageBinUserFilesPrefix, "_storage"), galleryItem.StoragePath);
                    Image image = Image.FromStream(fs);
                    int width = image.Width;
                    int height = image.Height;

                    galleryItem.ItemWidth = width;
                    galleryItem.ItemHeight = height;
                    galleryItem.Update();
                }

                Size hdSize = galleryItem.GetSize(new Size(1920, 1080));

                e.Core.Meta.Add("og:site_name", e.Core.Settings.SiteTitle);
                e.Core.Meta.Add("twitter:card", "photo");
                if (!string.IsNullOrEmpty(e.Core.Settings.TwitterName))
                {
                    e.Core.Meta.Add("twitter:site", e.Core.Settings.TwitterName);
                }
                if (galleryItem.Owner is User && !string.IsNullOrEmpty(((User)galleryItem.Owner).UserInfo.TwitterUserName))
                {
                    e.Core.Meta.Add("twitter:creator", ((User)galleryItem.Owner).UserInfo.TwitterUserName);
                }
                e.Core.Meta.Add("twitter:image:src", e.Core.Hyperlink.StripSid(e.Core.Hyperlink.AppendCurrentSid(galleryItem.DisplayUri)));
                if (!string.IsNullOrEmpty(galleryItem.ItemTitle))
                {
                    e.Core.Meta.Add("twitter:title", galleryItem.ItemTitle);
                    e.Core.Meta.Add("og:title", galleryItem.ItemTitle);
                }
                else
                {
                    e.Core.Meta.Add("og:title", galleryItem.Path);
                }
                e.Core.Meta.Add("og:type", "boxsocialapp:photo");
                e.Core.Meta.Add("og:url", e.Core.Hyperlink.StripSid(e.Core.Hyperlink.AppendCurrentSid(galleryItem.Uri)));
                e.Core.Meta.Add("og:image", e.Core.Hyperlink.StripSid(e.Core.Hyperlink.AppendCurrentSid(galleryItem.DisplayUri)));

                e.Page.CanonicalUri = galleryItem.Uri;

                e.Template.Parse("PAGE_TITLE", galleryItem.ItemTitle);
                e.Template.Parse("PHOTO_TITLE", galleryItem.ItemTitle);
                e.Template.Parse("PHOTO_ID", galleryItem.ItemId.ToString());
                e.Core.Display.ParseBbcode("PHOTO_DESCRIPTION", e.Core.Bbcode.FromStatusCode(galleryItem.ItemAbstract));
                e.Template.Parse("HD_WIDTH", hdSize.Width);
                e.Template.Parse("HD_HEIGHT", hdSize.Height);
                e.Template.Parse("PHOTO_COMMENTS", e.Core.Functions.LargeIntegerToString(galleryItem.Comments));
                e.Template.Parse("U_MARK_DISPLAY_PIC", galleryItem.MakeDisplayPicUri);
                e.Template.Parse("U_MARK_GALLERY_COVER", galleryItem.SetGalleryCoverUri);
                e.Template.Parse("U_ROTATE_LEFT", galleryItem.RotateLeftUri);
                e.Template.Parse("U_ROTATE_RIGHT", galleryItem.RotateRightUri);
                e.Template.Parse("U_TAG", galleryItem.TagUri);

                e.Template.Parse("PHOTO_MOBILE", galleryItem.MobileUri);
                e.Template.Parse("PHOTO_DISPLAY", galleryItem.DisplayUri);
                e.Template.Parse("PHOTO_FULL", galleryItem.FullUri);
                e.Template.Parse("PHOTO_ULTRA", galleryItem.UltraUri);

                if (gallery.Access.Can("EDIT_ITEMS"))
                {
                    e.Template.Parse("U_EDIT", galleryItem.EditUri);
                }

                if (gallery.Access.Can("DELETE_ITEMS"))
                {
                    e.Template.Parse("U_DELETE", galleryItem.DeleteUri);
                }

                if (gallery.Access.Can("CREATE_ITEMS"))
                {
                    e.Template.Parse("U_UPLOAD_PHOTO", gallery.PhotoUploadUri);
                }

                if (gallery.Access.Can("DOWNLOAD_ORIGINAL"))
                {
                    e.Template.Parse("U_VIEW_FULL", galleryItem.OriginalUri);
                }

                switch (galleryItem.Classification)
                {
                    case Classifications.Everyone:
                        e.Template.Parse("PAGE_CLASSIFICATION", "Suitable for Everyone");
                        e.Template.Parse("I_PAGE_CLASSIFICATION", "rating_e.png");
                        break;
                    case Classifications.Mature:
                        e.Template.Parse("PAGE_CLASSIFICATION", "Suitable for Mature Audiences 15+");
                        e.Template.Parse("I_PAGE_CLASSIFICATION", "rating_15.png");
                        break;
                    case Classifications.Restricted:
                        e.Template.Parse("PAGE_CLASSIFICATION", "Retricted to Audiences 18+");
                        e.Template.Parse("I_PAGE_CLASSIFICATION", "rating_18.png");
                        break;
                }

                if (galleryItem.License != null)
                {
                    if (!string.IsNullOrEmpty(galleryItem.License.Title))
                    {
                        e.Template.Parse("PAGE_LICENSE", galleryItem.License.Title);
                    }
                    if (!string.IsNullOrEmpty(galleryItem.License.Icon))
                    {
                        e.Template.Parse("I_PAGE_LICENSE", galleryItem.License.Icon);
                    }
                    if (!string.IsNullOrEmpty(galleryItem.License.Link))
                    {
                        e.Template.Parse("U_PAGE_LICENSE", galleryItem.License.Link);
                    }
                }

                Display.RatingBlock(galleryItem.ItemRating, e.Template, galleryItem.ItemKey);

                e.Template.Parse("ID", galleryItem.ItemId.ToString());
                e.Template.Parse("TYPEID", galleryItem.ItemKey.TypeId.ToString());
                //template.Parse("U_EDIT", ZzUri.BuildPhotoEditUri((long)photoTable.Rows[0]["gallery_item_id"])));

                if (gallery.Access.IsPublic())
                {
                    e.Template.Parse("IS_PUBLIC", "TRUE");

                    if (galleryItem.Info.SharedTimes > 0)
                    {
                        e.Template.Parse("SHARES", string.Format(" {0:d}", galleryItem.Info.SharedTimes));
                    }
                }
                else
                {
                    e.Template.Parse("IS_PUBLIC", "FALSE");
                }

                if (gallery.Access.Can("COMMENT_ITEMS"))
                {
                    e.Template.Parse("CAN_COMMENT", "TRUE");
                }

                e.Core.Display.DisplayComments(e.Template, e.Page.Owner, galleryItem);

                string pageUri = string.Format("{0}gallery/{1}",
                    HttpUtility.HtmlEncode(e.Page.Owner.UriStub), e.Slug);
                e.Core.Display.ParsePagination("COMMENT_PAGINATION", pageUri, 10, galleryItem.Comments);

                List<string[]> breadCrumbParts = new List<string[]>();

                breadCrumbParts.Add(new string[] { "gallery", e.Core.Prose.GetString("GALLERY") });
                if (gallery.Parents != null)
                {
                    foreach (ParentTreeNode node in gallery.Parents.Nodes)
                    {
                        breadCrumbParts.Add(new string[] { node.ParentSlug, node.ParentTitle });
                    }
                }
                breadCrumbParts.Add(new string[] { gallery.Path, gallery.GalleryTitle });
                if (!string.IsNullOrEmpty(galleryItem.ItemTitle))
                {
                    breadCrumbParts.Add(new string[] { galleryItem.Path, galleryItem.ItemTitle });
                }
                else
                {
                    breadCrumbParts.Add(new string[] { galleryItem.Path, galleryItem.Path });
                }

                e.Page.Owner.ParseBreadCrumbs(breadCrumbParts);

                List<UserTag> tags = UserTag.GetTags(e.Core, galleryItem);

                if (tags.Count > 0)
                {
                    e.Template.Parse("HAS_USER_TAGS", "TRUE");
                }

                e.Template.Parse("TAG_COUNT", tags.Count.ToString());

                int i = 0;

                foreach (UserTag tag in tags)
                {
                    VariableCollection tagsVariableCollection = e.Template.CreateChild("user_tags");

                    tagsVariableCollection.Parse("INDEX", i.ToString());
                    tagsVariableCollection.Parse("TAG_ID", tag.TagId);
                    tagsVariableCollection.Parse("TAG_X", (tag.TagLocation.X / 1000 - 50).ToString());
                    tagsVariableCollection.Parse("TAG_Y", (tag.TagLocation.Y / 1000 - 50).ToString());
                    tagsVariableCollection.Parse("DISPLAY_NAME", tag.TaggedMember.DisplayName);
                    tagsVariableCollection.Parse("U_MEMBER", tag.TaggedMember.Uri);
                    tagsVariableCollection.Parse("TAG_USER_ID", tag.TaggedMember.Id.ToString());
                }

                if (galleryItem.NextItem != null)
                {
                    e.Template.Parse("U_NEXT_PHOTO", galleryItem.NextItem.Uri);
                }

                if (galleryItem.PreviousItem != null)
                {
                    e.Template.Parse("U_PREVIOUS_PHOTO", galleryItem.PreviousItem.Uri);
                }

                /*string path1 = TPage.GetStorageFilePath(galleryItem.StoragePath);
                string path2 = e.Core.Storage.RetrieveFilePath(string.Empty, galleryItem.StoragePath);
                string path3 = e.Core.Storage.RetrieveFilePath("_thumb", galleryItem.StoragePath);

                HttpContext.Current.Response.Write(path1 + "<br />" + path2 + "<br />" + path3);*/

            }
            catch (GalleryItemNotFoundException)
            {
                e.Core.Functions.Generate404();
                return;
            }
        }