PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.15.4
GiveWP – Donation Plugin and Fundraising Platform v4.15.4
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 / Form / Template.php
give / src / Form Last commit date
LegacyConsumer 1 year ago Template 3 years ago LoadTemplate.php 4 years ago Template.php 1 year ago Templates.php 3 years ago
Template.php
349 lines
1 <?php
2
3 /**
4 * Handle basic setup of form template
5 *
6 * @package Give
7 * @since 2.7.0
8 */
9
10 namespace Give\Form;
11
12 use Give\DonationForms\Models\DonationForm;
13 use Give\Form\Template\Options;
14 use Give\Helpers\Form\Utils;
15 use Give\Helpers\Form\Utils as FormUtils;
16 use Give\Receipt\DonationReceipt;
17
18 defined('ABSPATH') || exit;
19
20 /**
21 * Template class.
22 *
23 * @since 2.7.0
24 */
25 abstract class Template
26 {
27 /**
28 * Flag to check whether or not open success page in iframe.
29 *
30 * @var bool $openSuccessPageInIframe If set to false then success page will open in window instead of iframe.
31 */
32 public $openSuccessPageInIframe = true;
33
34 /**
35 * Flag to check whether or not open failed page in iframe.
36 *
37 * @var bool $openFailedPageInIframe If set to false then failed page will open in window instead of iframe.
38 */
39 public $openFailedPageInIframe = true;
40
41 /**
42 * Determines how the form is rendered to the page.
43 *
44 * Acceptable values:
45 * - button (show a button that displays the form when clicked)
46 * - onpage (render the form right on the page)
47 *
48 * @var string
49 */
50 public $donationFormStyle = 'button';
51
52 /**
53 * Determines how the form amount choices are rendered to the page.
54 *
55 * Acceptable values:
56 * - buttons (render donation amount choices as button )
57 * - radio (render donation amount choices as radio )
58 * - dropdown (render donation amount choices in dropdown (select) )
59 *
60 * @var string
61 */
62 public $donationFormLevelsStyle = 'buttons';
63
64 /**
65 * Determines how the form field labels render on the page.
66 *
67 * Acceptable values:
68 * - true (render with floating label style)
69 * - false (render as is)
70 *
71 * @var bool
72 */
73 public $floatingLabelsStyle = false;
74
75 /**
76 * Determines whether or not render form content on page.
77 *
78 * Acceptable values:
79 * - true (render form content on page )
80 * - false (do not render form content on page)
81 *
82 * @var bool
83 */
84 public $showDonationIntroductionContent = false;
85
86 /**
87 * Get starting form height
88 *
89 * Returns starting height for iframe (in pixels), this is used to predict iframe height before the iframe loads
90 * Implemented in includes/shortcodes.php:
91 *
92 * @param int $formId Form ID
93 *
94 * @return int
95 **/
96 public function getFormStartingHeight($formId)
97 {
98 return 600;
99 }
100
101 /**
102 * Get form receipt height
103 *
104 * Returns receipt height for iframe (in pixels), this is used to predict iframe height before the iframe loads
105 * Implemented in includes/shortcodes.php:
106 * Implemented in form donation processing view
107 *
108 * @return int
109 **/
110 public function getFormReceiptHeight()
111 {
112 return 977;
113 }
114
115 /**
116 * Get loading view filepath
117 *
118 * @since 2.7.0
119 *
120 * @return string
121 */
122 public function getLoadingView()
123 {
124 return GIVE_PLUGIN_DIR . 'src/Views/Form/defaultLoadingView.php';
125 }
126
127 /**
128 * Renders the loading view
129 *
130 * @since 2.9.2
131 *
132 * @param int $formId
133 */
134 public function renderLoadingView($formId = null)
135 {
136 include $this->getLoadingView();
137 }
138
139 /**
140 * Get form view filepath
141 *
142 * @since 2.7.0
143 *
144 * @return string
145 */
146 public function getFormView()
147 {
148 return GIVE_PLUGIN_DIR . 'src/Views/Form/defaultFormTemplate.php';
149 }
150
151 /**
152 * Get receipt view filepath
153 *
154 * @since 2.7.0
155 *
156 * @return string
157 */
158 public function getReceiptView()
159 {
160 return GIVE_PLUGIN_DIR . 'src/Views/Form/defaultFormReceiptTemplate.php';
161 }
162
163 /**
164 * return form template ID.
165 *
166 * @since 2.7.0
167 * @return string
168 */
169 abstract public function getID();
170
171 /**
172 * Get form template name.
173 *
174 * @since 2.7.0
175 * @return string
176 */
177 abstract public function getName();
178
179 /**
180 * Get form template image.
181 *
182 * @since 2.7.0
183 * @return string
184 */
185 abstract public function getImage();
186
187 /**
188 * Get options config
189 *
190 * @since 2.7.0
191 * @return array
192 */
193 abstract public function getOptionsConfig();
194
195 /**
196 * Get form template options
197 *
198 * @return Options
199 */
200 public function getOptions()
201 {
202 return Options::fromArray($this->getOptionsConfig());
203 }
204
205 /**
206 * Get failed/cancelled donation message.
207 *
208 * @since 2.7.0
209 * @return string
210 */
211 public function getFailedDonationMessage()
212 {
213 return esc_html__(
214 'We\'re sorry, your donation failed to process. Please try again or contact site support.',
215 'give'
216 );
217 }
218
219 /**
220 * Get failed donation page URL.
221 *
222 * @since 2.7.0
223 *
224 * @param int $formId
225 *
226 * @return mixed
227 */
228 public function getFailedPageURL($formId)
229 {
230 return FormUtils::createFailedPageURL(Give()->routeForm->getURL(get_post_field('post_name', $formId)));
231 }
232
233 /**
234 * Get donate now button label text.
235 *
236 * @since 2.7.0
237 * @return string
238 */
239 public function getDonateNowButtonLabel()
240 {
241 return __('Donate Now', 'give');
242 }
243
244 /**
245 * Get continue to donation form button label text.
246 *
247 * @since 2.7.0
248 * @return string
249 */
250 public function getContinueToDonationFormLabel()
251 {
252 return __('Donate Now', 'give');
253 }
254
255 /**
256 * Get donation introduction text.
257 *
258 * @since 2.7.0
259 * @return string|null
260 */
261 public function getDonationIntroductionContent()
262 {
263 return null;
264 }
265
266 /**
267 * Return content position on donation form.
268 *
269 * Note: Even you are free to add introduction content at any place on donation form
270 * But still this depends upon form template style and configuration on which places you are allowed to show display introduction content.
271 *
272 * @since 2.7.0
273 * @return string|null
274 */
275 public function getDonationIntroductionContentPosition()
276 {
277 return null;
278 }
279
280 /**
281 * Get receipt details.
282 *
283 * @since 2.7.0
284 *
285 * @param int $donationId
286 *
287 * @return DonationReceipt
288 */
289 public function getReceiptDetails($donationId)
290 {
291 $receipt = new DonationReceipt($donationId);
292
293 /**
294 * Fire the action for receipt object.
295 *
296 * @since 2.7.0
297 */
298 do_action('give_new_receipt', $receipt);
299
300 return $receipt;
301 }
302
303 /**
304 * Get form heading
305 *
306 * @since 2.7.0
307 *
308 * @param int $formId
309 *
310 * @return string
311 */
312 public function getFormHeading($formId)
313 {
314 return get_the_title($formId);
315 }
316
317 /**
318 * Get form image
319 *
320 * @since 2.7.0
321 *
322 * @param int $formId
323 *
324 * @return string
325 */
326 public function getFormFeaturedImage($formId)
327 {
328 if (Utils::isV3Form($formId)) {
329 return DonationForm::find($formId)->settings->designSettingsImageUrl;
330 }
331
332 return get_the_post_thumbnail_url($formId, 'full');
333 }
334
335 /**
336 * Get form excerpt
337 *
338 * @since 2.7.0
339 *
340 * @param int|null $formId
341 *
342 * @return string
343 */
344 public function getFormExcerpt($formId)
345 {
346 return get_the_excerpt($formId);
347 }
348 }
349