PluginProbe
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on / 1.0
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on v1.0
2.0 1.7.1 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.5 1.6 1.7 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8
import-users / admin / class-uci-admin.php

class-uci-admin.php in Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on 1.0, at admin/class-uci-admin.php

350 lines 14.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*******************************************************************************
3 * Import Users is a Tool for importing CSV for the Wordpress
4 * plugin developed by Smackcoders. Copyright (C) 2017 Smackcoders.
5 *
6 * Import Users is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License version 3
8 * as published by the Free Software Foundation with the addition of the
9 * following permission added to Section 15 as permitted in Section 7(a): FOR
10 * ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Import Users,
11 Import Users DISCLAIMS THE WARRANTY OF NON
12 * INFRINGEMENT OF THIRD PARTY RIGHTS.
13 *
14 * Import Users is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program; if not, see http://www.gnu.org/licenses or write
21 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 * You can contact Smackcoders at email address info@smackcoders.com.
25 *
26 * The interactive user interfaces in original and modified versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
29 *
30 * In accordance with Section 7(b) of the GNU Affero General Public License
31 * version 3, these Appropriate Legal Notices must retain the display of the
32 * Import Users copyright notice. If the display of the logo is
33 * not reasonably feasible for technical reasons, the Appropriate Legal
34 * Notices must display the words
35 * "Copyright Smackcoders. 2017. All rights reserved".
36 ********************************************************************************/
37
38 if ( ! defined( 'ABSPATH' ) )
39 exit; // Exit if accessed directly
40
41 include_once ( plugin_dir_path(__FILE__) . '../includes/class-uci-helper.php' );
42
43 class User_SmackUCIAdmin extends User_SmackUCIHelper {
44
45 public function __construct() {
46 self::initializing_scheduler();
47 }
48
49 public static function show_admin_menus() {
50 $is_author_can_import = get_option('USER_SM_UCI_pro_settings', null);
51 $is_author_can_import = isset($is_author_can_import['author_editor_access']) ? $is_author_can_import['author_editor_access'] : '';
52 if ( apply_filters( 'USER_SM_UCI_enable_setup_wizard', true ) && is_user_logged_in() && current_user_can( 'administrator' ) ) {
53 add_action( 'admin_menu', array( __CLASS__, 'admin_menus' ) );
54 }
55 if ( is_user_logged_in() && ( current_user_can( 'author') || current_user_can('editor') ) && $is_author_can_import == 'on' ) {
56 add_action( 'admin_menu', array( __CLASS__, 'admin_menus_for_other_roles' ) );
57 }
58 }
59
60 /**
61 * Add admin menus/screens.
62 */
63 public static function admin_menus() {
64 global $submenu;
65 add_menu_page(USER_SM_UCI_SETTINGS, USER_SM_UCI_NAME, 'manage_options', USER_SM_UCI_SLUG, array(__CLASS__, 'USER_SM_UCI_screens'),plugins_url("assets/images/wp-ultimate-csv-importer.png",dirname(__FILE__)));
66 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Dashboard', 'import-users') , 'manage_options', 'user-uci-dashboard', array(__CLASS__, 'USER_SM_UCI_screens'));
67 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Import','import-users'), 'manage_options', 'user-uci-import', array(__CLASS__, 'USER_SM_UCI_screens'));
68 //add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Managers','wp-ultimate-csv-importer'), 'manage_options', 'sm-uci-managers', array(__CLASS__, 'USER_SM_UCI_screens'));
69 //add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Export','wp-ultimate-csv-importer'), 'manage_options', 'sm-uci-export', array(__CLASS__, 'USER_SM_UCI_screens'));
70 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Settings','import-users'), 'manage_options', 'user-uci-settings', array(__CLASS__, 'USER_SM_UCI_screens'));
71 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, esc_html__('Support','impotr users'), 'manage_options', 'user-uci-support', array(__CLASS__, 'USER_SM_UCI_screens'));
72 unset($submenu[USER_SM_UCI_SLUG][0]);
73 }
74
75 public static function admin_menus_for_other_roles() {
76 global $submenu;
77 add_menu_page(USER_SM_UCI_SETTINGS, USER_SM_UCI_NAME, '2', USER_SM_UCI_SLUG, array(__CLASS__, 'USER_SM_UCI_screens'),plugins_url("assets/images/wp-ultimate-csv-importer.png",dirname(__FILE__)));
78 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, 'Dashboard', '2', 'user-uci-dashboard', array(__CLASS__, 'USER_SM_UCI_screens'));
79 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, 'Import', '2', 'user-uci-import', array(__CLASS__, 'USER_SM_UCI_screens'));
80 //add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, 'Managers', '2', 'sm-uci-managers', array(__CLASS__, 'USER_SM_UCI_screens'));
81 //add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, 'Export', '2', 'sm-uci-export', array(__CLASS__, 'USER_SM_UCI_screens'));
82 add_submenu_page(USER_SM_UCI_SLUG, USER_SM_UCI_NAME, 'Support', '2', 'user-uci-support', array(__CLASS__, 'USER_SM_UCI_screens'));
83 unset($submenu[USER_SM_UCI_SLUG][0]);
84 }
85
86 public static function USER_SM_UCI_screens() {
87 global $uci_user_admin;
88 $uci_user_admin->show_top_navigation_menus();
89 switch (sanitize_title($_REQUEST['page'])) {
90 case 'user-uci-dashboard':
91 $uci_user_admin->show_uci_dashboard();
92 break;
93 case 'user-uci-import':
94 $uci_user_admin->show_import_screen();
95 break;
96 case 'user-uci-settings':
97 $uci_user_admin->show_settings_screen();
98 break;
99 case 'user-uci-support':
100 $uci_user_admin->show_support_screen();
101 break;
102 default:
103 break;
104 }
105 return false;
106 }
107
108 public function show_top_navigation_menus() {
109 echo '<div class="menu_bar import-users">
110 <h2 class="nav-tab-wrapper">
111 <a href="'. esc_url (admin_url() .'admin.php?page=user-uci-dashboard') .'" class="nav-tab nav-tab-active" id = "menu1">'.esc_html__('Dashboard','wp-ultimate-csv-importer').'</a>
112 <a href="'. esc_url (admin_url() .'admin.php?page=user-uci-import') . '" class="nav-tab" id = "menu2">'.esc_html__('Import','wp-ultimate-csv-importer').'</a>
113 <a href="'. esc_url (admin_url() .'admin.php?page=user-uci-settings') . '" class="nav-tab" id = "menu5">'.esc_html__('Settings','wp-ultimate-csv-importer').'</a>
114 <a href="'. esc_url (admin_url() .'admin.php?page=user-uci-support') . '" class="nav-tab" id = "menu6">'.esc_html__('Support','wp-ultimate-csv-importer').'</a>
115 </h2>
116 </div>
117 <div id="notification_wp_csv"></div>';
118 $myDir = USER_SM_UCI_DEFAULT_UPLOADS_DIR;
119 if(is_dir($myDir)) {
120 echo "<input type='hidden' id='is_found' name='is_found' value='dir found'/>";
121 } else {
122 echo "<input type='hidden' id='is_found' name='is_found' value='dir not found'/>";
123 } if(is_writable($myDir)) {
124 echo "<input type='hidden' id='is_perm_found' name='is_perm_found' value='perm found'/>";
125 } else {
126 echo "<input type='hidden' id='is_perm_found' name='is_perm_found' value='perm not found'/>";
127 }
128
129 }
130
131 public function show_import_screen() {
132 global $uci_user_admin;
133 $parserObj = new User_SmackCSVParser();
134 $uci_user_admin->show_notices($parserObj);
135 $step = isset($_REQUEST['step']) ? sanitize_title($_REQUEST['step']) : '';
136 switch ($step) {
137 case 'import_file': // Step one
138 include ( 'views/form-file-import-method.php' );
139 break;
140 case 'suggested_template':
141 # NOTE: Removed the suggested template view
142 break;
143 case 'mapping_config': // Step two
144 if(isset($_REQUEST['eventKey']) ? sanitize_key($_REQUEST['eventKey']):'' ) :
145 if(isset($_POST) && !empty($_POST)) :
146 $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
147 $parserObj->screenData = array('import_file' => $_POST);
148 update_option($_REQUEST['eventKey'], $parserObj->screenData);
149 else:
150 $parserObj->screenData = get_option($_REQUEST['eventKey']);
151 endif;
152 endif;
153 if(empty($parserObj->screenData)):
154 $parserObj->wp_session = "Your mapping configuration may lost. Please configure your mapping again!";
155 endif;
156 if(isset($_REQUEST['mapping_type'])) {
157 $mapping_type = $_REQUEST['mapping_type'];
158 } else {
159 $mapping_type = '';
160 }
161 switch($mapping_type) {
162 case 'advanced':
163 include ( 'views/form-advanced-mapping-configuration.php' );
164 break;
165 case 'normal':
166 default:
167 include ( 'views/form-mapping-configuration.php' );
168 break;
169 }
170 break;
171 case 'media_config':
172 include ( 'views/form-media-handling.php' );
173 break;
174 case 'import_config':
175 include ( 'views/form-import-configuration.php' );
176 break;
177 case 'confirm':
178 include ( 'views/form-ignite-import.php' );
179 break;
180 default:
181 include ( 'views/form-file-import-method.php' );
182 break;
183 }
184 return true;
185 }
186
187 public function show_manager_screen() {
188 // include ('views/form-manager-view.php' );
189 // return true;
190 }
191
192 public function show_uci_dashboard() {
193 include ('views/form-dashboard-view.php');
194 }
195
196 public function show_export_screen() {
197 //include ( 'views/form-export-data.php' );
198 }
199
200 public function show_settings_screen() {
201 include ('views/form-settings-view.php' );
202 return true;
203 }
204
205 public function show_support_screen() {
206 include ('views/form-support-view.php' );
207 return true;
208 }
209
210
211 public function show_notices($parseObj) {
212
213 }
214
215 public static function PieChart(){
216 echo '<canvas id="uci_pro_pieStats"></canvas>';
217 }
218
219 public static function LineChart(){
220 echo '<canvas id="uci_pro_lineStats" style="height:250px;"></canvas>';
221 }
222
223 public function get_mapping_widgets_order ($import_type) {
224 $widgets = array();
225 global $uci_user_admin;
226 $customposts = $uci_user_admin->get_import_custom_post_types();
227 if (in_array($import_type, get_taxonomies())) {
228 $import_type = 'Taxonomies';
229 }
230 if (in_array($import_type, $customposts)) {
231 $import_type = 'CustomPosts';
232 }
233 switch ($import_type) {
234
235 case 'Users':
236 $widgets = array('Core Fields','WordPress Custom Fields', 'Custom Fields by WP-Members', 'Billing And Shipping Information',
237 'ACF Pro Fields', 'ACF Fields', 'ACF Repeater Fields', 'Types Custom Fields', 'PODS Custom Fields', 'CCTM Custom Fields');
238 break;
239
240 }
241 return $widgets;
242 }
243
244 public function available_widgets ($import_type, $importAs) {
245 global $uci_user_admin;
246 $widgets = array();
247 $widgets_order = $uci_user_admin->get_mapping_widgets_order($import_type);
248 $supported_widgets = $uci_user_admin->get_available_widgets($import_type, $importAs);
249 if(!empty($widgets_order) && !empty($supported_widgets)) :
250 foreach($widgets_order as $item) {
251 # TODO: Need to check whether this item (widget) to be related with the $import_type
252 if(array_key_exists($item, $supported_widgets)) :
253 $widgets[$item] = $supported_widgets[$item];
254 endif;
255 }
256 endif;
257 return $widgets;
258 }
259
260 public function get_available_widgets ($import_type, $importAs) {
261 $possible_widgets = array();
262 global $uci_user_admin;
263 $customposts = $uci_user_admin->get_import_custom_post_types();
264 if (in_array($import_type, $customposts)) {
265 $import_type = 'CustomPosts';
266 }
267 if (in_array($import_type, get_taxonomies())) {
268 $import_type = 'Taxonomies';
269 }
270 $possible_widgets['Core Fields'] = 'CORE';
271 if($import_type == 'Posts' || $import_type == 'Pages' || $import_type == 'CustomPosts' ||
272 $import_type == 'WooCommerce' || $import_type == 'MarketPress' || $import_type == 'WPeCommerce' || $import_type == 'eShop' || $import_type == 'Users') {
273 $possible_widgets['WordPress Custom Fields'] = 'CORECUSTFIELDS';
274 }
275 $active_plugins = $this->get_active_plugins();
276 if(!empty($active_plugins)) {
277 foreach($active_plugins as $plugin) {
278 switch ($plugin) {
279
280 case 'wp-members/wp-members.php':
281 if($import_type == 'Users') {
282 $possible_widgets['Custom Fields by WP-Members'] = 'WPMEMBERS';
283 }
284 break;
285
286 }
287 }
288 if($import_type == 'Users') {
289 if( in_array('marketpress/marketpress.php', $this->get_active_plugins()) || in_array('wordpress-ecommerce/marketpress.php', $this->get_active_plugins()) || in_array('woocommerce/woocommerce.php', $this->get_active_plugins()) ) {
290 $possible_widgets['Billing And Shipping Information'] = 'BSI';
291 }
292 }
293 if($import_type != 'Pages')
294 $possible_widgets['Terms and Taxonomies'] = 'TERMS';
295 }
296 return $possible_widgets;
297 }
298
299 public function get_widget_fields($widget_name, $import_type, $importAs, $mode = null) {
300 $fields = array();
301 switch ($widget_name) {
302 case 'Core Fields':
303 $fields = $this->coreFields($import_type);
304 break;
305
306
307 case 'Billing And Shipping Information':
308 $fields = $this->billing_information_for_users();
309 break;
310
311 case 'Custom Fields by WP-Members':
312 $fields = $this->custom_fields_by_wp_members();
313 break;
314 case 'Custom Fields by Ultimate Member':
315 $fields = $this->custom_fields_by_ultimate_member();
316 break;
317 }
318 return $fields;
319 }
320
321 public function get_available_groups($type) {
322 $groups = array();
323 if ($type == 'Posts') {
324 $groups = array('CORE', 'CCTM', 'ACF', 'RF', 'TYPES', 'PODS', 'AIOSEO', 'YOASTSEO', 'CORECUST', 'TERMS', 'TAXO');
325 }
326 if ($type == 'Pages') {
327 $groups = array('CORE', 'CCTM', 'ACF', 'RF', 'TYPES', 'PODS', 'AIOSEO', 'YOASTSEO', 'CORECUST', 'TAXO');
328 }
329 if ($type == 'WooCommerce') {
330 $groups = array('CORE', 'CCTM', 'ACF', 'RF', 'TYPES', 'PODS', 'AIOSEO', 'YOASTSEO', 'ECOMMETA', 'CORECUST', 'TERMS', 'TAXO');
331 }
332 return $groups;
333 }
334
335 public static function initializing_scheduler() {
336 if( !wp_next_scheduled( 'smack_uci_image_scheduler' )) {
337 wp_schedule_event(time(), 'wp_ultimate_csv_importer_scheduled_images', 'smack_uci_image_scheduler');
338 }
339 if( !wp_next_scheduled( 'smack_uci_email_scheduler' )) {
340 wp_schedule_event(time(), 'wp_ultimate_csv_importer_scheduled_emails', 'smack_uci_email_scheduler');
341 }
342 if( !wp_next_scheduled( 'smack_uci_replace_inline_images' )) {
343 wp_schedule_event(time(), 'wp_ultimate_csv_importer_replace_inline_images', 'smack_uci_replace_inline_images');
344 }
345 }
346 }
347 add_action('init', array('User_SmackUCIAdmin', 'show_admin_menus'));
348 global $uci_user_admin;
349 $uci_user_admin = new User_SmackUCIAdmin();
350