Advertisement
Guest User

none

a guest
Mar 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. <div align="center" id="timer" style='color:black;font-size:24px;' ></div>
  2.  
  3. <?php
  4.  
  5. $time_start = microtime(true);
  6.  
  7. set_time_limit(0);
  8. ignore_user_abort(1);
  9.  
  10. function getContents($str, $startDelimiter, $endDelimiter) {
  11. $contents = array();
  12. $startDelimiterLength = strlen($startDelimiter);
  13. $endDelimiterLength = strlen($endDelimiter);
  14. $startFrom = $contentStart = $contentEnd = 0;
  15. while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
  16. $contentStart += $startDelimiterLength;
  17. $contentEnd = strpos($str, $endDelimiter, $contentStart);
  18. if (false === $contentEnd) {
  19. break;
  20. }
  21. $contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
  22. $startFrom = $contentEnd + $endDelimiterLength;
  23. }
  24.  
  25. return $contents;
  26. }
  27.  
  28. $host = "localhost";
  29. $user = "buysexto_user";
  30. $pass = "123123123";
  31. $database = "buysexto_pdb";
  32.  
  33. $con = mysqli_connect($host,$user,$pass,$database);
  34.  
  35. $result = mysqli_query($con,"SELECT * FROM product");
  36.  
  37. $sql = "ALTER TABLE `product` ADD `qty` int NOT NULL DEFAULT 0;";
  38. mysqli_query($con, $sql);
  39.  
  40. $sql = "ALTER TABLE `product` ADD `fulldescription` LONGTEXT;";
  41. mysqli_query($con, $sql);
  42.  
  43. $sql = "ALTER TABLE `product` ADD `specifications` LONGTEXT;";
  44. mysqli_query($con, $sql);
  45.  
  46. $sql = "ALTER TABLE `product` ADD `sizing` LONGTEXT;";
  47. mysqli_query($con, $sql);
  48.  
  49. $sql = "ALTER TABLE `product` ADD `productid` LONGTEXT;";
  50. mysqli_query($con, $sql);
  51.  
  52.  
  53. $counter = 0;
  54.  
  55.  
  56. while($row = mysqli_fetch_array($result))
  57. {
  58.  
  59. $qty = (isset($row['qty']) ? $row['qty'] : null);
  60.  
  61.  
  62. if ($qty >= 0) {
  63. $counter++;
  64.  
  65.  
  66. $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
  67. $homepage = @file_get_contents("https://www.sextoydropshipping.ca/catalogsearch/result/?dir=desc&q=".$row['upc'],false,$context);
  68.  
  69. $desc = "";
  70. if (strpos($homepage, '<h2>Product Description</h2>') !== false) {
  71. $desc = getContents($homepage, '<h2>Product Description</h2>', '</div>');
  72. $desc = end($desc);
  73. $desc = preg_replace('/(\s\s+|\t|\n)/', ' ', $desc);
  74. $desc = strip_tags($desc);
  75. $desc = ltrim($desc);
  76. $desc = rtrim($desc);
  77. $desc = mysqli_real_escape_string($con, $desc);
  78. $sql = "UPDATE `product` SET `fulldescription` = '$desc' WHERE `upc` = ".$row['upc'];
  79. mysqli_query($con, $sql);
  80. };
  81.  
  82. $spec = "";
  83. if (strpos($homepage, '<strong>Specifications</strong>') !== false) {
  84. $spec = getContents($homepage, '<strong>Specifications</strong>', '</div>');
  85. $spec = end($spec);
  86. $spec = preg_replace('/(\s\s+|\t|\n)/', ' ', $spec);
  87. $spec = str_replace("<br>", "", $spec);
  88. $spec = str_replace("<ul>", "", $spec);
  89. $spec = str_replace("</ul>", "", $spec);
  90. $spec = ltrim($spec);
  91. $spec = rtrim($spec);
  92. $spec = mysqli_real_escape_string($con, $spec);
  93. $sql = "UPDATE `product` SET `specifications` = '$spec' WHERE `upc` = ".$row['upc'];
  94. mysqli_query($con, $sql);
  95. };
  96.  
  97. $size = "";
  98. if (strpos($homepage, '<h3>Sizing Chart</h3>') !== false) {
  99. $size = getContents($homepage, '<h3>Sizing Chart</h3>', '</div>');
  100. $size = end($size);
  101. $size = preg_replace('/(\s\s+|\t|\n)/', ' ', $size);
  102. $size = str_replace("<br>", "", $size);
  103. $size = str_replace("<ul>", "", $size);
  104. $size = str_replace("</ul>", "", $size);
  105. $size = ltrim($size);
  106. $size = rtrim($size);
  107. $size = mysqli_real_escape_string($con, $size);
  108. $sql = "UPDATE `product` SET `sizing` = '$size' WHERE `upc` = ".$row['upc'];
  109. mysqli_query($con, $sql);
  110. };
  111.  
  112. $productid = "";
  113. if (strpos($homepage, 'product" value="') !== false) {
  114. $productid = getContents($homepage, 'product" value="', '"');
  115. $productid = end($productid);
  116. $productid = preg_replace('/(\s\s+|\t|\n)/', ' ', $productid);
  117. $productid = str_replace("<br>", "", $productid);
  118. $productid = str_replace("<ul>", "", $productid);
  119. $productid = str_replace("</ul>", "", $productid);
  120. $productid = ltrim($productid);
  121. $productid = rtrim($productid);
  122. $productid = mysqli_real_escape_string($con, $productid);
  123. $sql = "UPDATE `product` SET `productid` = '$productid' WHERE `upc` = ".$row['upc'];
  124. mysqli_query($con, $sql);
  125. };
  126.  
  127.  
  128. for($i=1; $i<7; $i++){
  129.  
  130. $theimage = $row["image$i"];
  131.  
  132. if ($theimage){
  133.  
  134. $theimage = trim($theimage);
  135. $theimage = ltrim($theimage);
  136. $theimage = rtrim($theimage);
  137. $theimage = preg_replace('/(\s\s+|\t|\n)/', ' ', $theimage);
  138.  
  139. $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
  140. $img = @file_get_contents($theimage,false,$context);
  141.  
  142. if ($img === false) {
  143. echo "</BR>FAILED GET URL: ".$row['upc']." - ".$theimage;
  144. } else {
  145.  
  146. $imgtitle = str_replace(" ", "-", $row['title']);
  147. $imgtitle = str_replace("/", "", $imgtitle);
  148.  
  149. if (!is_dir("./images/".$row['upc']."/")){mkdir("./images/".$row['upc']."/");};
  150. $content = @file_put_contents("./images/".$row['upc']."/".$imgtitle."-$i.jpg", $img);
  151. if ($content === false) {echo "</BR>FAILED TO PUT IMAGE: ".$row['upc']." - ".$theimage;}
  152.  
  153. }
  154.  
  155. }}
  156.  
  157. echo "<script type='text/javascript'>
  158. document.getElementById('timer').innerHTML = $counter;
  159. </script>";
  160.  
  161. }
  162. }
  163.  
  164. $time_end = microtime(true);
  165.  
  166. function formatPeriod($endtime, $starttime)
  167. {
  168. $duration = $endtime - $starttime;
  169. $hours = (int) ($duration / 60 / 60);
  170. $minutes = (int) ($duration / 60) - $hours * 60;
  171. $seconds = (int) $duration - $hours * 60 * 60 - $minutes * 60;
  172. return ($hours == 0 ? "00":$hours) . ":" . ($minutes == 0 ? "00":($minutes < 10? "0".$minutes:$minutes)) . ":" . ($seconds == 0 ? "00":($seconds < 10? "0".$seconds:$seconds));
  173. }
  174.  
  175. echo '</br><b>Total Execution Time:</b> '.formatPeriod($time_end, $time_start);
  176.  
  177.  
  178. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement