Completed
Push — master ( ac7d8e...ec16eb )
by Stephanie
05:53 queued 02:59
created

formidable.php ➔ frm_class_autoloader()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 10
nop 2
dl 0
loc 22
rs 6.9811
c 0
b 0
f 0
1
<?php
2
/*
3
Plugin Name: Formidable Forms
4
Description: Quickly and easily create drag-and-drop forms
5
Version: 3.0.03
6
Plugin URI: https://formidableforms.com/
7
Author URI: https://formidableforms.com/
8
Author: Strategy11
9
Text Domain: formidable
10
*/
11
12
/*  Copyright 2010  Formidable Forms
13
14
    This program is free software; you can redistribute it and/or modify
15
    it under the terms of the GNU General Public License, version 2, as
16
    published by the Free Software Foundation.
17
18
    This program is distributed in the hope that it will be useful,
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
    GNU General Public License for more details.
22
*/
23
24
add_action( 'plugins_loaded', 'load_formidable_forms', 0 );
25
function load_formidable_forms() {
26
	global $frm_vars;
27
	$frm_vars = array(
28
    	'load_css'     => false,
29
		'forms_loaded' => array(),
30
    	'created_entries'   => array(),
31
    	'pro_is_authorized' => false,
32
	);
33
34
	$frm_path = dirname(__FILE__);
35
	if ( file_exists( $frm_path . '/pro/formidable-pro.php' ) ) {
36
		include( $frm_path . '/pro/formidable-pro.php' );
37
	}
38
39
	FrmHooksController::trigger_load_hook();
40
}
41
42
// if __autoload is active, put it on the spl_autoload stack
43
if ( is_array( spl_autoload_functions() ) && in_array( '__autoload', spl_autoload_functions() ) ) {
44
    spl_autoload_register('__autoload');
45
}
46
47
// Add the autoloader
48
spl_autoload_register('frm_forms_autoloader');
49
50
function frm_forms_autoloader( $class_name ) {
51
    // Only load Frm classes here
52
	if ( ! preg_match( '/^Frm.+$/', $class_name ) || preg_match( '/^FrmPro.+$/', $class_name ) ) {
53
        return;
54
    }
55
56
	frm_class_autoloader( $class_name, dirname( __FILE__ ) );
57
}
58
59
/**
60
 * Autoload the Formidable and Pro classes
61
 * @since 3.0
62
 */
63
function frm_class_autoloader( $class_name, $filepath ) {
64
	$filepath .= '/classes';
65
66
	if ( preg_match( '/^.+Helper$/', $class_name ) ) {
67
		$filepath .= '/helpers/';
68
	} else if ( preg_match( '/^.+Controller$/', $class_name ) ) {
69
		$filepath .= '/controllers/';
70
	} else if ( preg_match( '/^.+Factory$/', $class_name ) ) {
71
		$filepath .= '/factories/';
72
	} else {
73
		$filepath .= '/models/';
74
		if ( strpos( $class_name, 'Field' ) && ! file_exists( $filepath . $class_name . '.php' ) ) {
75
			$filepath .= 'fields/';
76
		}
77
	}
78
79
	$filepath .= $class_name . '.php';
80
81
	if ( file_exists( $filepath ) ) {
82
		require( $filepath );
83
	}
84
}
85
86
register_activation_hook( __FILE__, 'FrmAppController::activation_install' );
87