private void DoSave(out string templateId)
	{
		try
		{
			ValidateSave(out templateId);

			string templateDirectory = BXPath.Combine(templatesPath, templateId);

			BXSecureIO.DirectoryEnsureExists(templateDirectory);

			BXSecureIO.FileWriteAllText(BXPath.Combine(templateDirectory, BXConfigurationUtility.Constants.TemplateFileName), TemplateEditor.Content);
			BXSecureIO.FileWriteAllText(BXPath.Combine(templateDirectory, BXConfigurationUtility.Constants.SiteStyleFileName), txtSiteStyle.Text);
			BXSecureIO.FileWriteAllText(BXPath.Combine(templateDirectory, BXConfigurationUtility.Constants.TemplateStyleFileName), txtTemplateStyle.Text);


			string langDirectory = BXPath.Combine(templateDirectory, "lang", BXLoc.CurrentLocale);
			BXSecureIO.DirectoryEnsureExists(langDirectory);

			BXResourceFile res = new BXResourceFile(BXPath.ToPhysicalPath(string.Format(templateLangFile, templateId, BXLoc.CurrentLocale)));

			if (res.ContainsKey("Template.Name"))
				res["Template.Name"] = Name.Text;
			else
				res.Add("Template.Name", Name.Text);

			if (res.ContainsKey("Template.Description"))
				res["Template.Description"] = Description.Text;
			else
				res.Add("Template.Description", Description.Text);

			res.Save();
		}
		catch (BXSecurityException ex)
		{
			throw new PublicException(ex);
		}
	}
