/// <summary>
    /// OnLoad event.
    /// </summary>
    /// <param name="e">Event argument</param>
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        si = EditForm.EditedObject as CssStylesheetInfo;

        previewState = GetPreviewStateFromCookies(CSSSTYLESHEET);

        // Add preview action
        HeaderAction preview = new HeaderAction
        {
            Text          = GetString("general.preview"),
            OnClientClick = "performToolbarAction('split');return false;",
            Visible       = (previewState == 0),
            Tooltip       = GetString("preview.tooltip"),
            Index         = 1
        };

        editMenuElem.ObjectEditMenu.AddExtraAction(preview);
        editMenuElem.ObjectEditMenu.PreviewMode = true;
        editMenuElem.MenuPanel.CssClass         = "PreviewMenu";

        bool hide = !(BrowserHelper.IsSafari() || BrowserHelper.IsChrome());

        if (hide)
        {
            pnlContainer.CssClass += " Hidden ";
        }
    }
Example #2
0
    /// <summary>
    /// Provides version rollback. Called when the "Rollback version" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool RollbackVersion()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (stylesheet != null)
        {
            // Prepare query parameters
            string where = "VersionObjectID =" + stylesheet.StylesheetID + " AND VersionObjectType = '" + stylesheet.ObjectType + "'";
            string orderBy = "VersionModifiedWhen ASC";
            int    topN    = 1;

            // Get dataset with versions according to the parameters
            DataSet versionDS = ObjectVersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, null);

            if (!DataHelper.DataSourceIsEmpty(versionDS))
            {
                // Get version
                ObjectVersionHistoryInfo version = new ObjectVersionHistoryInfo(versionDS.Tables[0].Rows[0]);

                // Roll back
                ObjectVersionManager.RollbackVersion(version.VersionID);

                return(true);
            }
        }

        return(false);
    }
