예제 #1
0
        public async Task <ActionResult> load()
        {
            var json   = new StreamReader(Request.Body).ReadToEnd();
            var data   = JsonConvert.DeserializeObject <BlogEntity>(json);
            var _posts = await BlogsBLL.LoadItems(_context, data);

            /* setup thumb path */
            foreach (var ph in _posts)
            {
                ph.url         = BlogUrlConfig.Generate_Post_Url(ph);
                ph.description = BlogScripts.PrepareShortDescription(ph.description, 2);
                Setup_Item(ph);
            }
            var _categories = new List <JGN_Categories>();

            if (data.loadstats)
            {
                _categories = await CategoryBLL.LoadItems(_context, new CategoryEntity()
                {
                    id         = 0,
                    type       = 6,
                    mode       = 0,
                    isenabled  = EnabledTypes.All,
                    parentid   = -1,
                    order      = "level asc", // don't change this
                    issummary  = false,
                    isdropdown = true,
                    loadall    = true // load all data
                });
            }
            var _records = 0;

            if (data.postid == 0)
            {
                _records = await BlogsBLL.Count(_context, data);
            }

            var settings = new
            {
                general = Jugnoon.Blogs.Configs.BlogSettings,
                aws     = Jugnoon.Blogs.Configs.AwsSettings
            };

            return(Ok(new { posts = _posts, records = _records, categories = _categories, settings = settings }));
        }
예제 #2
0
        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 }));
            }
        }