/// <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); }
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); }