phpQuery простой и удобный парсер

Доброго времени суток. В данной статье я хотел бы поделиться парсером, который я писал на phpQuery для woocommerce. В какой-то мере в этом парсере присутствуют элементы костылей, но общий принцип работы будет понятен, здесь нет ничего сложного и сверхъестественного. Ситуация была такая что спарсить товары нужно было срочно, а времени на раздумья особо не было. Сразу скажу что можно было сделать. Можно было сделать генерацию переменных для полей и создание полей если они отсутствуют, в зависимости от списка характеристик к определённым полям у товара т.к. разделов очень много и характеристики к товарам постоянно могли изменяться. Т.е. например одна и таже характеристика в списке у разного товара могла называться по разному (Вид, вид оборудования, вид изделия), а привязаться можно было именно только к названию характеристики т.к. другого индетификатора в списке не имелось. Но это всё лирика)) Вот собственно код:  (код пока не отображается феном всё портит))) )

 


<?php
header('Content-Type: text/html; charset= utf-8');
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

$parts = parse_url($_GET['url']);
print_r($parts);
$item = [];
$items =[];
$Attributes = [];
$hostlink = 'https://eurosmed.ru';

if($_GET['page'] > 1) $pageurl = 'page-'.$_GET['page'];
else $pageurl = '';

