| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* s2Member class autoloader. |
| 5 |
* |
| 6 |
* Defines the __autoload function for s2Member classes. |
| 7 |
* This highly optimizes s2Member. Giving it a much smaller footprint. |
| 8 |
* See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php} |
| 9 |
* |
| 10 |
* Copyright: © 2009-2011 |
| 11 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 12 |
* (coded in the USA) |
| 13 |
* |
| 14 |
* Released under the terms of the GNU General Public License. |
| 15 |
* You should have received a copy of the GNU General Public License, |
| 16 |
* along with this software. In the main directory, see: /licensing/ |
| 17 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 18 |
* |
| 19 |
* @package s2Member |
| 20 |
* @since 3.5 |
| 21 |
*/ |
| 22 |
if(!defined('WPINC')) // MUST have WordPress. |
| 23 |
exit ('Do not access this file directly.'); |
| 24 |
|
| 25 |
if(!function_exists('ws_plugin__s2member_classes')) |
| 26 |
{ |
| 27 |
/** |
| 28 |
* s2Member class autoloader. |
| 29 |
* |
| 30 |
* The __autoload function for s2Member classes. |
| 31 |
* This highly optimizes s2Member. Giving it a much smaller footprint. |
| 32 |
* See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php} |
| 33 |
* |
| 34 |
* @package s2Member |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @param string $class The class that needs to be loaded. Passed in by PHP itself. |
| 38 |
*/ |
| 39 |
function ws_plugin__s2member_classes($class = '') |
| 40 |
{ |
| 41 |
static $c; // Holds the classes directory location (location is optimized with a static var). |
| 42 |
static $c_class_dirs; // All possible dir & sub-directory locations (with a static var). |
| 43 |
|
| 44 |
if(strpos($class, 'c_ws_plugin__s2member_') === 0 && strpos($class, 'c_ws_plugin__s2member_pro_') === FALSE) |
| 45 |
{ |
| 46 |
$c = (!isset ($c)) ? dirname(dirname(__FILE__)).'/classes' : $c; // Configures location of classes. |
| 47 |
$c_class_dirs = (!isset ($c_class_dirs)) ? array_merge(array($c), _ws_plugin__s2member_classes_scan_dirs_r($c)) : $c_class_dirs; |
| 48 |
|
| 49 |
$class = str_replace('_', '-', str_replace('c_ws_plugin__s2member_', '', $class)); |
| 50 |
|
| 51 |
foreach($c_class_dirs as $class_dir) // Start looking for the class. |
| 52 |
if($class_dir === $c || strpos($class, basename($class_dir)) === 0) |
| 53 |
if(file_exists($class_dir.'/'.$class.'.inc.php')) |
| 54 |
{ |
| 55 |
include_once $class_dir.'/'.$class.'.inc.php'; |
| 56 |
break; // Now stop looking. |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Scans recursively for class sub-directories. |
| 63 |
* |
| 64 |
* Used by the s2Member autoloader. |
| 65 |
* |
| 66 |
* @package s2Member |
| 67 |
* @since 3.5 |
| 68 |
* |
| 69 |
* @param string $starting_dir The directory to start scanning from. |
| 70 |
* |
| 71 |
* @return string[] An array of class directories. |
| 72 |
*/ |
| 73 |
function _ws_plugin__s2member_classes_scan_dirs_r($starting_dir = '') |
| 74 |
{ |
| 75 |
$dirs = array(); // Initialize dirs array. |
| 76 |
|
| 77 |
foreach(func_get_args() as $starting_dir) |
| 78 |
if($starting_dir && is_dir($starting_dir)) |
| 79 |
foreach(scandir($starting_dir) as $dir) // Scan this directory. |
| 80 |
if($dir !== '.' && $dir !== '..' && is_dir($dir = $starting_dir.'/'.$dir)) |
| 81 |
$dirs = array_merge($dirs, array($dir), _ws_plugin__s2member_classes_scan_dirs_r($dir)); |
| 82 |
|
| 83 |
return $dirs; // Return all directories. |
| 84 |
} |
| 85 |
|
| 86 |
spl_autoload_register('ws_plugin__s2member_classes'); |
| 87 |
require_once dirname(dirname(dirname(__FILE__))).'/vendor/autoload.php'; |
| 88 |
} |
| 89 |
|