-
Notifications
You must be signed in to change notification settings - Fork 0
/
city_proxy.php
58 lines (50 loc) · 2.44 KB
/
city_proxy.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
<?php
require_once 'lib/chipin/lib/the_city_chipin.php';
require_once 'lib/chipin_wordpress_cache.php';
add_action('wp_ajax_thecity_process_request', 'thecity_process_request_callback');
function thecity_process_request_callback() {
$api_key = isset($_POST['api_key']) ? $_POST['api_key'] : '';
$user_token = isset($_POST['user_token']) ? $_POST['user_token'] : '';
$load = isset($_POST['load']) ? $_POST['load'] : '';
$html = array();
switch($load) {
case 'campuses':
$html = array('campuses' => array());
$campuses = TheCityChipin::campus_options($api_key, $user_token);
foreach ($campuses as $id => $name) { $html['campuses'][] = array('id' => $id, 'name' => $name); }
break;
case 'funds':
$campus_id = isset($_POST['campus_id']) ? $_POST['campus_id'] : 0;
$html = array('campus_id' => $campus_id, 'funds' => array());
$funds = TheCityChipin::fund_options($api_key, $user_token, $campus_id);
foreach ($funds as $id => $name) { $html['funds'][] = array('id' => $id, 'name' => $name); }
break;
case 'info':
$chipin_widget_id = isset($_POST['chipin_widget_id']) ? $_POST['chipin_widget_id'] : '';
global $wpdb;
$cacher = new ChipinWordPressCache($wpdb);
$data = $cacher->get_data($chipin_widget_id);
if(!is_null($data)) {
$white_list = empty($data['designation']) ? array() : array($data['designation']);
$chipin = new TheCityChipin($data['secret_key'], $data['user_token'], $data['campus_id'], $data['fund_id'], $data['start_date'], $data['end_date']);
$chipin->donations($white_list);
$html['totals'] = $chipin->designation_totals();
$html['widget_info'] = array(
'subdomain_key' => $data['subdomain_key'],
'campus_name' => $data['campus_name'],
'campus_id' => $data['campus_id'],
'fund_id' => $data['fund_id'],
'designation' => $data['designation'],
'suggested_amount' => $data['suggested_amount'],
'display_choice' => $data['display_choice'],
'start_date' => $data['start_date'],
'end_date' => $data['end_date'],
'goal_amount' => $data['goal_amount']
);
}
break;
}
echo json_encode($html);
die(); // this is required to return a proper result
}
?>