Esempio n. 1
0
        public static string BuildEditLink(News news, CmsBasePage basePage, bool userCanUpdate, SiteUser currentUser)
        {
            if (PageView.UserViewMode == PageViewMode.View)
            {
                return(string.Empty);
            }

            if (!basePage.UserCanAuthorizeZone(news.ZoneID))
            {
                return(string.Empty);
            }



            if (WebConfigSettings.EnableContentWorkflow && basePage.SiteInfo.EnableContentWorkflow && !news.IsPublished)
            {
                if (news.StateId.HasValue)
                {
                    int workflowId           = WorkflowHelper.GetWorkflowId(News.FeatureGuid);
                    int firstWorkflowStateId = WorkflowHelper.GetFirstWorkflowStateId(workflowId);

                    if (news.StateId.Value == firstWorkflowStateId)
                    {
                        if (currentUser == null)
                        {
                            return(string.Empty);
                        }
                    }
                }
            }

            return(string.Empty);
        }
Esempio n. 2
0
        protected void PopulateControls()
        {
            if (parametersAreInvalid)
            {
                pnlInnerWrap.Visible = false;
                return;
            }

            if (news.IsDeleted)
            {
                if (WebConfigSettings.Custom404Page.Length > 0)
                {
                    Server.Transfer(WebConfigSettings.Custom404Page);
                }
                else
                {
                    Server.Transfer("~/PageNotFound.aspx");
                }

                return;
            }

            if (news.IsPublished && news.EndDate < DateTime.UtcNow)
            {
                expired.Visible = true;
                //http://support.google.com/webmasters/bin/answer.py?hl=en&answer=40132
                // 410 means the resource is gone but once existed
                // google treats it as more permanent than a 404
                // and it should result in de-indexing the content
                Response.StatusCode        = 410;
                Response.StatusDescription = "Content Expired";
                if (
                    !NewsPermission.CanUpdate ||
                    !basePage.UserCanAuthorizeZone(news.ZoneID)
                    )
                {
                    pnlInnerWrap.Visible = false;
                    return;
                }
            }

            // if not published only the editor can see it
            if (!news.IsPublished)
            {
                bool stopRedirect = false;

                if (WebConfigSettings.EnableContentWorkflow && basePage.SiteInfo.EnableContentWorkflow)
                {
                    if (news.StateId.HasValue && WorkflowHelper.UserHasStatePermission(workflowId, news.StateId.Value))
                    {
                        stopRedirect = true;
                    }
                }
                else
                {
                    if (
                        (currentUser != null && currentUser.UserGuid == news.UserGuid) ||
                        (NewsPermission.CanUpdate && basePage.UserCanAuthorizeZone(news.ZoneID))
                        )
                    {
                        stopRedirect = true;
                    }
                }

                if (!stopRedirect)
                {
                    pnlInnerWrap.Visible = false;
                    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentZoneUrl());
                    return;
                }
            }

            SetupMetaTags();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<NewsDetail></NewsDetail>");
            XmlElement root = doc.DocumentElement;

            //XmlHelper.AddNode(doc, root, "ModuleTitle", module.ModuleTitle);
            XmlHelper.AddNode(doc, root, "ZoneTitle", basePage.CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "ZoneDescription", basePage.CurrentZone.Description);
            XmlHelper.AddNode(doc, root, "ViewMore", NewsResources.NewsMoreLinkText);
            XmlHelper.AddNode(doc, root, "Title", news.Title);
            XmlHelper.AddNode(doc, root, "SubTitle", news.SubTitle);
            XmlHelper.AddNode(doc, root, "ZoneUrl", SiteUtils.GetCurrentZoneUrl());

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

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

            XmlHelper.AddNode(doc, root, "EditLink", NewsHelper.BuildEditLink(news, basePage, userCanUpdate, currentUser));

            //XmlHelper.AddNode(doc, root, "ViewCVLink", GetCVListLink(news.NewsID, news.CommentCount, NewsPermission.CanManageComment));
            XmlHelper.AddNode(doc, root, "ApplyText", NewsResources.JobApplyLable);
            XmlHelper.AddNode(doc, root, "ApplyUrl", this.siteRoot + "/News/JobApplyDialog.aspx?zoneid=" + zoneId.ToString() + "&NewsID=" + newsId.ToString());

            XmlHelper.AddNode(doc, root, "ShowOption", news.ShowOption.ToString());

            XmlHelper.AddNode(doc, root, "CreatedDate", FormatDate(news.StartDate, NewsResources.NewsDateFormat));
            XmlHelper.AddNode(doc, root, "CreatedTime", FormatDate(news.StartDate, NewsResources.NewsTimeFormat));
            XmlHelper.AddNode(doc, root, "CreatedDD", FormatDate(news.StartDate, "dd"));
            XmlHelper.AddNode(doc, root, "CreatedYY", FormatDate(news.StartDate, "yy"));
            XmlHelper.AddNode(doc, root, "CreatedYYYY", FormatDate(news.StartDate, "yyyy"));
            XmlHelper.AddNode(doc, root, "CreatedMM", FormatDate(news.StartDate, "MM"));
            if (WorkingCulture.DefaultName.ToLower() == "vi-vn")
            {
                string monthVI = "Tháng " + FormatDate(news.StartDate, "MM");
                XmlHelper.AddNode(doc, root, "CreatedMMM", monthVI);
                XmlHelper.AddNode(doc, root, "CreatedMMMM", monthVI);
            }
            else
            {
                XmlHelper.AddNode(doc, root, "CreatedMMM", FormatDate(news.StartDate, "MMM"));
                XmlHelper.AddNode(doc, root, "CreatedMMMM", FormatDate(news.StartDate, "MMMM"));
            }

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

            if (displaySettings.ShowNextPreviousLink)
            {
                BuildNextPreviousXml(doc, root);
            }

            XmlHelper.AddNode(doc, root, "FacebookLike", RenderFacebookLike());
            XmlHelper.AddNode(doc, root, "PlusOne", RenderPlusOne());
            XmlHelper.AddNode(doc, root, "TweetThis", RenderTweetThis());
            XmlHelper.AddNode(doc, root, "Print", RenderPrinter());
            XmlHelper.AddNode(doc, root, "Email", RenderEmailSubject());
            XmlHelper.AddNode(doc, root, "FullUrl", NewsHelper.FormatNewsUrl(news.Url, news.NewsID, news.ZoneID));

            if (displaySettings.ShowAttribute)
            {
                BuildNewsAttributesXml(doc, root, languageId);
            }

            BuildNewsImagesXml(doc, root);

            #region Start news other

            BuildNewsOtherXml(doc, root, zoneId, pageNumber, config.RelatedItemsToShow, out totalPages);
            if (NewsHelper.IsAjaxRequest(Request) && WebUtils.ParseBoolFromQueryString("isajax", false))
            {
                Response.Write(XmlHelper.TransformXML(SiteUtils.GetXsltBasePath("news", config.XsltFileNameDetailPage), doc));
                Response.End();
                return;
            }

            string pageUrlLeaveOutPageNumber = NewsHelper.FormatNewsUrl(news.Url, news.NewsID, news.ZoneID);

            if (config.HidePaginationOnDetailPage)
            {
                divPager.Visible = false;
            }
            else
            {
                string pageUrl = pageUrlLeaveOutPageNumber;
                if (WebUtils.ParseInt32FromQueryString("NewsId", -1) == -1 && config.LoadFirstItem)
                {
                    pageUrl = SiteUtils.GetCurrentZoneUrl();
                }

                if (pageUrl.Contains("?"))
                {
                    pageUrl += "&amp;pagenumber={0}";
                }
                else
                {
                    pageUrl += "?pagenumber={0}";
                }
                pgr.PageURLFormat = pageUrl;
                pgr.ShowFirstLast = true;
                pgr.PageSize      = config.PageSize;
                pgr.PageCount     = totalPages;
                pgr.CurrentIndex  = pageNumber;
                divPager.Visible  = (totalPages > 1);
            }

            if (WebUtils.ParseInt32FromQueryString("pagenumber", -1) == 1)
            {
                basePage.AdditionalMetaMarkup += "\n<link rel=\"canonical\" href=\"" + pageUrlLeaveOutPageNumber + "\" />";
            }

            #endregion

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("news", config.XsltFileNameDetailPage), doc);

            News.IncrementViewedCount(news.NewsID);
        }
