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 / helpers / FrmFormsListHelper.php

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

396 lines 12.8 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 function __construct( $args ) {
10 $this->status = self::get_param( array( 'param' => 'form_type' ) );
11
12 parent::__construct( $args );
13 }
14
15 public function prepare_items() {
16 global $wpdb, $per_page, $mode;
17
18 $page = $this->get_pagenum();
19 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
20
21 $mode = self::get_param( array(
22 'param' => 'mode',
23 'default' => 'list',
24 ) );
25 $orderby = self::get_param( array(
26 'param' => 'orderby',
27 'default' => 'name',
28 ) );
29 $order = self::get_param( array(
30 'param' => 'order',
31 'default' => 'ASC',
32 ) );
33 $start = self::get_param( array(
34 'param' => 'start',
35 'default' => ( $page - 1 ) * $per_page,
36 ) );
37
38 $s_query = array(
39 array(
40 'or' => 1,
41 'parent_form_id' => null,
42 'parent_form_id <' => 1,
43 ),
44 );
45 switch ( $this->status ) {
46 case 'template':
47 $s_query['is_template'] = 1;
48 $s_query['status !'] = 'trash';
49 break;
50 case 'draft':
51 $s_query['is_template'] = 0;
52 $s_query['status'] = 'draft';
53 break;
54 case 'trash':
55 $s_query['status'] = 'trash';
56 break;
57 default:
58 $s_query['is_template'] = 0;
59 $s_query['status !'] = 'trash';
60 break;
61 }
62
63 $s = self::get_param( array(
64 'param' => 's',
65 'sanitize' => 'sanitize_text_field',
66 ) );
67 if ( $s != '' ) {
68 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
69 $search_terms = array_map('trim', $matches[0]);
70 foreach ( (array) $search_terms as $term ) {
71 $s_query[] = array(
72 'or' => true,
73 'name LIKE' => $term,
74 'description LIKE' => $term,
75 'created_at LIKE' => $term,
76 );
77 unset( $term );
78 }
79 }
80
81 $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
82 $total_items = FrmDb::get_count( 'frm_forms', $s_query );
83
84 $this->set_pagination_args( array(
85 'total_items' => $total_items,
86 'per_page' => $per_page,
87 ) );
88 }
89
90 public function no_items() {
91 if ( 'template' == $this->status ) {
92 esc_html_e( 'No Templates Found.', 'formidable' );
93 } else {
94 esc_html_e( 'No Forms Found.', 'formidable' );
95 ?>
96 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>"><?php esc_html_e( 'Add New', 'formidable' ); ?></a>
97 <?php
98 }
99 }
100
101 public function get_bulk_actions() {
102 $actions = array();
103
104 if ( in_array( $this->status, array( '', 'published' ) ) ) {
105 $actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
106 }
107
108 if ( 'trash' == $this->status ) {
109 if ( current_user_can('frm_edit_forms') ) {
110 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
111 }
112
113 if ( current_user_can('frm_delete_forms') ) {
114 $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
115 }
116 } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
117 $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
118 } else if ( current_user_can('frm_delete_forms') ) {
119 $actions['bulk_delete'] = __( 'Delete');
120 }
121
122 return $actions;
123 }
124
125 public function extra_tablenav( $which ) {
126 if ( 'top' != $which ) {
127 return;
128 }
129
130 if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
131 ?>
132 <div class="alignleft actions frm_visible_overflow">
133 <?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
134 </div>
135 <?php
136 return;
137 }
138
139 if ( 'template' != $this->status ) {
140 return;
141 }
142
143 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
144 $forms = FrmForm::get_published_forms( $where );
145
146 $base = admin_url('admin.php?page=formidable&form_type=template');
147 $args = array(
148 'frm_action' => 'duplicate',
149 'template' => true,
150 );
151
152 ?>
153 <div class="alignleft actions frm_visible_overflow">
154 <div class="dropdown frm_tiny_top_margin">
155 <a href="#" id="frm-templateDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php esc_html_e( 'Create New Template', 'formidable' ) ?> <b class="caret"></b></a>
156 <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop">
157 <?php
158 if ( empty( $forms ) ) {
159 ?>
160 <li class="frm_dropdown_li"><?php esc_html_e( 'You have not created any forms yet. You must create a form before you can make a template.', 'formidable' ) ?></li>
161 <?php
162 } else {
163 foreach ( $forms as $form ) {
164 $args['id'] = $form->id;
165 ?>
166 <li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li>
167 <?php
168 unset($form);
169 }
170 }
171 ?>
172 </ul>
173 </div>
174 </div>
175 <?php
176 }
177
178 public function get_views() {
179
180 $statuses = array(
181 'published' => __( 'My Forms', 'formidable' ),
182 'template' => __( 'Templates', 'formidable' ),
183 'draft' => __( 'Drafts', 'formidable' ),
184 'trash' => __( 'Trash', 'formidable' ),
185 );
186
187 $links = array();
188 $counts = FrmForm::get_count();
189 $form_type = self::get_param( array(
190 'param' => 'form_type',
191 'default' => 'published',
192 ) );
193
194 foreach ( $statuses as $status => $name ) {
195
196 if ( $status == $form_type ) {
197 $class = ' class="current"';
198 } else {
199 $class = '';
200 }
201
202 if ( $counts->{$status} || 'published' == $status ) {
203 $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>';
204 }
205
206 unset($status, $name);
207 }
208
209 return $links;
210 }
211
212 public function pagination( $which ) {
213 global $mode;
214
215 parent::pagination( $which );
216
217 if ( 'top' == $which ) {
218 $this->view_switcher( $mode );
219 }
220 }
221
222 public function single_row( $item, $style = '' ) {
223 global $frm_vars, $mode;
224
225 // Set up the hover actions for this user
226 $actions = array();
227 $edit_link = '?page=formidable&frm_action=edit&id=' . $item->id;
228 $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $item->id;
229
230 $this->get_actions($actions, $item, $edit_link, $duplicate_link);
231
232 $action_links = $this->row_actions( $actions );
233
234 // Set up the checkbox ( because the user is editable, otherwise its empty )
235 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
236
237 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
238
239 list( $columns, $hidden ) = $this->get_column_info();
240
241 $format = 'Y/m/d';
242 if ( 'list' != $mode ) {
243 $format .= ' \<\b\r \/\> g:i:s a';
244 }
245
246 foreach ( $columns as $column_name => $column_display_name ) {
247 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
248
249 $style = '';
250 if ( in_array( $column_name, $hidden ) ) {
251 $class .= ' frm_hidden';
252 }
253
254 $class = 'class="' . esc_attr( $class ) . '"';
255 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
256 $attributes = $class . $style . $data_colname;
257
258 switch ( $column_name ) {
259 case 'cb':
260 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
261 break;
262 case 'id':
263 case 'form_key':
264 $val = $item->{$column_name};
265 break;
266 case 'name':
267 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
268 $val .= $action_links;
269
270 break;
271 case 'created_at':
272 $date = date($format, strtotime($item->created_at));
273 $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
274 break;
275 case 'shortcode':
276 $val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
277 if ( 'excerpt' == $mode ) {
278 $val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
279 }
280 break;
281 case 'entries':
282 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
283 $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr('Saving entries is disabled for this form', 'formidable' ) . '"></i>';
284 } else {
285 $text = FrmEntry::getRecordCount($item->id);
286 $val = current_user_can('frm_view_entries') ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
287 unset($text);
288 }
289 break;
290 case 'type':
291 $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
292 break;
293 }
294
295 if ( isset($val) ) {
296 $r .= "<td $attributes>";
297 $r .= $val;
298 $r .= '</td>';
299 }
300 unset($val);
301 }
302 $r .= '</tr>';
303
304 return $r;
305 }
306
307 /**
308 * @param string $edit_link
309 * @param string $duplicate_link
310 */
311 private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
312 if ( 'trash' == $this->status ) {
313 if ( current_user_can('frm_edit_forms') ) {
314 $actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
315 }
316
317 if ( current_user_can('frm_delete_forms') ) {
318 $trash_url = wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id=' . $item->id, 'destroy_form_' . $item->id );
319 $actions['trash'] = '<a href="' . esc_url( $trash_url ) . '" class="submitdelete" onclick="return confirm(\'' . __( 'Are you sure you want to permanently delete that?', 'formidable' ) . '\')">' . __( 'Delete Permanently' ) . '</a>';
320 }
321 return;
322 }
323
324 if ( current_user_can('frm_edit_forms') ) {
325 if ( ! $item->is_template || ! $item->default_template ) {
326 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit' ) . '</a>';
327 }
328
329 if ( $item->is_template ) {
330 $actions['frm_duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Create Form from Template', 'formidable' ) . '</a>';
331 } else {
332 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
333
334 if ( FrmAppHelper::pro_is_installed() ) {
335 $actions['duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Duplicate', 'formidable' ) . '</a>';
336 }
337 }
338 }
339
340 $actions['trash'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
341 if ( empty( $actions['trash'] ) ) {
342 // the user doesn't have permission
343 unset( $actions['trash'] );
344 }
345
346 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview') . '</a>';
347 }
348
349 /**
350 * @param string $edit_link
351 */
352 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
353 $form_name = $item->name;
354 if ( trim($form_name) == '' ) {
355 $form_name = __( '(no title)');
356 }
357 $form_name = FrmAppHelper::kses( $form_name );
358 if ( 'excerpt' != $mode ) {
359 $form_name = FrmAppHelper::truncate( $form_name, 50 );
360 }
361
362 $val = '<strong>';
363 if ( 'trash' == $this->status ) {
364 $val .= $form_name;
365 } else {
366 $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> ';
367 }
368
369 $this->add_draft_label( $item, $val );
370 $val .= '</strong>';
371
372 $this->add_form_description( $item, $val );
373
374 return $val;
375 }
376
377 /**
378 * @param string $val
379 */
380 private function add_draft_label( $item, &$val ) {
381 if ( 'draft' == $item->status && 'draft' != $this->status ) {
382 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
383 }
384 }
385
386 /**
387 * @param string $val
388 */
389 private function add_form_description( $item, &$val ) {
390 global $mode;
391 if ( 'excerpt' == $mode ) {
392 $val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
393 }
394 }
395 }
396