Example #3
0
    /// <summary>
    /// Creates versioned css stylesheet. Called when the "Create versioned object" button is pressed.
    /// </summary>
    private bool CreateVersionedObject()
    {
        // Create new css stylesheet object
        CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

        // Check if object versioning of stylesheet objects is allowed on current site
        if (ObjectVersionManager.AllowObjectVersioning(newStylesheet, CMSContext.CurrentSiteName))
        {
            // Set the properties
            newStylesheet.StylesheetDisplayName = "My new versioned stylesheet";
            newStylesheet.StylesheetName        = "MyNewVersionedStylesheet";
            newStylesheet.StylesheetText        = "Some versioned CSS code";

            // Save the css stylesheet
            CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

            // Add css stylesheet to site
            int stylesheetId = newStylesheet.StylesheetID;
            int siteId       = CMSContext.CurrentSiteID;

            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheetId, siteId);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// UI Form Before Save event handling.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Control_OnBeforeSave(object sender, EventArgs e)
    {
        // Ensure proper values of code fields while creating a new stylesheet
        CssStylesheetInfo cssInfo = Control.EditedObject as CssStylesheetInfo;

        if (cssInfo == null)
        {
            return;
        }

        if (cssInfo.IsPlainCss())
        {
            return;
        }

        cssInfo.StylesheetDynamicCode = cssInfo.StylesheetText;

        // Check whether stylesheet dynamic code is valid
        string output;
        string error = ProcessCss(cssInfo.StylesheetDynamicCode, cssInfo.StylesheetDynamicLanguage, out output, hidCompiledCss);

        if (String.IsNullOrEmpty(error))
        {
            return;
        }

        Control.ShowError(error);

        // Reset stylesheet language
        cssInfo.StylesheetDynamicLanguage = CssStylesheetInfo.PLAIN_CSS;
        Control.StopProcessing            = true;
    }
Example #5
0
    /// <summary>
    /// OnPreRender control event handling.
    /// </summary>
    /// <param name="e">Event argument</param>
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        // Clear script loaded from viewstate and create new one.
        btnChange.OnClientClick = String.Empty;

        // Hide the Change button if the stylesheet object is checked-in or checked out by another user
        CssStylesheetInfo cssInfo = UIContext.EditedObject as CssStylesheetInfo;

        if ((cssInfo != null) && SynchronizationHelper.UseCheckinCheckout)
        {
            btnOpenSelection.Visible = cssInfo.Generalized.IsCheckedOut && cssInfo.Generalized.IsCheckedOutByUser(MembershipContext.AuthenticatedUser);
        }

        // Hide the change button if the user does not have permissions to modify CSS stylesheets
        btnOpenSelection.Visible = CurrentUser.IsAuthorizedPerResource("CMS.Design", "ModifyCMSCSSStylesheet");

        // Show confirmation if current language is not plain CSS
        if ((cssInfo != null) && !cssInfo.StylesheetDynamicLanguage.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
        {
            string index = Data["StylesheetDynamicLanguage"] as string;
            if (!String.IsNullOrEmpty(index))
            {
                index = Items.IndexOf(Items.FindByValue(index)).ToString();
            }
            string script = "var el = document.getElementById('" + ddlLanguages.ClientID + "'); if (el && (el.selectedIndex != " + index + ")) { if (!confirm(" + ScriptHelper.GetString(GetString("cssstylesheet.languagechangeconfirmation")) + ")) return false;  }";
            btnChange.OnClientClick = script;
        }

        if (!String.IsNullOrEmpty(OnButtonClientClick))
        {
            btnChange.OnClientClick += OnButtonClientClick;
        }
    }
Example #6
0
    /// <summary>
    /// Gets and bulk updates css stylesheets. Called when the "Get and bulk update stylesheets" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCssStylesheets()
    {
        // Prepare the parameters
        string where = "StylesheetName LIKE N'MyNewStylesheet%'";

        // Get the data
        DataSet stylesheets = CssStylesheetInfoProvider.GetCssStylesheets().Where(where);

        if (!DataHelper.DataSourceIsEmpty(stylesheets))
        {
            // Loop through the individual items
            foreach (DataRow stylesheetDr in stylesheets.Tables[0].Rows)
            {
                // Create object from DataRow
                CssStylesheetInfo modifyStylesheet = new CssStylesheetInfo(stylesheetDr);

                // Update the properties
                modifyStylesheet.StylesheetDisplayName = modifyStylesheet.StylesheetDisplayName.ToUpper();

                // Save the changes
                CssStylesheetInfoProvider.SetCssStylesheetInfo(modifyStylesheet);
            }

            return(true);
        }

        return(false);
    }
Example #7
0
    /// <summary>
    /// Initializes HTML editor's settings.
    /// </summary>
    protected void InitHTMLeditor()
    {
        htmlEditor.AutoDetectLanguage = false;
        htmlEditor.DefaultLanguage    = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlEditor.ToolbarSet         = "BizForm";

        // Allow metafile attachments in media dialog
        if ((ObjectID > 0) && (!string.IsNullOrEmpty(ObjectType)) && (!string.IsNullOrEmpty(ObjectCategory)))
        {
            DialogConfiguration config = htmlEditor.MediaDialogConfig;
            config.MetaFileObjectID   = ObjectID;
            config.MetaFileObjectType = ObjectType;
            config.MetaFileCategory   = ObjectCategory;
            config.HideAttachments    = false;
        }

        // Load CSS style for editor area if any
        if (CssStyleSheetID > 0)
        {
            CssStylesheetInfo cssi = CssStylesheetInfoProvider.GetCssStylesheetInfo(CssStyleSheetID);
            if (cssi != null)
            {
                htmlEditor.EditorAreaCSS = CSSHelper.GetStylesheetUrl(cssi.StylesheetName);
            }
        }
    }
Example #8
0
    /// <summary>
    /// Initializes header action control.
    /// </summary>
    private void InitializeHeaderActions(CssStylesheetInfo si)
    {
        // Header actions
        string[,] actions = new string[4, 11];

        // Save button
        actions[0, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[0, 1] = GetString("General.Save");
        actions[0, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png");
        actions[0, 6] = "save";
        actions[0, 8] = "true";

        // CheckOut
        actions[1, 0]  = HeaderActions.TYPE_SAVEBUTTON;
        actions[1, 1]  = GetString("General.CheckOut");
        actions[1, 5]  = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkout.png");
        actions[1, 6]  = "checkout";
        actions[1, 10] = "false";

        // CheckIn
        actions[2, 0]  = HeaderActions.TYPE_SAVEBUTTON;
        actions[2, 1]  = GetString("General.CheckIn");
        actions[2, 5]  = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkin.png");
        actions[2, 6]  = "checkin";
        actions[2, 10] = "false";

        // UndoCheckOut
        actions[3, 0]  = HeaderActions.TYPE_SAVEBUTTON;
        actions[3, 1]  = GetString("General.UndoCheckOut");
        actions[3, 2]  = "return confirm(" + ScriptHelper.GetString(GetString("General.ConfirmUndoCheckOut")) + ");";
        actions[3, 5]  = GetImageUrl("CMSModules/CMS_Content/EditMenu/undocheckout.png");
        actions[3, 6]  = "undocheckout";
        actions[3, 10] = "false";

        if (si != null)
        {
            if (si.StylesheetCheckedOutByUserID > 0)
            {
                // Checked out by current machine
                if (string.Equals(si.StylesheetCheckedOutMachineName, HTTPHelper.MachineName, StringComparison.OrdinalIgnoreCase))
                {
                    actions[2, 10] = "true";
                }
                if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                {
                    actions[3, 10] = "true";
                }
            }
            else
            {
                actions[1, 10] = "true";
            }
        }

        this.CurrentMaster.HeaderActions.LinkCssClass     = "ContentSaveLinkButton";
        this.CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
        this.CurrentMaster.HeaderActions.Actions          = actions;
    }
Example #9
0
    /// <summary>
    /// Deletes css stylesheet. Called when the "Delete stylesheet" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool DeleteCssStylesheet()
    {
        // Get the css stylesheet
        CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        // Delete the css stylesheet
        CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);

        return(deleteStylesheet != null);
    }
Example #10
0
    private void SetDialogMode(CssStylesheetInfo si)
    {
        // Check if stylesheet is under curent site
        int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;

        string where = SqlHelperClass.AddWhereCondition("SiteID = " + siteId, "StylesheetID = " + si.StylesheetID);
        DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("StylesheetID", where, null, 1);

        if (DataHelper.DataSourceIsEmpty(ds))
        {
            URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
        }

        // Set CSS classes
        CurrentMaster.PanelContent.CssClass = "PageContent";
        CurrentMaster.PanelFooter.CssClass  = "FloatRight";

        // Add save and close button
        LocalizedButton btnSaveAndCancel = new LocalizedButton
        {
            ID              = "btnSaveCancel",
            ResourceString  = "general.saveandclose",
            EnableViewState = false,
            CssClass        = "LongSubmitButton"
        };

        btnSaveAndCancel.Click += (sender, e) =>
        {
            if (Save())
            {
                ScriptHelper.RegisterStartupScript(this, GetType(), "SaveAndClose", "window.top.close();", true);
            }
        };

        CurrentMaster.PanelFooter.Controls.Add(btnSaveAndCancel);

        // Add close button
        CurrentMaster.PanelFooter.Controls.Add(new LocalizedButton
        {
            ID              = "btnClose",
            ResourceString  = "general.close",
            EnableViewState = false,
            OnClientClick   = "window.top.close(); return false;",
            CssClass        = "SubmitButton"
        });

        // Set CMS master page title
        CurrentMaster.Title.TitleText  = GetString("CssStylesheet.EditCssStylesheet");
        CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_CSSStylesheet/object.png");

        // Disable display and code name editing
        //txtCssStylesheetDisplayName.ReadOnly = txtCssStylesheetName.ReadOnly = true;
    }
Example #11
0
 /// <summary>
 /// UI Form Before Save event handling.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event argument</param>
 protected void EditForm_OnBeforeSave(object sender, EventArgs e)
 {
     // Ignore the change of stylesheet language in insert mode or if the flag is set
     if (!languageChangeProceeded && !EditForm.IsInsertMode && !plainCssOnly)
     {
         CssStylesheetInfo cssInfo = EditForm.EditedObject as CssStylesheetInfo;
         if (cssInfo != null)
         {
             cssInfo.StylesheetDynamicLanguage = ValidationHelper.GetString(EditForm.EditedObject.GetOriginalValue("StylesheetDynamicLanguage"), CssStylesheetInfo.PLAIN_CSS);
         }
     }
 }
Example #12
0
    /// <summary>
    /// Destroys version history. Called when the "Destroy history" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool DestroyHistory()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (stylesheet != null)
        {
            // Destroy version history
            ObjectVersionManager.DestroyObjectHistory(stylesheet.ObjectType, stylesheet.StylesheetID);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Creates css stylesheet. Called when the "Create stylesheet" button is pressed.
    /// </summary>
    private bool CreateCssStylesheet()
    {
        // Create new css stylesheet object
        CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

        // Set the properties
        newStylesheet.StylesheetDisplayName = "My new stylesheet";
        newStylesheet.StylesheetName = "MyNewStylesheet";
        newStylesheet.StylesheetText = "Some CSS code";

        // Save the css stylesheet
        CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

        return true;
    }
Example #14
0
    /// <summary>
    /// Creates css stylesheet. Called when the "Create stylesheet" button is pressed.
    /// </summary>
    private bool CreateCssStylesheet()
    {
        // Create new css stylesheet object
        CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

        // Set the properties
        newStylesheet.StylesheetDisplayName = "My new stylesheet";
        newStylesheet.StylesheetName        = "MyNewStylesheet";
        newStylesheet.StylesheetText        = "Some CSS code";


        // Save the css stylesheet
        CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

        return(true);
    }
Example #15
0
    /// <summary>
    /// 'Changed' event handling for StylesheetDynamicLanguage field.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void langControl_Changed(object sender, EventArgs e)
    {
        // Go on only if form validation succeeded
        if (EditForm.StopProcessing)
        {
            return;
        }

        string originalLanguage = ValidationHelper.GetString(EditForm.GetDataValue("StylesheetDynamicLanguage"), String.Empty);
        string newLanguage      = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetDynamicLanguage"), String.Empty);

        ChangeStylesheetLanguage(originalLanguage, newLanguage);

        if (!EditForm.IsInsertMode)
        {
            // Save data and refresh the page if the form is not in insert mode
            string redirectUrl = null;

            redirectUrl = URLHelper.UpdateParameterInUrl(RequestContext.CurrentURL, "saved", "1");

            /* Determine whether the StylesheetDynamicCode field control is visible in order to ensure correct value of the field. If it is not visible then BasicForm ignores the value of the field.
             * In that case it is necessary to set value of the field manually. */
            FormEngineUserControl ctrl = EditForm.FieldControls["StylesheetDynamicCode"];
            if ((ctrl != null) && !ctrl.Visible)
            {
                CssStylesheetInfo cssInfo = EditForm.EditedObject as CssStylesheetInfo;
                if (cssInfo != null)
                {
                    cssInfo.StylesheetDynamicCode = EditForm.GetFieldValue("StylesheetDynamicCode") as string;
                }
            }

            /* Determine whether the StylesheetText field control is visible in order to ensure correct value of the field. If it is not visible then BasicForm ignores the value of the field.
             * In that case it is necessary to set value of the field manually. */
            ctrl = EditForm.FieldControls["StylesheetText"];
            if ((ctrl != null) && !ctrl.Visible)
            {
                CssStylesheetInfo cssInfo = EditForm.EditedObject as CssStylesheetInfo;
                if (cssInfo != null)
                {
                    cssInfo.StylesheetText = EditForm.GetFieldValue("StylesheetText") as string;
                }
            }

            EditForm.SaveData(redirectUrl);
        }
    }
Example #16
0
    protected override void OnInit(EventArgs e)
    {
        fDisplayName.Label.Visible = false;
        fName.Label.Visible        = false;

        txtCssStylesheetText.Editor.EditorMode           = EditorModeEnum.Advanced;
        txtCssStylesheetText.Editor.Language             = LanguageEnum.CSS;
        txtCssStylesheetText.Editor.ShowBookmarks        = true;
        txtCssStylesheetText.Editor.Width                = Unit.Percentage(100);
        txtCssStylesheetText.Editor.Height               = Unit.Pixel(385);
        txtCssStylesheetText.Editor.RegularExpression    = @"\s*/\*\s*#\s*([a-zA-Z_0-9-/\+\*.=~\!@\$%\^&\(\[\]\);:<>\?\s]*)\s*#\s*\*/";
        txtCssStylesheetText.Editor.EnablePositionMember = true;
        txtCssStylesheetText.Editor.EnableSections       = true;

        si = CMSContext.EditedObject as CssStylesheetInfo;

        base.OnInit(e);
    }
Example #17
0
    /// <summary>
    /// Gets and updates css stylesheet. Called when the "Get and update stylesheet" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool GetAndUpdateCssStylesheet()
    {
        // Get the css stylesheet
        CssStylesheetInfo updateStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        if (updateStylesheet != null)
        {
            // Update the properties
            updateStylesheet.StylesheetDisplayName = updateStylesheet.StylesheetDisplayName.ToLower();

            // Save the changes
            CssStylesheetInfoProvider.SetCssStylesheetInfo(updateStylesheet);

            return(true);
        }

        return(false);
    }
Example #18
0
    /// <summary>
    /// Adds css stylesheet to site. Called when the "Add stylesheet to site" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool AddCssStylesheetToSite()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        if (stylesheet != null)
        {
            int stylesheetId = stylesheet.StylesheetID;
            int siteId       = SiteContext.CurrentSiteID;

            // Save the binding
            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheetId, siteId);

            return(true);
        }

        return(false);
    }
Example #19
0
    /// <summary>
    /// Retrieve the stylesheet either from the database or file if checked out.
    /// </summary>
    /// <param name="stylesheetName">Stylesheet's unique name</param>
    /// <returns>The stylesheet data (plain version only)</returns>
    private static CMSOutputResource GetStylesheet(string stylesheetName)
    {
        // Get the stylesheet
        CssStylesheetInfo stylesheetInfo = CssStylesheetInfoProvider.GetCssStylesheetInfo(stylesheetName);

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

        // Determine if the stylesheet is checked out or not
        string   checkedOutFile = URLHelper.GetPhysicalPath(stylesheetInfo.StylesheetCheckedOutFilename);
        string   stylesheet;
        DateTime lastModified;

        if ((stylesheetInfo.StylesheetCheckedOutByUserID > 0) &&
            (string.Equals(stylesheetInfo.StylesheetCheckedOutMachineName, HTTPHelper.MachineName, StringComparison.OrdinalIgnoreCase)) &&
            (File.Exists(checkedOutFile)))
        {
            // Read the stylesheet and timestamp from the checked out file
            using (StreamReader reader = StreamReader.New(checkedOutFile))
            {
                stylesheet = reader.ReadToEnd();
            }
            lastModified = File.GetLastWriteTime(checkedOutFile);
        }
        else
        {
            // Read the stylesheet and timestamp from database
            stylesheet   = stylesheetInfo.StylesheetText;
            lastModified = stylesheetInfo.StylesheetLastModified;
        }

        // Build the output
        CMSOutputResource resource = new CMSOutputResource()
        {
            Data         = HTMLHelper.ResolveCSSUrls(stylesheet, URLHelper.ApplicationPath),
            Name         = stylesheetInfo.StylesheetName,
            LastModified = lastModified,
            Etag         = stylesheetName,
        };

        return(resource);
    }
Example #20
0
    /// <summary>
    /// Creates new version of the object. Called when the "Ensure version" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool EnsureVersion()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (stylesheet != null)
        {
            // Check if object versioning of stylesheet objects is allowed on current site
            if (ObjectVersionManager.AllowObjectVersioning(stylesheet, CMSContext.CurrentSiteName))
            {
                // Ensure version
                ObjectVersionManager.EnsureVersion(stylesheet, false);

                return(true);
            }
        }

        return(false);
    }
