PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.1
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / admin / class-admin.php

class-admin.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.1.1, at includes/admin/class-admin.php

276 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin page handler class
5 */
6 class WeForms_Admin {
7
8 public function __construct() {
9
10 add_action( 'init', array( $this, 'register_post_type' ) );
11
12 add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
13
14 add_action( 'pre_update_option_wpuf_general', array( $this, 'watch_wpuf_settings' ) );
15
16 add_filter( 'admin_post_weforms_export_forms', array( $this, 'export_forms' ) );
17 add_filter( 'admin_post_weforms_export_form_entries', array( $this, 'export_form_entries' ) );
18 }
19
20 /**
21 * Register form post types
22 *
23 * @return void
24 */
25 public function register_post_type() {
26 $capability = weforms_form_access_capability();
27
28 register_post_type( 'wpuf_contact_form', array(
29 'label' => __( 'Contact Forms', 'weforms' ),
30 'public' => false,
31 'show_ui' => true,
32 'show_in_menu' => false,
33 'capability_type' => 'post',
34 'hierarchical' => false,
35 'query_var' => false,
36 'supports' => array('title'),
37 'capabilities' => array(
38 'publish_posts' => $capability,
39 'edit_posts' => $capability,
40 'edit_others_posts' => $capability,
41 'delete_posts' => $capability,
42 'delete_others_posts' => $capability,
43 'read_private_posts' => $capability,
44 'edit_post' => $capability,
45 'delete_post' => $capability,
46 'read_post' => $capability,
47 ),
48 'labels' => array(
49 'name' => __( 'Forms', 'weforms' ),
50 'singular_name' => __( 'Form', 'weforms' ),
51 'menu_name' => __( 'Contact Forms', 'weforms' ),
52 'add_new' => __( 'Add Form', 'weforms' ),
53 'add_new_item' => __( 'Add New Form', 'weforms' ),
54 'edit' => __( 'Edit', 'weforms' ),
55 'edit_item' => __( 'Edit Form', 'weforms' ),
56 'new_item' => __( 'New Form', 'weforms' ),
57 'view' => __( 'View Form', 'weforms' ),
58 'view_item' => __( 'View Form', 'weforms' ),
59 'search_items' => __( 'Search Form', 'weforms' ),
60 'not_found' => __( 'No Form Found', 'weforms' ),
61 'not_found_in_trash' => __( 'No Form Found in Trash', 'weforms' ),
62 'parent' => __( 'Parent Form', 'weforms' ),
63 ),
64 ) );
65 }
66
67 /**
68 * Register the admin menu
69 *
70 * @return void
71 */
72 public function register_admin_menu() {
73 global $submenu;
74
75 $capability = weforms_form_access_capability();
76
77 $hook = add_menu_page( __( 'weForms - The Best Contact Form', 'weforms' ), 'weForms', $capability, 'weforms', array( $this, 'contact_form_page'), 'data:image/svg+xml;base64,' . base64_encode( '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve"><g fill="#9ea3a8"><path d="M285.1,24.1C273.1,9.4,254.8,0,234.3,0H65.7C46.6,0,29.3,8.2,17.3,21.2C6.6,32.9,0,48.5,0,65.7v60.5v108.1 C0,270.6,29.4,300,65.7,300h140h28.6c15.3,0,29.5-5.3,40.7-14.1c15.2-12,25-30.7,25-51.6V65.7C300,49.9,294.4,35.4,285.1,24.1z M212.7,187L104.6,233c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7l108.1-46.1c11.1-4.8,24,0.3,28.7,11.4 C228.9,169.3,223.8,182.2,212.7,187z M217.4,107.1L99.9,157.8c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7L200.1,67 c11.1-4.8,24,0.3,28.7,11.4v0C233.6,89.5,228.5,102.3,217.4,107.1z"/></g></svg>' ), 56 );
78
79 if ( current_user_can( $capability ) ) {
80 $submenu['weforms'][] = array( __( 'All Forms', 'weforms' ), $capability, 'admin.php?page=weforms#/' );
81 $submenu['weforms'][] = array( __( 'Tools', 'weforms' ), $capability, 'admin.php?page=weforms#/tools' );
82
83 if ( class_exists( 'WeForms_Pro' ) ) {
84 if ( current_user_can( 'manage_options' ) ) {
85 $submenu['weforms'][] = array( __( 'Modules', 'weforms' ), $capability, 'admin.php?page=weforms#/modules' );
86 }
87 } else {
88 $submenu['weforms'][] = array( __( 'Premium', 'weforms' ), $capability, 'admin.php?page=weforms#/premium' );
89 }
90
91 do_action( 'weforms-admin-menu', $hook, $capability );
92
93 $submenu['weforms'][] = array( __( 'Help', 'weforms' ), $capability, 'admin.php?page=weforms#/help' );
94 }
95
96 // only admins should see the settings page
97 if ( current_user_can( 'manage_options' ) ) {
98 $submenu['weforms'][] = array( __( 'Settings', 'weforms' ), 'manage_options', 'admin.php?page=weforms#/settings' );
99 }
100
101 add_action( 'load-'. $hook, array( $this, 'load_assets' ) );
102 }
103
104 /**
105 * Load the asset libraries
106 *
107 * @return void
108 */
109 public function load_assets() {
110 require_once dirname( __FILE__ ) . '/class-form-builder-assets.php';
111 new WeForms_Form_Builder_Assets();
112 }
113
114 /**
115 * The contact form page handler
116 *
117 * @return void
118 */
119 public function contact_form_page() {
120 require_once dirname( __FILE__ ) . '/views/vue-index.php';
121 }
122
123 /**
124 * Export forms to JSON
125 *
126 * @return void
127 */
128 public function export_forms() {
129
130 check_admin_referer( 'weforms-export-forms' );
131
132 if ( ! isset( $_REQUEST['weforms_export_forms'] ) ) {
133 return;
134 }
135
136 $export_type = isset( $_POST['export_type'] ) ? $_POST['export_type'] : 'all';
137 $selected = isset( $_POST['selected_forms'] ) ? array_map( 'absint', $_POST['selected_forms'] ) : array();
138
139 if ( ! class_exists( 'WeForms_Admin_Tools' ) ) {
140 require_once dirname( __FILE__ ) . '/class-admin-tools.php';
141 }
142
143 switch ($export_type) {
144 case 'all':
145 WeForms_Admin_Tools::export_to_json();
146 return;
147
148 case 'selected':
149 WeForms_Admin_Tools::export_to_json( $selected );
150 return;
151 }
152
153 exit;
154 }
155
156 /**
157 * Export form entries to CSV
158 *
159 * @return void
160 */
161 public function export_form_entries() {
162
163 $form_id = isset( $_REQUEST['selected_forms'] ) ? absint( $_REQUEST['selected_forms'] ) : 0;
164
165 if ( ! $form_id ) {
166 return;
167 }
168
169 $entry_array = [];
170 $columns = weforms_get_entry_columns( $form_id, false );
171 $total_entries = weforms_count_form_entries( $form_id );
172 $entries = weforms_get_form_entries( $form_id, array(
173 'number' => $total_entries,
174 'offset' => 0
175 ) );
176 $extra_columns = array(
177 'ip_address' => __( 'IP Address', 'weforms' ),
178 'created_at' => __( 'Date', 'weforms' )
179 );
180
181 $columns = array_merge( array( 'id' => 'Entry ID' ), $columns, $extra_columns );
182
183 foreach ($entries as $entry) {
184 $temp = array();
185
186 foreach ($columns as $column_id => $label) {
187 switch ( $column_id ) {
188 case 'id':
189 $temp[ $column_id ] = $entry->id;
190 break;
191
192 case 'ip_address':
193 $temp[ $column_id ] = $entry->ip_address;
194 break;
195
196 case 'created_at':
197 $temp[ $column_id ] = $entry->created_at;
198 break;
199
200 default:
201 $value = weforms_get_entry_meta( $entry->id, $column_id, true );
202 $temp[ $column_id ] = str_replace( WeForms::$field_separator, ' ', $value );
203 break;
204 }
205 }
206
207 $entry_array[] = $temp;
208 }
209
210
211 error_reporting(0);
212
213 if ( ob_get_contents() ) {
214 ob_clean();
215 }
216
217 $blogname = strtolower( str_replace( " ", "-", get_option( 'blogname' ) ) );
218 $file_name = $blogname . "-weforms-entries-" . time() . '.csv';
219
220 // force download
221 header("Content-Type: application/force-download");
222 header("Content-Type: application/octet-stream");
223 header("Content-Type: application/download");
224
225 // disposition / encoding on response body
226 header("Content-Disposition: attachment;filename={$file_name}");
227 header("Content-Transfer-Encoding: binary");
228
229 $handle = fopen("php://output", 'w');
230
231 // put the column headers
232 fputcsv( $handle, array_values( $columns ) );
233
234 // put the entry values
235 foreach ($entry_array as $row) {
236 fputcsv( $handle, $row );
237 }
238
239 fclose( $handle );
240
241 exit;
242 }
243
244 /**
245 * Watch the wpuf general settings and sync with weforms settings
246 *
247 * @param array $value
248 *
249 * @return array
250 */
251 public function watch_wpuf_settings( $settings ) {
252 $merge_array = array();
253
254 if ( isset( $settings['gmap_api_key'] ) ) {
255 $merge_array['gmap_api'] = $settings['gmap_api_key'];
256 }
257
258 if ( isset( $settings['recaptcha_public'] ) ) {
259 $recaptcha = new StdClass;
260 $recaptcha->key = $settings['recaptcha_public'];
261 $recaptcha->secret = $settings['recaptcha_private'];
262
263 $merge_array['recaptcha'] = $recaptcha;
264 }
265
266 if ( $merge_array ) {
267 $weforms_settings = get_option( 'weforms_settings', array() );
268 $weforms_settings = array_merge( $weforms_settings, $merge_array );
269
270 update_option( 'weforms_settings', $weforms_settings );
271 }
272
273 return $settings;
274 }
275 }
276