Exemple #1
0
        private void PopulateControls()
        {
            if (HttpContext.Current == null)
            {
                return;
            }

            if (rootNode == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<ZoneList></ZoneList>");

            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "ModuleTitle", this.Title);
            XmlHelper.AddNode(doc, root, "ZoneTitle", CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "Title", GetZoneTitle(currentNode));
            XmlHelper.AddNode(doc, root, "Url", FormatUrl(currentNode));
            XmlHelper.AddNode(doc, root, "Target", (currentNode.OpenInNewWindow == true ? "_blank" : "_self"));
            XmlHelper.AddNode(doc, root, "ImageUrl", (currentNode != null ? currentNode.PrimaryImage : string.Empty));
            XmlHelper.AddNode(doc, root, "SecondImageUrl", (currentNode != null ? currentNode.SecondImage : string.Empty));

            if (ModuleConfiguration.ResourceFileDef.Length > 0 && ModuleConfiguration.ResourceKeyDef.Length > 0)
            {
                List <string> lstResourceKeys = ModuleConfiguration.ResourceKeyDef.SplitOnCharAndTrim(';');

                foreach (string item in lstResourceKeys)
                {
                    XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(ModuleConfiguration.ResourceFileDef, item));
                }
            }

            SiteMapNodeCollection allNodes = null;

            if (config.IsSubZone)
            {
                allNodes = startingNode.ChildNodes;
            }
            else
            {
                allNodes = startingNode.GetAllNodes();
            }

            foreach (SiteMapNode childNode in allNodes)
            {
                gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                if (gbNode == null)
                {
                    continue;
                }

                RenderNode(doc, root, gbNode);
            }

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc);
        }
Exemple #2
0
        public static string GetRangeZoneIdsToSemiColonSeparatedString(int siteId, int parentZoneId)
        {
            SiteMapDataSource siteMapDataSource = new SiteMapDataSource();

            siteMapDataSource.SiteMapProvider = "canhcamsite" + siteId.ToInvariantString();

            SiteMapNode rootNode     = siteMapDataSource.Provider.RootNode;
            SiteMapNode startingNode = null;

            if (rootNode == null)
            {
                return(null);
            }

            string listChildZoneIds = parentZoneId + ";";

            if (parentZoneId > -1)
            {
                SiteMapNodeCollection allNodes = rootNode.GetAllNodes();
                foreach (SiteMapNode childNode in allNodes)
                {
                    gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                    if (gbNode == null)
                    {
                        continue;
                    }

                    if (Convert.ToInt32(gbNode.Key) == parentZoneId)
                    {
                        startingNode = gbNode;
                        break;
                    }
                }
            }
            else
            {
                startingNode = rootNode;
            }

            if (startingNode == null)
            {
                return(string.Empty);
            }

            SiteMapNodeCollection childNodes = startingNode.GetAllNodes();

            foreach (gbSiteMapNode childNode in childNodes)
            {
                listChildZoneIds += childNode.Key + ";";
            }

            return(listChildZoneIds);
        }
Exemple #3
0
        private string GetDescription(gbSiteMapNode mapNode)
        {
            if (mapNode == null)
            {
                return(string.Empty);
            }

            string str = mapNode.Description;

            if (languageId > 0 && mapNode["Description" + languageId.ToString()] != null)
            {
                str = mapNode["Description" + languageId.ToString()];
            }

            return(str);
        }
Exemple #4
0
        private string GetZoneTitle(gbSiteMapNode mapNode)
        {
            if (mapNode == null)
            {
                return(string.Empty);
            }

            string title = mapNode.Title;

            if (languageId > 0 && mapNode["Title" + languageId.ToString()] != null)
            {
                title = mapNode["Title" + languageId.ToString()];
            }

            return(title);
        }
Exemple #5
0
        private void LoadSettings()
        {
            EnsureConfiguration();

            timeOffset = SiteUtils.GetUserTimeOffset();
            timeZone   = SiteUtils.GetUserTimeZone();

            languageId = WorkingCulture.LanguageId;
            newsId     = WebUtils.ParseInt32FromQueryString("NewsId", -1);

            isAdmin = WebUser.IsAdmin;
            if (!isAdmin)
            {
                isContentAdmin = WebUser.IsContentAdmin;
            }
            if ((!isAdmin) && (!isContentAdmin))
            {
                isSiteEditor = SiteUtils.UserIsSiteEditor();
            }

            basePage      = Page as CmsBasePage;
            userCanUpdate = NewsPermission.CanUpdate;
            currentUser   = SiteUtils.GetCurrentSiteUser();

            useFullUrlsForWebPage = WebConfigSettings.UseFullUrlsForWebPage;
            resolveFullUrlsForMenuItemProtocolDifferences = WebConfigSettings.ResolveFullUrlsForMenuItemProtocolDifferences;
            navigationSiteRoot = WebUtils.GetSiteRoot();
            if (resolveFullUrlsForMenuItemProtocolDifferences)
            {
                secureSiteRoot   = WebUtils.GetSecureSiteRoot();
                insecureSiteRoot = secureSiteRoot.Replace("https", "http");
            }

            isSecureRequest   = SiteUtils.IsSecureRequest();
            isMobileSkin      = SiteUtils.UseMobileSkin();
            siteMapDataSource = new SiteMapDataSource();
            siteMapDataSource.SiteMapProvider = "canhcamsite" + siteSettings.SiteId.ToInvariantString();

            rootNode     = siteMapDataSource.Provider.RootNode;
            currentNode  = SiteUtils.GetCurrentZoneSiteMapNode(rootNode);
            startingNode = rootNode;

            if (config.IsSubZone)
            {
                startingNode = currentNode;
            }
        }
Exemple #6
0
        private bool GetClickable(gbSiteMapNode mapNode)
        {
            if (mapNode == null)
            {
                return(false);
            }

            bool isClickable = false;

            if (languageId > 0)
            {
                if (mapNode["IsClickable" + languageId.ToString()] != null)
                {
                    isClickable = Convert.ToBoolean(mapNode["IsClickable" + languageId.ToString()]);
                }
            }
            else
            {
                isClickable = mapNode.IsClickable;
            }

            return(isClickable);
        }
Exemple #7
0
        public static XmlDocument BuildNewsDataXml(XmlDocument doc, XmlElement newsXml, News news, TimeZoneInfo timeZone,
                                                   double timeOffset, string editLink, int siteId = 1)
        {
            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, "ZoneId", news.ZoneID.ToInvariantString());

            SiteMapDataSource siteMapDataSource = new SiteMapDataSource();

            siteMapDataSource.SiteMapProvider = "canhcamsite" + siteId.ToInvariantString();

            SiteMapNode rootNode     = siteMapDataSource.Provider.RootNode;
            SiteMapNode startingNode = null;

            if (rootNode == null)
            {
                return(null);
            }

            if (news.ZoneID > -1)
            {
                SiteMapNodeCollection allNodes = rootNode.GetAllNodes();
                foreach (SiteMapNode childNode in allNodes)
                {
                    gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                    if (gbNode == null)
                    {
                        continue;
                    }

                    if (Convert.ToInt32(gbNode.Key) == news.ZoneID)
                    {
                        startingNode = gbNode;
                        XmlHelper.AddNode(doc, newsXml, "ZoneDescription", gbNode.Description);
                        XmlHelper.AddNode(doc, newsXml, "ZoneTitle", gbNode.Title);
                        break;
                    }
                }
            }

            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 != null && news.EndDate != DateTime.MaxValue)
            {
                XmlHelper.AddNode(doc, newsXml, "EndDate", FormatDate(news.EndDate, timeZone, timeOffset,
                                                                      ResourceHelper.GetResourceString("NewsResources", "NewsDateFormat")));
            }

            return(doc);
        }
Exemple #8
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();
        }
Exemple #9
0
        private string FormatUrl(gbSiteMapNode mapNode)
        {
            if (!GetClickable(mapNode))
            {
                return("#");
            }

            string url = string.Empty;

            if (WebConfigSettings.EnableHierarchicalFriendlyUrls)
            {
                url = mapNode.UrlExpand;
                if (languageId > 0 && mapNode["UrlExpand" + languageId.ToString()] != null)
                {
                    url = mapNode["UrlExpand" + languageId.ToString()];
                }
            }
            else
            {
                url = mapNode.Url;
                if (languageId > 0 && mapNode["Url" + languageId.ToString()] != null)
                {
                    url = mapNode["Url" + languageId.ToString()];
                }
            }

            string itemUrl     = Page.ResolveUrl(url);
            bool   useFullUrls = false;

            if (resolveFullUrlsForMenuItemProtocolDifferences)
            {
                if (isSecureRequest)
                {
                    if (
                        (!mapNode.UseSsl) &&
                        (!siteSettings.UseSslOnAllPages) &&
                        (url.StartsWith("~/"))
                        )
                    {
                        itemUrl     = insecureSiteRoot + url.Replace("~/", "/");
                        useFullUrls = true;
                    }
                }
                else
                {
                    if ((mapNode.UseSsl) || (siteSettings.UseSslOnAllPages))
                    {
                        if (url.StartsWith("~/"))
                        {
                            itemUrl     = secureSiteRoot + url.Replace("~/", "/");
                            useFullUrls = true;
                        }
                    }
                }
            }

            if (
                !useFullUrls &&
                useFullUrlsForWebPage &&
                url.StartsWith("~/")
                )
            {
                itemUrl = navigationSiteRoot + url.Replace("~/", "/");
            }

            return(itemUrl);
        }
