void WebEvents_OnLoadRequestedPath(HandleFlag handled) { if (handled.Handled) { return; } if (!WebAuthentication.IsLoggedIn) { return; } if (!WebAuthentication.VerifyAccess(PermissionType.ModifyPages)) { return; } if (SprocketPath.Sections.Length >= 4 && SprocketPath.Sections[0] == "admin") { switch (SprocketPath.Sections[1]) { case "pages": switch (SprocketPath.Sections[2]) { case "delete": { long id; if (long.TryParse(SprocketPath.Sections[3], out id)) { Page page = ContentManager.Instance.DataProvider.SelectPage(id); if (page != null) { Result r = page.SaveRevision("** Page deleted.", page.RevisionInformation.Draft, page.RevisionInformation.Hidden, true); if (!r.Succeeded) { Response.Write("Unable to delete page:<br/>" + r.Message); Response.End(); return; } } } } WebUtility.Redirect("admin/pages"); break; case "imgthumb": { long id; if (long.TryParse(SprocketPath.Sections[3], out id)) { SizingOptions options = new SizingOptions(60, 45, SizingOptions.Display.Constrain, id); FileManager.FileManager.Instance.TransmitImage(options); } } break; } break; } } }
public Result ReadAdminField(out IEditFieldData efdata) { ImageEditFieldData data = new ImageEditFieldData(); SprocketFile file = null; if (HttpContext.Current.Request.Files[fieldName] != null) { if (HttpContext.Current.Request.Files[fieldName].ContentLength > 0) { file = new SprocketFile(SecurityProvider.ClientSpaceID, HttpContext.Current.Request.Files[fieldName], "", ""); Image img; Result r = file.ValidateImageData(out img); if (!r.Succeeded) { efdata = new ImageEditFieldData(); return(new Result("The image selected could not be loaded. The system reported back the following error: " + r.Message)); } if (maxwidth > 0 || maxheight > 0) { SizingOptions options = new SizingOptions(maxwidth, maxheight, SizingOptions.Display.Constrain, 0); options.Image = img; MemoryStream stream = new MemoryStream(); FileManager.FileManager.Instance.ResizeImage(options, stream); file.FileData = stream.ToArray(); } } } bool deleted = HttpContext.Current.Request.Form["deleteimage_" + fieldName] != null; long existing; if (!long.TryParse(HttpContext.Current.Request.Form["existingimage_" + fieldName], out existing)) { existing = 0; } if (deleted) { data.SprocketFileID = 0; } else if (file != null) { data.SprocketFile = file; } else { data.SprocketFileID = existing; } efdata = data; return(new Result()); }
public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state) { if(args.Count == 0) throw new InstructionExecutionException("At the very least, one argument is required specifying the id of an image in the database.", contextToken); long id; if(!long.TryParse(args[0].Expression.Evaluate(state, args[0].Token).ToString(), out id)) throw new InstructionExecutionException("The first argument must be a valid integer representing the id of an image in the database.", args[0].Token); SizingOptions options = new SizingOptions(0, 0, SizingOptions.Display.Constrain, id); options.SuspendFilenameUpdate(true); if (args.Count > 1) { int width; if (!int.TryParse(args[1].Expression.Evaluate(state, args[1].Token).ToString(), out width)) throw new InstructionExecutionException("The second argument must be a valid integer representing the desired width (use 0 to scale relative to the height).", args[1].Token); options.Width = width; } if (args.Count > 2) { int height; if (!int.TryParse(args[2].Expression.Evaluate(state, args[2].Token).ToString(), out height)) throw new InstructionExecutionException("The third argument must be a valid integer representing the desired height (use 0 to scale relative to the width).", args[2].Token); options.Height = height; } if (args.Count > 3) { string strDisplayType = (TokenParser.VerifyUnderlyingType(args[3].Expression.Evaluate(state, args[3].Token)) ?? "").ToString(); SizingOptions.Display displayType; try { displayType = (SizingOptions.Display)Enum.Parse(typeof(SizingOptions.Display), strDisplayType, true); } catch { throw new InstructionExecutionException("\"" + strDisplayType + "\" is not a valid resize method type. If in doubt, try \"letterbox\".", args[3].Token); } options.DisplayType = displayType; } if (args.Count > 4) { string hexColor = (TokenParser.VerifyUnderlyingType(args[4].Expression.Evaluate(state, args[4].Token)) ?? "").ToString(); Color color; try { color = FileManager.HexToColor(hexColor); } catch { throw new InstructionExecutionException("The fifth argument should be a hex value specifying the background color to use during the image resize operation. You specified \"" + hexColor + "\".", args[4].Token); } options.BackgroundColor = color; } if (args.Count > 5) { int padding; if (!int.TryParse(args[5].Expression.Evaluate(state, args[5].Token).ToString(), out padding)) throw new InstructionExecutionException("The sixth argument must be a valid integer representing the desired padding between the photo and the edge of the graphic (use 0 for no padding).", args[5].Token); options.Padding = padding; } options.SuspendFilenameUpdate(false); return options.Filename; }
public object Evaluate(Token contextToken, List <ExpressionArgument> args, ExecutionState state) { if (args.Count == 0) { throw new InstructionExecutionException("At the very least, one argument is required specifying the id of an image in the database.", contextToken); } long id; if (!long.TryParse(args[0].Expression.Evaluate(state, args[0].Token).ToString(), out id)) { throw new InstructionExecutionException("The first argument must be a valid integer representing the id of an image in the database.", args[0].Token); } SizingOptions options = new SizingOptions(0, 0, SizingOptions.Display.Constrain, id); options.SuspendFilenameUpdate(true); if (args.Count > 1) { int width; if (!int.TryParse(args[1].Expression.Evaluate(state, args[1].Token).ToString(), out width)) { throw new InstructionExecutionException("The second argument must be a valid integer representing the desired width (use 0 to scale relative to the height).", args[1].Token); } options.Width = width; } if (args.Count > 2) { int height; if (!int.TryParse(args[2].Expression.Evaluate(state, args[2].Token).ToString(), out height)) { throw new InstructionExecutionException("The third argument must be a valid integer representing the desired height (use 0 to scale relative to the width).", args[2].Token); } options.Height = height; } if (args.Count > 3) { string strDisplayType = (TokenParser.VerifyUnderlyingType(args[3].Expression.Evaluate(state, args[3].Token)) ?? "").ToString(); SizingOptions.Display displayType; try { displayType = (SizingOptions.Display)Enum.Parse(typeof(SizingOptions.Display), strDisplayType, true); } catch { throw new InstructionExecutionException("\"" + strDisplayType + "\" is not a valid resize method type. If in doubt, try \"letterbox\".", args[3].Token); } options.DisplayType = displayType; } if (args.Count > 4) { string hexColor = (TokenParser.VerifyUnderlyingType(args[4].Expression.Evaluate(state, args[4].Token)) ?? "").ToString(); Color color; try { color = FileManager.HexToColor(hexColor); } catch { throw new InstructionExecutionException("The fifth argument should be a hex value specifying the background color to use during the image resize operation. You specified \"" + hexColor + "\".", args[4].Token); } options.BackgroundColor = color; } if (args.Count > 5) { int padding; if (!int.TryParse(args[5].Expression.Evaluate(state, args[5].Token).ToString(), out padding)) { throw new InstructionExecutionException("The sixth argument must be a valid integer representing the desired padding between the photo and the edge of the graphic (use 0 for no padding).", args[5].Token); } options.Padding = padding; } options.SuspendFilenameUpdate(false); return(options.Filename); }