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