protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);

            config = new FolderGalleryConfiguration(Settings);

            string pathToGallery = string.Empty;

            if (config.GalleryRootFolder.Length > 0)
            {
                pathToGallery = config.GalleryRootFolder;
            }
            else
            {
                pathToGallery = GetDefaultGalleryPath();
                if (pathToGallery.Length > 0)
                {
                    CreateDefaultFolderSetting(pathToGallery);
                }
            }

            //if (pathToGallery.Length == 0)
            //{
            //    pathToGallery = GetDefaultGalleryPath();
            //    if (pathToGallery.Length > 0) CreateDefaultFolderSetting(pathToGallery);
            //}

            try
            {
                if (!Directory.Exists(Server.MapPath(pathToGallery)))
                {
                    //pathToGallery = GetDefaultGalleryPath();
                    Directory.CreateDirectory(Server.MapPath(pathToGallery));
                }
            }
            catch (IOException ex)
            {
                log.Error(ex);
            }
            catch (HttpException ex)
            {
                log.Error(ex);
                //thrown at Server.MapPath if the path is not a valid virtual path
                pathToGallery = GetDefaultGalleryPath();
            }

            ShowPermaLinksSetting  = config.ShowPermaLinks;
            ShowMetaDetailsSetting = config.ShowMetaDetails;



            if (Page is mojoBasePage)
            {
                basePage          = Page as mojoBasePage;
                useMobileTemplate = basePage.UseMobileSkin;
            }

            if (useMobileTemplate)
            {
                this.Album1.Visible         = false;
                this.Album2.Visible         = true;
                this.Album2.GalleryRootPath = pathToGallery;
                this.Album2.DoSetup();
            }
            else
            {
                this.Album1.GalleryRootPath = pathToGallery;
                this.Album1.DoSetup();
            }
        }
예제 #2
0
        private void LoadSettings()
        {
            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();
            mojoSetup.EnsureFolderGalleryFolder(siteSettings);

            pageId   = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);

            // previous value
            //~/Data/Sites/{0}/FolderGalleries/
            // changed to
            //~/Data/Sites/{0}/media/FolderGalleries/
            // 2013-04-04
            // did this to make more useful since that allows browsing the images from the wysiwyg editor

            //basePath = "~/Data/Sites/"
            //    + siteSettings.SiteId.ToInvariantString()
            //    + "/FolderGalleries/";
            basePath = string.Format(CultureInfo.InvariantCulture,
                                     FolderGalleryConfiguration.BasePathFormat,
                                     siteSettings.SiteId);

            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);
            config         = new FolderGalleryConfiguration(moduleSettings);

            // this check is for backward compat with galleries previously created below ~/Data/Sites/{0}/FolderGalleries/
            if (config.GalleryRootFolder.Length > 0)
            {
                if (!config.GalleryRootFolder.StartsWith(basePath))
                {
                    // legacy path
                    basePath = "~/Data/Sites/"
                               + siteSettings.SiteId.ToInvariantString()
                               + "/FolderGalleries/";
                }
            }

            try
            {
                // ensure directory
                if (!Directory.Exists(Server.MapPath(basePath)))
                {
                    Directory.CreateDirectory(Server.MapPath(basePath));
                }
            }
            catch (IOException ex)
            {
                log.Error(ex);
            }

            //allowEditUsersToChangeFolderPath = WebUtils.ParseBoolFromHashtable(
            //    moduleSettings, "AllowEditUsersToChangeFolderPath", allowEditUsersToChangeFolderPath);

            //allowEditUsersToUpload = WebUtils.ParseBoolFromHashtable(
            //    moduleSettings, "AllowEditUsersToUpload", allowEditUsersToUpload);

            if (!WebUser.IsAdminOrContentAdmin)
            {
                pnlUpload.Visible = config.AllowEditUsersToUpload;
                pnlEdit.Visible   = config.AllowEditUsersToChangeFolderPath;
            }

            uploader.MaxFilesAllowed      = FolderGalleryConfiguration.MaxFilesToUploadAtOnce;
            uploader.AcceptFileTypes      = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(WebConfigSettings.ImageFileExtensions);
            uploader.UploadButtonClientId = btnUpload.ClientID;
            uploader.ServiceUrl           = SiteRoot + "/FolderGallery/upload.ashx?pageid=" + pageId.ToInvariantString()
                                            + "&mid=" + moduleId.ToInvariantString();
            uploader.FormFieldClientId = hdnState.ClientID; // not really used but prevents submitting all the form

            string refreshFunction = "function refresh" + moduleId.ToInvariantString()
                                     + " () { window.location.href = '" + SiteUtils.GetCurrentPageUrl() + "'; } ";

            uploader.UploadCompleteCallback = "refresh" + moduleId.ToInvariantString();

            ScriptManager.RegisterClientScriptBlock(
                this,
                this.GetType(), "refresh" + moduleId.ToInvariantString(),
                refreshFunction,
                true);


            AddClassToBody("foldergalleryedit");
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);

            config = new FolderGalleryConfiguration(Settings);

            string pathToGallery = string.Empty;

            if (config.GalleryRootFolder.Length > 0)
            {
                pathToGallery = config.GalleryRootFolder;

            }
            else
            {
                pathToGallery = GetDefaultGalleryPath();
                if (pathToGallery.Length > 0) CreateDefaultFolderSetting(pathToGallery);

            }

            //if (pathToGallery.Length == 0)
            //{
            //    pathToGallery = GetDefaultGalleryPath();
            //    if (pathToGallery.Length > 0) CreateDefaultFolderSetting(pathToGallery);
            //}

            try
            {

                if (!Directory.Exists(Server.MapPath(pathToGallery)))
                {
                    //pathToGallery = GetDefaultGalleryPath();
                    Directory.CreateDirectory(Server.MapPath(pathToGallery));
                }
            }
            catch (IOException ex)
            {

                log.Error(ex);

            }
            catch (HttpException ex)
            {
                log.Error(ex);
                //thrown at Server.MapPath if the path is not a valid virtual path
                pathToGallery = GetDefaultGalleryPath();

            }

            ShowPermaLinksSetting = config.ShowPermaLinks;
            ShowMetaDetailsSetting = config.ShowMetaDetails;

            if (Page is mojoBasePage)
            {
                basePage = Page as mojoBasePage;
                useMobileTemplate = basePage.UseMobileSkin;
            }

            if (useMobileTemplate)
            {
                this.Album1.Visible = false;
                this.Album2.Visible = true;
                this.Album2.GalleryRootPath = pathToGallery;
                this.Album2.DoSetup();
            }
            else
            {
                this.Album1.GalleryRootPath = pathToGallery;
                this.Album1.DoSetup();
            }
        }