Esempio n. 3
0
        protected void PopulateControls()
        {
            if (parametersAreInvalid)
            {
                pnlInnerWrap.Visible = false;
                return;
            }

            if (product.IsDeleted)
            {
                if (WebConfigSettings.Custom404Page.Length > 0)
                {
                    Server.Transfer(WebConfigSettings.Custom404Page);
                }
                else
                {
                    Server.Transfer("~/PageNotFound.aspx");
                }

                return;
            }

            if (product.IsPublished && product.EndDate < DateTime.UtcNow)
            {
                expired.Visible = true;
                //http://support.google.com/webmasters/bin/answer.py?hl=en&answer=40132
                // 410 means the resource is gone but once existed
                // google treats it as more permanent than a 404
                // and it should result in de-indexing the content
                Response.StatusCode        = 410;
                Response.StatusDescription = "Content Expired";
                if (
                    !ProductPermission.CanUpdate ||
                    !basePage.UserCanAuthorizeZone(product.ZoneId)
                    )
                {
                    pnlInnerWrap.Visible = false;
                    return;
                }
            }

            // if not published only the editor can see it
            if ((!product.IsPublished) || (product.StartDate > DateTime.UtcNow))
            {
                bool stopRedirect = false;
                if (
                    (currentUser != null && currentUser.UserGuid == product.UserGuid) ||
                    ((ProductPermission.CanViewList || ProductPermission.CanUpdate) && basePage.UserCanAuthorizeZone(product.ZoneId))
                    )
                {
                    stopRedirect = true;
                }

                if (!stopRedirect)
                {
                    pnlInnerWrap.Visible = false;
                    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentZoneUrl());
                    return;
                }
            }

            SetupMetaTags();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<ProductDetail></ProductDetail>");
            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "ZoneTitle", basePage.CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "Title", product.Title);
            XmlHelper.AddNode(doc, root, "SubTitle", product.SubTitle);
            XmlHelper.AddNode(doc, root, "ZoneUrl", SiteUtils.GetCurrentZoneUrl());

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

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

            XmlHelper.AddNode(doc, root, "EditLink", ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser));

            XmlHelper.AddNode(doc, root, "ProductId", product.ProductId.ToString());
            XmlHelper.AddNode(doc, root, "ShowOption", product.ShowOption.ToString());
            XmlHelper.AddNode(doc, root, "ProductType", product.ProductType.ToString());

            XmlHelper.AddNode(doc, root, "Code", product.Code);
            if (product.Price > 0)
            {
                XmlHelper.AddNode(doc, root, "Price", ProductHelper.FormatPrice(product.Price, true));
            }
            if (product.OldPrice > 0)
            {
                XmlHelper.AddNode(doc, root, "OldPrice", ProductHelper.FormatPrice(product.OldPrice, true));
            }

            XmlHelper.AddNode(doc, root, "CreatedDate", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset,
                                                                                 ProductResources.ProductDateFormat));
            XmlHelper.AddNode(doc, root, "CreatedTime", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset,
                                                                                 ProductResources.ProductTimeFormat));
            XmlHelper.AddNode(doc, root, "CreatedDD", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "dd"));
            XmlHelper.AddNode(doc, root, "CreatedYY", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "yy"));
            XmlHelper.AddNode(doc, root, "CreatedYYYY", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "yyyy"));
            XmlHelper.AddNode(doc, root, "CreatedMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MM"));
            if (WorkingCulture.DefaultName.ToLower() == "vi-vn")
            {
                string monthVI = "Tháng " + ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MM");
                XmlHelper.AddNode(doc, root, "CreatedMMM", monthVI);
                XmlHelper.AddNode(doc, root, "CreatedMMMM", monthVI);
            }
            else
            {
                XmlHelper.AddNode(doc, root, "CreatedMMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MMM"));
                XmlHelper.AddNode(doc, root, "CreatedMMMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MMMM"));
            }

            XmlHelper.AddNode(doc, root, "Code", product.Code);
            XmlHelper.AddNode(doc, root, "BriefContent", product.BriefContent);
            XmlHelper.AddNode(doc, root, "FullContent", product.FullContent);
            XmlHelper.AddNode(doc, root, "ViewCount", product.ViewCount.ToString());
            XmlHelper.AddNode(doc, root, "FileUrl", product.FileAttachment);

            if (
                displaySettings.ShowNextPreviousLink &&
                !config.LoadFirstProduct
                )
            {
                BuildNextPreviousXml(doc, root);
            }

            string pageUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId);

            XmlHelper.AddNode(doc, root, "FacebookLike", RenderFacebookLike());
            XmlHelper.AddNode(doc, root, "PlusOne", RenderPlusOne());
            XmlHelper.AddNode(doc, root, "TweetThis", RenderTweetThis());
            XmlHelper.AddNode(doc, root, "Print", RenderPrinter());
            //XmlHelper.AddNode(doc, root, "Email", RenderEmailSubject());
            XmlHelper.AddNode(doc, root, "FullUrl", pageUrl);

            BuildProductRelatedXml(doc, root, languageId);

            if (ProductConfiguration.EnableComparing)
            {
                XmlHelper.AddNode(doc, root, "CompareListUrl", siteRoot + "/Product/Compare.aspx");
            }

            if (displaySettings.ShowAttribute)
            {
                BuildProductAttributesXml(doc, root, languageId);
            }

            BuildProductPropertiesXml(doc, root, languageId);
            BuildProductMediaXml(doc, root);
            BuildProductOtherXml(doc, root, zoneId, pageNumber, config.OtherProductsPerPage, out totalPages);

            if (config.LoadFirstProduct)
            {
                pageUrl = SiteUtils.GetCurrentZoneUrl();
            }

            if (pageUrl.Contains("?"))
            {
                pageUrl += "&amp;pagenumber={0}";
            }
            else
            {
                pageUrl += "?pagenumber={0}";
            }

            pgr.PageURLFormat = pageUrl;
            pgr.ShowFirstLast = true;
            pgr.PageSize      = config.OtherProductsPerPage;
            pgr.PageCount     = totalPages;
            pgr.CurrentIndex  = pageNumber;
            divPager.Visible  = (totalPages > 1);

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", config.XsltFileNameDetailPage), doc);

            if (Page.Header == null)
            {
                return;
            }

            string canonicalUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId);

            if (SiteUtils.IsSecureRequest() && (!basePage.CurrentPage.RequireSsl) && (!basePage.SiteInfo.UseSslOnAllPages))
            {
                if (WebConfigSettings.ForceHttpForCanonicalUrlsThatDontRequireSsl)
                {
                    canonicalUrl = canonicalUrl.Replace("https:", "http:");
                }
            }

            //LoadWorkflow();

            //Literal link = new Literal();
            //link.ID = "newsurl";
            //link.Text = "\n<link rel='canonical' href='" + canonicalUrl + "' />";

            //Page.Header.Controls.Add(link);

            Product.IncrementViewCount(product.ProductId);
        }