示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (moduleId > -1)
            {
                if (itemId > -1)
                {
                    GalleryImage galleryImage = new GalleryImage(moduleId, itemId);
                    if (galleryImage.ModuleId != moduleId)
                    {
                        SiteUtils.RedirectToAccessDeniedPage(this);
                        return;
                    }

                    galleryImage.ContentChanged += new ContentChangedEventHandler(galleryImage_ContentChanged);

                    GalleryHelper.DeleteImages(galleryImage, fileSystem, imageFolderPath);
                    galleryImage.Delete();
                    CurrentPage.UpdateLastModifiedTime();
                    CacheHelper.ClearModuleCache(moduleId);
                    SiteUtils.QueueIndexing();
                }
            }

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
示例#2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            GalleryImage galleryImage;

            if (moduleId > -1)
            {
                if (itemId > -1)
                {
                    galleryImage = new GalleryImage(moduleId, itemId);
                }
                else
                {
                    galleryImage = new GalleryImage(moduleId);
                }

                if (galleryImage.ModuleId != moduleId)
                {
                    SiteUtils.RedirectToAccessDeniedPage(this);
                    return;
                }

                Module module = GetModule(moduleId, Gallery.FeatureGuid);
                galleryImage.ModuleGuid = module.ModuleGuid;

                galleryImage.ContentChanged += new ContentChangedEventHandler(galleryImage_ContentChanged);

                int displayOrder;
                if (!Int32.TryParse(txtDisplayOrder.Text, out displayOrder))
                {
                    displayOrder = -1;
                }

                if (displayOrder > -1)
                {
                    galleryImage.DisplayOrder = displayOrder;
                }

                galleryImage.WebImageHeight  = config.WebSizeHeight;
                galleryImage.WebImageWidth   = config.WebSizeWidth;
                galleryImage.ThumbNailHeight = config.ThumbnailHeight;
                galleryImage.ThumbNailWidth  = config.ThumbnailWidth;
                galleryImage.Description     = edDescription.Text;
                galleryImage.Caption         = txtCaption.Text;
                galleryImage.UploadUser      = Context.User.Identity.Name;
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                if (siteUser != null)
                {
                    galleryImage.UserGuid = siteUser.UserGuid;
                }

                // as long as javascript is available this code should never execute
                // because the standard file input ir replaced by javascript and the file upload happens
                // at the service url /ImageGallery/upload.ashx
                // this is fallback implementation

                if (uploader.HasFile)
                {
                    string ext = Path.GetExtension(uploader.FileName);
                    if (!SiteUtils.IsAllowedUploadBrowseFile(ext, ".jpg|.gif|.png|.jpeg"))
                    {
                        lblMessage.Text = GalleryResources.InvalidFile;

                        return;
                    }

                    string newFileName  = Path.GetFileName(uploader.FileName).ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                    string newImagePath = VirtualPathUtility.Combine(fullSizeImageFolderPath, newFileName);
                    if (galleryImage.ImageFile == newFileName)
                    {
                        // an existing gallery image delete the old one
                        fileSystem.DeleteFile(newImagePath);
                    }
                    else
                    {
                        // this is a new galleryImage instance, make sure we don't use the same file name as any other instance
                        int i = 1;
                        while (fileSystem.FileExists(VirtualPathUtility.Combine(fullSizeImageFolderPath, newFileName)))
                        {
                            newFileName = i.ToInvariantString() + newFileName;
                            i          += 1;
                        }
                    }
                    newImagePath = VirtualPathUtility.Combine(fullSizeImageFolderPath, newFileName);

                    if (galleryImage.ItemId > -1)
                    {
                        //updating with a new image so delete the previous version
                        GalleryHelper.DeleteImages(galleryImage, fileSystem, imageFolderPath);
                    }


                    //using (Stream s = flImage.FileContent)
                    //{
                    //    fileSystem.SaveFile(newImagePath, s, flImage.ContentType, true);
                    //}
                    using (Stream s = uploader.FileContent)
                    {
                        fileSystem.SaveFile(newImagePath, s, IOHelper.GetMimeType(Path.GetExtension(ext).ToLower()), true);
                    }



                    galleryImage.ImageFile     = newFileName;
                    galleryImage.WebImageFile  = newFileName;
                    galleryImage.ThumbnailFile = newFileName;
                    galleryImage.Save();
                    GalleryHelper.ProcessImage(galleryImage, fileSystem, imageFolderPath, uploader.FileName, config.ResizeBackgroundColor);

                    CurrentPage.UpdateLastModifiedTime();
                    CacheHelper.ClearModuleCache(moduleId);

                    SiteUtils.QueueIndexing();
                    if (hdnReturnUrl.Value.Length > 0)
                    {
                        WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                        return;
                    }
                }
                else // not hasfile
                {       //updating a previously uploaded image
                    if (itemId > -1)
                    {
                        if (galleryImage.Save())
                        {
                            CurrentPage.UpdateLastModifiedTime();
                            CacheHelper.ClearModuleCache(moduleId);
                            SiteUtils.QueueIndexing();
                            if (newItem)
                            {
                                string thisUrl = SiteRoot + "/ImageGallery/EditImage.aspx?pageid="
                                                 + pageId.ToInvariantString()
                                                 + "&mid=" + moduleId.ToInvariantString()
                                                 + "&ItemID=" + galleryImage.ItemId.ToInvariantString();

                                WebUtils.SetupRedirect(this, thisUrl);
                                return;
                            }
                            else
                            {
                                if (hdnReturnUrl.Value.Length > 0)
                                {
                                    WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                                    return;
                                }

                                WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                            }
                        }
                    }
                }
            }
        }