ID, ATKP_FIELDGROUP_POSTTYPE.'_fields'); foreach ($fields as $newfield ) { array_push($allfields, $newfield); } } $newfields = $this->get_rows($importurl); foreach($newfields as $nfield) { try { $udf = null; foreach($allfields as $field) { if($field->caption == sanitize_text_field($nfield['name'])) { $udf = $field; break; } } if($udf == null) continue; $fieldvalue = sanitize_text_field($nfield['caption']); if($udf->type == 6) { //update taxonomy ATKPTools::check_taxonomy($post_id, $udf->name, $fieldvalue, false); } else { $fieldname = 'cf_'.$udf->name; if($udf->format == 'number') { //extract number from string $fieldvalue = preg_replace("/[^0-9]/","",$fieldvalue); $fieldvalue = intval($fieldvalue); } //$oldval =ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE.'_'.$fieldname); //if($oldval == '') ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE.'_'.$fieldname , $fieldvalue); } } catch(Exception $e) { } } }catch(Exception $e) { } } public function get_rows($url) { $fields = array(); if(ATKPTools::startsWith($url, 'https://www.billiger.de/')) { if ( function_exists( 'wp_remote_get' ) ) { $response = wp_remote_get( $url); $statusCode = null; if ( function_exists( 'is_wp_error' ) && ! is_wp_error( $response ) ) { // Success if ( isset( $response['response']['code'] ) ) { $statusCode = $response['response']['code']; } if ( '200' == $statusCode ) { $page = $response['body']; } } } if (!class_exists('simple_html_dom')) { require_once ATKP_PLUGIN_DIR . '/lib/simple_html_dom.php'; } $html = new simple_html_dom(); $html->load($page); if (!$html) return false; $productinfo = $html->find('div.product-information', 0); $keypairs = $productinfo->find('div[class=key-value-pairs]'); $field = null; foreach($keypairs as $keypair) { foreach($keypair->children as $child) { if(strpos($child->class, 'key') !== false) { if($field['name'] != 'Marke' && $field['name'] != 'Gelistet seit') array_push($fields, $field); $div = $child->find('span[class=pull]',0); $field = array(); $field['name'] = trim($div->plaintext); $desc = $child->find('div[class=tooltip]',0); if($desc != null) $field['description'] = trim($desc->find('p',0)->plaintext); } else if(strpos($child->class, 'value') !== false) { $field['caption'] = trim($child->plaintext); } } if($field != null && $field['name'] != '') array_push($fields, $field); } } else { $arr = explode("\n", $url); foreach($arr as $line){ $parts = explode("\t", $line); if(count($parts) == 1) { //wenn kein tabulator dazwischen, trennen mittels leerzeichen $parts = explode(" ", $line); } $field = array(); $field['name'] = trim($parts[0]); array_shift ($parts); $field['caption'] = trim(implode(" ",$parts)); array_push($fields, $field); } } //$udf = new atkp_udfield(); return $fields; } } ?>