-
Notifications
You must be signed in to change notification settings - Fork 21
/
focus-gravity.php
312 lines (258 loc) · 9.01 KB
/
focus-gravity.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
/*
* Template Name: Focus Gravity
* Version: 1.2
* Description: Focus Gravity providing a classic layout which epitomises Gravity Forms Print Preview. It's the familiar layout you've come to love. Through the Template tab you can control the PDF header and footer, change the background color or image, and show or hide the form title, page names, HTML fields and the Section Break descriptions.
* Author: Gravity PDF
* Author URI: https://gravitypdf.com
* Group: Core
* License: GPLv2
* Required PDF Version: 4.0-alpha
* Tags: Header, Footer, Background, Optional HTML Fields, Optional Page Fields, Combined Row, Alternate Colors
*/
/* Prevent direct access to the template */
if ( ! class_exists('GFForms')) {
return;
}
/*
* All Gravity PDF 4.x templates have access to the following variables:
*
* $form (The current Gravity Form array)
* $entry (The raw entry data)
* $form_data (The processed entry data stored in an array)
* $settings (the current PDF configuration)
* $fields (an array of Gravity Form fields which can be accessed with their ID number)
* $config (The initialised template config class – eg. /config/focus-gravity.php)
* $gfpdf (the main Gravity PDF object containing all our helper classes)
* $args (contains an array of all variables - the ones being described right now - passed to the template)
*/
/*
* Load up our template-specific appearance settings
*/
$misc = GPDFAPI::get_misc_class();
$accent_colour = ( ! empty( $settings['focusgravity_accent_colour'] ) ) ? $settings['focusgravity_accent_colour'] : '#e3e3e3';
$accent_contrast_colour = $misc->get_contrast( $accent_colour );
$secondary_colour = ( ! empty( $settings['focusgravity_secondary_colour'] ) ) ? $settings['focusgravity_secondary_colour'] : '#eaf2fa';
$secondary_contrast_colour = $misc->get_contrast( $secondary_colour );
$label_format = ( ! empty( $settings['focusgravity_label_format'] ) ) ? $settings['focusgravity_label_format'] : 'combined_label';
?>
<!-- Include styles needed for the PDF -->
<style>
/* Handle Gravity Forms CSS Ready Classes */
.row-separator {
clear: both;
padding: 1.25mm 0;
}
.gf_left_half,
.gf_left_third, .gf_middle_third,
.gf_first_quarter, .gf_second_quarter, .gf_third_quarter,
.gf_list_2col li, .gf_list_3col li, .gf_list_4col li, .gf_list_5col li {
float: left;
}
.gf_right_half,
.gf_right_third,
.gf_fourth_quarter {
float: right;
}
.gf_left_half, .gf_right_half,
.gf_list_2col li {
width: 49%;
}
.gf_left_third, .gf_middle_third, .gf_right_third,
.gf_list_3col li {
width: 32.3%;
}
.gf_first_quarter, .gf_second_quarter, .gf_third_quarter, .gf_fourth_quarter {
width: 24%;
}
.gf_list_4col li {
width: 24%;
}
.gf_list_5col li {
width: 19%;
}
.gf_left_half, .gf_right_half {
padding-right: 1%;
}
.gf_left_third, .gf_middle_third, .gf_right_third {
padding-right: 1.505%;
}
.gf_first_quarter, .gf_second_quarter, .gf_third_quarter, .gf_fourth_quarter {
padding-right: 1.333%;
}
.gf_right_half, .gf_right_third, .gf_fourth_quarter {
padding-right: 0;
}
/* Don't double float the list items if already floated (mPDF does not support this ) */
.gf_left_half li, .gf_right_half li,
.gf_left_third li, .gf_middle_third li, .gf_right_third li {
width: 100% !important;
float: none !important;
}
/*
* Headings
*/
h3 {
margin: 1.5mm 0 0.5mm;
padding: 0;
}
/*
* Quiz Style Support
*/
.gquiz-field {
color: #666;
}
.gquiz-correct-choice {
font-weight: bold;
color: black;
}
.gf-quiz-img {
padding-left: 5px !important;
vertical-align: middle;
}
/*
* Survey Style Support
*/
.gsurvey-likert-choice-label {
padding: 4px;
}
.gsurvey-likert-choice, .gsurvey-likert-choice-label {
text-align: center;
}
/*
* Terms of Service (Gravity Perks) Support
*/
.terms-of-service-agreement {
padding-top: 2px;
font-weight: bold;
}
.terms-of-service-tick {
font-size: 150%;
}
/*
* List Support
*/
ul, ol {
margin: 0;
padding-left: 1mm;
padding-right: 1mm;
}
li {
margin: 0;
padding: 0;
list-style-position: inside;
}
/*
* Header / Footer
*/
.alignleft {
float: left;
}
.alignright {
float: right;
}
.aligncenter {
text-align: center;
}
p.alignleft {
text-align: left;
float: none;
}
p.alignright {
text-align: right;
float: none;
}
/*
* Independant Template Styles
*/
#container {
border-radius: 5px;
border: 1px solid <?php echo $accent_colour; ?>;
}
#form_title {
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
h3 {
background: <?php echo $accent_colour; ?>;
color: <?php echo $accent_contrast_colour; ?>;
margin: 0;
}
.gfpdf-page {
border-top: 1px solid #FFF;
}
.gfpdf-field .label {
font-weight: bold;
border-bottom: 1px solid <?php echo $accent_colour; ?>;
background: <?php echo $secondary_colour; ?>;
color: <?php echo $secondary_contrast_colour; ?>;
}
.value, .gfpdf-section-description, .gfpdf-field .label, h3, .gfpdf-html .value {
padding: 7px 6px 7px 10px;
}
.gfpdf-html {
border-top: 5px solid <?php echo $secondary_colour; ?>;
}
table.gfield_list th {
background: <?php echo $accent_colour; ?>;
color: <?php echo $accent_contrast_colour; ?>;
}
table.entry-products th, table.entry-products td.emptycell {
background: none;
}
<?php if( $label_format == 'combined_label' ): ?>
.gfpdf-field .label {
background: none;
border: none;
padding-bottom: 0;
}
.value {
padding-top: 0;
}
.even {
background: <?php echo $secondary_colour; ?>;
}
<?php else: ?>
.gfpdf-html .value {
border-top: 1px solid <?php echo $accent_colour; ?>;
}
<?php endif; ?>
</style>
<!-- Output our HTML markup -->
<?php
/*
* Load our core-specific styles from our PDF settings which will be passed to the PDF template $config array
*/
$show_form_title = ( ! empty( $settings['show_form_title'] ) && $settings['show_form_title'] == 'Yes' ) ? true : false;
$show_page_names = ( ! empty( $settings['show_page_names'] ) && $settings['show_page_names'] == 'Yes' ) ? true : false;
$show_html = ( ! empty( $settings['show_html'] ) && $settings['show_html'] == 'Yes' ) ? true : false;
$show_section_content = ( ! empty( $settings['show_section_content'] ) && $settings['show_section_content'] == 'Yes' ) ? true : false;
$enable_conditional = ( ! empty( $settings['enable_conditional'] ) && $settings['enable_conditional'] == 'Yes' ) ? true : false;
$show_empty = ( ! empty( $settings['show_empty'] ) && $settings['show_empty'] == 'Yes' ) ? true : false;
/**
* Set up our configuration array to control what is and is not shown in the generated PDF
*
* @var array
*/
$html_config = array(
'settings' => $settings,
'meta' => array(
'echo' => true, /* whether to output the HTML or return it */
'exclude' => true, /* whether we should exclude fields with a CSS value of 'exclude'. Default to true */
'empty' => $show_empty, /* whether to show empty fields or not. Default is false */
'conditional' => $enable_conditional, /* whether we should skip fields hidden with conditional logic. Default to true. */
'show_title' => $show_form_title, /* whether we should show the form title. Default to true */
'section_content' => $show_section_content, /* whether we should include a section breaks content. Default to false */
'page_names' => $show_page_names, /* whether we should show the form's page names. Default to false */
'html_field' => $show_html, /* whether we should show the form's html fields. Default to false */
'individual_products' => false, /* Whether to show individual fields in the entry. Default to false - they are grouped together at the end of the form */
'enable_css_ready_classes' => true, /* Whether to enable or disable Gravity Forms CSS Ready Class support in your PDF */
),
);
/*
* Generate our HTML markup
*
* You can access Gravity PDFs common functions and classes through our API wrapper class "GPDFAPI"
*/
$pdf = GPDFAPI::get_pdf_class();
$pdf->process_html_structure($entry, GPDFAPI::get_pdf_class('model'), $html_config);