Ultimate CSV Importer - Version 1.0.0

Version Description

Download this release

Release Info

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

Version 1.0.0

Readme.txt ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Wp Ultimate CSV Importer Plugin ===
2
+ Contributors: Smackcoders
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=fenzik@gmail.com&lc=JP&item_name=WordPress%20Plugins&item_number=wp%2dplugins&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
4
+ Tags: batch, excel, import, spreadsheet, plugin, admin, csv, importer,
5
+ Requires at least: 3.4
6
+ Tested up to: 3.4.2
7
+ Stable tag: 1.0.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ A plugin that helps to import any csv file as post, page or custom post data's by matching csv headers to wp fields.
12
+
13
+
14
+ == Description ==
15
+
16
+ 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.
17
+
18
+ 1. Admin can import the data's from any csv file.
19
+ 2. Can define the type of post and post status while importing.
20
+ 3. Provides header mapping feature to import the data's as your need.
21
+ 4. Users can map coloumn headers to exixting fields or assign as custom fileds.
22
+ 5. Import unlimited datas as post.
23
+ 6. Make imported post as published or make it as draft.
24
+
25
+
26
+ Support and Feature requests.
27
+ ----------------------------
28
+ Please visit http://www.smackcoders.com/category/free-wordpress-plugins.html for guides and tutorials. Please mail us to wpsupport@smackcoders.com for any timely support or feature request. Support at wordpress is not possible for now.
29
+
30
+
31
+ == Installation ==
32
+
33
+ Wp Ultimate CSV Importer is very easy to install like any other wordpress plugin. No need to edit or modify anything here.
34
+
35
+ 1. Unzip the file 'wp-ultimate-csv-importer.zip'.
36
+ 2. Upload the ' wp-ultimate-csv-importer ' directory to '/wp-content/plugins/' directory using ftp client or upload and install wp-ultimate-csv-importer.zip through plugin install wizard in wp admin panel .
37
+ 3. Activate the plugin through the 'Plugins' menu in WordPress.
38
+ 4. After activating, you will see an option for 'Wp Ultimate CSV Importer' in the admin menu (left navigation) and you will import the csv files to import the data's.
39
+
40
+
41
+ == Screenshots ==
42
+
43
+ 1. Admin settings for Wp Ultimate CSV Importer Plugin .
44
+ 2. Admin settings for Import Data and Header Mapping configutration to import data's from a csv file.
45
+
46
+
47
+ == Changelog ==
48
+
49
+ 1.0.0
50
+
51
+ Initial release version. Tested and found works well without any issues.
52
+
53
+
54
+ == Upgrade Notice ==
55
+
56
+ Initial release of plugin v1.0.0
57
+
58
+
59
+ == Frequently Asked Questions ==
60
+
61
+ 1. How to install the plugin?
62
+ Like other plugins wp-ultimate-csv-importer is easy to install. Upload the wp-ultimate-csv-importer.zip file through plugin install page through wp admin. Everything will work fine with it.
63
+
64
+ 2. How to use the plugin?
65
+
66
+ After plugin activation you can see the ' Wp Ultimate CSV Importer ' menu in admin backend.
67
+
68
+ 1. Browse csv file to import the data's.
69
+ 2. You can mapping the headers to import the data's.
70
+ 3. If you checked the import as draft,it will import as draft then you can publish the data's later.
71
+ 4. The data's are imported based on the post type you selected.
72
+
73
+ Configuring our plugin is as simple as that.
74
+
75
+
76
+ Please use support section in wordpress itself for any further queries and feature request.
77
+
78
+
images/paypal_donate_button.png ADDED
Binary file
imported_csv/readme.txt ADDED
File without changes
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
wp_ultimate_csv_importer.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // Function for add customfield
3
+
4
+ function addcustomfield(){
5
+ var a = document.getElementById('h1').value;
6
+ var aa = document.getElementById('h2').value;
7
+ for(i=0;i<aa;i++){
8
+ var b = document.getElementById('mapping'+i).value;
9
+ if(b=='add_custom'+i){
10
+ document.getElementById('textbox'+i).style.display="";
11
+ }
12
+ else{
13
+ document.getElementById('textbox'+i).style.display="none";
14
+ }
15
+ }
16
+ }
17
+
18
+ // Function for check file exist
19
+
20
+ function file_exist(){
21
+
22
+ if(document.getElementById('csv_import').value==''){
23
+ return false;
24
+ }
25
+ else{
26
+ return true;
27
+ }
28
+ }
wp_ultimate_csv_importer.php ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ *Plugin Name: Wp Ultimate CSV Importer
4
+ *Plugin URI: http://www.smackcoders.com/category/free-wordpress-plugins.html
5
+ *Description: A plugin that helps to import the data's from a CSV file.
6
+ *Version: 1.0.0
7
+ *Author: smackcoders.com
8
+ *Author URI: http://www.smackcoders.com
9
+ *
10
+ * Copyright (C) 2012 Fredrick SujinDoss.M (email : fredrickm@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/category/free-wordpress-plugins.html
26
+
27
+ ***********************************************************************************************
28
+ */
29
+
30
+
31
+ // Global variable declaration
32
+ global $data_rows;
33
+ $data_rows = array();
34
+ global $headers ;
35
+ $headers = array();
36
+ global $defaults;
37
+ global $wpdb;
38
+ global $keys;
39
+
40
+ // Get the custom fields
41
+ $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
42
+ $keys = $wpdb->get_col( "
43
+ SELECT meta_key
44
+ FROM $wpdb->postmeta
45
+ GROUP BY meta_key
46
+ HAVING meta_key NOT LIKE '\_%'
47
+ ORDER BY meta_key
48
+ LIMIT $limit" );
49
+ // Default header array
50
+ $defaults = array(
51
+ 'post_title' => null,
52
+ 'post_content' => null,
53
+ 'post_excerpt' => null,
54
+ 'post_date' => null,
55
+ 'post_tags' => null,
56
+ 'post_categories' => null,
57
+ 'post_author' => null,
58
+ 'post_parent' => 0,
59
+ );
60
+ foreach($keys as $val){
61
+ $defaults[$val]=$val;
62
+ }
63
+ // Admin menu settings
64
+ function wp_ultimate_csv_importer() {
65
+ add_menu_page('CSV importer settings', 'Wp Ultimate CSV Importer', 'manage_options',
66
+ 'upload_csv_file', 'upload_csv_file');
67
+ }
68
+
69
+ add_action("admin_menu", "wp_ultimate_csv_importer");
70
+ wp_enqueue_script("upload_csv_file", site_url()."/wp-content/plugins/wp-ultimate-csv-importer/wp_ultimate_csv_importer.js", array("jquery"));
71
+
72
+ // Plugin description details
73
+ function description(){
74
+ $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>
75
+ <p>
76
+ 1. Admin can import the data's from any csv file.
77
+ </p>
78
+ <p>
79
+ 2. Can define the type of post and post status while importing.
80
+ </p>
81
+ <p>
82
+ 3. Provides header mapping feature to import the data's as your need.
83
+ </p>
84
+ <p>
85
+ 4. Users can map coloumn headers to exixting fields or assign as custom fileds.
86
+ </p>
87
+ <p>
88
+ 5. Import unlimited datas as post.
89
+ </p>
90
+ <p>
91
+ 6. Make imported post as published or make it as draft.
92
+ </p>
93
+ <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/category/free-wordpress-plugins.html' target='_blank'>Smackcoders.com Blog </a></p>
94
+
95
+ <div align='center' style='margin-top:40px;'> 'While the scripts on this site are free, donations are greatly appreciated. '<br/><br/><a href='https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=fenzik@gmail.com&lc=JP&item_name=WordPress%20Plugins&item_number=wp%2dplugins&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted' target='_blank'><img src='".site_url()."/wp-content/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>
96
+ </div><br/>";
97
+ return $string;
98
+ }
99
+
100
+ // CSV File Reader
101
+ function csv_file_data($file)
102
+ {
103
+ global $data_rows;
104
+ global $headers;
105
+ $resource = fopen($file, 'r');
106
+ while ($keys = fgetcsv($resource)) {
107
+ if ($c == 0) {
108
+ $headers = $keys;
109
+ } else {
110
+ array_push($data_rows, $keys);
111
+ }
112
+
113
+ $c ++;
114
+ }
115
+ fclose($resource);
116
+ }
117
+
118
+ // Move file
119
+ function move_file()
120
+ {
121
+ $uploads_dir = getcwd ().'/../wp-content/plugins/wp-ultimate-csv-importer/imported_csv';
122
+ if ($_FILES["csv_import"]["error"] == 0) {
123
+ $tmp_name = $_FILES["csv_import"]["tmp_name"];
124
+ $name = $_FILES["csv_import"]["name"];
125
+ move_uploaded_file($tmp_name, "$uploads_dir/$name");
126
+ }
127
+ }
128
+
129
+ // Remove file
130
+ function fileDelete($filepath,$filename) {
131
+ $success = FALSE;
132
+ if (file_exists($filepath.$filename)&&$filename!=""&&$filename!="n/a") {
133
+ unlink ($filepath.$filename);
134
+ $success = TRUE;
135
+ }
136
+ return $success;
137
+ }
138
+
139
+ // Mapping the fields and upload data's
140
+ function upload_csv_file()
141
+ {
142
+ global $headers;
143
+ global $data_rows;
144
+ global $defaults;
145
+ global $keys;
146
+ global $custom_array;
147
+ $custom_array = array();
148
+ if(isset($_POST['Import']))
149
+ {
150
+ csv_file_data($_FILES['csv_import']['tmp_name']);
151
+ move_file();
152
+ ?>
153
+ <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://smackcoders.com/category/free-wordpress-plugins.html" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
154
+
155
+ <div style="float:left;min-width:45%">
156
+ <form class="add:the-list: validate" method="post">
157
+ <h3>Import Data Configuration</h3>
158
+ <div style="margin-top:30px;>
159
+ <input name="_csv_importer_import_as_draft" type="hidden" value="publish" />
160
+ <label><input name="csv_importer_import_as_draft" type="checkbox" <?php if ('draft' == $opt_draft) { echo 'checked="checked"'; } ?> value="draft" /> Import as drafts </label>&nbsp;&nbsp;
161
+ </p>
162
+ <label> Select Post Type </label>&nbsp;&nbsp;
163
+ <select name='csv_importer_cat'>
164
+ <?php
165
+ $post_types=get_post_types();
166
+ foreach($post_types as $key => $value){
167
+ if(($value!='attachment') && ($value!='revision') && ($value!='nav_menu_item')){ ?>
168
+ <option id="<?php echo($value);?>" name="<?php echo($value);?>"> <?php echo($value);?> </option>
169
+ <?php }
170
+ }
171
+ ?>
172
+ <select>
173
+ <br/></div><br/>
174
+ <h3>Mapping the Fields</h3>
175
+ <div id='display_area'>
176
+ <?php $cnt =count($defaults)+2; $cnt1 =count($headers); ?>
177
+ <input type="hidden" id="h1" name="h1" value="<?php echo $cnt; ?>"/>
178
+ <input type="hidden" id="h2" name="h2" value="<?php echo $cnt1; ?>"/>
179
+ <table>
180
+ <?php
181
+ $count = 0;
182
+ foreach($headers as $key=>$value){
183
+ ?>
184
+ <tr>
185
+ <td>
186
+ <label><?php print($value);?></label>
187
+ </td>
188
+ <td>
189
+ <select name="mapping<?php print($count);?>" id="mapping<?php print($count);?>" class ='uiButton' onchange="addcustomfield();">
190
+ <option id="select" name="select">-- Select --</option>
191
+ <?php
192
+ foreach($defaults as $key1=>$value1){
193
+ ?>
194
+ <option value ="<?php print($key1);?>"><?php print($key1);?></option>
195
+ <?php }
196
+ ?>
197
+ <option value="add_custom<?php print($count);?>">Add Custom Field</option>
198
+ </select>
199
+ <input type="text" id="textbox<?php print($count); ?>" name="textbox<?php print($count); ?>" style="display:none;"/>
200
+ </td>
201
+ </tr>
202
+ <?php
203
+ $count++; }
204
+ ?>
205
+ </table>
206
+ </div><br/>
207
+ <input type='hidden' name='filename' id='filename' value="<?php echo($_FILES['csv_import']['name']);?>" />
208
+ <input type='submit' name= 'post_csv' value='Import' />
209
+ </form>
210
+ </div>
211
+ <div style="min-width:45%;">
212
+ <?php $result = description(); print_r($result); ?>
213
+ </div>
214
+ <?php
215
+ }
216
+ else if(isset($_POST['post_csv']))
217
+ {
218
+ $dir = getcwd ().'/../wp-content/plugins/wp-ultimate-csv-importer/imported_csv/';
219
+ csv_file_data($dir.$_POST['filename']);
220
+ foreach($_POST as $postkey=>$postvalue){
221
+ if($postvalue != '-- Select --'){
222
+ $ret_array[$postkey]=$postvalue;
223
+ }
224
+ }
225
+ foreach($data_rows as $key => $value){
226
+ for($i=0;$i<count($value) ; $i++)
227
+ {
228
+ if(array_key_exists('mapping'.$i,$ret_array)){
229
+ if($ret_array['mapping'.$i]!='add_custom'.$i){
230
+ $new_post[$ret_array['mapping'.$i]] = $value[$i];
231
+ }
232
+ else{
233
+ $new_post[$ret_array['textbox'.$i]] = $value[$i];
234
+ $custom_array[$ret_array['textbox'.$i]] = $value[$i];
235
+ }
236
+ }
237
+ }
238
+ for($inc=0;$inc<count($value);$inc++){
239
+ foreach($keys as $k => $v){
240
+ if(array_key_exists($v,$new_post)){
241
+ $custom_array[$v] =$new_post[$v];
242
+ }
243
+ }
244
+ /* if(array_key_exists('textbox'.$inc,$new_post)){
245
+ $custom_array['textbox'.$inc] =$new_post['textbox'.$inc];
246
+ }*/
247
+ }
248
+ foreach($new_post as $ckey => $cval){
249
+ if(array_key_exists($ckey,$custom_array)){
250
+ $darray[$ckey]=$new_post[$ckey];
251
+ }
252
+ else{
253
+ $data_array[$ckey]=$new_post[$ckey];
254
+ }
255
+ }
256
+ $data_array['post_status']='publish';
257
+ if(isset($_POST['csv_importer_import_as_draft'])){
258
+ $data_array['post_status']='draft';
259
+ }
260
+ $data_array['post_type']=$_POST['csv_importer_cat'];
261
+ $post_id = wp_insert_post( $data_array );
262
+ if(!empty($custom_array)){
263
+ foreach($custom_array as $custom_key => $custom_value){
264
+ add_post_meta($post_id, $custom_key, $custom_value);
265
+ }
266
+ }
267
+ }
268
+ ?>
269
+ <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> Successfully Imported ! </b></div>
270
+ <div style="margin-top:30px;margin-left:10px">
271
+ <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
272
+ <input type="submit" id="goto" name="goto" value="Continue" />
273
+ </form>
274
+ </div>
275
+ <?php
276
+ // Remove CSV file
277
+ if(file_exists($dir.$filename)){
278
+ $filename = $_POST['filename'];
279
+ chmod("$dir"."$filename", 755);
280
+ fileDelete($dir,$filename); //die;
281
+ }
282
+ }
283
+ else
284
+ {
285
+ ?>
286
+ <div class="wrap">
287
+ <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://smackcoders.com/category/free-wordpress-plugins.html" target="_blank">www.smackcoders.com</a> for the latest news and details of other great plugins and tools. </div><br/>
288
+ <div style="min-width:45%;float:left;height:500px;">
289
+ <h2>Import CSV</h2>
290
+ <form class="add:the-list: validate" method="post" enctype="multipart/form-data" onsubmit="return file_exist();">
291
+
292
+ <!-- File input -->
293
+ <p><label for="csv_import">Upload file:</label><br/>
294
+ <input name="csv_import" id="csv_import" type="file" value="" aria-required="true" /></p>
295
+ <p class="submit"><input type="submit" class="button" name="Import" value="Import" /></p>
296
+ </form>
297
+ </div>
298
+ <div style="min-width:45%;">
299
+ <?php $result = description(); print_r($result); ?>
300
+ </div>
301
+ </div><!-- end wrap -->
302
+ <?php
303
+ }
304
+ }
305
+
306
+ ?>