Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function __autoload($ClassName) {
- global $_CFG;
- if ( in_array($ClassName, array(
- 'TextlistModule',
- 'InputModule',
- 'OutputModule',
- 'PartialOutputModule',
- 'AuthOutputModule')) ) {
- $ClassName = 'Module';
- }
- if ( substr_count($ClassName, 'Model') ) {
- $paths = array(
- $_CFG['path_to_modules'].'libraries/models/',
- $_CFG['path_to_cms'].'core/libraries/models/'
- );
- foreach ( $paths as $path ) {
- if ( file_exists($path.$ClassName.'.php') ) {
- require_once $path.$ClassName.'.php';
- return true;
- }
- }
- }
- static $isInSite = null;
- if ( $isInSite === null ) {
- $isInSite = (strpos($_SERVER['REQUEST_URI'], '/in_site/') === 0);
- }
- $cname = strtolower($ClassName);
- // Finding the folder
- $Pattern = sprintf('%1$slibraries/{%2$s.class,%3$s.class,%2$s,%3$s}',
- $_CFG['path_to_modules'], $ClassName, $cname);
- $DirPaths = glob($Pattern, GLOB_BRACE | GLOB_ONLYDIR | GLOB_MARK);
- if ( $DirPaths ) {
- $DirPath = end($DirPaths);
- // Finding the file within the folder
- $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
- $DirPath, $ClassName, $cname);
- $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
- if ( $FilePaths ) {
- require_once(end($FilePaths));
- return true;
- }
- $Pattern2 = sprintf('%1$s{%4$s/%2$s.class.php,%4$s/%3$s.class.php,%4$s/%2$s.php,%4$s/%3$s.php}',
- $DirPath, $ClassName, $cname, $isInSite ? 'input' : 'output');
- $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
- if ( $FilePaths ) {
- require_once(end($FilePaths));
- return true;
- }
- } else {
- $ModuleName = (stripos($ClassName, 'Module') === false) ? $ClassName : str_ireplace('Module', '', $ClassName);
- $FilePath = sprintf('%1$s%3$s/%2$s/module.php',
- $_CFG['path_to_modules'], $ModuleName, $isInSite ? 'input' : 'output');
- //echo $FilePath;
- if ( file_exists($FilePath) ) {
- require_once($FilePath);
- return true;
- }
- }
- //if we are still here and the class is not loaded try one of the core files
- $Pattern = sprintf('%1$score/libraries/{%2$s.class,%3$s.class,%2$s,%3$s}',
- $_CFG['path_to_cms'], $ClassName, $cname);
- $DirPaths = glob($Pattern, GLOB_BRACE | GLOB_ONLYDIR | GLOB_MARK);
- if ( $DirPaths ) {
- $DirPath = end($DirPaths);
- // Finding the file within the folder
- $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
- $DirPath, $ClassName, $cname);
- $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
- if ($FilePaths) {
- require_once(end($FilePaths));
- return true;
- }
- $Pattern2 = sprintf('%1$s{%4$s/%2$s.class.php,%4$s/%3$s.class.php,%4$s/%2$s.php,%4$s/%3$s.php}',
- $DirPath, $ClassName, $cname, $isInSite ? 'input' : 'output');
- $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
- if ($FilePaths) {
- require_once(end($FilePaths));
- return true;
- }
- }
- if ( $isInSite ) {
- //still here that means that we're attemting to load an output module in inSite
- if ( $DirPaths ) {
- $DirPath = end($DirPaths);
- // Finding the file within the folder
- $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
- $DirPath, $ClassName, $cname);
- $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
- if ( $FilePaths ) {
- require_once(end($FilePaths));
- return true;
- }
- $Pattern2 = sprintf('%1$s{%4$s/%2$s.class.php,%4$s/%3$s.class.php,%4$s/%2$s.php,%4$s/%3$s.php}',
- $DirPath, $ClassName, $cname, 'output');
- $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
- if ( $FilePaths ) {
- require_once(end($FilePaths));
- return true;
- }
- } else {
- $ModuleName = (stripos($ClassName, 'Module') === false) ? $ClassName : str_ireplace('Module', '', $ClassName);
- $FilePath = sprintf('%1$s%3$s/%2$s/module.php',
- $_CFG['path_to_modules'], $ModuleName, 'output');
- //echo $FilePath;
- if ( file_exists($FilePath) ) {
- require_once($FilePath);
- return true;
- }
- }
- }
- }
- spl_autoload_register('__autoload');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement