PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.02
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 +82 -492 6.345.2.02 View file →
@@ -3,55 +3,30 @@
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 - * The transient name that stores data for which posts a form is embedded in.
10 - *
11 - * @since 6.32
12 - *
13 - * @var string
14 - */
15 - private static $embed_posts_transient_name = 'frm_posts_contain_form';
16 -
17 - /**
18 - * @var string
19 - */
20 7 public $status = '';
21 8
22 9 public $total_items = 0;
23 10
24 - /**
25 - * @param array $args
26 - */
27 11 public function __construct( $args ) {
28 12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
29 13
30 14 parent::__construct( $args );
31 - $this->screen->set_screen_reader_content(
32 - array(
33 - 'heading_list' => esc_html__( 'Forms list', 'formidable' ),
34 - )
35 - );
36 15 }
37 16
38 - /**
39 - * @return void
40 - */
41 17 public function prepare_items() {
42 - global $per_page, $mode;
18 + global $wpdb, $per_page, $mode;
43 19
44 20 $page = $this->get_pagenum();
45 21 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
46 22
47 - $mode = self::get_param(
23 + $mode = self::get_param(
48 24 array(
49 25 'param' => 'mode',
50 26 'default' => 'list',
51 27 )
52 28 );
53 -
54 29 $orderby = self::get_param(
55 30 array(
56 31 'param' => 'orderby',
57 32 'default' => 'name',
@@ -62,12 +37,9 @@
62 37 'param' => 'order',
63 38 'default' => 'ASC',
64 39 )
65 40 );
66 -
67 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
68 -
69 - $start = self::get_param(
41 + $start = self::get_param(
70 42 array(
71 43 'param' => 'start',
72 44 'default' => ( $page - 1 ) * $per_page,
73 45 )
@@ -99,14 +71,12 @@
99 71 'param' => 's',
100 72 'sanitize' => 'sanitize_text_field',
101 73 )
102 74 );
103 -
104 - if ( $s !== '' ) {
75 + if ( $s != '' ) {
105 76 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
106 77 $search_terms = array_map( 'trim', $matches[0] );
107 -
108 - foreach ( $search_terms as $term ) {
78 + foreach ( (array) $search_terms as $term ) {
109 79 $s_query[] = array(
110 80 'or' => true,
111 81 'name LIKE' => $term,
112 82 'description LIKE' => $term,
@@ -117,10 +87,10 @@
117 87 unset( $term );
118 88 }
119 89 }
120 90
121 - $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
122 - $total_items = FrmDb::get_count( 'frm_forms', $s_query );
91 + $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
92 + $total_items = FrmDb::get_count( 'frm_forms', $s_query );
123 93 $this->total_items = $total_items;
124 94
125 95 $this->set_pagination_args(
126 96 array(
@@ -129,46 +99,17 @@
129 99 )
130 100 );
131 101 }
132 102
133 - /**
134 - * @return void
135 - */
136 103 public function no_items() {
137 - $s = self::get_param(
138 - array(
139 - 'param' => 's',
140 - 'sanitize' => 'sanitize_text_field',
141 - )
142 - );
143 -
144 - if ( $s !== '' ) {
145 - $current_url = set_url_scheme(
146 - 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' )
147 - );
148 - $clear_url = remove_query_arg( 's', $current_url );
149 -
150 - echo '<p>';
151 - printf(
152 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
153 - esc_html__( 'No forms match your search. %1$sClear search%2$s', 'formidable' ),
154 - '<a href="' . esc_url( $clear_url ) . '">',
155 - '</a>'
156 - );
157 - echo '</p>';
158 - return;
159 - }
160 -
161 104 if ( $this->status === 'trash' ) {
162 105 echo '<p>';
163 106 esc_html_e( 'No forms found in the trash.', 'formidable' );
164 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
165 107 ?>
166 108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
167 109 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
168 110 </a>
169 111 <?php
170 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
171 112 echo '</p>';
172 113 } else {
173 114 $title = __( 'No Forms Found', 'formidable' );
174 115 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
@@ -177,9 +118,9 @@
177 118
178 119 public function get_bulk_actions() {
179 120 $actions = array();
180 121
181 - if ( 'trash' === $this->status ) {
122 + if ( 'trash' == $this->status ) {
182 123 if ( current_user_can( 'frm_edit_forms' ) ) {
183 124 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
184 125 }
185 126
@@ -194,35 +135,24 @@
194 135
195 136 return $actions;
196 137 }
197 138
198 - /**
199 - * @param string $which
200 - *
201 - * @return void
202 - */
203 139 public function extra_tablenav( $which ) {
204 - if ( 'top' !== $which ) {
140 + if ( 'top' != $which ) {
205 141 return;
206 142 }
207 143
208 - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) {
209 - return;
144 + if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
145 + ?>
146 + <div class="alignleft actions frm_visible_overflow">
147 + <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
148 + </div>
149 + <?php
210 150 }
211 -
212 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
213 - ?>
214 - <div class="alignleft actions frm_visible_overflow">
215 - <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
216 - </div>
217 - <?php
218 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
219 151 }
220 152
221 - /**
222 - * @return array
223 - */
224 153 public function get_views() {
154 +
225 155 $statuses = array(
226 156 'published' => __( 'My Forms', 'formidable' ),
227 157 'draft' => __( 'Drafts', 'formidable' ),
228 158 'trash' => __( 'Trash', 'formidable' ),
@@ -229,14 +159,8 @@
229 159 );
230 160
231 161 $links = array();
232 162 $counts = FrmForm::get_count();
233 - $form_type = FrmAppHelper::simple_get( 'form_type', 'sanitize_title', 'published' );
234 -
235 - if ( isset( $statuses[ $form_type ] ) ) {
236 - $counts->$form_type = $this->total_items;
237 - }
238 -
239 163 $form_type = self::get_param(
240 164 array(
241 165 'param' => 'form_type',
242 166 'default' => 'published',
@@ -243,13 +167,18 @@
243 167 )
244 168 );
245 169
246 170 foreach ( $statuses as $status => $name ) {
247 - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons
248 171
172 + if ( $status == $form_type ) {
173 + $class = ' class="current"';
174 + } else {
175 + $class = '';
176 + }
177 +
249 178 if ( $counts->{$status} || 'draft' !== $status ) {
250 179 /* translators: %1$s: Status, %2$s: Number of items */
251 - $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
180 + $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>';
252 181 }
253 182
254 183 unset( $status, $name );
255 184 }
@@ -256,16 +185,20 @@
256 185
257 186 return $links;
258 187 }
259 188
260 - /**
261 - * @param stdClass $item
262 - * @param string $style
263 - *
264 - * @return string
265 - */
189 + public function pagination( $which ) {
190 + global $mode;
191 +
192 + parent::pagination( $which );
193 +
194 + if ( 'top' === $which ) {
195 + $this->view_switcher( $mode );
196 + }
197 + }
198 +
266 199 public function single_row( $item, $style = '' ) {
267 - global $mode;
200 + global $frm_vars, $mode;
268 201
269 202 // Set up the hover actions for this user
270 203 $actions = array();
271 204 $edit_link = FrmForm::get_edit_link( $item->id );
@@ -272,34 +205,33 @@
272 205
273 206 $this->get_actions( $actions, $item, $edit_link );
274 207
275 208 $action_links = $this->row_actions( $actions );
276 - $checkbox = $this->get_row_checkbox( $item );
277 - $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
278 209
210 + // Set up the checkbox ( because the user is editable, otherwise its empty )
211 + $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
212 +
213 + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
214 +
279 215 list( $columns, $hidden ) = $this->get_column_info();
280 216
281 217 $format = 'Y/m/d';
282 -
283 - if ( 'list' !== $mode ) {
218 + if ( 'list' != $mode ) {
284 219 $format .= ' \<\b\r \/\> g:i:s a';
285 220 }
286 221
287 222 foreach ( $columns as $column_name => $column_display_name ) {
288 - $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
223 + $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
224 +
289 225 $style = '';
290 -
291 - if ( in_array( $column_name, $hidden, true ) ) {
292 - $class .= ' hidden';
226 + if ( in_array( $column_name, $hidden ) ) {
227 + $class .= ' frm_hidden';
293 228 }
294 229
295 - if ( $column_name === 'name' ) {
296 - $class .= ' column-primary';
297 - }
230 + $class = 'class="' . esc_attr( $class ) . '"';
231 + $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
232 + $attributes = $class . $style . $data_colname;
298 233
299 - $class = 'class="' . esc_attr( $class ) . '"';
300 - $attributes = $class . $style . $this->get_column_data_attr( $column_name, $column_display_name );
301 -
302 234 switch ( $column_name ) {
303 235 case 'cb':
304 236 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
305 237 break;
@@ -307,24 +239,35 @@
307 239 case 'form_key':
308 240 $val = $item->{$column_name};
309 241 break;
310 242 case 'name':
311 - $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
243 + $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
312 244 $val .= $action_links;
245 +
313 246 break;
314 247 case 'created_at':
315 248 $date = gmdate( $format, strtotime( $item->created_at ) );
316 249 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
317 250 break;
251 + case 'shortcode':
252 + $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>';
253 + $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $item ) );
254 + break;
318 255 case 'entries':
319 - $val = $this->get_entries_column_value( $item );
320 - break;
321 - default:
322 - if ( method_exists( $this, 'column_' . $column_name ) ) {
323 - $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
256 + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
257 + $val = FrmAppHelper::icon_by_class(
258 + 'frmfont frm_forbid_icon frm_bstooltip',
259 + array(
260 + 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
261 + 'echo' => false,
262 + )
263 + );
264 + } else {
265 + $text = FrmEntry::getRecordCount( $item->id );
266 + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
267 + unset( $text );
324 268 }
325 - break;
326 - }//end switch
269 + }
327 270
328 271 if ( isset( $val ) ) {
329 272 $r .= "<td $attributes>";
330 273 $r .= $val;
@@ -330,210 +273,56 @@
330 273 $r .= $val;
331 274 $r .= '</td>';
332 275 }
333 276 unset( $val );
334 - }//end foreach
335 - return $r . '</tr>';
336 - }
337 -
338 - /**
339 - * @param string $column_name
340 - * @param string $column_display_name
341 - *
342 - * @return string
343 - */
344 - private function get_column_data_attr( $column_name, $column_display_name ) {
345 - if ( 'settings' === $column_name ) {
346 - return ' data-colname="' . esc_attr( trim( strip_tags( $column_display_name ) ) ) . '"';
347 277 }
348 - return ' data-colname="' . esc_attr( $column_display_name ) . '"';
349 - }
278 + $r .= '</tr>';
350 279
351 - /**
352 - * @param object $item
353 - *
354 - * @return string
355 - */
356 - private function get_entries_column_value( $item ) {
357 - if ( ! empty( $item->options['no_save'] ) ) {
358 - return (string) FrmAppHelper::icon_by_class(
359 - 'frmfont frm_forbid_icon frm_bstooltip',
360 - array(
361 - 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
362 - 'echo' => false,
363 - )
364 - );
365 - }
366 -
367 - $text = intval( FrmEntry::getRecordCount( $item->id ) );
368 - return current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : (string) $text; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
280 + return $r;
369 281 }
370 282
371 283 /**
372 - * @param object $item
373 - *
374 - * @return string
375 - */
376 - private function get_row_checkbox( $item ) {
377 - // Set up the checkbox (because the user is editable, otherwise it's empty).
378 - $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
379 - $checkbox_label_text = sprintf(
380 - // translators: Form title
381 - __( 'Select %s', 'formidable' ),
382 - ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text()
383 - );
384 -
385 - return $checkbox . '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . esc_html( $checkbox_label_text ) . '</span></label>';
386 - }
387 -
388 - /**
389 - * Get the HTML for the Actions column in the form list.
390 - * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
391 - *
392 - * @since 6.0
393 - * @deprecated 6.32 We moved these actions to other places. This column will show if there is a filter added to the hook.
394 - *
395 - * @param stdClass $form
396 - *
397 - * @return string
398 - */
399 - protected function column_shortcode( $form ) {
400 - $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
401 - $val .= $this->column_style( $form );
402 - $val .= $this->column_views( $form );
403 - $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
404 - // Remove the space hard coded in Landing pages.
405 - $val = str_replace( '&nbsp;', '', $val );
406 - return '<div>' . $val . '</div>';
407 - }
408 -
409 - /**
410 - * Get the HTML for the Style column in the form list.
411 - *
412 - * @since 6.0
413 - *
414 - * @param stdClass $form
415 - *
416 - * @return string
417 - */
418 - protected function column_style( $form ) {
419 - $style_setting = $form->options['custom_style'] ?? '';
420 - $frm_settings = FrmAppHelper::get_settings();
421 -
422 - if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
423 - // Don't show a link if styling is off.
424 - return '';
425 - }
426 -
427 - $style = FrmStylesController::get_form_style( $form );
428 -
429 - if ( ! $style ) {
430 - // Do a second pass to avoid null values.
431 - $frm_style = new FrmStyle( 'default' );
432 - $style = $frm_style->get_one();
433 - }
434 -
435 - $href = FrmStylesHelper::get_edit_url( $style, $form->id );
436 - 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
437 - }
438 -
439 - /**
440 - * Generate the HTML for the form Views page.
441 - *
442 - * @since 6.19
443 - *
444 - * @param stdClass $form Form object.
445 - *
446 - * @return string
447 - */
448 - protected function column_views( $form ) {
449 - $attributes = array(
450 - 'href' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $form->id ) . '&show_nav=1' ),
451 - 'title' => __( 'Link to list of all views for this form.', 'formidable' ),
452 - 'target' => '_blank',
453 - );
454 -
455 - if ( class_exists( 'FrmViewsDisplay' ) ) {
456 - $view_ids = FrmViewsDisplay::get_display_ids_by_form( $form->id );
457 - $view_count = $view_ids ? count( $view_ids ) : 0;
458 - } else {
459 - $view_count = 0;
460 - }
461 -
462 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
463 - return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '>
464 - ' . intval( $view_count ) .
465 - '</a>';
466 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
467 - }
468 -
469 - /**
470 - * Get the HTML for the Settings column in the form list.
471 - *
472 - * @since 6.32
473 - *
474 - * @return string
475 - */
476 - protected function column_settings() {
477 - return '&nbsp;';
478 - }
479 -
480 - /**
481 - * @param array $actions
482 - * @param object $item
483 284 * @param string $edit_link
484 - *
485 - * @return void
486 285 */
487 286 private function get_actions( &$actions, $item, $edit_link ) {
488 287 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
489 -
490 288 foreach ( $new_actions as $link => $action ) {
491 289 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
492 290 }
493 291
494 - if ( 'trash' === $this->status ) {
292 + if ( 'trash' == $this->status ) {
495 293 $actions = $new_actions;
294 +
496 295 return;
497 296 }
498 297
499 298 if ( current_user_can( 'frm_edit_forms' ) ) {
500 - $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>';
501 - $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . esc_html__( 'Settings', 'formidable' ) . '</a>';
299 + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
300 + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
502 301 }
503 302
504 - $actions = array_merge( $actions, $new_actions );
505 - $actions['embed'] = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . esc_html__( 'Embed', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
506 - $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
303 + $actions = array_merge( $actions, $new_actions );
304 + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
507 305 }
508 306
509 307 /**
510 - * @param object $item
511 - * @param array $actions
512 308 * @param string $edit_link
513 - * @param string $mode
514 - *
515 - * @return string
516 309 */
517 310 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
518 311 $form_name = $item->name;
519 -
520 - if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
521 - $form_name = FrmFormsHelper::get_no_title_text();
312 + if ( trim( $form_name ) == '' ) {
313 + $form_name = __( '(no title)', 'formidable' );
522 314 }
523 -
524 315 $form_name = FrmAppHelper::kses( $form_name );
525 -
526 - if ( 'excerpt' !== $mode ) {
316 + if ( 'excerpt' != $mode ) {
527 317 $form_name = FrmAppHelper::truncate( $form_name, 50 );
528 318 }
529 319
530 320 $val = '<strong>';
531 -
532 - if ( 'trash' === $this->status ) {
321 + if ( 'trash' == $this->status ) {
533 322 $val .= $form_name;
534 323 } else {
535 - $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
324 + $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> ';
536 325 }
537 326
538 327 $this->add_draft_label( $item, $val );
539 328 $val .= '</strong>';
@@ -543,29 +332,22 @@
543 332 return $val;
544 333 }
545 334
546 335 /**
547 - * @param object $item
548 336 * @param string $val
549 - *
550 - * @return void
551 337 */
552 338 private function add_draft_label( $item, &$val ) {
553 - if ( 'draft' === $item->status && 'draft' !== $this->status ) {
554 - $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>';
339 + if ( 'draft' == $item->status && 'draft' != $this->status ) {
340 + $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
555 341 }
556 342 }
557 343
558 344 /**
559 - * @param object $item
560 345 * @param string $val
561 - *
562 - * @return void
563 346 */
564 347 private function add_form_description( $item, &$val ) {
565 348 global $mode;
566 -
567 - if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
349 + if ( 'excerpt' == $mode ) {
568 350 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
569 351 }
570 352 }
571 353
@@ -573,198 +355,6 @@
573 355 * @return string
574 356 */
575 357 protected function confirm_bulk_delete() {
576 358 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
577 - }
578 -
579 - /**
580 - * @param stdClass $form
581 - *
582 - * @return string
583 - */
584 - public function column_embeds( $form ) {
585 - $posts = $this->get_posts_contain_form( $form );
586 -
587 - if ( ! $posts ) {
588 - return '<span class="frm-forms-list-embeds-zero">0</span>';
589 - }
590 -
591 - return FrmAppHelper::clip(
592 - function () use ( $posts ) {
593 - ?>
594 - <a href="#" class="frm-forms-list-embeds-btn" data-posts="<?php echo esc_attr( wp_json_encode( $posts ) ); ?>">
595 - <?php
596 - FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon' );
597 - echo intval( count( $posts ) );
598 - ?>
599 - </a>
600 - <?php
601 - }
602 - );
603 - }
604 -
605 - /**
606 - * Gets posts or pages that contain the form shortcode.
607 - *
608 - * @since 6.32
609 - *
610 - * @param stdClass $form Form object.
611 - *
612 - * @return array
613 - */
614 - private function get_posts_contain_form( $form ) {
615 - $cached_posts = get_transient( self::$embed_posts_transient_name );
616 -
617 - if ( isset( $cached_posts[ $form->id ] ) && is_array( $cached_posts[ $form->id ] ) ) {
618 - return $cached_posts[ $form->id ];
619 - }
620 -
621 - $posts = $this->query_posts_contain_form( $form );
622 -
623 - if ( ! is_array( $posts ) ) {
624 - return array();
625 - }
626 -
627 - foreach ( $posts as $post ) {
628 - if ( ! property_exists( $post, 'permalink' ) ) {
629 - $post->permalink = get_permalink( $post->ID );
630 - }
631 -
632 - if ( ! property_exists( $post, 'edit_link' ) ) {
633 - $post->edit_link = get_edit_post_link( $post->ID );
634 - }
635 -
636 - // Ensure post_name is not null or the string "null"
637 - if ( ! isset( $post->post_name ) ) {
638 - $post->post_name = '';
639 - }
640 -
641 - // Ensure post_title is not null or the string "null"
642 - if ( ! isset( $post->post_title ) ) {
643 - $post->post_title = '';
644 - }
645 -
646 - if ( '' === $post->post_title ) {
647 - $post->post_title = __( '(no title)', 'formidable' );
648 - }
649 - }//end foreach
650 -
651 - if ( ! is_array( $cached_posts ) ) {
652 - $cached_posts = array();
653 - }
654 -
655 - $cached_posts[ $form->id ] = $posts;
656 - set_transient( self::$embed_posts_transient_name, $cached_posts, DAY_IN_SECONDS );
657 -
658 - return $posts;
659 - }
660 -
661 - /**
662 - * Gets search strings for a form inside a post.
663 - *
664 - * @since 6.32
665 - *
666 - * @param int $form_id Form ID.
667 - *
668 - * @return string[]
669 - */
670 - protected function get_search_strings_for_form( $form_id ) {
671 - return $this->get_base_search_strings_for_form( $form_id );
672 - }
673 -
674 - /**
675 - * Gets the base search strings for a form inside a post.
676 - *
677 - * @since 6.32
678 - *
679 - * @param int $form_id Form ID.
680 - *
681 - * @return string[]
682 - */
683 - protected function get_base_search_strings_for_form( $form_id ) {
684 - return array(
685 - '[formidable id=' . $form_id . ']',
686 - '[formidable id=' . $form_id . ' ',
687 - '[formidable id="' . $form_id . '"',
688 - "[formidable id='" . $form_id . "'",
689 - '<!-- wp:formidable/simple-form {"formId":"' . $form_id . '"',
690 - );
691 - }
692 -
693 - /**
694 - * Queries for posts that contain the form shortcode.
695 - *
696 - * @param stdClass $form Form object.
697 - *
698 - * @return array
699 - */
700 - private function query_posts_contain_form( $form ) {
701 - $form_id = $form->id;
702 - global $wpdb;
703 - $query_strings = $this->get_search_strings_for_form( $form_id );
704 - $like_where = array();
705 -
706 - foreach ( $query_strings as $query_string ) {
707 - $like_where[] = $wpdb->remove_placeholder_escape( $wpdb->prepare( 'post_content LIKE %s', '%' . $query_string . '%' ) );
708 - }
709 -
710 - $like_where = implode( ' OR ', $like_where );
711 - $where = "post_type IN ('post', 'page') AND ($like_where)";
712 -
713 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
714 - $posts = $wpdb->get_results( "SELECT ID,post_title,post_name FROM $wpdb->posts WHERE $where" );
715 -
716 - if ( ! is_array( $posts ) ) {
717 - return array();
718 - }
719 -
720 - /**
721 - * @since 6.32
722 - *
723 - * @param stdClass[] $posts
724 - * @param array $args
725 - */
726 - $filtered_posts = apply_filters( 'frm_get_posts_contain_form', $posts, compact( 'form' ) );
727 -
728 - if ( ! is_array( $filtered_posts ) ) {
729 - _doing_it_wrong( 'frm_get_posts_contain_form', 'Filter should return an array.', '6.32' );
730 - return $posts;
731 - }
732 -
733 - return $filtered_posts;
734 - }
735 -
736 - /**
737 - * Maybe clear the embed posts transient.
738 - *
739 - * @since 6.32
740 - *
741 - * @param int $post_id Post ID.
742 - * @param WP_Post $post Post object.
743 - *
744 - * @return void
745 - */
746 - public static function maybe_clear_embed_posts_transient( $post_id, $post ) {
747 - if ( str_contains( $post->post_content, '[formidable ' ) || str_contains( $post->post_content, '<!-- wp:formidable/simple-form ' ) ) {
748 - // New post contains the form shortcode, so clear the embed posts transient.
749 - delete_transient( self::$embed_posts_transient_name );
750 - return;
751 - }
752 -
753 - $cached_posts = get_transient( self::$embed_posts_transient_name );
754 -
755 - if ( ! is_array( $cached_posts ) ) {
756 - return;
757 - }
758 -
759 - // If the new post data of a cached post doesn't contain the Formidable forms, clear the transient.
760 - foreach ( $cached_posts as $posts ) {
761 - foreach ( $posts as $post_data ) {
762 - if ( intval( $post_data->ID ) === intval( $post_id ) ) {
763 - // This post contains the form shortcode before updating, so clear the embed posts transient.
764 - delete_transient( self::$embed_posts_transient_name );
765 - return;
766 - }
767 - }
768 - }
769 359 }
770 360 }