Example #21
0
    /// <summary>
    /// Deletes object. Called when the "Delete object" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool DeleteObject()
    {
        // Get the css stylesheet
        CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (deleteStylesheet != null)
        {
            // Check if restoring from recycle bin is allowed on current site
            if (ObjectVersionManager.AllowObjectRestore(deleteStylesheet, CMSContext.CurrentSiteName))
            {
                // Delete the css stylesheet
                CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);

                return(true);
            }
        }

        return(false);
    }
Example #22
0
    /// <summary>
    /// Removes css stylesheet from site. Called when the "Remove stylesheet from site" button is pressed.
    /// Expects the AddCssStylesheetToSite method to be run first.
    /// </summary>
    private bool RemoveCssStylesheetFromSite()
    {
        // Get the css stylesheet
        CssStylesheetInfo removeStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        if (removeStylesheet != null)
        {
            int siteId = SiteContext.CurrentSiteID;

            // Get the binding
            CssStylesheetSiteInfo stylesheetSite = CssStylesheetSiteInfoProvider.GetCssStylesheetSiteInfo(removeStylesheet.StylesheetID, siteId);

            // Delete the binding
            CssStylesheetSiteInfoProvider.DeleteCssStylesheetSiteInfo(stylesheetSite);

            return(true);
        }

        return(false);
    }
