Ultimate CSV Importer - Version 3.0.0

Version Description

Download this release

Release Info

Developer smackcoders
Plugin Icon 128x128 Ultimate CSV Importer
Version 3.0.0
Comparing to
See all releases

Code changes from version 2.7.0 to 3.0.0

Readme.txt CHANGED
@@ -1,37 +1,52 @@
1
  === WP Ultimate CSV Importer Plugin ===
2
- Contributors: Smackcoders
3
  Donate link: http://www.smackcoders.com/donate.html
4
  Tags: batch, excel, import, spreadsheet, plugin, admin, csv, importer,
5
  Requires at least: 3.4
6
  Tested up to: 3.5.1
7
- Stable tag: 2.7.0
8
- Version: 2.7.0
9
- Author: Smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
  License: GPLv2 or later
12
 
13
- A plugin that helps to import any csv file as post, page or custom post data's by matching csv headers to wp fields.
14
 
15
 
16
  == Description ==
17
 
18
- WP Ultimate CSV Importer Plugin helps you to import any csv file as post, page or even as custom post data's by matching its headers to relevant fields or custom fields.
 
19
 
20
- 1. Admin can import the data's from any csv file.
21
- 2. Can define the type of post and post status while importing.
22
- 3. Provides header mapping feature to import the data's as your need.
23
- 4. Users can map column headers to existing fields or assign as custom fields.
24
- 5. Import unlimited data as post.
25
- 6. Make imported post as published or make it as draft.
26
- 7. Added featured image import functionality.
27
 
28
- The pro version of this plugin is available now with lot more new features, functionalities, controls and usability. Please upgrade to pro version to enjoy the powerful features like importing nested categories, WP-e-commerce products, eShop products, custom taxonomies in bulk with simple clicks.
29
 
30
- Important Note: To import your posts for scheduled publishing in future, have a date coloumn in your csv with the date of post to be published on. If the date is a future date, then the post will be automatically scheduled for publishing on particular date as mentioned in csv.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- Note: Your theme should support featured image function. If not, please add the following code to header.php or where it needed.
33
- add_theme_support( 'post-thumbnails' );
34
 
 
 
 
 
 
 
35
  You can follow the instructions as given here
