-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
170 lines (137 loc) · 5.81 KB
/
ajax.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
<?php
/*
Copyright (c) 2009-2011, Jarkko Laine.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
function donation_can_ajax_get_style_options() {
$nonce = $_REQUEST['nonce'];
if (!wp_verify_nonce($nonce, 'donation_can_ajax-style_options')) {
die('Nonce verification failed.');
}
if (current_user_can('dc_styles')) {
$widget = new DonationWidget();
$instance = array();
$style_id = esc_attr($_REQUEST['style']);
$number = esc_attr($_REQUEST["wn"]);
$widget->number = $number;
$settings = $widget->get_settings();
if (is_array($settings)) {
$instance = $settings[$number];
}
// TODO: see if this is needed anymore...?
// This is run before Donation Can has chance to load the texts properly, so we need to do it here manually...
//load_plugin_textdomain("donation_can", false, "donation-can");
echo $widget->get_widget_options($style_id, $instance);
}
exit;
}
function donation_can_ajax_style_autocomplete() {
$q = strtolower($_REQUEST["q"]);
if (!$q) exit;
$items = array(
".backlink",
".backlink a",
".description",
".donations-list",
".donations-list li",
".donation-date",
".donation-options",
".donation-options .donation-callout",
".donation-options .donation-button-list",
".donation-options .donation-button-list a.button",
".donation-options select",
".progress-element",
".progress-element .progress-meter",
".progress-element .progress-meter .progress-container",
".progress-element .progress-meter .progress-container .progress-bar",
".progress-element .progress-text",
".progress-element .progress-text .percentage",
".progress-element .progress-text .raised-label",
".progress-element .progress-text .of-label",
".progress-element .progress-text .currency",
".progress-element .progress-text .goal",
".progress-element .progress-text .goal-label",
".progress-element .progress-text .raised",
".submit-donation",
".submit-donation input",
".custom-text",
".donation-widget-title",
".donation-can-cause-selection"
);
header("Content-type: text/plain");
foreach ($items as $key) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key\n";
}
}
exit;
}
function donation_can_ajax_get_cause_data() {
// Donation cause data
$cause_code = esc_attr(esc_attr($_REQUEST['cause']));
$cause = donation_can_get_goal($cause_code);
$filtered_cause = array(
"donation_goal" => $cause["donation_goal"],
"currency" => $cause["currency"],
"description" => $cause["description"],
"donation_options" => $cause["donation_sums"]
);
echo json_encode($filtered_cause);
exit;
}
function donation_can_ajax_export() {
$nonce = $_REQUEST['_wpnonce'];
$type = esc_attr($_REQUEST['type']);
$requested_format = esc_attr($_REQUEST['format']);
if (!strcasecmp($requested_format, "csv") && !strcasecmp($requested_format, "xml")) {
$requested_format = "csv";
}
if ($type != "causes" && $type != "donations" && $type != "settings" && $type != "styles") {
die("Invalid export type: " . $type);
}
if (!wp_verify_nonce($nonce, 'donation_can_ajax-export')) {
die('Nonce verification failed.');
}
if (current_user_can('dc_general_settings')) {
$exporter = new DonationCanDataExport(donation_can_get_options_handler());
$format = 'csv';
if ($type == "causes") {
$output = $exporter->exportCauses(strtoupper($requested_format));
$format = strtolower($requested_format);
$filename = 'donation_can-causes.' . date('Y-m-d') . '.' . $format;
} else if ($type == "settings") {
$output = $exporter->exportSettings();
$filename = 'donation_can-settings.' . date('Y-m-d') . '.xml';
$format = 'xml';
} else if ($type == "styles") {
$output = $exporter->exportStyles();
$filename = 'donation_can-styles.' . date('Y-m-d') . '.xml';
$format = 'xml';
} else if ($type == "donations") {
$output = $exporter->exportDonations(strtoupper($requested_format));
$format = strtolower($requested_format);
$filename = 'donation_can-donations.' . date('Y-m-d') . '.' . $format;
}
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $filename);
header('Content-Type: text/' . $format . '; charset=' . get_option( 'blog_charset' ), true);
echo $output;
}
exit;
}
add_action('wp_ajax_donation_can-get_style_options', 'donation_can_ajax_get_style_options');
add_action('wp_ajax_nopriv_donation_can-get_cause_data', 'donation_can_ajax_get_cause_data');
add_action('wp_ajax_donation_can-get_cause_data', 'donation_can_ajax_get_cause_data');
add_action('wp_ajax_donation_can-style_autocomplete', 'donation_can_ajax_style_autocomplete');
add_action('wp_ajax_donation_can-export', 'donation_can_ajax_export');
?>