-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathninja-forms-firebase.php
More file actions
180 lines (148 loc) · 4.88 KB
/
ninja-forms-firebase.php
File metadata and controls
180 lines (148 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/*
* Plugin Name: Ninja Forms - Firebase
* Plugin URI: http://www.burak-dogan.com/ninja-forms-firebase
* Description: Plugin simply integrates firebase database with ninja forms
* Version: 3.1.0
* Author: Burak Doğan
* Author URI: http://www.burak-dogan.com
* Text Domain: ninja-forms-firebase
*
* Copyright 2017 Burak Doğan.
*/
if( version_compare( get_option( 'ninja_forms_version', '0.0.0' ), '3', '<' ) || get_option( 'ninja_forms_load_deprecated', FALSE ) ) {
//include 'deprecated/ninja-forms-firebase.php';
} else {
/**
* Class NF_Firebase
*/
final class NF_Firebase
{
const VERSION = '0.0.2';
const SLUG = 'firebase';
const NAME = 'Firebase';
const AUTHOR = 'Burak Doğan';
const PREFIX = 'NF_Firebase';
/**
* @var NF_Firebase
* @since 3.0
*/
private static $instance;
/**
* Plugin Directory
*
* @since 3.0
* @var string $dir
*/
public static $dir = '';
/**
* Plugin URL
*
* @since 3.0
* @var string $url
*/
public static $url = '';
/**
* Main Plugin Instance
*
* Insures that only one instance of a plugin class exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 3.0
* @static
* @static var array $instance
* @return NF_Firebase Highlander Instance
*/
public static function instance()
{
if (!isset(self::$instance) && !(self::$instance instanceof NF_Firebase)) {
self::$instance = new NF_Firebase();
self::$dir = plugin_dir_path(__FILE__);
self::$url = plugin_dir_url(__FILE__);
/*
* Register our autoloader
*/
spl_autoload_register(array(self::$instance, 'autoloader'));
}
return self::$instance;
}
public function __construct()
{
/*
* Required for all Extensions.
*/
add_action( 'admin_init', array( $this, 'setup_license') );
/*
* Optional. If your extension processes or alters form submission data on a per form basis...
*/
add_filter( 'ninja_forms_register_actions', array($this, 'register_actions'));
}
/**
* Optional. If your extension processes or alters form submission data on a per form basis...
*/
public function register_actions($actions)
{
$actions[ 'firebase' ] = new NF_Firebase_Actions_SendFirebaseDatabase(); // includes/Actions/SendFirebaseDatabase.php
return $actions;
}
/*
* Optional methods for convenience.
*/
public function autoloader($class_name)
{
if (class_exists($class_name)) return;
if ( false === strpos( $class_name, self::PREFIX ) ) return;
$class_name = str_replace( self::PREFIX, '', $class_name );
$classes_dir = realpath(plugin_dir_path(__FILE__)) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;
$class_file = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
if (file_exists($classes_dir . $class_file)) {
require_once $classes_dir . $class_file;
}
}
/**
* Template
*
* @param string $file_name
* @param array $data
*/
public static function template( $file_name = '', array $data = array() )
{
if( ! $file_name ) return;
extract( $data );
include self::$dir . 'includes/Templates/' . $file_name;
}
/**
* Config
*
* @param $file_name
* @return mixed
*/
public static function config( $file_name )
{
return include self::$dir . 'includes/Config/' . $file_name . '.php';
}
/*
* Required methods for all extension.
*/
public function setup_license()
{
if ( ! class_exists( 'NF_Extension_Updater' ) ) return;
new NF_Extension_Updater( self::NAME, self::VERSION, self::AUTHOR, __FILE__, self::SLUG );
}
}
/**
* The main function responsible for returning The Highlander Plugin
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* @since 3.0
* @return {class} Highlander Instance
*/
function NF_Firebase()
{
return NF_Firebase::instance();
}
NF_Firebase();
}