Example #1
0
	public static function CopyDirFilesEx($startFolderFrom, $startFolderTo, $arTranslateExt=array('php','css','js')) {
		global $APPLICATION;
		
		if (realpath($startFolderFrom) === realpath($startFolderTo)) {
			return false;
		}
		if (!is_dir($startFolderFrom)) {
			return false;
		}
		if (!is_dir($startFolderTo)) {
			mkdir($startFolderTo, BX_DIR_PERMISSIONS, true);
		}
		
		if (!is_array($arTranslateExt))
			$arTranslateExt=array('php','css','js');
		
		if ($dh = @opendir($startFolderFrom)) {
			while (($file = readdir($dh)) !== false) {
				if ($file == '.' || $file == '..') {
					continue;
				}
				$curFile = $startFolderFrom.'/'.$file;
				$toFile = $startFolderTo.'/'.$file;
				if (is_dir($curFile)) {
					WizardServices::CopyDirFilesEx($curFile, $toFile, $arTranslateExt);
				}
				if (is_file($curFile)) {
					$ext = ToLower(end(explode('.', $curFile)));
					if (!in_array($ext, $arTranslateExt)) {
						@copy($curFile, $toFile);
						@chmod($toFile, BX_FILE_PERMISSIONS);
						continue;
					}
					if (($fileContent = @file_get_contents($curFile)) !== false) {
						$fileContent = $APPLICATION->ConvertCharset($fileContent, 'Windows-1251', 'UTF-8');
						$res = @file_put_contents($toFile, $fileContent);
						if ($res) {
							@chmod($toFile, BX_FILE_PERMISSIONS);
						}
					}
				}
			}
		}
		
		return true;
	}
