forked from mtb24/Feeds
/
parse_googlebase.php
executable file
·111 lines (93 loc) · 2.64 KB
/
parse_googlebase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
//////////////////////////////
//this is parse_googlebase.php
//////////////////////////////
//increased error reporting
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
//include our functions file
require_once('functions.php');
//name of the text datafile
$datafile = $feedSettings[0]['file'];
//open the file
$handle = fopen($datafile, "r");
//////////////////////////////
if($handle){
//empty the ONLINE_LISTINGS table
emptyTable('ONLINE_LISTINGS');
$count = 0;
$shipping_deal_count = 0;
///////////////////////
// loop through line by line, and do any text processing required
while( ($line = fgets($handle, 4096) ) !== false){
$exploded_tab_array = explode("\t", trim($line) );
//echo "<pre>";
//var_dump($exploded_tab_array);
//echo '</pre><br>';
$shipping = "";
$gender = '';
$age_group = '';
//assign some reference variables
$link = $exploded_tab_array[0];
$condition = $exploded_tab_array[1];
$brand = $exploded_tab_array[2];
$title = stripHTML($exploded_tab_array[3]);
$title = str_replace(',','',$title);
$description = stripHTML($exploded_tab_array[4]);
$description = str_replace(',','',$description);
$image_link = $exploded_tab_array[5];
$product_type = $exploded_tab_array[6];
$google_product_category = $exploded_tab_array[7];
$price = $exploded_tab_array[8];
$availability = $exploded_tab_array[9];
$expiration_date = $exploded_tab_array[10];
$id = $exploded_tab_array[11];
$mpn = $exploded_tab_array[12];
$gtin = $exploded_tab_array[13];
$color = $exploded_tab_array[14];
$size = $exploded_tab_array[15];
$shipping_weight = $exploded_tab_array[16];
(in_array($mpn, $freeShippingByMPN)) ? $shipping = 'US:::0.00 USD' : $shipping = '';
///////////////
//hack so we don't insert the first line
if($count > 0){
//call our function to add a new Item and get back the InsertID
$item_id = insertNewOnlineListing(
$link,
$condition,
$brand,
$title,
$description,
$image_link,
$product_type,
$google_product_category,
$price,
$availability,
$expiration_date,
$id,
$mpn,
$gtin,
$color,
$size,
$shipping_weight,
$shipping,
$gender,
$age_group);
}
//incremement the counter
$count++;
///////////////
}
///////////////////////
//error check
if( !feof($handle) ){
echo "Error: unexpected fgets() fail\n";
}
///////////////////////
fclose($handle);
// store item count
storeItemCount('SE', $count);
}
//all done!
echo '<br />Finished processing SE file! - '.$count.' items<br /><br />';
?>