PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.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
formidable / classes / helpers / FrmFormsListHelper.php

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

358 lines 9.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(
22 array(
23 'param' => 'mode',
24 'default' => 'list',
25 )
26 );
27 $orderby = self::get_param(
28 array(
29 'param' => 'orderby',
30 'default' => 'name',
31 )
32 );
33 $order = self::get_param(
34 array(
35 'param' => 'order',
36 'default' => 'ASC',
37 )
38 );
39 $start = self::get_param(
40 array(
41 'param' => 'start',
42 'default' => ( $page - 1 ) * $per_page,
43 )
44 );
45
46 $s_query = array(
47 array(
48 'or' => 1,
49 'parent_form_id' => null,
50 'parent_form_id <' => 1,
51 ),
52 );
53 switch ( $this->status ) {
54 case 'draft':
55 $s_query['is_template'] = 0;
56 $s_query['status'] = 'draft';
57 break;
58 case 'trash':
59 $s_query['status'] = 'trash';
60 break;
61 default:
62 $s_query['is_template'] = 0;
63 $s_query['status !'] = 'trash';
64 break;
65 }
66
67 $s = self::get_param(
68 array(
69 'param' => 's',
70 'sanitize' => 'sanitize_text_field',
71 )
72 );
73 if ( $s != '' ) {
74 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
75 $search_terms = array_map( 'trim', $matches[0] );
76 foreach ( (array) $search_terms as $term ) {
77 $s_query[] = array(
78 'or' => true,
79 'name LIKE' => $term,
80 'description LIKE' => $term,
81 'created_at LIKE' => $term,
82 'form_key LIKE' => $term,
83 'id' => $term,
84 );
85 unset( $term );
86 }
87 }
88
89 $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
90 $total_items = FrmDb::get_count( 'frm_forms', $s_query );
91
92 $this->set_pagination_args(
93 array(
94 'total_items' => $total_items,
95 'per_page' => $per_page,
96 )
97 );
98 }
99
100 public function no_items() {
101 echo '<p>';
102 if ( $this->status === 'trash' ) {
103 esc_html_e( 'No forms found in the trash.', 'formidable' );
104 ?>
105 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
106 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
107 </a>
108 <?php
109 } else {
110
111 esc_html_e( 'No Forms Found.', 'formidable' );
112 ?>
113 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=add_new' ) ); ?>">
114 <?php esc_html_e( 'Add New', 'formidable' ); ?>
115 </a>
116 <?php
117 }
118 echo '</p>';
119 }
120
121 public function get_bulk_actions() {
122 $actions = array();
123
124 if ( 'trash' == $this->status ) {
125 if ( current_user_can( 'frm_edit_forms' ) ) {
126 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
127 }
128
129 if ( current_user_can( 'frm_delete_forms' ) ) {
130 $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
131 }
132 } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
133 $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
134 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
135 $actions['bulk_delete'] = __( 'Delete', 'formidable' );
136 }
137
138 return $actions;
139 }
140
141 public function extra_tablenav( $which ) {
142 if ( 'top' != $which ) {
143 return;
144 }
145
146 if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
147 ?>
148 <div class="alignleft actions frm_visible_overflow">
149 <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
150 </div>
151 <?php
152 }
153 }
154
155 public function get_views() {
156
157 $statuses = array(
158 'published' => __( 'My Forms', 'formidable' ),
159 'draft' => __( 'Drafts', 'formidable' ),
160 'trash' => __( 'Trash', 'formidable' ),
161 );
162
163 $links = array();
164 $counts = FrmForm::get_count();
165 $form_type = self::get_param(
166 array(
167 'param' => 'form_type',
168 'default' => 'published',
169 )
170 );
171
172 foreach ( $statuses as $status => $name ) {
173
174 if ( $status == $form_type ) {
175 $class = ' class="current"';
176 } else {
177 $class = '';
178 }
179
180 if ( $counts->{$status} || 'draft' !== $status ) {
181 /* translators: %1$s: Status, %2$s: Number of items */
182 $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>';
183 }
184
185 unset( $status, $name );
186 }
187
188 return $links;
189 }
190
191 public function pagination( $which ) {
192 global $mode;
193
194 parent::pagination( $which );
195
196 if ( 'top' == $which ) {
197 $this->view_switcher( $mode );
198 }
199 }
200
201 public function single_row( $item, $style = '' ) {
202 global $frm_vars, $mode;
203
204 // Set up the hover actions for this user
205 $actions = array();
206 $edit_link = FrmForm::get_edit_link( $item->id );
207
208 $this->get_actions( $actions, $item, $edit_link );
209
210 $action_links = $this->row_actions( $actions );
211
212 // Set up the checkbox ( because the user is editable, otherwise its empty )
213 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
214
215 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
216
217 list( $columns, $hidden ) = $this->get_column_info();
218
219 $format = 'Y/m/d';
220 if ( 'list' != $mode ) {
221 $format .= ' \<\b\r \/\> g:i:s a';
222 }
223
224 foreach ( $columns as $column_name => $column_display_name ) {
225 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
226
227 $style = '';
228 if ( in_array( $column_name, $hidden ) ) {
229 $class .= ' frm_hidden';
230 }
231
232 $class = 'class="' . esc_attr( $class ) . '"';
233 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
234 $attributes = $class . $style . $data_colname;
235
236 switch ( $column_name ) {
237 case 'cb':
238 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
239 break;
240 case 'id':
241 case 'form_key':
242 $val = $item->{$column_name};
243 break;
244 case 'name':
245 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
246 $val .= $action_links;
247
248 break;
249 case 'created_at':
250 $date = date( $format, strtotime( $item->created_at ) );
251 $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
252 break;
253 case 'shortcode':
254 $val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
255 if ( 'excerpt' == $mode ) {
256 $val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
257 }
258 break;
259 case 'entries':
260 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
261 $val = FrmAppHelper::icon_by_class(
262 'frmfont frm_forbid_icon frm_bstooltip',
263 array(
264 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
265 'echo' => false,
266 )
267 );
268 } else {
269 $text = FrmEntry::getRecordCount( $item->id );
270 $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
271 unset( $text );
272 }
273 }
274
275 if ( isset( $val ) ) {
276 $r .= "<td $attributes>";
277 $r .= $val;
278 $r .= '</td>';
279 }
280 unset( $val );
281 }
282 $r .= '</tr>';
283
284 return $r;
285 }
286
287 /**
288 * @param string $edit_link
289 */
290 private function get_actions( &$actions, $item, $edit_link ) {
291 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
292 foreach ( $new_actions as $link => $action ) {
293 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
294 }
295
296 if ( 'trash' == $this->status ) {
297 $actions = $new_actions;
298
299 return;
300 }
301
302 if ( current_user_can( 'frm_edit_forms' ) ) {
303 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
304 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
305 }
306
307 $actions = array_merge( $actions, $new_actions );
308 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
309 }
310
311 /**
312 * @param string $edit_link
313 */
314 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
315 $form_name = $item->name;
316 if ( trim( $form_name ) == '' ) {
317 $form_name = __( '(no title)', 'formidable' );
318 }
319 $form_name = FrmAppHelper::kses( $form_name );
320 if ( 'excerpt' != $mode ) {
321 $form_name = FrmAppHelper::truncate( $form_name, 50 );
322 }
323
324 $val = '<strong>';
325 if ( 'trash' == $this->status ) {
326 $val .= $form_name;
327 } else {
328 $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> ';
329 }
330
331 $this->add_draft_label( $item, $val );
332 $val .= '</strong>';
333
334 $this->add_form_description( $item, $val );
335
336 return $val;
337 }
338
339 /**
340 * @param string $val
341 */
342 private function add_draft_label( $item, &$val ) {
343 if ( 'draft' == $item->status && 'draft' != $this->status ) {
344 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
345 }
346 }
347
348 /**
349 * @param string $val
350 */
351 private function add_form_description( $item, &$val ) {
352 global $mode;
353 if ( 'excerpt' == $mode ) {
354 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
355 }
356 }
357 }
358