Exemple #1
0
 function OnPostForm()
 {
     $wizard =& $this->GetWizard();
     $templateID = $wizard->GetSiteTemplateID();
     $templatePath = BX_PERSONAL_ROOT . "/templates/" . $templateID;
     $arReplace = array("COMPANY_NAME" => $wizard->GetVar("company_name"), "COMPANY_SLOGAN" => $wizard->GetVar("company_slogan"));
     CWizardUtil::ReplaceMacros($_SERVER["DOCUMENT_ROOT"] . $templatePath . "/include_areas/company_name.php", $arReplace);
     $server_name = $_SERVER["HTTP_HOST"] != '' ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
     if ($_SERVER["SERVER_PORT"] != 80 && $_SERVER["SERVER_PORT"] != 443 && $_SERVER["SERVER_PORT"] > 0 && strpos($_SERVER["HTTP_HOST"], ":") === false) {
         $server_name .= ":" . $_SERVER["SERVER_PORT"];
     }
     COption::SetOptionString("main", "server_name", $server_name);
     COption::SetOptionString("main", "site_name", htmlspecialcharsEx($wizard->GetVar("company_name")));
     COption::SetOptionString("main", "wizard_company_slogan", $wizard->GetVar("company_slogan"));
     $themeVarName = $templateID . "_themeID";
     $themeID = $wizard->GetVar($themeVarName);
     $themeID = Rel2Abs("/", $themeID);
     $themePath = $_SERVER["DOCUMENT_ROOT"] . DemoSiteUtil::GetTemplatesPath($wizard->GetPath()) . "/" . $templateID . "/themes/" . $themeID;
     CopyDirFiles($themePath, $_SERVER["DOCUMENT_ROOT"] . $templatePath, $rewrite = true, $recursive = true, $delete_after_copy = false, $exclude = "description.php");
     $companyLogo = $wizard->GetVar("company_logo");
     CWizardUtil::CopyFile($companyLogo, $templatePath . "/images/logo.gif", false);
     COption::SetOptionString("main", "wizard_site_logo", $companyLogo);
 }
	function OnPostForm()
	{
		$wizard = &$this->GetWizard();
		if ($wizard->IsNextButtonClick())
		{
			$arResult = $wizard->GetVars(true);
			
			// папка пространства имен
			
			$arCreateDirs = array();
			
			if($arResult['new_namespace']) {
				$arResult['namespace'] = BEONO_COMPONENT_PATH.$arResult['new_namespace'];
			}
			
			$arCreateDirs[] = $arResult['namespace'];
			
			// папка компонента
			
			$new_component_path = $arResult['namespace']."/".$arResult['id'];			
			$arCreateDirs[] = $new_component_path;			
			
			// component.php
			
			if (!isset($arResult['snippets'])) {
				$arResult['snippets'] = array();				
			}
			
			if ($arResult['type'] == 'complex') {
				$arResult["snippets"][] = 'complex';
			}
			
			$arCreateFiles = array(); // Список файлов, которые нужно создать
			
			$component_file_content = file_get_contents(dirname(__FILE__)."/src/component.php");	
			$arCreateFiles[$new_component_path."/component.php"] = $this->__getContentBySnippets($component_file_content, $arResult["snippets"]);
		
			// .description.php
					
			$component_file_content = file_get_contents(dirname(__FILE__)."/src/.description.php");	

			$component_file_content = strtr($component_file_content, array(
				"#name#" => htmlspecialchars($arResult['name']),
				"#description#" => htmlspecialchars($arResult['description']),
				"#path_id#" => htmlspecialchars($arResult['path_id']),
				"#path_child_id#" => htmlspecialchars($arResult['path_child_id']),
				"#path_child_name#" => htmlspecialchars($arResult['path_child_name']),
				"#type#" => ($arResult['type']=='complex')?'Y':'N',
			));
			
			$arCreateFiles[$new_component_path."/.description.php"] = $component_file_content;
			
			// .parameters.php
		
			$parameters_snippets = $arResult["snippets"];
			if ($arResult['type'] == 'complex' && !in_array('iblock', $arResult["snippets"])) {
				$parameters_snippets[] = 'iblock';			
			}
			
			$component_file_content = file_get_contents(dirname(__FILE__)."/src/.parameters.php");			
			$arCreateFiles[$new_component_path."/.parameters.php"] = $this->__getContentBySnippets($component_file_content, $parameters_snippets);

			if ($arResult['type'] == 'complex') {
				$arResult["snippets"][] = 'template';
			}
			
			if (in_array('template', $arResult["snippets"])) {
				
				$new_component_template_path = $new_component_path."/templates/.default";
				
				$arCreateDirs[] = $new_component_template_path;
				
				if ($arResult['type'] == 'complex') {
					$arCreateFiles[$new_component_template_path."/list.php"] = file_get_contents(dirname(__FILE__)."/src/templates/.default/list.php");
					$arCreateFiles[$new_component_template_path."/detail.php"] = file_get_contents(dirname(__FILE__)."/src/templates/.default/detail.php");
				} else {
					$arCreateFiles[$new_component_template_path."/template.php"] = file_get_contents(dirname(__FILE__)."/src/templates/.default/template.php");
				}
				
				if (in_array('css', $arResult["template_options"])) {					
					$arCreateFiles[$new_component_template_path."/style.css"] = " ";					
				}
				
				if (in_array('js', $arResult["template_options"])) {					
					$arCreateFiles[$new_component_template_path."/script.js"] = " ";					
				}
				
				if (in_array('epilog', $arResult["template_options"])) {					
					$arCreateFiles[$new_component_template_path."/component_epilog.php"] = '<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); ?>';					
				}
				
				if (in_array('lang', $arResult["template_options"])) {					
					$arCreateDirs[] = $new_component_template_path."/lang";
					$arCreateDirs[] = $new_component_template_path."/lang/ru";
					$arCreateFiles[$new_component_template_path."/lang/ru/template.php"] = '<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); ?>';				
				}
			}
			
			// Lang
			
			if (in_array('lang', $arResult["snippets"])) {
				$arCreateDirs[] = $new_component_path."/lang";
				$arCreateDirs[] = $new_component_path."/lang/ru";
				$arCreateFiles[$new_component_path."/lang/ru/.description.php"] = '<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); ?>';
				$arCreateFiles[$new_component_path."/lang/ru/.parameters.php"] = '<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); ?>';
				$arCreateFiles[$new_component_path."/lang/ru/component.php"] = '<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); ?>';
			}
			
			// icon.gif			
			$arCreateDirs[] = $new_component_path."/images";
			
			if(!$wizard->GetVar("icon")) {				
				$arCreateFiles[$new_component_path."/images/icon.gif"] = file_get_contents(dirname(__FILE__)."/src/images/icon.gif");			
			}
			
			// Создаем папки
			foreach($arCreateDirs as $new_dir_path) {
				if (!file_exists($new_dir_path)) {				
					if(!mkdir($new_dir_path, BX_DIR_PERMISSIONS, true)) {
						$this->SetError("Can't create directory ".$new_dir_path);
						return false;
					}			
				}
			}
			
			// Создаем файлы
			foreach($arCreateFiles as $new_file_path=>$new_file_content) {
				if(!file_put_contents($new_file_path, $new_file_content)) {					
					$this->SetError("Can't create file ".$new_file_path);
					return false;
				} else {
					chmod($new_file_path, BX_FILE_PERMISSIONS);
				}
			}

			if($wizard->GetVar("icon")) {	
				CWizardUtil::CopyFile($wizard->GetVar("icon"), str_replace($_SERVER['DOCUMENT_ROOT'], '', $new_component_path."/images/icon.gif"));							
			}
		}
	}