PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.22.3
GiveWP – Donation Plugin and Fundraising Platform v2.22.3
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / Views / Form / Templates / Classic / Classic.php
give / src / Views / Form / Templates / Classic Last commit date
resources 3 years ago Classic.php 4 years ago optionConfig.php 4 years ago
Classic.php
401 lines
1 <?php
2
3 namespace Give\Views\Form\Templates\Classic;
4
5 use Give\Helpers\Form\Template\Utils\Frontend;
6 use Give_Donate_Form;
7 use Give\Form\Template;
8 use Give\Form\Template\Hookable;
9 use Give\Form\Template\Scriptable;
10 use Give\Helpers\Form\Template as FormTemplateUtils;
11 use Give\Receipt\DonationReceipt;
12 use InvalidArgumentException;
13
14 /**
15 * Classic Donation Form Template
16 *
17 * @since 2.18.0
18 */
19 class Classic extends Template implements Hookable, Scriptable
20 {
21 /**
22 * @var array
23 */
24 private $options;
25
26 /**
27 * @var bool
28 */
29 private $scriptsLoaded = false;
30
31 public function __construct()
32 {
33 $this->options = FormTemplateUtils::getOptions();
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public function getID()
40 {
41 return 'classic';
42 }
43
44 /**
45 * @inheritDoc
46 */
47 public function getName()
48 {
49 return __('Classic Form', 'give');
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function getImage()
56 {
57 return GIVE_PLUGIN_URL . 'assets/dist/images/admin/template-preview-classic.png';
58 }
59
60 /**
61 * @inheritDoc
62 */
63 public function getOptionsConfig()
64 {
65 return require 'optionConfig.php';
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function loadHooks()
72 {
73 add_action('give_pre_form', [$this, 'renderIconDefinitions']);
74
75 // Display header
76 if ('enabled' === $this->options[ 'visual_appearance' ][ 'display_header' ]) {
77 add_action('give_pre_form', [$this, 'renderHeader'], 10, 3);
78 }
79
80 add_action('give_before_donation_levels', [$this, 'renderDonationAmountHeading'], 20);
81
82 $sections = [
83 [
84 'hooks' => ['give_donation_form_top'],
85 'class' => 'give-donation-amount-section',
86 ],
87 [
88 'hooks' => ['give_donation_form_register_login_fields'],
89 'class' => 'give-personal-info-section',
90 ],
91 [
92 'hooks' => ['give_payment_mode_top', 'give_payment_mode_bottom'],
93 'class' => 'give-payment-details-section',
94 ],
95 [
96 'hooks' => ['give_donation_form_before_submit', 'give_donation_form_after_submit'],
97 'class' => 'give-donate-now-button-section',
98 ],
99 [
100 'hooks' => ['give_donation_summary_top', 'give_donation_summary_bottom'],
101 'class' => 'give-donation-form-summary-section',
102 ],
103 ];
104
105 foreach ($sections as $section) {
106 list ($start, $end) = array_pad($section[ 'hooks' ], 2, null);
107
108 add_action($start, function () use ($section) {
109 printf('<section class="give-form-section %s">', $section[ 'class' ]);
110 }, -10000);
111
112 add_action($end ? : $start, function () {
113 echo '</section>';
114 }, 10000);
115 }
116
117 /**
118 * Remove actions
119 */
120 // Remove goal.
121 remove_action('give_pre_form', 'give_show_goal_progress');
122 // Remove intermediate continue button which appears when display style set to anything other than "onpage".
123 remove_action('give_after_donation_levels', 'give_display_checkout_button');
124 // Hide title.
125 add_filter('give_form_title', '__return_empty_string');
126 }
127
128
129 /**
130 * @inheritDoc
131 */
132 public function loadScripts()
133 {
134 if ($this->scriptsLoaded) {
135 return;
136 }
137
138 $this->scriptsLoaded = true;
139
140 // Font
141 if ($primaryFont = $this->getPrimaryFont()) {
142 wp_enqueue_style(
143 'give-google-font',
144 'https://fonts.googleapis.com/css?family=' . urlencode($primaryFont) . ':400,500,600,700&display=swap',
145 [],
146 GIVE_VERSION
147 );
148 }
149
150 wp_enqueue_style(
151 'give-classic-template',
152 GIVE_PLUGIN_URL . 'assets/dist/css/give-classic-template.css',
153 [],
154 GIVE_VERSION
155 );
156
157 // We are replacing the Give styles with this template. Let’s not fight
158 // against ourselves. This will help us not need to write such specific
159 // styles so that users can still override ours.
160 add_action('wp_enqueue_scripts', function () {
161 wp_dequeue_style('give-styles');
162 wp_dequeue_style('give_recurring_css');
163 wp_dequeue_style('give-currency-switcher-style');
164 wp_dequeue_style('give-fee-recovery');
165 wp_dequeue_style('give-donation-summary-style-frontend');
166 wp_dequeue_style('give-authorize-css');
167 }, 10);
168
169 // CSS Variables
170 wp_add_inline_style(
171 'give-classic-template',
172 $this->loadFile('css/variables.php', [
173 'primaryColor' => $this->options[ 'visual_appearance' ][ 'primary_color' ],
174 'headerBackgroundImage' => $this->options[ 'visual_appearance' ][ 'header_background_image' ],
175 'headerBackgroundColor' => $this->options[ 'visual_appearance' ][ 'header_background_color' ],
176 'statsProgressBarColor' => give_get_meta(Frontend::getFormId(), '_give_goal_color', true),
177 'primaryFont' => $primaryFont ? : 'inherit'
178 ])
179 );
180
181 // JS
182 wp_enqueue_script(
183 'give-classic-template-js',
184 GIVE_PLUGIN_URL . 'assets/dist/js/give-classic-template.js',
185 ['give'],
186 GIVE_VERSION,
187 true
188 );
189
190 wp_localize_script(
191 'give-classic-template-js',
192 'classicTemplateOptions',
193 $this->options
194 );
195 }
196
197 /**
198 * @inheritDoc
199 */
200 public function getLoadingView()
201 {
202 return $this->loadFile('views/loading.php', [
203 'options' => $this->options[ 'visual_appearance' ]
204 ]);
205 }
206
207 /**
208 * @inheritDoc
209 */
210 public function renderLoadingView($formId = null)
211 {
212 echo $this->getLoadingView();
213 }
214
215 /**
216 * @inheritDoc
217 */
218 public function getReceiptView()
219 {
220 return wp_doing_ajax()
221 ? $this->getFilePath('views/receipt.php')
222 : parent::getReceiptView();
223 }
224
225 /**
226 * Render donation form header
227 *
228 * @since 2.19.0 use trinary operator instead of Coalesce operator to make code php 5.6 compatible.
229 *
230 * @param int $formId
231 * @param array $args
232 * @param Give_Donate_Form $form
233 */
234 public function renderHeader($formId, $args, $form)
235 {
236 $hasGoal = $form->has_goal();
237
238 echo $this->loadFile('views/header.php', [
239 'title' => isset($this->options['visual_appearance']['main_heading']) ? $this->options['visual_appearance']['main_heading'] : $form->post_title,
240 'description' => $this->options[ 'visual_appearance' ][ 'description' ],
241 'isSecureBadgeEnabled' => $this->options[ 'visual_appearance' ][ 'secure_badge' ] === 'enabled',
242 'secureBadgeContent' => $this->options[ 'visual_appearance' ][ 'secure_badge_text' ],
243 'hasGoal' => $hasGoal,
244 'goalStats' => $hasGoal ? $this->getFormGoalStats($form) : []
245 ]);
246 }
247
248 /**
249 * Render donation amount heading
250 */
251 public function renderDonationAmountHeading()
252 {
253 echo $this->loadFile('views/donation-amount-heading.php', [
254 'content' => $this->options[ 'donation_amount' ][ 'headline' ],
255 ]);
256 }
257
258 /**
259 * Render the SVG icon definitions.
260 *
261 * @void
262 */
263 public function renderIconDefinitions()
264 {
265 echo $this->loadFile('views/icon-defs.php');
266 }
267
268 /**
269 * @inheritDoc
270 */
271 public function getReceiptDetails($donationId)
272 {
273 $receipt = new DonationReceipt($donationId);
274
275 $receipt->heading = esc_html(give_do_email_tags($this->options[ 'donation_receipt' ][ 'headline' ], ['payment_id' => $donationId]));
276 $receipt->message = wp_kses_post(give_do_email_tags($this->options[ 'donation_receipt' ][ 'description' ], ['payment_id' => $donationId]));
277
278 /**
279 * Fire the action for receipt object.
280 *
281 * @since 2.7.0
282 */
283 do_action('give_new_receipt', $receipt);
284
285 return $receipt;
286 }
287
288 public function getFormGoalStats(Give_Donate_Form $form)
289 {
290 $goalStats = give_goal_progress_stats($form->get_ID());
291 $raisedRaw = $form->get_earnings();
292
293 // Setup default raised value
294 $raised = give_currency_filter(
295 give_format_amount(
296 $raisedRaw,
297 [
298 'sanitize' => false,
299 'decimal' => false,
300 ]
301 )
302 );
303
304 // Setup default count value
305 $count = $form->get_sales();
306
307 // Setup default count label
308 $countLabel = _n('donation', 'donations', $count, 'give');
309
310 // Setup default goal value
311 $goal = give_currency_filter(
312 give_format_amount(
313 $form->get_goal(),
314 [
315 'sanitize' => false,
316 'decimal' => false,
317 ]
318 )
319 );
320
321 $stats = [
322 'raised' => $raised,
323 'raisedRaw' => $raisedRaw,
324 'progress' => $goalStats[ 'progress' ],
325 'count' => $count,
326 'countLabel' => $countLabel,
327 'goal' => $goal,
328 'goalRaw' => $goalStats[ 'raw_goal' ],
329 ];
330
331 switch ($goalStats[ 'format' ]) {
332 case 'donation':
333 return array_merge($stats, [
334 'count' => $goalStats[ 'actual' ],
335 'goal' => $goalStats[ 'goal' ],
336 ]);
337
338 case 'donors':
339 return array_merge($stats, [
340 'count' => $goalStats[ 'actual' ],
341 'countLabel' => _n('donor', 'donors', $count, 'give'),
342 'goal' => $goalStats[ 'goal' ],
343 ]);
344
345 default:
346 return $stats;
347 }
348 }
349
350 /**
351 * Load file
352 *
353 * @param string $file
354 * @param array $args
355 *
356 * @return string
357 * @throws InvalidArgumentException
358 *
359 */
360 protected function loadFile($file, $args = [])
361 {
362 $filePath = $this->getFilePath($file);
363
364 if (! file_exists($filePath)) {
365 throw new InvalidArgumentException("File {$filePath} does not exist");
366 }
367
368 ob_start();
369 extract($args);
370 include $filePath;
371
372 return ob_get_clean();
373 }
374
375 /**
376 * Get file path
377 *
378 * @param string $file
379 *
380 * @return string
381 */
382 protected function getFilePath($file = '')
383 {
384 return GIVE_PLUGIN_DIR . "src/Views/Form/Templates/Classic/resources/{$file}";
385 }
386
387 /**
388 * @return string|null
389 */
390 protected function getPrimaryFont()
391 {
392 $primaryFont = $this->options[ 'visual_appearance' ][ 'primary_font' ];
393
394 if ($primaryFont !== 'system') {
395 return $primaryFont;
396 }
397
398 return null;
399 }
400 }
401