Created
April 22, 2011 11:23
-
-
Save itechGroup/936468 to your computer and use it in GitHub Desktop.
Скрипт по генерации структуры сайта из фрейма со структурой сайта из прототипа axure
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"); | |
$path = array(); | |
function generate($data, $level=0) { | |
global $path; | |
foreach ($data as $k=>$v) { | |
if (!is_array($v) && trim($v)!='' && $k=='#' && $data['@']['onclick']!='') { | |
$v = strtolower($v); | |
$link = strtolower(str_replace("'",'',str_replace('.html','',$data['@']['onclick']))); | |
if ($link!='home') { | |
foreach ($path as $_k=>$_v) { | |
if ($_k>$level) unset($path[$_k]); | |
} | |
$path[$level] = $link; | |
} | |
if ($v!='home') | |
add_struct_item('/'.implode('/',$path).'/',$v); | |
} elseif (is_array($v)&&count($v)>0) { | |
generate($v,$level+1); | |
} | |
} | |
} | |
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(); | |
$s = strip_tags($_REQUEST['struct'],'<a><ul><li><div><table><a>'); | |
$s = str_replace('onc lick','onclick',$s); | |
$s = str_replace(' ','',$s); | |
$s = str_replace('parent.mainFrame.location=','',$s); | |
$objXML->LoadString($s); | |
$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