Created
April 22, 2011 11:22
-
-
Save itechGroup/936465 to your computer and use it in GitHub Desktop.
Скрипт по генерации структуры сайта из карты сайта в html формате
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php"); | |
$APPLICATION->SetTitle("Мебельная компания"); | |
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/xml.php"); | |
function generate($data, $path='') { | |
foreach ($data as $k=>$v) { | |
if (!is_array($v) && trim($v)!='' && $k=='#' && $data['@']['href']!='') { | |
add_struct_item($data['@']['href'],$v); | |
} elseif (is_array($v)&&count($v)>0) { | |
generate($v); | |
} | |
} | |
} | |
function add_struct_item ($path, $title, $file='index.php') { | |
$sitepath = $path; | |
echo "$sitepath <br/>"; | |
$path = $_SERVER['DOCUMENT_ROOT'].$path; | |
mkdir($path, BX_DIR_PERMISSIONS, true); | |
/* Формируем загловки секций */ | |
$f = fopen($path.'.section.php','w'); | |
fwrite($f,"<?\n"); | |
fwrite($f,' $sSectionName = "'.$title.'"'.";\n"); | |
fwrite($f,"?>\n"); | |
fclose($f); | |
/* Формируем сам файл */ | |
$f = fopen($path.$file,'w'); | |
fwrite($f,"<?\n"); | |
fwrite($f,'require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");'."\n"); | |
fwrite($f,'$APPLICATION->SetTitle("'.$title.'");'."\n"); | |
fwrite($f,"?>\n"); | |
fwrite($f," <h1>$title</h1>\n"); | |
fwrite($f,"<?\n"); | |
fwrite($f,'require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");'."\n"); | |
fwrite($f,"?>\n"); | |
fclose($f); | |
/* Добавляем пункты меню */ | |
if ($sitepath[0]=='/') $sitepath = substr($sitepath,1); | |
if (strlen($sitepath)>0 && $sitepath[strlen($sitepath)-1]=='/') $sitepath = substr($sitepath,0,strlen($sitepath)-1); | |
$dirs = explode('/',$sitepath); | |
if (count($dirs)>0) unset($dirs[count($dirs)-1]); | |
if (count($dirs)==0 && $sitepath!='') { | |
if(!file_exists($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.top.menu.php")) { | |
create_menu($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.top.menu.php"); | |
} | |
$f = fopen($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.top.menu.php",'a'); | |
fwrite($f,"\n<?\n"); | |
fwrite($f,'$aMenuLinks[] = Array('."\n"); | |
fwrite($f,'"'.$title.'",'."\n"); | |
fwrite($f,'"/'.$sitepath.'",'."\n"); | |
fwrite($f,'Array(),'."\n"); | |
fwrite($f,'Array(),'."\n"); | |
fwrite($f,'"",'."\n"); | |
fwrite($f,')'."\n"); | |
fwrite($f,"?>"); | |
fclose($f); | |
} elseif(count($dirs)>0) { | |
if(!file_exists($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.left.menu.php")) { | |
create_menu($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.left.menu.php"); | |
} | |
$f = fopen($_SERVER['DOCUMENT_ROOT']."/".implode('/',$dirs)."/.left.menu.php",'a'); | |
fwrite($f,"\n<?\n"); | |
fwrite($f,'$aMenuLinks[] = Array('."\n"); | |
fwrite($f,'"'.$title.'",'."\n"); | |
fwrite($f,'"/'.$sitepath.'",'."\n"); | |
fwrite($f,'Array(),'."\n"); | |
fwrite($f,'Array(),'."\n"); | |
fwrite($f,'"",'."\n"); | |
fwrite($f,')'."\n"); | |
fwrite($f,"?>"); | |
fclose($f); | |
} | |
echo "$sitepath <br/>"; | |
} | |
function create_menu ($fname) { | |
$f = fopen($fname,'w'); | |
fwrite($f,'<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>'); | |
fclose($f); | |
} | |
if (trim($_REQUEST['struct'])!='') { | |
$objXML = new CDataXML(); | |
$objXML->LoadString($_REQUEST['struct']); | |
$arData = $objXML->GetArray(); | |
generate($arData); | |
} | |
?> | |
<form method="POST"> | |
<textarea name="struct"><?=htmlspecialchars($_REQUEST['struct'])?></textarea> | |
<input type="submit"> | |
</form> | |
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment