| @@ -3,19 +3,12 @@ | ||
| 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 ); |
| @@ -29,9 +22,9 @@ | ||
| 29 | 22 | /** |
| 30 | 23 | * @return void |
| 31 | 24 | */ |
| 32 | 25 | public function prepare_items() { |
| 33 | - global $per_page, $mode; | |
| 26 | + global $wpdb, $per_page, $mode; | |
| 34 | 27 | |
| 35 | 28 | $page = $this->get_pagenum(); |
| 36 | 29 | $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' ); |
| 37 | 30 | |
| @@ -55,9 +48,9 @@ | ||
| 55 | 48 | ); |
| 56 | 49 | |
| 57 | 50 | FrmAppController::apply_saved_sort_preference( $orderby, $order ); |
| 58 | 51 | |
| 59 | - $start = self::get_param( | |
| 52 | + $start = self::get_param( | |
| 60 | 53 | array( |
| 61 | 54 | 'param' => 'start', |
| 62 | 55 | 'default' => ( $page - 1 ) * $per_page, |
| 63 | 56 | ) |
| @@ -89,13 +82,11 @@ | ||
| 89 | 82 | 'param' => 's', |
| 90 | 83 | 'sanitize' => 'sanitize_text_field', |
| 91 | 84 | ) |
| 92 | 85 | ); |
| 93 | - | |
| 94 | - if ( $s !== '' ) { | |
| 86 | + if ( $s != '' ) { | |
| 95 | 87 | preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches ); |
| 96 | 88 | $search_terms = array_map( 'trim', $matches[0] ); |
| 97 | - | |
| 98 | 89 | foreach ( $search_terms as $term ) { |
| 99 | 90 | $s_query[] = array( |
| 100 | 91 | 'or' => true, |
| 101 | 92 | 'name LIKE' => $term, |
| @@ -126,15 +117,13 @@ | ||
| 126 | 117 | public function no_items() { |
| 127 | 118 | if ( $this->status === 'trash' ) { |
| 128 | 119 | echo '<p>'; |
| 129 | 120 | esc_html_e( 'No forms found in the trash.', 'formidable' ); |
| 130 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 131 | 121 | ?> |
| 132 | 122 | <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>"> |
| 133 | 123 | <?php esc_html_e( 'See all forms.', 'formidable' ); ?> |
| 134 | 124 | </a> |
| 135 | 125 | <?php |
| 136 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 137 | 126 | echo '</p>'; |
| 138 | 127 | } else { |
| 139 | 128 | $title = __( 'No Forms Found', 'formidable' ); |
| 140 | 129 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php'; |
| @@ -161,10 +150,8 @@ | ||
| 161 | 150 | return $actions; |
| 162 | 151 | } |
| 163 | 152 | |
| 164 | 153 | /** |
| 165 | - * @param string $which | |
| 166 | - * | |
| 167 | 154 | * @return void |
| 168 | 155 | */ |
| 169 | 156 | public function extra_tablenav( $which ) { |
| 170 | 157 | if ( 'top' !== $which ) { |
| @@ -170,19 +157,15 @@ | ||
| 170 | 157 | if ( 'top' !== $which ) { |
| 171 | 158 | return; |
| 172 | 159 | } |
| 173 | 160 | |
| 174 | - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) { | |
| 175 | - return; | |
| 161 | + if ( 'trash' === $this->status && current_user_can( 'frm_delete_forms' ) ) { | |
| 162 | + ?> | |
| 163 | + <div class="alignleft actions frm_visible_overflow"> | |
| 164 | + <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?> | |
| 165 | + </div> | |
| 166 | + <?php | |
| 176 | 167 | } |
| 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 | 168 | } |
| 186 | 169 | |
| 187 | 170 | /** |
| 188 | 171 | * @return array |
| @@ -209,13 +192,18 @@ | ||
| 209 | 192 | ) |
| 210 | 193 | ); |
| 211 | 194 | |
| 212 | 195 | foreach ( $statuses as $status => $name ) { |
| 213 | - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 214 | 196 | |
| 197 | + if ( $status == $form_type ) { | |
| 198 | + $class = ' class="current"'; | |
| 199 | + } else { | |
| 200 | + $class = ''; | |
| 201 | + } | |
| 202 | + | |
| 215 | 203 | if ( $counts->{$status} || 'draft' !== $status ) { |
| 216 | 204 | /* 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 | |
| 205 | + $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 | 206 | } |
| 219 | 207 | |
| 220 | 208 | unset( $status, $name ); |
| 221 | 209 | } |
| @@ -224,9 +212,8 @@ | ||
| 224 | 212 | } |
| 225 | 213 | |
| 226 | 214 | /** |
| 227 | 215 | * @param string $which |
| 228 | - * | |
| 229 | 216 | * @return void |
| 230 | 217 | */ |
| 231 | 218 | public function pagination( $which ) { |
| 232 | 219 | global $mode; |
| @@ -240,13 +227,12 @@ | ||
| 240 | 227 | |
| 241 | 228 | /** |
| 242 | 229 | * @param stdClass $item |
| 243 | 230 | * @param string $style |
| 244 | - * | |
| 245 | 231 | * @return string |
| 246 | 232 | */ |
| 247 | 233 | public function single_row( $item, $style = '' ) { |
| 248 | - global $mode; | |
| 234 | + global $frm_vars, $mode; | |
| 249 | 235 | |
| 250 | 236 | // Set up the hover actions for this user |
| 251 | 237 | $actions = array(); |
| 252 | 238 | $edit_link = FrmForm::get_edit_link( $item->id ); |
| @@ -263,14 +249,14 @@ | ||
| 263 | 249 | ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text() |
| 264 | 250 | ); |
| 265 | 251 | |
| 266 | 252 | $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 . '>'; | |
| 268 | 253 | |
| 254 | + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>'; | |
| 255 | + | |
| 269 | 256 | list( $columns, $hidden ) = $this->get_column_info(); |
| 270 | 257 | |
| 271 | 258 | $format = 'Y/m/d'; |
| 272 | - | |
| 273 | 259 | if ( 'list' !== $mode ) { |
| 274 | 260 | $format .= ' \<\b\r \/\> g:i:s a'; |
| 275 | 261 | } |
| 276 | 262 | |
| @@ -275,10 +261,10 @@ | ||
| 275 | 261 | } |
| 276 | 262 | |
| 277 | 263 | foreach ( $columns as $column_name => $column_display_name ) { |
| 278 | 264 | $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' ); |
| 265 | + | |
| 279 | 266 | $style = ''; |
| 280 | - | |
| 281 | 267 | if ( in_array( $column_name, $hidden, true ) ) { |
| 282 | 268 | $class .= ' frm_hidden'; |
| 283 | 269 | } |
| 284 | 270 | |
| @@ -306,9 +292,9 @@ | ||
| 306 | 292 | $date = gmdate( $format, strtotime( $item->created_at ) ); |
| 307 | 293 | $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>'; |
| 308 | 294 | break; |
| 309 | 295 | case 'entries': |
| 310 | - if ( ! empty( $item->options['no_save'] ) ) { | |
| 296 | + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) { | |
| 311 | 297 | $val = FrmAppHelper::icon_by_class( |
| 312 | 298 | 'frmfont frm_forbid_icon frm_bstooltip', |
| 313 | 299 | array( |
| 314 | 300 | 'title' => __( 'Saving entries is disabled for this form', 'formidable' ), |
| @@ -316,9 +302,9 @@ | ||
| 316 | 302 | ) |
| 317 | 303 | ); |
| 318 | 304 | } else { |
| 319 | 305 | $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 | |
| 306 | + $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 | 307 | unset( $text ); |
| 322 | 308 | } |
| 323 | 309 | break; |
| 324 | 310 | default: |
| @@ -334,9 +320,11 @@ | ||
| 334 | 320 | $r .= '</td>'; |
| 335 | 321 | } |
| 336 | 322 | unset( $val ); |
| 337 | 323 | }//end foreach |
| 338 | - return $r . '</tr>'; | |
| 324 | + $r .= '</tr>'; | |
| 325 | + | |
| 326 | + return $r; | |
| 339 | 327 | } |
| 340 | 328 | |
| 341 | 329 | /** |
| 342 | 330 | * Get the HTML for the Actions column in the form list. |
| @@ -344,19 +332,19 @@ | ||
| 344 | 332 | * |
| 345 | 333 | * @since 6.0 |
| 346 | 334 | * |
| 347 | 335 | * @param stdClass $form |
| 348 | - * | |
| 349 | 336 | * @return string |
| 350 | 337 | */ |
| 351 | 338 | 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 | |
| 339 | + $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>'; | |
| 353 | 340 | $val .= $this->column_style( $form ); |
| 354 | 341 | $val .= $this->column_views( $form ); |
| 355 | 342 | $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) ); |
| 356 | 343 | // Remove the space hard coded in Landing pages. |
| 357 | 344 | $val = str_replace( ' ', '', $val ); |
| 358 | - return '<div>' . $val . '</div>'; | |
| 345 | + $val = '<div>' . $val . '</div>'; | |
| 346 | + return $val; | |
| 359 | 347 | } |
| 360 | 348 | |
| 361 | 349 | /** |
| 362 | 350 | * Get the HTML for the Style column in the form list. |
| @@ -363,13 +351,12 @@ | ||
| 363 | 351 | * |
| 364 | 352 | * @since 6.0 |
| 365 | 353 | * |
| 366 | 354 | * @param stdClass $form |
| 367 | - * | |
| 368 | 355 | * @return string |
| 369 | 356 | */ |
| 370 | 357 | protected function column_style( $form ) { |
| 371 | - $style_setting = $form->options['custom_style'] ?? ''; | |
| 358 | + $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : ''; | |
| 372 | 359 | $frm_settings = FrmAppHelper::get_settings(); |
| 373 | 360 | |
| 374 | 361 | if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) { |
| 375 | 362 | // Don't show a link if styling is off. |
| @@ -376,9 +363,8 @@ | ||
| 376 | 363 | return ''; |
| 377 | 364 | } |
| 378 | 365 | |
| 379 | 366 | $style = FrmStylesController::get_form_style( $form ); |
| 380 | - | |
| 381 | 367 | if ( ! $style ) { |
| 382 | 368 | // Do a second pass to avoid null values. |
| 383 | 369 | $frm_style = new FrmStyle( 'default' ); |
| 384 | 370 | $style = $frm_style->get_one(); |
| @@ -384,9 +370,9 @@ | ||
| 384 | 370 | $style = $frm_style->get_one(); |
| 385 | 371 | } |
| 386 | 372 | |
| 387 | 373 | $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 | |
| 374 | + 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 | 375 | } |
| 390 | 376 | |
| 391 | 377 | /** |
| 392 | 378 | * Generate the HTML for the form Views page. |
| @@ -393,23 +379,20 @@ | ||
| 393 | 379 | * |
| 394 | 380 | * @since 6.19 |
| 395 | 381 | * |
| 396 | 382 | * @param stdClass $form Form object. |
| 397 | - * | |
| 398 | 383 | * @return string |
| 399 | 384 | */ |
| 400 | 385 | protected function column_views( $form ) { |
| 401 | 386 | $attributes = array( |
| 402 | 387 | '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' ), | |
| 388 | + 'title' => __( 'View Form', 'formidable' ), | |
| 404 | 389 | 'target' => '_blank', |
| 405 | 390 | ); |
| 406 | 391 | |
| 407 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 408 | 392 | return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '> |
| 409 | 393 | ' . FrmAppHelper::icon_by_class( 'frmfont frm_eye_icon', array( 'echo' => false ) ) . |
| 410 | 394 | '</a>'; |
| 411 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 412 | 395 | } |
| 413 | 396 | |
| 414 | 397 | /** |
| 415 | 398 | * @param array $actions |
| @@ -419,9 +402,8 @@ | ||
| 419 | 402 | * @return void |
| 420 | 403 | */ |
| 421 | 404 | private function get_actions( &$actions, $item, $edit_link ) { |
| 422 | 405 | $new_actions = FrmFormsHelper::get_action_links( $item->id, $item ); |
| 423 | - | |
| 424 | 406 | foreach ( $new_actions as $link => $action ) { |
| 425 | 407 | $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' ); |
| 426 | 408 | } |
| 427 | 409 | |
| @@ -430,14 +412,14 @@ | ||
| 430 | 412 | return; |
| 431 | 413 | } |
| 432 | 414 | |
| 433 | 415 | 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>'; | |
| 416 | + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>'; | |
| 417 | + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>'; | |
| 436 | 418 | } |
| 437 | 419 | |
| 438 | 420 | $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 | |
| 421 | + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>'; | |
| 440 | 422 | } |
| 441 | 423 | |
| 442 | 424 | /** |
| 443 | 425 | * @param object $item |
| @@ -448,25 +430,21 @@ | ||
| 448 | 430 | * @return string |
| 449 | 431 | */ |
| 450 | 432 | private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) { |
| 451 | 433 | $form_name = $item->name; |
| 452 | - | |
| 453 | - if ( is_null( $form_name ) || trim( $form_name ) === '' ) { | |
| 434 | + if ( is_null( $form_name ) || trim( $form_name ) == '' ) { | |
| 454 | 435 | $form_name = FrmFormsHelper::get_no_title_text(); |
| 455 | 436 | } |
| 456 | - | |
| 457 | 437 | $form_name = FrmAppHelper::kses( $form_name ); |
| 458 | - | |
| 459 | - if ( 'excerpt' !== $mode ) { | |
| 438 | + if ( 'excerpt' != $mode ) { | |
| 460 | 439 | $form_name = FrmAppHelper::truncate( $form_name, 50 ); |
| 461 | 440 | } |
| 462 | 441 | |
| 463 | 442 | $val = '<strong>'; |
| 464 | - | |
| 465 | 443 | if ( 'trash' === $this->status ) { |
| 466 | 444 | $val .= $form_name; |
| 467 | 445 | } 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 | |
| 446 | + $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 | 447 | } |
| 470 | 448 | |
| 471 | 449 | $this->add_draft_label( $item, $val ); |
| 472 | 450 | $val .= '</strong>'; |
| @@ -482,9 +460,9 @@ | ||
| 482 | 460 | * |
| 483 | 461 | * @return void |
| 484 | 462 | */ |
| 485 | 463 | private function add_draft_label( $item, &$val ) { |
| 486 | - if ( 'draft' === $item->status && 'draft' !== $this->status ) { | |
| 464 | + if ( 'draft' === $item->status && 'draft' != $this->status ) { | |
| 487 | 465 | $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>'; |
| 488 | 466 | } |
| 489 | 467 | } |
| 490 | 468 | |
| @@ -495,9 +473,8 @@ | ||
| 495 | 473 | * @return void |
| 496 | 474 | */ |
| 497 | 475 | private function add_form_description( $item, &$val ) { |
| 498 | 476 | global $mode; |
| 499 | - | |
| 500 | 477 | if ( 'excerpt' === $mode && ! is_null( $item->description ) ) { |
| 501 | 478 | $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 ); |
| 502 | 479 | } |
| 503 | 480 | } |