// GET: blogs/search public async Task <IActionResult> search(string term) { if (term == null) { return(Redirect("/blogs")); } var _sanitize = new HtmlSanitizer(); term = _sanitize.Sanitize(UtilityBLL.ReplaceHyphinWithSpace(term)); /* ***************************************/ // Process Page Meta & BreaCrumb /* ***************************************/ var _meta = PageMeta.returnPageMeta(new PageQuery() { controller = ControllerContext.ActionDescriptor.ControllerName, index = ControllerContext.ActionDescriptor.ActionName, pagenumber = 1, matchterm = term }); if (Jugnoon.Settings.Configs.GeneralSettings.store_searches) { //********************************************* // User Search Tracking Script //******************************************** if (!TagsBLL.Validate_Tags(term.Trim()) && !term.Trim().Contains("@")) { // check if tag doesn't exist var count_tags = await TagsBLL.Count(_context, new TagEntity() { type = TagsBLL.Types.General, tag_type = TagsBLL.TagType.UserSearches, isenabled = EnabledTypes.Enabled }); if (count_tags == 0) { TagsBLL.Add(_context, term.Trim(), TagsBLL.Types.General, 0, TagsBLL.TagType.UserSearches, EnabledTypes.Enabled, term.Trim()); } } } /* List Initialization */ var ListEntity = new BlogListViewModel() { QueryOptions = new BlogEntity() { term = term, }, BreadItems = _meta.BreadItems }; return(View(ListEntity)); }
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 })); } }