array_ad_conditions.php
10 years ago
cap_map.php
10 years ago
functions.php
11 years ago
load_modules.php
9 years ago
load_modules.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | final class Advanced_Ads_ModuleLoader { |
| 4 | |
| 5 | protected static $loader; |
| 6 | protected static $textdomains = array(); |
| 7 | protected static $modules = array(); |
| 8 | |
| 9 | public static function getLoader() |
| 10 | { |
| 11 | if ( null === self::$loader ) { |
| 12 | self::$loader = require_once ADVADS_BASE_PATH . 'vendor/autoload_52.php'; |
| 13 | } |
| 14 | |
| 15 | return self::$loader; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Module loader options: |
| 20 | * - array 'disabled': Pretty name by (module) dirname |
| 21 | * |
| 22 | * @param string $path path to modules |
| 23 | * @param array $options module loader options |
| 24 | */ |
| 25 | public static function loadModules($path, $options = array()) { |
| 26 | $loader = self::getLoader(); |
| 27 | |
| 28 | $disabledModules = isset($options['disabled']) ? (array) $options['disabled'] : array(); |
| 29 | $isAdmin = is_admin(); |
| 30 | |
| 31 | // iterate modules |
| 32 | foreach ( glob( $path . '*/main.php' ) as $module ) { |
| 33 | $modulePath = dirname( $module ); |
| 34 | $moduleName = basename( $modulePath ); |
| 35 | |
| 36 | // configuration is enabled by default (localisation, autoloading and other undemanding stuff) |
| 37 | if ( file_exists( $modulePath . '/config.php' ) ) { |
| 38 | $config = require $modulePath . '/config.php'; |
| 39 | // append autoload classmap |
| 40 | if ( isset($config['classmap']) && is_array( $config['classmap'] ) ) { |
| 41 | $loader->addClassmap( $config['classmap'] ); |
| 42 | } |
| 43 | // append textdomain |
| 44 | /*if ( isset($config['textdomain']) && $config['textdomain'] ) { |
| 45 | self::$textdomains[$config['textdomain']] = "modules/$moduleName/languages"; |
| 46 | }*/ |
| 47 | } |
| 48 | |
| 49 | // admin is enabled by default |
| 50 | if ( $isAdmin && file_exists( $modulePath . '/admin.php' ) ) { |
| 51 | include $modulePath . '/admin.php'; // do not care if this fails |
| 52 | } |
| 53 | |
| 54 | // skip if disabled |
| 55 | if ( isset( $disabledModules[$moduleName] ) ) { |
| 56 | continue ; |
| 57 | } |
| 58 | |
| 59 | self::$modules[$moduleName] = $modulePath; |
| 60 | } |
| 61 | |
| 62 | // register textdomains if non-empty |
| 63 | /* if ( self::$textdomains !== array() ) { |
| 64 | add_action( 'plugins_loaded', array( 'Advanced_Ads_ModuleLoader', 'load_module_textdomains') ); |
| 65 | }*/ |
| 66 | |
| 67 | // load modules |
| 68 | foreach ( self::$modules as $name => $path ) { |
| 69 | require_once $path . '/main.php'; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @deprecated since 1.7.6 |
| 75 | */ |
| 76 | public static function load_module_textdomains() { |
| 77 | foreach ( self::$textdomains as $slug => $rel_path ) { |
| 78 | load_plugin_textdomain( ADVADS_SLUG, false, ADVADS_BASE_DIR . '/languages' ); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 |