36
  [http://codex.wordpress.org/Function_Reference/the_post_thumbnail](http://codex.wordpress.org/Function_Reference/the_post_thumbnail)
37
  [http://codex.wordpress.org/Post_Thumbnails](http://codex.wordpress.org/Post_Thumbnails) [http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5](http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5)
@@ -40,26 +55,19 @@ Posts and Pages Module - This module will import all your data into bulk posts o
40
 
41
  Custom posts - Similar to post and pages you can import any custom post types that is configured in your WordPress. You can also assign feature image for each post created.
42
 
43
- For more powerful features upgrade to pro version of ultimate csv importer plugin have many more features like
44
-
45
- Category - You can import any number category you want. Category name fields are mandatory. Slug and description field is optional. Slugs are created automatically if not mapped.
46
-
47
- Nested category - This module is just like category module, provided you can import nested categories. You can import nested categories through name field like category1 | category2 | category3. If the category doesn't exist it will be created in a hierarchy as mention in name field.
48
 
49
- Tags - Import bulk tags using this module and assign to post, custom post or products.
50
-
51
- Users with roles - Import bulk users with their roles by role id. There 11 fields to map in which user login, email and role are mandatory fields. Roles are mentioned in CSV as ids. Please ensure roles are created in advance before import. Other wise default role is assigned for missing role ids.
52
-
53
- Custom taxonomy - Is your Wordpress is configured for custom taxonomy, you can import bulk custom taxonomies as like as nested categories.
54
-
55
- WP Commerce/ eshop - You can import products in bulk if these modules are installed in your Wordpress.
56
 
57
 
58
  Support and Feature request.
59
  ----------------------------
60
 
61
  Please create issues only in our tracker http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free/issues instead of WordPress support forum.
62
-
63
  For guides and tutorials, visit http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free .
64
 
65
 
@@ -67,8 +75,8 @@ For guides and tutorials, visit http://forge.smackcoders.com/projects/wp-ultimat
67
  == Installation ==
68
 
69
 
70
- Please click here for [Detailed Installation Instructions](http://www.smackcoders.com/blog/category/free-wordpress-plugins/wordpress-ultimate-csv-importer-plugin/)
71
-
72
 
73
 
74
  == Screenshots ==
@@ -79,6 +87,25 @@ Please click here for [Detailed Installation Instructions](http://www.smackcoder
79
 
80
 
81
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  = 2.7.0 = Post Status
84
  -- Added more post status options
@@ -136,11 +163,13 @@ Please click here for [Detailed Installation Instructions](http://www.smackcoder
136
 
137
  == Upgrade Notice ==
138
 
139
- =v 2.7.0 = Major improvements and feature changes.
 
 
140
 
141
- =v 2.6.0 = Bug fixed and should upgrade.
142
 
143
- =v 2.5.0 = Issues fixed and updated to WordPress-3.5.1 compatibility.
144
  -- Duplicate detection added.
145
  -- Added more information in success message.
146
  -- Import memory issues solved.
@@ -163,6 +192,20 @@ Please click here for [Detailed Installation Instructions](http://www.smackcoder
163
 
164
 
165
  == Frequently Asked Questions ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  Please click here for [ Detailed Frequently Asked Questions](http://www.smackcoders.com/blog/category/free-wordpress-plugins/wordpress-ultimate-csv-importer-plugin/)
168
 
1
  === WP Ultimate CSV Importer Plugin ===
2
+ Contributors: smackcoders
3
  Donate link: http://www.smackcoders.com/donate.html
4
  Tags: batch, excel, import, spreadsheet, plugin, admin, csv, importer,
5
  Requires at least: 3.4
6
  Tested up to: 3.5.1
7
+ Stable tag: 3.0.0
8
+ Version: 3.0.0
9
+ Author: smackcoders
10
  Author URI: http://profiles.wordpress.org/smackcoders/
11
  License: GPLv2 or later
12
 
13
+ A plugin that turns your offline data as wordpress post, page or custom post data's by simple mapping feature as csv file import.
14
 
15
 
16
  == Description ==
17
 
18
+ Version 3.0.0 is out now. So many major improvement changes,
19
+ more flexible import options and added powerful features.
20
 
21
+ WP Ultimate CSV Importer Plugin helps you to import any CSV file as post, page or even as custom post type. Convert your offline database maintained for years into your valuable website content. Also do periodical content changes, maintenance, content update, prices, offers, coupons and inventory etc.
 
 
 
 
 
 
22
 
23
+ This simple but ultimate plugin as you can import everything needed to create as any WP post types from admin as simple as CSV file. Just in few clicks to map your CSV data set to match the Wordpress fields to import. That�s all, now your imports are turned as Wordpress site content in matter of seconds. No more pain of creating post content one by one of converting your offline data. You can import all the essential data as Wordpress post and skip unwanted things. Or you can import as many as custom fields without missing even a single data. Provided you should have a theme that supports custom fields. So you can now make use of your offline data, inventory, price catalog, information data, database and any other excel data sheet for online content distribution to your valuable visitor or customers.
24
 
25
+ 1. Admin can import the data's from any CSV file.
26
+ 2. Can import as post, page or custom post.
27
+ 3. Compatible with Custom post type UI plugin support
28
+ 4. Can define the type of post and post status while importing.
29
+ 5. Powerful mapping feature enable importing the data's as perfect Wordpress post types.
30
+ 6. Users can map column headers to existing fields or create and assign as unlimited custom fields.
31
+ 7. Import unlimited data as any post type.
32
+ 8. Make imported post as published, private, pending, draft, sticky or even as password protected.
33
+ 9. Define different post status for every individual post via CSV.
34
+ 10. Add featured image Url to every post.
35
+ 11. Assign authors to every post.
36
+ 12. Add title, content, excerpt and slug to posts
37
+ 13. Assign multiple tags and categories to post
38
+ 14. Non existing tags and categories are created automatically
39
+ 15. Assign date of publishing either a previous date or futures date for scheduled publishing.
40
+ 16. Skip Duplicate titles or content or both to avoid duplicates at time of import itself
41
+ 17. Only option we missed is post format, will be added in next major update.
42
 
 
 
43
 
44
+ <p>http://www.youtube.com/embed/OwKdt_NlT2U?list=PL2k3Ck1bFtbQqFhOK7g08kxENI4qQkmC-</p>
45
+
46
+
47
+ Important Notes:
48
+ You can schedule your post for future publishing automatically by mentioning futuredate and time in date field of partcular post in your csv file.
49
+ Your theme should support featured image function. If not, please add the following code to header.php or where you need to diplay. add_theme_support( 'post-thumbnails' );
50
  You can follow the instructions as given here
51
  [http://codex.wordpress.org/Function_Reference/the_post_thumbnail](http://codex.wordpress.org/Function_Reference/the_post_thumbnail)
52
  [http://codex.wordpress.org/Post_Thumbnails](http://codex.wordpress.org/Post_Thumbnails) [http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5](http://wordpress.org/support/topic/featured-image-not-showing-7?replies=5)
55
 
56
  Custom posts - Similar to post and pages you can import any custom post types that is configured in your WordPress. You can also assign feature image for each post created.
57
 
58
+ The pro version of this plugin is available now with lot more new features, functionalities, controls and improved usability. Please upgrade to pro version to enjoy the powerful features like importing nested categories, WP-e-commerce products, eShop products, custom taxonomies in bulk with simple clicks.For more powerful features upgrade to pro version of ultimate csv importer plugin have many more features like
 
 
 
 
59
 
60
+ One click Import of Nested category with complex hierarchies to any no. of levels with proper description and seo slugs
61
+ One click Import of bulk tags with proper description and seo slugs
62
+ One click Import of Users with roles
63
+ One click Import of Custom taxonomies with proper description and seo slugs
64
+ Import, update and maintain your WP Commerce / eshop inventory, prices, periodical and short term offers, coupons, bonus etc.
 
 
65
 
66
 
67
  Support and Feature request.
68
  ----------------------------
69
 
70
  Please create issues only in our tracker http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free/issues instead of WordPress support forum.
 
71
  For guides and tutorials, visit http://forge.smackcoders.com/projects/wp-ultimate-csv-importer-free .
72
 
73
 
75
  == Installation ==
76
 
77
 
78
+ Please click here for [Detailed Installation Instructions](http://www.smackcoders.com/blog/how-to-guide-for-free-wordpress-ultimate-csv-importer-plugin.html)
79
+ Or view our hoe to guide video guide in our [Youtube Channel](www.youtube.com/user/smackcoders)
80
 
81
 
82
  == Screenshots ==
87
 
88
 
89
  == Changelog ==
90
+ = 3.0.0 = Lot of performance improvements
91
+ - Much improved workflow
92
+ - Custom Field mapping and import fixed
93
+ - Add custom field option improved.
94
+ - Date format handling improved
95
+ - Any Date format is supported now
96
+ - Future scheduling and status improved
97
+ - Overall Status option improved and issue fixed
98
+ - Password field fixed for Protected
99
+ - Status as in CSV option improved and fixed
100
+ - Can apply post status for individual post via csv itself
101
+ - Now password should be mentioned as {password}
102
+ - Featured image handling improved and fixed. More improvement are scheduled.
103
+ - Category in numericals are restricted and skipped to Uncategorized
104
+ - Duplicate check options improved for both title and content option.
105
+ - Post authors can be User ID or name
106
+ - Post author issue fixed and improved
107
+ - Wrong user id or name are automatically assigned under admin
108
+ - Multi category and tags improved
109
 
110
  = 2.7.0 = Post Status
111
  -- Added more post status options
163
 
164
  == Upgrade Notice ==
165
 
166
+ =v 3.0.0 = Must upgrade to have Major improvements, performance fixes and issue fixes
167
+
168
+ =v 2.7.0 = Major improvements and feature changes.
169
 
170
+ =v 2.6.0 = Bug fixed and should upgrade.
171
 
172
+ =v 2.5.0 = Issues fixed and updated to WordPress-3.5.1 compatibility.
173
  -- Duplicate detection added.
174
  -- Added more information in success message.
175
  -- Import memory issues solved.
192
 
193
 
194
  == Frequently Asked Questions ==
195
+ How to Format a CSV file for WP Ultimate CSV Importer Plugin?
196
+
197
+ This video helps you to tweak/format your CSV file to make a fast, simple and easy import using WP Ultimate CSV importer plugin without missing all the
198
+ features. We have used MS Excel as CSV editor here. You can use other applications also. Take advantage of our importer format by slightly tweaking your csv.
199
+
200
+ <p>http://www.youtube.com/watch?v=pnObJdiedus</p>
201
+
202
+ For more details visit www.smackcoders.com
203
+
204
+ How to creat a well formatted csv? - the other way to learn tweaking
205
+
206
+ We have used text editor here to explain how to create a well formatted csv in seconds for importing. You can use this format to take advantage of our importer format by slightly tweaking your csv. This video helps you to tweak/format your CSV file to make a fast, simple and easy import using WP Ultimate CSV importer plugin without missing all the features.
207
+
208
+ <p>http://www.youtube.com/watch?v=9W_my0rSybE</p>
209
 
210
  Please click here for [ Detailed Frequently Asked Questions](http://www.smackcoders.com/blog/category/free-wordpress-plugins/wordpress-ultimate-csv-importer-plugin/)
211
 
SmackImpCE.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author fenzik
4
+ * Common class for Smackcoder's CSV Importer CE
5
+ */
6
+ require_once ("SmackWpHandler.php");
7
+ class SmackImpCE extends SmackWpHandler {
8
+
9
+ // @var string CSV upload directory name
10
+ public $uploadDir = 'ultimate_importer';
11
+
12
+ // @var boolean post title check
13
+ public $titleDupCheck = false;
14
+
15
+ // @var boolean content title check
16
+ public $conDupCheck = false;
17
+
18
+ // @var string delimiter
19
+ public $delim = ",";
20
+
21
+ // @var array delilimters supported by CSV importer
22
+ public $delim_avail = array (
23
+ ',',
24
+ ';'
25
+ );
26
+
27
+ // @var array wp field keys
28
+ public $keys = array ();
29
+
30
+ // @var array for default columns
31
+ public $defCols = array (
32
+ 'post_title' => null,
33
+ 'post_content' => null,
34
+ 'post_excerpt' => null,
35
+ 'post_date' => null,
36
+ 'post_name' => null,
37
+ 'post_tag' => null,
38
+ 'post_category' => null,
39
+ 'post_author' => null,
40
+ 'featured_image' => null,
41
+ 'post_parent' => 0,
42
+ 'post_status' => 0
43
+ );
44
+
45
+ // @var array CSV headers
46
+ public $headers = array ();
47
+
48
+ // @var boolean for post flag
49
+ public $postFlag = false;
50
+
51
+ // @var int duplicate post count
52
+ public $dupPostCount = 0;
53
+
54
+ // @var int inserted post count
55
+ public $insPostCount = 0;
56
+
57
+ // @var int no post author count
58
+ public $noPostAuthCount = 0;
59
+
60
+ // @var string CSV file name
61
+ public $csvFileName;
62
+
63
+ /**
64
+ */
65
+ function __construct() {
66
+ $this->getKeyVals ();
67
+ }
68
+
69
+ /**
70
+ * Manage duplicates
71
+ *
72
+ * @param
73
+ * string type = (title|content), string content
74
+ */
75
+ function duplicateChecks($type = 'title', $text, $gettype) {
76
+ global $wpdb;
77
+
78
+ if ($type == 'content') {
79
+ $contentLength = strlen ( $text );
80
+ $post_exist = $wpdb->get_results ( "select ID from " . $wpdb->posts . " where length(post_content) = \"{$contentLength}\"" );
81
+ if (count ( $post_exist ) > 0) {
82
+ $chkforeach = 0;
83
+ foreach ( $post_exist as $singlepost ) {
84
+ $postdata = $wpdb->get_results ( "select post_content from " . $wpdb->posts . " where id = \"{$singlepost->ID}\"" );
85
+ if (substr ( $postdata [0]->post_content, 0, 50 ) == substr ( $text, 0, 50 )) {
86
+ $this->dupPostCount ++;
87
+ return false;
88
+ }
89
+ }
90
+ } else {
91
+ return true;
92
+ }
93
+ } else if ($type == 'title') {
94
+ $post_exist = $wpdb->get_results ( "select ID from " . $wpdb->posts . " where post_title = \"{$text}\" and post_type = \"{$gettype}\" and post_status in('publish','future','draft','pending','private')" );
95
+ if (count ( $post_exist ) == 0 && ($text != null || $text != ''))
96
+ return true;
97
+ }
98
+ $this->dupPostCount ++;
99
+ return false;
100
+ }
101
+
102
+ /**
103
+ * Get upload directory
104
+ */
105
+ function getUploadDirectory() {
106
+ $upload_dir = wp_upload_dir ();
107
+ return $upload_dir ['basedir'] . "/" . $this->uploadDir;
108
+ }
109
+
110
+ /**
111
+ * Move CSV to the upload directory
112
+ */
113
+ function move_file() {
114
+ if ($_FILES ["csv_import"] ["error"] == 0) {
115
+ $tmp_name = $_FILES ["csv_import"] ["tmp_name"];
116
+ $this->csvFileName = $_FILES ["csv_import"] ["name"];
117
+ move_uploaded_file ( $tmp_name, $this->getUploadDirectory () . "/$this->csvFileName" );
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Remove CSV file
123
+ */
124
+ function fileDelete($filepath, $filename) {
125
+ if (file_exists ( $filepath . $filename ) && $filename != "" && $filename != "n/a") {
126
+ unlink ( $filepath . $filename );
127
+ return TRUE;
128
+ }
129
+ return FALSE;
130
+ }
131
+
132
+ /**
133
+ * Get field colum keys
134
+ */
135
+ function getKeyVals() {
136
+ global $wpdb;
137
+ $limit = ( int ) apply_filters ( 'postmeta_form_limit', 30 );
138
+ $this->keys = $wpdb->get_col ( "SELECT meta_key FROM $wpdb->postmeta
139
+ GROUP BY meta_key
140
+ HAVING meta_key NOT LIKE '\_%'
141
+ ORDER BY meta_key
142
+ LIMIT $limit" );
143
+
144
+ foreach ( $this->keys as $val ) {
145
+ $this->defCols ["CF: " . $val] = $val;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Check upload dirctory permission
151
+ */
152
+ function checkUploadDirPermission() {
153
+ $this->getUploadDirectory ();
154
+ $upload_dir = wp_upload_dir ();
155
+ if (! is_dir ( $upload_dir ['basedir'] )) {
156
+ print " <div style='font-size:16px;margin-left:20px;margin-top:25px;'>" . $this->t ( "UPLOAD_PERMISSION_ERROR" ) . "
157
+ </div><br/>
158
+ <div style='margin-left:20px;'>
159
+ <form class='add:the-list: validate' method='post' action=''>
160
+ <input type='submit' class='button-primary' name='Import Again' value='" . $this->t ( "IMPORT_AGAIN" ) . "'/>
161
+ </form>
162
+ </div>";
163
+ $this->freeze ();
164
+ } else {
165
+ if (! is_dir ( $this->getUploadDirectory () )) {
166
+ wp_mkdir_p ( $this->getUploadDirectory () );
167
+ }
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Function converts CSV data to formatted array.
173
+ *
174
+ * @param $file CSV
175
+ * input filename
176
+ * @param $delim delimiter
177
+ * for the CSV
178
+ * @return array formatted CSV output as array
179
+ */
180
+ function csv_file_data($file, $delim) {
181
+ $this->checkUploadDirPermission ();
182
+ ini_set ( "auto_detect_line_endings", true );
183
+
184
+ $data_rows = array ();
185
+ $resource = fopen ( $file, 'r' );
186
+
187
+ $init = 0;
188
+ while ( $keys = fgetcsv ( $resource, '', $this->delim, '"' ) ) {
189
+ if ($init == 0) {
190
+ $this->headers = $keys;
191
+ } else {
192
+ array_push ( $data_rows, $keys );
193
+ }
194
+ $init ++;
195
+ }
196
+ fclose ( $resource );
197
+ ini_set ( "auto_detect_line_endings", false );
198
+ return $data_rows;
199
+ }
200
+
201
+ /**
202
+ * function to map the csv file and process it
203
+ *
204
+ * @return boolean
205
+ */
206
+ function processDataInWP() {
207
+ global $wpdb;
208
+
209
+ $smack_taxo = array ();
210
+ $custom_array = array ();
211
+
212
+ $data_rows = $this->csv_file_data ( $this->getUploadDirectory () . "/" . $_POST ['filename'], $this->delim );
213
+
214
+ foreach ( $_POST as $postkey => $postvalue ) {
215
+ if ($postvalue != '-- Select --') {
216
+ $ret_array [$postkey] = $postvalue;
217
+ }
218
+ }
219
+
220
+ foreach ( $data_rows as $key => $value ) {
221
+
222
+ for($i = 0; $i < count ( $value ); $i ++) {
223
+ if (array_key_exists ( 'mapping' . $i, $ret_array )) {
224
+ if ($ret_array ['mapping' . $i] != 'add_custom' . $i) {
225
+ $strip_CF = strpos($ret_array['mapping'.$i],'CF: ');
226
+ if($strip_CF === 0){
227
+ $custom_key = substr($ret_array['mapping'.$i], 4);
228
+ $custom_array[$custom_key] = $value[$i];
229
+ }
230
+ else{
231
+ $new_post[$ret_array['mapping'.$i]] = $value[$i];
232
+ }
233
+
234
+ } else {
235
+ $new_post [$ret_array ['textbox' . $i]] = $value [$i];
236
+ $custom_array [$ret_array ['textbox' . $i]] = $value [$i];
237
+ }
238
+ }
239
+ }
240
+ for($inc = 0; $inc < count ( $value ); $inc ++) {
241
+ foreach ( $this->keys as $k => $v ) {
242
+ if (array_key_exists ( $v, $new_post )) {
243
+ $custom_array [$v] = $new_post [$v];
244
+ }
245
+ }
246
+ }
247
+
248
+ foreach ( $new_post as $ckey => $cval ) {
249
+ $this->postFlag = true;
250
+ $taxo = get_taxonomies ();
251
+ foreach ( $taxo as $taxokey => $taxovalue ) {
252
+ if ($taxokey != 'category' && $taxokey != 'link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format') {
253
+ if ($taxokey == $ckey) {
254
+ $smack_taxo [$ckey] = $new_post [$ckey];
255
+ }
256
+ }
257
+ }
258
+ if ($ckey != 'post_category' && $ckey != 'post_tag' && $ckey != 'featured_image' && $ckey != $smack_taxo [$ckey]) {
259
+ if (array_key_exists ( $ckey, $custom_array )) {
260
+ $darray [$ckey] = $new_post [$ckey];
261
+ } else {
262
+ if (array_key_exists ( $ckey, $smack_taxo )) {
263
+ } else {
264
+ $data_array [$ckey] = $new_post [$ckey];
265
+ }
266
+ }
267
+ } else {
268
+
269
+ switch ($ckey) {
270
+ case 'post_tag' :
271
+ $tags [$ckey] = $new_post [$ckey];
272
+ break;
273
+ case 'post_category' :
274
+ $categories [$ckey] = $new_post [$ckey];
275
+ break;
276
+ case 'featured_image' :
277
+ /*
278
+ * TODO: Cleanup required
279
+ */
280
+ $split_filename = explode ( '/', htmlentities ( $new_post [$ckey] ) );
281
+ $arr_filename = count ( $split_filename );
282
+ $plain_filename = $split_filename [$arr_filename - 1];
283
+ $new_post [$ckey] = str_replace ( ' ', '%20', $new_post [$ckey] );
284
+ $file_url = $filetype [$ckey] = $new_post [$ckey];
285
+ $file_type = explode ( '.', $filetype [$ckey] );
286
+ $count = count ( $file_type );
287
+ $type = $file_type [$count - 1];
288
+ if ($type == 'png') {
289
+ $file ['post_mime_type'] = 'image/png';
290
+ } else if ($type == 'jpg' || $type == 'jpeg') {
291
+ $file ['post_mime_type'] = 'image/jpeg';
292
+ } else if ($type == 'gif') {
293
+ $file ['post_mime_type'] = 'image/gif';
294
+ }
295
+ $img_name = explode ( '/', $file_url );
296
+ $imgurl_split = count ( $img_name );
297
+ $img_name = explode ( '.', $img_name [$imgurl_split - 1] );
298
+ $img_title = $img_name = $img_name [0];
299
+ $dir = wp_upload_dir ();
300
+ $dirname = 'featured_image';
301
+ $full_path = $dir ['basedir'] . '/' . $dirname;
302
+ $baseurl = $dir ['baseurl'] . '/' . $dirname;
303
+ $filename = explode ( '/', $file_url );
304
+ $file_split = count ( $filename );
305
+ $filepath = $full_path . '/' . $plain_filename;
306
+ $fileurl = $baseurl . '/' . $filename [$file_split - 1];
307
+ if(is_dir($full_path)){
308
+ $smack_fileCopy = copy($file_url,$filepath);
309
+ }
310
+ else{
311
+ wp_mkdir_p($full_path);
312
+ $smack_fileCopy = copy($file_url,$filepath);
313
+ }
314
+ if ($smack_fileCopy) {
315
+ $file ['guid'] = $fileurl;
316
+ $file ['post_title'] = $img_title;
317
+ $file ['post_content'] = '';
318
+ $file ['post_status'] = 'inherit';
319
+ } else {
320
+ $file = false;
321
+ }
322
+ break;
323
+ }
324
+ }
325
+ }
326
+
327
+ $data_array['post_type'] = $_POST['csv_importer_cat'];
328
+
329
+ if ($this->titleDupCheck)
330
+ $this->postFlag = $this->duplicateChecks ( 'title', $data_array ['post_title'], $data_array ['post_type'] );
331
+
332
+ if ($this->conDupCheck && $this->postFlag)
333
+ $this->postFlag = $this->duplicateChecks ( 'content', $data_array ['post_content'], '' );
334
+
335
+ if ($this->postFlag) {
336
+ unset ( $sticky );
337
+ if($_POST['importallwithps'] != 0)
338
+ $data_array['post_status'] = $_POST['importallwithps'];
339
+ switch ($data_array ['post_status']) {
340
+ case 1 :
341
+ $data_array['post_status'] = 'publish';
342
+ break;
343
+ case 2 :
344
+ $data_array['post_status'] = 'publish';
345
+ $sticky = true;
346
+ break;
347
+ case 3 :
348
+ $data_array['post_status'] = 'publish';
349
+ $data_array ['post_password'] = $_POST ['postsPassword'];
350
+ break;
351
+ case 4 :
352
+ $data_array ['post_status'] = 'private';
353
+ break;
354
+ case 5 :
355
+ $data_array ['post_status'] = 'draft';
356
+ break;
357
+ case 6 :
358
+ $data_array ['post_status'] = 'pending';
359
+ break;
360
+ default :
361
+ $poststatus = $data_array['post_status'] = strtolower( $data_array['post_status'] );
362
+ if($data_array['post_status'] != 'publish' && $data_array['post_status'] != 'private' && $data_array['post_status'] != 'draft' && $data_array['post_status'] != 'pending' && $data_array['post_status'] != 'sticky'){
363
+ $stripPSF = strpos($data_array['post_status'],'{');
364
+ if($stripPSF === 0){
365
+ $poststatus = substr($data_array['post_status'], 1);
366
+ $stripPSL = substr($poststatus, -1);
367
+ if($stripPSL == '}'){
368
+ $postpwd = substr($poststatus,0, -1);
369
+ $data_array['post_status'] = 'publish';
370
+ $data_array ['post_password'] = $postpwd;
371
+ }
372
+ else{
373
+ $data_array['post_status'] = 'publish';
374
+ $data_array ['post_password'] = $poststatus;
375
+ }
376
+ }
377
+ else{
378
+ $data_array['post_status'] = 'publish';
379
+ }
380
+ }
381
+ if($data_array['post_status'] == 'sticky'){
382
+ $data_array['post_status'] = 'publish';
383
+ $sticky = true;
384
+ }
385
+
386
+ }
387
+ // Author name/id update
388
+ $authorLen = strlen($data_array ['post_author']);
389
+ $postuserid = $data_array ['post_author'];
390
+ $checkpostuserid = intval($data_array ['post_author']);
391
+ $postAuthorLen = strlen($checkpostuserid);
392
+
393
+ if($authorLen == $postAuthorLen){
394
+ $postauthor = $wpdb->get_results ( "select ID from $wpdb->users where ID = \"{$postuserid}\"" );
395
+ }
396
+ else{
397
+ $postauthor = $wpdb->get_results ( "select ID from $wpdb->users where user_login = \"{$postuserid}\"" );
398
+ }
399
+
400
+ if (! $postauthor [0]->ID) {
401
+ $data_array ['post_author'] = 1;
402
+ $this->noPostAuthCount ++;
403
+ } else {
404
+ $data_array ['post_author'] = $postauthor [0]->ID;
405
+ }
406
+
407
+ // Date format post
408
+ if (! $data_array ['post_date'])
409
+ $data_array ['post_date'] = date ( 'Y-m-d H:i:s' );
410
+ $data_array ['post_date'] = date ( 'Y-m-d H:i:s', strtotime ( $data_array ['post_date'] ) );
411
+ if ($data_array)
412
+ $post_id = wp_insert_post ( $data_array );
413
+ unset($data_array);
414
+ unset($postauthor);
415
+ if ($post_id) {
416
+ $this->insPostCount ++;
417
+ if ($sticky)
418
+ stick_post ( $post_id );
419
+
420
+ if (! empty ( $custom_array )) {
421
+ foreach ( $custom_array as $custom_key => $custom_value ) {
422
+ add_post_meta ( $post_id, $custom_key, $custom_value );
423
+ }
424
+ }
425
+
426
+ // Create custom taxonomy to post
427
+ if (! empty ( $smack_taxo )) {
428
+ foreach ( $smack_taxo as $taxo_key => $taxo_value ) {
429
+ $split_line = explode ( '|', $taxo_value );
430
+ wp_set_object_terms ( $post_id, $split_line, $taxo_key );
431
+ }
432
+ }
433
+
434
+ // Create/Add tags to post
435
+ if (! empty ( $tags )) {
436
+ foreach ( $tags as $tag_key => $tag_value ) {
437
+ wp_set_post_tags ( $post_id, $tag_value );
438
+ }
439
+ }
440
+
441
+ // Create/Add category to post
442
+ if (! empty ( $categories )) {
443
+ $split_cate = explode ( '|', $categories ['post_category'] );
444
+ foreach ( $split_cate as $key => $val ) {
445
+ if (is_numeric ( $val ))
446
+ $split_cate[$key] = 'uncategorized';
447
+ }
448
+ wp_set_object_terms ( $post_id, $split_cate, 'category' );
449
+ }
450
+ // Add featured image
451
+ if (! empty ( $file )) {
452
+ $file_name = $dirname . '/' . $img_title . '.' . $type;
453
+ $attach_id = wp_insert_attachment ( $file, $file_name, $post_id );
454
+ require_once (ABSPATH . 'wp-admin/includes/image.php');
455
+ $attach_data = wp_generate_attachment_metadata ( $attach_id, $fileurl );
456
+ wp_update_attachment_metadata ( $attach_id, $attach_data );
457
+ set_post_thumbnail ( $post_id, $attach_id );
458
+ }
459
+ }
460
+ }
461
+ }
462
+
463
+ if (file_exists ( $this->getUploadDirectory () . $_POST ['filename'] )) {
464
+ $this->fileDelete ( $this->getUploadDirectory (), $_POST ['filename'] );
465
+ }
466
+ }
467
+ }
468
+ ?>
SmackWpHandler.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author fenzik
4
+ * Smackcoders common Wordpress Handler
5
+ */
6
+ class SmackWpHandler {
7
+
8
+ /**
9
+ */
10
+ function __construct() {
11
+
12
+ // TODO - Not for now
13
+ }
14
+
15
+ /**
16
+ * Smack translation
17
+ */
18
+ function t($lstr) {
19
+ global $slang;
20
+ return $slang [$lstr];
21
+ }
22
+
23
+ /**
24
+ * Function to get user language
25
+ * TODO - Available on 3.0.x
26
+ */
27
+ function user_language() {
28
+ return "en_us";
29
+ }
30
+
31
+ /**
32
+ * Exit operation
33
+ *
34
+ * @param $str string
35
+ * to display
36
+ */
37
+ function freeze($str = "") {
38
+ die ( $str );
39
+ }
40
+ }
41
+
42
+ ?>
languages/en_us.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author fenzik
4
+ * Language file for English US
5
+ */
6
+
7
+ $slang = Array(
8
+ 'ENABLE_DUPLICATION_POST_TITLE'=>'Enable duplicate Post Title detection',
9
+ 'ENABLE_DUPLICATION_POST_CONTENT'=>'Enable duplicate Post Content detection',
10
+ 'UPLOAD_PERMISSION_ERROR'=>'Your WordPress doesn\'t have the uploads folder. Please create the uploads folders and set write permission for that.',
11
+ 'IMPORT_AGAIN'=>'Import Again',
12
+ 'NOTE' => 'Note',
13
+ 'NOTE_CONTENT_1' => 'Your CSV should contain "," or ";" as delimiters.',
14
+ 'NOTE_CONTENT_2' => 'In CSV, tags should be seperated by "," to import mutiple tags and categories should be seperated by "|" to import multiple categories.',
15
+ 'CHOOSE_ANOTHER_DELIMITER' => 'Your CSV file cannot be processed. It may contains wrong delimiter, kindly choose another delimiter.',
16
+ 'IMPORT_CSV_FILE' => 'Import CSV File',
17
+ 'UPLOAD_FILE' => 'Upload file',
18
+ 'ENABLE_DUPLICATION_HINT' => '(Enabling this options may slow down the import process)',
19
+ 'PASSWORD_HINT' => 'Type your password here',
20
+ );
21
+
22
+ ?>
wp_ultimate_csv_importer.js CHANGED
@@ -1,45 +1,47 @@
1
  function importAllPostStatus(selectedId,headerCount){
2
- var select;
3
- var options;
4
- if(selectedId != 0){
5
- document.getElementById('poststatusalert').style.display = 'none';
6
- for(var u=0;u< headerCount;u++){
7
- select = document.getElementById('mapping'+u);
8
- options = select.options;
9
- for(var o=0;o<options.length;o++){
10
- if(options[o].value == 'post_status'){
11
- select.remove(o);
12
- }
 
13
  }
14
  }
15
- }
16
- else{
17
- document.getElementById('poststatusalert').style.display = 'block';
18
 
19
- for(var v=0;v<headerCount;v++){
20
- select = document.getElementById('mapping'+v);
21
- options = select.options;
22
- poststatus = 0;
23
- for(var o=0;o<options.length;o++){
24
- if(options[o].value == 'post_status')
25
- poststatus = 1;
26
- }
27
- if(poststatus == 0){
28
- var option=document.createElement("option");
29
- option.text="post_status";
30
- select.add(option);
31
- }
32
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
- }//exits post_status show hide
35
- if(selectedId == 3){
36
- document.getElementById('postsPassword').style.display = "";
37
- document.getElementById('passwordlabel').style.display = "";
38
- }
39
- else{
40
- document.getElementById('postsPassword').style.display = "none";
41
- document.getElementById('passwordlabel').style.display = "none";
42
- }
43
  }
44
 
45
  // Function for add customfield
@@ -50,23 +52,17 @@ function addcustomfield(myval,selected_id){
50
  var selected_value;
51
  for(var i=0;i<aa;i++){
52
  var b = document.getElementById('mapping'+i).value;
53
- if(b == 'post_date'){
54
- document.getElementById('date'+i).style.display="";
55
- }
56
- else{
57
- document.getElementById('date'+i).style.display="none";
58
- }
59
  if(b=='add_custom'+i){
60
  document.getElementById('textbox'+i).style.display="";
61
  document.getElementById('customspan'+i).style.display = "";
62
  }
63
  else{
64
  document.getElementById('textbox'+i).style.display="none";
65
- document.getElementById('customspan'+i).style.display = "none";
66
 
67
  }
68
  }
69
- var header_count = document.getElementById('h2').value;
70
  for(var j=0;j<header_count;j++){
71
  var selected_value = document.getElementById('mapping'+j);
72
  var value1 = selected_value.options[selected_value.selectedIndex].value;
@@ -103,7 +99,7 @@ function import_csv(){
103
  post_status_msg = 'Off';
104
  chk_status_in_csv = document.getElementById('importallwithps').value;
105
  if(chk_status_in_csv != 0)
106
- post_status_msg = 'On';
107
  var array = new Array();
108
  var val1,val2;
109
  val1 = val2 = 'Off';
@@ -121,23 +117,23 @@ function import_csv(){
121
  }
122
  if(post_status_msg == 'Off'){
123
  if(array[j] == 'post_status')
124
- post_status_msg = 'On';
125
  }
126
-
127
  }
128
  if(val1 == 'On' && val2 == 'On' && post_status_msg == 'On') {
129
- return true;
130
  }
131
  else {
132
- if(val1 == 'Off')
133
- error_msg += " post_title,";
134
- if(val2 == 'Off')
135
- error_msg += " post_content,";
136
- if(post_status_msg == 'Off')
137
- error_msg += " post_status";
138
  }
139
 
140
- alert('Error: '+error_msg+' are mandatory fields. Please map the fields to proceed.');
141
- return false;
142
 
143
  }
1
  function importAllPostStatus(selectedId,headerCount){
2
+ var select;
3
+ var options;
4
+ if(selectedId != 0){
5
+ // document.getElementById('poststatusalert').style.display = 'none';
6
+ for(var u=0;u< headerCount;u++){
7
+ select = document.getElementById('mapping'+u);
8
+ options = select.options;
9
+ for(var o=0;o<options.length;o++){
10
+ if(options[o].value == 'post_status'){
11
+ select.remove(o);
12
+ }
13
+ }
14
  }
15
  }
16
+ else{
17
+ // document.getElementById('poststatusalert').style.display = 'block';
 
18
 
19
+ for(var v=0;v<headerCount;v++){
20
+ select = document.getElementById('mapping'+v);
21
+ options = select.options;
22
+ poststatus = 0;
23
+ for(var o=0;o<options.length;o++){
24
+ if(options[o].value == 'post_status')
25
+ poststatus = 1;
26
+ }
27
+ if(poststatus == 0){
28
+ var option=document.createElement("option");
29
+ option.text="post_status";
30
+ select.add(option);
31
+ }
32
 
33
+ }
34
+ }//exits post_status show hide
35
+ if(selectedId == 3){
36
+ document.getElementById('postsPassword').style.display = "";
37
+ document.getElementById('passwordlabel').style.display = "";
38
+ document.getElementById('passwordhint').style.display = "";
39
+ }
40
+ else{
41
+ document.getElementById('postsPassword').style.display = "none";
42
+ document.getElementById('passwordlabel').style.display = "none";
43
+ document.getElementById('passwordhint').style.display = "none";
44
  }
 
 
 
 
 
 
 
 
 
45
  }
46
 
47
  // Function for add customfield
52
  var selected_value;
53
  for(var i=0;i<aa;i++){
54
  var b = document.getElementById('mapping'+i).value;
 
 
 
 
 
 
55
  if(b=='add_custom'+i){
56
  document.getElementById('textbox'+i).style.display="";
57
  document.getElementById('customspan'+i).style.display = "";
58
  }
59
  else{
60
  document.getElementById('textbox'+i).style.display="none";
61
+ document.getElementById('customspan'+i).style.display = "none";
62
 
63
  }
64
  }
65
+ var header_count = document.getElementById('h2').value;
66
  for(var j=0;j<header_count;j++){
67
  var selected_value = document.getElementById('mapping'+j);
68
  var value1 = selected_value.options[selected_value.selectedIndex].value;
99
  post_status_msg = 'Off';
100
  chk_status_in_csv = document.getElementById('importallwithps').value;
101
  if(chk_status_in_csv != 0)
102
+ post_status_msg = 'On';
103
  var array = new Array();
104
  var val1,val2;
105
  val1 = val2 = 'Off';
117
  }
118
  if(post_status_msg == 'Off'){
119
  if(array[j] == 'post_status')
120
+ post_status_msg = 'On';
121
  }
122
+
123
  }
124
  if(val1 == 'On' && val2 == 'On' && post_status_msg == 'On') {
125
+ return true;
126
  }
127
  else {
128
+ if(val1 == 'Off')
129
+ error_msg += " post_title,";
130
+ if(val2 == 'Off')
131
+ error_msg += " post_content,";
132
+ if(post_status_msg == 'Off')
133
+ error_msg += " post_status";
134
  }
135
 
136
+ alert('Error: '+error_msg+' are mandatory fields. Please map the fields to proceed.');
137
+ return false;
138
 
139
  }
wp_ultimate_csv_importer.php CHANGED
@@ -3,686 +3,324 @@
3
  *Plugin Name: WP Ultimate CSV Importer
4
  *Plugin URI: http://www.smackcoders.com/blog/how-to-guide-for-free-wordpress-ultimate-csv-importer-plugin.html
5
  *Description: A plugin that helps to import the data's from a CSV file.
6
- *Version: 2.7.0
7
  *Author: smackcoders.com
8
  *Author URI: http://www.smackcoders.com
9
  *
10
- * Copyright (C) 2012 Smackcoders (www.smackcoders.com)
11
  *
12
- This program is free software; you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License, version 2, as
14
- published by the Free Software Foundation.
15
 
16
- This program is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU General Public License for more details.
20
 
21
- You should have received a copy of the GNU General Public License
22
- along with this program; if not, write to the Free Software
23
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  *
25
  * @link http://www.smackcoders.com/blog/category/free-wordpress-plugins
26
  ***********************************************************************************************
27
  */
28
 
29
- #Credits to Fredrick Marks
30
- # php.ini overriding values for import a big csv file
31
- ini_set('max_execution_time', 700);
32
- ini_set('memory_limit', '128M');
33
 
34
- require( dirname(__FILE__) . '/../../../wp-load.php' );
35
 
36
- // Global variable declaration
37
- global $data_rows;
38
- $data_rows = array();
39
- global $headers ;
40
- $headers = array();
41
- global $defaults;
42
- global $wpdb;
43
- global $keys;
44
- global $delim;
45
- global $contentUrl;
46
- $contentUrl = WP_CONTENT_URL;
47
- # Code added by goku
48
- $delim = empty($_POST['delim']) ? '' : $_POST['delim'];
49
- // Get the custom fields
50
- $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
51
- $keys = $wpdb->get_col( "
52
- SELECT meta_key
53
- FROM $wpdb->postmeta
54
- GROUP BY meta_key
55
- HAVING meta_key NOT LIKE '\_%'
56
- ORDER BY meta_key
57
- LIMIT $limit" );
58
 
59
- // Default header array
60
- $defaults = array(
61
- 'post_title' => null,
62
- 'post_content' => null,
63
- 'post_excerpt' => null,
64
- 'post_date' => null,
65
- 'post_name' => null,
66
- 'post_tag' => null,
67
- 'post_category' => null,
68
- 'post_author' => null,
69
- 'featured_image' => null,
70
- 'post_parent' => 0,
71
- 'post_status' => 0,
72
- );
73
- foreach($keys as $val){
74
- $defaults["CF: ".$val]=$val;
75
- }
76
- // Admin menu settings
77
- function wp_ultimate_csv_importer() {
78
- global $contentUrl;
79
- add_menu_page('CSV importer settings', 'WP Ultimate CSV Importer', 'manage_options',
80
- 'upload_csv_file', 'upload_csv_file', $contentUrl."/plugins/wp-ultimate-csv-importer/images/icon.png");
81
- }
82
-
83
- function LoadWpScript()
84
- {
85
- global $contentUrl;
86
- wp_register_script('wp_ultimate_scripts', $contentUrl."/plugins/wp-ultimate-csv-importer/wp_ultimate_csv_importer.js", array("jquery"));
87
- wp_enqueue_script('wp_ultimate_scripts');
88
- }
89
- add_action('admin_enqueue_scripts', 'LoadWpScript');
90
- add_action("admin_menu", "wp_ultimate_csv_importer");
91
 
92
- // Plugin description details
93
- function description(){
94
- global $contentUrl;
95
- $string = "<p>WP Ultimate CSV Importer Plugin helps you to manage the post,page and </br> custom post data's from a CSV file.</p>
96
- <p>
97
- 1. Admin can import the data's from any csv file.
98
- </p>
99
- <p>
100
- 2. Can define the type of post and post status while importing.
101
- </p>
102
- <p>
103
- 3. Provides header mapping feature to import the data's as your need.
104
- </p>
105
- <p>
106
- 4. Users can map coloumn headers to exixting fields or assign as custom fileds.
107
- </p>
108
- <p>
109
- 5. Import unlimited datas as post.
110
- </p>
111
- <p>
112
- 6. Make imported post as published or make it as draft.
113
- </p>
114
- <p>
115
- 7. Added featured image import functionality.
116
- </p>
117
- <p><b> Important Note:- </b></p><p><span style='color:red;'>1. Your csv should have the seperate column for post_date. <br/>2. It must be in the following format. ( yyyy-mm-dd hh:mm:ss ).</span></p>
118
- <p>Configuring our plugin is as simple as that. If you have any questions, issues and request on new features, plaese visit <a href='http://www.smackcoders.com/blog/category/free-wordpress-plugins' target='_blank'>Smackcoders.com blog </a></p>
119
-
120
- <div align='center' style='margin-top:40px;'> 'While the scripts on this site are free, donations are greatly appreciated. '<br/><br/><a href='http://www.smackcoders.com/donate.html' target='_blank'><img src='".$contentUrl."/plugins/wp-ultimate-csv-importer/images/paypal_donate_button.png' /></a><br/><br/><a href='http://www.smackcoders.com/' target='_blank'><img src='http://www.smackcoders.com/wp-content/uploads/2012/09/Smack_poweredby_200.png'></a>
121
- </div><br/>";
122
- return $string;
123
  }
124
-
125
- // CSV File Reader
126
- # Code modified by Fredrick Marks
127
- function csv_file_data($file,$delim)
128
- {
129
- $upload_dir = wp_upload_dir();
130
- if(!is_dir($upload_dir['basedir'])){
131
- $returnContent = " <div style='font-size:16px;margin-left:20px;margin-top:25px;'>Your WordPress doesn't have the uploads folder. Please create the uploads folders and set write permission for that.
132
- </div><br/>
133
- <div style='margin-left:20px;'>
134
- <form class='add:the-list: validate' method='post' action=''>
135
- <input type='submit' class='button-primary' name='Import Again' value='Import Again'/>
136
- </form>
137
- </div>
138
- ";
139
- echo $returnContent;die;
140
- }
141
- else{
142
- $importdir = $upload_dir['basedir']."/ultimate_importer/";
143
- if(!is_dir($importdir))
144
- {
145
- wp_mkdir_p($importdir);
146
- }
147
- }
148
- ini_set("auto_detect_line_endings", true);
149
- global $data_rows;
150
- global $headers;
151
- global $delim;
152
- # Code added by goku
153
- $c = 0;
154
- $resource = fopen($file, 'r');
155
- while ($keys = fgetcsv($resource,'',"$delim",'"')) {
156
- if ($c == 0) {
157
- $headers = $keys;
158
- } else {
159
- array_push($data_rows, $keys);
160
- }
161
- $c ++;
162
- }
163
- fclose($resource);
164
- ini_set("auto_detect_line_endings", false);
165
  }
166
 
167
- // Move file
168
- function move_file()
169
- {
170
- # Code added by goku
171
- $upload_dir = wp_upload_dir();
172
- $uploads_dir = $upload_dir['basedir']."/ultimate_importer";
173
- if ($_FILES["csv_import"]["error"] == 0) {
174
- $tmp_name = $_FILES["csv_import"]["tmp_name"];
175
- $name = $_FILES["csv_import"]["name"];
176
- move_uploaded_file($tmp_name, "$uploads_dir/$name");
177
- }
178
- }
179
 
180
- // Remove file
181
- function fileDelete($filepath,$filename) {
182
- $success = FALSE;
183
- if (file_exists($filepath.$filename)&&$filename!=""&&$filename!="n/a") {
184
- unlink ($filepath.$filename);
185
- $success = TRUE;
186
- }
187
- return $success;
188
- }
189
-
190
- // Mapping the fields and upload data's
191
- function upload_csv_file()
192
- {
193
- global $headers;
194
- global $data_rows;
195
- global $defaults;
196
- global $keys;
197
  global $custom_array;
198
- global $delim;
199
  global $wpdb;
200
- # Code added by goku
201
- $upload_dir = wp_upload_dir();
202
- $importdir = $upload_dir['basedir']."/ultimate_importer/";
203
- $custom_array = array();
204
- if(isset($_POST['Import']))
205
- {
206
- $duplicatesDetection = $_POST['titleduplicatecheck'];
207
- csv_file_data($_FILES['csv_import']['tmp_name'],$delim);
208
- move_file();
209
- ?>
210
- <br/>
211
- <marquee onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);" >Now the <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">Pro Version</a> is Available. For more details,please visit <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">here</a></marquee>
212
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://www.smackcoders.com/blog/category/free-wordpress-plugins" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
213
- <?php if ( count($headers)>=1 && count($data_rows)>=1 ){?>
214
- <div style="float:left;min-width:45%">
215
- <form class="add:the-list: validate" method="post" onsubmit="return import_csv();">
216
- <h3>Import Data Configuration</h3>
217
- <div style="margin-top:30px;>
218
- <input name="_csv_importer_import_as_draft" type="hidden" value="publish" />
219
- </p>
220
- <label> Select Post Type </label>&nbsp;&nbsp;
221
- <select name='csv_importer_cat'>
222
- <?php
223
- $post_types=get_post_types();
224
- foreach($post_types as $key => $value){
225
- if(($value!='featured_image') && ($value!='attachment') && ($value!='wpsc-product') && ($value!='wpsc-product-file') && ($value!='revision') && ($value!='nav_menu_item')){ ?>
226
- <option id="<?php echo($value);?>" name="<?php echo($value);?>"> <?php echo($value);?> </option>
227
- <?php }
228
- }
229
- ?>
230
- <select>
231
- <br/>
232
- <br/>
233
- <?php $cnt1 = count($headers); ?>
234
-
235
- <label>Import with post status</label>&nbsp;&nbsp;
236
- <select name = 'importallwithps' id= 'importallwithps' onchange = 'importAllPostStatus(this.value, "<?php echo $cnt1?>")'>
237
- <option value = '0'>Status as in CSV</option>
238
- <option value = '1'>Publish</option>
239
- <option value = '2'>Sticky</option>
240
- <option value = '3'>Protected</option>
241
- <option value = '4'>Private</option>
242
- <option value = '5'>Draft</option>
243
- <option value = '6'>Pending</option>
244
- </select>
245
- </div><br/>
246
- <span style='color:red;'id = 'poststatusalert'>post_status field must mapped below as in CSV</span>
247
- <label style='display:none;' id = 'passwordlabel'>Posts Password</label>&nbsp;&nbsp;
248
- <input type='text' style='display:none' id = 'postsPassword' name = 'postsPassword'>
249
- <h3>Mapping the Fields</h3>
250
- <div id='display_area'>
251
- <?php $cnt =count($defaults)+2; ?>
252
- <input type="hidden" id="h1" name="h1" value="<?php echo $cnt; ?>"/>
253
- <input type="hidden" id="h2" name="h2" value="<?php echo $cnt1; ?>"/>
254
- <input type="hidden" id="titleduplicatecheck" name = "titleduplicatecheck" value="<?php echo $_POST['titleduplicatecheck'] ?>" />
255
- <input type="hidden" id="contentduplicatecheck" name="contentduplicatecheck" value="<?php echo $_POST['contentduplicatecheck'] ?>" />
256
- <input type="hidden" id="delim" name="delim" value="<?php echo $_POST['delim']; ?>" />
257
- <input type="hidden" id="header_array" name="header_array" value="<?php print_r($headers);?>" />
258
- <table style="font-size:12px;">
259
- <?php
260
- $count = 0;
261
- foreach($headers as $key=>$value){
262
- ?>
263
- <tr>
264
- <td>
265
- <label><?php print($value);?></label>
266
- </td>
267
- <td>
268
- <select name="mapping<?php print($count);?>" id="mapping<?php print($count);?>" class ='uiButton' onchange="addcustomfield(this.value,<?php echo $count; ?>);">
269
- <option id="select" name="select">-- Select --</option>
270
- <?php
271
- foreach($defaults as $key1=>$value1){
272
- ?>
273
- <option value ="<?php print($key1);?>">
274
- <?php if($key1 != 'post_name')
275
- print($key1);
276
- else
277
- print 'post_slug';?>
278
- </option>
279
- <?php } $taxo = get_taxonomies();
280
- foreach($taxo as $taxokey => $taxovalue){
281
- if($taxokey !='category' && $taxokey !='link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format'){ ?>
282
- <option value ="<?php print($taxokey);?>"><?php print($taxovalue);?></option>
283
- <?php }
284
- }
285
- ?>
286
- <option value="add_custom<?php print($count);?>">Add Custom Field</option>
287
- </select>
288
- <!-- added to solve issue id 1072-->
289
- <input type="text" id="textbox<?php print($count); ?>" name="textbox<?php print($count); ?>" style="display:none;" value="<?php echo $value ?>" />
290
- <span style="display:none;color:red;margin-left:5px;" id="customspan<?php echo $count?>" >Name this Field</span>
291
- <select id="date<?php print($count); ?>" name="date<?php print($count); ?>" style="display:none;">
292
- <option value="M/DD/YYYY">M/DD/YYYY</option>
293
- <option value="M/DD/YYYY HH:MM">M/DD/YYYY HH:MM</option>
294
- <option value="M/DD/YYYY HH:MM PM">M/DD/YYYY HH:MM PM</option>
295
- <option value="MM/DD/YYYY">MM/DD/YYYY</option>
296
- <option value="MM/DD/YYYY HH:MM">MM/DD/YYYY HH:MM</option>
297
- <option value="MM/DD/YYYY HH:MM PM">MM/DD/YYYY HH:MM PM</option>
298
- <option value="YYYY-MM-DD HH:MM:SS">YYYY-MM-DD HH:MM:SS</option>
299
- </select>
300
- </td>
301
- </tr>
302
- <?php
303
- $count++; }
304
- ?>
305
- </table>
306
- </div><br/>
307
- <input type='hidden' name='filename' id='filename' value="<?php echo($_FILES['csv_import']['name']);?>" />
308
- <input type='submit' class='button-primary' name= 'post_csv' id='post_csv' value='Import' />
309
- </form>
310
- </div>
311
- <div style="min-width:45%;">
312
- <?php $result = description(); print_r($result); ?>
313
- </div>
314
- <?php
315
- }
316
- else { ?>
317
- <div style="font-size:16px;margin-left:20px;">Your CSV file cannot be processed. It may contains wrong delimiter or please choose the correct delimiter.
318
- </div><br/>
319
- <div style="margin-left:20px;">
320
- <form class="add:the-list: validate" method="post" action="">
321
- <input type="submit" class="button-primary" name="Import Again" value="Import Again"/>
322
- </form>
323
- </div>
324
- <div style="margin-left:20px;margin-top:30px;">
325
- <b>Note :-</b>
326
- <p>1. Your CSV should contain "," or ";" as delimiters.</p>
327
- <p>2. In CSV, tags should be seperated by "," to import mutiple tags and categories should be seperated by "|" to import multiple categories.</p>
328
- </div>
329
- <?php }
330
- }
331
- else if(isset($_POST['post_csv'])){
332
- # added for issue id 1072
333
- for($d=0;$d<count($_POST);$d++){
334
- if($_POST['mapping'.$d] == 'post_date'){
335
- $dateformat = $_POST['date'.$d];
336
- }
337
- }
338
- $insertedRecords = 0;
339
- $duplicates = 0;
340
- $wrongpostauthor = 0;
341
- $smack_taxo = array();
342
- # Code added by goku
343
- $upload_dir = wp_upload_dir();
344
- $dir = $upload_dir['basedir']."/ultimate_importer/";
345
- csv_file_data($dir.$_POST['filename'],$delim);
346
- foreach($_POST as $postkey=>$postvalue){
347
- if($postvalue != '-- Select --'){
348
- $ret_array[$postkey]=$postvalue;
349
- }
350
- }
351
- foreach($data_rows as $key => $value){
352
- for($i=0;$i<count($value) ; $i++)
353
- {
354
- if(array_key_exists('mapping'.$i,$ret_array)){
355
- if($ret_array['mapping'.$i]!='add_custom'.$i){
356
- $new_post[$ret_array['mapping'.$i]] = $value[$i];
357
- }
358
- else{
359
- $new_post[$ret_array['textbox'.$i]] = $value[$i];
360
- $custom_array[$ret_array['textbox'.$i]] = $value[$i];
361
- }
362
- }
363
- }
364
- for($inc=0;$inc<count($value);$inc++){
365
- foreach($keys as $k => $v){
366
- if(array_key_exists($v,$new_post)){
367
- $custom_array[$v] =$new_post[$v];
368
- }
369
- }
370
- }
371
- foreach($new_post as $ckey => $cval){
372
- $taxo = get_taxonomies();
373
- foreach($taxo as $taxokey => $taxovalue){
374
- if($taxokey !='category' && $taxokey !='link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format'){
375
- if($taxokey == $ckey){
376
- $smack_taxo[$ckey] = $new_post[$ckey];
377
- }
378
- }
379
- }
380
- if($ckey!='post_category' && $ckey!='post_tag' && $ckey!='featured_image' && $ckey!= $smack_taxo[$ckey]){ // Code modified at version 2.5.0 by Fredrick Marks
381
- if(array_key_exists($ckey,$custom_array)){
382
- $darray[$ckey]=$new_post[$ckey];
383
- }
384
- else{
385
- if(array_key_exists($ckey,$smack_taxo)){
386
-
387
- }
388
- else{
389
- $data_array[$ckey]=$new_post[$ckey];
390
- }
391
- }
392
- }
393
- else{
394
- if($ckey == 'post_tag'){
395
- $tags[$ckey]=$new_post[$ckey];
396
- }
397
- if($ckey == 'post_category'){
398
- $categories[$ckey]=$new_post[$ckey];
399
- }
400
- if($ckey == 'featured_image'){
401
- $file_url=$filetype[$ckey]=$new_post[$ckey];
402
- $file_type = explode('.',$filetype[$ckey]);
403
- $count = count($file_type);
404
- $type= $file_type[$count-1];
405
- if($type == 'png'){
406
- $file['post_mime_type']='image/png';
407
- }
408
- else if($type == 'jpg'){
409
- $file['post_mime_type']='image/jpeg';
410
- }
411
- else if($type == 'gif'){
412
- $file['post_mime_type']='image/gif';
413
- }
414
- $img_name = explode('/',$file_url);
415
- $imgurl_split = count($img_name);
416
- $img_name = explode('.',$img_name[$imgurl_split-1]);
417
- $img_title = $img_name = $img_name[0];
418
- $dir = wp_upload_dir();
419
- $dirname = 'featured_image';
420
- $full_path = $dir['basedir'].'/'.$dirname;
421
- $baseurl = $dir['baseurl'].'/'.$dirname;
422
- $filename = explode('/',$file_url);
423
- $file_split = count($filename);
424
- $filepath = $full_path.'/'.$filename[$file_split-1];
425
- $fileurl = $baseurl.'/'.$filename[$file_split-1];
426
- if(is_dir($full_path)){
427
- $smack_fileCopy = copy($file_url,$filepath);
428
- }
429
- else{
430
- wp_mkdir_p($full_path);
431
- $smack_fileCopy = copy($file_url,$filepath);
432
- }
433
- if($smack_fileCopy){
434
- $file['guid']=$fileurl;
435
- $file['post_title']=$img_title;
436
- $file['post_content']='';
437
- $file['post_status']='inherit';
438
- }
439
- else{
440
- $file = false;
441
- }
442
- }
443
- }
444
- }
445
- #code added for issue 1087
446
- $sticky = false;
447
- if($_POST['importallwithps'] == 0){
448
- unset($data_array['post_password']);
449
- if(($data_array['post_status'] == 1)||($data_array['post_status'] == 'Publish'))
450
- $data_array['post_status'] = 'publish';
451
- elseif(($data_array['post_status'] == 4)||($data_array['post_status'] == 'Draft'))
452
- $data_array['post_status'] = 'draft';
453
- elseif(($data_array['post_status'] == '3')||($data_array['post_status'] == 'Private'))
454
- $data_array['post_status'] = 'private';
455
- elseif(($data_array['post_status'] == 5)||($data_array['post_status'] == 'Pending'))
456
- $data_array['post_status'] = 'pending';
457
- elseif(($data_array['post_status'] == 2)||($data_array['post_status'] == 'Sticky')){
458
- $data_array['post_status'] = 'publish';
459
- $sticky = true;
460
- }
461
- elseif(($data_array['post_status'] == ''))
462
- $data_array['post_status'] = 'publish';
463
- else {
464
- if(strlen($data_array['post_status']) <= 10)
465
- $data_array['post_password'] = $data_array['post_status'];
466
- else
467
- $data_array['post_password'] = substr($data_array['post_status'],0,10);
468
- $data_array['post_status'] = 'publish';
469
- }
470
- }
471
- else{
472
- unset($data_array['post_password']);
473
- if($_POST['importallwithps'] == 1)
474
- $data_array['post_status'] = 'publish';
475
- if($_POST['importallwithps'] == 2){
476
- $data_array['post_status'] = 'publish';
477
- $sticky = true;
478
- }
479
- if($_POST['importallwithps'] == 3){
480
- $data_array['post_status'] = 'publish';
481
- $data_array['post_password'] = $_POST['postsPassword'];
482
- }
483
- if($_POST['importallwithps'] == 4)
484
- $data_array['post_status'] = 'private';
485
- if($_POST['importallwithps'] == 5)
486
- $data_array['post_status'] = 'draft';
487
- if($_POST['importallwithps'] == 6){
488
- $data_array['post_status'] = 'pending';
489
- }
490
- }
491
- $data_array['post_type']=$_POST['csv_importer_cat'];
492
- $permission = 'ok';
493
- $chkinsert =1;
494
- $chkedContent = 1;
495
- // Duplicate Check code starts
496
- if($_POST['titleduplicatecheck']){
497
- $permission = 'notok';
498
- $title = $data_array['post_title'];
499
- $gettype = $data_array['post_type'];
500
- $post_table = $wpdb->posts;
501
- $post_exist = $wpdb->get_results("select ID from $post_table where post_title = \"{$title}\" and post_type = \"{$gettype}\" and post_status in('publish','future','draft')");
502
- if(count($post_exist) == 0 && ($title != null || $title != '')){
503
- $chkinsert = 0;
504
- $permission = 'ok';
505
- }
506
- }
507
- if($_POST['contentduplicatecheck']){
508
- $permission = 'ok';
509
- $content = $data_array['post_content'];
510
- $contentLength = strlen($content);
511
- $post_table = $wpdb->posts;
512
- $post_exist = $wpdb->get_results("select ID from $post_table where length(post_content) = \"{$contentLength}\"");
513
- if(count($post_exist)==0){
514
- $chkedContent = 0;
515
- }
516
- else{
517
- $chkforeach = 0;
518
- foreach($post_exist as $singlepost){
519
- $postdata = $wpdb->get_results("select post_content from $post_table where id = \"{$singlepost->ID}\"");
520
- $chkDbString = substr($postdata[0]->post_content,0,50);
521
- $chkFormString = substr($content,0,50);
522
- if($chkDbString == $chkFormString){
523
- $permission = 'notok';
524
- }
525
 
526
- }
527
- }
528
- }
529
- if($permission == 'notok')
530
- $duplicates++;
531
- if(!(is_numeric($data_array['post_author']))){
532
- $postuserid = $data_array['post_author'];
533
- $postauthor = $wpdb->get_results("select id from wp_users where user_login = \"{$postuserid}\"");
534
- if($postauthor == null){
535
- $data_array['post_author'] = 1;
536
- $data_array['post_status'] = 'draft';
537
- $wrongpostauthor++;
538
- }
539
- else
540
- $data_array['post_author'] = $postauthor[0]->id;
541
- }
542
- // Duplicate Check code ends
543
-
544
- if($permission == 'ok'){
545
-
546
- if($dateformat != 'YYYY-MM-DD HH:MM:SS'){
547
- if($dateformat == 'MM/DD/YYYY HH:MM'){
548
- $splitdate = explode(" ",$data_array['post_date']);
549
- $date = $splitdate[0];
550
- $time = $splitdate[1];
551
- $formatdatearray = explode("/",$date);
552
- $exactdate = $formatdatearray[2].'-'.$formatdatearray[0].'-'.$formatdatearray[1];
553
- $data_array['post_date'] = $exactdate.' '.$time;
554
- }
555
- if($dateformat == 'M/DD/YYYY HH:MM'){
556
- $splitdate = explode(" ",$data_array['post_date']);
557
- $date = $splitdate[0];
558
- $time = $splitdate[1];
559
- $formatdatearray = explode("/",$date);
560
- $exactdate = $formatdatearray[2].'-'.$formatdatearray[0].'-'.$formatdatearray[1];
561
- $data_array['post_date'] = $exactdate.' '.$time;
562
- }
563
- if(($dateformat == 'M/DD/YYYY')||($dateformat == 'MM/DD/YYYY')){
564
- $splitdate = explode(" ",$data_array['post_date']);
565
- $date = $splitdate[0];
566
- $formatdatearray = explode("/",$date);
567
- $exactdate = $formatdatearray[2].'-'.$formatdatearray[0].'-'.$formatdatearray[1];
568
- $data_array['post_date'] = $exactdate;
569
- }
570
- if(($dateformat == 'M/DD/YYYY HH:MM PM')||($dateformat == 'MM/DD/YYYY HH:MM PM')){
571
- $splitdate = explode(" ",$data_array['post_date']);
572
- $date = $splitdate[0];
573
- $time = $splitdate[1];
574
- $chkpm = $splitdate[2];
575
- if($chkpm == 'PM'||$chkpm == 'pm'){
576
- $time = strtotime($time .' + 12 hour');
577
- $time = date('G:i:s',$time);
578
- }
579
- $formatdatearray = explode("/",$date);
580
- $exactdate = $formatdatearray[2].'-'.$formatdatearray[0].'-'.$formatdatearray[1];
581
- $data_array['post_date'] = $exactdate.' '.$time;
582
- }
583
- }
584
- $post_id = wp_insert_post( $data_array );
585
- if($sticky)
586
- stick_post($post_id);
587
- if($post_id){
588
- $insertedRecords = $insertedRecords+1;
589
- }
590
- if(!empty($custom_array)){
591
- foreach($custom_array as $custom_key => $custom_value){
592
- add_post_meta($post_id, $custom_key, $custom_value);
593
- }
594
- }
595
 
596
- // Create custom taxonomy to post
597
- if(!empty($smack_taxo)){
598
- foreach($smack_taxo as $taxo_key => $taxo_value){
599
- $split_line = explode('|',$taxo_value);
600
- wp_set_object_terms( $post_id, $split_line, $taxo_key );
601
- }
602
- } // End of code to add custom taxonomy
603
-
604
- // Create/Add tags to post
605
- if(!empty($tags)){
606
- foreach($tags as $tag_key => $tag_value){
607
- wp_set_post_tags( $post_id, $tag_value );
608
- }
609
- } // End of code to add tags
610
 
611
- // Create/Add category to post
612
- if(!empty($categories)){
613
- $split_line = explode('|',$categories['post_category']);
614
- wp_set_object_terms($post_id, $split_line, 'category');
615
 
616
- } // End of code to add category
 
617
 
618
- // Featured image by Fredrick Marks
619
- if(!empty($file)){
620
- $file_name=$dirname.'/'.$img_title.'.'.$type;
621
- $attach_id = wp_insert_attachment($file, $file_name, $post_id);
622
- require_once(ABSPATH . 'wp-admin/includes/image.php');
623
- $attach_data = wp_generate_attachment_metadata( $attach_id, $fileurl );
624
- wp_update_attachment_metadata( $attach_id, $attach_data );
625
- set_post_thumbnail( $post_id, $attach_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
  }
 
 
 
 
 
 
 
 
 
 
 
 
627
  }
628
- }
629
- if(($insertedRecords != 0) || ($duplicates != 0)){
630
- ?>
631
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; padding: 5px;text-align:center"><b> <?php echo '('.$insertedRecords.')'; ?> records are successfully Imported !<br> <?php echo '('.$duplicates.')'; ?> duplicate records found !
632
- <?php if($wrongpostauthor != 0){ ?><br>
633
- <?php echo $wrongpostauthor; ?> posts with no valid UserID/Name are assigned admin as author.
634
- <?php
635
- //ask and fill the error msg
636
-
637
- } ?></b></div>
638
- <?php }else if(($insertedRecords == 0) && ($duplicates == 0)){ ?>
639
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; padding: 5px;text-align:center"><b> Check your CSV file and format. </b></div>
640
- <?php } ?>
641
- <div style="margin-top:30px;margin-left:10px">
642
- <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
643
- <input type="submit" class='button-primary' id="goto" name="goto" value="Continue" />
644
- </form>
645
  </div>
646
- <?php
647
- $upload_dir = wp_upload_dir();
648
- $csvdir = $upload_dir['basedir']."/ultimate_importer/";
649
- $CSVfile = $_POST['filename'];
650
- if(file_exists($csvdir.$CSVfile)){
651
- fileDelete($csvdir,$CSVfile);
652
- }
653
- }
654
- else
655
- {
656
- ?>
657
- <div class="wrap">
658
- <marquee onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);" >Now the <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">Pro Version</a> is Available. For more details,please visit <a href="http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html" target="_blank">here</a></marquee>
659
- <div style="background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center"> Please check out <a href="http://www.smackcoders.com/blog/category/free-wordpress-plugins" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
660
- <div style="min-width:45%;float:left;height:500px;">
661
- <h2>Import CSV File</h2>
662
- <form class="add:the-list: validate" method="post" enctype="multipart/form-data" onsubmit="return file_exist();">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
663
 
664
  <!-- File input -->
665
- <p><label for="csv_import">Upload file:</label><br/>
666
- <input name="csv_import" id="csv_import" type="file" value="" aria-required="true" /></p><br/>
667
- <p><input type="checkbox" name="titleduplicatecheck" value=1> Enable Duplicate Post Title Detection<br>
668
- <p><input type="checkbox" name="contentduplicatecheck" value = 1> Enable Duplicate Post Content Detection <br>
669
- <!-- added above checkboxes for issueid 1057-->
670
- <p><label>Delimiter</label>&nbsp;&nbsp;&nbsp;
671
- <select name="delim" id="delim">
672
- <option value=",">,</option>
673
- <option value=";">;</option>
674
- </select>
675
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
676
 
677
- <p class="submit"><input type="submit" class="button-primary" name="Import" value="Import" /></p>
678
- </form>
679
- </div>
680
- <div style="min-width:45%;">
681
- <?php $result = description(); print_r($result); ?>
682
- </div>
683
- </div><!-- end wrap -->
684
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
685
  }
686
  }
687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688
  ?>
3
  *Plugin Name: WP Ultimate CSV Importer
4
  *Plugin URI: http://www.smackcoders.com/blog/how-to-guide-for-free-wordpress-ultimate-csv-importer-plugin.html
5
  *Description: A plugin that helps to import the data's from a CSV file.
6
+ *Version: 3.0.0
7
  *Author: smackcoders.com
8
  *Author URI: http://www.smackcoders.com
9
  *
10
+ * Copyright (C) 2013 Smackcoders (www.smackcoders.com)
11
  *
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License, version 2, as
14
+ published by the Free Software Foundation.
15
 
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
 
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  *
25
  * @link http://www.smackcoders.com/blog/category/free-wordpress-plugins
26
  ***********************************************************************************************
27
  */
28
 
29
+ ini_set ( 'max_execution_time', 600 );
30
+ ini_set ( 'memory_limit', '128M' );
 
 
31
 
32
+ require_once (dirname ( __FILE__ ) . '/../../../wp-load.php');
33
 
34
+ require_once ("SmackImpCE.php");
35
+ $impCE = new SmackImpCE ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ require_once ("languages/" . $impCE->user_language () . ".php");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ // Admin menu settings
40
+ function wp_ultimate_csv_importer() {
41
+ add_menu_page ( 'CSV importer settings', 'WP Ultimate CSV Importer', 'manage_options', 'upload_csv_file', 'upload_csv_file', WP_CONTENT_URL . "/plugins/wp-ultimate-csv-importer/images/icon.png" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
43
+ function LoadWpScript() {
44
+ wp_register_script ( 'wp_ultimate_scripts', WP_CONTENT_URL . "/plugins/wp-ultimate-csv-importer/wp_ultimate_csv_importer.js", array (
45
+ "jquery"
46
+ ) );
47
+ wp_enqueue_script ( 'wp_ultimate_scripts' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
49
 
50
+ add_action ( 'admin_enqueue_scripts', 'LoadWpScript' );
51
+ add_action ( "admin_menu", "wp_ultimate_csv_importer" );
 
 
 
 
 
 
 
 
 
 
52
 
53
+ /**
54
+ * Home page layout and importer
55
+ */
56
+ function upload_csv_file() {
57
+ global $impCE;
 
 
 
 
 
 
 
 
 
 
 
 
58
  global $custom_array;
 
59
  global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ $importdir = $impCE->getUploadDirectory ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ /*
64
+ * Get POST data
65
+ */
66
+ if (isset ( $_POST ['delim'] ) && in_array ( $_POST ['delim'], $impCE->delim_avail ))
67
+ $impCE->delim = $_POST ['delim'];
 
 
 
 
 
 
 
 
 
68
 
69
+ if (isset ( $_POST ['titleduplicatecheck'] ) && trim($_POST ['titleduplicatecheck'] != ""))
70
+ $impCE->titleDupCheck = true;
 
 
71
 
72
+ if (isset ( $_POST ['contentduplicatecheck'] ) && trim($_POST ['contentduplicatecheck'] != ""))
73
+ $impCE->conDupCheck = true;
74
 
75
+ $custom_array = array ();
76
+ if (isset ( $_POST ['Import'] )) {
77
+ $data_rows = $impCE->csv_file_data ( $_FILES ['csv_import'] ['tmp_name'], $impCE->delim );
78
+ $impCE->move_file ();
79
+
80
+ echo renderTop();
81
+ if ( count($impCE->headers)>=1 && count($data_rows)>=1 ){?>
82
+ <div style="float: left; min-width: 45%">
83
+ <form class="add:the-list: validate" method="post"
84
+ onsubmit="return import_csv();">
85
+ <h3>Import Data Configuration</h3>
86
+ <div style="margin-top: 30px;">
87
+ <table><tr><td>
88
+ <input name="_csv_importer_import_as_draft" type="hidden"
89
+ value="publish" /> <label> Select Post Type </label></td><td> <select
90
+ name='csv_importer_cat'>
91
+ <?php
92
+ foreach ( get_post_types () as $key => $value ) {
93
+ if (($value != 'featured_image') && ($value != 'attachment') && ($value != 'wpsc-product') && ($value != 'wpsc-product-file') && ($value != 'revision') && ($value != 'nav_menu_item')) {
94
+ ?>
95
+ <option id="<?php echo($value);?>"> <?php echo($value);?> </option>
96
+ <?php
97
+
98
+ }
99
+ }
100
+ ?>
101
+ </select> </td></tr><tr><td>
102
+ <?php $cnt1 = count($impCE->headers);?>
103
+
104
+ <label>Import with post status</label></td> <td><select
105
+ name='importallwithps' id='importallwithps'
106
+ onchange='importAllPostStatus(this.value, "<?php echo $cnt1?>")'>
107
+ <option value='0'>Status as in CSV</option>
108
+ <option value='1'>Publish</option>
109
+ <option value='2'>Sticky</option>
110
+ <option value='4'>Private</option>
111
+ <option value='3'>Protected</option>
112
+ <option value='5'>Draft</option>
113
+ <option value='6'>Pending</option>
114
+ </select></td></tr></table>
115
+ </div>
116
+ <br />
117
+ <label id='passwordlabel' style="display:none">Password</label>&nbsp;&nbsp;
118
+ <input type='text' id='postsPassword' name='postsPassword' value = 'admin' style="display:none">
119
+ <label id='passwordhint' style="display:none;color:red;"><?php echo $impCE->t("PASSWORD_HINT"); ?></label>
120
+ <h3>Mapping the Fields</h3>
121
+ <div id='display_area'>
122
+ <?php $cnt =count($impCE->defCols) +2; ?>
123
+ <input type="hidden" id="h1" name="h1" value="<?php echo $cnt; ?>" />
124
+ <input type="hidden" id="h2" name="h2" value="<?php echo $cnt1; ?>" />
125
+ <input type="hidden" id="titleduplicatecheck"
126
+ name="titleduplicatecheck"
127
+ value="<?php echo $_POST['titleduplicatecheck'] ?>" /> <input
128
+ type="hidden" id="contentduplicatecheck"
129
+ name="contentduplicatecheck"
130
+ value="<?php echo $_POST['contentduplicatecheck'] ?>" /> <input
131
+ type="hidden" id="delim" name="delim"
132
+ value="<?php echo $_POST['delim']; ?>" /> <input type="hidden"
133
+ id="header_array" name="header_array"
134
+ value="<?php print_r($impCE->headers);?>" />
135
+ <table style="font-size: 12px;">
136
+ <?php
137
+ $count = 0;
138
+ foreach ( $impCE->headers as $key => $value ) {
139
+ ?>
140
+ <tr>
141
+ <td><label><?php print($value);?></label></td>
142
+ <td><select name="mapping<?php print($count);?>"
143
+ id="mapping<?php print($count);?>" class='uiButton'
144
+ onchange="addcustomfield(this.value,<?php echo $count; ?>);">
145
+ <option id="select">-- Select --</option>
146
+ <?php
147
+ foreach ( $impCE->defCols as $key1 => $value1 ) {
148
+ ?>
149
+ <option value="<?php print($key1);?>">
150
+ <?php
151
+
152
+ if ($key1 != 'post_name')
153
+ print ($key1) ;
154
+ else
155
+ print 'post_slug';
156
+ ?>
157
+ </option>
158
+ <?php
159
+
160
+ }
161
+ foreach ( get_taxonomies () as $taxokey => $taxovalue ) {
162
+ if ($taxokey != 'category' && $taxokey != 'link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format') {
163
+ ?>
164
+ <option value="<?php print($taxokey);?>"><?php print($taxovalue);?></option>
165
+ <?php
166
+
167
+ }
168
  }
169
+ ?>
170
+ <option value="add_custom<?php print($count);?>">Add Custom Field</option>
171
+ </select> <!-- added to solve issue id 1072--> <input type="text"
172
+ id="textbox<?php print($count); ?>"
173
+ name="textbox<?php print($count); ?>" style="display: none;"
174
+ value="<?php echo $value ?>" /> <span
175
+ style="display: none; color: red; margin-left: 5px;"
176
+ id="customspan<?php echo $count?>">Name this Field</span>
177
+ </td>
178
+ </tr>
179
+ <?php
180
+ $count ++;
181
  }
182
+ ?>
183
+ </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  </div>
185
+ <br /> <input type='hidden' name='filename' id='filename'
186
+ value="<?php echo($_FILES['csv_import']['name']);?>" /> <input
187
+ type='submit' class='button-primary' name='post_csv' id='post_csv'
188
+ value='Import' />
189
+ </form>
190
+ </div>
191
+ <div style="min-width: 45%;">
192
+ <?php print(renderDesc()); ?>
193
+ </div>
194
+ <?php
195
+ } else {
196
+ ?>
197
+ <div style="font-size: 16px; margin-left: 20px;"><?php echo $impCE->t("CHOOSE_ANOTHER_DELIMITER"); ?>
198
+ </div>
199
+ <br />
200
+ <div style="margin-left: 20px;">
201
+ <form class="add:the-list: validate" method="post" action="">
202
+ <input type="submit" class="button-primary" name="Import Again"
203
+ value="Import Again" />
204
+ </form>
205
+ </div>
206
+ <div style="margin-left: 20px; margin-top: 30px;">
207
+ <b><?php echo $impCE->t("NOTE"); ?> :-</b>
208
+ <p>1. <?php echo $impCE->t("NOTE_CONTENT_1"); ?></p>
209
+ <p>2. <?php echo $impCE->t("NOTE_CONTENT_2"); ?></p>
210
+ </div>
211
+ <?php
212
+
213
+ }
214
+ } else if (isset ( $_POST ['post_csv'] )) {
215
+
216
+ $impCE->processDataInWP();
217
+
218
+ if (( $impCE->insPostCount != 0) || ($impCE->dupPostCount != 0)) {
219
+ ?>
220
+ <div
221
+ style="background-color: #FFFFE0; border-color: #E6DB55; border-radius: 3px 3px 3px 3px; border-style: solid; border-width: 1px; margin: 5px 15px 2px; padding: 5px; text-align: center">
222
+ <b> <?php echo '('.$impCE->insPostCount.')'; ?> records are successfully Imported !<br> <?php echo '('.$impCE->dupPostCount.')'; ?> duplicate records found !
223
+ <?php if($impCE->noPostAuthCount != 0){ ?><br>
224
+ <?php echo $impCE->noPostAuthCount; ?> posts with no valid UserID/Name are assigned admin as author.
225
+ <?php
226
+ // ask and fill the error msg
227
+ }
228
+ ?></b>
229
+ </div>
230
+ <?php }else if(($impCE->insPostCount == 0) && ($impCE->dupPostCount == 0)){ ?>
231
+ <div
232
+ style="background-color: #FFFFE0; border-color: #E6DB55; border-radius: 3px 3px 3px 3px; border-style: solid; border-width: 1px; margin: 5px 15px 2px; padding: 5px; text-align: center">
233
+ <b> Check your CSV file and format. </b>
234
+ </div>
235
+ <?php } ?>
236
+ <div style="margin-top: 30px; margin-left: 10px">
237
+ <form class="add:the-list: validate" method="post"
238
+ enctype="multipart/form-data">
239
+ <input type="submit" class='button-primary' id="goto" name="goto"
240
+ value="Continue" />
241
+ </form>
242
+ </div>
243
+ <?php
244
+
245
+ } else {
246
+ ?>
247
+ <div class="wrap">
248
+ <?php echo renderTop(); ?>
249
+
250
+ <div style="min-width: 45%; float: left; height: 500px;">
251
+ <h2><?php echo $impCE->t('IMPORT_CSV_FILE'); ?></h2>
252
+ <form class="add:the-list: validate" method="post"
253
+ enctype="multipart/form-data" onsubmit="return file_exist();">
254
 
255
  <!-- File input -->
256
+ <p>
257
+ <label for="csv_import"><?php echo $impCE->t('UPLOAD_FILE'); ?>:</label><br />
258
+ <input name="csv_import" id="csv_import" type="file" value=""
259
+ required="required" />
 
 
 
 
 
 
260
  </p>
261
+ <br />
262
+ <p>
263
+ <input type="checkbox" name="titleduplicatecheck" value=1> <?php echo $impCE->t("ENABLE_DUPLICATION_POST_TITLE"); ?><br>
264
+
265
+
266
+ <p>
267
+ <input type="checkbox" name="contentduplicatecheck" value=1> <?php echo $impCE->t("ENABLE_DUPLICATION_POST_CONTENT"); ?> <br>
268
+ <!-- added above checkboxes for issueid 1057-->
269
+
270
+ <p>
271
+ <label id="duplicatehint" style="color:red;" ><?php echo $impCE->t("ENABLE_DUPLICATION_HINT");?></label>
272
+ <br>
273
 
274
+ <p>
275
+ <label>Delimiter</label>&nbsp;&nbsp;&nbsp; <select name="delim"
276
+ id="delim">
277
+ <option value=",">,</option>
278
+ <option value=";">;</option>
279
+ </select>
280
+ </p>
281
+
282
+ <p class="submit">
283
+ <input type="submit" class="button-primary" name="Import"
284
+ value="Import" />
285
+ </p>
286
+ </form>
287
+ </div>
288
+ <div style="min-width: 45%;">
289
+ <?php print(renderDesc()); ?>
290
+ </div>
291
+ </div>
292
+ <!-- end wrap -->
293
+ <?php
294
  }
295
  }
296
 
297
+
298
+ /**
299
+ * Function to display the plugin home description
300
+ */
301
+ function renderDesc() {
302
+ return "<p>WP Ultimate CSV Importer Plugin helps you to manage the post,page and </br> custom post data's from a CSV file.</p>
303
+ <p>1. Admin can import the data's from any csv file.</p>
304
+ <p>2. Can define the type of post and post status while importing.</p>
305
+ <p>3. Provides header mapping feature to import the data's as your need.</p>
306
+ <p>4. Users can map coloumn headers to existing fields or assign as custom fileds.</p>
307
+ <p>5. Import unlimited datas as post.</p>
308
+ <p>6. Make imported post as published or make it as draft.</p>
309
+ <p>7. Added featured image import functionality.</p>
310
+ <p><b> Important Note:- </b></p>
311
+ <p><span style='color:red;'>1. Your csv should have the seperate column for post_date.
312
+ <br/>2. It must be in the following format. ( yyyy-mm-dd hh:mm:ss ).</span></p>
313
+ <p>Configuring our plugin is as simple as that. If you have any questions, issues and request on new features, plaese visit <a href='http://www.smackcoders.com/blog/category/free-wordpress-plugins' target='_blank'>Smackcoders.com blog </a></p>
314
+ <div align='center' style='margin-top:40px;'> 'While the scripts on this site are free, donations are greatly appreciated. '<br/><br/><a href='http://www.smackcoders.com/donate.html' target='_blank'><img src='" . WP_CONTENT_URL . "/plugins/wp-ultimate-csv-importer/images/paypal_donate_button.png' /></a><br/><br/><a href='http://www.smackcoders.com/' target='_blank'><img src='http://www.smackcoders.com/wp-content/uploads/2012/09/Smack_poweredby_200.png'></a>
315
+ </div><br/>";
316
+ }
317
+
318
+ /**
319
+ * To render the top section
320
+ */
321
+ function renderTop() {
322
+ return "<marquee onmouseover=\"this.setAttribute('scrollamount', 0, 0);\" onmouseout=\"this.setAttribute('scrollamount', 6, 0);\" >Now the <a href='http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html' target='_blank'>Pro Version</a> is Available. For more details,please visit <a href='http://www.smackcoders.com/wp-ultimate-csv-importer-pro.html' target='_blank'>here</a></marquee>
323
+ <div style='background-color: #FFFFE0;border-color: #E6DB55;border-radius: 3px 3px 3px 3px;border-style: solid;border-width: 1px;margin: 5px 15px 2px; margin-top:15px;padding: 5px;text-align:center'> Please check out <a href='http://www.smackcoders.com/blog/category/free-wordpress-plugins' target='_blank'>www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>";
324
+ }
325
+
326
  ?>