Exemplo n.º 1
0
        public void LoadPageControls()
        {
            this.CurrentWebPage.Header.Controls.Add(new Literal {
                Text = "\r\n"
            });

            List <HtmlMeta> lstMD = GetHtmlMeta(this.CurrentWebPage.Header);

            HtmlMeta metaGenerator = new HtmlMeta();

            metaGenerator.Name    = "generator";
            metaGenerator.Content = SiteData.CarrotCakeCMSVersion;
            this.CurrentWebPage.Header.Controls.Add(metaGenerator);
            this.CurrentWebPage.Header.Controls.Add(new Literal {
                Text = "\r\n"
            });

            if (guidContentID == SiteData.CurrentSiteID && SiteData.IsPageReal)
            {
                IsPageTemplate = true;
            }

            if (theSite != null && pageContents != null)
            {
                if (theSite.BlockIndex || pageContents.BlockIndex)
                {
                    bool     bCrawlExist = false;
                    HtmlMeta metaNoCrawl = new HtmlMeta();
                    metaNoCrawl.Name = "robots";

                    if (lstMD.Where(x => x.Name == "robots").Count() > 0)
                    {
                        metaNoCrawl = lstMD.Where(x => x.Name == "robots").FirstOrDefault();
                        bCrawlExist = true;
                    }

                    metaNoCrawl.Content = "noindex,nofollow,noarchive";

                    if (!bCrawlExist)
                    {
                        this.CurrentWebPage.Header.Controls.Add(metaNoCrawl);
                        this.CurrentWebPage.Header.Controls.Add(new Literal {
                            Text = "\r\n"
                        });
                    }
                }
            }

            InsertSpecialCtrl(this.CurrentWebPage.Header, ControlLocation.Header);

            if (pageContents != null)
            {
                HtmlMeta metaDesc   = new HtmlMeta();
                HtmlMeta metaKey    = new HtmlMeta();
                bool     bDescExist = false;
                bool     bKeyExist  = false;

                if (lstMD.Where(x => x.Name == "description").Count() > 0)
                {
                    metaDesc   = lstMD.Where(x => x.Name == "description").FirstOrDefault();
                    bDescExist = true;
                }
                if (lstMD.Where(x => x.Name == "keywords").Count() > 0)
                {
                    metaKey   = lstMD.Where(x => x.Name == "keywords").FirstOrDefault();
                    bKeyExist = true;
                }

                metaDesc.Name    = "description";
                metaKey.Name     = "keywords";
                metaDesc.Content = String.IsNullOrEmpty(pageContents.MetaDescription) ? theSite.MetaDescription : pageContents.MetaDescription;
                metaKey.Content  = String.IsNullOrEmpty(pageContents.MetaKeyword) ? theSite.MetaKeyword : pageContents.MetaKeyword;

                int indexPos = 6;
                if (this.CurrentWebPage.Header.Controls.Count > indexPos)
                {
                    if (!String.IsNullOrEmpty(metaDesc.Content) && !bDescExist)
                    {
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, new Literal {
                            Text = "\r\n"
                        });
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, metaDesc);
                    }
                    if (!String.IsNullOrEmpty(metaKey.Content) && !bKeyExist)
                    {
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, new Literal {
                            Text = "\r\n"
                        });
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, metaKey);
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(metaDesc.Content) && !bDescExist)
                    {
                        this.CurrentWebPage.Header.Controls.Add(metaDesc);
                        this.CurrentWebPage.Header.Controls.Add(new Literal {
                            Text = "\r\n"
                        });
                    }
                    if (!String.IsNullOrEmpty(metaKey.Content) && !bKeyExist)
                    {
                        this.CurrentWebPage.Header.Controls.Add(metaKey);
                        this.CurrentWebPage.Header.Controls.Add(new Literal {
                            Text = "\r\n"
                        });
                    }
                }

                metaDesc.Visible = !String.IsNullOrEmpty(metaDesc.Content);
                metaKey.Visible  = !String.IsNullOrEmpty(metaKey.Content);
            }

            contCenter = new ContentContainer();
            contLeft   = new ContentContainer();
            contRight  = new ContentContainer();

            if (pageContents != null)
            {
                using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                    PageViewType pvt            = pageHelper.GetBlogHeadingFromURL(theSite, SiteData.CurrentScriptName);
                    string       sTitleAddendum = pvt.ExtraTitle;

                    if (!String.IsNullOrEmpty(sTitleAddendum))
                    {
                        if (!String.IsNullOrEmpty(pageContents.PageHead))
                        {
                            pageContents.PageHead = pageContents.PageHead.Trim() + ": " + sTitleAddendum;
                        }
                        else
                        {
                            pageContents.PageHead = sTitleAddendum;
                        }
                        pageContents.TitleBar = pageContents.TitleBar.Trim() + ": " + sTitleAddendum;
                    }

                    PagedDataSummary pd = (PagedDataSummary)cu.FindControl(typeof(PagedDataSummary), this.CurrentWebPage);

                    if (pd != null)
                    {
                        PagedDataSummaryTitleOption titleOpts = pd.TypeLabelPrefixes.Where(x => x.KeyValue == pvt.CurrentViewType).FirstOrDefault();

                        if (titleOpts == null &&
                            (pvt.CurrentViewType == PageViewType.ViewType.DateDayIndex ||
                             pvt.CurrentViewType == PageViewType.ViewType.DateMonthIndex ||
                             pvt.CurrentViewType == PageViewType.ViewType.DateYearIndex))
                        {
                            titleOpts = pd.TypeLabelPrefixes.Where(x => x.KeyValue == PageViewType.ViewType.DateIndex).FirstOrDefault();
                        }

                        if (titleOpts != null && !String.IsNullOrEmpty(titleOpts.FormatText))
                        {
                            pvt.ExtraTitle = string.Format(titleOpts.FormatText, pvt.RawValue);
                            sTitleAddendum = pvt.ExtraTitle;
                        }

                        if (titleOpts != null && !String.IsNullOrEmpty(titleOpts.LabelText))
                        {
                            pageContents.PageHead    = titleOpts.LabelText + " " + sTitleAddendum;
                            pageContents.NavMenuText = pageContents.PageHead;
                            pageContents.TitleBar    = pageContents.PageHead;
                        }
                    }
                }

                this.CurrentWebPage.Title = SetPageTitle(pageContents);

                DateTime dtModified = theSite.ConvertSiteTimeToLocalServer(pageContents.EditDate);
                string   strModifed = dtModified.ToString("r");
                HttpContext.Current.Response.AppendHeader("Last-Modified", strModifed);
                HttpContext.Current.Response.Cache.SetLastModified(dtModified);

                DateTime dtExpire = DateTime.Now.AddSeconds(15);

                contCenter.Text = pageContents.PageText;
                contLeft.Text   = pageContents.LeftPageText;
                contRight.Text  = pageContents.RightPageText;

                contCenter.DatabaseKey = pageContents.Root_ContentID;
                contLeft.DatabaseKey   = pageContents.Root_ContentID;
                contRight.DatabaseKey  = pageContents.Root_ContentID;

                pageContents = CMSConfigHelper.IdentifyLinkAsInactive(pageContents);

                if (SecurityData.IsAuthenticated)
                {
                    HttpContext.Current.Response.Cache.SetNoServerCaching();
                    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    dtExpire = DateTime.Now.AddMinutes(-10);
                    HttpContext.Current.Response.Cache.SetExpires(dtExpire);

                    if (!SecurityData.AdvancedEditMode)
                    {
                        if (SecurityData.IsAdmin || SecurityData.IsSiteEditor)
                        {
                            if (!SiteData.IsPageSampler && !IsPageTemplate)
                            {
                                Control editor = this.CurrentWebPage.LoadControl(SiteFilename.EditNotifierControlPath);
                                this.CurrentWebPage.Form.Controls.Add(editor);
                            }
                        }
                    }
                    else
                    {
                        contCenter.IsAdminMode = true;
                        contLeft.IsAdminMode   = true;
                        contRight.IsAdminMode  = true;

                        contCenter.ZoneChar = "c";
                        contLeft.ZoneChar   = "l";
                        contRight.ZoneChar  = "r";

                        contCenter.TextZone = ContentContainer.TextFieldZone.TextCenter;
                        contLeft.TextZone   = ContentContainer.TextFieldZone.TextLeft;
                        contRight.TextZone  = ContentContainer.TextFieldZone.TextRight;

                        contCenter.Text = pageContents.PageText;
                        contLeft.Text   = pageContents.LeftPageText;
                        contRight.Text  = pageContents.RightPageText;

                        Control editor = this.CurrentWebPage.LoadControl(SiteFilename.AdvancedEditControlPath);
                        this.CurrentWebPage.Form.Controls.Add(editor);

                        MarkWidgets(this.CurrentWebPage, true);
                    }
                }
                else
                {
                    HttpContext.Current.Response.Cache.SetExpires(dtExpire);
                }

                InsertSpecialCtrl(this.CurrentWebPage.Form, ControlLocation.Footer);

                if (pageWidgets.Any())
                {
                    CMSConfigHelper cmsHelper = new CMSConfigHelper();

                    //find each placeholder in use ONCE!
                    List <LabeledControl> lstPlaceholders = (from ph in pageWidgets
                                                             where ph.Root_ContentID == pageContents.Root_ContentID
                                                             select new LabeledControl(ph.PlaceholderName, FindTheControl(ph.PlaceholderName, this.CurrentWebPage))).Distinct().ToList();

                    List <Widget> lstWidget = null;

                    if (SecurityData.AdvancedEditMode)
                    {
                        lstWidget = (from w in pageWidgets
                                     orderby w.WidgetOrder, w.EditDate
                                     where w.Root_ContentID == pageContents.Root_ContentID
                                     //&& w.IsWidgetActive == true
                                     && w.IsWidgetPendingDelete == false
                                     select w).ToList();
                    }
                    else
                    {
                        lstWidget = (from w in pageWidgets
                                     orderby w.WidgetOrder, w.EditDate
                                     where w.Root_ContentID == pageContents.Root_ContentID &&
                                     w.IsWidgetActive == true &&
                                     w.IsRetired == false && w.IsUnReleased == false &&
                                     w.IsWidgetPendingDelete == false
                                     select w).ToList();
                    }

                    foreach (Widget theWidget in lstWidget)
                    {
                        WidgetContainer plcHolder = (WidgetContainer)(from d in lstPlaceholders
                                                                      where d.ControlLabel == theWidget.PlaceholderName
                                                                      select d.KeyControl).FirstOrDefault();
                        if (plcHolder != null)
                        {
                            plcHolder.EnableViewState = true;
                            Control widget = new Control();

                            if (theWidget.ControlPath.EndsWith(".ascx"))
                            {
                                if (File.Exists(this.CurrentWebPage.Server.MapPath(theWidget.ControlPath)))
                                {
                                    try {
                                        widget = this.CurrentWebPage.LoadControl(theWidget.ControlPath);
                                    } catch (Exception ex) {
                                        Literal lit = new Literal();
                                        lit.Text = "<b>ERROR: " + theWidget.ControlPath + "</b> <br />\r\n" + ex.ToString();
                                        widget   = lit;
                                    }
                                }
                                else
                                {
                                    Literal lit = new Literal();
                                    lit.Text = "MISSING FILE: " + theWidget.ControlPath + "<br />\r\n";
                                    widget   = lit;
                                }
                            }

                            if (theWidget.ControlPath.ToLowerInvariant().StartsWith("class:"))
                            {
                                try {
                                    string className = theWidget.ControlPath.Replace("CLASS:", "");
                                    Type   t         = Type.GetType(className);
                                    Object o         = Activator.CreateInstance(t);

                                    if (o != null)
                                    {
                                        widget = o as Control;
                                    }
                                    else
                                    {
                                        Literal lit = new Literal();
                                        lit.Text = "OOPS: " + theWidget.ControlPath + "<br />\r\n";
                                        widget   = lit;
                                    }
                                } catch (Exception ex) {
                                    Literal lit = new Literal();
                                    lit.Text = "<b>ERROR: " + theWidget.ControlPath + "</b> <br />\r\n" + ex.ToString();
                                    widget   = lit;
                                }
                            }

                            widget.EnableViewState = true;

                            IWidget w = null;
                            if (widget is IWidget)
                            {
                                w               = widget as IWidget;
                                w.SiteID        = SiteData.CurrentSiteID;
                                w.PageWidgetID  = theWidget.Root_WidgetID;
                                w.RootContentID = theWidget.Root_ContentID;
                            }

                            if (widget is IWidgetParmData)
                            {
                                IWidgetParmData    wp      = widget as IWidgetParmData;
                                List <WidgetProps> lstProp = theWidget.ParseDefaultControlProperties();

                                wp.PublicParmValues = lstProp.ToDictionary(t => t.KeyName, t => t.KeyValue);
                            }

                            if (widget is IWidgetRawData)
                            {
                                IWidgetRawData wp = widget as IWidgetRawData;
                                wp.RawWidgetData = theWidget.ControlProperties;
                            }

                            if (widget is IWidgetEditStatus)
                            {
                                IWidgetEditStatus wes = widget as IWidgetEditStatus;
                                wes.IsBeingEdited = SecurityData.AdvancedEditMode;
                            }

                            Dictionary <string, string> lstMenus = new Dictionary <string, string>();
                            if (widget is IWidgetMultiMenu)
                            {
                                IWidgetMultiMenu wmm = widget as IWidgetMultiMenu;
                                lstMenus = wmm.JSEditFunctions;
                            }

                            if (SecurityData.AdvancedEditMode)
                            {
                                WidgetWrapper plcWrapper = plcHolder.AddWidget(widget, theWidget);

                                CMSPlugin plug = (from p in cmsHelper.ToolboxPlugins
                                                  where p.FilePath.ToLowerInvariant() == plcWrapper.ControlPath.ToLowerInvariant()
                                                  select p).FirstOrDefault();

                                if (plug != null)
                                {
                                    plcWrapper.ControlTitle = plug.Caption;
                                }
                                else
                                {
                                    plcWrapper.ControlTitle = "UNTITLED";
                                }

                                plcWrapper.ID = WrapCtrlId;

                                if (w != null)
                                {
                                    if (w.EnableEdit)
                                    {
                                        if (lstMenus.Count < 1)
                                        {
                                            string sScript = w.JSEditFunction;
                                            if (String.IsNullOrEmpty(sScript))
                                            {
                                                sScript = "cmsGenericEdit('" + pageContents.Root_ContentID + "','" + plcWrapper.DatabaseKey + "')";
                                            }

                                            plcWrapper.JSEditFunction = sScript;
                                        }
                                        else
                                        {
                                            plcWrapper.JSEditFunctions = lstMenus;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                plcHolder.AddWidget(widget);
                            }

                            widget.ID = CtrlId;
                        }
                    }

                    cmsHelper.Dispose();
                }
            }
        }