public static async Task Update(ApplicationDbContext context, JGN_Blogs entity) { Validation(entity); ScreenContent(context, entity); var item = context.JGN_Blogs .Where(p => p.id == entity.id) .FirstOrDefault(); if (item != null) { item.title = UtilityBLL.processNull(entity.title, 0); item.description = UtilityBLL.processNull(entity.description, 0); item.tags = UtilityBLL.processNull(entity.tags, 0); item.picture_url = UtilityBLL.processNull(entity.picture_url, 0); item.picture_caption = UtilityBLL.processNull(entity.picture_caption, 0); context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); // Content Associated Categories Processing CategoryContentsBLL.ProcessAssociatedContentCategories(context, entity.categories, item.id, (byte)CategoryContentsBLL.Types.Blogs, true); // update user stats await update_stats(context, entity.userid); } }
public static string Return_Blog_Single_Image(JGN_Blogs Entity, string defaultpath) { string ProcessedPictureName = ""; var BlogImages = Entity.picture_url.Split(char.Parse(",")); if (BlogImages.Length > 0) { string Picture = BlogImages[0].ToString(); if (!Picture.StartsWith("http")) { string ImagePath = "thumbs/"; ProcessedPictureName = Config.GetUrl() + "contents/blogs/" + ImagePath + "" + Picture; } else { ProcessedPictureName = Picture; } } else { // default picture ProcessedPictureName = defaultpath; } return(ProcessedPictureName); }
public static async Task <JGN_Blogs> Add(ApplicationDbContext context, JGN_Blogs entity) { Validation(entity); ScreenContent(context, entity); var ent = new JGN_Blogs() { userid = entity.userid, title = entity.title, description = entity.description, tags = entity.tags, isenabled = (byte)entity.isenabled, isapproved = (byte)entity.isapproved, created_at = DateTime.Now, fetch_url = UtilityBLL.processNull(entity.fetch_url, 0), picture_url = UtilityBLL.processNull(entity.picture_url, 0), cover_url = UtilityBLL.processNull(entity.cover_url, 0), picture_caption = UtilityBLL.processNull(entity.picture_caption, 0), }; context.Entry(ent).State = EntityState.Added; await context.SaveChangesAsync(); entity.id = ent.id; // Content Associated Categories Processing CategoryContentsBLL.ProcessAssociatedContentCategories(context, entity.categories, entity.id, (byte)CategoryContentsBLL.Types.Blogs, false); // update user stats await update_stats(context, entity.userid); return(entity); }
private static void ScreenContent(ApplicationDbContext context, JGN_Blogs entity) { if (Jugnoon.Settings.Configs.GeneralSettings.screen_content == 1) { entity.title = DictionaryBLL.Process_Screening(context, UtilityBLL.processNull(entity.title, 0)); entity.description = DictionaryBLL.Process_Screening(context, UtilityBLL.processNull(entity.description, 0)); entity.tags = DictionaryBLL.Process_Screening(context, UtilityBLL.processNull(entity.tags, 0)); } }
// Note: Important Terms // isenabled: // ........... 0: Not Enabled. // ........... 1: Enabled // ........... 2: Both enabled, disabled // isadult: // ........... 0: Not Adult. // ........... 1: Adult // isapproved: // ........... 0: Not approved // ........... 1: Approved #region Action Script public static void Validation(JGN_Blogs entity) { if (entity.title != null && entity.title.Length > 100) { entity.title = entity.title.Substring(0, 99); } if (entity.tags != null && entity.tags.Length > 300) { entity.tags = entity.tags.Substring(0, 299); } }
public static string Prepare_Description(JGN_Blogs Entity, int Length) { var _desc = BBCode.MakeHtml(Entity.description, true); if (_desc.Length > Length) { _desc = UtilityBLL.StripHTML(_desc.Substring(0, Length) + "...stpr"); string removeBrokenHyperlinks = Regex.Replace(_desc, @"<a(.*)?stpr", ""); string removeBrokenP = Regex.Replace(removeBrokenHyperlinks, @"<p(.*)?stpr", ""); _desc = removeBrokenP.Replace("stpr", ""); } else { _desc = UtilityBLL.StripHTML(_desc); } return(_desc); }
private void Setup_Item(JGN_Blogs blg) { blg.files = new List <FileEntity>(); if (blg.cover_url == null) { blg.cover_url = ""; } if (blg.picture_url == null) { blg.picture_url = ""; } if (blg.cover_url != "") { blg.cover_url = BlogUtil.Return_Blog_Cover(blg.cover_url); } if (blg.picture_url != "") { var _pics = blg.picture_url.Split(char.Parse(",")); foreach (var pic in _pics) { string imgUrl = BlogUtil.Return_Blog_Image(pic, Jugnoon.Blogs.Configs.BlogSettings.default_path); blg.files.Add(new FileEntity() { filename = pic, img_url = imgUrl }); } } if (blg.created_at == null) { blg.created_at = DateTime.Now; } blg.url = BlogUrlConfig.Generate_Post_Url(blg); blg.author_url = UserUrlConfig.ProfileUrl(blg.author, Jugnoon.Settings.Configs.RegistrationSettings.uniqueFieldOption); // process content blg.description = UtilityBLL.Process_Content_Text(blg.description); }
public static string Generate_Post_Url(JGN_Blogs entity) { string URLTITLE = ""; int maxium_length = Jugnoon.Settings.Configs.GeneralSettings.maximum_dynamic_link_length; if (entity.title.Length > maxium_length && maxium_length > 0) { URLTITLE = entity.title.Substring(0, maxium_length); } else if (entity.title.Length < 3) { URLTITLE = "preview-post"; } else { URLTITLE = entity.title; } URLTITLE = UtilityBLL.ReplaceSpaceWithHyphin_v2(URLTITLE.Trim().ToLower()); return(Config.GetUrl("post/" + entity.id + "/" + URLTITLE)); }
public async Task <ActionResult> proc() { var json = new StreamReader(Request.Body).ReadToEnd(); var model = JsonConvert.DeserializeObject <JGN_Blogs>(json); if (model.title != null && model.title.Length < 5) { return(Ok(new { status = "error", message = "Please enter title" })); } if (model.description == null || model.description == "" || model.description.Length < 10) { return(Ok(new { status = "error", message = "Please enter proper description" })); } // validate tags if (model.tags != null && Jugnoon.Settings.Configs.FeatureSettings.enable_tags) { if (!TagsBLL.Validate_Tags(model.tags)) { return(Ok(new { status = "error", message = "Tags not validated" })); } // Process tags if (model.tags != "") { TagsBLL.Process_Tags(_context, model.tags, TagsBLL.Types.Blogs, 0); } } var b_settings = new Jugnoon.Blogs.Settings.General(); // process categories int _isapproved = 1; // enable it bydefault if (b_settings.blogPostModeration == 1) { // Moderator Review Required _isapproved = 0; } //XSS CLEANUP string content = ""; if (model.description != null && model.description != "") { content = UGeneral.SanitizeText(model.description); } // normal tags if (b_settings.tag_Processing) { content = BlogScripts.Generate_Auto_Tag_Links(_context, content); } // normal category if (b_settings.category_Processing) { content = BlogScripts.Generate_Auto_Category_Links(_context, content); } // blog banner upload functionality if (model.cover_url != null && model.cover_url != "") { if (model.cover_url.StartsWith("data:image")) { // base 64 image var image_url = model.cover_url.Replace("data:image/png;base64,", ""); byte[] image = Convert.FromBase64String(image_url); // create image name var _title = UtilityBLL.ReplaceSpaceWithHyphin(model.title); if (_title.Length > 15) { _title = _title.Substring(0, 15); } string thumbFileName = _title + Guid.NewGuid().ToString().Substring(0, 8) + ".png"; var path = SiteConfig.Environment.ContentRootPath + DirectoryPaths.BlogsPhotoDirectoryPath; if (System.IO.File.Exists(path + "" + thumbFileName)) { System.IO.File.Delete(path + "" + thumbFileName); } // local storage System.IO.File.WriteAllBytes(path + "" + thumbFileName, image); model.cover_url = await Jugnoon.Helper.Aws.UploadPhoto(_context, thumbFileName, path, Jugnoon.Blogs.Configs.AwsSettings.midthumb_directory_path); } } // normal blog posts upload string _publish_path = ""; // Add information in table var filename = new StringBuilder(); if (model.files.Count > 0) { foreach (var item in model.files) { if (filename.ToString().Length > 0) { filename.Append(","); } filename.Append(item.filename); } } if (filename.ToString() != "") { _publish_path = AwsCloud.UploadPostCover(filename.ToString(), model.userid); } else { _publish_path = filename.ToString(); } if (model.id == 0) { var blg = new JGN_Blogs(); blg.categories = model.categories; blg.userid = model.userid; if (model.title != null) { blg.title = model.title; if (blg.title.Length > 100) { blg.title = blg.title.Substring(0, 99); } } blg.description = content; if (model.tags != null) { blg.tags = model.tags; if (blg.tags.Length > 300) { blg.tags = blg.tags.Substring(0, 299); } } blg.isenabled = 1; // enabled in start blg.isapproved = (byte)_isapproved; blg.picture_caption = model.picture_caption; blg.picture_url = _publish_path; // filename blg.cover_url = model.cover_url; blg = await BlogsBLL.Add(_context, blg); Setup_Item(blg); return(Ok(new { status = "success", record = blg, message = SiteConfig.generalLocalizer["_record_created"].Value })); } else { var blg = new JGN_Blogs(); blg.id = model.id; blg.userid = model.userid; if (model.title != null) { blg.title = model.title; } blg.description = content; if (model.tags != null) { blg.tags = model.tags; } blg.isapproved = (byte)_isapproved; blg.categories = model.categories; blg.picture_caption = model.picture_caption; blg.picture_url = _publish_path; Setup_Item(blg); await BlogsBLL.Update(_context, blg); return(Ok(new { status = "success", record = blg, message = SiteConfig.generalLocalizer["_record_updated"].Value })); } }