コード例 #1
0
    /// <summary>
    /// Gets and bulk updates layouts. Called when the "Get and bulk update layouts" button is pressed.
    /// Expects the CreateLayout method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateLayouts()
    {
        // Prepare the parameters
        string where = "LayoutCodeName LIKE N'MyNewLayout%'";

        // Get the data
        DataSet layouts = LayoutInfoProvider.GetLayouts(where, null);

        if (!DataHelper.DataSourceIsEmpty(layouts))
        {
            // Loop through the individual items
            foreach (DataRow layoutDr in layouts.Tables[0].Rows)
            {
                // Create object from DataRow
                LayoutInfo modifyLayout = new LayoutInfo(layoutDr);

                // Update the properties
                modifyLayout.LayoutDisplayName = modifyLayout.LayoutDisplayName.ToUpper();

                // Save the changes
                LayoutInfoProvider.SetLayoutInfo(modifyLayout);
            }

            return(true);
        }

        return(false);
    }
コード例 #2
0
    /// <summary>
    /// Saves the layout.
    /// </summary>
    /// <returns>Returns true if successful</returns>
    private bool SaveLayout()
    {
        string codeName = tbCodeName.Text.Trim();

        // Find out whether required fields are not empty
        string result = new Validator()
                        .NotEmpty(codeName, GetString("Administration-PageLayout_New.ErrorEmptyLayoutCodeName"))
                        .NotEmpty(tbLayoutDisplayName.Text, GetString("Administration-PageLayout_New.ErrorEmptyLayoutDisplayName"))
                        .NotEmpty(tbLayoutCode.Text.Trim(), GetString("Administration-PageLayout_New.ErrorEmptyLayoutCode"))
                        .IsCodeName(codeName, GetString("general.invalidcodename"))
                        .Result;

        if (result == "")
        {
            if (li == null)
            {
                li = new LayoutInfo();
            }

            li.LayoutCodeName    = codeName;
            li.LayoutDisplayName = tbLayoutDisplayName.Text.Trim();
            li.LayoutDescription = tbLayoutDescription.Text;
            li.LayoutType        = LayoutInfoProvider.GetLayoutTypeEnum(this.drpType.SelectedValue);

            if (li.LayoutCheckedOutByUserID <= 0)
            {
                li.LayoutCode = tbLayoutCode.Text;
                li.LayoutCSS  = txtLayoutCSS.Text;
            }

            try
            {
                LayoutInfoProvider.SetLayoutInfo(li);
                lblInfo.Visible   = true;
                lblInfo.Text      = GetString("General.ChangesSaved");
                breadcrumbs[1, 0] = li.LayoutDisplayName;
            }
            catch (Exception ex)
            {
                lblInfo.Visible  = false;
                lblError.Visible = true;
                lblError.Text    = ex.Message.Replace("%%name%%", li.LayoutCodeName);
                return(false);
            }

            layoutId = li.LayoutId;

            UploadFile.ObjectID = layoutId;
            UploadFile.UploadFile();

            return(!UploadFile.SavingFailed);
        }
        else
        {
            lblError.Text    = result;
            lblError.Visible = true;
            return(false);
        }
    }
コード例 #3
0
ファイル: EditLayout.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Check in event handler.
    /// </summary>
    protected void btnCheckIn_Click(object sender, EventArgs e)
    {
        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            string filename    = "";
            string tmpFileName = "";

            if (li != null)
            {
                tmpFileName = li.LayoutCheckedOutFilename;
            }
            else
            {
                tmpFileName = pti.PageTemplateLayoutCheckedOutFileName;
            }

            if (HttpContext.Current != null)
            {
                filename = HttpContext.Current.Server.MapPath(tmpFileName);
            }
            StreamReader sr = StreamReader.New(filename);

            // Read away the directive lines
            int skiplines = LayoutInfoProvider.GetLayoutDirectives().Split('\n').Length - 1;
            for (int i = 0; i < skiplines; i++)
            {
                sr.ReadLine();
            }

            string newcode = sr.ReadToEnd();
            sr.Close();
            File.Delete(filename);

            if (li != null)
            {
                li.LayoutCheckedOutByUserID    = 0;
                li.LayoutCheckedOutFilename    = "";
                li.LayoutCheckedOutMachineName = "";
                li.LayoutCode = newcode;
                LayoutInfoProvider.SetLayoutInfo(li);
            }
            else
            {
                pti.PageTemplateLayoutCheckedOutByUserID    = 0;
                pti.PageTemplateLayoutCheckedOutFileName    = "";
                pti.PageTemplateLayoutCheckedOutMachineName = "";
                pti.PageTemplateLayout = newcode;
                PageTemplateInfoProvider.SetPageTemplateInfo(pti);
            }

            txtLayout.Text = newcode;
        }
    }
