PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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
← All changes | classes/helpers/FrmFormsListHelper.php +53 -114 6.28 → 6.7.2 View file →
@@ -3,28 +3,16 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmFormsListHelper extends FrmListHelper {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public $status = '';
12 8
13 9 public $total_items = 0;
14 10
15 - /**
16 - * @param array $args
17 - */
18 11 public function __construct( $args ) {
19 12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
20 13
21 14 parent::__construct( $args );
22 - $this->screen->set_screen_reader_content(
23 - array(
24 - 'heading_list' => esc_html__( 'Forms list', 'formidable' ),
25 - )
26 - );
27 15 }
28 16
29 17 /**
30 18 * @return void
@@ -29,9 +17,9 @@
29 17 /**
30 18 * @return void
31 19 */
32 20 public function prepare_items() {
33 - global $per_page, $mode;
21 + global $wpdb, $per_page, $mode;
34 22
35 23 $page = $this->get_pagenum();
36 24 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
37 25
@@ -52,12 +40,9 @@
52 40 'param' => 'order',
53 41 'default' => 'ASC',
54 42 )
55 43 );
56 -
57 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
58 -
59 - $start = self::get_param(
44 + $start = self::get_param(
60 45 array(
61 46 'param' => 'start',
62 47 'default' => ( $page - 1 ) * $per_page,
63 48 )
@@ -89,14 +74,12 @@
89 74 'param' => 's',
90 75 'sanitize' => 'sanitize_text_field',
91 76 )
92 77 );
93 -
94 - if ( $s !== '' ) {
78 + if ( $s != '' ) {
95 79 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
96 80 $search_terms = array_map( 'trim', $matches[0] );
97 -
98 - foreach ( $search_terms as $term ) {
81 + foreach ( (array) $search_terms as $term ) {
99 82 $s_query[] = array(
100 83 'or' => true,
101 84 'name LIKE' => $term,
102 85 'description LIKE' => $term,
@@ -107,10 +90,10 @@
107 90 unset( $term );
108 91 }
109 92 }
110 93
111 - $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
112 - $total_items = FrmDb::get_count( 'frm_forms', $s_query );
94 + $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
95 + $total_items = FrmDb::get_count( 'frm_forms', $s_query );
113 96 $this->total_items = $total_items;
114 97
115 98 $this->set_pagination_args(
116 99 array(
@@ -126,15 +109,13 @@
126 109 public function no_items() {
127 110 if ( $this->status === 'trash' ) {
128 111 echo '<p>';
129 112 esc_html_e( 'No forms found in the trash.', 'formidable' );
130 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
131 113 ?>
132 114 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
133 115 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
134 116 </a>
135 117 <?php
136 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
137 118 echo '</p>';
138 119 } else {
139 120 $title = __( 'No Forms Found', 'formidable' );
140 121 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
@@ -143,9 +124,9 @@
143 124
144 125 public function get_bulk_actions() {
145 126 $actions = array();
146 127
147 - if ( 'trash' === $this->status ) {
128 + if ( 'trash' == $this->status ) {
148 129 if ( current_user_can( 'frm_edit_forms' ) ) {
149 130 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
150 131 }
151 132
@@ -161,34 +142,26 @@
161 142 return $actions;
162 143 }
163 144
164 145 /**
165 - * @param string $which
166 - *
167 146 * @return void
168 147 */
169 148 public function extra_tablenav( $which ) {
170 - if ( 'top' !== $which ) {
149 + if ( 'top' != $which ) {
171 150 return;
172 151 }
173 152
174 - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) {
175 - return;
153 + if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
154 + ?>
155 + <div class="alignleft actions frm_visible_overflow">
156 + <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
157 + </div>
158 + <?php
176 159 }
177 -
178 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
179 - ?>
180 - <div class="alignleft actions frm_visible_overflow">
181 - <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
182 - </div>
183 - <?php
184 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
185 160 }
186 161
187 - /**
188 - * @return array
189 - */
190 162 public function get_views() {
163 +
191 164 $statuses = array(
192 165 'published' => __( 'My Forms', 'formidable' ),
193 166 'draft' => __( 'Drafts', 'formidable' ),
194 167 'trash' => __( 'Trash', 'formidable' ),
@@ -209,13 +182,18 @@
209 182 )
210 183 );
211 184
212 185 foreach ( $statuses as $status => $name ) {
213 - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons
214 186
187 + if ( $status == $form_type ) {
188 + $class = ' class="current"';
189 + } else {
190 + $class = '';
191 + }
192 +
215 193 if ( $counts->{$status} || 'draft' !== $status ) {
216 194 /* translators: %1$s: Status, %2$s: Number of items */
217 - $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
195 + $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
218 196 }
219 197
220 198 unset( $status, $name );
221 199 }
@@ -223,10 +201,8 @@
223 201 return $links;
224 202 }
225 203
226 204 /**
227 - * @param string $which
228 - *
229 205 * @return void
230 206 */
231 207 public function pagination( $which ) {
232 208 global $mode;
@@ -240,13 +216,12 @@
240 216
241 217 /**
242 218 * @param stdClass $item
243 219 * @param string $style
244 - *
245 220 * @return string
246 221 */
247 222 public function single_row( $item, $style = '' ) {
248 - global $mode;
223 + global $frm_vars, $mode;
249 224
250 225 // Set up the hover actions for this user
251 226 $actions = array();
252 227 $edit_link = FrmForm::get_edit_link( $item->id );
@@ -255,31 +230,24 @@
255 230
256 231 $action_links = $this->row_actions( $actions );
257 232
258 233 // Set up the checkbox ( because the user is editable, otherwise its empty )
259 - $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
260 - $checkbox_label_text = sprintf(
261 - // translators: Form title
262 - __( 'Select %s', 'formidable' ),
263 - ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text()
264 - );
234 + $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
265 235
266 - $checkbox .= '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . esc_html( $checkbox_label_text ) . '</span></label>';
267 - $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
236 + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
268 237
269 238 list( $columns, $hidden ) = $this->get_column_info();
270 239
271 240 $format = 'Y/m/d';
272 -
273 - if ( 'list' !== $mode ) {
241 + if ( 'list' != $mode ) {
274 242 $format .= ' \<\b\r \/\> g:i:s a';
275 243 }
276 244
277 245 foreach ( $columns as $column_name => $column_display_name ) {
278 - $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
246 + $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
247 +
279 248 $style = '';
280 -
281 - if ( in_array( $column_name, $hidden, true ) ) {
249 + if ( in_array( $column_name, $hidden ) ) {
282 250 $class .= ' frm_hidden';
283 251 }
284 252
285 253 if ( $column_name === 'name' ) {
@@ -298,9 +266,9 @@
298 266 case 'form_key':
299 267 $val = $item->{$column_name};
300 268 break;
301 269 case 'name':
302 - $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
270 + $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
303 271 $val .= $action_links;
304 272 break;
305 273 case 'created_at':
306 274 $date = gmdate( $format, strtotime( $item->created_at ) );
@@ -306,9 +274,9 @@
306 274 $date = gmdate( $format, strtotime( $item->created_at ) );
307 275 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
308 276 break;
309 277 case 'entries':
310 - if ( ! empty( $item->options['no_save'] ) ) {
278 + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
311 279 $val = FrmAppHelper::icon_by_class(
312 280 'frmfont frm_forbid_icon frm_bstooltip',
313 281 array(
314 282 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
@@ -316,9 +284,9 @@
316 284 )
317 285 );
318 286 } else {
319 287 $text = FrmEntry::getRecordCount( $item->id );
320 - $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
288 + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
321 289 unset( $text );
322 290 }
323 291 break;
324 292 default:
@@ -334,9 +302,11 @@
334 302 $r .= '</td>';
335 303 }
336 304 unset( $val );
337 305 }//end foreach
338 - return $r . '</tr>';
306 + $r .= '</tr>';
307 +
308 + return $r;
339 309 }
340 310
341 311 /**
342 312 * Get the HTML for the Actions column in the form list.
@@ -344,19 +314,18 @@
344 314 *
345 315 * @since 6.0
346 316 *
347 317 * @param stdClass $form
348 - *
349 318 * @return string
350 319 */
351 320 protected function column_shortcode( $form ) {
352 - $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
321 + $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_html__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>';
353 322 $val .= $this->column_style( $form );
354 - $val .= $this->column_views( $form );
355 323 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
356 324 // Remove the space hard coded in Landing pages.
357 325 $val = str_replace( '&nbsp;', '', $val );
358 - return '<div>' . $val . '</div>';
326 + $val = '<div>' . $val . '</div>';
327 + return $val;
359 328 }
360 329
361 330 /**
362 331 * Get the HTML for the Style column in the form list.
@@ -363,13 +332,12 @@
363 332 *
364 333 * @since 6.0
365 334 *
366 335 * @param stdClass $form
367 - *
368 336 * @return string
369 337 */
370 338 protected function column_style( $form ) {
371 - $style_setting = $form->options['custom_style'] ?? '';
339 + $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : '';
372 340 $frm_settings = FrmAppHelper::get_settings();
373 341
374 342 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
375 343 // Don't show a link if styling is off.
@@ -376,9 +344,8 @@
376 344 return '';
377 345 }
378 346
379 347 $style = FrmStylesController::get_form_style( $form );
380 -
381 348 if ( ! $style ) {
382 349 // Do a second pass to avoid null values.
383 350 $frm_style = new FrmStyle( 'default' );
384 351 $style = $frm_style->get_one();
@@ -384,35 +351,12 @@
384 351 $style = $frm_style->get_one();
385 352 }
386 353
387 354 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
388 - return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
355 + return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
389 356 }
390 357
391 358 /**
392 - * Generate the HTML for the form Views page.
393 - *
394 - * @since 6.19
395 - *
396 - * @param stdClass $form Form object.
397 - *
398 - * @return string
399 - */
400 - protected function column_views( $form ) {
401 - $attributes = array(
402 - 'href' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $form->id ) . '&show_nav=1' ),
403 - 'title' => __( 'Link to list of all views for this form.', 'formidable' ),
404 - 'target' => '_blank',
405 - );
406 -
407 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
408 - return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '>
409 - ' . FrmAppHelper::icon_by_class( 'frmfont frm_eye_icon', array( 'echo' => false ) ) .
410 - '</a>';
411 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
412 - }
413 -
414 - /**
415 359 * @param array $actions
416 360 * @param object $item
417 361 * @param string $edit_link
418 362 *
@@ -419,25 +363,25 @@
419 363 * @return void
420 364 */
421 365 private function get_actions( &$actions, $item, $edit_link ) {
422 366 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
423 -
424 367 foreach ( $new_actions as $link => $action ) {
425 368 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
426 369 }
427 370
428 - if ( 'trash' === $this->status ) {
371 + if ( 'trash' == $this->status ) {
429 372 $actions = $new_actions;
373 +
430 374 return;
431 375 }
432 376
433 377 if ( current_user_can( 'frm_edit_forms' ) ) {
434 - $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>';
435 - $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . esc_html__( 'Settings', 'formidable' ) . '</a>';
378 + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
379 + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
436 380 }
437 381
438 382 $actions = array_merge( $actions, $new_actions );
439 - $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . esc_html__( 'Preview', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
383 + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
440 384 }
441 385
442 386 /**
443 387 * @param object $item
@@ -448,25 +392,21 @@
448 392 * @return string
449 393 */
450 394 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
451 395 $form_name = $item->name;
452 -
453 - if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
454 - $form_name = FrmFormsHelper::get_no_title_text();
396 + if ( trim( $form_name ) == '' ) {
397 + $form_name = __( '(no title)', 'formidable' );
455 398 }
456 -
457 399 $form_name = FrmAppHelper::kses( $form_name );
458 -
459 - if ( 'excerpt' !== $mode ) {
400 + if ( 'excerpt' != $mode ) {
460 401 $form_name = FrmAppHelper::truncate( $form_name, 50 );
461 402 }
462 403
463 404 $val = '<strong>';
464 -
465 - if ( 'trash' === $this->status ) {
405 + if ( 'trash' == $this->status ) {
466 406 $val .= $form_name;
467 407 } else {
468 - $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> '; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
408 + $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
469 409 }
470 410
471 411 $this->add_draft_label( $item, $val );
472 412 $val .= '</strong>';
@@ -482,10 +422,10 @@
482 422 *
483 423 * @return void
484 424 */
485 425 private function add_draft_label( $item, &$val ) {
486 - if ( 'draft' === $item->status && 'draft' !== $this->status ) {
487 - $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>';
426 + if ( 'draft' == $item->status && 'draft' != $this->status ) {
427 + $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
488 428 }
489 429 }
490 430
491 431 /**
@@ -495,10 +435,9 @@
495 435 * @return void
496 436 */
497 437 private function add_form_description( $item, &$val ) {
498 438 global $mode;
499 -
500 - if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
439 + if ( 'excerpt' == $mode ) {
501 440 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
502 441 }
503 442 }
504 443