Exemplo n.º 1
0
        public string Files(string Identifier, string uid)
        {
            string result      = string.Empty;
            string ControlName = string.Empty;

            if (!string.IsNullOrEmpty(Identifier) && PortalSettings != null && UserInfo != null)
            {
                if (HttpContext.Current.Request.Form.AllKeys.Contains("ControlName"))
                {
                    ControlName = HttpContext.Current.Request.Form.Get("ControlName");
                }

                int FolderID = BrowseUploadFactory.GetRootFolder(PortalSettings.Current.PortalId).FolderID;
                if (string.IsNullOrEmpty(uid))
                {
                    result = BrowseUploadFactory.UploadFile(Identifier, HttpContext.Current, PortalSettings, new ModuleInfo(), UserInfo, isUploadAllowed(ActiveModule, UserInfo, ControlName), "jpg,jpeg,png,gif,pdf,zip,rar,xls,xlsx,css,xml,doc,docx,webp", 100, AppFactory.GetAppInformation().Name, uid, FolderID);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public dynamic ConvertSave(string FilePath, int Id, Stream stream, string Suffix = null)
        {
            dynamic result = "failed";

            using (MemoryStream memoryStream = new MemoryStream())
            {
                if (stream != null)
                {
                    List <Setting> settings = Managers.SettingManager.GetSettings(PortalSettings.PortalId, 0, "security_settings");
                    string         Picture_DefaultFolder = "-1";
                    if (settings != null && settings.Count > 0 && settings.Where(s => s.Name == "Picture_DefaultFolder").FirstOrDefault() != null)
                    {
                        Picture_DefaultFolder = settings.Where(s => s.Name == "Picture_DefaultFolder").FirstOrDefault().Value;
                    }

                    IFolderInfo folderInfo = FolderManager.Instance.GetFolder(Picture_DefaultFolder == "-1" ? BrowseUploadFactory.GetRootFolder(PortalSettings.PortalId).FolderID : int.Parse(Picture_DefaultFolder));
                    if (folderInfo != null && BrowseUploadFactory.HasPermission(folderInfo, "WRITE"))
                    {
                        string FileName = Security.ReplaceIllegalCharacters(Path.GetFileName(FilePath));
                        if (Id > -1)
                        {
                            FileName = Id + FileName.Substring(FileName.LastIndexOf('.'));
                        }

                        string FileExtension = FileName.Substring(FileName.LastIndexOf('.'));

                        //Force extention to be .png to maintain transparency
                        FileName      = FileName.Remove(FileName.Length - FileExtension.Length) + ".png";
                        FileExtension = ".png";

                        string TempFileName = FileName;

                        if (Security.IsAllowedExtension(FileExtension, FileSetting.FileType.Split(',')))
                        {
                            int count = 1;

Find:
                            if (FileManager.Instance.FileExists(folderInfo, TempFileName))
                            {
                                string FName = FileName.Remove(FileName.Length - FileExtension.Length);
                                if (!string.IsNullOrEmpty(Suffix))
                                {
                                    if (FileName.Contains(Suffix))
                                    {
                                        string[] FInfo = FileName.Split(new string[] { Suffix }, StringSplitOptions.None);
                                        if (FInfo.Length > 1)
                                        {
                                            FName = FInfo[0];
                                        }
                                    }
                                }
                                TempFileName = FName + (!string.IsNullOrEmpty(Suffix) ? Suffix : string.Empty) + count + FileExtension;
                                count++;
                                goto Find;
                            }
                            else
                            {
                                byte[] photoBytes = ToByteArray(stream);

                                System.Drawing.Image SrcImage = System.Drawing.Image.FromStream(stream);
                                int Width = SrcImage.Width;
                                SrcImage.Dispose();

                                using (MemoryStream inStream = new MemoryStream(photoBytes))
                                {
                                    FileName = TempFileName;
                                    IFileInfo fileInfo;
                                    if (!string.IsNullOrEmpty(Suffix))
                                    {
                                        using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                                        {
                                            //Convert to png
                                            ISupportedImageFormat format = new PngFormat();

                                            System.Drawing.Size size = new System.Drawing.Size(Width, 0);

                                            // Load, resize, set the format and quality and save an image.
                                            imageFactory.Load(inStream)
                                            .Format(format)
                                            .Save(memoryStream);
                                            fileInfo = FileManager.Instance.AddFile(folderInfo, FileName, memoryStream);
                                            memoryStream.Seek(0, SeekOrigin.Begin);
                                        }
                                    }
                                    else
                                    {
                                        stream.CopyTo(memoryStream);
                                        fileInfo = FileManager.Instance.AddFile(folderInfo, FileName, memoryStream);
                                        memoryStream.Seek(0, SeekOrigin.Begin);
                                    }

                                    if (Utils.IsImageVersionable(fileInfo))
                                    {
                                        BrowseUploadFactory.CropImage(FileName, FileExtension, folderInfo, memoryStream);
                                    }

                                    if (fileInfo != null)
                                    {
                                        result = BrowseUploadFactory.GetUrl(fileInfo.FileId);
                                    }
                                }
                            }
                        }
                    }

                    else
                    {
                        throw new Exception("Error: You do not have write permission for folder " + (folderInfo != null ? folderInfo.FolderPath.TrimEnd('/') : string.Empty));
                    }
                }
            }
            return(result);
        }
        internal static List <IUIData> GetData(PortalSettings portalSettings, ModuleInfo moduleInfo, Dictionary <string, string> parameters)
        {
            int PortalID = portalSettings.PortalId;
            int ModuleID = 0;

            if (moduleInfo != null)
            {
                ModuleID = moduleInfo.ModuleID;
            }

            string profile = string.Empty;

            if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.UrlReferrer != null && HttpContext.Current.Request.UrlReferrer.ToString().Contains("profile="))
            {
                profile = HttpContext.Current.Request.UrlReferrer.ToString().Split('=').Last();
            }
            else if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.UrlReferrer != null && HttpContext.Current.Request.UrlReferrer.ToString().Contains("profile/"))
            {
                profile = HttpContext.Current.Request.UrlReferrer.ToString().Split('/').Last();
                if (profile.Contains('?'))
                {
                    profile = profile.Split('?').First();
                }
            }
            Dictionary <string, IUIData> Settings           = new Dictionary <string, IUIData>();
            List <HTMLEditor_Profile>    HTMLEditorProfiles = GetHTMLEditorProfiles(PortalID);
            int ProfileID = 0;

            Settings.Add("UID", new UIData()
            {
                Name = "UID", Value = parameters.Where(p => p.Key == "uid").FirstOrDefault().Value
            });
            HTMLEditor Editor = HTMLEditor.Query("where UID=@0", Settings["UID"].Value + ModuleID).SingleOrDefault();

            if (Editor != null)
            {
                ProfileID = Editor.ProfileID;
                HTMLEditorSetting HTMLEditorSetting = DotNetNuke.Common.Utilities.Json.Deserialize <HTMLEditorSetting>(Editor.Settings);
                if (HTMLEditorSetting.UploadFilesRootFolder == 0)
                {
                    HTMLEditorSetting.UploadFilesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                }

                if (HTMLEditorSetting.UploadImagesRootFolder == 0)
                {
                    HTMLEditorSetting.UploadImagesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                }

                Settings.Add("Settings", new UIData()
                {
                    Name = "Settings", Options = HTMLEditorSetting
                });
            }
            else
            {
                if (!string.IsNullOrEmpty(profile) && HTMLEditorProfiles.Where(p => p.Name.ToLower() == profile.ToLower()).FirstOrDefault() != null)
                {
                    ProfileID = HTMLEditorProfiles.Where(p => p.Name.ToLower() == profile.ToLower()).FirstOrDefault().ProfileID;
                }

                HTMLEditorSetting HTMLEditorSetting = new HTMLEditorSetting();
                HTMLEditorSetting.UploadFilesRootFolder = HTMLEditorSetting.UploadImagesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                Settings.Add("Settings", new UIData()
                {
                    Name = "Settings", Options = HTMLEditorSetting
                });
            }

            Settings.Add("Profiles", new UIData()
            {
                Name = "Profiles", Options = HTMLEditorProfiles, Value = ProfileID.ToString()
            });
            Settings.Add("EditorOptions", new UIData()
            {
                Name = "EditorOptions", Options = GetEditorOptions(HTMLEditorProfiles, int.Parse(Settings["Profiles"].Value))
            });
            Settings.Add("LocalizationKeyValue", new UIData()
            {
                Name = "LocalizationKeyValue", Options = getLocalizationKeyValue()
            });
            Settings.Add("Folders", new UIData()
            {
                Name = "Folders", Options = BrowseUploadFactory.GetFolders(PortalID)
            });
            Settings.Add("IsSuperUser", new UIData()
            {
                Name = "IsSuperUser", Value = PortalSettings.Current.UserInfo.IsSuperUser.ToString()
            });
            Settings.Add("ModuleID", new UIData()
            {
                Name = "ModuleID", Value = ModuleID.ToString()
            });
            return(Settings.Values.ToList());
        }