Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'config.php';
- require_once("image.inc.php");
- require_once '/home/besthall/www/config/config.inc.php';
- $image_path_cat = '/home/besthall/www/img/c/';
- global $image_path_cat;
- global $content;
- global $cat_parent;
- global $catid;
- global $imgurl;
- global $di;
- $delimiter = ";";
- $url = $_REQUEST['url'];
- $id_parent = $_REQUEST['idparent'];
- $loopcat = $_REQUEST['autocat'];
- $selecturlcat = $_REQUEST['autourlcat'];
- $startid = $_REQUEST['startid'];
- $nleft = $_REQUEST['startid']-1;
- $nright = $_REQUEST['startid']+1;
- $categoryid = $_REQUEST['categoryid'];
- $dimension = $_REQUEST['dimension'];
- $active = $_REQUEST['activecat'];
- $product_count = 0;
- $countotal = 0;
- if ($active == "1") {
- $active = "1";
- } else {
- $active = "0";
- }
- $csv_categorie = $_SERVER['DOCUMENT_ROOT'].'/scrape/categorie.csv';
- if($_REQUEST['autocat'] == '1'){
- $autocatsql = mysql_query("SELECT * FROM sc_caturl where page='0'");
- while($row = mysql_fetch_array($autocatsql)) {
- *** DO SOMETHING ***
- } }
- $query1 = mysql_query("SELECT id_category, name FROM category_lang where id_category='$id_parent'");
- while($row = mysql_fetch_array($query1)) {
- global $htmlCatheader;
- if($dimension == '0'){
- $htmlCatheader = '<h1>'.$row[name].'</h1><div id="subcategories"><ul class="clearfix">';
- }
- elseif($dimension == '1'){
- $htmlCatheader = '<h1>'.$row[name].'</h1><div id="subcategories2"><ul class="clearfix">';
- }
- }
- if ($url !== ''){ $newurl = $url; } elseif ($selecturlcat !== ''){ $newurl = $selecturlcat; }elseif ($loopcat == '1'){$newurl = $row['url']; }
- $content = file_get_contents($newurl);
- $tmp1 = explode('categoryListBoxContents',$content);
- $product_count = count($tmp1);
- for($k=1;$k<$product_count;$k++){
- $tmp2 = explode('alt="',$tmp1[$k]);
- $tmp3 = explode('" title="',$tmp2[1]);
- $name = html_entity_decode($tmp3[0], ENT_COMPAT, 'UTF-8');
- $tmp4 = explode('><a href="',$tmp1[$k]);
- $tmp5 = explode('">',$tmp4[1]);
- $cat_detail = $tmp5[0];
- $tmp8 = explode('<img src="',$tmp1[$k]);
- $tmp9 = explode('"',$tmp8[1]);
- $image = "http://www.gointernational.co.uk/".$tmp9[0];
- $csvcat .= $startid.';'.$id_parent.';'.$active.';'.str_replace(';','',$name).";".$image." \n";
- $startid++;
- $countotal++;
- }
- $csv_category = fopen ($csv_categorie,'w');
- fwrite ($csv_category,$csvcat);
- fclose ($csv_category);
- mysql_query("UPDATE sc_caturl SET active='0' WHERE category='$categoryid'");
- //// DEBUT GET level_depth FROM category ///
- $topcatsql = mysql_query("SELECT id_category, level_depth FROM category where id_category='$id_parent'");
- $topcatrow = mysql_fetch_array($topcatsql);
- $level_depth = $topcatrow['level_depth']+1;
- //// FIN ///
- //// DEBUT GET NLEFT AND NRIGHT FROM CATEGORY ///
- $nleftsql = mysql_query("SELECT MAX(nleft) AS max FROM category");
- $nleftrow = mysql_fetch_array($nleftsql);
- $nleft = $nleftrow['max']+2;
- $nright = $nleftrow['max']+3;
- //// FIN ///
- $pos = '0';
- //// DEBUT Ajouter les data du fichier CSV dans MYSQL ///
- unset($catid);
- unset($imgurl);
- if (($fp = fopen($csv_categorie, "r")) !== false){
- while (($data = fgetcsv($fp, 1000, $delimiter)) !== false) {
- $date_format = date("Y-m-d H:i:s");
- $catname = mysql_real_escape_string(trim($data[3]));
- $catname2 = mysql_real_escape_string(trim($data[3]));
- $cat_parent = $data[1];
- $linkrewrite = str_replace("&", "and", $catname);
- $linkrewrite = str_replace("'", "",$linkrewrite);
- $string = preg_replace("/[^a-zA-Z0-9 _-]/", "",$linkrewrite);
- $linkrewrite = strtolower($linkrewrite);
- $linkrewrite = preg_replace("/[ ]+/", " ",$linkrewrite);
- $linkrewrite = str_replace(" ", "-", $linkrewrite);
- $catid[] = $data[0];
- $imgurl[] = $data[4];
- 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());
- 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());
- mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',1);");
- mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',2);");
- mysql_query("INSERT INTO category_group (id_category,id_group) VALUES ('$data[0]',3);");
- mysql_query("INSERT INTO category_shop (id_category,id_shop,position) VALUES ('$data[0]','1','$pos');");
- mysql_query("UPDATE sc_caturl SET active='0' WHERE category='$data[1]'");
- $nleft = $nleft+2;
- $nright = $nright+2;
- $pos++;
- }
- Category::regenerateEntireNtree();
- importUrl($catid);
- }
- //// FIN ///
- function importUrl($nocatid){
- global $content;
- global $cat_parent;
- $urlcat1 = explode('categoryListBoxContents',$content);
- $subcat1 = explode('<h1 id="indexCategoriesHeading">',$content);
- $urlcat_count = count($urlcat1);
- $t=0;
- for($k=1;$k<$urlcat_count;$k++){
- $urlcat4 = explode('alt="',$urlcat1[$k]);
- $urlcat5 = explode('" title="',$urlcat4[1]);
- $name = mysql_real_escape_string(trim($urlcat5[0]));
- $subcat3 = explode('</h1>',$subcat1[1]);
- $subname = mysql_real_escape_string(trim($subcat3[0]));
- $urlcat2 = explode('href="',$urlcat1[$k]);
- $urlcat3 = explode('"><img',$urlcat2[1]);
- $catUrl = $urlcat3[0];
- $catUrl =html_entity_decode($catUrl, ENT_COMPAT, 'UTF-8');
- $page_detail = file_get_contents($catUrl);
- $catUrl6 = explode('of <strong>',$page_detail);
- $catUrl7 = explode('</strong> products)</div>',$catUrl6[1]);
- $howpage = $catUrl7[0];
- if ($howpage == ''){
- $finalpage = '0';
- }elseif ($howpage < 21){
- $finalpage = '1';
- }else{
- $finalpage = ceil(($howpage / 21));
- }
- $numcatid = $nocatid[$t];
- $catUrl = str_replace('&','&',$catUrl);
- $catsub = $cat_parent.$numcatid;
- 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());
- $t++;
- }
- }
- $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";
- $query = mysql_query($sql_duplicate);
- $num_rows = mysql_num_rows($query);
- $replace = range('a','z');
- while ($row = mysql_fetch_assoc($query, MYSQL_ASSOC)) {
- if(!empty($row['link_rewrite'])){
- $list_words = array();
- $list_words = getcatListWordsRelatedContent($row['link_rewrite'], $row['count'], $replace);
- $list_sql = "SELECT id_category FROM category_lang WHERE link_rewrite = '{$row["link_rewrite"]}'";
- $list_query = mysql_query($list_sql);
- $di = 0;
- $sql_update = "UPDATE category_lang SET link_rewrite = '%s' WHERE id_category = %s ";
- while( $l_row = mysql_fetch_assoc($list_query, MYSQL_ASSOC)) {
- mysql_query(sprintf($sql_update, $list_words[$di], $l_row['id_category']));
- $di++;
- }
- }
- }
- function getcatListWordsRelatedContent($content,$count,$replace = array()){
- $list_words = array();
- $list_words = getcatListWords($content);
- while ( count($list_words) < $count) {
- $parts = split('-', $content);
- $num = catfactorial(count($parts));
- $remain = $count - count($list_words);
- $mod = ceil($remain/$num) < count($replace) ? ceil($remain/$num) : count($replace) ;
- shuffle($parts);
- $tmp = $parts;
- $random_part = array_shift($parts);
- $tmp1 = $parts;
- $rand_arr = array_rand($replace,$mod);
- $rand_arr = is_array($rand_arr) ? $rand_arr : array($rand_arr);
- foreach( $rand_arr as $index ){
- $is_prefix = mt_rand(1,100) % 2 == 0 ;
- if( $is_prefix ){
- array_push($parts, $replace[$index].$random_part);
- } else {
- array_push($parts, $random_part.$replace[$index]);
- }
- $content = implode("-", $parts);
- $list_words = array_merge($list_words, getcatListWords($content));
- $parts = $tmp1;
- }
- if( count($parts) > 1){
- $content = implode("-".$replace[ array_rand($replace)], $tmp);
- } else {
- $content = $is_prefix ? $replace[ array_rand($replace)]. $content : $content.$replace[ array_rand($replace)];
- }
- }
- return $list_words;
- }
- function getcatListWords($word){
- $set = split('-', $word);
- $size = count($set) - 1;
- if($size == 0) return $set;
- $perm = range(0, $size);
- $j = 0;
- $perms = array();
- do {
- foreach ($perm as $i) { $perms[$j][] = $set[$i]; }
- } while ($perm = catpc_next_permutation($perm, $size) and ++$j);
- return array_map('catmerge',$perms);
- }
- function catpc_next_permutation($p, $size) {
- for ($i = $size - 1; $p[$i] >= $p[$i+1]; --$i) { }
- if ($i <= -1) { return false; }
- for ($j = $size; $p[$j] <= $p[$i]; --$j) { }
- $tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
- for (++$i, $j = $size; $i < $j; ++$i, --$j) {
- $tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
- }
- $tmp = null;
- return $p;
- }
- function catmerge($arr){
- return implode("-", $arr);
- }
- function catfactorial($number) {
- if ($number < 2) {
- return 1;
- } else {
- return ($number * catfactorial($number-1));
- }
- }
- if($dimension == '0' || $dimension == '1'){
- buildbody($catid,$dimension,$imgurl);
- }
- function buildbody($nobody,$dimension,$imgurl){
- global $htmlCatbody;
- $i = 0;
- foreach ($nobody as $key => $value) {
- $checkcatsql = mysql_query("SELECT id_category, link_rewrite, name FROM category_lang WHERE id_category='$value';") or die ("Selezione1 non eseguita".mysql_error());
- while($row = mysql_fetch_array($checkcatsql)) {
- $checkcatdepth = $row['link_rewrite'];
- $name = $row['name'];
- $shortname = $row['name'];
- insert_image($value, $imgurl[$i]);
- if($dimension == '0'){
- $htmlCatbody = $htmlCatbody.'<li><div class="subcategory-image">
- <a class="img" title="'.$name.'" href="http://best-halloween-costumes.co.uk/'.$checkcatdepth.'/">
- <img class="replace-2x" src="http://best-halloween-costumes.co.uk/img/c/'.$value.'-bigcat.jpg" alt="'.$name.'" />
- </a>
- </div>
- <div class="homebox">
- <h5>'.$catname.'</h5>
- <a href="http://best-halloween-costumes.co.uk/'.$linkrewrite.'/">View selection > </a></div>
- <div class="cat_desc">
- <h1>'.$catname.'</h1>
- </div>
- </li>';
- }
- if($dimension == '1'){
- if (mb_strlen($shortname, 'utf8' ) > 22 ) {
- $last_space = strrpos(substr($shortname, 0, 22 ), ' ' );
- $shortname = substr($shortname, 0, $last_space ) . '';
- }
- $htmlCatbody = $htmlCatbody.'<li>
- <div class="subcategory-image">
- <a class="img" href="http://best-halloween-costumes.co.uk/'.$checkcatdepth.'/">
- <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>
- </li>';
- }
- $i++;
- }
- }
- }
- if($dimension == '0' || $dimension == '1'){
- $htmlCatfooter='</ul></div>';
- $htmlcat = $htmlCatheader.$htmlCatbody.$htmlCatfooter;
- mysql_query("UPDATE category_lang SET description = '$htmlcat' WHERE id_category='$id_parent'");
- } else {
- mysql_query("UPDATE category_lang SET description = '' WHERE id_category='$id_parent'");
- }
- if ($di == ''){ $di = '0'; }else{$di = $di-1;}
- $select_catname_sql = mysql_query("SELECT name FROM category_lang where id_category = '$categoryid'");
- $select_catname_row = mysql_fetch_array($select_catname_sql);
- $select_catname = $select_catname_row['name'];
- echo '
- <div style="display: table;position: absolute;height: 100%;width: 100%;">
- <div style="display: table-cell;vertical-align: middle;">
- <div style="width:700px;margin-left: auto;margin-right: auto ;">
- <div style="float:left;width: 259px;height: 194px;background-image: url(http://best-halloween-costumes.co.uk/scrape/data.jpg);"></div>
- <div style="float:left;height:259px;padding-top:50px;padding-left:10px;">
- <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.$countotal.'</strong> Produit ajouté dans <strong>'.$select_catname.'</strong> </div>
- <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>
- <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.$_REQUEST['startid'].'</strong> ID Début</div>
- <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.($startid-2).'</strong> ID Fin</div>
- <div style="font-family:arial;font-size:14px;line-height:20px;"><strong style="font-size:15px;">'.($startid-1).'</strong> ID Prochain </div>
- <div style="clear:both;padding-top:100px;margin-left: auto;margin-right: auto ;">
- <form><input type="button" value="Retour" onclick="history.go(-1)"></form>
- </div></div></div></div>';
- fclose($handle);
- fclose($fh);
- //unlink('size.csv');
- mysql_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement