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