PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 1.07.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v1.07.11
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 / FrmListHelper.php

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

229 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
4
5 if(class_exists('FrmListHelper'))
6 return;
7
8 class FrmListHelper extends WP_List_Table {
9
10 function __construct($args) {
11 global $frm_settings;
12
13 $args = wp_parse_args( $args, array(
14 'ajax' => false,
15 'table_name' => '',
16 'page_name' => '',
17 'params' => array()
18 ) );
19 $this->table_name = $args['table_name'];
20 $this->page_name = $args['page_name'];
21 $this->params = $args['params'];
22
23 $screen = get_current_screen();
24
25 parent::__construct( $args );
26 }
27
28 function ajax_user_can() {
29 return current_user_can( 'administrator' );
30 }
31
32 function prepare_items() {
33 global $wpdb, $per_page, $frm_settings;
34 $paged = $this->get_pagenum();
35 $default_orderby = 'name';
36 $default_order = 'ASC';
37
38 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
39 $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
40
41 $page = $this->get_pagenum();
42 $default_count = empty($this->page_name) ? 20 : 10;
43 $per_page = $this->get_items_per_page( 'formidable_page_formidable'. str_replace('-', '_', $this->page_name) .'_per_page', $default_count);
44
45 $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
46 $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
47 $fid = isset( $_REQUEST['fid'] ) ? $_REQUEST['fid'] : '';
48 if($s != ''){
49 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
50 $search_terms = array_map('trim', $matches[0]);
51 }
52
53 $s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ". (int)$this->params['template'];
54
55 if($s != ''){
56 foreach ( (array) $search_terms as $term ) {
57 if ( !empty($s_query) ) {
58 $s_query .= " AND";
59 }
60
61 $term = FrmAppHelper::esc_like($term);
62
63 $s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%'. $term .'%', '%'. $term .'%', '%'. $term .'%');
64
65 unset($term);
66 }
67 }
68
69 $frm_form = new FrmForm();
70 $this->items = $frm_form->getAll($s_query, " ORDER BY $orderby $order", " LIMIT $start, $per_page", true, false);
71 $total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name);
72
73
74 $this->set_pagination_args( array(
75 'total_items' => $total_items,
76 'per_page' => $per_page
77 ) );
78 }
79
80 function no_items() {
81 if ($this->params['template']){
82 _e('No Templates Found', 'formidable') ?>.
83 <br/><br/><?php _e('To add a new template','formidable') ?>:
84 <ol><li><?php printf(__('Create a new %1$sform%2$s.', 'formidable'), '<a href="?page=formidable&amp;frm_action=new-selection">', '</a>') ?></li>
85 <li><?php printf(__('After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable'), '<a href="?page=formidable">', '</a>') ?></li>
86 <li><?php _e('Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable') ?></li>
87 </ol>
88 <?php }else{
89 _e('No Forms Found', 'formidable') ?>.
90 <a href="?page=formidable&amp;frm_action=new-selection"><?php _e('Add New', 'formidable'); ?></a>
91 <?php }
92 }
93
94 function get_bulk_actions(){
95 $actions = array();
96 if ( current_user_can('frm_delete_forms') ) {
97 $actions['bulk_delete'] = __('Delete');
98 }
99
100 return $actions;
101 }
102
103 function display_rows() {
104 $style = '';
105 foreach ( $this->items as $item ) {
106 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
107 echo "\n\t", $this->single_row( $item, $style );
108 }
109 }
110
111 function single_row( $item, $style='') {
112 global $frm_vars, $frm_entry;
113 $checkbox = '';
114
115 // Set up the hover actions for this user
116 $actions = array();
117 $title = esc_attr(strip_tags($item->name));
118
119 if ( current_user_can('frm_edit_forms') ) {
120 $edit_link = "?page=formidable&frm_action=edit&id={$item->id}";
121 $duplicate_link = "?page=formidable&frm_action=duplicate&id={$item->id}";
122
123 $actions['frm_edit'] = "<a href='" . esc_url( $edit_link ) . "'>". __('Edit') ."</a>";
124
125 if ( $this->params['template'] ) {
126 $actions['frm_duplicate'] = "<a href='" . wp_nonce_url( $duplicate_link ) . "'>". __('Create Form from Template', 'formidable') ."</a>";
127 } else {
128 $actions['frm_settings'] = "<a href='" . wp_nonce_url( "?page=formidable&frm_action=settings&id={$item->id}" ) . "'>". __('Settings', 'formidable') ."</a>";
129
130 if ( $frm_vars['pro_is_installed'] ) {
131 $actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __('Duplicate', 'formidable') .'</a>';
132 }
133 }
134 }
135
136 $delete_link = "?page=formidable&frm_action=destroy&id={$item->id}";
137 if(current_user_can('frm_delete_forms'))
138 $actions['trash'] = '<a class="submitdelete" href="' . wp_nonce_url( $delete_link ) .'" onclick="return confirm(\''. __('Are you sure you want to delete that?', 'formidable') .'\')">' . __( 'Delete' ) . '</a>';
139
140 $actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __('Preview') .'</a>';
141
142 $action_links = $this->row_actions( $actions );
143
144 // Set up the checkbox ( because the user is editable, otherwise its empty )
145 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
146
147 $r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
148
149 list( $columns, $hidden ) = $this->get_column_info();
150 $action_col = false;
151
152 foreach ( $columns as $column_name => $column_display_name ) {
153 $class = 'class="'. $column_name .' column-'. $column_name .'"';
154
155 $style = '';
156 if ( in_array( $column_name, $hidden ) )
157 $style = ' style="display:none;"';
158 else if(!$action_col and !in_array($column_name, array('cb', 'id')))
159 $action_col = $column_name;
160
161 $attributes = "$class$style";
162
163 switch ( $column_name ) {
164 case 'cb':
165 $r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
166 break;
167 case 'id':
168 case 'form_key':
169 $val = $item->{$column_name};
170 break;
171 case 'name':
172 if(trim($item->{$column_name}) == '')
173 $val = __('(no title)');
174 else
175 $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
176 break;
177 case 'description':
178 $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
179 break;
180 case 'created_at':
181 $format = 'Y/m/d'; //get_option('date_format');
182 $date = date($format, strtotime($item->{$column_name}));
183 $val = "<abbr title='". date($format .' g:i:s A', strtotime($item->{$column_name})) ."'>". $date ."</abbr>";
184 break;
185 case 'shortcode':
186 $val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
187 $val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
188 break;
189 case 'entries':
190 $text = $frm_entry->getRecordCount($item->id);
191 //$text = sprintf(_n( '%1$s Entry', '%1$s Entries', $text, 'formidable' ), $text);
192 $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
193 unset($text);
194 break;
195 case 'link':
196 $links = array();
197 if($frm_vars['pro_is_installed'] and current_user_can('frm_create_entries'))
198 $links[] = '<a href="'. wp_nonce_url( "?page=formidable-entries&frm_action=new&form={$item->id}" ) .'" class="frm_add_entry_icon frm_icon_font frm_bstooltip" title="'. __('Add Entry', 'formidable'). '" data-toggle="tooltip"> </a>';
199
200 if ( current_user_can('frm_edit_forms') ){
201 $links[] = '<a href="' . wp_nonce_url( "?page=formidable&frm_action=duplicate&id={$item->id}&template=1" ) .'" class="frm_icon_font frm_new_template_icon frm_bstooltip" title="'. __('Create template from form', 'formidable') .'" data-toggle="tooltip"> </a>';
202 }
203
204 $val = implode(' ', $links);
205 break;
206 default:
207 $val = $column_name;
208 break;
209 }
210
211 if(isset($val)){
212 $r .= "<td $attributes>";
213 if($column_name == $action_col){
214 $r .= '<a class="row-title" href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'">'. $val .'</a> ';
215 $r .= $action_links;
216 }else{
217 $r .= $val;
218 }
219 $r .= '</td>';
220 }
221 unset($val);
222 }
223 $r .= '</tr>';
224
225 return $r;
226 }
227
228 }
229