| 1 |
lars |
1 |
<?
|
|
|
2 |
function getZipFileList( $zipfile, $filter = "", $returnString = false)
|
|
|
3 |
{
|
|
|
4 |
$cmd = "unzip -l $zipfile $filter";
|
|
|
5 |
echo $cmd."\n";
|
|
|
6 |
exec($cmd, $returnValue);
|
|
|
7 |
if ($returnString)
|
|
|
8 |
{
|
|
|
9 |
return implode($returnValue,"\n");
|
|
|
10 |
}
|
|
|
11 |
else
|
|
|
12 |
{
|
|
|
13 |
$returnValue = array_slice ($returnValue, 3, -2);
|
|
|
14 |
foreach($returnValue as $lineNr => $lineValue)
|
|
|
15 |
{
|
|
|
16 |
$buffer = preg_split("/\s+/", trim($lineValue));
|
|
|
17 |
$returnValue[$lineNr] = array
|
|
|
18 |
(
|
|
|
19 |
length => $buffer[0],
|
|
|
20 |
date => $buffer[1],
|
|
|
21 |
time => $buffer[2],
|
|
|
22 |
name => $buffer[3]
|
|
|
23 |
);
|
|
|
24 |
}
|
|
|
25 |
return $returnValue;
|
|
|
26 |
}
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/* ########################################################################################################### */
|
|
|
30 |
|
|
|
31 |
function getZipFileExtractedTo( $zipfile, $filename, $targetPath)
|
|
|
32 |
{
|
|
|
33 |
$filename = str_replace(" ", "\ ", $filename);
|
|
|
34 |
$filename = str_replace("(", "\(", $filename);
|
|
|
35 |
$filename = str_replace(")", "\)", $filename);
|
|
|
36 |
|
|
|
37 |
$cmd="unzip -joC $zipfile $filename -d $targetPath";
|
|
|
38 |
echo $cmd."\n";
|
|
|
39 |
preg_match
|
|
|
40 |
(
|
|
|
41 |
"/inflating:.*\/(.*?)$/",
|
|
|
42 |
exec($cmd),
|
|
|
43 |
$matches
|
|
|
44 |
);
|
|
|
45 |
echo "-> ".$matches[1]."\n";
|
|
|
46 |
return $matches[1];
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/* ########################################################################################################### */
|
|
|
50 |
|
|
|
51 |
function getZipFileContent( $zipfile, $filename)
|
|
|
52 |
{
|
|
|
53 |
$cmd="unzip -p $zipfile $filename";
|
|
|
54 |
echo $cmd."\n";
|
|
|
55 |
exec($cmd, $returnValue);
|
|
|
56 |
return implode($returnValue,"\n");
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/* ########################################################################################################### */
|
|
|
60 |
|
|
|
61 |
function parseProdanetData($xml)
|
|
|
62 |
{
|
|
|
63 |
global $zipfile;
|
|
|
64 |
|
|
|
65 |
preg_match
|
|
|
66 |
(
|
|
|
67 |
"/<ProductRecord ProdanetEAN=\"(.*?)\">.*?(<Features>(.*?)<\/Features>)/",
|
|
|
68 |
$xml,
|
|
|
69 |
$matches
|
|
|
70 |
);
|
|
|
71 |
array_shift ($matches);
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
//Header verarbeiten
|
|
|
75 |
preg_match
|
|
|
76 |
(
|
|
|
77 |
"/<VersionNumber>(.*?)<\/VersionNumber>.*?<RevisionNumber>(.*?)<\/RevisionNumber>.*?<Timestamp>(.*?)<\/Timestamp>.*?<Country>(.*?)<\/Country>.*?<Sender>(.*?)<\/Sender>.*?<Receiver>(.*?)<\/Receiver>/",
|
|
|
78 |
$xml,
|
|
|
79 |
$header
|
|
|
80 |
);
|
|
|
81 |
array_shift ($header);
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
//Data verarbeiten
|
|
|
85 |
preg_match
|
|
|
86 |
(
|
|
|
87 |
"/<Brand>(.*?)<\/Brand>.*?<ProductName1>(.*?)<\/ProductName1>.*?<ProductName2>(.*?)<\/ProductName2>.*?<ProductColor>(.*?)<\/ProductColor>.*?<ProductGroupName>(.*?)<\/ProductGroupName>/",
|
|
|
88 |
$xml,
|
|
|
89 |
$data
|
|
|
90 |
);
|
|
|
91 |
array_shift ($data);
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
//Features verarbeiten
|
|
|
95 |
return
|
|
|
96 |
array
|
|
|
97 |
(
|
|
|
98 |
"Header" => array
|
|
|
99 |
(
|
|
|
100 |
"VersionNumber" => $header[0],
|
|
|
101 |
"RevisionNumber" => $header[1],
|
|
|
102 |
"Timestamp" => $header[2],
|
|
|
103 |
"Country" => $header[3],
|
|
|
104 |
"Sender" => $header[4],
|
|
|
105 |
"Receiver" => $header[5]
|
|
|
106 |
),
|
|
|
107 |
"ProductMasterRecordData" => array
|
|
|
108 |
(
|
|
|
109 |
"ProdanetEAN" => $matches[0],
|
|
|
110 |
"Brand" => $data[0],
|
|
|
111 |
"ProductName1" => $data[1],
|
|
|
112 |
"ProductName2" => $data[2],
|
|
|
113 |
"ProductColor" => $data[3],
|
|
|
114 |
"ProductGroupName" => $data[4],
|
|
|
115 |
"ProductImage" => getZipFileExtractedTo
|
|
|
116 |
(
|
|
|
117 |
$zipfile,
|
|
|
118 |
"*".$matches[0].".j*",
|
|
|
119 |
"/web/apache/pq-media.de/images/Bild_1/original"
|
|
|
120 |
)
|
|
|
121 |
),
|
|
|
122 |
"ProductFeatureRecord" => $matches[1]
|
|
|
123 |
);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/* ########################################################################################################### */
|
|
|
127 |
/* ########################################################################################################### */
|
|
|
128 |
/* ########################################################################################################### */
|
|
|
129 |
|
|
|
130 |
$zipfile = $_SERVER[argv][1] ;
|
|
|
131 |
|
|
|
132 |
mysql_connect("127.0.0.1:3306","content_managem","k-dp-u");
|
|
|
133 |
mysql_query ("use pq_media_de") or die (mysql_errno().": ".mysql_error());
|
|
|
134 |
|
|
|
135 |
foreach(getZipFileList($zipfile, "*.xml", false) as $productFile)
|
|
|
136 |
{
|
|
|
137 |
$data=parseProdanetData(getZipFileContent($zipfile, $productFile[name]));
|
|
|
138 |
|
|
|
139 |
$query="
|
|
|
140 |
insert into
|
|
|
141 |
artikel
|
|
|
142 |
(
|
|
|
143 |
Father,
|
|
|
144 |
Language,
|
|
|
145 |
kennung,
|
|
|
146 |
hersteller,
|
|
|
147 |
kurzbezeichnung,
|
|
|
148 |
langbezeichnung ,
|
|
|
149 |
bild_1_url,
|
|
|
150 |
beschreibung,
|
|
|
151 |
erstellt_am,
|
|
|
152 |
erstellt_von,
|
|
|
153 |
prodanetVersionNumber,
|
|
|
154 |
prodanetRevisionNumber,
|
|
|
155 |
prodanetTimestamp
|
|
|
156 |
)
|
|
|
157 |
values
|
|
|
158 |
(
|
|
|
159 |
1,
|
|
|
160 |
'".addslashes($data[Header][Country])."',
|
|
|
161 |
'".addslashes($data[ProductMasterRecordData][ProdanetEAN])."',
|
|
|
162 |
'".addslashes($data[ProductMasterRecordData][Brand])."',
|
|
|
163 |
'".addslashes($data[ProductMasterRecordData][ProductName1])."',
|
|
|
164 |
'".addslashes($data[ProductMasterRecordData][ProductName2])."',
|
|
|
165 |
'".addslashes($data[ProductMasterRecordData][ProductImage])."',
|
|
|
166 |
'".addslashes($data[ProductFeatureRecord])."',
|
|
|
167 |
NOW(),
|
|
|
168 |
'ProdaNet-Import',
|
|
|
169 |
'".addslashes($data[Header][VersionNumber])."',
|
|
|
170 |
'".addslashes($data[Header][RevisionNumber])."',
|
|
|
171 |
'".addslashes($data[Header][Timestamp])."'
|
|
|
172 |
)
|
|
|
173 |
";
|
|
|
174 |
print_r($query);
|
|
|
175 |
mysql_query ($query) or die (mysql_errno().": ".mysql_error()."\n\n".$query);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
function imageConvert($path="/web/apache/pq-media.de/images/Bild_1")
|
|
|
179 |
{
|
|
|
180 |
$original=$path."/original";
|
|
|
181 |
$handle=opendir($original);
|
|
|
182 |
|
|
|
183 |
while ($image = readdir ($handle))
|
|
|
184 |
{
|
|
|
185 |
if (is_file ($original."/".$image))
|
|
|
186 |
{
|
|
|
187 |
$image = str_replace(" ", "\ ", $image);
|
|
|
188 |
$image = str_replace("(", "\(", $image);
|
|
|
189 |
$image = str_replace(")", "\)", $image);
|
|
|
190 |
|
|
|
191 |
$cmd = array
|
|
|
192 |
(
|
|
|
193 |
"convert -scale 180x180 $original/$image $path/180x180/$image",
|
|
|
194 |
"convert -scale 120x120 $original/$image $path/120x120/$image",
|
|
|
195 |
"convert -scale 80x120 $original/$image $path/80x120/$image",
|
|
|
196 |
"convert -scale 30x30 $original/$image $path/30x30/$image",
|
|
|
197 |
"rm $original/$image"
|
|
|
198 |
);
|
|
|
199 |
foreach($cmd as $exec)
|
|
|
200 |
{
|
|
|
201 |
echo $exec."\n";
|
|
|
202 |
exec($exec);
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
closedir($handle);
|
|
|
208 |
}
|
|
|
209 |
imageConvert();
|
|
|
210 |
?>
|