예제 #4
0
        public void ProcessRequest(HttpContext context)
        {
            base.Initialize(context);

            if (!UserCanEditModule(ModuleId, FolderGalleryConfiguration.FeatureGuid))
            {
                log.Info("User has no edit permission so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentSite == null)
            {
                log.Info("CurrentSite is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentUser == null)
            {
                log.Info("CurrentUser is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            // this feature only uses the actual system.io file system
            //if (FileSystem == null)
            //{
            //    log.Info("FileSystem is null so returning 404");
            //    Response.StatusCode = 404;
            //    return;
            //}

            if (Request.Files.Count == 0)
            {
                log.Info("Posted File Count is zero so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count > FolderGalleryConfiguration.MaxFilesToUploadAtOnce)
            {
                log.Info("Posted File Count is higher than configured limit so returning 404");
                Response.StatusCode = 404;
                return;
            }

            module = GetModule(ModuleId, FolderGalleryConfiguration.FeatureGuid);

            if (module == null)
            {
                log.Info("Module is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            Hashtable moduleSettings = ModuleSettings.GetModuleSettings(ModuleId);
            config = new FolderGalleryConfiguration(moduleSettings);

            string imageFolderPath;
            if (config.GalleryRootFolder.Length > 0)
            {
                imageFolderPath = config.GalleryRootFolder;
            }
            else
            {
                imageFolderPath = string.Format(CultureInfo.InvariantCulture,
                    FolderGalleryConfiguration.BasePathFormat,
                    CurrentSite.SiteId);
            }

            context.Response.ContentType = "text/plain";//"application/json";
            var r = new System.Collections.Generic.List<UploadFilesResult>();
            JavaScriptSerializer js = new JavaScriptSerializer();

            try
            {
                for (int f = 0; f < Request.Files.Count; f++)
                {
                    HttpPostedFile file = Request.Files[f];

                    string ext = Path.GetExtension(file.FileName);
                    string newFileName = Path.GetFileName(file.FileName);
                    if (SiteUtils.IsAllowedUploadBrowseFile(ext, ".jpg|.gif|.png|.jpeg"))
                    {
                        string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                        if(File.Exists(Server.MapPath(newImagePath)))
                        {
                            File.Delete(Server.MapPath(newImagePath));
                        }

                        file.SaveAs(Server.MapPath(newImagePath));

                        //using (Stream s = file.InputStream)
                        //{
                        //    //FileSystem.SaveFile(newImagePath, s, file.ContentType, true);

                        //}

                        r.Add(new UploadFilesResult()
                        {
                            //Thumbnail_url =
                            Name = newFileName,
                            Length = file.ContentLength,
                            Type = file.ContentType
                        });

                    }

                }

            }
            catch(Exception ex)
            {
                log.Error(ex);
            }

            var uploadedFiles = new
            {
                files = r.ToArray()
            };

            var jsonObj = js.Serialize(uploadedFiles);
            context.Response.Write(jsonObj.ToString());
        }
예제 #5
0
        private void LoadSettings()
        {
            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();
            mojoSetup.EnsureFolderGalleryFolder(siteSettings);

            pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);

            // previous value
            //~/Data/Sites/{0}/FolderGalleries/
            // changed to
            //~/Data/Sites/{0}/media/FolderGalleries/
            // 2013-04-04
            // did this to make more useful since that allows browsing the images from the wysiwyg editor

            //basePath = "~/Data/Sites/"
            //    + siteSettings.SiteId.ToInvariantString()
            //    + "/FolderGalleries/";
            basePath = string.Format(CultureInfo.InvariantCulture,
                FolderGalleryConfiguration.BasePathFormat,
                siteSettings.SiteId);

            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);
            config = new FolderGalleryConfiguration(moduleSettings);

            // this check is for backward compat with galleries previously created below ~/Data/Sites/{0}/FolderGalleries/
            if (config.GalleryRootFolder.Length > 0)
            {
                if (!config.GalleryRootFolder.StartsWith(basePath))
                {
                    // legacy path
                    basePath = "~/Data/Sites/"
                        + siteSettings.SiteId.ToInvariantString()
                        + "/FolderGalleries/";

                }
            }

            try
            {
                // ensure directory
                if (!Directory.Exists(Server.MapPath(basePath)))
                {
                    Directory.CreateDirectory(Server.MapPath(basePath));
                }
            }
            catch (IOException ex)
            {
                log.Error(ex);
            }

            //allowEditUsersToChangeFolderPath = WebUtils.ParseBoolFromHashtable(
            //    moduleSettings, "AllowEditUsersToChangeFolderPath", allowEditUsersToChangeFolderPath);

            //allowEditUsersToUpload = WebUtils.ParseBoolFromHashtable(
            //    moduleSettings, "AllowEditUsersToUpload", allowEditUsersToUpload);

            if (!WebUser.IsAdminOrContentAdmin)
            {
                pnlUpload.Visible = config.AllowEditUsersToUpload;
                pnlEdit.Visible = config.AllowEditUsersToChangeFolderPath;
            }

            uploader.MaxFilesAllowed = FolderGalleryConfiguration.MaxFilesToUploadAtOnce;
            uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(SiteUtils.ImageFileExtensions());
            uploader.UploadButtonClientId = btnUpload.ClientID;
            uploader.ServiceUrl = SiteRoot + "/FolderGallery/upload.ashx?pageid=" + pageId.ToInvariantString()
                + "&mid=" + moduleId.ToInvariantString();
            uploader.FormFieldClientId = hdnState.ClientID; // not really used but prevents submitting all the form

            string refreshFunction = "function refresh" + moduleId.ToInvariantString()
                    + " () { window.location.href = '" + SiteUtils.GetCurrentPageUrl() + "'; } ";

            uploader.UploadCompleteCallback = "refresh" + moduleId.ToInvariantString();

            ScriptManager.RegisterClientScriptBlock(
                this,
                this.GetType(), "refresh" + moduleId.ToInvariantString(),
                refreshFunction,
                true);

            AddClassToBody("foldergalleryedit");
        }