コード例 #4
0
    /// <summary>
    /// Creates layout. Called when the "Create layout" button is pressed.
    /// </summary>
    private bool CreateLayout()
    {
        // Create new layout object
        LayoutInfo newLayout = new LayoutInfo();

        // Set the properties
        newLayout.LayoutDisplayName = "My new layout";
        newLayout.LayoutCodeName    = "MyNewLayout";
        newLayout.LayoutDescription = "This is layout created by API Example";
        newLayout.LayoutCode        = "<cms:CMSWebPartZone ZoneID=\"zoneA\" runat=\"server\" />";

        // Save the layout
        LayoutInfoProvider.SetLayoutInfo(newLayout);

        return(true);
    }
コード例 #5
0
    /// <summary>
    /// Gets and updates layout. Called when the "Get and update layout" button is pressed.
    /// Expects the CreateLayout method to be run first.
    /// </summary>
    private bool GetAndUpdateLayout()
    {
        // Get the layout
        LayoutInfo updateLayout = LayoutInfoProvider.GetLayoutInfo("MyNewLayout");

        if (updateLayout != null)
        {
            // Update the properties
            updateLayout.LayoutDisplayName = updateLayout.LayoutDisplayName.ToLower();

            // Save the changes
            LayoutInfoProvider.SetLayoutInfo(updateLayout);

            return(true);
        }

        return(false);
    }
コード例 #6
0
ファイル: EditLayout.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Discard check out event handler.
    /// </summary>
    protected void btnUndoCheckOut_Click(object sender, EventArgs e)
    {
        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            string filename    = "";
            string tmpFileName = "";

            if (li != null)
            {
                tmpFileName = li.LayoutCheckedOutFilename;
            }
            else
            {
                tmpFileName = pti.PageTemplateLayoutCheckedOutFileName;
            }

            if (HttpContext.Current != null)
            {
                filename = HttpContext.Current.Server.MapPath(tmpFileName);
            }
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            if (li != null)
            {
                li.LayoutCheckedOutByUserID    = 0;
                li.LayoutCheckedOutFilename    = "";
                li.LayoutCheckedOutMachineName = "";
                LayoutInfoProvider.SetLayoutInfo(li);
            }
            else
            {
                pti.PageTemplateLayoutCheckedOutByUserID    = 0;
                pti.PageTemplateLayoutCheckedOutFileName    = "";
                pti.PageTemplateLayoutCheckedOutMachineName = "";
                PageTemplateInfoProvider.SetPageTemplateInfo(pti);
            }
        }
    }
コード例 #7
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if ((nodeId > 0) && (node != null))
        {
            LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(drpType.SelectedValue);

            // Check the permissions
            if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                // Update the layout
                if (node.DocumentPageTemplateID > 0)
                {
                    PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(node.DocumentPageTemplateID);
                    if (pti != null)
                    {
                        // Get shared layout
                        LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(pti.LayoutID);
                        if (li != null)
                        {
                            // Update shared layout
                            li.LayoutCode = txtLayout.Text;
                            li.LayoutType = layoutType;

                            LayoutInfoProvider.SetLayoutInfo(li);
                        }
                        else if (pti.PageTemplateLayoutCheckedOutByUserID <= 0)
                        {
                            // Update custom layout
                            pti.PageTemplateLayout     = txtLayout.Text;
                            pti.PageTemplateLayoutType = layoutType;

                            PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                        }
                    }
                }
            }

            // Update fields
            node.NodeBodyElementAttributes = txtBodyCss.Text;
            node.NodeDocType  = txtDocType.Text;
            node.NodeHeadTags = txtHeadTags.Value.ToString();

            // Update the node
            node.Update();

            // Update search index
            if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled))
            {
                SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID());
            }

            // Log synchronization
            DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");

            // Clear cache
            PageInfoProvider.RemoveAllPageInfosFromCache();
        }
    }
