PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.01
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 / helpers / FrmFormsListHelper.php

FrmFormsListHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.2.01, at classes/helpers/FrmFormsListHelper.php

361 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFormsListHelper extends FrmListHelper {
7 public $status = '';
8
9 public $total_items = 0;
10
11 public function __construct( $args ) {
12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
13
14 parent::__construct( $args );
15 }
16
17 public function prepare_items() {
18 global $wpdb, $per_page, $mode;
19
20 $page = $this->get_pagenum();
21 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
22
23 $mode = self::get_param(
24 array(
25 'param' => 'mode',
26 'default' => 'list',
27 )
28 );
29 $orderby = self::get_param(
30 array(
31 'param' => 'orderby',
32 'default' => 'name',
33 )
34 );
35 $order = self::get_param(
36 array(
37 'param' => 'order',
38 'default' => 'ASC',
39 )
40 );
41 $start = self::get_param(
42 array(
43 'param' => 'start',
44 'default' => ( $page - 1 ) * $per_page,
45 )
46 );
47
48 $s_query = array(
49 array(
50 'or' => 1,
51 'parent_form_id' => null,
52 'parent_form_id <' => 1,
53 ),
54 );
55 switch ( $this->status ) {
56 case 'draft':
57 $s_query['is_template'] = 0;
58 $s_query['status'] = 'draft';
59 break;
60 case 'trash':
61 $s_query['status'] = 'trash';
62 break;
63 default:
64 $s_query['is_template'] = 0;
65 $s_query['status !'] = 'trash';
66 break;
67 }
68
69 $s = self::get_param(
70 array(
71 'param' => 's',
72 'sanitize' => 'sanitize_text_field',
73 )
74 );
75 if ( $s != '' ) {
76 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
77 $search_terms = array_map( 'trim', $matches[0] );
78 foreach ( (array) $search_terms as $term ) {
79 $s_query[] = array(
80 'or' => true,
81 'name LIKE' => $term,
82 'description LIKE' => $term,
83 'created_at LIKE' => $term,
84 'form_key LIKE' => $term,
85 'id' => $term,
86 );
87 unset( $term );
88 }
89 }
90
91 $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
92 $total_items = FrmDb::get_count( 'frm_forms', $s_query );
93 $this->total_items = $total_items;
94
95 $this->set_pagination_args(
96 array(
97 'total_items' => $total_items,
98 'per_page' => $per_page,
99 )
100 );
101 }
102
103 public function no_items() {
104 if ( $this->status === 'trash' ) {
105 echo '<p>';
106 esc_html_e( 'No forms found in the trash.', 'formidable' );
107 ?>
108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
109 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
110 </a>
111 <?php
112 echo '</p>';
113 } else {
114 $title = __( 'No Forms Found', 'formidable' );
115 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
116 }
117 }
118
119 public function get_bulk_actions() {
120 $actions = array();
121
122 if ( 'trash' == $this->status ) {
123 if ( current_user_can( 'frm_edit_forms' ) ) {
124 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
125 }
126
127 if ( current_user_can( 'frm_delete_forms' ) ) {
128 $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
129 }
130 } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
131 $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
132 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
133 $actions['bulk_delete'] = __( 'Delete', 'formidable' );
134 }
135
136 return $actions;
137 }
138
139 public function extra_tablenav( $which ) {
140 if ( 'top' != $which ) {
141 return;
142 }
143
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
150 }
151 }
152
153 public function get_views() {
154
155 $statuses = array(
156 'published' => __( 'My Forms', 'formidable' ),
157 'draft' => __( 'Drafts', 'formidable' ),
158 'trash' => __( 'Trash', 'formidable' ),
159 );
160
161 $links = array();
162 $counts = FrmForm::get_count();
163 $form_type = self::get_param(
164 array(
165 'param' => 'form_type',
166 'default' => 'published',
167 )
168 );
169
170 foreach ( $statuses as $status => $name ) {
171
172 if ( $status == $form_type ) {
173 $class = ' class="current"';
174 } else {
175 $class = '';
176 }
177
178 if ( $counts->{$status} || 'draft' !== $status ) {
179 /* translators: %1$s: Status, %2$s: Number of items */
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>';
181 }
182
183 unset( $status, $name );
184 }
185
186 return $links;
187 }
188
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
199 public function single_row( $item, $style = '' ) {
200 global $frm_vars, $mode;
201
202 // Set up the hover actions for this user
203 $actions = array();
204 $edit_link = FrmForm::get_edit_link( $item->id );
205
206 $this->get_actions( $actions, $item, $edit_link );
207
208 $action_links = $this->row_actions( $actions );
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
215 list( $columns, $hidden ) = $this->get_column_info();
216
217 $format = 'Y/m/d';
218 if ( 'list' != $mode ) {
219 $format .= ' \<\b\r \/\> g:i:s a';
220 }
221
222 foreach ( $columns as $column_name => $column_display_name ) {
223 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
224
225 $style = '';
226 if ( in_array( $column_name, $hidden ) ) {
227 $class .= ' frm_hidden';
228 }
229
230 $class = 'class="' . esc_attr( $class ) . '"';
231 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
232 $attributes = $class . $style . $data_colname;
233
234 switch ( $column_name ) {
235 case 'cb':
236 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
237 break;
238 case 'id':
239 case 'form_key':
240 $val = $item->{$column_name};
241 break;
242 case 'name':
243 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
244 $val .= $action_links;
245
246 break;
247 case 'created_at':
248 $date = gmdate( $format, strtotime( $item->created_at ) );
249 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
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;
255 case 'entries':
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 );
268 }
269 }
270
271 if ( isset( $val ) ) {
272 $r .= "<td $attributes>";
273 $r .= $val;
274 $r .= '</td>';
275 }
276 unset( $val );
277 }
278 $r .= '</tr>';
279
280 return $r;
281 }
282
283 /**
284 * @param string $edit_link
285 */
286 private function get_actions( &$actions, $item, $edit_link ) {
287 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
288 foreach ( $new_actions as $link => $action ) {
289 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
290 }
291
292 if ( 'trash' == $this->status ) {
293 $actions = $new_actions;
294
295 return;
296 }
297
298 if ( current_user_can( 'frm_edit_forms' ) ) {
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>';
301 }
302
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>';
305 }
306
307 /**
308 * @param string $edit_link
309 */
310 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
311 $form_name = $item->name;
312 if ( trim( $form_name ) == '' ) {
313 $form_name = __( '(no title)', 'formidable' );
314 }
315 $form_name = FrmAppHelper::kses( $form_name );
316 if ( 'excerpt' != $mode ) {
317 $form_name = FrmAppHelper::truncate( $form_name, 50 );
318 }
319
320 $val = '<strong>';
321 if ( 'trash' == $this->status ) {
322 $val .= $form_name;
323 } else {
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> ';
325 }
326
327 $this->add_draft_label( $item, $val );
328 $val .= '</strong>';
329
330 $this->add_form_description( $item, $val );
331
332 return $val;
333 }
334
335 /**
336 * @param string $val
337 */
338 private function add_draft_label( $item, &$val ) {
339 if ( 'draft' == $item->status && 'draft' != $this->status ) {
340 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
341 }
342 }
343
344 /**
345 * @param string $val
346 */
347 private function add_form_description( $item, &$val ) {
348 global $mode;
349 if ( 'excerpt' == $mode ) {
350 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
351 }
352 }
353
354 /**
355 * @return string
356 */
357 protected function confirm_bulk_delete() {
358 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
359 }
360 }
361