예제 #1
0
        public override CmsDependency[] getDependencies()
        {
            List <CmsDependency> ret = new List <CmsDependency>();

            try
            {
                ret.Add(new CmsDatabaseTableDependency(@"
                CREATE TABLE  `userimagegallery` (
                  `PageId` int(10) unsigned NOT NULL,
                  `Identifier` int(10) unsigned NOT NULL,
                  `LangCode` varchar(5) NOT NULL,
                  `NumThumbsPerPage` int(10) NOT NULL,
                  `NumThumbsPerRow` int(10) NOT NULL,
                  `ThumbnailDisplayBoxWidth` int(10) NOT NULL,
                  `ThumbnailDisplayBoxHeight` int(10) NOT NULL,
                  `FullSizeDisplayBoxWidth` int(10) NOT NULL,
                  `FullSizeDisplayBoxHeight` int(10) NOT NULL,
                  `FullSizeLinkMode` varchar(255) NOT NULL,
                  `CaptionDisplayLocation` varchar(255) NOT NULL,
                  PRIMARY KEY (`PageId`,`Identifier`,`LangCode`)
                ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
            "));

                ret.AddRange(SWFUploadHelpers.SWFUploadDependencies);

                // -- writable directories
                ret.Add(CmsWritableDirectoryDependency.UnderAppPath("UserFiles/ImageGalleries"));

                // -- each placeholder directory should be writable.
                UserImageGalleryDb db = (new UserImageGalleryDb());
                UserImageGalleryPlaceholderData[] phs = db.getAllUserImageGalleryPlaceholderDatas();
                foreach (UserImageGalleryPlaceholderData ph in phs)
                {
                    CmsPage p = CmsContext.getPageById(ph.PageId);
                    if (p.ID >= 0)
                    {
                        string dir = ph.getImageStorageDirectory(p);
                        if (dir != String.Empty)
                        {
                            ret.Add(new CmsWritableDirectoryDependency(dir));
                            // -- check if the image gallery files on disk are in the database.
                            if (CmsLocalFileOnDisk.FetchAllFilesInDirectory(dir).Length > 0)
                            {
                                foreach (string fn in System.IO.Directory.GetFiles(dir))
                                {
                                    if (!fn.StartsWith(CmsLocalFileOnDisk.DeletedFileFilenamePrefix))
                                    {
                                        ret.Add(new CmsMessageDependency("The UserImageGallery directory '" + dir + "' has files, but are not in the database"));
                                        break;
                                    }
                                } // foreach
                            }
                        }
                    }
                }

                // -- REQUIRED config entries
                ret.Add(new CmsConfigItemDependency("UserImageGallery.PageXofYText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.PrevLinkText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.NextLinkText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.ReturnToGalleryText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.NoImageText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.ImageRemovedText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.SetCaptionButtonText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.RemoveImageButtonText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.SetCaptionButtonText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.RemoveImageButtonText"));
                ret.Add(new CmsConfigItemDependency("UserImageGallery.UploadImageButtonText"));
            }
            catch (Exception ex)
            {
                ret.Add(new CmsMessageDependency("Error gathering UserImageGallery dependencies: " + ex.Message));
            }

            return(ret.ToArray());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CmsContext.currentUserCanWriteToUserFilesOnDisk)
            {
                Response.StatusCode = 500;
                Response.Write("Authentication required - access denied");
                Response.End();
                return;
            }

            try
            {
                HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];

                string dir = "Image/";
                if (Request.QueryString["dir"] != null && Request.QueryString["dir"] != "")
                {
                    dir = Request.QueryString["dir"];
                }

                string baseDir = "~/UserFiles/";

                if (Request.QueryString["DMS"] != null && Request.QueryString["DMS"] == "1")
                {
                    baseDir = CmsConfig.getConfigValue("DMSFileStorageFolderUrl", "");
                    if (!baseDir.EndsWith("/"))
                    {
                        baseDir += "/";
                    }
                }

                string fullDir = System.Web.Hosting.HostingEnvironment.MapPath(baseDir + dir);

                if (!fullDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    fullDir += Path.DirectorySeparatorChar;
                }

                string fullFilename = fullDir + Path.GetFileName(jpeg_image_upload.FileName);

                jpeg_image_upload.SaveAs(fullFilename);

                CmsLocalFileOnDisk r = CmsLocalFileOnDisk.CreateFromFile(fullFilename);
                bool b = r.SaveToDatabase();
                if (b)
                {
                    Response.StatusCode = 200;
                    Response.Write(Path.GetFileName(fullFilename));
                    Response.End();
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            // If any kind of error occurs return a 500 Internal Server error
            Response.StatusCode = 500;
            Response.Write("An error occured");
            Response.End();
        }