Exemple #1
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 }));
            }
        }
Exemple #2
0
        public async Task <ActionResult> proc()
        {
            var json  = new StreamReader(Request.Body).ReadToEnd();
            var model = JsonConvert.DeserializeObject <JGN_ForumTopics>(json);

            // new topic posted
            if (model.replyid == 0)
            {
                // check title
                if (model.title.Length < 5)
                {
                    return(Ok(new { status = "error", message = SiteConfig.generalLocalizer["_invalid_title"].Value }));
                }
            }

            // Add information in table
            var topics = new JGN_ForumTopics();

            if (model.id > 0)
            {
                topics.id = model.id;
            }

            string content = UGeneral.SanitizeText(model.description);

            topics.description = content;
            topics.title       = model.title;
            if (topics.title.Length > 200)
            {
                topics.title = topics.title.Substring(0, 199);
            }
            topics.tags    = model.tags;
            topics.forumid = model.forumid;
            topics.userid  = model.userid;
            int isapproved = 1;

            topics.isapproved = (byte)isapproved;
            topics.isenabled  = 1;
            topics.replyid    = model.replyid;


            topics = await ForumTopicBLL.Process(_context, topics, true);

            if (model.tags != "" && model.replyid == 0 && model.id == 0)
            {
                // Process tags
                TagsBLL.Process_Tags(_context, model.tags, TagsBLL.Types.Forums, 0);
            }


            // Mail Procesing Section
            if (model.id == 0 && model.replyid == 0)
            {
                //  ProcessMail(tid, topics.replyid, topics.username, model.GroupID, model.Description, model.Title);
                // add newly added topic id in struct for user activity and group posting
                //topics.id = topics.id;
            }

            topics.url        = Forum_Urls.Prepare_Topic_Url(topics.id, topics.title, true);
            topics.author_url = UserUrlConfig.ProfileUrl(topics.author, Jugnoon.Settings.Configs.RegistrationSettings.uniqueFieldOption);

            return(Ok(new { status = "success", record = topics, message = SiteConfig.generalLocalizer["_record_created"].Value }));
        }
Exemple #3
0
        public async Task <IActionResult> post(PostTopicViewModel model)
        {
            if (ModelState.IsValid)
            {
                // new topic posted
                if (model.ReplyID == 0)
                {
                    // check title
                    if (model.Title.Length < 10)
                    {
                        model.Message = SiteConfig.forumLocalizer["_forum_post_msg_09"].Value;
                        return(View(model));
                    }

                    if (UtilityBLL.isLongWordExist(model.Title) || UtilityBLL.isLongWordExist(model.Title))
                    {
                        model.Message = SiteConfig.generalLocalizer["_invalid_title"];
                        return(View(model));
                    }
                }

                // Add information in table
                var topics = new JGN_ForumTopics();
                if (model.TopicID > 0)
                {
                    topics.id = model.TopicID;
                }

                topics.forumid = model.ForumID;

                string content = UGeneral.SanitizeText(model.Description);

                // Process Contents -> links, bbcodes etc
                // content = UtilityBLL.Process_Content_Text(content);
                // Generate Album Preview
                //content = AlbumsBLL.Generate_Blog_Gallery_Previews(content);

                topics.description = content;

                if (model.ReplyID > 0)
                {
                    var _lst = await ForumTopicBLL.LoadItems(_context, new ForumTopicEntity()
                    {
                        id      = model.TopicID,
                        loadall = true
                    });

                    if (_lst.Count > 0)
                    {
                        topics.tags    = _lst[0].tags;
                        topics.title   = _lst[0].title;
                        topics.forumid = _lst[0].forumid;
                        if (topics.title.Length > 200)
                        {
                            topics.title = topics.title.Substring(0, 199);
                        }
                    }
                }
                else
                {
                    if (model.Tags != null)
                    {
                        topics.tags = model.Tags;
                        if (topics.tags.Length > 300)
                        {
                            topics.tags = topics.tags.Substring(0, 299);
                        }
                    }

                    topics.title = model.Title;
                }
                topics.userid = model.UserName;

                int isapproved = 1;
                if (Jugnoon.Settings.Configs.GeneralSettings.content_approval == 0 && !model.isAdmin && model.ReplyID == 0)
                {
                    isapproved = 0; // manual approval
                }
                topics.isapproved = (byte)isapproved;
                topics.isenabled  = 1;
                topics.replyid    = model.ReplyID;

                topics = await ForumTopicBLL.Process(_context, topics, model.isAdmin);

                if (model.Tags != "")
                {
                    // Process tags
                    TagsBLL.Process_Tags(_context, model.Tags, TagsBLL.Types.Forums, 0);
                }


                // Mail Procesing Section
                if (model.TopicID == 0 && model.ReplyID == 0)
                {
                    ProcessMail(topics.id, topics.replyid, topics.userid, model.GroupID, model.Description, model.Title);
                    // add newly added topic id in struct for user activity and group posting
                    //topics.topicid = topics.topicid;
                }

                if (model.ReplyID > 0)
                {
                    // topic is posted in reply
                    // redirect to topic
                    return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.replyid, topics.title, model.isAdmin) + "?status=posted"));
                }

                return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.id, topics.title, model.isAdmin) + "?status=posted"));
            }

            // initialize values
            if (model.ForumID == 0)
            {
                model.ForumList = await ForumBLLC.LoadItems(_context, new ForumEntity()
                {
                    loadall = true,

                    iscache = true
                });
            }
            model.Message = "Validation Error";
            return(View(model));
        }