Example #23
0
    protected int SaveNewCssStylesheet()
    {
        CssStylesheetInfo cs = new CssStylesheetInfo
        {
            StylesheetDisplayName = txtDisplayName.Text,
            StylesheetName        = txtName.Text,
            StylesheetText        = txtText.Text
        };

        CssStylesheetInfoProvider.SetCssStylesheetInfo(cs);

        // Stylesheet is assigned to site if checkbox is showed and checked or in dialog mode(stylesheet is assigned to specified or current site)
        if (((chkAssign.Visible && chkAssign.Checked) || dialogMode) && (CurrentSite != null) && (cs.StylesheetID > 0))
        {
            // Add new stylesheet to the actual site
            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(cs.StylesheetID, CurrentSite.SiteID);
        }

        return(cs.StylesheetID);
    }
Example #24
0
    /// <summary>
    /// Returns the links to CSS files which should be used for displaying the page.
    /// </summary>
    private static string GetCssFileLink()
    {
        // Get stylesheet
        CssStylesheetInfo csi = null;

        if (CMSContext.CurrentPageInfo.DocumentStylesheetID > 0)
        {
            csi = CssStylesheetInfoProvider.GetCssStylesheetInfo(CMSContext.CurrentPageInfo.DocumentStylesheetID);
        }
        // If not found, get default stylesheet from the current site
        if ((csi == null) && (CMSContext.CurrentSite.SiteDefaultStylesheetID > 0))
        {
            csi = CssStylesheetInfoProvider.GetCssStylesheetInfo(CMSContext.CurrentSite.SiteDefaultStylesheetID);
        }
        // If stylesheet found, get the URL
        if (csi != null)
        {
            return(CSSHelper.GetCSSFileLink(CSSHelper.GetStylesheetUrl(csi.StylesheetName)));
        }
        return(null);
    }
Example #25
0
    /// <summary>
    /// Destroys latest version from history. Called when the "Destroy version" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool DestroyVersion()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (stylesheet != null)
        {
            // Get the latest version
            ObjectVersionHistoryInfo version = ObjectVersionManager.GetLatestVersion(stylesheet.ObjectType, stylesheet.StylesheetID);

            if (version != null)
            {
                // Destroy the latest version
                ObjectVersionManager.DestroyObjectVersion(version.VersionID);

                return(true);
            }
        }

        return(false);
    }
Example #26
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Setup the filesystem browser
        int cssStylesheetId = QueryHelper.GetInteger("cssstylesheetid", 0);

        if (cssStylesheetId > 0)
        {
            CssStylesheetInfo csi = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssStylesheetId);
            EditedObject = csi;

            if (csi != null)
            {
                // Ensure the theme folder
                themeElem.Path = csi.GetThemePath();
            }
        }
        else
        {
            EditedObject = null;
        }
    }
Example #27
0
    /// <summary>
    /// Creates new version of the object. Called when the "Create version" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool CreateVersion()
    {
        // Get the css stylesheet
        CssStylesheetInfo newStylesheetVersion = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (newStylesheetVersion != null)
        {
            // Check if object versioning of stylesheet objects is allowed on current site
            if (ObjectVersionManager.AllowObjectVersioning(newStylesheetVersion, CMSContext.CurrentSiteName))
            {
                // Update the properties
                newStylesheetVersion.StylesheetDisplayName = newStylesheetVersion.StylesheetDisplayName.ToLower();

                // Create new version
                ObjectVersionManager.CreateVersion(newStylesheetVersion, true);

                return(true);
            }
        }

        return(false);
    }
