/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="cmd"></param> /// <param name="input"></param> /// <returns></returns> public override object OnRPC(ManagerEngine man, string cmd, Hashtable input) { switch (cmd) { case "copyFiles": return(this.CopyFiles(man, input)); case "moveFiles": return(this.MoveFiles(man, input)); case "createDocs": return(this.CreateDocs(man, input)); case "createZip": return(this.CreateZip(man, input)); case "loadContent": return(this.LoadContent(man, input)); case "saveContent": return(this.SaveContent(man, input)); } return(null); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnInit(ManagerEngine man) { // Register local file system factroy man.FileSystems["zip"] = new ZipFileFactory(); return(true); // Pass to next }
private object RemoveFavorites(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "status", "file", "message" }); HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; HttpCookie cookie; ArrayList chunks; if ((cookie = request.Cookies["fav"]) == null) { return(rs); } chunks = new ArrayList(cookie.Value.Split(new char[] { ',' })); cookie.Expires = DateTime.Now.AddDays(30); for (int i = 0; input["path" + i] != null; i++) { string path = (string)input["path" + i]; chunks.RemoveAt(chunks.IndexOf(path)); rs.Add("OK", man.EncryptPath(path), "Path was removed."); } cookie.Value = this.Implode(chunks, ","); response.Cookies.Remove("fav"); response.Cookies.Add(cookie); return(rs); }
public override bool OnInsertFile(ManagerEngine man, IFile file) { HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; HttpCookie cookie; ArrayList chunks; if ((cookie = request.Cookies["hist"]) == null) { cookie = new HttpCookie("hist"); } cookie.Expires = DateTime.Now.AddDays(30); if (cookie.Value != null) { chunks = new ArrayList(cookie.Value.Split(new char[] { ',' })); if (chunks.IndexOf(man.EncryptPath(file.AbsolutePath)) == -1) { chunks.Add(man.EncryptPath(file.AbsolutePath)); } cookie.Value = this.Implode(chunks, ","); } else { cookie.Value = man.EncryptPath(file.AbsolutePath); } response.Cookies.Remove("hist"); response.Cookies.Add(cookie); return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnAuthenticate(ManagerEngine man) { HttpContext context = HttpContext.Current; string[] ipAddresses = man.Config.Get("IPAuthenticator.ip_numbers").Split(new char[] { ',' }); foreach (string ipadds in ipAddresses) { string[] ipRange = ipadds.Split(new char[] { '-' }); // Single IP if (ipRange.Length == 1 && NetUtils.GetIPAddress(ipRange[0]) == NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"])) { return(true); } // IP range if (ipRange.Length == 2 && NetUtils.GetIPAddress(ipRange[0]) >= NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"]) && NetUtils.GetIPAddress(ipRange[1]) <= NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"])) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="cmd"></param> /// <param name="input"></param> /// <returns></returns> public override object OnRPC(ManagerEngine man, string cmd, Hashtable input) { switch (cmd) { case "getMediaInfo": return(this.GetMediaInfo(man, input)); case "cropImage": return(this.CropImage(man, input)); case "resizeImage": return(this.ResizeImage(man, input)); case "rotateImage": return(this.RotateImage(man, input)); case "flipImage": return(this.FlipImage(man, input)); case "saveImage": return(this.SaveImage(man, input)); } return(null); }
private ResultSet ResizeImage(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "status", "file", "message" }); IFile file, targetFile; ManagerConfig config; string tempName; int w, h; file = man.GetFile(man.DecryptPath((string)input["path"])); config = file.Config; if (!man.IsToolEnabled("edit", config)) { throw new ManagerException("{#error.no_access}"); } if (!file.Exists) { rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.file_not_exists}"); return(rs); } if (file.Name.IndexOf("mcic_") != 0 && !man.VerifyFile(file, "edit")) { rs.Add("FATAL", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg); return(rs); } if (input["temp"] != null && (bool)input["temp"]) { tempName = "mcic_" + HttpContext.Current.Session.SessionID + "." + PathUtils.GetExtension(file.Name); if (input["target"] != null) { targetFile = man.GetFile(man.DecryptPath((string)input["target"]), tempName); } else { targetFile = man.GetFile(file.Parent, tempName); } } else { targetFile = file; } w = Convert.ToInt32(input["width"]); h = Convert.ToInt32(input["height"]); try { ImageUtils.ResizeImage(file.AbsolutePath, targetFile.AbsolutePath, w, h, config.GetInt("edit.jpeg_quality", 90)); rs.Add("OK", man.EncryptPath(targetFile.AbsolutePath), "{#message.resize_success}"); } catch (Exception ex) { man.Logger.Error(ex.ToString()); rs.Add("FAILED", man.EncryptPath(targetFile.AbsolutePath), "{#error.resize_failed}"); } return(rs); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="prefix"></param> /// <returns></returns> public override bool OnPreInit(ManagerEngine man, string prefix) { if (prefix == "im") { man.Config = ((ManagerConfig)man.ResolveConfig("Moxiecode.ImageManager.ImageManagerPlugin", "ImageManagerPlugin")).Clone(); } return(true); }
private Hashtable LoadContent(ManagerEngine man, Hashtable input) { Hashtable result = new Hashtable(); IFile file; ManagerConfig config; StreamReader reader = null; Stream stream = null; file = man.GetFile(man.DecryptPath((string)input["path"])); config = file.Config; if (!man.IsToolEnabled("edit", config)) { throw new ManagerException("{#error.no_access}"); } if (config.GetBool("general.demo", false)) { throw new ManagerException("{#error.demo}"); } if (!man.VerifyFile(file, "edit")) { throw new ManagerException(man.InvalidFileMsg); } if (!file.CanWrite) { throw new ManagerException("{#error.no_write_access}"); } if (!config.GetBool("filesystem.writable", true)) { throw new ManagerException("{#error.no_write_access}"); } // Load content try { stream = file.Open(FileMode.Open); if (stream != null) { reader = new StreamReader(stream); result["content"] = reader.ReadToEnd(); } else { throw new ManagerException("{#error.no_access}"); } } finally { if (stream != null) { stream.Close(); } } return(result); }
/// <summary> /// Gets called after any authenication is performed and verified. /// This method should return false if the execution chain is to be broken. /// </summary> /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param> /// <returns>true/false if the execution of the event chain should continue execution.</returns> public override bool OnInit(ManagerEngine man) { ManagerConfig config = man.Config; // Override a config option config["somegroup.someoption"] = "somevalue"; return(true); }
public Manager PrintUserLogForm(DBContext context, ManagerEngine managerEngine) { Console.WriteLine("Введите логин :"); string login = Console.ReadLine(); Console.WriteLine("Введите пароль :"); string password = Console.ReadLine(); return(managerEngine.CheckManagerData(context, login, password)); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="cmd"></param> /// <param name="input"></param> /// <returns></returns> public override bool OnStream(ManagerEngine man, string cmd, NameValueCollection input) { switch (cmd) { case "thumb": return(this.StreamThumb(man, input)); } return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnAuthenticate(ManagerEngine man) { HttpContext context = HttpContext.Current; ManagerConfig config = man.Config; string loggedInKey, groupsKey, userKey, pathKey, rootPathKey, configPrefix; // Support both old and new format loggedInKey = (string)config.Get("SessionAuthenticator.logged_in_key", config["authenticator.session.logged_in_key"]); groupsKey = (string)config.Get("SessionAuthenticator.groups_key", config["authenticator.session.groups_key"]); userKey = (string)config.Get("SessionAuthenticator.user_key", config["authenticator.session.user_key"]); pathKey = (string)config.Get("SessionAuthenticator.path_key", config["authenticator.session.path_key"]); rootPathKey = (string)config.Get("SessionAuthenticator.rootpath_key", config["authenticator.session.rootpath_key"]); configPrefix = (string)config.Get("SessionAuthenticator.config_prefix", "mcmanager") + "."; // Grab current user/login string user = (string)(context.Session[userKey] != null ? context.Session[userKey] : ""); // Cleanup user = user.Replace("\\", ""); user = user.Replace("/", ""); user = user.Replace(":", ""); // Replace all ${user} with current user for (int i = 0; i < config.Keys.Count; i++) { config[config.Keys[i]] = config[config.Keys[i]].Replace("${user}", user); config[config.Keys[i]] = config[config.Keys[i]].Replace("{$user}", user); } // Loop through all sessions foreach (string key in context.Session.Keys) { if (key.StartsWith(configPrefix)) { config[key.Substring(configPrefix.Length)] = "" + context.Session[key]; } } // path specified in session if (context.Session[pathKey] != null) { config["filesystem.path"] = (string)context.Session[pathKey]; } // Root path specified in session if (context.Session[rootPathKey] != null) { config["filesystem.rootpath"] = (string)context.Session[rootPathKey]; } // Force update of internal items man.Config = man.Config; return(context.Session[loggedInKey] != null && StringUtils.CheckBool((string)context.Session[loggedInKey])); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="file"></param> /// <param name="type"></param> /// <param name="info"></param> /// <returns></returns> public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info) { string ext = PathUtils.GetExtension(file.Name).ToLower(); info["thumbnail"] = false; switch (ext) { case "gif": case "jpeg": case "jpg": case "png": MediaInfo imageSize = new MediaInfo(file.AbsolutePath); ManagerConfig config = file.Config; int thumbWidth, thumbHeight; double scale; // Constrain proportions scale = Math.Min(config.GetInt("thumbnail.width", 90) / (double)imageSize.Width, config.GetInt("thumbnail.height", 90) / (double)imageSize.Height); if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") { thumbWidth = scale > 1 ? imageSize.Width : (int)Math.Floor(imageSize.Width * scale); thumbHeight = scale > 1 ? imageSize.Height : (int)Math.Floor(imageSize.Height * scale); } else { thumbWidth = config.GetInt("thumbnail.width", 90); thumbHeight = config.GetInt("thumbnail.height", 90); } info["width"] = imageSize.Width; info["height"] = imageSize.Height; info["editable"] = true; info["twidth"] = thumbWidth; info["theight"] = thumbHeight; info["thumbnail"] = true; // Get thumbnail URL if (type == "insert") { IFile thumbFile = man.GetFile(file.Parent + "/" + config.Get("thumbnail.folder", "mcith") + "/" + config.Get("thumbnail.prefix", "mcith") + file.Name); if (thumbFile.Exists) { info["thumbnail_url"] = man.ConvertPathToURI(thumbFile.AbsolutePath); } } break; } return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="file"></param> /// <param name="type"></param> /// <param name="info"></param> /// <returns></returns> public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info) { switch (type) { case "list": info["previewable"] = file.IsFile && man.VerifyFile(file, "preview"); info["editable"] = file.IsFile && man.VerifyFile(file, "edit"); break; } return(true); }
private void Cleanup(ManagerEngine man, IFile dir) { IFile[] files = dir.ListFiles(); foreach (IFile file in files) { if (file.Name.StartsWith("mcic_") && file.LastModified < DateTime.Now.AddMinutes(-30)) { file.Delete(); } } }
public override object OnRPC(ManagerEngine man, string cmd, Hashtable input) { switch (cmd) { case "addFavorites": return(this.AddFavorites(man, input)); case "removeFavorites": return(this.RemoveFavorites(man, input)); } return(null); }
/// <summary> /// Initializes a file instance by a absolute path, child name and type. /// This can be userful when filtering non existing files. /// </summary> /// <param name="man">Reference to manager that requested the file.</param> /// <param name="absolute_path">Absolute file/directory path.</param> /// <param name="child_name">Name of child file for the directory.</param> /// <param name="type">Type of file to create.</param> public BaseFile(ManagerEngine man, string absolute_path, string child_name, FileType type) { this.manager = man; if (child_name != null && child_name != "") { this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name); } else { this.absPath = PathUtils.ToUnixPath(absolute_path); } }
/// <summary> /// Initializes a file instance by a absolute path, child name and type. /// This can be userful when filtering non existing files. /// </summary> /// <param name="man">Reference to manager that requested the file.</param> /// <param name="absolute_path">Absolute file/directory path.</param> /// <param name="child_name">Name of child file for the directory.</param> /// <param name="type">Type of file to create.</param> public ZipFileImpl(ManagerEngine man, string absolute_path, string child_name, FileType type) : base(man, absolute_path, child_name, type) { this.absPath = this.absPath.Replace("zip://", ""); Match match = Regex.Match(this.absPath, @"^(.*?.zip)(.*?)$", RegexOptions.IgnoreCase); this.zipPath = match.Groups[1].Value; this.innerPath = match.Groups[2].Value; if (this.innerPath == "") { this.innerPath = "/"; } }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="file"></param> /// <param name="type"></param> /// <param name="info"></param> /// <returns></returns> public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info) { switch (type) { case "insert": // Can be used by the insert_templates like this {$custom.mycustomfield} info["mycustomfield"] = file.Name.ToUpper(); // Will be used as title/alt in TinyMCE link/image dialogs info["description"] = file.Name + "(" + StringUtils.GetSizeStr(file.Length) + ")"; break; } // Pass to next handler return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnAuthenticate(ManagerEngine man) { HttpContext context = HttpContext.Current; ManagerConfig config = man.Config; string loggedInKey, groupsKey, userKey, pathKey, rootPathKey, configPrefix; // Support both old and new format loggedInKey = (string) config.Get("SessionAuthenticator.logged_in_key", config["authenticator.session.logged_in_key"]); groupsKey = (string) config.Get("SessionAuthenticator.groups_key", config["authenticator.session.groups_key"]); userKey = (string) config.Get("SessionAuthenticator.user_key", config["authenticator.session.user_key"]); pathKey = (string) config.Get("SessionAuthenticator.path_key", config["authenticator.session.path_key"]); rootPathKey = (string) config.Get("SessionAuthenticator.rootpath_key", config["authenticator.session.rootpath_key"]); configPrefix = (string) config.Get("SessionAuthenticator.config_prefix", "mcmanager") + "."; // Grab current user/login string user = (string) (context.Session[userKey] != null ? context.Session[userKey] : ""); // Cleanup user = user.Replace("\\", ""); user = user.Replace("/", ""); user = user.Replace(":", ""); // Replace all ${user} with current user for (int i=0; i<config.Keys.Count; i++) { config[config.Keys[i]] = config[config.Keys[i]].Replace("${user}", user); config[config.Keys[i]] = config[config.Keys[i]].Replace("{$user}", user); } // Loop through all sessions foreach (string key in context.Session.Keys) { if (key.StartsWith(configPrefix)) config[key.Substring(configPrefix.Length)] = "" + context.Session[key]; } // path specified in session if (context.Session[pathKey] != null) config["filesystem.path"] = (string) context.Session[pathKey]; // Root path specified in session if (context.Session[rootPathKey] != null) config["filesystem.rootpath"] = (string) context.Session[rootPathKey]; // Force update of internal items man.Config = man.Config; return context.Session[loggedInKey] != null && StringUtils.CheckBool((string) context.Session[loggedInKey]); }
/// <summary> /// Initializes a file instance by a absolute path, child name and type. /// This can be userful when filtering non existing files. /// </summary> /// <param name="man">Reference to manager that requested the file.</param> /// <param name="absolute_path">Absolute file/directory path.</param> /// <param name="child_name">Name of child file for the directory.</param> /// <param name="type">Type of file to create.</param> public LocalFile(ManagerEngine man, string absolute_path, string child_name, FileType type) { this.manager = man; if (child_name != "") { this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name); } else { this.absPath = PathUtils.ToUnixPath(absolute_path); } if (type == FileType.Directory) { this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath)); } else if (type == FileType.File) { this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath)); } else { // Create file info or dir info this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath)); if (!this.fileInfo.Exists) { this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath)); this.fileInfo = null; } if (this.fileInfo != null) { this.absPath = PathUtils.ToUnixPath(this.fileInfo.FullName); } if (this.dirInfo != null) { this.absPath = PathUtils.RemoveTrailingSlash(PathUtils.ToUnixPath(this.dirInfo.FullName)); } } this.config = this.manager.Config; this.configResolved = false; this.triggerEvents = true; }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="action"></param> /// <param name="file1"></param> /// <param name="file2"></param> /// <returns></returns> public override bool OnBeforeFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2) { ManagerConfig config; if (action == FileAction.Delete) { config = file1.Config; if (config.GetBool("filesystem.delete_format_images", false)) { ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("upload.format")); ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("edit.format")); } } return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnAuthenticate(ManagerEngine man) { HttpContext context = HttpContext.Current; ManagerConfig config = man.Config; string user = context.User.Identity.Name; // Cleanup user = user.Replace("\\", ""); user = user.Replace("/", ""); user = user.Replace(":", ""); // Replace all ${user} with current user for (int i = 0; i < config.Keys.Count; i++) { config[config.Keys[i]] = config[config.Keys[i]].Replace("${user}", user); } return(context.User.Identity.IsAuthenticated); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <returns></returns> public override bool OnAuthenticate(ManagerEngine man) { HttpContext context = HttpContext.Current; string[] ipAddresses = man.Config.Get("IPAuthenticator.ip_numbers").Split(new char[]{','}); foreach (string ipadds in ipAddresses) { string[] ipRange = ipadds.Split(new char[]{'-'}); // Single IP if (ipRange.Length == 1 && NetUtils.GetIPAddress(ipRange[0]) == NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"])) return true; // IP range if (ipRange.Length == 2 && NetUtils.GetIPAddress(ipRange[0]) >= NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"]) && NetUtils.GetIPAddress(ipRange[1]) <= NetUtils.GetIPAddress(context.Request.ServerVariables["REMOTE_ADDR"])) return true; } return false; }
private ResultSet CreateZip(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "status", "fromfile", "tofile", "message" }); if (man.GetFile(man.DecryptPath((string)input["topath"]), (string)input["toname"] + ".zip").Exists) { throw new ManagerException("{#error.tofile_exists}"); } for (int i = 0; input["frompath" + i] != null; i++) { IFile fromFile = man.GetFile(man.DecryptPath((string)input["frompath" + i])); IFile toFile = man.GetFile("zip://" + PathUtils.AddTrailingSlash(man.DecryptPath((string)input["topath"])) + input["toname"] + ".zip", fromFile.Name); if (!man.IsToolEnabled("zip", toFile.Config)) { throw new ManagerException("{#error.no_access}"); } if (!fromFile.Exists) { rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_from_file}"); continue; } // Zip check if (!man.VerifyFile(fromFile, "zip")) { rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg); continue; } if (fromFile.CopyTo(toFile)) { rs.Add("OK", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#message.zip_success}"); } } return(rs); }
private bool StreamThumb(ManagerEngine man, NameValueCollection input) { HttpContext context = HttpContext.Current; string path, contentType; ManagerConfig config; IFile file; // Get input path = man.DecryptPath((string)input["path"]); // Find mime type contentType = man.MimeTypes[PathUtils.GetExtension(path).ToLower()]; if (contentType != null) { context.Response.ContentType = contentType; } // Get and stream file file = man.GetFile(path); config = file.Config; try { path = MakeThumb(man, file).AbsolutePath; } catch (Exception) { // Ignore } // Stream thumbnail if (file is LocalFile) { context.Response.WriteFile(path); } else { IOUtils.StreamFromTo(file.Open(FileMode.Open), context.Response.OutputStream, 1024); } return(false); }
private IFile MakeThumb(ManagerEngine man, IFile file) { ManagerConfig config = file.Config; IFile thumbFile; int thumbWidth, thumbHeight; int configWidth, configHeight; double scale; MediaInfo thumbSize = new MediaInfo(); // Is not enabled if (!config.GetBool("thumbnail.enabled", true)) { return(file); } // Setup thumbnail path IFile thumbDir = man.GetFile(file.Parent, config.Get("thumbnail.folder", "mcith")); if (!thumbDir.Exists) { thumbDir.MkDir(); } configWidth = config.GetInt("thumbnail.width", 90); configHeight = config.GetInt("thumbnail.height", 90); // Make thumbnail thumbFile = man.GetFile(thumbDir.AbsolutePath, config.Get("thumbnail.prefix", "mcith") + file.Name); MediaInfo imageSize = new MediaInfo(file.AbsolutePath); // Need to scale? if (imageSize.Width < configWidth && imageSize.Height < configHeight) { return(file); } // To large if (imageSize.Width > config.GetInt("thumbnail.max_width", 65535) || imageSize.Height > config.GetInt("thumbnail.max_height", 65535)) { return(file); } // Constrain proportions scale = Math.Min(configWidth / (double)imageSize.Width, configHeight / (double)imageSize.Height); if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") { thumbWidth = scale > 1 ? imageSize.Width : (int)Math.Floor(imageSize.Width * scale); thumbHeight = scale > 1 ? imageSize.Height : (int)Math.Floor(imageSize.Height * scale); } else { thumbWidth = config.GetInt("thumbnail.width", 90); thumbHeight = config.GetInt("thumbnail.height", 90); } if (thumbFile.Exists) { thumbSize = new MediaInfo(thumbFile.AbsolutePath); } if (!thumbFile.Exists || thumbSize.Width != thumbWidth || thumbSize.Height != thumbHeight || file.LastModified != thumbFile.LastModified) { ImageUtils.MakeThumbnail(file.AbsolutePath, thumbFile.AbsolutePath, thumbWidth, thumbHeight, file.LastModified, config.GetInt("thumbnail.jpeg_quality", 75)); } return(thumbFile); }
private ResultSet SaveImage(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "status", "file", "message" }); IFile file, targetFile; ManagerConfig config; file = man.GetFile(man.DecryptPath((string)input["path"])); config = file.Config; if (!man.IsToolEnabled("edit", config)) { throw new ManagerException("{#error.no_access}"); } if (config.GetBool("general.demo", false)) { rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.demo}"); this.Cleanup(man, file.ParentFile); return(rs); } if (file.Name.IndexOf("mcic_") != 0 && !man.VerifyFile(file, "edit")) { rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg); this.Cleanup(man, file.ParentFile); return(rs); } targetFile = man.GetFile(file.Parent, (string)input["target"]); if (file.AbsolutePath != targetFile.AbsolutePath) { string fileExt = PathUtils.GetExtension(file.Name).ToLower(); string targetExt = PathUtils.GetExtension(targetFile.Name).ToLower(); if (fileExt != targetExt) { rs.Add("FAILED", man.EncryptPath(targetFile.AbsolutePath), "{#error.invalid_filename}"); this.Cleanup(man, file.ParentFile); return(rs); } if (config.GetBool("filesystem.delete_format_images", false)) { ImageUtils.DeleteFormatImages(targetFile.AbsolutePath, config.Get("edit.format")); } if (targetFile.Exists) { targetFile.Delete(); } file.RenameTo(targetFile); if (config.Get("edit.format") != null) { ImageUtils.FormatImage(targetFile.AbsolutePath, config.Get("edit.format"), config.GetInt("edit.jpeg_quality", 90)); } this.Cleanup(man, file.ParentFile); } rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.save_success}"); return(rs); }
private ResultSet GetMediaInfo(ManagerEngine man, Hashtable input) { ResultSet rs = new ResultSet(new string[] { "name", "path", "url", "size", "type", "created", "modified", "width", "height", "attribs", "next", "prev", "custom" }); BasicFileFilter fileFilter; IFile file, parent; IFile[] files; string prev, next, attribs, url, ext; int width, height; bool match; Hashtable customInfo = new Hashtable(); ManagerConfig config; if (input["url"] != null) { input["path"] = man.ConvertURIToPath(new Uri((string)input["url"]).AbsolutePath); } file = man.GetFile(man.DecryptPath((string)input["path"])); config = file.Config; parent = file.ParentFile; if (parent.IsDirectory) { // Setup file filter fileFilter = new BasicFileFilter(); //fileFilter->setDebugMode(true); fileFilter.IncludeDirectoryPattern = config["filesystem.include_directory_pattern"]; fileFilter.ExcludeDirectoryPattern = config["filesystem.exclude_directory_pattern"]; fileFilter.IncludeFilePattern = config["filesystem.include_file_pattern"]; fileFilter.ExcludeFilePattern = config["filesystem.exclude_file_pattern"]; fileFilter.IncludeExtensions = config["filesystem.extensions"]; fileFilter.OnlyFiles = true; // List files files = parent.ListFilesFiltered(fileFilter); } else { throw new ManagerException("{#error.file_not_exists}"); } match = false; prev = ""; next = ""; // Find next and prev foreach (IFile curFile in files) { if (curFile.AbsolutePath == file.AbsolutePath) { match = true; continue; } else if (!match) { prev = curFile.AbsolutePath; } if (match) { next = curFile.AbsolutePath; break; } } ext = PathUtils.GetExtension(file.Name).ToLower(); // Input default size? MediaInfo size = new MediaInfo(file.AbsolutePath); width = size.Width != -1 ? size.Width : 425; height = size.Height != -1 ? size.Height : 350; // Get custom info man.DispatchEvent(EventType.CustomInfo, file, "info", customInfo); attribs = (file.CanRead && config.GetBool("filesystem.readable", true) ? "R" : "-") + (file.CanWrite && config.GetBool("filesystem.writable", true) ? "W" : "-"); url = PathUtils.RemoveTrailingSlash(config["preview.urlprefix"]) + man.ConvertPathToURI(file.AbsolutePath); rs.Add(file.Name, man.EncryptPath(file.AbsolutePath), url, file.Length, ext, StringUtils.GetDate(file.CreationDate, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")), StringUtils.GetDate(file.LastModified, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")), width, height, attribs, man.EncryptPath(next), man.EncryptPath(prev), customInfo); return(rs); }
public override bool OnInit(ManagerEngine man) { man.FileSystems.Add("favorite", new FavoriteFileFactory()); return(true); }
/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="action"></param> /// <param name="file1"></param> /// <param name="file2"></param> /// <returns></returns> public override bool OnFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2) { IFile thumbnailFolder, thumbnail; ManagerConfig config; switch (action) { case FileAction.Add: config = file1.Config; if (config.Get("upload.format") != null) { ImageUtils.FormatImage(file1.AbsolutePath, config.Get("upload.format"), config.GetInt("upload.autoresize_jpeg_quality", 90)); } if (config.GetBool("upload.create_thumbnail", true)) { thumbnail = this.MakeThumb(man, file1); } if (config.GetBool("upload.autoresize", false)) { string ext = PathUtils.GetExtension(file1.Name).ToLower(); int newWidth, newHeight, configWidth, configHeight; double scale; // Validate format if (ext != "gif" && ext != "jpeg" && ext != "jpg" && ext != "png") { return(true); } MediaInfo imageInfo = new MediaInfo(file1.AbsolutePath); configWidth = config.GetInt("upload.max_width", 1024); configHeight = config.GetInt("upload.max_height", 768); // Needs scaling? if (imageInfo.Width > configWidth || imageInfo.Height > configHeight) { scale = Math.Min(configWidth / (double)imageInfo.Width, configHeight / (double)imageInfo.Height); newWidth = scale > 1 ? imageInfo.Width : (int)Math.Floor(imageInfo.Width * scale); newHeight = scale > 1 ? imageInfo.Height : (int)Math.Floor(imageInfo.Height * scale); ImageUtils.ResizeImage(file1.AbsolutePath, file1.AbsolutePath, newWidth, newHeight, config.GetInt("upload.autoresize_jpeg_quality", 90)); } } break; case FileAction.Delete: config = file1.Config; if (config.GetBool("thumbnail.delete", true)) { thumbnailFolder = man.GetFile(file1.Parent, config["thumbnail.folder"]); thumbnail = man.GetFile(thumbnailFolder.AbsolutePath, config.Get("thumbnail.prefix", "mcith") + file1.Name); if (thumbnail.Exists) { thumbnail.Delete(); } // Delete empty thumbnail folder if (thumbnailFolder.Exists && thumbnailFolder.ListFiles().Length == 0) { thumbnailFolder.Delete(); } } break; } return(true); }