| 1 |
<?php |
| 2 |
spl_autoload_register( 'tcmp_autoload' ); |
| 3 |
function tcmp_autoload( $class ) { |
| 4 |
$root = dirname( __FILE__ ) . '/includes/classes/'; |
| 5 |
tcmp_autoload_root( $root, $class ); |
| 6 |
} |
| 7 |
function tcmp_autoload_root( $root, $class ) { |
| 8 |
$slash = substr( $root, strlen( $root ) - 1 ); |
| 9 |
if ( '/' !== $slash && '\\' !== $slash ) { |
| 10 |
$root .= '/'; |
| 11 |
} |
| 12 |
$name = str_replace( TCMP_PLUGIN_PREFIX, '', $class ); |
| 13 |
if ( strpos( $class, TCMP_PLUGIN_PREFIX ) === false ) { |
| 14 |
//autoload only plugin classes |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$h = opendir( $root ); |
| 19 |
while ( $file = readdir( $h ) ) { |
| 20 |
if ( is_dir( $root . $file ) && '.' !== $file && '..' !== $file ) { |
| 21 |
tcmp_autoload_root( $root . $file, $class ); |
| 22 |
} elseif ( file_exists( $root . $name . '.php' ) ) { |
| 23 |
include_once( $root . $name . '.php' ); |
| 24 |
} elseif ( file_exists( $root . $class . '.php' ) ) { |
| 25 |
include_once( $root . $class . '.php' ); |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
function tcmp_include_php( $root ) { |
| 30 |
$h = opendir( $root ); |
| 31 |
$slash = substr( $root, strlen( $root ) - 1 ); |
| 32 |
if ( '/' !== $slash && '\\' !== $slash ) { |
| 33 |
$root .= '/'; |
| 34 |
} |
| 35 |
|
| 36 |
while ( $file = readdir( $h ) ) { |
| 37 |
if ( is_dir( $root . $file ) && '.' !== $file && '..' !== $file ) { |
| 38 |
tcmp_include_php( $root . $file ); |
| 39 |
} elseif ( strlen( $file ) > 5 ) { |
| 40 |
$ext = '.php'; |
| 41 |
$length = strlen( $ext ); |
| 42 |
$start = $length * -1; //negative |
| 43 |
if ( strcasecmp( substr( $file, $start ), $ext ) === 0 ) { |
| 44 |
include_once( $root . $file ); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|