Beispiel #2
0
	protected void GridView_Select(object sender, BXSelectEventArgs e)
	{
		DataTable dt = new DataTable("Templates");
		dt.Columns.Add("ID", typeof(string));
		dt.Columns.Add("Name", typeof(string));
		dt.Columns.Add("Description", typeof(string));
		dt.Columns.Add("PreviewSmall", typeof(string));
		dt.Columns.Add("PreviewBig", typeof(string));
		dt.Columns.Add("PreviewBigPath", typeof(string));

		int i = -1;
		foreach (DirectoryInfo temp in new DirectoryInfo(BXPath.MapPath(BXConfigurationUtility.Constants.TemplatesFolderPath)).GetDirectories())
		{
			var tempFile =
				BXApplicationHelper.ApplicationType == BXApplicationTechnologyType.Mvc
				? "template.cshtml"
				: BXConfigurationUtility.Constants.TemplateFileName;

			if (!File.Exists(Path.Combine(temp.FullName, tempFile)))
			{
				continue;
			}
			i++;
			if (i < e.PagingOptions.startRowIndex || i >= e.PagingOptions.startRowIndex + e.PagingOptions.maximumRows)
			{
				continue;
			}

			DataRow newRow = dt.NewRow();
			newRow["ID"] = temp.Name;

			string resorcePath = string.Format("{0}\\lang\\{1}\\include.lang", temp.FullName, BXLoc.CurrentLocale);
			if (File.Exists(resorcePath))
			{
				using (var res = new BXResourceFile(resorcePath))
				{
					if (res.ContainsKey("Template.Name"))
					{
						newRow["Name"] = res["Template.Name"];
					}

					if (res.ContainsKey("Template.Description"))
					{
						newRow["Description"] = BXStringUtility.HtmlToText(res["Template.Description"] ?? "");
					}
				}
			}

			if (File.Exists(temp.FullName + "\\preview.gif"))
			{
				newRow["PreviewSmall"] = ResolveClientUrl(BXPath.Combine(
					BXConfigurationUtility.Constants.TemplatesFolderPath,
					temp.Name,
					"preview.gif"
				));
			}

			if (File.Exists(temp.FullName + "\\screen.gif"))
			{
				newRow["PreviewBig"] = ResolveClientUrl(BXPath.Combine(
					BXConfigurationUtility.Constants.TemplatesFolderPath,
					temp.Name,
					"screen.gif"
				));
				newRow["PreviewBigPath"] = temp.FullName + "\\screen.gif";
			}

			dt.Rows.Add(newRow);
		}
		var view = new DataView(dt) { Sort = e.SortExpression };
		e.Data = view;
	}
	private void LoadData()
	{
		try
		{
            string tmplId = TemplateId;
			//ID
			if (!string.IsNullOrEmpty(tmplId))
			{
				string templatePath = BXPath.Combine(BXConfigurationUtility.Constants.TemplatesFolderPath, tmplId);
				hlPath.Visible = true;
				hlPath.Text = Encode(templatePath);
				hlPath.NavigateUrl = string.Format("FileMan.aspx?path={0}", HttpUtility.UrlEncode(templatePath));
				lbID.Visible = true;
				lbID.Text = tmplId;
				txtID.Visible = false;
				Left.Visible = true;
				Right.Visible = true;
			}
			else
			{
				hlPath.Visible = false;
				lbID.Visible = false;
				txtID.Visible = true;
				Left.Visible = false;
				Right.Visible = false;
			}

			//NAME
			BXResourceFile res = new BXResourceFile(MapPath(string.Format(templateLangFile, tmplId, BXLoc.CurrentLocale)));


			if (res.ContainsKey("Template.Name"))
				Name.Text = res["Template.Name"];

			if (res.ContainsKey("Template.Description"))
				Description.Text = res["Template.Description"];

			string masterFile = BXPath.Combine(BXConfigurationUtility.Constants.TemplatesFolderPath, tmplId, BXConfigurationUtility.Constants.TemplateFileName);
			if (BXSecureIO.FileExists(masterFile))
				TemplateEditor.Content = BXSecureIO.FileReadAllText(masterFile);
            else if (string.IsNullOrEmpty(tmplId))
            {
                TemplateEditor.Content = Bitrix.Services.Text.BXDefaultFiles.BuildMaster();
            }

			TemplateEditor.TemplateId = Request.QueryString["id"];

			string siteStyleFile = BXPath.Combine(BXConfigurationUtility.Constants.TemplatesFolderPath, TemplateId, BXConfigurationUtility.Constants.SiteStyleFileName);
			if (BXSecureIO.FileExists(siteStyleFile))
				txtSiteStyle.Text = BXSecureIO.FileReadAllText(siteStyleFile);

			string templateStyleFile = BXPath.Combine(BXConfigurationUtility.Constants.TemplatesFolderPath, TemplateId, BXConfigurationUtility.Constants.TemplateStyleFileName);
			if (BXSecureIO.FileExists(templateStyleFile))
				txtTemplateStyle.Text = BXSecureIO.FileReadAllText(templateStyleFile);

			//FILES
			FileInfo[] allFiles = new DirectoryInfo(BXPath.ToPhysicalPath(BXPath.Combine(BXConfigurationUtility.Constants.TemplatesFolderPath, TemplateId))).GetFiles();
			List<FileInfo> filteredFiles = new List<FileInfo>();
			foreach (FileInfo file in allFiles)
			{
				if (!file.Name.Equals(BXConfigurationUtility.Constants.SiteStyleFileName, StringComparison.CurrentCultureIgnoreCase)
					&& !file.Name.Equals(BXConfigurationUtility.Constants.TemplateFileName, StringComparison.CurrentCultureIgnoreCase)
					&& !file.Name.Equals(BXConfigurationUtility.Constants.TemplateStyleFileName, StringComparison.CurrentCultureIgnoreCase))
					filteredFiles.Add(file);
			}
			repFiles.DataSource = filteredFiles;
			repFiles.DataBind();
		}
		catch (BXSecurityException ex)
		{
			throw new PublicException(ex);
		}
	}
Beispiel #4
0
    private void CreateTemplateCell(string template, HtmlTableCell cell)
    {
        bool controlExist = false;
        DropDownList templates = new DropDownList();
        if (cell.Controls.Count == 1)
        {
            controlExist = true;
            templates = cell.Controls[0] as DropDownList;
        }

        if (!controlExist)
        {
            templates.Items.Add(new ListItem(GetMessage("NoSelection"), ""));
            if (templateDirectories == null)
			{
				DirectoryInfo dir = new DirectoryInfo(MapPath("~/bitrix/templates"));
				templateDirectories = dir.Exists ? dir.GetDirectories() : new DirectoryInfo[0];
			}

            foreach (DirectoryInfo temp in templateDirectories)
            {
				if (!File.Exists(Path.Combine(temp.FullName, BXConfigurationUtility.Constants.TemplateFileName)))
					continue;
				
				ListItem li = new ListItem();
                li.Value = temp.Name;
                li.Text = temp.Name;
                string resorcePath = string.Format("{0}\\lang\\{1}\\include.lang", temp.FullName, BXLoc.CurrentLocale);
                if (File.Exists(resorcePath))
                {
                    using (BXResourceFile res = new BXResourceFile(resorcePath))
                    {
                        if (res.ContainsKey("Template.Name"))
                            li.Text = res["Template.Name"];
                    }
                }
                templates.Items.Add(li);
            }
            cell.Controls.Add(templates);
        }
        templates.SelectedValue = template;
    }