Esempio n. 1
0
        public static Template MakeNew(string Name, BusinessLogic.User u, Template master)
        {
            //ensure unique alias
            if (GetByAlias(Name) != null)
            {
                Name = EnsureUniqueAlias(Name, 1);
            }

            Template t = MakeNew(Name, u);

            t.MasterTemplate = master.Id;
            t.Design         = "";

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                string design = t.getMasterPageHeader() + "\n";

                foreach (string cpId in master.contentPlaceholderIds())
                {
                    design += "<asp:content ContentPlaceHolderId=\"" + cpId + "\" runat=\"server\">\n\t\n</asp:content>\n\n";
                }

                t.Design = design;
            }

            t.Save();
            return(t);
        }
Esempio n. 2
0
        public static Template MakeNew(string Name, BusinessLogic.User u, Template master)
        {
            //ensure unique alias
            if (GetByAlias(Name) != null)
                Name = EnsureUniqueAlias(Name, 1);

            Template t = MakeNew(Name, u);
            t.MasterTemplate = master.Id;
            t.Design = "";

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                string design = t.getMasterPageHeader() + "\n";

                foreach (string cpId in master.contentPlaceholderIds())
                {
                    design += "<asp:content ContentPlaceHolderId=\"" + cpId + "\" runat=\"server\">\n\t\n</asp:content>\n\n";
                }

                t.Design = design;
            }

            t.Save();
            return t;
        }
        internal static string CreateDefaultMasterPageContent(Template template, string currentAlias)
        {
            string design = GetMasterPageHeader(template) + "\n";

            if (template.HasMasterTemplate)
            {
                var master = new Template(template.MasterTemplate);

                foreach (string cpId in master.contentPlaceholderIds())
                {
                    design += "<asp:content ContentPlaceHolderId=\"" + cpId +
                              "\" runat=\"server\">\n\t\n</asp:content>\n\n";
                }
            }
            else
            {
                design += GetMasterContentElement(template) + "\n";
                design += template.Design;
                design += "\n</asp:Content>" + Environment.NewLine;
            }

            return design;


            /*
            var masterPageContent = template.Design;

            if (!IsMasterPageSyntax(masterPageContent))
                masterPageContent = ConvertToMasterPageSyntax(template);

            // Add header to master page if it doesn't exist
            if (!masterPageContent.TrimStart().StartsWith("<%@"))
            {
                masterPageContent = GetMasterPageHeader(template) + "\n" + masterPageContent;
            }
            else
            {
                // verify that the masterpage attribute is the same as the masterpage
                string masterHeader =
                    masterPageContent.Substring(0, masterPageContent.IndexOf("%>") + 2).Trim(
                        Environment.NewLine.ToCharArray());

                // find the masterpagefile attribute
                MatchCollection m = Regex.Matches(masterHeader, "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"",
                                                  RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                
                foreach (Match attributeSet in m)
                {
                    if (attributeSet.Groups["attributeName"].Value.ToLower() == "masterpagefile")
                    {
                        // validate the masterpagefile
                        string currentMasterPageFile = attributeSet.Groups["attributeValue"].Value;
                        string currentMasterTemplateFile = ParentTemplatePath(template);

                        if (currentMasterPageFile != currentMasterTemplateFile)
                        {
                            masterPageContent =
                                masterPageContent.Replace(
                                    attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"",
                                    attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile +
                                    "\"");
                        }
                    }
                }

            }
            
            return masterPageContent;
             * */
        }
Esempio n. 4
0
        internal static string CreateDefaultMasterPageContent(Template template, string currentAlias)
        {
            string design = GetMasterPageHeader(template) + "\n";

            if (template.HasMasterTemplate)
            {
                var master = new Template(template.MasterTemplate);

                foreach (string cpId in master.contentPlaceholderIds())
                {
                    design += "<asp:content ContentPlaceHolderId=\"" + cpId +
                              "\" runat=\"server\">\n\t\n</asp:content>\n\n";
                }
            }
            else
            {
                design += GetMasterContentElement(template) + "\n";
                design += template.Design;
                design += "\n</asp:Content>" + Environment.NewLine;
            }

            return(design);


            /*
             * var masterPageContent = template.Design;
             *
             * if (!IsMasterPageSyntax(masterPageContent))
             *  masterPageContent = ConvertToMasterPageSyntax(template);
             *
             * // Add header to master page if it doesn't exist
             * if (!masterPageContent.TrimStart().StartsWith("<%@"))
             * {
             *  masterPageContent = GetMasterPageHeader(template) + "\n" + masterPageContent;
             * }
             * else
             * {
             *  // verify that the masterpage attribute is the same as the masterpage
             *  string masterHeader =
             *      masterPageContent.Substring(0, masterPageContent.IndexOf("%>") + 2).Trim(
             *          Environment.NewLine.ToCharArray());
             *
             *  // find the masterpagefile attribute
             *  MatchCollection m = Regex.Matches(masterHeader, "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"",
             *                                    RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
             *
             *  foreach (Match attributeSet in m)
             *  {
             *      if (attributeSet.Groups["attributeName"].Value.ToLower() == "masterpagefile")
             *      {
             *          // validate the masterpagefile
             *          string currentMasterPageFile = attributeSet.Groups["attributeValue"].Value;
             *          string currentMasterTemplateFile = ParentTemplatePath(template);
             *
             *          if (currentMasterPageFile != currentMasterTemplateFile)
             *          {
             *              masterPageContent =
             *                  masterPageContent.Replace(
             *                      attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"",
             *                      attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile +
             *                      "\"");
             *          }
             *      }
             *  }
             *
             * }
             *
             * return masterPageContent;
             * */
        }