jsAutoLoad.js.php
Go to the documentation of this file.00001 <?php
00005 $strDir = __FILE__;
00006 $arrDir = explode( "/" , $strDir );
00007 array_pop( $arrDir );
00008 array_pop( $arrDir );
00009 $intDeep = isset( $_REQUEST['deep'] ) ? $_REQUEST['deep'] : 0;
00010 $intBack = isset( $_REQUEST['back'] ) ? $_REQUEST['back'] : 0;
00011
00012 while( $intDeep-- )
00013 {
00014 array_pop( $arrDir );
00015 }
00016 $strDir = implode( "/" , $arrDir );
00017 print "/* strDir $strDir*/";
00018 for( $i = 0 ; $i < $intBack ; $i++ )
00019 {
00020 array_pop( $arrDir );
00021 }
00022 $strBack = implode( "/" , $arrDir );
00023 print "/* strBack $strBack*/";
00024
00025 $arrFolders = array();
00026 $arrFiles = ( describe_folder( $strDir , $strBack , $arrFolders ) );
00027
00028 function describe_folder( $strDir , $strParentDir = null , &$arrFolders = null)
00029 {
00030 $arrFiles = array();
00031 if( $arrFolders == null )
00032 {
00033 $arrFolders = array();
00034 }
00035
00036 if( $strParentDir == null )
00037 {
00038 $strParentDir = $strDir;
00039 }
00040
00041 $arrDirFiles = scandir( $strDir );
00042 foreach( $arrDirFiles as $strFileName )
00043 {
00044 if( $strFileName[0] == "." )
00045 {
00046 continue;
00047 }
00048 $strDirFolder = $strDir . '/' . $strFileName;
00049 if( is_dir( $strDirFolder ) )
00050 {
00051 $strShortName = str_replace( array( "-" , '+' , ' ' , '.' ), "_" , $strFileName );
00052 $arrFolders[ $strShortName ] = $strDirFolder;
00053 $arrChildFiles = describe_folder( $strDirFolder , $strParentDir , $arrFolders );
00054 $arrFiles = array_merge( $arrFiles , $arrChildFiles );
00055 }
00056 else
00057 {
00058 $strType = ( substr( $strFileName , strpos( $strFileName , "." ) ) );
00059 if( $strType == ".js" )
00060 {
00061 $strPath = $strDirFolder;
00062 $strRelative = "." . str_replace( $strParentDir , "", $strPath );
00063 $strShortName = substr( $strFileName , 0 , -3 );
00064 $strShortName = str_replace( array( "-" , '+' , ' ' , '.' ), "_" , $strShortName );
00065
00066 $arrFiles[ ucfirst( $strShortName ) ] = $strRelative;
00067 }
00068 }
00069 }
00070 return $arrFiles;
00071 }
00072 ?>
00073 window.autoload = function(){};
00074
00075 <?php foreach( $arrFiles as $strShortNameFile => $strPathFile ): ?>
00076 window.autoload.<?php print "load" . $strShortNameFile ?> = function <?php print "load" . $strShortNameFile ?>()
00077 {
00078 require_once( "<?php print str_repeat( "../", $intBack ) . $strPathFile ?>" );
00079 return <? print $strShortNameFile ?>;
00080 }
00081 window.autoload.<?php print "new" . $strShortNameFile ?> = function <?php print "new" . $strShortNameFile ?>( p1 , p2 , p3 , p4 , p5 , p6 )
00082 {
00083 window.autoload.<?php print "load" . $strShortNameFile ?>();
00084 var objElement = new <?php print $strShortNameFile ?>( p1 , p2 , p3 , p4 , p5 , p6 );
00085 return objElement;
00086 };
00087
00088 <? endforeach ?>
00089 <?php foreach( $arrFolders as $strShort => $strFolder ): ?>
00090 window.autoload.getPathOf<?php print ucfirst( $strShort ) ?> = function getPathOf<?php print ucfirst( $strShort ) ?>()
00091 {
00092 return '<?php print str_repeat( "../", $intBack ) . '.' . substr( $strFolder , strlen( $strDir ) ) ?>';
00093 }
00094 <? endforeach ?>