Advertisement
Guest User

Untitled

a guest
May 16th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. $html = str_get_html(curl($infoLink));
  2. $product = new Product;
  3. $product->name = $html->find($prod_name, 0)->innertext;
  4. $product->systemName = preg_replace("![^a-z0-9]+!i", "_", $product->name);
  5. $product->infoLink = $infoLink;
  6. $product->designer = $html->find($label_name, 0)->innertext;
  7. $product->description = strip_tags($html->find($description, 0)->innertext);
  8. $product->price = strip_tags($html->find($price, 0)->innertext);
  9. $product->store = $store;
  10. $product->category = $general_cat;
  11. $product->spec_cat = $spec_cat;
  12. if(!is_null($mainImg)) {
  13.     $product->mainImage = $html->find($mainImg, 0)->src;
  14.     for ($idx = 0; $idx < 10; $idx++) {
  15.         $more = $html->find($more_imgs, $idx);
  16.         if (!is_null($more)) {
  17.             $product->moreImages[$idx] = $more->src;
  18.         } else {
  19.             return;
  20.         }
  21.     }
  22. } else {
  23.     for ($idx = 0; $idx < 10; $idx++) {
  24.         $more = $html->find($more_imgs, $idx);
  25.         if (($idx == 0) && (!is_null($more))) {
  26.             $product->mainImage = $more->src;
  27.         } elseif (!is_null($more)) {
  28.             $product->moreImages[$idx] = $more->src;
  29.         } else {
  30.             return;
  31.         }
  32.     }
  33. }
  34. $imageUrls = $product->moreImages;
  35. $imgs = 0;
  36. $imgDir = "img/".$store."/";
  37. $imgDirName = dirname($imgDir);
  38. if (!is_dir($imgDir)) {
  39.     mkdir($imgDirName, 0755, true);
  40. }
  41. $product->allImgPaths[0] = $imgDir.$product->systemName."_0.jpg";
  42. copy($product->mainImage, $imgDir.$product->systemName."_0.jpg");
  43. foreach ($imageUrls as $key => $value) {
  44.     $imgs++;
  45.     $fileName = (string)$product->systemName . "_" . $imgs . ".jpg";
  46.     copy($baseURL.$value, $imgDir . $fileName);
  47.     $product->allImgPaths[$imsgs] = $imgDir . "/" . $fileName;
  48. }
  49. // Write an individual JSON file
  50. $fileDir = 'json/' . $store . '/';
  51. $dirName = dirname($fileDir);
  52. if (!is_dir($fileDir)) {
  53.     mkdir($dirName, 0755, true);
  54. }
  55. $fp = fopen($fileDir . $product->systemName . '.json', 'w');
  56. fwrite($fp, json_encode($product, JSON_PRETTY_PRINT));
  57. fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement