/
load.php
215 lines (161 loc) · 5.43 KB
/
load.php
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* Payments load
*
* @package Components\Payments
*/
add_action( 'after_setup_theme', '_appthemes_load_payments', 998 );
add_action( 'after_setup_theme', '_appthemes_load_price_format', 999 );
function _appthemes_load_payments() {
if ( !current_theme_supports( 'app-payments' ) )
return;
require APP_FRAMEWORK_DIR . '/load-p2p.php';
require_once APP_FRAMEWORK_DIR . '/includes/tables.php';
require_once APP_FRAMEWORK_DIR . '/admin/class-meta-box.php';
require_once APP_FRAMEWORK_DIR . '/admin/class-tabs-page.php';
require dirname( __FILE__ ) . '/utils/queue.php';
require dirname( __FILE__ ) . '/utils/log.php';
// Orders
require dirname( __FILE__ ) . '/order-class.php';
require dirname( __FILE__ ) . '/order-factory.php';
require dirname( __FILE__ ) . '/order-draft-class.php';
require dirname( __FILE__ ) . '/order-receipt-class.php';
require dirname( __FILE__ ) . '/order-functions.php';
require dirname( __FILE__ ) . '/order-upgrade.php';
require dirname( __FILE__ ) . '/order-templates.php';
require dirname( __FILE__ ) . '/item-registry.php';
if( is_admin() ){
require dirname( __FILE__ ) . '/admin/admin.php';
require dirname( __FILE__ ) . '/admin/order-list.php';
require dirname( __FILE__ ) . '/admin/order-single.php';
require dirname( __FILE__ ) . '/admin/settings.php';
require dirname( __FILE__ ) . '/admin/order-meta.php';
APP_Connected_Post_Orders::init();
APP_Connected_User_Orders::init();
}
// Gateways
require_once( dirname( __FILE__ ) . '/gateways/gateway-class.php' );
require_once( dirname( __FILE__ ) . '/gateways/boomerang-class.php' );
require_once( dirname( __FILE__ ) . '/gateways/gateway-registry.php' );
require_once( dirname( __FILE__ ) . '/gateways/gateway-functions.php' );
require_once( dirname( __FILE__ ) . '/gateways/paypal/paypal.php' );
require_once( dirname( __FILE__ ) . '/gateways/bank-transfer/bank-transfer.php' );
// Load escrow
require_once( dirname( __FILE__ ) . '/escrow/load.php' );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
require_once( dirname( __FILE__ ) . '/gateways/test/test.php' );
}
new APP_Order_Summary;
extract( appthemes_payments_get_args(), EXTR_SKIP );
if( !current_theme_supports( 'app-price-format') ){
add_theme_support( 'app-price-format', array() );
}
appthemes_load_items();
appthemes_load_options();
}
function appthemes_load_items(){
extract( appthemes_payments_get_args(), EXTR_SKIP );
if( !empty( $items ) ){
foreach( $items as $item ){
if( !isset( $item['type'] ) || !isset( $item['title'] ) )
continue;
if( !isset( $item['meta'] ) )
$item['meta'] = array();
APP_Item_Registry::register( $item['type'], $item['title'], $item['meta'] );
}
}
}
function appthemes_load_options(){
extract( appthemes_payments_get_args(), EXTR_SKIP );
if( is_admin() )
APP_Connected_Post_Orders::add_post_type( $items_post_types );
if( $options ){
APP_Gateway_Registry::register_options( $options );
}
else{
$defaults = array(
'currency_code' => 'USD',
'currency_identifier' => 'symbol',
'currency_position' => 'left',
'thousands_separator' => ',',
'decimal_separator' => '.',
'tax_charge' => 0,
'gateways' => array(
'enabled' => array()
)
);
$options = new scbOptions( 'app_payments', false, $defaults );
APP_Gateway_Registry::register_options( $options );
}
}
function appthemes_payments_get_args( $option = '' ){
static $original = array();
static $generated = array();
if( ! current_theme_supports( 'app-payments' ) ) {
return array();
}
$args_sets = get_theme_support( 'app-payments' );
if ( $original != $args_sets ) {
// numeric array, contains multiple sets of arguments
// first item contains preferable set
$original = $args_sets;
if ( ! is_array( $args_sets ) ) {
$args_sets = array();
}
$args = array();
foreach ( $args_sets as $args_set ) {
foreach ( $args_set as $key => $arg ) {
if ( ! isset( $args[ $key ] ) ) {
$args[ $key ] = $arg;
} elseif ( 'escrow' === $key && $arg ) {
$args[ $key ] = true;
} elseif ( is_array( $arg ) ) {
$args[ $key ] = array_merge_recursive( (array) $args[ $key ], $arg );
}
}
}
$defaults = array(
'items' => array(),
'items_post_types' => array( 'post' ),
'options' => false,
'images_url' => get_template_directory_uri() . '/includes/payments/images/',
'templates' => array(
'bank-transfer' => 'order-bank-transfer.php',
),
'escrow' => false,
);
$generated = wp_parse_args( $args, $defaults );
}
if ( empty( $option ) ) {
return $generated;
} else {
return $generated[ $option ];
}
}
function _appthemes_load_price_format() {
if ( !current_theme_supports( 'app-price-format' ) )
return;
require dirname( __FILE__ ) . '/utils/currencies.php';
require dirname( __FILE__ ) . '/utils/numbers.php';
}
function appthemes_price_format_get_args( $option = '', $force = false ){
if( !current_theme_supports( 'app-price-format' ) && !$force )
return array();
list($args) = get_theme_support( 'app-price-format' );
$defaults = array(
'currency_default' => 'USD',
'currency_identifier' => 'symbol',
'currency_position' => 'left',
'thousands_separator' => ',',
'decimal_separator' => '.',
'hide_decimals' => false,
);
$args = wp_parse_args( $args, $defaults );
if( !in_array( $args['currency_identifier'], array( 'symbol', 'code') ) ){
$args['currency_identifier'] = 'symbol';
}
if( empty( $option ) )
return $args;
else
return $args[ $option ];
}