Example #2
0
	function OnPostForm()
	{
		$wizard = &$this->GetWizard();
		
		if ($wizard->IsNextButtonClick())
		{
			$SITES = $wizard->GetVar('sites');
			$arSitesPassed = array();
			$pub_files = $wizard->GetVar('public_files_installed');
			$pub_data = $wizard->GetVar('public_data_installed');
			$pub_updater = $wizard->GetVar('public_data_updater');
			
			$arErrors=array();
			
			if (is_array($SITES) && count($SITES)) {
				$rS = CSite::GetList($ord='id', $dir='asc', array('ACTIVE'=>'Y'));
				$arSites = array();
				while($arr = $rS->Fetch()) {
					$arSites[$arr['LID']] = $arr;
				}
				
				foreach($SITES as $ST) {
					if (! in_array($ST, array_keys($arSites)) || !($arSites[$ST]['DIR'] || $arSites[$ST]['DOC_ROOT'])) {
						$arErrors[] = array('LID'=>$ST, 'MSG'=>GetMessage('WD_SITE_NOT_FOUND'));
						continue;
					}
					if (! empty($arSites[$ST]['DOC_ROOT'])) {
						if (! is_writable($arSites[$ST]['DOC_ROOT']) ) {
							$arErrors[] = array('LID'=>$ST, 'NAME'=>$arSites[$ST]['NAME'], 'PATH'=>$arSites[$ST]['DOC_ROOT'], 'MSG'=>GetMessage('WD_SITE_NOT_WRITABLE'));
							continue;
						}
						else {
							$doc_root = preg_replace('#\/$#', '', $arSites[$ST]['DOC_ROOT']);
						}
					}
					else {
						if (! is_writable($_SERVER['DOCUMENT_ROOT'] . $arSites[$ST]['DIR']) ) {
							$arErrors[] = array('LID'=>$ST, 'NAME'=>$arSites[$ST]['NAME'], 'PATH'=>$_SERVER['DOCUMENT_ROOT'] . $arSites[$ST]['DIR'], 'MSG'=>GetMessage('WD_SITE_NOT_WRITABLE'));
							continue;
						}
						else {
							$doc_root = preg_replace('#\/$#', '', $_SERVER['DOCUMENT_ROOT'] . $arSites[$ST]['DIR']);
						}
					}
					$tmpls = $wizard->GetVar('template_installed');
					$arFields=array();
					$arFields['NAME'] = $arSites[$ST]['NAME'];
					$index=1;
					foreach($tmpls as $tp) {
						$arFields["TEMPLATE"][] = array(
							"TEMPLATE" => $tp,
							"SORT" => $index++,
							"CONDITION" => ''
						);
					}
					
					$bIsUTF = (defined('BX_UTF') && BX_UTF == true);
					
					if (!$bIsUTF) {
						if (CopyDirFiles(str_replace('\\', '/', dirname(__FILE__)) . '/public_files', $doc_root, true, true) !== false) {
							$pub_files[] = '[' . $arSites[$ST]['LID'] . '] ' . $arSites[$ST]['NAME'];
							
							$langs = new CLang;
							if ($langs->Update($ST, $arFields) === false) {
								$arErrors[] = array('LID'=>$ST, 'NAME'=>$arSites[$ST]['NAME'], 'MSG'=>GetMessage('WD_TPL_NOT_ASSIGN'));
							}
							$arSitesPassed[] = $ST;
						}
						else {
							$this->SetError( GetMessage('WD_STEP_2_NOT_INSTALLED') );
						}
					}
					else {
						if (WizardServices::CopyDirFilesEx(str_replace('\\', '/', dirname(__FILE__)) . '/public_files', $doc_root) !== false) {
							
							$pub_files[] = '[' . $arSites[$ST]['LID'] . '] ' . $arSites[$ST]['NAME'];
							
							$langs = new CLang;
							if ($langs->Update($ST, $arFields) === false) {
								$arErrors[] = array('LID'=>$ST, 'NAME'=>$arSites[$ST]['NAME'], 'MSG'=>GetMessage('WD_TPL_NOT_ASSIGN'));
							}
							$arSitesPassed[] = $ST;
						}
						else {
							$this->SetError( GetMessage('WD_STEP_2_NOT_INSTALLED') );
						}
					}
				}
			}
			$wizard->SetVar('errors', $arErrors);
			$wizard->SetVar('public_files_installed', $pub_files);
			//$install_data = $wizard->GetVar('install_data');
			if (count($arSitesPassed) && count($pub_data)) {
				CModule::IncludeModule('iblock');
				// create iblock type
				$arType = array(
					'ID'=>'BT',
					"SECTIONS" => "Y",
					"IN_RSS" => "N",
					"SORT" => 100,
					"LANG" => Array(),
				);
				$arLanguages = Array();
				$rsLanguage = CLanguage::GetList($by, $order, array());
				while($arLanguage = $rsLanguage->Fetch())
					$arLanguages[] = $arLanguage["LID"];	
					
				$bIBType = true;
				$dbType = CIBlockType::GetList(Array(),Array("=ID" => $arType["ID"]));
				if(! $dbType->Fetch()) {
					foreach($arLanguages as $languageID)
					{
						$arType["LANG"][$languageID]["NAME"] = 'Bitrixtemplates';
						$arType["LANG"][$languageID]["ELEMENT_NAME"] = 'Item';
						$arType["LANG"][$languageID]["SECTION_NAME"] = 'Section';
					}
					$iblockType = new CIBlockType;
					$bIBType = $iblockType->Add($arType);
				}
				
				if ($bIBType) {
					$arCodeToId = array();
					foreach($pub_data as $arF) {
						$iblockCode = $arF['name'];
						$rsIBlock = CIBlock::GetList(array(), array("CODE" => $iblockCode, "TYPE" => $arType['ID']));
						if ($arIBlock = $rsIBlock->Fetch())
						{
							CIBlock::Delete($arIBlock["ID"]); 
						}
						$filepath = str_replace('\\', '/', dirname(__FILE__)) . '/public_data/'.$arF['filepath'];
						$filepath = preg_replace('#^.+?\/bitrix\/#','/bitrix/', $filepath);
						//echo $filepath;
						$iblockID = WizardServices::ImportIBlockFromXML(
							$filepath,
							$iblockCode,
							$arType['ID'],
							$arSitesPassed
						);
						$arCodeToId[$iblockCode] = $iblockID;
					}
					if ($pub_updater) {
						$updater = str_replace('\\', '/', dirname(__FILE__)) . '/public_data/'.$pub_updater;
						$arUpdate = array();
						include($updater);
						if (is_array($arUpdate)) {
							foreach($arUpdate as $arData) {
								$file = $_SERVER[DOCUMENT_ROOT].$arData['file'];
								//echo $file;
								//print_r($arCodeToId);
								$iblockCode = ToUpper($arData['code']).'_IBLOCK_CODE';
								$iblockId = ToUpper($arData['code']).'_IBLOCK_ID';
								$id = $arCodeToId[$arData['code']];
								if (file_exists($file) && $id) {
									CWizardUtil::ReplaceMacros($file, array($iblockCode => $arType['ID'], $iblockId => $id));
								}
							}
						}
					}
				}
			}
		}
	}