PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 2.05.09
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v2.05.09
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmTableHTMLGenerator.php

FrmTableHTMLGenerator.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 2.05.09, at classes/models/FrmTableHTMLGenerator.php

299 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @since 2.04
5 */
6 class FrmTableHTMLGenerator {
7
8 /**
9 * @var string
10 * @since 2.04
11 */
12 private $type = '';
13
14 /**
15 * @var array
16 * @since 2.04
17 */
18 private $style_settings = array();
19
20 /**
21 * @var bool
22 * @since 2.04
23 */
24 private $use_inline_style = true;
25
26 /**
27 * @var string
28 * @since 2.04
29 */
30 private $direction = 'ltr';
31
32 /**
33 * @var bool
34 * @since 2.04
35 */
36 private $odd = true;
37
38 /**
39 * @var string
40 * @since 2.04
41 */
42 private $table_style = '';
43
44 /**
45 * @var string
46 * @since 2.04
47 */
48 private $td_style = '';
49
50
51 /**
52 * FrmTableHTMLGenerator constructor.
53 *
54 * @param string $type
55 * @param array $atts
56 */
57 public function __construct( $type, $atts = array() ) {
58
59 $this->type = (string) $type;
60 $this->init_style_settings( $atts );
61 $this->init_use_inline_style( $atts );
62 $this->init_direction( $atts );
63 $this->init_table_style();
64 $this->init_td_style();
65
66 }
67
68 /**
69 * Set the style_settings property
70 *
71 * @since 2.04
72 *
73 * @param array $atts
74 */
75 private function init_style_settings( $atts ) {
76 $this->style_settings = apply_filters( 'frm_show_entry_styles', array(
77 'border_color' => 'dddddd',
78 'bg_color' => 'f7f7f7',
79 'text_color' => '444444',
80 'font_size' => '12px',
81 'border_width' => '1px',
82 'alt_bg_color' => 'ffffff',
83 ) );
84
85 foreach ( $this->style_settings as $key => $setting ) {
86 if ( isset( $atts[ $key ] ) && $atts[ $key ] !== '' ) {
87 $this->style_settings[ $key ] = $atts[ $key ];
88 }
89
90 if ( $this->is_color_setting( $key ) ) {
91 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
92 }
93 }
94 }
95
96 /**
97 * Set the use_inline_style property
98 *
99 * @since 2.04
100 *
101 * @param array $atts
102 */
103 private function init_use_inline_style( $atts ) {
104 if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) {
105 $this->use_inline_style = false;
106 }
107 }
108
109 /**
110 * Set the direction property
111 *
112 * @since 2.04
113 *
114 * @param array $atts
115 */
116 private function init_direction( $atts ) {
117 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
118 $this->direction = 'rtl';
119 }
120 }
121
122 /**
123 * Set the table_style property
124 *
125 * @since 2.04
126 */
127 private function init_table_style() {
128 if ( $this->use_inline_style === true ) {
129
130 $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
131 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
132
133 }
134 }
135
136 /**
137 * Set the td_style property
138 *
139 * @since 2.04
140 */
141 private function init_td_style() {
142 if ( $this->use_inline_style === true ) {
143
144 $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';';
145 $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;';
146 $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
147
148 $this->td_style = ' style="' . $td_style_attributes . '"';
149 }
150 }
151
152 /**
153 * Determine if setting is for a color, e.g. text color, background color, or border color
154 *
155 * @param string $setting_key name of setting
156 *
157 * @since 2.05
158 *
159 * @return boolean
160 */
161 private function is_color_setting( $setting_key ) {
162 return strpos( $setting_key, 'color' ) !== false;
163 }
164
165 /**
166 * Get color markup from color setting value
167 *
168 * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
169 *
170 * @since 2.05
171 *
172 * @return string
173 */
174 private function get_color_markup( $color_markup ) {
175 $color_markup = trim( $color_markup );
176
177 //check if each character in string is valid hex digit
178 if ( ctype_xdigit( $color_markup ) ) {
179 $color_markup = '#' . $color_markup;
180 }
181
182 return $color_markup;
183 }
184
185 /**
186 * Get the table row background color
187 *
188 * @since 2.04
189 *
190 * @return string
191 */
192 private function table_row_background_color() {
193 return ( $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'] );
194 }
195
196 /**
197 * Get the table row style
198 *
199 * @since 2.04
200 *
201 * @return string
202 */
203 private function tr_style() {
204
205 if ( $this->type === 'shortcode' ) {
206 $tr_style = ' style="[frm-alt-color]"';
207 } else if ( $this->use_inline_style ) {
208 $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
209 } else {
210 $tr_style = '';
211 }
212
213 return $tr_style;
214 }
215
216 /**
217 * Switch the odd property from true to false or false to true
218 *
219 * @since 2.04
220 */
221 private function switch_odd() {
222 if ( $this->type !== 'shortcode' ) {
223 $this->odd = ! $this->odd;
224 }
225 }
226
227 /**
228 * Generate a table header
229 *
230 * @since 2.04
231 *
232 * @return string
233 */
234 public function generate_table_header() {
235 return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
236 }
237
238 /**
239 * Generate a table footer
240 *
241 * @since 2.04
242 *
243 * @return string
244 */
245 public function generate_table_footer() {
246 return '</tbody></table>';
247 }
248
249 /**
250 * Generate a two cell row for an HTML table
251 *
252 * @since 2.04
253 *
254 * @param string $label
255 * @param string $value
256 *
257 * @return string
258 */
259 public function generate_two_cell_table_row( $label, $value ) {
260 $row = '<tr' . $this->tr_style() . '>';
261
262 if ( 'rtl' == $this->direction ) {
263 $first = $value;
264 $second = $label;
265 } else {
266 $first = $label;
267 $second = $value;
268 }
269
270 $row .= '<td' . $this->td_style . '>' . $first . '</td>';
271 $row .= '<td' . $this->td_style . '>' . $second . '</td>';
272
273 $row .= '</tr>' . "\r\n";
274
275 $this->switch_odd();
276
277 return $row;
278 }
279
280 /**
281 * Generate a single cell row for an HTML table
282 *
283 * @since 2.04
284 *
285 * @param string $value
286 *
287 * @return string
288 */
289 public function generate_single_cell_table_row( $value ) {
290 $row = '<tr' . $this->tr_style() . '>';
291 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
292 $row .= '</tr>' . "\r\n";
293
294 $this->switch_odd();
295
296 return $row;
297 }
298 }
299