Example #28
0
    /// <summary>
    /// Destroys object (without creating new version for recycle bin). Called when the "DestroyObject" button is pressed.
    /// Expects the CreateVersionedObject method to be run first.
    /// </summary>
    private bool DestroyObject()
    {
        // Get the css stylesheet
        CssStylesheetInfo destroyStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

        if (destroyStylesheet != null)
        {
            // Destroy the object (in action context with disabled creating of new versions for recycle bin)
            using (CMSActionContext context = new CMSActionContext())
            {
                // Disable creating of new versions
                context.CreateVersion = false;

                // Destroy the css stylesheet
                CssStylesheetInfoProvider.DeleteCssStylesheetInfo(destroyStylesheet);

                return(true);
            }
        }

        return(false);
    }
    protected int SaveNewCssStylesheet()
    {
        CssStylesheetInfo cs = new CssStylesheetInfo
                                   {
                                       StylesheetDisplayName = txtDisplayName.Text,
                                       StylesheetName = txtName.Text,
                                       StylesheetText = txtText.Text
                                   };

        CssStylesheetInfoProvider.SetCssStylesheetInfo(cs);
        CMSContext.EditedObject = cs;

        // Stylesheet is assigned to site if checkbox is showed and checked or in dialog mode(stylesheet is assigned to specified or current site)
        if (((chkAssign.Visible && chkAssign.Checked) || dialogMode) && (CurrentSite != null) && (cs.StylesheetID > 0))
        {
            // Add new stylesheet to the actual site
            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(cs.StylesheetID, CurrentSite.SiteID);
        }

        CMSObjectManager.CheckOutNewObject(Page);

        return cs.StylesheetID;
    }
    /// <summary>
    /// Gets and bulk updates css stylesheets. Called when the "Get and bulk update stylesheets" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCssStylesheets()
    {
        // Prepare the parameters
        string where = "StylesheetName LIKE N'MyNewStylesheet%'";

        // Get the data
        DataSet stylesheets = CssStylesheetInfoProvider.GetCssStylesheets(where, null);
        if (!DataHelper.DataSourceIsEmpty(stylesheets))
        {
            // Loop through the individual items
            foreach (DataRow stylesheetDr in stylesheets.Tables[0].Rows)
            {
                // Create object from DataRow
                CssStylesheetInfo modifyStylesheet = new CssStylesheetInfo(stylesheetDr);

                // Update the properties
                modifyStylesheet.StylesheetDisplayName = modifyStylesheet.StylesheetDisplayName.ToUpper();

                // Save the changes
                CssStylesheetInfoProvider.SetCssStylesheetInfo(modifyStylesheet);
            }

            return true;
        }

        return false;
    }
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser;

        // Check for UI permissions
        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "Properties", "Properties.General", "General.Design", "Design.EditCSSStylesheets" }, SiteContext.CurrentSiteName))
        {
            RedirectToUIElementAccessDenied("CMS.Content", "Properties;Properties.General;General.Design;Design.EditCSSStylesheets");
        }

        // Page has been opened in CMSDesk and only stylesheet style editing is allowed
        isDialog = (QueryHelper.GetBoolean("dialog", false) || QueryHelper.GetBoolean("isindialog", false));

        // Prevent replacing of the master page with dialog master page
        RequiresDialog = false;

        if (isDialog)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash", "objectid", true, true, true))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("dialogs.badhashtitle"), ResHelper.GetString("dialogs.badhashtext"))));
            }

            // Check 'Design Web site' permission
            if (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))
            {
                RedirectToAccessDenied("CMS.Design", "Design");
            }
        }
        else
        {
            CheckGlobalAdministrator();
        }

        string stylesheet = QueryHelper.GetString("objectid", "0");

        // If default stylesheet defined and selected, choose it
        if (stylesheet == "default")
        {
            si = PortalContext.CurrentSiteStylesheet;
        }

        // Default stylesheet not selected try to find stylesheet selected
        if (si != null)
        {
            cssStylesheetId = si.StylesheetID;
        }
        else
        {
            cssStylesheetId = ValidationHelper.GetInteger(stylesheet, 0);
            if (cssStylesheetId > 0)
            {
                // Get the stylesheet
                si = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssStylesheetId);
            }
        }

        SetEditedObject(si, null);

        // Check site association in case that user is not admin
        var checkSiteAssociation = !currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin);

        if ((si != null) && isDialog && checkSiteAssociation)
        {
            // Check if stylesheet is under current site
            int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;
            DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites()
                .WhereEquals("SiteID", siteId)
                .WhereEquals("StylesheetID", si.StylesheetID)
                .TopN(1);

            if (DataHelper.DataSourceIsEmpty(ds))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
            }
        }

        base.OnPreInit(e);
    }
    /// <summary>
    /// Creates versioned css stylesheet. Called when the "Create versioned object" button is pressed.
    /// </summary>
    private bool CreateVersionedObject()
    {
        // Create new css stylesheet object
        CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

        // Check if object versioning of stylesheet objects is allowed on current site
        if (ObjectVersionManager.AllowObjectVersioning(newStylesheet))
        {
            // Set the properties
            newStylesheet.StylesheetDisplayName = "My new versioned stylesheet";
            newStylesheet.StylesheetName = "MyNewVersionedStylesheet";
            newStylesheet.StylesheetText = "Some versioned CSS code";

            // Save the css stylesheet
            CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

            // Add css stylesheet to site
            int stylesheetId = newStylesheet.StylesheetID;
            int siteId = SiteContext.CurrentSiteID;

            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheetId, siteId);

            return true;
        }

        return false;
    }
