Advertisement
Guest User

Untitled

a guest
Nov 26th, 2019
2,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.08 KB | None | 0 0
  1. <?php
  2.  
  3.     function __autoload($ClassName) {
  4.         global $_CFG;
  5.         if ( in_array($ClassName, array(
  6.             'TextlistModule',
  7.             'InputModule',
  8.             'OutputModule',
  9.             'PartialOutputModule',
  10.             'AuthOutputModule')) ) {
  11.             $ClassName = 'Module';
  12.         }
  13.  
  14.         if ( substr_count($ClassName, 'Model') ) {
  15.  
  16.             $paths = array(
  17.                 $_CFG['path_to_modules'].'libraries/models/',
  18.                 $_CFG['path_to_cms'].'core/libraries/models/'
  19.             );
  20.  
  21.             foreach ( $paths as $path ) {
  22.                 if ( file_exists($path.$ClassName.'.php') ) {
  23.                     require_once $path.$ClassName.'.php';
  24.                     return true;
  25.                 }
  26.             }
  27.         }
  28.  
  29.         static $isInSite = null;
  30.         if ( $isInSite === null ) {
  31.             $isInSite = (strpos($_SERVER['REQUEST_URI'], '/in_site/') === 0);
  32.         }
  33.  
  34.         $cname = strtolower($ClassName);
  35.         // Finding the folder
  36.         $Pattern = sprintf('%1$slibraries/{%2$s.class,%3$s.class,%2$s,%3$s}',
  37.             $_CFG['path_to_modules'], $ClassName, $cname);
  38.         $DirPaths = glob($Pattern, GLOB_BRACE | GLOB_ONLYDIR | GLOB_MARK);
  39.         if ( $DirPaths ) {
  40.             $DirPath = end($DirPaths);
  41.  
  42.             // Finding the file within the folder
  43.             $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
  44.                 $DirPath, $ClassName, $cname);
  45.             $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
  46.  
  47.             if ( $FilePaths ) {
  48.                 require_once(end($FilePaths));
  49.                 return true;
  50.             }
  51.  
  52.             $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}',
  53.                 $DirPath, $ClassName, $cname, $isInSite ? 'input' : 'output');
  54.             $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
  55.             if ( $FilePaths ) {
  56.                 require_once(end($FilePaths));
  57.                 return true;
  58.             }
  59.  
  60.         } else {
  61.             $ModuleName = (stripos($ClassName, 'Module') === false) ? $ClassName : str_ireplace('Module', '', $ClassName);
  62.             $FilePath = sprintf('%1$s%3$s/%2$s/module.php',
  63.                 $_CFG['path_to_modules'], $ModuleName, $isInSite ? 'input' : 'output');
  64.             //echo $FilePath;
  65.             if ( file_exists($FilePath) ) {
  66.                 require_once($FilePath);
  67.                 return true;
  68.             }
  69.         }
  70.         //if we are still here and the class is not loaded try one of the core files
  71.         $Pattern = sprintf('%1$score/libraries/{%2$s.class,%3$s.class,%2$s,%3$s}',
  72.         $_CFG['path_to_cms'], $ClassName, $cname);
  73.         $DirPaths = glob($Pattern, GLOB_BRACE | GLOB_ONLYDIR | GLOB_MARK);
  74.         if ( $DirPaths ) {
  75.             $DirPath = end($DirPaths);
  76.  
  77.             // Finding the file within the folder
  78.             $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
  79.                 $DirPath, $ClassName, $cname);
  80.             $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
  81.  
  82.             if ($FilePaths) {
  83.                 require_once(end($FilePaths));
  84.                 return true;
  85.             }
  86.  
  87.             $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}',
  88.                 $DirPath, $ClassName, $cname, $isInSite ? 'input' : 'output');
  89.             $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
  90.             if ($FilePaths) {
  91.                 require_once(end($FilePaths));
  92.                 return true;
  93.             }
  94.         }
  95.         if ( $isInSite ) {
  96.             //still here that means that we're attemting to load an output module in inSite
  97.             if ( $DirPaths ) {
  98.                 $DirPath = end($DirPaths);
  99.  
  100.                 // Finding the file within the folder
  101.                 $Pattern = sprintf('%1$s{%2$s.class.php,%3$s.class.php,%2$s.php,%3$s.php}',
  102.                     $DirPath, $ClassName, $cname);
  103.                 $FilePaths = glob($Pattern, GLOB_BRACE | GLOB_NOESCAPE);
  104.  
  105.                 if ( $FilePaths ) {
  106.                     require_once(end($FilePaths));
  107.                     return true;
  108.                 }
  109.  
  110.                 $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}',
  111.                     $DirPath, $ClassName, $cname, 'output');
  112.                 $FilePaths = glob($Pattern2, GLOB_BRACE | GLOB_NOESCAPE);
  113.                 if ( $FilePaths ) {
  114.                     require_once(end($FilePaths));
  115.                     return true;
  116.                 }
  117.  
  118.             } else {
  119.                 $ModuleName = (stripos($ClassName, 'Module') === false) ? $ClassName : str_ireplace('Module', '', $ClassName);
  120.                 $FilePath = sprintf('%1$s%3$s/%2$s/module.php',
  121.                     $_CFG['path_to_modules'], $ModuleName, 'output');
  122.                 //echo $FilePath;
  123.                 if ( file_exists($FilePath) ) {
  124.                     require_once($FilePath);
  125.                     return true;
  126.                 }
  127.             }
  128.         }
  129.     }
  130.  
  131. spl_autoload_register('__autoload');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement