@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.014'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.014'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -15,290 +15,290 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * instance of the EE_System object |
|
| 20 | - * |
|
| 21 | - * @var $_instance |
|
| 22 | - * @access private |
|
| 23 | - */ |
|
| 24 | - private static $_instance = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * $_autoloaders |
|
| 28 | - * @var array $_autoloaders |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_autoloaders; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * set to "paths" to display autoloader class => path mappings |
|
| 35 | - * set to "times" to display autoloader loading times |
|
| 36 | - * set to "all" to display both |
|
| 37 | - * |
|
| 38 | - * @var string $debug |
|
| 39 | - * @access private |
|
| 40 | - */ |
|
| 41 | - public static $debug = false; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * class constructor |
|
| 47 | - * |
|
| 48 | - * @access private |
|
| 49 | - * @return \EEH_Autoloader |
|
| 50 | - */ |
|
| 51 | - private function __construct() |
|
| 52 | - { |
|
| 53 | - if (self::$_autoloaders === null) { |
|
| 54 | - self::$_autoloaders = array(); |
|
| 55 | - $this->_register_custom_autoloaders(); |
|
| 56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @access public |
|
| 64 | - * @return EEH_Autoloader |
|
| 65 | - */ |
|
| 66 | - public static function instance() |
|
| 67 | - { |
|
| 68 | - // check if class object is instantiated |
|
| 69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | - self::$_instance = new self(); |
|
| 71 | - } |
|
| 72 | - return self::$_instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * espresso_autoloader |
|
| 79 | - * |
|
| 80 | - * @access public |
|
| 81 | - * @param $class_name |
|
| 82 | - * @internal param $className |
|
| 83 | - * @internal param string $class_name - simple class name ie: session |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public static function espresso_autoloader($class_name) |
|
| 87 | - { |
|
| 88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * register_autoloader |
|
| 97 | - * |
|
| 98 | - * @access public |
|
| 99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 101 | - * @param bool $debug **deprecated** |
|
| 102 | - * @throws \EE_Error |
|
| 103 | - */ |
|
| 104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
| 105 | - { |
|
| 106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 107 | - foreach ($class_paths as $class => $path) { |
|
| 108 | - // skip all files that are not PHP |
|
| 109 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 110 | - continue; |
|
| 111 | - } |
|
| 112 | - // don't give up! you gotta... |
|
| 113 | - // get some class |
|
| 114 | - if (empty($class)) { |
|
| 115 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
| 116 | - } |
|
| 117 | - // one day you will find the path young grasshopper |
|
| 118 | - if (empty($path)) { |
|
| 119 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
| 120 | - } |
|
| 121 | - // is file readable ? |
|
| 122 | - if ($read_check && ! is_readable($path)) { |
|
| 123 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
| 124 | - } |
|
| 125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
| 127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * get_autoloaders |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public static function get_autoloaders() |
|
| 144 | - { |
|
| 145 | - return self::$_autoloaders; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * register core, model and class 'autoloaders' |
|
| 153 | - * |
|
| 154 | - * @access private |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - private function _register_custom_autoloaders() |
|
| 158 | - { |
|
| 159 | - EEH_Autoloader::$debug = ''; |
|
| 160 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
| 161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 164 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 165 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 167 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 168 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 169 | - EEH_Debug_Tools::instance()->show_times(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * register core, model and class 'autoloaders' |
|
| 177 | - * |
|
| 178 | - * @access public |
|
| 179 | - */ |
|
| 180 | - public static function register_helpers_autoloaders() |
|
| 181 | - { |
|
| 182 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * register core, model and class 'autoloaders' |
|
| 190 | - * |
|
| 191 | - * @access public |
|
| 192 | - * @return void |
|
| 193 | - */ |
|
| 194 | - public static function register_form_sections_autoloaders() |
|
| 195 | - { |
|
| 196 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * register core, model and class 'autoloaders' |
|
| 204 | - * |
|
| 205 | - * @access public |
|
| 206 | - * @return void |
|
| 207 | - */ |
|
| 208 | - public static function register_line_item_display_autoloaders() |
|
| 209 | - { |
|
| 210 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * register core, model and class 'autoloaders' |
|
| 218 | - * |
|
| 219 | - * @access public |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - public static function register_line_item_filter_autoloaders() |
|
| 223 | - { |
|
| 224 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * register template part 'autoloaders' |
|
| 232 | - * |
|
| 233 | - * @access public |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - public static function register_template_part_autoloaders() |
|
| 237 | - { |
|
| 238 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 245 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 246 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
| 247 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
| 248 | - * time the autoloader is used |
|
| 249 | - * |
|
| 250 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
| 251 | - * @param bool $recursive |
|
| 252 | - * @param bool $debug **deprecated** |
|
| 253 | - * @throws \EE_Error |
|
| 254 | - */ |
|
| 255 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
| 256 | - { |
|
| 257 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 258 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 259 | - } |
|
| 260 | - // make sure last char is a / |
|
| 261 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
| 262 | - $class_to_filepath_map = array(); |
|
| 263 | - $exclude = array( 'index' ); |
|
| 264 | - // get all the files in that folder that end in php |
|
| 265 | - $filepaths = glob($folder.'*'); |
|
| 266 | - |
|
| 267 | - if (empty($filepaths)) { |
|
| 268 | - return; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - foreach ($filepaths as $filepath) { |
|
| 272 | - if (substr($filepath, -4, 4) === '.php') { |
|
| 273 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 274 | - if (! in_array($class_name, $exclude)) { |
|
| 275 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 276 | - } |
|
| 277 | - } elseif ($recursive) { |
|
| 278 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 282 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 283 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 284 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * add_alias |
|
| 292 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 293 | - * |
|
| 294 | - * @access public |
|
| 295 | - * @param string $class_name - simple class name ie: EE_Session |
|
| 296 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 297 | - */ |
|
| 298 | - public static function add_alias($class_name, $alias) |
|
| 299 | - { |
|
| 300 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 301 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 302 | - } |
|
| 303 | - } |
|
| 18 | + /** |
|
| 19 | + * instance of the EE_System object |
|
| 20 | + * |
|
| 21 | + * @var $_instance |
|
| 22 | + * @access private |
|
| 23 | + */ |
|
| 24 | + private static $_instance = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * $_autoloaders |
|
| 28 | + * @var array $_autoloaders |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_autoloaders; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * set to "paths" to display autoloader class => path mappings |
|
| 35 | + * set to "times" to display autoloader loading times |
|
| 36 | + * set to "all" to display both |
|
| 37 | + * |
|
| 38 | + * @var string $debug |
|
| 39 | + * @access private |
|
| 40 | + */ |
|
| 41 | + public static $debug = false; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * class constructor |
|
| 47 | + * |
|
| 48 | + * @access private |
|
| 49 | + * @return \EEH_Autoloader |
|
| 50 | + */ |
|
| 51 | + private function __construct() |
|
| 52 | + { |
|
| 53 | + if (self::$_autoloaders === null) { |
|
| 54 | + self::$_autoloaders = array(); |
|
| 55 | + $this->_register_custom_autoloaders(); |
|
| 56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @access public |
|
| 64 | + * @return EEH_Autoloader |
|
| 65 | + */ |
|
| 66 | + public static function instance() |
|
| 67 | + { |
|
| 68 | + // check if class object is instantiated |
|
| 69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | + self::$_instance = new self(); |
|
| 71 | + } |
|
| 72 | + return self::$_instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * espresso_autoloader |
|
| 79 | + * |
|
| 80 | + * @access public |
|
| 81 | + * @param $class_name |
|
| 82 | + * @internal param $className |
|
| 83 | + * @internal param string $class_name - simple class name ie: session |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public static function espresso_autoloader($class_name) |
|
| 87 | + { |
|
| 88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * register_autoloader |
|
| 97 | + * |
|
| 98 | + * @access public |
|
| 99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 101 | + * @param bool $debug **deprecated** |
|
| 102 | + * @throws \EE_Error |
|
| 103 | + */ |
|
| 104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
| 105 | + { |
|
| 106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 107 | + foreach ($class_paths as $class => $path) { |
|
| 108 | + // skip all files that are not PHP |
|
| 109 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 110 | + continue; |
|
| 111 | + } |
|
| 112 | + // don't give up! you gotta... |
|
| 113 | + // get some class |
|
| 114 | + if (empty($class)) { |
|
| 115 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
| 116 | + } |
|
| 117 | + // one day you will find the path young grasshopper |
|
| 118 | + if (empty($path)) { |
|
| 119 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
| 120 | + } |
|
| 121 | + // is file readable ? |
|
| 122 | + if ($read_check && ! is_readable($path)) { |
|
| 123 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
| 124 | + } |
|
| 125 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
| 127 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * get_autoloaders |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public static function get_autoloaders() |
|
| 144 | + { |
|
| 145 | + return self::$_autoloaders; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * register core, model and class 'autoloaders' |
|
| 153 | + * |
|
| 154 | + * @access private |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + private function _register_custom_autoloaders() |
|
| 158 | + { |
|
| 159 | + EEH_Autoloader::$debug = ''; |
|
| 160 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
| 161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 164 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 165 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 167 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 168 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 169 | + EEH_Debug_Tools::instance()->show_times(); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * register core, model and class 'autoloaders' |
|
| 177 | + * |
|
| 178 | + * @access public |
|
| 179 | + */ |
|
| 180 | + public static function register_helpers_autoloaders() |
|
| 181 | + { |
|
| 182 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * register core, model and class 'autoloaders' |
|
| 190 | + * |
|
| 191 | + * @access public |
|
| 192 | + * @return void |
|
| 193 | + */ |
|
| 194 | + public static function register_form_sections_autoloaders() |
|
| 195 | + { |
|
| 196 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * register core, model and class 'autoloaders' |
|
| 204 | + * |
|
| 205 | + * @access public |
|
| 206 | + * @return void |
|
| 207 | + */ |
|
| 208 | + public static function register_line_item_display_autoloaders() |
|
| 209 | + { |
|
| 210 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * register core, model and class 'autoloaders' |
|
| 218 | + * |
|
| 219 | + * @access public |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + public static function register_line_item_filter_autoloaders() |
|
| 223 | + { |
|
| 224 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * register template part 'autoloaders' |
|
| 232 | + * |
|
| 233 | + * @access public |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + public static function register_template_part_autoloaders() |
|
| 237 | + { |
|
| 238 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 245 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 246 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
| 247 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
| 248 | + * time the autoloader is used |
|
| 249 | + * |
|
| 250 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
| 251 | + * @param bool $recursive |
|
| 252 | + * @param bool $debug **deprecated** |
|
| 253 | + * @throws \EE_Error |
|
| 254 | + */ |
|
| 255 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
| 256 | + { |
|
| 257 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 258 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 259 | + } |
|
| 260 | + // make sure last char is a / |
|
| 261 | + $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
| 262 | + $class_to_filepath_map = array(); |
|
| 263 | + $exclude = array( 'index' ); |
|
| 264 | + // get all the files in that folder that end in php |
|
| 265 | + $filepaths = glob($folder.'*'); |
|
| 266 | + |
|
| 267 | + if (empty($filepaths)) { |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + foreach ($filepaths as $filepath) { |
|
| 272 | + if (substr($filepath, -4, 4) === '.php') { |
|
| 273 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 274 | + if (! in_array($class_name, $exclude)) { |
|
| 275 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 276 | + } |
|
| 277 | + } elseif ($recursive) { |
|
| 278 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 282 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 283 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 284 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * add_alias |
|
| 292 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 293 | + * |
|
| 294 | + * @access public |
|
| 295 | + * @param string $class_name - simple class name ie: EE_Session |
|
| 296 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 297 | + */ |
|
| 298 | + public static function add_alias($class_name, $alias) |
|
| 299 | + { |
|
| 300 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 301 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if (self::$_autoloaders === null) { |
| 54 | 54 | self::$_autoloaders = array(); |
| 55 | 55 | $this->_register_custom_autoloaders(); |
| 56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public static function instance() |
| 67 | 67 | { |
| 68 | 68 | // check if class object is instantiated |
| 69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | 70 | self::$_instance = new self(); |
| 71 | 71 | } |
| 72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public static function espresso_autoloader($class_name) |
| 87 | 87 | { |
| 88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 89 | + require_once(self::$_autoloaders[$class_name]); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
| 105 | 105 | { |
| 106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
| 107 | 107 | foreach ($class_paths as $class => $path) { |
| 108 | 108 | // skip all files that are not PHP |
| 109 | 109 | if (substr($path, strlen($path) - 3) !== 'php') { |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | if ($read_check && ! is_readable($path)) { |
| 123 | 123 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
| 124 | 124 | } |
| 125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
| 127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 125 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
| 126 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path); |
|
| 127 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
| 128 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | EEH_Autoloader::$debug = ''; |
| 160 | 160 | \EEH_Autoloader::register_helpers_autoloaders(); |
| 161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
| 162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
| 163 | 163 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
| 164 | 164 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
| 165 | 165 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
| 166 | 166 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
| 167 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 167 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
| 168 | 168 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
| 169 | 169 | EEH_Debug_Tools::instance()->show_times(); |
| 170 | 170 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public static function register_line_item_display_autoloaders() |
| 209 | 209 | { |
| 210 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 210 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public static function register_line_item_filter_autoloaders() |
| 223 | 223 | { |
| 224 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 224 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | public static function register_template_part_autoloaders() |
| 237 | 237 | { |
| 238 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 238 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
| 259 | 259 | } |
| 260 | 260 | // make sure last char is a / |
| 261 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
| 261 | + $folder .= $folder[strlen($folder) - 1] !== DS ? DS : ''; |
|
| 262 | 262 | $class_to_filepath_map = array(); |
| 263 | - $exclude = array( 'index' ); |
|
| 263 | + $exclude = array('index'); |
|
| 264 | 264 | // get all the files in that folder that end in php |
| 265 | 265 | $filepaths = glob($folder.'*'); |
| 266 | 266 | |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | foreach ($filepaths as $filepath) { |
| 272 | 272 | if (substr($filepath, -4, 4) === '.php') { |
| 273 | 273 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
| 274 | - if (! in_array($class_name, $exclude)) { |
|
| 275 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 274 | + if ( ! in_array($class_name, $exclude)) { |
|
| 275 | + $class_to_filepath_map [$class_name] = $filepath; |
|
| 276 | 276 | } |
| 277 | 277 | } elseif ($recursive) { |
| 278 | 278 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public static function add_alias($class_name, $alias) |
| 299 | 299 | { |
| 300 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 301 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 300 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 301 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | } |
@@ -12,121 +12,121 @@ |
||
| 12 | 12 | class EE_Register_Model_Extensions implements EEI_Plugin_API |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - protected static $_registry; |
|
| 16 | - protected static $_extensions = array(); |
|
| 15 | + protected static $_registry; |
|
| 16 | + protected static $_extensions = array(); |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * register method for setting up model extensions |
|
| 20 | - * |
|
| 21 | - * @param string $model_id unique id for the extensions being setup |
|
| 22 | - * @param array $config { |
|
| 23 | - * @throws EE_Error |
|
| 24 | - * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
| 25 | - * the models naming convention, which is: EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. Where |
|
| 26 | - * your_plugin_slug} is really anything you want (but something having to do with your addon, like |
|
| 27 | - * 'Calendar' or '3D_View') and model_name_extended} is the model extended. The class contained in teh file |
|
| 28 | - * should extend EEME_Base_{model_name_extended}.model_ext.php. Where {your_plugin_slug} is really anything |
|
| 29 | - * you want (but something having to do with your addon, like 'Calendar' or '3D_View') and |
|
| 30 | - * {model_name_extended} is the model extended. The class contained in teh file should extend EEME_Base |
|
| 31 | - * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
| 32 | - * the model class extension naming convention, which is: |
|
| 33 | - * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. Where your_plugin_slug} is something like |
|
| 34 | - * 'Calendar','MailChimp',etc, and model_name_extended} is the name of the model extended, eg |
|
| 35 | - * 'Attendee','Event',etc. The class contained in the file should extend |
|
| 36 | - * EEE_Base_Class._{model_name_extended}.class_ext.php. Where {your_plugin_slug} is something like |
|
| 37 | - * 'Calendar','MailChimp',etc, and {model_name_extended} is the name of the model extended, eg |
|
| 38 | - * 'Attendee','Event',etc. The class contained in the file should extend EEE_Base_Class. |
|
| 39 | - * } |
|
| 40 | - * |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public static function register($model_id = null, $config = array()) |
|
| 44 | - { |
|
| 45 | - // required fields MUST be present, so let's make sure they are. |
|
| 46 | - if (empty($model_id) |
|
| 47 | - || ! is_array($config) |
|
| 48 | - || (empty($config['model_extension_paths']) && empty($config['class_extension_paths'])) |
|
| 49 | - ) { |
|
| 50 | - throw new EE_Error( |
|
| 51 | - __( |
|
| 52 | - 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ) |
|
| 55 | - ); |
|
| 56 | - } |
|
| 18 | + /** |
|
| 19 | + * register method for setting up model extensions |
|
| 20 | + * |
|
| 21 | + * @param string $model_id unique id for the extensions being setup |
|
| 22 | + * @param array $config { |
|
| 23 | + * @throws EE_Error |
|
| 24 | + * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
| 25 | + * the models naming convention, which is: EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. Where |
|
| 26 | + * your_plugin_slug} is really anything you want (but something having to do with your addon, like |
|
| 27 | + * 'Calendar' or '3D_View') and model_name_extended} is the model extended. The class contained in teh file |
|
| 28 | + * should extend EEME_Base_{model_name_extended}.model_ext.php. Where {your_plugin_slug} is really anything |
|
| 29 | + * you want (but something having to do with your addon, like 'Calendar' or '3D_View') and |
|
| 30 | + * {model_name_extended} is the model extended. The class contained in teh file should extend EEME_Base |
|
| 31 | + * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
| 32 | + * the model class extension naming convention, which is: |
|
| 33 | + * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. Where your_plugin_slug} is something like |
|
| 34 | + * 'Calendar','MailChimp',etc, and model_name_extended} is the name of the model extended, eg |
|
| 35 | + * 'Attendee','Event',etc. The class contained in the file should extend |
|
| 36 | + * EEE_Base_Class._{model_name_extended}.class_ext.php. Where {your_plugin_slug} is something like |
|
| 37 | + * 'Calendar','MailChimp',etc, and {model_name_extended} is the name of the model extended, eg |
|
| 38 | + * 'Attendee','Event',etc. The class contained in the file should extend EEE_Base_Class. |
|
| 39 | + * } |
|
| 40 | + * |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public static function register($model_id = null, $config = array()) |
|
| 44 | + { |
|
| 45 | + // required fields MUST be present, so let's make sure they are. |
|
| 46 | + if (empty($model_id) |
|
| 47 | + || ! is_array($config) |
|
| 48 | + || (empty($config['model_extension_paths']) && empty($config['class_extension_paths'])) |
|
| 49 | + ) { |
|
| 50 | + throw new EE_Error( |
|
| 51 | + __( |
|
| 52 | + 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ) |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - // make sure we don't register twice |
|
| 59 | - if (isset(self::$_registry[ $model_id ])) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - // check correct loading |
|
| 63 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
| 64 | - EE_Error::doing_it_wrong( |
|
| 65 | - __METHOD__, |
|
| 66 | - sprintf( |
|
| 67 | - __( |
|
| 68 | - 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - $model_id, |
|
| 72 | - '<br />', |
|
| 73 | - did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
| 74 | - did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
| 75 | - ), |
|
| 76 | - '4.3' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 58 | + // make sure we don't register twice |
|
| 59 | + if (isset(self::$_registry[ $model_id ])) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | + // check correct loading |
|
| 63 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
| 64 | + EE_Error::doing_it_wrong( |
|
| 65 | + __METHOD__, |
|
| 66 | + sprintf( |
|
| 67 | + __( |
|
| 68 | + 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + $model_id, |
|
| 72 | + '<br />', |
|
| 73 | + did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
| 74 | + did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
| 75 | + ), |
|
| 76 | + '4.3' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - self::$_registry[ $model_id ] = $config; |
|
| 81 | - self::$_extensions[ $model_id ] = array(); |
|
| 80 | + self::$_registry[ $model_id ] = $config; |
|
| 81 | + self::$_extensions[ $model_id ] = array(); |
|
| 82 | 82 | |
| 83 | - if (isset($config['model_extension_paths'])) { |
|
| 84 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
| 85 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
|
| 86 | - // remove all files that are not PHP |
|
| 87 | - foreach ($class_to_filepath_map as $class => $path) { |
|
| 88 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 89 | - unset($class_to_filepath_map[ $class ]); |
|
| 90 | - continue; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
| 94 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
| 95 | - self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
| 96 | - } |
|
| 97 | - unset($config['model_extension_paths']); |
|
| 98 | - } |
|
| 99 | - if (isset($config['class_extension_paths'])) { |
|
| 100 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
| 101 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
|
| 102 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
| 103 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
| 104 | - self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
| 105 | - } |
|
| 106 | - unset($config['class_extension_paths']); |
|
| 107 | - } |
|
| 108 | - foreach ($config as $unknown_key => $unknown_config) { |
|
| 109 | - throw new EE_Error( |
|
| 110 | - sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
| 111 | - ); |
|
| 112 | - } |
|
| 113 | - } |
|
| 83 | + if (isset($config['model_extension_paths'])) { |
|
| 84 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
| 85 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
|
| 86 | + // remove all files that are not PHP |
|
| 87 | + foreach ($class_to_filepath_map as $class => $path) { |
|
| 88 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 89 | + unset($class_to_filepath_map[ $class ]); |
|
| 90 | + continue; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
| 94 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
| 95 | + self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
| 96 | + } |
|
| 97 | + unset($config['model_extension_paths']); |
|
| 98 | + } |
|
| 99 | + if (isset($config['class_extension_paths'])) { |
|
| 100 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
| 101 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
|
| 102 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
| 103 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
| 104 | + self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
| 105 | + } |
|
| 106 | + unset($config['class_extension_paths']); |
|
| 107 | + } |
|
| 108 | + foreach ($config as $unknown_key => $unknown_config) { |
|
| 109 | + throw new EE_Error( |
|
| 110 | + sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * deregister |
|
| 118 | - * |
|
| 119 | - * @param string $model_id |
|
| 120 | - */ |
|
| 121 | - public static function deregister($model_id = null) |
|
| 122 | - { |
|
| 123 | - if (isset(self::$_registry[ $model_id ])) { |
|
| 124 | - unset(self::$_registry[ $model_id ]); |
|
| 125 | - foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
| 126 | - foreach ($extension_of_type as $extension) { |
|
| 127 | - $extension->deregister(); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 116 | + /** |
|
| 117 | + * deregister |
|
| 118 | + * |
|
| 119 | + * @param string $model_id |
|
| 120 | + */ |
|
| 121 | + public static function deregister($model_id = null) |
|
| 122 | + { |
|
| 123 | + if (isset(self::$_registry[ $model_id ])) { |
|
| 124 | + unset(self::$_registry[ $model_id ]); |
|
| 125 | + foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
| 126 | + foreach ($extension_of_type as $extension) { |
|
| 127 | + $extension->deregister(); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // make sure we don't register twice |
| 59 | - if (isset(self::$_registry[ $model_id ])) { |
|
| 59 | + if (isset(self::$_registry[$model_id])) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | // check correct loading |
| 63 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
| 63 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
| 64 | 64 | EE_Error::doing_it_wrong( |
| 65 | 65 | __METHOD__, |
| 66 | 66 | sprintf( |
@@ -77,31 +77,31 @@ discard block |
||
| 77 | 77 | ); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - self::$_registry[ $model_id ] = $config; |
|
| 81 | - self::$_extensions[ $model_id ] = array(); |
|
| 80 | + self::$_registry[$model_id] = $config; |
|
| 81 | + self::$_extensions[$model_id] = array(); |
|
| 82 | 82 | |
| 83 | 83 | if (isset($config['model_extension_paths'])) { |
| 84 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
| 84 | + require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php'); |
|
| 85 | 85 | $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
| 86 | 86 | // remove all files that are not PHP |
| 87 | 87 | foreach ($class_to_filepath_map as $class => $path) { |
| 88 | 88 | if (substr($path, strlen($path) - 3) !== 'php') { |
| 89 | - unset($class_to_filepath_map[ $class ]); |
|
| 89 | + unset($class_to_filepath_map[$class]); |
|
| 90 | 90 | continue; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
| 94 | 94 | foreach (array_keys($class_to_filepath_map) as $classname) { |
| 95 | - self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
| 95 | + self::$_extensions[$model_id]['models'][$classname] = new $classname; |
|
| 96 | 96 | } |
| 97 | 97 | unset($config['model_extension_paths']); |
| 98 | 98 | } |
| 99 | 99 | if (isset($config['class_extension_paths'])) { |
| 100 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
| 100 | + require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php'); |
|
| 101 | 101 | $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
| 102 | 102 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
| 103 | 103 | foreach (array_keys($class_to_filepath_map) as $classname) { |
| 104 | - self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
| 104 | + self::$_extensions[$model_id]['classes'][$classname] = new $classname; |
|
| 105 | 105 | } |
| 106 | 106 | unset($config['class_extension_paths']); |
| 107 | 107 | } |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public static function deregister($model_id = null) |
| 122 | 122 | { |
| 123 | - if (isset(self::$_registry[ $model_id ])) { |
|
| 124 | - unset(self::$_registry[ $model_id ]); |
|
| 125 | - foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
| 123 | + if (isset(self::$_registry[$model_id])) { |
|
| 124 | + unset(self::$_registry[$model_id]); |
|
| 125 | + foreach (self::$_extensions[$model_id] as $extension_of_type) { |
|
| 126 | 126 | foreach ($extension_of_type as $extension) { |
| 127 | 127 | $extension->deregister(); |
| 128 | 128 | } |