Example #33
0
    /// <summary>
    /// Detects stylesheet language change and converts CSS code according to the former and the latter language.
    /// </summary>
    /// <param name="originalLanguage">The previous language</param>
    /// <param name="newLanguage">The new language</param>
    private void ChangeStylesheetLanguage(string originalLanguage, string newLanguage)
    {
        // Check whether the stylesheet language has actually changed.
        if (!String.IsNullOrEmpty(newLanguage) && !String.IsNullOrEmpty(originalLanguage) && !originalLanguage.EqualsCSafe(newLanguage, true))
        {
            string code         = String.Empty;
            string output       = String.Empty;
            string errorMessage = String.Empty;

            if (newLanguage.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
            {
                // Changed from any CSS preprocessor language to plain CSS.
                code = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetDynamicCode"), String.Empty);
                // Try to parse the code against the original preprocessor language.
                errorMessage = CSSStylesheetNewControlExtender.ProcessCss(code, originalLanguage, out output, hidCompiledCss);
            }
            else if (originalLanguage.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
            {
                // Changed from Plain CSS to some CSS preprocessor language.
                code = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetText"), String.Empty);
                // Try to parse the code against the new preprocessor language.
                errorMessage = CSSStylesheetNewControlExtender.ProcessCss(code, newLanguage, out output, hidCompiledCss);
            }
            else
            {
                // Changed from CSS preprocessor language to another one.
                code = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetDynamicCode"), String.Empty);
                // Try to parse the code against the original preprocessor language.
                errorMessage = CSSStylesheetNewControlExtender.ProcessCss(code, originalLanguage, out output, hidCompiledCss);
            }

            if (String.IsNullOrEmpty(errorMessage))
            {
                // Success -> Set correct values to form controls.
                if (newLanguage.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
                {
                    // output -> StylesheetText
                    EditForm.FieldControls["StylesheetText"].Value = output;
                }
                else if (originalLanguage.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
                {
                    // Copy the original code to StylesheetDynamicCode field.
                    EditForm.FieldControls["StylesheetDynamicCode"].Value = code;
                }
                else
                {
                    // Copy the original code to StylesheetDynamicCode field.
                    EditForm.FieldControls["StylesheetDynamicCode"].Value = output;
                }

                // Prevent to additional change processing.
                languageChangeProceeded = true;
            }
            else
            {
                // Failure -> Show error message
                EditForm.AddError(errorMessage);
                // Prevent further processing
                EditForm.StopProcessing = true;
                // Set drop-down list to its former value
                FormEngineUserControl langControl = EditForm.FieldControls["StylesheetDynamicLanguage"];
                if (langControl != null)
                {
                    langControl.Value = originalLanguage;
                    CssStylesheetInfo cssInfo = EditForm.EditedObject as CssStylesheetInfo;
                    if (cssInfo != null)
                    {
                        cssInfo.StylesheetDynamicLanguage = originalLanguage;
                    }
                }
            }
        }
    }
    protected override void OnInit(EventArgs e)
    {
        fDisplayName.Label.Visible = false;
        fName.Label.Visible = false;

        txtCssStylesheetText.Editor.EditorMode = EditorModeEnum.Advanced;
        txtCssStylesheetText.Editor.Language = LanguageEnum.CSS;
        txtCssStylesheetText.Editor.ShowBookmarks = true;
        txtCssStylesheetText.Editor.Width = Unit.Percentage(100);
        txtCssStylesheetText.Editor.Height = Unit.Pixel(385);
        txtCssStylesheetText.Editor.RegularExpression = @"\s*/\*\s*#\s*([a-zA-Z_0-9-/\+\*.=~\!@\$%\^&\(\[\]\);:<>\?\s]*)\s*#\s*\*/";
        txtCssStylesheetText.Editor.EnablePositionMember = true;
        txtCssStylesheetText.Editor.EnableSections = true;

        si = CMSContext.EditedObject as CssStylesheetInfo;

        base.OnInit(e);
    }
Example #35
0
    /// <summary>
    /// Displays and hides plain CSS code preview.
    /// </summary>
    private void HandleCssCodePreview()
    {
        if (RequestHelper.IsPostBack() && !plainCssOnly)
        {
            // Don't process if the CSS preview control is not visible
            FormEngineUserControl previewControl = EditForm.FieldControls["StylesheetCodePreview"];
            if ((previewControl != null) && !previewControl.Visible)
            {
                return;
            }

            // Get the edited stylesheet
            CssStylesheetInfo cssInfo = EditForm.EditedObject as CssStylesheetInfo;
            if (cssInfo == null)
            {
                return;
            }

            string lang        = ValidationHelper.GetString(cssInfo.StylesheetDynamicLanguage, CssStylesheetInfo.PLAIN_CSS);
            string previewMode = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetCodePreview"), String.Empty);

            // Display preview
            if (!String.IsNullOrEmpty(previewMode) && previewMode.EqualsCSafe("preview", true) && !lang.EqualsCSafe(CssStylesheetInfo.PLAIN_CSS, true))
            {
                // Get the stylesheet dynamic code
                string code   = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetDynamicCode"), String.Empty);
                string output = String.Empty;

                // Run preprocessor
                string parserError = CSSStylesheetNewControlExtender.ProcessCss(code, lang, out output, hidCompiledCss);

                if (String.IsNullOrEmpty(parserError))
                {
                    // Set the editor value and disable editing
                    FormEngineUserControl plainCssEditor = EditForm.FieldControls["StylesheetText"];
                    if (plainCssEditor != null)
                    {
                        plainCssEditor.Value = output;
                        codePreviewDisplayed = true;
                    }

                    // Hide dynamic code editor
                    FormEngineUserControl dynamicCodeEditor = EditForm.FieldControls["StylesheetDynamicCode"];
                    if (dynamicCodeEditor != null)
                    {
                        dynamicCodeEditor.CssClass = "Hidden";
                    }
                }
                else
                {
                    // Handle the error that occurred during parsing
                    EditForm.ShowError(parserError);
                    FormEngineUserControl previewField = EditForm.FieldControls["StylesheetCodePreview"];
                    if (previewField != null)
                    {
                        previewField.Value = lang;
                    }
                }

                return;
            }

            // Hide preview
            if (!String.IsNullOrEmpty(previewMode) && !previewMode.EqualsCSafe("preview", true))
            {
                // Ensure the visibility of the field if the preview is not active
                FormEngineUserControl dynamicCodeEditor = EditForm.FieldControls["StylesheetDynamicCode"];
                if (dynamicCodeEditor != null)
                {
                    dynamicCodeEditor.CssClass = "";
                }

                // Enable for editing despite the editor is hidden
                FormEngineUserControl plainCssEditor = EditForm.FieldControls["StylesheetText"];
                if (plainCssEditor != null)
                {
                    plainCssEditor.Enabled = true;
                }
            }
        }
    }
    /// <summary>
    /// OnLoad event.
    /// </summary>
    /// <param name="e">Event argument</param>
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        si = EditForm.EditedObject as CssStylesheetInfo;

        previewState = GetPreviewStateFromCookies(CMSPreviewControl.CSSSTYLESHEET);

        // Add preview action
        HeaderAction preview = new HeaderAction
        {
            Text = GetString("general.preview"),
            OnClientClick = "performToolbarAction('split');return false;",
            Visible = (previewState == 0),
            Tooltip = GetString("preview.tooltip"),
            Index = 1
        };

        editMenuElem.ObjectEditMenu.AddExtraAction(preview);
        editMenuElem.ObjectEditMenu.PreviewMode = true;
        editMenuElem.MenuPanel.CssClass = "PreviewMenu";

        if ((si != null) && (si.StylesheetID != 0))
        {
            cssStylesheetId = si.StylesheetID;
        }
        else
        {
            cssStylesheetId = QueryHelper.GetInteger("cssstylesheetid", 0);
        }

        bool hide = !(BrowserHelper.IsSafari() || BrowserHelper.IsChrome());
        if (hide)
        {
            pnlContainer.CssClass += " Hidden ";
        }
    }
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        // Check for UI permissions
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "Properties", "Properties.General", "General.Design", "Design.EditCSSStylesheets" }, CMSContext.CurrentSiteName))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "Properties;Properties.General;General.Design;Design.EditCSSStylesheets");
        }

        // Page has been opened in CMSDesk and only stylesheet style editing is allowed
        requiresDialog = QueryHelper.GetBoolean("editonlycode", false);

        if (requiresDialog)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash", "saved;cssstylesheetid;selectorid;tabmode;siteid;aliaspath;line", true, true, true))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("dialogs.badhashtitle"), ResHelper.GetString("dialogs.badhashtext"))));
            }

            // Check 'Design Web site' permission if opened from CMS Desk
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Design", "Design"))
            {
                RedirectToCMSDeskAccessDenied("CMS.Design", "Design");
            }
        }
        else
        {
            CheckAccessToSiteManager();
        }

        string stylesheet = QueryHelper.GetString("cssstylesheetid", "0");

        // If default stylesheet defined and selected, choose it
        if (stylesheet == "default")
        {
            si = CMSContext.CurrentSiteStylesheet;
        }

        // Default stylesheet not selected try to find stylesheet selected
        if (si != null)
        {
            cssStylesheetId = si.StylesheetID;
        }
        else
        {
            cssStylesheetId = ValidationHelper.GetInteger(stylesheet, 0);
            if (cssStylesheetId > 0)
            {
                // Get the stylesheet
                si = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssStylesheetId);
            }
        }

        SetEditedObject(si, "CssStylesheet_Edit.aspx");

        var checkSiteAssociation = QueryHelper.GetBoolean("checksiteassociation", true);

        if ((si != null) && requiresDialog && checkSiteAssociation)
        {
            // Check if stylesheet is under current site
            int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;
            string where = SqlHelperClass.AddWhereCondition("SiteID = " + siteId, "StylesheetID = " + si.StylesheetID);
            DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("StylesheetID", where, null, 1);
            if (DataHelper.DataSourceIsEmpty(ds))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
            }
        }

        base.OnPreInit(e);
    }