Exemple #10
0
        private bool ShouldRender(gbSiteMapNode mapNode)
        {
            if (mapNode == null)
            {
                return(false);
            }

            if (
                languageId > 0 &&
                mapNode["Title" + languageId.ToString()] == null
                )
            {
                return(false);
            }

            if (mapNode.Roles == null)
            {
                if ((!isAdmin) && (!isContentAdmin) && (!isSiteEditor))
                {
                    return(false);
                }
            }
            else
            {
                if ((!isAdmin) && (mapNode.Roles.Count == 1) && (mapNode.Roles[0].ToString() == "Admins"))
                {
                    return(false);
                }

                if ((!isAdmin) && (!isContentAdmin) && (!isSiteEditor) && (!WebUser.IsInRoles(mapNode.Roles)))
                {
                    return(false);
                }
            }

            //if (!mapNode.IncludeInMenu && config.IsSubMenu) { return false; }
            if (!mapNode.IsPublished)
            {
                return(false);
            }

            if (config.ZonePosition > 0)
            {
                if ((mapNode.Position & config.ZonePosition) == 0)
                {
                    return(false);
                }
            }

            if ((mapNode.HideAfterLogin) && (Page.Request.IsAuthenticated))
            {
                return(false);
            }

            if ((!isMobileSkin) && (mapNode.PublishMode == mobileOnly))
            {
                return(false);
            }

            if ((isMobileSkin) && (mapNode.PublishMode == webOnly))
            {
                return(false);
            }

            return(true);
        }
Exemple #11
0
        private void RenderNode(XmlDocument doc, XmlElement xmlElement, gbSiteMapNode gbNode)
        {
            if (!ShouldRender(gbNode))
            {
                return;
            }

            XmlElement item = doc.CreateElement("Zone");

            xmlElement.AppendChild(item);

            XmlHelper.AddNode(doc, item, "ZoneId", gbNode.ZoneId.ToInvariantString());
            XmlHelper.AddNode(doc, item, "Depth", gbNode.Depth.ToInvariantString());
            XmlHelper.AddNode(doc, item, "ChildCount", gbNode.ChildNodes.Count.ToInvariantString());
            XmlHelper.AddNode(doc, item, "IsClickable", gbNode.IsClickable.ToString().ToLower());
            XmlHelper.AddNode(doc, item, "Url", FormatUrl(gbNode));
            XmlHelper.AddNode(doc, item, "Target", (gbNode.OpenInNewWindow == true ? "_blank" : "_self"));
            XmlHelper.AddNode(doc, item, "Title", GetZoneTitle(gbNode));
            XmlHelper.AddNode(doc, item, "Description", GetDescription(gbNode));
            XmlHelper.AddNode(doc, item, "ImageUrl", gbNode.PrimaryImage);

            List <Product> lstProducts = new List <Product>();

            if (config.ShowAllProducts)
            {
                string zoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, gbNode.ZoneId);
                if (config.MaxItemsToGet == 0)
                {
                    int iCount = Product.GetCountByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());
                }
                else if (config.MaxItemsToGet > 0)
                {
                    lstProducts = Product.GetPageByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition, 1, config.MaxItemsToGet);
                }
                else
                {
                    int iCount = Product.GetCountByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());

                    lstProducts = Product.GetPageByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition, 1, Math.Abs(config.MaxItemsToGet));
                }
            }
            else
            {
                if (config.MaxItemsToGet == 0)
                {
                    int iCount = Product.GetCount(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());
                }
                else if (config.MaxItemsToGet > 0)
                {
                    lstProducts = Product.GetPage(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition, 1, config.MaxItemsToGet);
                }
                else
                {
                    int iCount = Product.GetCount(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());

                    lstProducts = Product.GetPage(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition, 1, Math.Abs(config.MaxItemsToGet));
                }
            }

            foreach (Product product in lstProducts)
            {
                XmlElement productXml = doc.CreateElement("Product");
                item.AppendChild(productXml);

                ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser));
            }

            if ((currentNode != null) &&
                (currentNode.ZoneGuid == gbNode.ZoneGuid)    // Selected
                )
            {
                XmlHelper.AddNode(doc, item, "IsActive", "true");
            }
            else
            {
                XmlHelper.AddNode(doc, item, "IsActive", "false");
            }

            if (gbNode.ChildNodes.Count > 0)
            {
                foreach (SiteMapNode childNode in gbNode.ChildNodes)
                {
                    gbSiteMapNode gbChildNode = childNode as gbSiteMapNode;
                    if (gbChildNode == null)
                    {
                        continue;
                    }

                    RenderNode(doc, item, gbChildNode);
                }
            }
        }