Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.85 KB | None | 0 0
  1. <?php
  2.  
  3. include 'config.php';
  4. require_once("image.inc.php");
  5. require_once '/home/besthall/www/config/config.inc.php';
  6.  
  7. $image_path_cat = '/home/besthall/www/img/c/';
  8.  
  9. global $image_path_cat;
  10. global $content;
  11. global $cat_parent;
  12. global $catid;
  13. global $imgurl;
  14. global $di;
  15.  
  16.  
  17. $delimiter = ";";
  18.  
  19. $url = $_REQUEST['url'];
  20. $id_parent = $_REQUEST['idparent'];
  21. $loopcat = $_REQUEST['autocat'];
  22. $selecturlcat = $_REQUEST['autourlcat'];
  23. $startid = $_REQUEST['startid'];
  24. $nleft = $_REQUEST['startid']-1;
  25. $nright = $_REQUEST['startid']+1;
  26. $categoryid = $_REQUEST['categoryid'];
  27. $dimension = $_REQUEST['dimension'];
  28. $active = $_REQUEST['activecat'];
  29.  
  30. $product_count = 0;
  31. $countotal = 0;
  32.  
  33.  
  34. if ($active == "1") {
  35. $active = "1";
  36. } else {
  37. $active = "0";
  38. }
  39.  
  40.  
  41. $csv_categorie = $_SERVER['DOCUMENT_ROOT'].'/scrape/categorie.csv';
  42.  
  43.  
  44. if($_REQUEST['autocat'] == '1'){
  45. $autocatsql = mysql_query("SELECT * FROM sc_caturl where page='0'");
  46. while($row = mysql_fetch_array($autocatsql)) {
  47.  
  48. *** DO SOMETHING ***
  49.  
  50. } }
  51.  
  52.  
  53. $query1 = mysql_query("SELECT id_category, name FROM category_lang where id_category='$id_parent'");
  54.  
  55. while($row = mysql_fetch_array($query1)) {
  56. global $htmlCatheader;
  57. if($dimension == '0'){
  58. $htmlCatheader = '<h1>'.$row[name].'</h1><div id="subcategories"><ul class="clearfix">';
  59. }
  60. elseif($dimension == '1'){
  61. $htmlCatheader = '<h1>'.$row[name].'</h1><div id="subcategories2"><ul class="clearfix">';
  62. }
  63.  
  64. }
  65.  
  66.  
  67. if ($url !== ''){ $newurl = $url; } elseif ($selecturlcat !== ''){ $newurl = $selecturlcat; }elseif ($loopcat == '1'){$newurl = $row['url']; }
  68.  
  69.  
  70. $content = file_get_contents($newurl);
  71.  
  72.  
  73. $tmp1 = explode('categoryListBoxContents',$content);
  74.  
  75. $product_count = count($tmp1);
  76.  
  77.  
  78.  
  79.  
  80. for($k=1;$k<$product_count;$k++){
  81.  
  82. $tmp2 = explode('alt="',$tmp1[$k]);
  83. $tmp3 = explode('" title="',$tmp2[1]);
  84. $name = html_entity_decode($tmp3[0], ENT_COMPAT, 'UTF-8');
  85.  
  86. $tmp4 = explode('><a href="',$tmp1[$k]);
  87. $tmp5 = explode('">',$tmp4[1]);
  88. $cat_detail = $tmp5[0];
  89.  
  90. $tmp8 = explode('<img src="',$tmp1[$k]);
  91. $tmp9 = explode('"',$tmp8[1]);
  92. $image = "http://www.gointernational.co.uk/".$tmp9[0];
  93.  
  94. $csvcat .= $startid.';'.$id_parent.';'.$active.';'.str_replace(';','',$name).";".$image." \n";
  95.  
  96. $startid++;
  97. $countotal++;
  98.  
  99.  
  100.  
  101. }
  102.  
  103. $csv_category = fopen ($csv_categorie,'w');
  104. fwrite ($csv_category,$csvcat);
  105. fclose ($csv_category);
  106.  
  107. mysql_query("UPDATE sc_caturl SET active='0' WHERE category='$categoryid'");
  108.  
  109.  
  110. //// DEBUT GET level_depth FROM category ///
  111. $topcatsql = mysql_query("SELECT id_category, level_depth FROM category where id_category='$id_parent'");
  112. $topcatrow = mysql_fetch_array($topcatsql);
  113. $level_depth = $topcatrow['level_depth']+1;
  114. //// FIN ///
  115.  
  116.  
  117. //// DEBUT GET NLEFT AND NRIGHT FROM CATEGORY ///
  118. $nleftsql = mysql_query("SELECT MAX(nleft) AS max FROM category");
  119. $nleftrow = mysql_fetch_array($nleftsql);
  120. $nleft = $nleftrow['max']+2;
  121. $nright = $nleftrow['max']+3;
  122. //// FIN ///
  123. $pos = '0';
  124. //// DEBUT Ajouter les data du fichier CSV dans MYSQL ///
  125.  
  126. unset($catid);
  127. unset($imgurl);
  128.  
  129. if (($fp = fopen($csv_categorie, "r")) !== false){
  130. while (($data = fgetcsv($fp, 1000, $delimiter)) !== false) {
  131. $date_format = date("Y-m-d H:i:s");
  132.  
  133. $catname = mysql_real_escape_string(trim($data[3]));
  134. $catname2 = mysql_real_escape_string(trim($data[3]));
  135. $cat_parent = $data[1];
  136.  
  137. $linkrewrite = str_replace("&", "and", $catname);
  138. $linkrewrite = str_replace("'", "",$linkrewrite);
  139. $string = preg_replace("/[^a-zA-Z0-9 _-]/", "",$linkrewrite);
  140. $linkrewrite = strtolower($linkrewrite);
  141. $linkrewrite = preg_replace("/[ ]+/", " ",$linkrewrite);
  142. $linkrewrite = str_replace(" ", "-", $linkrewrite);
  143.  
  144. $catid[] = $data[0];
  145. $imgurl[] = $data[4];
  146.  
  147. mysql_query("INSERT INTO category (id_category, id_parent, id_shop_default, level_depth, nleft, nright, active, date_add, date_upd) VALUES ('$data[0]','$data[1]','1','$level_depth','$nleft','$nright','$active','$date_format','$date_format');")or die ("ERREUR #1 INSERT CATEGORY ".mysql_error());
  148. mysql_query("INSERT INTO category_lang (id_category, id_lang, name, link_rewrite) VALUES ('$data[0]','2','$catname','$linkrewrite');")or die ("ERREUR #2 INSERT CATEGORY_LANG ".mysql_error());
  149. mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',1);");
  150. mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',2);");
  151. mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',3);");
  152. mysql_query("INSERT INTO category_shop (id_category,id_shop,position) VALUES ('$data[0]','1','$pos');");
  153. mysql_query("UPDATE sc_caturl SET active='0' WHERE category='$data[1]'");
  154.  
  155.  
  156. $nleft = $nleft+2;
  157. $nright = $nright+2;
  158. $pos++;
  159.  
  160. }
  161.  
  162. Category::regenerateEntireNtree();
  163. importUrl($catid);
  164.  
  165. }
  166.  
  167. //// FIN ///
  168.  
  169.  
  170. function importUrl($nocatid){
  171. global $content;
  172. global $cat_parent;
  173.  
  174. $urlcat1 = explode('categoryListBoxContents',$content);
  175. $subcat1 = explode('<h1 id="indexCategoriesHeading">',$content);
  176.  
  177. $urlcat_count = count($urlcat1);
  178.  
  179. $t=0;
  180.  
  181. for($k=1;$k<$urlcat_count;$k++){
  182.  
  183.  
  184. $urlcat4 = explode('alt="',$urlcat1[$k]);
  185. $urlcat5 = explode('" title="',$urlcat4[1]);
  186.  
  187. $name = mysql_real_escape_string(trim($urlcat5[0]));
  188.  
  189. $subcat3 = explode('</h1>',$subcat1[1]);
  190. $subname = mysql_real_escape_string(trim($subcat3[0]));
  191.  
  192. $urlcat2 = explode('href="',$urlcat1[$k]);
  193. $urlcat3 = explode('"><img',$urlcat2[1]);
  194.  
  195.  
  196. $catUrl = $urlcat3[0];
  197. $catUrl =html_entity_decode($catUrl, ENT_COMPAT, 'UTF-8');
  198.  
  199. $page_detail = file_get_contents($catUrl);
  200.  
  201. $catUrl6 = explode('of <strong>',$page_detail);
  202. $catUrl7 = explode('</strong> products)</div>',$catUrl6[1]);
  203. $howpage = $catUrl7[0];
  204.  
  205. if ($howpage == ''){
  206. $finalpage = '0';
  207. }elseif ($howpage < 21){
  208. $finalpage = '1';
  209. }else{
  210. $finalpage = ceil(($howpage / 21));
  211. }
  212.  
  213. $numcatid = $nocatid[$t];
  214.  
  215. $catUrl = str_replace('&amp;','&',$catUrl);
  216.  
  217. $catsub = $cat_parent.$numcatid;
  218.  
  219. mysql_query("INSERT INTO sc_caturl (subname,name,url,page,cat_parent,category,active,catsub) VALUES ('$subname','$name','$catUrl','$finalpage','$cat_parent','$numcatid','1','$catsub');")or die ("ERREUR CATURL #2 <br>".mysql_error());
  220.  
  221. $t++;
  222.  
  223. }
  224. }
  225.  
  226.  
  227. $sql_duplicate = "SELECT count(id_category) as count,link_rewrite FROM category_lang WHERE link_rewrite != '' GROUP BY link_rewrite HAVING count(id_category) > 1";
  228. $query = mysql_query($sql_duplicate);
  229. $num_rows = mysql_num_rows($query);
  230.  
  231. $replace = range('a','z');
  232. while ($row = mysql_fetch_assoc($query, MYSQL_ASSOC)) {
  233. if(!empty($row['link_rewrite'])){
  234. $list_words = array();
  235. $list_words = getcatListWordsRelatedContent($row['link_rewrite'], $row['count'], $replace);
  236.  
  237. $list_sql = "SELECT id_category FROM category_lang WHERE link_rewrite = '{$row["link_rewrite"]}'";
  238. $list_query = mysql_query($list_sql);
  239.  
  240. $di = 0;
  241. $sql_update = "UPDATE category_lang SET link_rewrite = '%s' WHERE id_category = %s ";
  242. while( $l_row = mysql_fetch_assoc($list_query, MYSQL_ASSOC)) {
  243. mysql_query(sprintf($sql_update, $list_words[$di], $l_row['id_category']));
  244. $di++;
  245. }
  246. }
  247.  
  248. }
  249.  
  250.  
  251. function getcatListWordsRelatedContent($content,$count,$replace = array()){
  252.  
  253. $list_words = array();
  254. $list_words = getcatListWords($content);
  255.  
  256. while ( count($list_words) < $count) {
  257. $parts = split('-', $content);
  258. $num = catfactorial(count($parts));
  259. $remain = $count - count($list_words);
  260. $mod = ceil($remain/$num) < count($replace) ? ceil($remain/$num) : count($replace) ;
  261.  
  262. shuffle($parts);
  263. $tmp = $parts;
  264. $random_part = array_shift($parts);
  265. $tmp1 = $parts;
  266. $rand_arr = array_rand($replace,$mod);
  267. $rand_arr = is_array($rand_arr) ? $rand_arr : array($rand_arr);
  268. foreach( $rand_arr as $index ){
  269.  
  270. $is_prefix = mt_rand(1,100) % 2 == 0 ;
  271. if( $is_prefix ){
  272. array_push($parts, $replace[$index].$random_part);
  273. } else {
  274. array_push($parts, $random_part.$replace[$index]);
  275. }
  276.  
  277. $content = implode("-", $parts);
  278. $list_words = array_merge($list_words, getcatListWords($content));
  279. $parts = $tmp1;
  280. }
  281. if( count($parts) > 1){
  282. $content = implode("-".$replace[ array_rand($replace)], $tmp);
  283. } else {
  284. $content = $is_prefix ? $replace[ array_rand($replace)]. $content : $content.$replace[ array_rand($replace)];
  285. }
  286. }
  287.  
  288. return $list_words;
  289. }
  290.  
  291.  
  292. function getcatListWords($word){
  293. $set = split('-', $word);
  294. $size = count($set) - 1;
  295. if($size == 0) return $set;
  296. $perm = range(0, $size);
  297. $j = 0;
  298. $perms = array();
  299. do {
  300. foreach ($perm as $i) { $perms[$j][] = $set[$i]; }
  301. } while ($perm = catpc_next_permutation($perm, $size) and ++$j);
  302.  
  303. return array_map('catmerge',$perms);
  304. }
  305.  
  306.  
  307. function catpc_next_permutation($p, $size) {
  308. for ($i = $size - 1; $p[$i] >= $p[$i+1]; --$i) { }
  309. if ($i <= -1) { return false; }
  310. for ($j = $size; $p[$j] <= $p[$i]; --$j) { }
  311. $tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
  312. for (++$i, $j = $size; $i < $j; ++$i, --$j) {
  313. $tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
  314. }
  315. $tmp = null;
  316. return $p;
  317. }
  318.  
  319. function catmerge($arr){
  320. return implode("-", $arr);
  321. }
  322.  
  323. function catfactorial($number) {
  324. if ($number < 2) {
  325. return 1;
  326. } else {
  327. return ($number * catfactorial($number-1));
  328. }
  329. }
  330.  
  331.  
  332. if($dimension == '0' || $dimension == '1'){
  333. buildbody($catid,$dimension,$imgurl);
  334. }
  335.  
  336.  
  337. function buildbody($nobody,$dimension,$imgurl){
  338. global $htmlCatbody;
  339. $i = 0;
  340.  
  341. foreach ($nobody as $key => $value) {
  342. $checkcatsql = mysql_query("SELECT id_category, link_rewrite, name FROM category_lang WHERE id_category='$value';") or die ("Selezione1 non eseguita".mysql_error());
  343.  
  344. while($row = mysql_fetch_array($checkcatsql)) {
  345.  
  346. $checkcatdepth = $row['link_rewrite'];
  347. $name = $row['name'];
  348. $shortname = $row['name'];
  349.  
  350. insert_image($value, $imgurl[$i]);
  351.  
  352. if($dimension == '0'){
  353.  
  354. $htmlCatbody = $htmlCatbody.'<li><div class="subcategory-image">
  355. <a class="img" title="'.$name.'" href="http://best-halloween-costumes.co.uk/'.$checkcatdepth.'/">
  356. <img class="replace-2x" src="http://best-halloween-costumes.co.uk/img/c/'.$value.'-bigcat.jpg" alt="'.$name.'" />
  357. </a>
  358. </div>
  359. <div class="homebox">
  360. <h5>'.$catname.'</h5>
  361. <a href="http://best-halloween-costumes.co.uk/'.$linkrewrite.'/">View selection &gt; </a></div>
  362. <div class="cat_desc">
  363. <h1>'.$catname.'</h1>
  364. </div>
  365. </li>';
  366. }
  367.  
  368. if($dimension == '1'){
  369.  
  370. if (mb_strlen($shortname, 'utf8' ) > 22 ) {
  371. $last_space = strrpos(substr($shortname, 0, 22 ), ' ' );
  372. $shortname = substr($shortname, 0, $last_space ) . '';
  373. }
  374.  
  375. $htmlCatbody = $htmlCatbody.'<li>
  376. <div class="subcategory-image">
  377. <a class="img" href="http://best-halloween-costumes.co.uk/'.$checkcatdepth.'/">
  378. <img title="'.$name.'" src="http://best-halloween-costumes.co.uk/img/c/'.$value.'-smallcat.jpg" alt="'.$name.'" width="292" height="164" /><br />'.$shortname.'</a></div>
  379. </li>';
  380. }
  381. $i++;
  382. }
  383. }
  384. }
  385.  
  386.  
  387. if($dimension == '0' || $dimension == '1'){
  388. $htmlCatfooter='</ul></div>';
  389. $htmlcat = $htmlCatheader.$htmlCatbody.$htmlCatfooter;
  390. mysql_query("UPDATE category_lang SET description = '$htmlcat' WHERE id_category='$id_parent'");
  391. } else {
  392. mysql_query("UPDATE category_lang SET description = '' WHERE id_category='$id_parent'");
  393. }
  394.  
  395.  
  396.  
  397.  
  398. if ($di == ''){ $di = '0'; }else{$di = $di-1;}
  399.  
  400. $select_catname_sql = mysql_query("SELECT name FROM category_lang where id_category = '$categoryid'");
  401. $select_catname_row = mysql_fetch_array($select_catname_sql);
  402. $select_catname = $select_catname_row['name'];
  403.  
  404. echo '
  405. <div style="display: table;position: absolute;height: 100%;width: 100%;">
  406. <div style="display: table-cell;vertical-align: middle;">
  407. <div style="width:700px;margin-left: auto;margin-right: auto ;">
  408. <div style="float:left;width: 259px;height: 194px;background-image: url(http://best-halloween-costumes.co.uk/scrape/data.jpg);"></div>
  409. <div style="float:left;height:259px;padding-top:50px;padding-left:10px;">
  410. <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.$countotal.'</strong> Produit ajout&eacute; dans <strong>'.$select_catname.'</strong> </div>
  411. <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.$di.'</strong> Liens doublons ont été trouvé et corrigé;</div>
  412. <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.$_REQUEST['startid'].'</strong> ID D&eacute;but</div>
  413. <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.($startid-2).'</strong> ID Fin</div>
  414. <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.($startid-1).'</strong> ID Prochain </div>
  415. <div style="clear:both;padding-top:100px;margin-left: auto;margin-right: auto ;">
  416. <form><input type="button" value="Retour" onclick="history.go(-1)"></form>
  417. </div></div></div></div>';
  418. fclose($handle);
  419. fclose($fh);
  420. //unlink('size.csv');
  421. mysql_close($conn);
  422. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement