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