Example #38
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var previewState = GetPreviewStateFromCookies(MASTERPAGE);

        // Keep current user
        var user = MembershipContext.AuthenticatedUser;

        // Get document node
        tree = new TreeProvider(user);
        node = UIContext.EditedObject as TreeNode;

        // Register the dialog script
        ScriptHelper.RegisterDialogScript(Page);

        // Register save changes
        ScriptHelper.RegisterSaveChanges(Page);

        // Save changes support
        bool   confirmChanges = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSConfirmChanges");
        string script         = string.Empty;

        if (confirmChanges)
        {
            script  = "CMSContentManager.confirmLeave=" + ScriptHelper.GetString(ResHelper.GetString("Content.ConfirmLeave", user.PreferredUICultureCode), true, false) + "; \n";
            script += "CMSContentManager.confirmLeaveShort=" + ScriptHelper.GetString(ResHelper.GetString("Content.ConfirmLeaveShort", user.PreferredUICultureCode), true, false) + "; \n";
        }
        else
        {
            script += "CMSContentManager.confirmChanges = false;";
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "saveChangesScript", script, true);

        try
        {
            if (node != null)
            {
                DocumentContext.CurrentPageInfo = PageInfoProvider.GetPageInfo(node.NodeSiteName, node.NodeAliasPath, node.DocumentCulture, null, node.NodeID, false);

                // Title
                string title = DocumentContext.CurrentTitle;
                if (!string.IsNullOrEmpty(title))
                {
                    title = "<title>" + title + "</title>";
                }

                // Body class
                string bodyCss = DocumentContext.CurrentBodyClass;

                if (bodyCss != null && bodyCss.Trim() != "")
                {
                    bodyCss = "class=\"" + bodyCss + "\"";
                }
                else
                {
                    bodyCss = "";
                }

                // Metadata
                string meta = "<meta http-equiv=\"pragma\" content=\"no-cache\" />";

                string description = DocumentContext.CurrentDescription;
                if (description != "")
                {
                    meta += "<meta name=\"description\" content=\"" + description + "\" />";
                }

                string keywords = DocumentContext.CurrentKeyWords;
                if (keywords != "")
                {
                    meta += "<meta name=\"keywords\"  content=\"" + keywords + "\" />";
                }

                // Site style sheet
                string cssSiteSheet = "";

                int stylesheetId = DocumentContext.CurrentPageInfo.DocumentStylesheetID;

                CssStylesheetInfo cssInfo = CssStylesheetInfoProvider.GetCssStylesheetInfo((stylesheetId > 0) ? stylesheetId : SiteContext.CurrentSite.SiteDefaultStylesheetID);

                if (cssInfo != null)
                {
                    cssSiteSheet = CssLinkHelper.GetCssFileLink(CssLinkHelper.GetStylesheetUrl(cssInfo.StylesheetName));
                }

                // Theme CSS files
                string themeCssFiles = "";
                if (cssInfo != null)
                {
                    try
                    {
                        string directory = URLHelper.GetPhysicalPath(string.Format("~/App_Themes/{0}/", cssInfo.StylesheetName));
                        if (Directory.Exists(directory))
                        {
                            foreach (string file in Directory.GetFiles(directory, "*.css"))
                            {
                                themeCssFiles += CssLinkHelper.GetCssFileLink(CssLinkHelper.GetPhysicalCssUrl(cssInfo.StylesheetName, Path.GetFileName(file)));
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                // Add values to page
                mHead = FormatHTML(HighlightHTML(title + meta + cssSiteSheet + themeCssFiles), 2);
                mBody = bodyCss;
            }
        }
        catch
        {
            ShowError(GetString("MasterPage.PageEditErr"));
        }

        LoadData();

        // Add save action
        SaveAction save = new SaveAction();

        save.CommandArgument = ComponentEvents.SAVE_DATA;
        save.CommandName     = ComponentEvents.SAVE_DATA;

        headerActions.ActionsList.Add(save);

        if (pti != null)
        {
            // Disable buttons for no-template
            bool actionsEnabled = (pti.PageTemplateId > 0);

            // Edit layout
            HeaderAction action = new HeaderAction
            {
                Text          = GetString("content.ui.pagelayout"),
                Tooltip       = GetString("pageplaceholder.editlayouttooltip"),
                OnClientClick = "EditLayout();return false;",
                Enabled       = actionsEnabled
            };
            headerActions.ActionsList.Add(action);

            string elemUrl = ApplicationUrlHelper.GetElementDialogUrl("cms.design", "PageTemplate.EditPageTemplate", pti.PageTemplateId);

            // Edit page properties action
            action = new HeaderAction
            {
                Text          = GetString("PageProperties.EditTemplateProperties"),
                Tooltip       = GetString("PageProperties.EditTemplateProperties"),
                OnClientClick = "modalDialog('" + elemUrl + "', 'TemplateSelection', '85%', '85%');return false;",
                Enabled       = actionsEnabled
            };

            CMSPagePlaceholder.RegisterEditLayoutScript(this, pti.PageTemplateId, node.NodeAliasPath, null);
            headerActions.ActionsList.Add(action);

            // Preview
            HeaderAction preview = new HeaderAction
            {
                Text          = GetString("general.preview"),
                OnClientClick = "performToolbarAction('split');return false;",
                Visible       = ((previewState == 0) && !PortalUIHelper.DisplaySplitMode),
                Tooltip       = GetString("preview.tooltip")
            };
            headerActions.ActionsList.Add(preview);

            headerActions.ActionPerformed += headerActions_ActionPerformed;
        }

        RegisterInitScripts(pnlBody.ClientID, pnlMenu.ClientID, false);
    }
    private void SetDialogMode(CssStylesheetInfo si)
    {
        // Check if stylesheet is under curent site
        int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;
        string where = SqlHelperClass.AddWhereCondition("SiteID = " + siteId, "StylesheetID = " + si.StylesheetID);
        DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("StylesheetID", where, null, 1);
        if (DataHelper.DataSourceIsEmpty(ds))
        {
            URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
        }

        // Set CSS classes
        CurrentMaster.PanelContent.CssClass = "PageContent";
        CurrentMaster.PanelFooter.CssClass = "FloatRight";

        // Add save and close button
        LocalizedButton btnSaveAndCancel = new LocalizedButton
        {
            ID = "btnSaveCancel",
            ResourceString = "general.saveandclose",
            EnableViewState = false,
            CssClass = "LongSubmitButton"
        };

        btnSaveAndCancel.Click += (sender, e) =>
        {
            if (Save())
            {
                ScriptHelper.RegisterStartupScript(this, GetType(), "SaveAndClose", "window.top.close();", true);
            }
        };

        CurrentMaster.PanelFooter.Controls.Add(btnSaveAndCancel);

        // Add close button
        CurrentMaster.PanelFooter.Controls.Add(new LocalizedButton
        {
            ID = "btnClose",
            ResourceString = "general.close",
            EnableViewState = false,
            OnClientClick = "window.top.close(); return false;",
            CssClass = "SubmitButton"
        });

        // Set CMS master page title
        CurrentMaster.Title.TitleText = GetString("CssStylesheet.EditCssStylesheet");
        CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_CSSStylesheet/object.png");

        // Disable display and code name editing
        //txtCssStylesheetDisplayName.ReadOnly = txtCssStylesheetName.ReadOnly = true;
    }
    /// <summary>
    /// Initializes header action control.
    /// </summary>
    private void InitializeHeaderActions(CssStylesheetInfo si)
    {
        // Header actions
        string[,] actions = new string[4, 11];

        // Save button
        actions[0, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[0, 1] = GetString("General.Save");
        actions[0, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png");
        actions[0, 6] = "save";
        actions[0, 8] = "true";

        // CheckOut
        actions[1, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[1, 1] = GetString("General.CheckOut");
        actions[1, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkout.png");
        actions[1, 6] = "checkout";
        actions[1, 10] = "false";

        // CheckIn
        actions[2, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[2, 1] = GetString("General.CheckIn");
        actions[2, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkin.png");
        actions[2, 6] = "checkin";
        actions[2, 10] = "false";

        // UndoCheckOut
        actions[3, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[3, 1] = GetString("General.UndoCheckOut");
        actions[3, 2] = "return confirm(" + ScriptHelper.GetString(GetString("General.ConfirmUndoCheckOut")) + ");";
        actions[3, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/undocheckout.png");
        actions[3, 6] = "undocheckout";
        actions[3, 10] = "false";

        if (si != null)
        {
            if (si.StylesheetCheckedOutByUserID > 0)
            {
                // Checked out by current machine
                if (string.Equals(si.StylesheetCheckedOutMachineName, HTTPHelper.MachineName, StringComparison.OrdinalIgnoreCase))
                {
                    actions[2, 10] = "true";
                }
                if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                {
                    actions[3, 10] = "true";
                }
            }
            else
            {
                actions[1, 10] = "true";
            }
        }

        this.CurrentMaster.HeaderActions.LinkCssClass = "ContentSaveLinkButton";
        this.CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
        this.CurrentMaster.HeaderActions.Actions = actions;
    }