Exemple #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);
        }
Exemple #2
0
        private static Template MakeNew(string Name, BusinessLogic.User u, Template master, string design)
        {
            Template t = MakeNew(Name, u, design);

            t.MasterTemplate = master.Id;

            t.Save();
            return(t);
        }
		public JsonResult SaveTemplate(string templateName, string templateAlias, string templateContents, int templateId, int masterTemplateId)
		{
			Template t;
			try
			{
				t = new Template(templateId)
						{
							Text = templateName,
							Alias = templateAlias,
							MasterTemplate = masterTemplateId,
							Design = templateContents
						};
			}
			catch (ArgumentException ex)
			{
				//the template does not exist
				return Failed("Template does not exist", ui.Text("speechBubbles", "templateErrorHeader"), ex);
			}

			try
			{
				t.Save();

				// Clear cache in rutime
				if (UmbracoSettings.UseDistributedCalls)
					dispatcher.Refresh(new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"), t.Id);
				else
					template.ClearCachedTemplate(t.Id);

				return Success(ui.Text("speechBubbles", "templateSavedText"), ui.Text("speechBubbles", "templateSavedHeader"));
			}
			catch (Exception ex)
			{
				return Failed(ui.Text("speechBubbles", "templateErrorText"), ui.Text("speechBubbles", "templateErrorHeader"), ex);
			}
		}
        public void SaveMasterPageFile(string masterPageContent)
        {
            // Add header to master page if it doesn't exist
            if (!masterPageContent.StartsWith("<%@"))
            {
                masterPageContent = getMasterPageHeader() + "\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 = currentMasterTemplateFileName();
                        if (currentMasterPageFile != currentMasterTemplateFile)
                        {
                            masterPageContent =
                                masterPageContent.Replace(
                                    attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"",
                                    attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile + "\"");
                        }
                    }
                }
            }

            //we have a Old Alias if the alias and therefor the masterpage file name has changed...
            //so before we save the new masterfile, we'll clear the old one, so we don't up with
            //Unused masterpage files
            if (!string.IsNullOrEmpty(_oldAlias) && _oldAlias != _alias)
            {
                //Ensure that child templates have the right master masterpage file name
                if (HasChildren)
                {
                    //store children array here because iterating over an Array property object is very inneficient.
                    var c = Children;
                    foreach (CMSNode cmn in c)
                    {
                        Template t = new Template(cmn.Id);
                        t.SaveAsMasterPage();
                        t.Save();
                    }
                }

                //then kill the old file..
                string _oldFile = IOHelper.MapPath(SystemDirectories.Masterpages + "/" + _oldAlias.Replace(" ", "") + ".Master");

                if (System.IO.File.Exists(_oldFile))
                {
                    System.IO.File.Delete(_oldFile);
                }
            }

            // save the file in UTF-8

            File.WriteAllText(MasterPageFile, masterPageContent, System.Text.Encoding.UTF8);
        }
Exemple #5
0
        public void SaveMasterPageFile(string masterPageContent)
        {
            // Add header to master page if it doesn't exist
            if (!masterPageContent.StartsWith("<%@"))
            {
                masterPageContent = getMasterPageHeader() + "\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 = currentMasterTemplateFileName();
                        if (currentMasterPageFile != currentMasterTemplateFile)
                        {
                            masterPageContent =
                                masterPageContent.Replace(
                                attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"",
                                attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile + "\"");

                        }
                    }
                }

            }

            //we have a Old Alias if the alias and therefor the masterpage file name has changed...
            //so before we save the new masterfile, we'll clear the old one, so we don't up with
            //Unused masterpage files
            if (!string.IsNullOrEmpty(_oldAlias) && _oldAlias != _alias)
            {

                //Ensure that child templates have the right master masterpage file name
                if (HasChildren)
                {
                    //store children array here because iterating over an Array property object is very inneficient.
                    var c = Children;
                    foreach (CMSNode cmn in c)
                    {
                        Template t = new Template(cmn.Id);
                        t.SaveAsMasterPage();
                        t.Save();
                    }
                }

                //then kill the old file..
                string _oldFile = IOHelper.MapPath(SystemDirectories.Masterpages + "/" + _oldAlias.Replace(" ", "") + ".master");

                if (System.IO.File.Exists(_oldFile))
                    System.IO.File.Delete(_oldFile);
            }

            // save the file in UTF-8

            File.WriteAllText(MasterPageFile, masterPageContent, System.Text.Encoding.UTF8);
        }
        public string SaveTemplate(string templateName, string templateAlias, string templateContents, int templateID, int masterTemplateID)
        {
            if (BasePage.ValidateUserContextID(BasePage.umbracoUserContextID))
            {
                var _template = new Template(templateID);
                string retVal = "false";

                if (_template != null)
                {
                    _template.Text = templateName;
                    _template.Alias = templateAlias;
                    _template.MasterTemplate = masterTemplateID;
                    _template.Design = templateContents;

                    _template.Save();

                    retVal = "true";

                    // Clear cache in rutime
                    if (UmbracoSettings.UseDistributedCalls)
                        dispatcher.Refresh(new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"), _template.Id);
                    else
                        template.ClearCachedTemplate(_template.Id);
                }
                return retVal;
            }
            return "false";
        }
        public void update(templateCarrier carrier, string username, string password)
        {
            
          
            if (carrier.Id == 0) throw new Exception("ID must be specifed when updating");
            if (carrier == null) throw new Exception("No carrier specified");

            cms.businesslogic.template.Template template;
            try
            {
                template = new cms.businesslogic.template.Template(carrier.Id);
            }
            catch (Exception)
            {
                throw new Exception("Template with ID " + carrier.Id + " not found");
            }

            template.MasterTemplate = carrier.MastertemplateId;
            template.Alias = carrier.Alias;
            template.Text = carrier.Name ;
            template.Design = carrier.Design;
            template.Save();
            clearCachedTemplate(template);
        }
        public string SaveTemplate(string templateName, string templateAlias, string templateContents, int templateID, int masterTemplateID)
        {
            if (AuthorizeRequest(DefaultApps.settings.ToString()))
            {
                var _template = new Template(templateID);
                string retVal = "false";

                if (_template != null)
                {
                    _template.Text = templateName;
                    _template.Alias = templateAlias;
                    _template.MasterTemplate = masterTemplateID;
                    _template.Design = templateContents;

                    _template.Save();

                    retVal = "true";                    
                }
                return retVal;
            }
            return "false";
        }