コード例 #8
0
ファイル: EditLayout.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Check out layout event handler.
    /// </summary>
    protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        // Ensure version before check-out
        using (CMSActionContext context = new CMSActionContext())
        {
            context.AllowAsyncActions = false;

            // Save first
            if (!SaveLayout())
            {
                return;
            }
        }

        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            try
            {
                string         filename   = "";
                string         tmpCode    = "";
                LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx;

                if (li != null)
                {
                    filename   = LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, null, li.LayoutType);
                    layoutType = li.LayoutType;

                    tmpCode = li.LayoutCode;
                }
                else
                {
                    filename   = PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType);
                    layoutType = pti.PageTemplateLayoutType;

                    tmpCode = pti.PageTemplateLayout;
                }

                // Write the code to the file
                string fullfilename = "";
                if (HttpContext.Current != null)
                {
                    fullfilename = HttpContext.Current.Server.MapPath(filename);
                    DirectoryHelper.EnsureDiskPath(fullfilename, HttpContext.Current.Server.MapPath("~/"));
                }

                StringBuilder sb = new StringBuilder();
                if (layoutType == LayoutTypeEnum.Ascx)
                {
                    sb.Append(LayoutInfoProvider.GetLayoutDirectives());
                }
                sb.Append(tmpCode);

                string content = HTMLHelper.EnsureLineEnding(sb.ToString(), "\r\n");
                File.WriteAllText(fullfilename, content);

                // Set the layout data
                if (li != null)
                {
                    // Shared layout
                    li.LayoutCheckedOutByUserID    = user.UserID;
                    li.LayoutCheckedOutMachineName = "";
                    if (HttpContext.Current != null)
                    {
                        li.LayoutCheckedOutMachineName = HTTPHelper.MachineName;
                    }
                    li.LayoutCheckedOutFilename = filename;

                    LayoutInfoProvider.SetLayoutInfo(li);
                }
                else
                {
                    // Page template layout
                    pti.PageTemplateLayoutCheckedOutByUserID    = user.UserID;
                    pti.PageTemplateLayoutCheckedOutMachineName = "";
                    if (HttpContext.Current != null)
                    {
                        pti.PageTemplateLayoutCheckedOutMachineName = HTTPHelper.MachineName;
                    }
                    pti.PageTemplateLayoutCheckedOutFileName = filename;

                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
            }
            catch
            {
                return;
            }
        }
    }
コード例 #9
0
ファイル: EditLayout.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Saves the layout code.
    /// </summary>
    /// <returns>Returns true if save successful</returns>
    private bool SaveLayout()
    {
        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            string mPath = "";
            if ((HttpContext.Current != null) && (HttpContext.Current.Server != null))
            {
                mPath = HttpContext.Current.Server.UrlPathEncode(URLHelper.ApplicationPath);
            }

            LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(this.drpType.SelectedValue);

            // Check the permissions
            if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                if (li != null)
                {
                    // Shared layout
                    li.LayoutType = layoutType;
                    li.LayoutCode = HTMLHelper.UnResolveUrls(this.txtLayout.Text, mPath);

                    LayoutInfoProvider.SetLayoutInfo(li);
                }
                else
                {
                    // Custom layout
                    pti.PageTemplateLayoutType = layoutType;
                    pti.PageTemplateLayout     = HTMLHelper.UnResolveUrls(this.txtLayout.Text, mPath);

                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
            }
            this.lblLayoutInfo.Text = ResHelper.GetString("General.ChangesSaved", culture);

            // Resave page template XML
            if (layoutType == LayoutTypeEnum.Ascx)
            {
                PageTemplateInfo ti = this.PagePlaceholder.PageInfo.PageTemplateInfo;
                if ((ti != null) && (ti.PageTemplateId > 0))
                {
                    try
                    {
                        // Load the layout
                        CMSAbstractLayout layout = (CMSAbstractLayout)this.Page.LoadControl(LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, li.LayoutVersionGUID));
                        layout.ID = "abstractLayout";

                        // Remove zones without web parts
                        ArrayList removeZones = new ArrayList();
                        foreach (WebPartZoneInstance zone in ti.WebPartZones)
                        {
                            if (zone.WebParts.Count <= 0)
                            {
                                removeZones.Add(zone);
                            }
                        }
                        foreach (WebPartZoneInstance zone in removeZones)
                        {
                            ti.WebPartZones.Remove(zone);
                        }

                        // Ensure all zones
                        foreach (DictionaryEntry zone in layout.WebPartZones)
                        {
                            ti.EnsureZone(((CMSWebPartZone)zone.Value).ID);
                        }

                        this.Controls.Remove(layout);

                        // Save the page template
                        PageTemplateInfoProvider.SetPageTemplateInfo(ti);
                    }
                    catch
                    {
                    }
                }
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }