Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

export_yahoo.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: export_yahoo.php,v 1.3 2005/03/08 16:18:42 ghb Exp $
5 //
6 // Created on: <22-Jun-2001 13:16:55 br>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2005 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27
29 // Includes : include the classes.
30 ob_end_clean();
31
32 // include_once( "classes/template.inc" );
33 include_once( "eztrade/classes/ezproduct.php" );
34 include_once( "classes/INIFile.php" );
35
36 //
38
40 // increse php execution time to allow for long running scripts (re: ftp connections)
41 ini_set("max_execution_time", 300);
42 ini_set('upload_max_filesize', 5242880); // 5MB
43
45 // Settings
46
47 $ini =& eZINI::instance( 'site.ini' );
48
49 $SiteURL = $ini->variable( "site", "UserSiteURL" );
50 $wwwDir = $ini->variable( "site", "UserSiteURL" );
51 $PricesIncludeVAT = $ini->variable( "eZTradeMain", "PricesIncludeVAT" ) == "enabled" ? true : false;
52 $MainImageWidth = $ini->variable( "eZTradeMain", "MainImageWidth" );
53 $MainImageHeight = $ini->variable( "eZTradeMain", "MainImageHeight" );
54 $SitePath = $ini->variable( "site", "SitePath" );
55
56
58 // FTP: Server, User, Password
59
60 // use file location + name
61 //$YahooServer = $ini->variable( "site", "ServerYahoo" );
62 //$YahooUser = $ini->variable( "site", "UserYahoo" );
63 //$froogle_pass = $ini->variable( "site", "PasswordYahoo" );
64
65 $YahooServer="hedwig.google.com";
66 $YahooUser="fullthrottle";
67 $YahooKey="key";
68
69 $YahooServer="fullthrottle.com";
70 $YahooServerPort="21";
71 $YahooUser="full";
72 $YahooKey="key";
73
74 if( $Action == "export" ){
75 $exportCSVFile = true;
76 } elseif( $Action == "export-cron" ) {
77 // export : csv file to user agent
78 $exportCSVFile = false;
79 } else {
80 $exportCSVFile = false;
81 }
82
83 // if( $Action == "export-cron" ) {
84 // export : csv file to user agent
85 // $exportCSVFile = false;
86 // }
87
88
90 // Build Product Export Data
91
92 // if ($exportCSVFile){
93
94 $product = new eZProduct();
95 $productList = $product->activeProducts( "time", 0, "" );
96
97
98 // Build Feed Header (Yahoo)
99 // $feed_froogle_header = "product_url\t name\t description\t price\t image_url\t category\n";
100
101 $feed = "code\t product-url\t name\t price\t merchant-category\t description\t image-url\n";
102
103 // $feed_yahoo_header_extended = "code\t product-url\t name\t price\t merchant-category\t description\t image-url\t isbn\t medium\t condition\t classification\t availability\t ean\t weight\t upc\t manufacturer\t manufacturer-part-no\t model-no\n";
104
105 /* Example of original rules (problems-inside)
106
107 $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
108 "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
109 "'([\r\n])[\s]+'", // Strip out white space
110 "'[\r\n\s]+'",
111 "'&(quot|#34);'i", // Replace HTML entities
112 "'&(amp|#38);'i",
113 "'&(lt|#60);'i",
114 "'&(gt|#62);'i",
115 "'&(nbsp|#160);'i",
116 "'&(iexcl|#161);'i",
117 "'&(cent|#162);'i",
118 "'&(pound|#163);'i",
119 "'&(copy|#169);'i",
120 "'&#(\d+);'e"); // evaluate as php
121
122 $replace = array ("",
123 "",
124 "\\1",
125 "\"",
126 "&",
127 "<",
128 ">",
129 " ",
130 chr(161),
131 chr(162),
132 chr(163),
133 chr(169),
134 "chr(\\1)");
135 */
136
137 // these string patters might cause space to " problems
138
139 // "'([\r\n])[\s]+'", // Strip out white space
140 // "'[\r\n\s]+'",
141
142 // "\\1",
143 // "\"",
144
145 // replace the previous string patterns with these values (ordered list)
146 $replace = array ("",
147 "",
148 "&",
149 "<",
150 ">",
151 " ",
152 chr(161),
153 chr(162),
154 chr(163),
155 chr(169),
156 "chr(\\1)");
157
158 // patterns
159 $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
160 "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
161 "'([\r\n])[\s]+'", // Strip out white space
162 "'\n'i",
163 "'\r\n'i",
164 "'\r'i",
165 "'&(quot|#34);'i", // Replace HTML entities
166 "'&(amp|#38);'i",
167 "'&(lt|#60);'i",
168 "'&(gt|#62);'i",
169 "'&(nbsp|#160);'i",
170 "'&(iexcl|#161);'i",
171 "'&(cent|#162);'i",
172 "'&(pound|#163);'i",
173 "'&(copy|#169);'i",
174 "'&#(\d+);'e"); // evaluate as php
175
176 $replace = array ("",
177 "",
178 "\\1",
179 "",
180 "",
181 "",
182 "&",
183 "<",
184 ">",
185 " ",
186 chr(161),
187 chr(162),
188 chr(163),
189 chr(169),
190 "chr(\\1)");
191
192 // prepare each product information
193 foreach ($productList as $product)
194 {
195 // product exclusion (by product id, _not_ category)
196 if ( $product->id() != 1126 ) {
197
198 // $line['product_idl'] = $product->productNumber();
199 $line['product_id'] = $product->id();
200
201 $line['product_url'] = "http://" . $wwwDir . "/trade/productview/" . $product->id() . "/";
202
203 $line['name'] = html_entity_decode( $product->name() ) ." - ". $product->productNumber();
204 // print($line['name']);
205
206 // this line causes "" in product name, so we are removing it
207 $line['name'] = preg_replace($search, $replace, $line['name']);
208 // $line['name'] = $line['name'];
209
210 // not sure why this is commented out? no tax in price?
211 // $line['price'] = str_replace( "$&nbsp;", "", $product->localePrice( $PricesIncludeVAT ) );
212 $line['price'] = $product->price();
213
214 $category = $product->categoryDefinition();
215 $pathArray =& $category->path();
216 $line['category'] = "";
217 $i = 1;
218
219 foreach ( $pathArray as $path )
220 {
221 $line['category'] .= $path[1];
222 if ( $i != count($pathArray) )
223 $line['category'] .= " > ";
224 $i++;
225 }
226
227 $line['description'] = html_entity_decode($product->brief());
228
229 $line['description'] = preg_replace($search, $replace, $line['description']);
230 // $line['description'] = $line['description'];
231
232 $mainImage = $product->mainImage();
233 if ( $mainImage )
234 {
235 $variation =& $mainImage->requestImageVariation( $MainImageWidth, $MainImageHeight );
236 $line['image_url'] = "http://" . $SiteURL . "/" . $variation->imagePath();
237 }
238 else
239 $line['image_url'] = "";
240
241 // Yahoo Extended Product Fields
242 // isbn\t medium\t condition\t classification\t availability\t ean\t weight\t upc\t manufacturer\t manufacturer-part-no\t model-no\n";
243
244 // Product IBSN (Books)
245 $line['ibsn'] = "";
246
247 // Product Medium
248 $line['medium'] = "";
249
250 // Product Condition
251 $line['condition'] = "";
252
253 // Product Classification
254 $line['classification'] = "";
255
256 // Product Availablity
257 $line['availablity'] = "";
258
259 // Product " ean "
260 $line['ean'] = "";
261
262 // Product Weight
263 $line['weight'] = "";
264
265 // Product UPC
266 $line['upc'] = "";
267
268 // Product Brand
269 $line['brand'] = "";
270
271 // Product Manufacturer
272 $line['manufacturer'] = "";
273
274 // Product Manufacturer Part No
275 $line['manufacturer-part-no'] = "";
276
277 // Product Model No
278 $line['model-no'] = "";
279
280 // Product Size
281 $line['size'] = "";
282
283 // Product Color
284 $line['color'] = "";
285
286 // Product Sale Price
287 $line['sale_price'] = "";
288
289 // Product msrp (The manufacturer's suggested retail price)
290 $line['msrp'] = "";
291
292 // Product 'In-Stock'
293 $line['in-stock'] = "";
294
295 // Product Promotion Text
296 $line['promo-text'] = "";
297
298 // Product Shipping Price
299 $line['shipping-price'] = "";
300
301 // Product Shipping Weight
302 $line['shipping-weight'] = "";
303
304 // Product shipping-surcharge
305 $line['shipping-surcharge'] = "";
306
307 // Product shipping-class
308 $line['shipping-class'] = "";
309
310 // Product Size
311 $line['size'] = "";
312
313 // Product Size
314 $line['size'] = "";
315
316 // Product Size
317 $line['size'] = "";
318
319
320
321 // Build Feed (Minimal)
322 // $feed_header = "code\t product-url\t name\t price\t merchant-category\t description\t image-url\n";
323
324 $feed .=
325 $line['product_id'] . "\t" .
326 $line['product_url'] . "\t" .
327 $line['name'] . "\t" .
328 $line['price'] . "\t" .
329 $line['category'] . "\t" .
330 $line['description'] . "\t" .
331 $line['image_url'] . "\n" ;
332
333 // $line['medium'] . "\n";
334 }
335
336 }
337
338 $file = new eZFile();
339 $file->dumpYahooDataToFile( $feed, "data.txt" );
340
341 $fileName = $file->tmpName();
342 $fileSize = filesize( $fileName );
343
344 chmod( $fileName, 0644 );
345
346 // unlink ( "/home/full/public_html/export_froogle/");
347 // unlink ( "/home/full/public_html/export_yahoo/");
348
349 $fp = fopen( $fileName, "r" );
350 $content =& fread( $fp, $fileSize );
351
352
353
354
355 /*
357 }
358 else {
359 // fake file
360 // $file = new eZFile();
361 // $file->dumpDataToFile( $feed, "fullthrottle.txt" );
362
363 // $fileName = $file->tmpName();
364 // $fileSize = filesize( $fileName );
365
366 //$fileName = $SitePath . '/export_froogle/attQ98AJz';
367 $fileName = $SitePath . '/export_yahoo/attQ98AJz';
368
369 $fileSize = filesize( $fileName );
370 //chmod( $fileName, 0777 );
371
372 // $fp = fopen( $fileName, "r" );
373 // $content =& fread( $fp, $fileSize );
374 }
376 */
377
378
379
380
382 // export to a file instead.... else, export to a file and ftp instead....
383 if( $exportCSVFile ){
384 header( "Cache-Control:" );
385 header( "Content-Length: $fileSize" );
386 header( "Content-disposition: attachment; filename=data.txt" );
387 header( "Content-Transfer-Encoding: binary" );
388
389 echo($content);
390 unlink( $file->tmpName() );
391 } else {
392 $source_file_name = $fileName;
393
394
395 // $destination_file = "/trash/fullthrottle.txt";
396
397 /*
398 $source_fp = fopen( $source_file_name , 'r');
399 $source_c =& fread( $source_fp, $fileSize );
400 */
401
402 // die($source_c);
403
404
405 // begin debug / log output
406 echo "\n ############################################################### \n";
407
408 include_once("classes/ezdatetime.php");
409
410 $date = new eZDateTime();
411 $month = $date->month();
412 $day = $date->day();
413 $year = $date->year();
414 $hour = $date->addZero($date->hour());
415 $minute = $date->addZero($date->minute());
416
417 $date = "$month".'/'."$day".'/'."$year".' | '."$hour".' : '."$minute";
418 echo "Date : $date \n";
419 echo "CSV : Exponential Basic (trade) Product : Export File : ($fileSize kb) : $fileName \n";
420
421
423 // if ( isset( $dfile ) )
424 // {
425 // save the buffer contents
426
427 // echo "Run: $SitePath/bin/cron/yahoo_upload.sh $SitePath/export_yahoo/attQ98AJz \n";
428 echo "Run: $SitePath/bin/cron/yahoo_upload.sh $fileName \n";
429
430 /*
431 $buffer =& ob_get_contents();
432 ob_end_clean();
433
434 // fetch the system printout
435 ob_start();
436 */
437
438 // $SitePath
439 // system( "$SitePath/bin/cron/yahoo_upload.sh $SitePath/export_yahoo/attQ98AJz" );
440
441 system( "$SitePath/bin/cron/yahoo_upload.sh $fileName" );
442
443
444 /*
445 $ret = ob_get_contents();
446 ob_end_clean();
447
448 // fill the buffer with the old values
449 ob_start();
450 print( $buffer );
451 // }
452
453 */
454
455
456 // echo " \n";
457 // print("end of file\n\n");
459
460 // unlink export file
461 unlink( $file->tmpName() );
462
463 }
464 exit();
465 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$pathArray
$pathArray
Definition: admin/adlist.php:74
$i
$i
Definition: admin/adlist.php:91
eZDateTime
Definition: ezdatetime.php:55
eZFile
Tool class which has convencience functions for files and directories.
Definition: ezfile.php:19
eZProduct
Definition: ezproduct.php:71
$Action
$Action
Definition: companysearch.php:80
$file
foreach($productList as $product) $file
Definition: export_yahoo.php:338
$minute
$minute
Definition: export_yahoo.php:415
$feed
$feed
Definition: export_yahoo.php:101
$YahooServer
$YahooServer
Definition: export_yahoo.php:65
$MainImageWidth
$MainImageWidth
Definition: export_yahoo.php:52
$YahooUser
$YahooUser
Definition: export_yahoo.php:66
$wwwDir
$wwwDir
Definition: export_yahoo.php:50
$SitePath
$SitePath
Definition: export_yahoo.php:54
$fp
$fp
Definition: export_yahoo.php:349
$YahooKey
$YahooKey
Definition: export_yahoo.php:67
$SiteURL
$SiteURL
Definition: export_yahoo.php:49
$MainImageHeight
$MainImageHeight
Definition: export_yahoo.php:53
$date
$date
Definition: export_yahoo.php:410
$day
$day
Definition: export_yahoo.php:412
$hour
$hour
Definition: export_yahoo.php:414
$content
$content
Definition: export_yahoo.php:350
$PricesIncludeVAT
$PricesIncludeVAT
Definition: export_yahoo.php:51
$product
$product
Definition: export_yahoo.php:94
$fileName
$fileName
Definition: export_yahoo.php:341
$month
$month
Definition: export_yahoo.php:411
$year
$year
Definition: export_yahoo.php:413
$ini
$ini
Definition: export_yahoo.php:47
$fileSize
$fileSize
Definition: export_yahoo.php:342
$YahooServerPort
$YahooServerPort
Definition: export_yahoo.php:70
$search
$search
Definition: export_yahoo.php:159
$replace
$replace
Definition: export_yahoo.php:146
$productList
$productList
Definition: export_yahoo.php:95
$variation
$variation
Definition: ezimagecatalogue/user/menubox.php:55
exit
exit
Definition: folder.php:81
$mainImage
foreach( $pathArray as $path) $mainImage
Definition: productpreview.php:167
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.