if($_GET['url']){

    if(include('phpQuery.php')){ echo 'Y';}
    else{echo '';}

    $html = file_get_contents($_GET['url'].$pageurl);
    $pq = phpQuery::newDocument($html);

    $links = $pq->find('.product-items-list .product-item-title');


    /** Работаем с информацией в общем списке **/
    $i=0; foreach ($links as $link) {
        $pqLink = pq($link);



        /** Работаем с детальной информацией **/
        $detailPrice = file_get_contents('https://eurosmed.ru/'.$pqLink->attr('href'));
        $pqDetail = phpQuery::newDocument($detailPrice);


        $NAME = $pqDetail->find('.titleh1 h1')->text();
        $CONTENT = $pqDetail->find('#category_description')->html();
        $CONTENT = preg_replace("/<img.+?>/","",$CONTENT);
        $PRICE = $pqDetail->find('.price span')->text();


        $PRICE = str_replace(' ', '', $PRICE);

        if($PRICE != 'позапросу')
        $PRICE  =  (int)$PRICE ;
        else  $PRICE = '';

        $items = array('name' => $NAME, 'price' => $PRICE  , 'content' => $CONTENT );

        $dimg = $pqDetail->find('.fancybox')->attr('href');
        $thumb_url  = $hostlink.$dimg;

        $image_gallery = $pqDetail->find('.carousel-inner .item a');


        $propertiesList = $pqDetail->find('.features')->find('li');

        $prop_proizvoditelnost_min = [];            $prop_tip_klinka = [];
        $prop_zadavaemyj_obyom =[];                 $prop_vid_tovara = [];
        $prop_rabota_akkumulyatora = [];            $prop_proizvodimye_gazy = [];
        $prop_vid_dozatora = [];                    $prop_vid_skanera=[];
        $prop_chastota_ventilyacii_dyx_min = [];    $prop_dyxatelnyj_obemml = [];
        $prop_kolichestvo_sekcij = [];              $prop_ugol_naklona_golenimin_max = [];
        $prop_pokazaniya_k_primeneniyu = [];        $prop_gruzopodemnost_kg = [];
        $prop_regulirovka_vysoty_min_max_mm = [];   $prop_ugol_naklona_spinki_min_max = [];
        $prop_tip_svetilnikov = [];                 $prop_vid_reabilitacii = [];
        $prop_diametr_bloka_osveshheniya_mm = [];   $prop_uroven_osveshhennosti_klk = [];
        $prop_type_regim_raboty = [];               $prop_type_rezanie_s_koagulaciei = [];
        $prop_type_rabocha_chastota = [];           $prop_type_ganarator = [];
        $prop_type_aparat = [];                     $prop_type_instrument =[];
        $prop_type_endoskopii = [];                 $prop_derzatel_flakona  = [];
        $prop_type_siduhka  = [];                   $prop_type_stoika =[];
        $prop_section = [];                         $prop_material = [];
        $prop_vmestimost  = [];                     $prop_type_spa = [];
        $prop_num_forsun = [];                      $objom_prop = [];
        $city_prop = [];                            $prop_type_item = [];
        $prop_functional = [];                      $brend = [];

        foreach ($propertiesList as $propItem){
            $prop_el = pq($propItem);


            if($prop_el->find('label')->attr('feature_id') == '221') {
                if($prop_el->find('span'))
                    $prop_proizvoditelnost_min[] = $prop_el->find('span')->text();
                else $prop_proizvoditelnost_min = false;}

            if($prop_el->find('label')->attr('feature_id') == '250') {
                if($prop_el->find('span'))
                    $prop_zadavaemyj_obyom[] = $prop_el->find('span')->text();
                else $prop_zadavaemyj_obyom = false;}

                       if($prop_el->find('label')->attr('feature_id') == '252') {
                if($prop_el->find('span'))
                    $prop_rabota_akkumulyatora[] = $prop_el->find('span')->text();
                else $prop_rabota_akkumulyatora = false;}

            if($prop_el->find('label')->attr('feature_id') == '247') {
                if($prop_el->find('span'))
                    $prop_vid_dozatora[] = $prop_el->find('span')->text();
                else $prop_vid_dozatora = false;}

            if($prop_el->find('label')->attr('feature_id') == '260') {
                if($prop_el->find('span'))
                    $prop_tip_klinka[] = $prop_el->find('span')->text();
                else $prop_tip_klinka = false;}


            if($prop_el->find('label')->attr('feature_id') == '259') {
                if($prop_el->find('span'))
                    $prop_vid_tovara[] = $prop_el->find('span')->text();
                else $prop_vid_tovara = false;}


                 if($prop_el->find('label')->attr('feature_id') == '257') {
                if($prop_el->find('span'))
                    $prop_proizvodimye_gazy[] = $prop_el->find('span')->text();
                else $prop_proizvodimye_gazy = false;}


                        if($prop_el->find('label')->attr('feature_id') == '288') {
                if($prop_el->find('span'))
                    $prop_vid_skanera[] = $prop_el->find('span')->text();
                else $prop_vid_skanera = false;}


            if($prop_el->find('label')->attr('feature_id') == '395') {
                if($prop_el->find('span'))
                    $prop_chastota_ventilyacii_dyx_min[] = $prop_el->find('span')->text();
                else $prop_chastota_ventilyacii_dyx_min = false;}

                        if($prop_el->find('label')->attr('feature_id') == '396') {
                if($prop_el->find('span'))
                    $prop_dyxatelnyj_obemml[] = $prop_el->find('span')->text();
                else $prop_dyxatelnyj_obemml = false;}

            if($prop_el->find('label')->attr('feature_id') == '377') {
                if($prop_el->find('span'))
                    $prop_kolichestvo_sekcij[] = $prop_el->find('span')->text();
                else $prop_kolichestvo_sekcij = false;}


             if($prop_el->find('label')->attr('feature_id') == '387') {
                if($prop_el->find('span'))
                    $prop_ugol_naklona_golenimin_max[] = $prop_el->find('span')->text();
                 else $prop_ugol_naklona_golenimin_max = false;}


            if($prop_el->find('label')->attr('feature_id') == '276') {
                if($prop_el->find('span'))
                    $prop_pokazaniya_k_primeneniyu[] = $prop_el->find('span')->text();
                else $prop_pokazaniya_k_primeneniyu = false;}


            if($prop_el->find('label')->attr('feature_id') == '322') {
                if($prop_el->find('span'))
                    $prop_gruzopodemnost_kg[] = $prop_el->find('span')->text();
                else $prop_gruzopodemnost_kg = false;}


            if($prop_el->find('label')->attr('feature_id') == '318') {
                if($prop_el->find('span'))
                    $prop_regulirovka_vysoty_min_max_mm[] = $prop_el->find('span')->text();
                else $prop_regulirovka_vysoty_min_max_mm = false;}


            if($prop_el->find('label')->attr('feature_id') == '319') {
                if($prop_el->find('span'))
                    $prop_ugol_naklona_spinki_min_max[] = $prop_el->find('span')->text();
                else $prop_ugol_naklona_spinki_min_max = false;}


            if($prop_el->find('label')->attr('feature_id') == '195') {
                if($prop_el->find('span'))
                    $prop_tip_svetilnikov[] = $prop_el->find('span')->text();
                else $prop_tip_svetilnikov = false;}


            if($prop_el->find('label')->attr('feature_id') == '212') {
                if($prop_el->find('span'))
                    $prop_vid_reabilitacii[] = $prop_el->find('span')->text();
                else $prop_vid_reabilitacii = false;}


            if($prop_el->find('label')->attr('feature_id') == '291') {
                if($prop_el->find('span'))
                    $prop_diametr_bloka_osveshheniya_mm[] = $prop_el->find('span')->text();
                else $prop_diametr_bloka_osveshheniya_mm = false;}

            if($prop_el->find('label')->attr('feature_id') == '197') {
                if($prop_el->find('span'))
                    $prop_uroven_osveshhennosti_klk[] = $prop_el->find('span')->text();
                else $prop_uroven_osveshhennosti_klk = false;}

            if($prop_el->find('label')->attr('feature_id') == '159') {
                if($prop_el->find('span'))
                    $prop_type_regim_raboty[] = $prop_el->find('span')->text();
                else $prop_type_regim_raboty = false;}

            if($prop_el->find('label')->attr('feature_id') == '380') {
                if($prop_el->find('span'))
                    $prop_type_rezanie_s_koagulaciei[] = $prop_el->find('span')->text();
                else $prop_type_rezanie_s_koagulaciei = false;}

            if($prop_el->find('label')->attr('feature_id') == '379') {
                if($prop_el->find('span'))
                    $prop_type_mohnost_razreza[] = $prop_el->find('span')->text();
                else $prop_type_mohnost_razreza = false;}

            if($prop_el->find('label')->attr('feature_id') == '378') {
                if($prop_el->find('span'))
                    $prop_type_rabocha_chastota[] = $prop_el->find('span')->text();
                else $prop_type_rabocha_chastota = false;}

            if($prop_el->find('label')->attr('feature_id') == '261') {
                if($prop_el->find('span'))
                    $prop_type_ganarator[] = $prop_el->find('span')->text();
                else $prop_type_ganarator = false;}

            if($prop_el->find('label')->attr('feature_id') == '177') {
                if($prop_el->find('span'))
                    $prop_type_aparat[] = $prop_el->find('span')->text();
                else $prop_type_aparat = false;}


            if($prop_el->find('label')->attr('feature_id') == '289') {
                if($prop_el->find('span'))
                    $prop_type_instrument[] = $prop_el->find('span')->text();
                else $prop_type_instrument = false;}

            if($prop_el->find('label')->attr('feature_id') == '411') {
                if($prop_el->find('span'))
                    $prop_type_endoskopii[] = $prop_el->find('span')->text();
                else $prop_type_endoskopii = false;}

            if($prop_el->find('label')->attr('feature_id') == '375') {
                if($prop_el->find('span'))
                    $prop_derzatel_flakona[] = $prop_el->find('span')->text();
                else $prop_derzatel_flakona = false;}


            if($prop_el->find('label')->attr('feature_id') == '183') {
                if($prop_el->find('span'))
                    $prop_type_siduhka[] = $prop_el->find('span')->text();
                else $prop_type_siduhka = false;}

            if($prop_el->find('label')->attr('feature_id') == ' 374') {
                if($prop_el->find('span'))
                    $prop_type_stoika[] = $prop_el->find('span')->text();
                else $prop_type_stoika = false;}


            if($prop_el->find('label')->attr('feature_id') == '377') {
                if($prop_el->find('span'))
                    $prop_section[] = $prop_el->find('span')->text();
                else $prop_section = false;}

            if($prop_el->find('label')->attr('feature_id') == '214') {
                if($prop_el->find('span'))
                    $prop_material[] = $prop_el->find('span')->text();
                else $prop_material = false;}

            if($prop_el->find('label')->attr('feature_id') == '340') {
                if($prop_el->find('span'))
                    $prop_vmestimost[] = $prop_el->find('span')->text();
                else $prop_vmestimost = false;}

            if($prop_el->find('label')->attr('feature_id') == '339') {
                if($prop_el->find('span'))
                    $prop_forma[] = $prop_el->find('span')->text();
                else $prop_forma = false;}

            if($prop_el->find('label')->attr('feature_id') == '338') {
                if($prop_el->find('span'))
                    $prop_type_spa[] = $prop_el->find('span')->text();
                else $prop_type_spa = false;}


            if($prop_el->find('label')->attr('feature_id') == '298') {
                if($prop_el->find('span'))
                    $prop_num_forsun[] = $prop_el->find('span')->text();
                else $prop_num_forsun = false;
            }


            if($prop_el->find('label')->attr('feature_id') == '295') {
                if($prop_el->find('span'))
                    $objom_prop[] = $prop_el->find('span')->text();
                else $objom_prop = false;
            }


            if($prop_el->find('label')->attr('feature_id') == '181' || $prop_el->find('label')->attr('feature_id') == '219') {
               if($prop_el->find('span'))
                $city_prop[] = $prop_el->find('span')->text();
               else $city_prop = false;
            }

            if($prop_el->find('label')->attr('feature_id') == '271' || $prop_el->find('label')->attr('feature_id') =='210') {
                if($prop_el->find('span'))
                    $prop_type_item[] = $prop_el->find('span')->text();
                else $prop_type_item = false;
            }

            if($prop_el->find('label')->attr('feature_id') == '263') {
                if($prop_el->find('span'))
                    $prop_functional[] = $prop_el->find('span')->text();
                else $prop_functional = false;
            }


            if($prop_el->find('label')->text() == 'Бренд:') {
                if($prop_el->find('span'))
                    $brend[] = $prop_el->find('span')->text();
                else $brend = false;
            }


        }
                $post_data = array(
                    'post_title'    => wp_strip_all_tags( $NAME),
                    'post_content'  => $CONTENT,
                    'post_status'   => 'publish',
                    'post_author'   => 1,
                    'post_category' => 0,
                    'post_type' => 'product',
                    'tax_input' => array('product_cat'=>array($_GET['cat']))

                );



                $post_id = wp_insert_post( $post_data );


                wp_set_object_terms($post_id, 'simple', 'product_type');     //Тип товара (Простой товар)
                update_post_meta( $post_id, '_visibility', 'visible' );           // Видимость: открыто
                update_post_meta( $post_id, '_stock_status', 'instock');

               if($PRICE) {
                   update_post_meta($post_id, '_regular_price', $PRICE);
                   update_post_meta($post_id, '_price', $PRICE);
               }




                if($prop_rabota_akkumulyatora){
                    wp_set_object_terms($prop_rabota_akkumulyatora, 'pa_rabota-ot-akkumulyatora-ch');
                    $thedata = Array(
                        'name'=>'pa_rabota-ot-akkumulyatora-ch',
                        'value'=>$prop_rabota_akkumulyatora,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_rabota-ot-akkumulyatora-ch' => $thedata), $Attributes);
                }

                if($prop_zadavaemyj_obyom){
                    wp_set_object_terms($prop_zadavaemyj_obyom, 'pa_zadavaemyj-obyom-ml');
                    $thedata = Array(
                        'name'=>'pa_zadavaemyj-obyom-ml',
                        'value'=>$prop_zadavaemyj_obyom,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_zadavaemyj-obyom-ml' => $thedata), $Attributes);
                }

                          if($prop_gruzopodemnost_kg){
                    wp_set_object_terms($prop_gruzopodemnost_kg, 'pa_gruzopodemnost-kg');
                    $thedata = Array(
                        'name'=>'pa_gruzopodemnost-kg',
                        'value'=>$prop_gruzopodemnost_kg,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_gruzopodemnost-kg' => $thedata), $Attributes);
                }


                 if($prop_vid_dozatora){
                    wp_set_object_terms($prop_vid_dozatora, 'pa_vid-dozatora');
                    $thedata = Array(
                        'name'=>'pa_vid-dozatora',
                        'value'=>$prop_vid_dozatora,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_vid-dozatora' => $thedata), $Attributes);
                }


                   if($prop_tip_klinka){
                    wp_set_object_terms($prop_tip_klinka, 'pa_tip-klinka');
                    $thedata = Array(
                        'name'=>'pa_tip-klinka',
                        'value'=>$prop_tip_klinka,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_tip-klinka' => $thedata), $Attributes);
                }


                 if($prop_vid_tovara){
                            wp_set_object_terms($prop_vid_tovara, 'pa_vid-tovara');
                            $thedata = Array(
                                'name'=>'pa_vid-tovara',
                                'value'=>$prop_vid_tovara,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_vid-tovara' => $thedata), $Attributes);
                }


                if($prop_proizvodimye_gazy){
                            wp_set_object_terms($prop_proizvodimye_gazy, 'pa_proizvodimye-gazy');
                            $thedata = Array(
                                'name'=>'pa_proizvodimye-gazy',
                                'value'=>$prop_proizvodimye_gazy,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_proizvodimye-gazy' => $thedata), $Attributes);
                }


                 if($prop_proizvoditelnost_min){
                            wp_set_object_terms($prop_proizvoditelnost_min, 'pa_proizvoditelnost-l-min');
                            $thedata = Array(
                                'name'=>'pa_proizvoditelnost-l-min',
                                'value'=>$prop_proizvoditelnost_min,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_proizvoditelnost-l-min' => $thedata), $Attributes);
                }


                 if($prop_dyxatelnyj_obemml){
                            wp_set_object_terms($prop_dyxatelnyj_obemml , 'pa_dyxatelnyj-obemml');
                            $thedata = Array(
                                'name'=>'pa_dyxatelnyj-obemml',
                                'value'=>$prop_dyxatelnyj_obemml,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_dyxatelnyj-obemml' => $thedata), $Attributes);
                }


                           if($prop_chastota_ventilyacii_dyx_min){
                            wp_set_object_terms($prop_chastota_ventilyacii_dyx_min, 'pa_chastota-ventilyacii-dyx-min');
                            $thedata = Array(
                                'name'=>'pa_chastota-ventilyacii-dyx-min',
                                'value'=>$prop_chastota_ventilyacii_dyx_min,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_chastota-ventilyacii-dyx-min' => $thedata), $Attributes);
                }


                     if($prop_vid_skanera){
                            wp_set_object_terms($prop_vid_skanera, 'pa_vid-skanera');
                            $thedata = Array(
                                'name'=>'pa_vid-skanera',
                                'value'=>$prop_vid_skanera,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_vid-skanera' => $thedata), $Attributes);
                }


                if($prop_pokazaniya_k_primeneniyu){
                            wp_set_object_terms($prop_pokazaniya_k_primeneniyu, 'pa_pokazaniya-k-primeneniyu');
                            $thedata = Array(
                                'name'=>'pa_pokazaniya-k-primeneniyu',
                                'value'=>$prop_pokazaniya_k_primeneniyu,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_pokazaniya-k-primeneniyu' => $thedata), $Attributes);
                }


                if($prop_ugol_naklona_golenimin_max){
                            wp_set_object_terms($prop_ugol_naklona_golenimin_max, 'pa_ugol-naklona-golenimin-max');
                            $thedata = Array(
                                'name'=>'pa_ugol-naklona-golenimin-max',
                                'value'=>$prop_ugol_naklona_golenimin_max,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_ugol-naklona-golenimin-max' => $thedata), $Attributes);
                }


              if($prop_kolichestvo_sekcij){
                            wp_set_object_terms($prop_kolichestvo_sekcij, 'pa_kolichestvo-sekcij');
                            $thedata = Array(
                                'name'=>'pa_kolichestvo-sekcij',
                                'value'=>$prop_kolichestvo_sekcij,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_kolichestvo-sekcij' => $thedata), $Attributes);
                }



                 if($prop_ugol_naklona_spinki_min_max){
                            wp_set_object_terms($prop_ugol_naklona_spinki_min_max, 'pa_ugol-naklona-spinki-min-max');
                            $thedata = Array(
                                'name'=>'pa_ugol-naklona-spinki-min-max',
                                'value'=>$prop_ugol_naklona_spinki_min_max,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_ugol-naklona-spinki-min-max' => $thedata), $Attributes);
              }



                if($prop_vid_reabilitacii){
                            wp_set_object_terms($prop_vid_reabilitacii, 'pa_vid-reabilitacii');
                            $thedata = Array(
                                'name'=>'pa_vid-reabilitacii',
                                'value'=>$prop_vid_reabilitacii,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_vid-reabilitacii' => $thedata), $Attributes);
              }


                if($prop_regulirovka_vysoty_min_max_mm){
                            wp_set_object_terms($prop_regulirovka_vysoty_min_max_mm, 'pa_regulirovka-vysoty-min-max-mm');
                            $thedata = Array(
                                'name'=>'pa_regulirovka-vysoty-min-max-mm',
                                'value'=>$prop_regulirovka_vysoty_min_max_mm,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_regulirovka-vysoty-min-max-mm' => $thedata), $Attributes);
              }

                if($prop_type_regim_raboty){
                            wp_set_object_terms($prop_type_regim_raboty, 'pa_rezhim-raboty');
                            $thedata = Array(
                                'name'=>'pa_rezhim-raboty',
                                'value'=>$prop_type_regim_raboty,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_rezhim-raboty' => $thedata), $Attributes);
              }


                if($prop_diametr_bloka_osveshheniya_mm){
                            wp_set_object_terms($prop_diametr_bloka_osveshheniya_mm, 'pa_diametr-bloka-osveshheniya-mm');
                            $thedata = Array(
                                'name'=>'pa_diametr-bloka-osveshheniya-mm',
                                'value'=>$prop_diametr_bloka_osveshheniya_mm,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_diametr-bloka-osveshheniya-mm' => $thedata), $Attributes);
              }

                if($prop_uroven_osveshhennosti_klk){
                            wp_set_object_terms($prop_uroven_osveshhennosti_klk, 'pa_uroven-osveshhennosti-klk');
                            $thedata = Array(
                                'name'=>'pa_uroven-osveshhennosti-klk',
                                'value'=>$prop_uroven_osveshhennosti_klk,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_rezhim-raboty' => $thedata), $Attributes);
              }

                if($prop_tip_svetilnikov){
                            wp_set_object_terms($prop_tip_svetilnikov, 'pa_tip-svetilnikov');
                            $thedata = Array(
                                'name'=>'pa_tip-svetilnikov',
                                'value'=>$prop_tip_svetilnikov,
                                'is_visible' => '1',
                                'is_variation' => '0',
                                'is_taxonomy' => '1'
                            );
                            $Attributes = array_merge (array( 'pa_tip-svetilnikov' => $thedata), $Attributes);
              }


             if($prop_type_rezanie_s_koagulaciei){
                 wp_set_object_terms($prop_type_rezanie_s_koagulaciei, 'pa_rezanie-s-koagulyaciej-vt');
                 $thedata = Array(
                     'name'=>'pa_rezanie-s-koagulyaciej-vt',
                     'value'=>$prop_type_rezanie_s_koagulaciei,
                     'is_visible' => '1',
                     'is_variation' => '0',
                     'is_taxonomy' => '1'
                 );
                 $Attributes = array_merge (array( 'pa_rezanie-s-koagulyaciej-vt' => $thedata), $Attributes);
             }


            if($prop_type_mohnost_razreza){
                wp_set_object_terms($prop_type_mohnost_razreza, 'pa_moshhnost-razreza-vt');
                $thedata = Array(
                    'name'=>'pa_moshhnost-razreza-vt',
                    'value'=>$prop_type_mohnost_razreza,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_moshhnost-razreza-vt' => $thedata), $Attributes);
            }

          if($prop_type_rabocha_chastota){
              wp_set_object_terms($prop_type_rabocha_chastota, 'pa_rabochaya-chastota-mgc');
              $thedata = Array(
                  'name'=>'pa_rabochaya-chastota-mgc',
                  'value'=>$prop_type_ganarator,
                  'is_visible' => '1',
                  'is_variation' => '0',
                  'is_taxonomy' => '1'
              );
              $Attributes = array_merge (array( 'pa_rabochaya-chastota-mgc' => $thedata), $Attributes);
          }


        if($prop_type_ganarator){
            wp_set_object_terms($prop_type_ganarator, 'pa_generator');
            $thedata = Array(
                'name'=>'pa_generator',
                'value'=>$prop_type_ganarator,
                'is_visible' => '1',
                'is_variation' => '0',
                'is_taxonomy' => '1'
            );
            $Attributes = array_merge (array( 'pa_generator' => $thedata), $Attributes);
        }


         if($prop_type_aparat){
                wp_set_object_terms($prop_type_aparat, 'pa_tip');
                $thedata = Array(
                    'name'=>'pa_tip',
                    'value'=>$prop_type_aparat,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_tip' => $thedata), $Attributes);
         }


        if($prop_type_instrument){
            wp_set_object_terms($prop_type_instrument, 'pa_vid-instrumenta');
            $thedata = Array(
                'name'=>'pa_vid-instrumenta',
                'value'=>$prop_type_instrument,
                'is_visible' => '1',
                'is_variation' => '0',
                'is_taxonomy' => '1'
            );
            $Attributes = array_merge (array( 'pa_tip-endoskopii' => $thedata), $Attributes);
        }


        if($prop_type_endoskopii){
            wp_set_object_terms($prop_type_endoskopii, 'pa_tip-endoskopii');
            $thedata = Array(
                'name'=>'pa_tip-endoskopii',
                'value'=>$prop_type_endoskopii,
                'is_visible' => '1',
                'is_variation' => '0',
                'is_taxonomy' => '1'
            );
            $Attributes = array_merge (array( 'pa_tip-endoskopii' => $thedata), $Attributes);
        }


            if($prop_derzatel_flakona){
                wp_set_object_terms($prop_derzatel_flakona, 'pa_derzhatel-flakona-sht');
                $thedata = Array(
                    'name'=>'pa_derzhatel-flakona-sht',
                    'value'=>$prop_derzatel_flakona,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_derzhatel-flakona-sht' => $thedata), $Attributes);
            }


            if($prop_type_stoika){
                wp_set_object_terms($prop_type_stoika, 'pa_stojka');
                $thedata = Array(
                    'name'=>'pa_stojka',
                    'value'=>$prop_type_stoika,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_stojka' => $thedata), $Attributes);
            }


            if($prop_type_siduhka){
                wp_set_object_terms($prop_type_siduhka, 'pa_tip-sidushki');
                $thedata = Array(
                    'name'=>'pa_tip-sidushki',
                    'value'=>$prop_type_siduhka,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_tip-sidushki' => $thedata), $Attributes);
            }

             if($prop_section){
                 wp_set_object_terms($prop_section, 'pa_kolichestvo-sekcij');
                $thedata = Array(
                'name'=>'pa_kolichestvo-sekcij',
                'value'=>$prop_section,
                'is_visible' => '1',
                'is_variation' => '0',
                'is_taxonomy' => '1'
             );
             $Attributes = array_merge (array( 'pa_kolichestvo-sekcij' => $thedata), $Attributes);
            }


             if($prop_material){
                    wp_set_object_terms($prop_material, 'pa_material');
                    $thedata = Array(
                        'name'=>'pa_material',
                        'value'=>$prop_material,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_vmestimost-chel' => $thedata), $Attributes);
             }

            if($prop_vmestimost) {
                wp_set_object_terms($prop_vmestimost, 'pa_vmestimost-chel');
                $thedata = Array(
                    'name'=>'pa_vmestimost-chel',
                    'value'=>$prop_vmestimost,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_vmestimost-chel' => $thedata), $Attributes);
            }


            if($prop_forma) {
                wp_set_object_terms($prop_forma, 'pa_forma');
                $thedata = Array(
                    'name'=>'pa_forma',
                    'value'=>$prop_forma,
                    'is_visible' => '1',
                    'is_variation' => '0',
                    'is_taxonomy' => '1'
                );
                $Attributes = array_merge (array( 'pa_forma' => $thedata), $Attributes);
            }


             if($prop_type_spa) {
                 wp_set_object_terms($prop_type_spa, 'pa_vid-spa-bassejna');
                 $thedata = Array(
                     'name'=>'pa_vid-spa-bassejna',
                     'value'=>$prop_type_spa,
                     'is_visible' => '1',
                     'is_variation' => '0',
                     'is_taxonomy' => '1'
                 );
                 $Attributes = array_merge (array( 'pa_vid-spa-bassejna' => $thedata), $Attributes);
             }


                if($prop_num_forsun) {
                    wp_set_object_terms($prop_num_forsun, 'pa_kolichestvo-forsunok-sht');
                    $thedata = Array(
                        'name'=>'pa_kolichestvo-forsunok-sht',
                        'value'=>$prop_num_forsun,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_kolichestvo-forsunok-sht' => $thedata), $Attributes);
                }


                if($city_prop) {
                    wp_set_object_terms($post_id, $city_prop, 'pa_strana-proisxozhdeniya');
                    $thedata = Array(
                        'name'=>'pa_strana-proisxozhdeniya',
                        'value'=>$city_prop,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_strana-proisxozhdeniya' => $thedata), $Attributes);
                }



                if($objom_prop){

                    wp_set_object_terms($post_id, $objom_prop, 'pa_zadavaemyj-obyom-ml');
                    $thedata = Array(
                        'name'=>'pa_zadavaemyj-obyom-ml',
                        'value'=>$objom_prop,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_zadavaemyj-obyom-ml' => $thedata), $Attributes);

                }


                if($brend) {
                    wp_set_object_terms($post_id, $brend, 'pa_brend');
                    $thedata = Array(
                        'name'=>'pa_brend',
                        'value'=>$brend,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_brend' => $thedata), $Attributes);

                }


                if($prop_functional){

                    wp_set_object_terms($post_id, $prop_functional, 'pa_funkcii');
                    $thedata = Array(
                        'name'=>'pa_funkcii',
                        'value'=>$prop_functional,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_funkcii' => $thedata), $Attributes);

                }


                if($prop_type_item){
                    wp_set_object_terms($post_id, $prop_type_item, 'pa_naznachenie');
                    $thedata = Array(
                        'name'=>'pa_naznachenie',
                        'value'=>$prop_type_item,
                        'is_visible' => '1',
                        'is_variation' => '0',
                        'is_taxonomy' => '1'
                    );
                    $Attributes = array_merge (array( 'pa_naznachenie' => $thedata), $Attributes);
                }


        update_post_meta( $post_id, '_product_attributes', $Attributes);




        require_once(ABSPATH . 'wp-admin/includes/file.php');
        require_once(ABSPATH . 'wp-admin/includes/media.php');
        require_once(ABSPATH . "wp-admin" . '/includes/image.php');


        $tmp = download_url( $thumb_url );

        if(!is_wp_error($tmp)) {

       // Set variables for storage
       // fix file name for query strings

        preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
        $file_array['name'] = basename($matches[0]);
        $file_array['tmp_name'] = $tmp;
        //print_r ($file_array);
        //use media_handle_sideload to upload img:
        $thumbid = media_handle_sideload($file_array, $post_id, $NameProd); //Описание изображения
        set_post_thumbnail($post_id, $thumbid);}


/*
        foreach($image_gallery as $key => $itemImg){

        $values = pq($itemImg);
            $value = $hostlink.$values->attr('href');
            echo $value.'<br>';

                //print_r($tmp2);
                $tmp2 = download_url( $value );
                if ($tmp2) {
                    // fix file name for query strings
                    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $value, $matches);
                    $file_array2['name'] = basename($matches[0]);
                    $file_array2['tmp_name'] = $tmp2;
                    $imgID[$key] = media_handle_sideload( $file_array2, $post_id, $NameProd);   //Описание изображения
                    //print_r($imgID);
                };


            update_post_meta( $post_id, '_product_image_gallery', implode(", ", $imgID));
        };
*/

        shell_exec('rm -rf /tmp/*');

       /* break;*/


    }





 if($_GET['page'] < $_GET['stop']){
        $page = $_GET["page"]+1;
        echo '
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

<script>   
   $( document ).ready(function() {
     setTimeout(function() {
     window.location.href = "?url='.$_GET["url"].'&page='.$page.'&stop='.$_GET["stop"].'&cat='.$_GET["cat"].'"; 
 }, 1000);
});

</script>   ';
    }




}
?>


Обратный звонок1

Имя
Телефон
x


Имя
Телефон