Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string bannerCategoryCodeName = ValidationHelper.GetString(GetValue("BannerCategoryCodeName"), "");

        BannerCategoryInfo bannerCategory = BannerCategoryInfoProvider.GetBannerCategoryInfoFromSiteOrGlobal(bannerCategoryCodeName, SiteContext.CurrentSiteID);

        if ((bannerCategory == null) || (bannerCategory.BannerCategoryEnabled == false))
        {
            Visible = !HideIfBannerNotFound;
            return;
        }

        if (URLHelper.IsPostback() && KeepPreviousBannerOnPostBack && BannerIDViewState.HasValue)
        {
            bannerReused = true;
            banner       = BannerInfoProvider.GetBannerInfo(BannerIDViewState.Value);
        }

        // If random banner should be picked or banner from viewstate was not found
        if (banner == null)
        {
            bannerReused = false;
            // Get random banner from selected category. Decrement hits left for this banner only if page is displayed on the live site.
            banner = BannerInfoProvider.GetRandomValidBanner(bannerCategory.BannerCategoryID, (currentViewMode.IsLiveSite()));
        }

        // Exits if no banner was found
        if (banner == null)
        {
            Visible = !HideIfBannerNotFound;
            return;
        }

        // Store banner id in the viewstate if the same banner should be used if request is postback
        if (KeepPreviousBannerOnPostBack)
        {
            BannerIDViewState = banner.BannerID;
        }

        string width       = ValidationHelper.GetString(GetValue("Width"), "");
        string height      = ValidationHelper.GetString(GetValue("Height"), "");
        string anchorClass = ValidationHelper.GetString(GetValue("AnchorClass"), "");
        bool   fakeLink    = ValidationHelper.GetBoolean(GetValue("FakeLink"), true);

        if (width != "")
        {
            lnkBanner.Style["width"] = width;
        }
        if (height != "")
        {
            lnkBanner.Style["height"] = height;
        }

        lnkBanner.CssClass = string.Format("CMSBanner {0}", anchorClass).Trim();

        lnkBanner.Visible = true;



        // Do not set link if we are not on the live site.
        if (currentViewMode.IsOneOf(ViewModeEnum.LiveSite, ViewModeEnum.Preview))
        {
            // Link pointing to our custom handler which logs click and redirects
            string bannerRedirectURL = URLHelper.ResolveUrl("~/CMSModules/BannerManagement/CMSPages/BannerRedirect.ashx?bannerID=" + banner.BannerID);

            if (fakeLink)
            {
                // By default href attribute will be set to 'nice' URL
                lnkBanner.Attributes.Add("href", URLHelper.ResolveUrl(banner.BannerURL));

                // After clicking href will be set to URL pointing to custom handler which counts clicks
                lnkBanner.Attributes.Add("onclick", string.Format("this.href='{0}';", bannerRedirectURL));

                // GECKO doesn't count middle mouse click as click, so onmouseup (or down) needs to be added
                lnkBanner.Attributes.Add("onmouseup", string.Format("this.href='{0}';", bannerRedirectURL));
            }
            else
            {
                // If faking links is disabled, set href to redirect url
                lnkBanner.Attributes.Add("href", bannerRedirectURL);
            }

            // Add target="_blank" attribute if link should be opened in new window
            if (banner.BannerBlank)
            {
                lnkBanner.Target = "_blank";
            }
        }

        if (banner.BannerType == BannerTypeEnum.Image)
        {
            BannerImageAttributes bannerImageAttributes = BannerManagementHelper.DeserializeBannerImageAttributes(banner.BannerContent);

            imgBanner.AlternateText = bannerImageAttributes.Alt;
            imgBanner.ToolTip       = bannerImageAttributes.Title;
            imgBanner.CssClass      = bannerImageAttributes.Class;
            imgBanner.Style.Value   = HTMLHelper.HTMLEncode(bannerImageAttributes.Style);

            imgBanner.ImageUrl = URLHelper.ResolveUrl(bannerImageAttributes.Src);

            imgBanner.Visible = true;
            ltrBanner.Visible = false;
        }
        else
        {
            string text = MacroResolver.Resolve(banner.BannerContent);

            ltrBanner.Text    = HTMLHelper.ResolveUrls(text, null, false);
            imgBanner.Visible = false;
            ltrBanner.Visible = true;

            if (banner.BannerType == BannerTypeEnum.HTML)
            {
                ControlsHelper.ResolveDynamicControls(this);
            }
        }
    }
    /// <summary>
    /// Saves widget properties.
    /// </summary>
    public bool Save()
    {
        if (VariantID > 0)
        {
            // Check MVT/CP security
            if (!CheckPermissions("Manage"))
            {
                DisplayError("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((CurrentPageInfo != null) && (mTemplateInstance != null) && SaveForm(formCustom))
        {
            ViewModeEnum viewMode = PortalContext.ViewMode;

            // Check manage permission for non-livesite version
            if (!viewMode.IsLiveSite() && viewMode != ViewModeEnum.DashboardWidgets && viewMode != ViewModeEnum.UserWidgets)
            {
                if (CurrentUser.IsAuthorizedPerDocument(CurrentPageInfo.NodeID, CurrentPageInfo.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed)
                {
                    DisplayError("general.modifynotallowed");
                    return(false);
                }

                // Check design permissions
                if (PortalContext.IsDesignMode(viewMode, false) && !PortalContext.CurrentUserIsDesigner)
                {
                    RedirectToAccessDenied("CMS.Design", "Design");
                }
            }

            PageTemplateInfo pti = mTemplateInstance.ParentPageTemplate;
            if (PortalContext.IsDesignMode(viewMode) && SynchronizationHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName));
                return(false);
            }

            // Get the zone
            mWebPartZoneInstance = mTemplateInstance.EnsureZone(ZoneId);

            if (mWebPartZoneInstance != null)
            {
                mWebPartZoneInstance.WidgetZoneType = ZoneType;

                // Add new widget
                if (IsNewWidget)
                {
                    bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false));
                    int  widgetID     = ValidationHelper.GetInteger(WidgetId, 0);

                    // Create new widget instance
                    mWidgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, mTemplateInstance);
                }

                // Ensure handling of the currently edited object (if not exists -> redirect)
                UIContext.EditedObject = mWidgetInstance;

                mWidgetInstance.XMLVersion = 1;
                if (IsNewVariant)
                {
                    mWidgetInstance = mWidgetInstance.Clone();

                    // Check whether the editor widgets have been already customized
                    if (CurrentPageInfo.DocumentTemplateInstance.WebPartZones.Count == 0)
                    {
                        // There are no customized editor widgets yet => copy the default editor widgets from the page template under the document (to enable customization)

                        // Save to the document as editor admin changes
                        TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider);

                        // Extract and set the document web parts
                        node.SetValue("DocumentWebParts", mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor));

                        // Save the document
                        DocumentHelper.UpdateDocument(node, mTreeProvider);
                    }
                }

                bool isLayoutWidget = ((mWebPartInfo != null) && ((WebPartTypeEnum)mWebPartInfo.WebPartType == WebPartTypeEnum.Layout));

                // Get basicform's datarow and update widget
                SaveFormToWidget(formCustom, mTemplateInstance, isLayoutWidget);

                // Ensure unique id for new widget variant or layout widget
                if (IsNewVariant || (isLayoutWidget && IsNewWidget))
                {
                    string controlId = GetUniqueWidgetId(mWidgetInfo.WidgetName);

                    if (!string.IsNullOrEmpty(controlId))
                    {
                        mWidgetInstance.ControlID = controlId;
                    }
                    else
                    {
                        DisplayError("Unable to generate unique widget id.");
                        return(false);
                    }
                }

                // Allow set dashboard in design mode
                if ((ZoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName))
                {
                    viewMode = ViewModeEnum.Design;
                    PortalContext.SetViewMode(ViewModeEnum.Design);
                }

                bool isWidgetVariant = (VariantID > 0) || IsNewVariant;
                if (!isWidgetVariant)
                {
                    // Save the changes
                    if ((viewMode.IsEdit(true) || viewMode.IsEditLive()) && (ZoneType == WidgetZoneTypeEnum.Editor))
                    {
                        if (DocumentManager.AllowSave)
                        {
                            // Store the editor widgets in the temporary interlayer
                            PortalContext.SaveEditorWidgets(CurrentPageInfo.DocumentID, mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor));
                        }
                    }
                    else
                    {
                        // Save the changes
                        CMSPortalManager.SaveTemplateChanges(CurrentPageInfo, mTemplateInstance, ZoneType, viewMode, mTreeProvider);
                    }
                }
                else if ((viewMode.IsEdit()) && (ZoneType == WidgetZoneTypeEnum.Editor))
                {
                    Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;

                    VariantHelper.SaveWebPartVariantChanges(mWidgetInstance, VariantID, 0, VariantMode, properties);

                    // Log widget variant synchronization
                    TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider);
                    DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, mTreeProvider);
                }
            }

            // Reload the form (because of macro values set only by JS)
            formCustom.ReloadData();

            // Display info message
            ShowChangesSaved();

            // Clear the cached web part
            CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe());

            return(true);
        }

        return(false);
    }