예제 #1
0
        protected void btnDeleteImage_Click(object sender, EventArgs e)
        {
            try
            {
                bool isDeleted = false;
                foreach (GridDataItem data in grid.SelectedItems)
                {
                    Guid guid = new Guid(data.GetDataKeyValue("Guid").ToString());

                    ContentMedia media = new ContentMedia(guid);
                    if (media != null && media.Guid != Guid.Empty)
                    {
                        NewsHelper.DeleteImages(media, fileSystem, imageFolderPath);
                        ContentMedia.Delete(guid);

                        isDeleted = true;
                    }
                }

                if (isDeleted)
                {
                    grid.Rebind();
                    updImages.Update();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
예제 #2
0
        public static XmlDocument BuildNewsDataXml(XmlDocument doc, XmlElement newsXml, News news, TimeZoneInfo timeZone, double timeOffset, string editLink)
        {
            XmlHelper.AddNode(doc, newsXml, "Title", news.Title);
            XmlHelper.AddNode(doc, newsXml, "SubTitle", news.SubTitle);
            XmlHelper.AddNode(doc, newsXml, "Url", NewsHelper.FormatNewsUrl(news.Url, news.NewsID, news.ZoneID));
            XmlHelper.AddNode(doc, newsXml, "Target", NewsHelper.GetNewsTarget(news.OpenInNewWindow));
            XmlHelper.AddNode(doc, newsXml, "ShowOption", news.ShowOption.ToString());
            XmlHelper.AddNode(doc, newsXml, "NewsId", news.NewsID.ToString()); //2016-08-11

            string imageFolderPath          = NewsHelper.MediaFolderPath(news.SiteId, news.NewsID);
            string thumbnailImageFolderPath = imageFolderPath + "thumbs/";

            if (news.ImageFile.Length > 0)
            {
                XmlHelper.AddNode(doc, newsXml, "ImageUrl", VirtualPathUtility.ToAbsolute(imageFolderPath + news.ImageFile));
            }
            if (news.ThumbnailFile.Length > 0)
            {
                XmlHelper.AddNode(doc, newsXml, "ThumbnailUrl", VirtualPathUtility.ToAbsolute(thumbnailImageFolderPath + news.ThumbnailFile));
            }

            XmlHelper.AddNode(doc, newsXml, "EditLink", editLink);

            XmlHelper.AddNode(doc, newsXml, "BriefContent", news.BriefContent);
            XmlHelper.AddNode(doc, newsXml, "FullContent", news.FullContent);
            XmlHelper.AddNode(doc, newsXml, "ViewCount", news.Viewed.ToString());
            XmlHelper.AddNode(doc, newsXml, "CommentCount", news.CommentCount.ToString());
            XmlHelper.AddNode(doc, newsXml, "FileUrl", news.FileAttachment);

            object startDate = news.StartDate;

            XmlHelper.AddNode(doc, newsXml, "CreatedDate", FormatDate(startDate, timeZone, timeOffset, ResourceHelper.GetResourceString("NewsResources", "NewsDateFormat")));
            XmlHelper.AddNode(doc, newsXml, "CreatedTime", FormatDate(startDate, timeZone, timeOffset, ResourceHelper.GetResourceString("NewsResources", "NewsTimeFormat")));
            XmlHelper.AddNode(doc, newsXml, "CreatedDD", FormatDate(startDate, timeZone, timeOffset, "dd"));
            XmlHelper.AddNode(doc, newsXml, "CreatedYY", FormatDate(startDate, timeZone, timeOffset, "yy"));
            XmlHelper.AddNode(doc, newsXml, "CreatedYYYY", FormatDate(startDate, timeZone, timeOffset, "yyyy"));
            XmlHelper.AddNode(doc, newsXml, "CreatedMM", FormatDate(startDate, timeZone, timeOffset, "MM"));
            if (System.Globalization.CultureInfo.CurrentCulture.Name.ToLower() == "vi-vn")
            {
                string monthVI = "Tháng " + FormatDate(startDate, timeZone, timeOffset, "MM");
                XmlHelper.AddNode(doc, newsXml, "CreatedMMM", monthVI);
                XmlHelper.AddNode(doc, newsXml, "CreatedMMMM", monthVI);
            }
            else
            {
                XmlHelper.AddNode(doc, newsXml, "CreatedMMM", FormatDate(startDate, timeZone, timeOffset, "MMM"));
                XmlHelper.AddNode(doc, newsXml, "CreatedMMMM", FormatDate(startDate, timeZone, timeOffset, "MMMM"));
            }

            if (news.EndDate != DateTime.MaxValue)
            {
                XmlHelper.AddNode(doc, newsXml, "EndDate", FormatDate(news.EndDate, timeZone, timeOffset, ResourceHelper.GetResourceString("NewsResources", "NewsDateFormat")));
            }

            return(doc);
        }
예제 #3
0
        protected void btnUpdateImage_Click(object sender, EventArgs e)
        {
            if (news == null)
            {
                return;
            }

            //txtImageTitle.Text = txtImageTitle.Text.Trim();
            NewsHelper.VerifyNewsFolders(fileSystem, imageFolderPath);

            foreach (UploadedFile file in uplImageFile.UploadedFiles)
            {
                string ext = file.GetExtension();
                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                {
                    ContentMedia image = new ContentMedia();
                    image.SiteGuid    = siteSettings.SiteGuid;
                    image.ContentGuid = news.NewsGuid;
                    //image.Title = txtImageTitle.Text;
                    image.DisplayOrder = 0;

                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    if (image.MediaFile == newFileName)
                    {
                        // an existing image delete the old one
                        fileSystem.DeleteFile(newImagePath);
                    }
                    else
                    {
                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                        int i = 1;
                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                        {
                            newFileName = i.ToInvariantString() + newFileName;
                            i          += 1;
                        }
                    }

                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    file.SaveAs(Server.MapPath(newImagePath));

                    image.MediaFile       = newFileName;
                    image.ThumbnailFile   = newFileName;
                    image.ThumbNailWidth  = displaySettings.ThumbnailWidth;
                    image.ThumbNailHeight = displaySettings.ThumbnailHeight;
                    image.Save();
                    NewsHelper.ProcessImage(image, fileSystem, imageFolderPath, file.FileName, NewsHelper.GetColor(displaySettings.ResizeBackgroundColor));
                }
            }
            grid.Rebind();
            updImages.Update();
        }
예제 #4
0
        protected virtual void LoadSettings()
        {
            currentUser = SiteUtils.GetCurrentSiteUser();
            if (currentUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot);
            }
            if (newsId > -1)
            {
                news = new News(siteSettings.SiteId, newsId);
                if (news != null && news.NewsID > 0)
                {
                    KLnews = new KLNews(news.NewsID, 0);
                    if (news.IsDeleted)
                    {
                        SiteUtils.RedirectToEditAccessDeniedPage();
                        return;
                    }
                    newsType        = news.NewsType;
                    imageFolderPath = NewsHelper.MediaFolderPath(siteSettings.SiteId, news.NewsID);
                }
            }

            shortcontent.ImageManager.ViewPaths   = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };
            shortcontent.ImageManager.UploadPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };
            shortcontent.ImageManager.DeletePaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };


            fullcontent.ImageManager.ViewPaths   = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };
            fullcontent.ImageManager.UploadPaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };
            fullcontent.ImageManager.DeletePaths = new string[] { AuthorHepper.PublicFolderPath(siteSettings.SiteId, currentUser.UserId) };

            FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider];

            if (p != null)
            {
                fileSystem = p.GetFileSystem();
            }
        }
예제 #5
0
        public static void SendApprovalRequestNotification(
            SmtpSettings smtpSettings,
            SiteSettings siteSettings,
            int workflowId,
            SiteUser submittingUser,
            News draftNews
            )
        {
            if (!draftNews.StateId.HasValue)
            {
                return;
            }

            WorkflowState workflowState = WorkflowHelper.GetWorkflowState(workflowId, draftNews.StateId.Value);

            if (workflowState == null || workflowState.StateId == -1)
            {
                return;
            }

            if (workflowState.ReviewRoles.Length == 0 ||
                workflowState.NotifyTemplate.Length == 0)    //"ApprovalRequestNotification"
            {
                return;
            }

            string approvalRoles = workflowState.ReviewRoles;

            gbSiteMapNode gbNode = SiteUtils.GetSiteMapNodeByZoneId(draftNews.ZoneID);

            if (gbNode != null)
            {
                List <string> authorizedRoles = gbNode.AuthorizedRoles.SplitOnCharAndTrim(';');
                List <string> reviewRoles     = workflowState.ReviewRoles.SplitOnCharAndTrim(';');

                if (authorizedRoles.Count > 0 && reviewRoles.Count > 0)
                {
                    approvalRoles = string.Empty;

                    foreach (string reviewRole in reviewRoles)
                    {
                        foreach (string role in authorizedRoles)
                        {
                            if (reviewRole.ToLower() == role.ToLower())
                            {
                                approvalRoles += reviewRole + ";";
                            }
                        }
                    }
                }
            }

            List <string> emailAddresses = SiteUser.GetEmailAddresses(siteSettings.SiteId, approvalRoles);

            int queuedMessageCount = 0;

            EmailTemplate template        = EmailTemplate.Get(siteSettings.SiteId, workflowState.NotifyTemplate);
            string        subject         = template.Subject.Replace("{SiteName}", siteSettings.SiteName);
            string        messageTemplate = template.HtmlBody;

            List <string> emailTo = (template.ToAddresses.Length > 0 ? ";" + template.ToAddresses : "").SplitOnCharAndTrim(';');

            string emailToAddress = string.Empty;

            foreach (string email in emailAddresses)
            {
                if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    continue;
                }
                if (!Email.IsValidEmailAddressSyntax(email))
                {
                    continue;
                }

                if (!emailToAddress.Contains(email + ";"))
                {
                    emailToAddress += email + ";";
                }
            }
            foreach (string email in emailTo)
            {
                if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    continue;
                }
                if (!Email.IsValidEmailAddressSyntax(email))
                {
                    continue;
                }

                if (!emailToAddress.Contains(email + ";"))
                {
                    emailToAddress += email + ";";
                }
            }

            string replyEmail = submittingUser.Email;

            if (template.ReplyToAddress.Length > 0)
            {
                replyEmail += ";" + template.ReplyToAddress;
            }

            string fromEmailAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias);

            StringBuilder message = new StringBuilder();

            message.Append(messageTemplate);
            message.Replace("{Title}", draftNews.Title);
            message.Replace("{SubmittedDate}", DateTimeHelper.GetLocalTimeString(draftNews.ApprovedUtc, SiteUtils.GetUserTimeZone(), SiteUtils.GetUserTimeOffset()));
            message.Replace("{SubmittedBy}", submittingUser.Name);
            message.Replace("{ContentUrl}", NewsHelper.FormatNewsUrl(draftNews.Url, draftNews.NewsID, draftNews.ZoneID));

            EmailMessageTask messageTask = new EmailMessageTask(smtpSettings);

            messageTask.SiteGuid       = siteSettings.SiteGuid;
            messageTask.EmailFrom      = siteSettings.DefaultEmailFromAddress;
            messageTask.EmailFromAlias = fromEmailAlias;
            messageTask.EmailReplyTo   = replyEmail;
            messageTask.EmailTo        = emailToAddress;
            messageTask.EmailCc        = template.CcAddresses;
            messageTask.EmailBcc       = template.BccAddresses;
            messageTask.UseHtml        = true;
            messageTask.Subject        = subject;
            messageTask.HtmlBody       = message.ToString();
            messageTask.QueueTask();
            queuedMessageCount += 1;

            //Email.Send(
            //        smtpSettings,
            //        siteSettings.DefaultEmailFromAddress,
            //        siteSettings.DefaultFromEmailAlias,
            //        submittingUser.Email,
            //        email,
            //        string.Empty,
            //        string.Empty,
            //        messageSubject,
            //        message.ToString(),
            //        false,
            //        Email.PriorityNormal);

            WebTaskManager.StartOrResumeTasks();
        }