Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php error_log(date('d.m.Y H:i:s').' WCAS: catalogue sync started'); set_time_limit(0);..

Decoded Output download

<?php 
 error_log(date('d.m.Y H:i:s').' WCAS: catalogue sync started'); set_time_limit(0); if( php_sapi_name() !== 'cli' ) { die("Meant to be run from command line"); } function find_wordpress_base_path() { $dir = dirname(__FILE__); do { if( file_exists($dir."/wp-config.php") ) { return $dir; } } while( $dir = realpath("$dir/..") ); return null; } define('BASE_PATH', find_wordpress_base_path()."/" ); define('WP_USE_THEMES', false); global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header; require(BASE_PATH . 'wp-load.php'); global $xml_cats, $xml_names; $WCAS_Integration = new WCAS_Integration(); $site_id = (int)$WCAS_Integration->settings['site_id']; if ($site_id){ if ( ! file_exists ( WCAS_XML_DIR.'/site_'.$site_id.'.yml' ) ){ error_log(date('d.m.Y H:i:s').' WCAS: no main yml file found. Trying to download it.'); $WCAS_Integration->download_xml($site_id); } } $files = scandir(WCAS_XML_DIR); $xml_roots = array(); $xml_cats = array(); $xml_names = array(); foreach ($files as $file){ if (preg_match('|^site_\d+\.yml$|',$file)) { $yml_catalog = simplexml_load_file( WCAS_XML_DIR.'/'.$file ); foreach ($yml_catalog->shop->categories->category as $category){ $attr = $category->attributes(); if ( empty($attr['id']) ) continue; $xml_cat_id = (string)$attr['id']; $xml_names[$xml_cat_id] = wp_unslash(trim((string)$category)); if ( empty($attr['parentId']) ){ $parent_cat_id = '0'; if ( !in_array($xml_cat_id, $xml_roots) ) $xml_roots[] = $xml_cat_id; } else{ $parent_cat_id = (string)$attr['parentId']; if ( empty($xml_cats[$parent_cat_id]) ) $xml_cats[$parent_cat_id]=array(); if ( !in_array($xml_cat_id, $xml_cats[$parent_cat_id]) ) $xml_cats[$parent_cat_id][] = $xml_cat_id; } } } } foreach ( $xml_roots as $tmp=>$root_id ){ if ( in_multiarray($root_id, $xml_cats) ) unset ( $xml_roots[$tmp] ); } $all_cats = $xml_cats; $all_cats[0] = $xml_roots; foreach ( $all_cats as $cats_arr ){ $tmp_names = array(); foreach ( $cats_arr as $xml_cat_id ){ $tmp_names[$xml_cat_id] = $xml_names[$xml_cat_id]; } $arr_cnt = array_count_values($tmp_names); foreach ( $arr_cnt as $title=>$cnt){ if ( $cnt > 1 ) { $found = array_keys( $tmp_names, $title ); for( $i=1, $max=count($found); $i<$max; $i++ ){ $xml_names[$found[$i]] .= ' '.$i; } } } } if(!count($xml_roots)) die('cant find any root categories in xml'); $final = make_tree($xml_roots); $xml_roots= null; $xml_cats = null; $all_cats = null; global $assigned, $wp_parent; $assigned = array(); $wp_parent = array(); $wp_cats = get_terms( 'product_cat', array( 'hide_empty' => 0, 'fields' => 'id=>parent', ) ); foreach ( $wp_cats as $cat_id=>$parent_cat_id ){ $term_meta = get_option( "taxonomy_".$cat_id ); if ( !empty($term_meta['as_cat_id']) ) { $assigned[$cat_id] = $term_meta['as_cat_id']; $wp_parent[$cat_id] = $parent_cat_id; } } $wp_cats = null; foreach ( $final as $xml_cat=>$child ){ fix_cat($xml_cat, 0, $child); } error_log('WCAS: catalogue sync finished'); function fix_cat($xml_cat, $xml_parent_cat, $child){ global $xml_names, $assigned, $wp_parent; $wp_cat_id = array_search( $xml_cat, $assigned ); if ( !$wp_cat_id ){ if ( $xml_parent_cat ) $wp_parent_cat_id = array_search( $xml_parent_cat, $assigned ); else $wp_parent_cat_id = 0; $res = wp_insert_term( $xml_names[$xml_cat], 'product_cat', $args = array('parent'=>$wp_parent_cat_id, 'slug'=>wcas_str2slug($xml_names[$xml_cat]) ) ); if ( $res instanceof WP_Error ){ error_log ('ERROR adding cat with apishops_id='.$xml_cat.'. Name: '.$xml_names[$xml_cat]); error_log ( print_r($res,1) ); error_log ('EXIT'); exit; } $term_meta = get_option( "taxonomy_".$res['term_id'] ); $term_meta['as_cat_id'] = $xml_cat; update_option( "taxonomy_".$res['term_id'], $term_meta ); $assigned[$res['term_id']] = $xml_cat; $wp_parent[$res['term_id']] = $xml_parent_cat; error_log ("OK. New catalogue added. Cat id (AS):".$xml_cat.", cat id (site): ".$res['term_id'] .",	name: ".$xml_names[$xml_cat] .( !empty($xml_names[$xml_parent_cat]) ? "	(parent: ".$xml_names[$xml_parent_cat].")" : "" ) ); } else { $curr_wp_parent_cat_id = $wp_parent[$wp_cat_id]; if( $xml_parent_cat ) $must_wp_parent_cat_id = array_search( $xml_parent_cat, $assigned ); else $must_wp_parent_cat_id = 0; if ( $curr_wp_parent_cat_id != $must_wp_parent_cat_id){ $term = get_term_by('id',$wp_cat_id,'product_cat'); $res = wp_update_term( $term->term_id, 'product_cat', $args = array('parent' => $must_wp_parent_cat_id) ); if ( $res instanceof WP_Error ){ error_log ('ERROR moving cat '.$term->term_id); error_log ( print_r($res,1) ); error_log ('EXIT'); exit; } $wp_parent[$wp_cat_id] = $must_wp_parent_cat_id; error_log ('OK. Fix parent for catalogue. Cat id (AS):'.$xml_cat.', cat id (site): '.$wp_cat_id); } } if ( !empty($child) && is_array($child) && count($child) ) { foreach ( $child as $xml_cat_2=>$child_2){ fix_cat($xml_cat_2, $xml_cat, $child_2); } } } function make_tree ( $work_arr ){ global $xml_cats; foreach ( $work_arr as $cat_id ){ if (!empty($xml_cats[$cat_id])) $final[$cat_id] = make_tree($xml_cats[$cat_id] ); else $final[$cat_id] = ''; } return $final; } function in_multiarray ( $value, $array ){ if( empty($value) ) return FALSE; if( !is_array($array) || !count($array) ) return FALSE; foreach ( $array as $arr ){ if ( !is_array($arr) ){ if ( $arr==$value ) return TRUE; } else{ if ( in_multiarray ( $value, $arr ) ) return TRUE; } } return FALSE; } function wcas_str2slug($string) { $converter = array( '' => 'a', '' => 'b', '' => 'v', '' => 'g', '' => 'd', '' => 'e', '' => 'yo', '' => 'zh', '' => 'z', '' => 'i', '' => 'j', '' => 'k', '' => 'l', '' => 'm', '' => 'n', '' => 'o', '' => 'p', '' => 'r', '' => 's', '' => 't', '' => 'u', '' => 'f', '' => 'h', '' => 'c', '' => 'ch', '' => 'sh', '' => 'shch', '' => '', '' => 'y', '' => '', '' => 'eh', '' => 'yu', '' => 'ya', '' => 'a', '' => 'b', '' => 'v', '' => 'g', '' => 'd', '' => 'e', '' => 'yo', '' => 'zh', '' => 'z', '' => 'i', '' => 'j', '' => 'k', '' => 'l', '' => 'm', '' => 'n', '' => 'o', '' => 'p', '' => 'r', '' => 's', '' => 't', '' => 'u', '' => 'f', '' => 'h', '' => 'c', '' => 'ch', '' => 'sh', '' => 'shch', '' => '', '' => 'y', '' => '', '' => 'eh', '' => 'yu', '' => 'ya', ); $str = strtr($string, $converter); $str = strtolower($str); $str = preg_replace('|[^-a-z0-9_]+|', '-', $str); $str = preg_replace('|-{2,}|', '-', $str); $str = trim($str, "-"); return $str; }  ?>

Did this file decode correctly?

Original Code

<?php
 error_log(date('d.m.Y H:i:s').' WCAS: catalogue sync started'); set_time_limit(0); if( php_sapi_name() !== 'cli' ) { die("Meant to be run from command line"); } function find_wordpress_base_path() { $dir = dirname(__FILE__); do { if( file_exists($dir."/wp-config.php") ) { return $dir; } } while( $dir = realpath("$dir/..") ); return null; } define('BASE_PATH', find_wordpress_base_path()."/" ); define('WP_USE_THEMES', false); global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header; require(BASE_PATH . 'wp-load.php'); global $xml_cats, $xml_names; $WCAS_Integration = new WCAS_Integration(); $site_id = (int)$WCAS_Integration->settings['site_id']; if ($site_id){ if ( ! file_exists ( WCAS_XML_DIR.'/site_'.$site_id.'.yml' ) ){ error_log(date('d.m.Y H:i:s').' WCAS: no main yml file found. Trying to download it.'); $WCAS_Integration->download_xml($site_id); } } $files = scandir(WCAS_XML_DIR); $xml_roots = array(); $xml_cats = array(); $xml_names = array(); foreach ($files as $file){ if (preg_match('|^site_\d+\.yml$|',$file)) { $yml_catalog = simplexml_load_file( WCAS_XML_DIR.'/'.$file ); foreach ($yml_catalog->shop->categories->category as $category){ $attr = $category->attributes(); if ( empty($attr['id']) ) continue; $xml_cat_id = (string)$attr['id']; $xml_names[$xml_cat_id] = wp_unslash(trim((string)$category)); if ( empty($attr['parentId']) ){ $parent_cat_id = '0'; if ( !in_array($xml_cat_id, $xml_roots) ) $xml_roots[] = $xml_cat_id; } else{ $parent_cat_id = (string)$attr['parentId']; if ( empty($xml_cats[$parent_cat_id]) ) $xml_cats[$parent_cat_id]=array(); if ( !in_array($xml_cat_id, $xml_cats[$parent_cat_id]) ) $xml_cats[$parent_cat_id][] = $xml_cat_id; } } } } foreach ( $xml_roots as $tmp=>$root_id ){ if ( in_multiarray($root_id, $xml_cats) ) unset ( $xml_roots[$tmp] ); } $all_cats = $xml_cats; $all_cats[0] = $xml_roots; foreach ( $all_cats as $cats_arr ){ $tmp_names = array(); foreach ( $cats_arr as $xml_cat_id ){ $tmp_names[$xml_cat_id] = $xml_names[$xml_cat_id]; } $arr_cnt = array_count_values($tmp_names); foreach ( $arr_cnt as $title=>$cnt){ if ( $cnt > 1 ) { $found = array_keys( $tmp_names, $title ); for( $i=1, $max=count($found); $i<$max; $i++ ){ $xml_names[$found[$i]] .= ' '.$i; } } } } if(!count($xml_roots)) die('cant find any root categories in xml'); $final = make_tree($xml_roots); $xml_roots= null; $xml_cats = null; $all_cats = null; global $assigned, $wp_parent; $assigned = array(); $wp_parent = array(); $wp_cats = get_terms( 'product_cat', array( 'hide_empty' => 0, 'fields' => 'id=>parent', ) ); foreach ( $wp_cats as $cat_id=>$parent_cat_id ){ $term_meta = get_option( "taxonomy_".$cat_id ); if ( !empty($term_meta['as_cat_id']) ) { $assigned[$cat_id] = $term_meta['as_cat_id']; $wp_parent[$cat_id] = $parent_cat_id; } } $wp_cats = null; foreach ( $final as $xml_cat=>$child ){ fix_cat($xml_cat, 0, $child); } error_log('WCAS: catalogue sync finished'); function fix_cat($xml_cat, $xml_parent_cat, $child){ global $xml_names, $assigned, $wp_parent; $wp_cat_id = array_search( $xml_cat, $assigned ); if ( !$wp_cat_id ){ if ( $xml_parent_cat ) $wp_parent_cat_id = array_search( $xml_parent_cat, $assigned ); else $wp_parent_cat_id = 0; $res = wp_insert_term( $xml_names[$xml_cat], 'product_cat', $args = array('parent'=>$wp_parent_cat_id, 'slug'=>wcas_str2slug($xml_names[$xml_cat]) ) ); if ( $res instanceof WP_Error ){ error_log ('ERROR adding cat with apishops_id='.$xml_cat.'. Name: '.$xml_names[$xml_cat]); error_log ( print_r($res,1) ); error_log ('EXIT'); exit; } $term_meta = get_option( "taxonomy_".$res['term_id'] ); $term_meta['as_cat_id'] = $xml_cat; update_option( "taxonomy_".$res['term_id'], $term_meta ); $assigned[$res['term_id']] = $xml_cat; $wp_parent[$res['term_id']] = $xml_parent_cat; error_log ("OK. New catalogue added. Cat id (AS):".$xml_cat.", cat id (site): ".$res['term_id'] .",\tname: ".$xml_names[$xml_cat] .( !empty($xml_names[$xml_parent_cat]) ? "\t(parent: ".$xml_names[$xml_parent_cat].")" : "" ) ); } else { $curr_wp_parent_cat_id = $wp_parent[$wp_cat_id]; if( $xml_parent_cat ) $must_wp_parent_cat_id = array_search( $xml_parent_cat, $assigned ); else $must_wp_parent_cat_id = 0; if ( $curr_wp_parent_cat_id != $must_wp_parent_cat_id){ $term = get_term_by('id',$wp_cat_id,'product_cat'); $res = wp_update_term( $term->term_id, 'product_cat', $args = array('parent' => $must_wp_parent_cat_id) ); if ( $res instanceof WP_Error ){ error_log ('ERROR moving cat '.$term->term_id); error_log ( print_r($res,1) ); error_log ('EXIT'); exit; } $wp_parent[$wp_cat_id] = $must_wp_parent_cat_id; error_log ('OK. Fix parent for catalogue. Cat id (AS):'.$xml_cat.', cat id (site): '.$wp_cat_id); } } if ( !empty($child) && is_array($child) && count($child) ) { foreach ( $child as $xml_cat_2=>$child_2){ fix_cat($xml_cat_2, $xml_cat, $child_2); } } } function make_tree ( $work_arr ){ global $xml_cats; foreach ( $work_arr as $cat_id ){ if (!empty($xml_cats[$cat_id])) $final[$cat_id] = make_tree($xml_cats[$cat_id] ); else $final[$cat_id] = ''; } return $final; } function in_multiarray ( $value, $array ){ if( empty($value) ) return FALSE; if( !is_array($array) || !count($array) ) return FALSE; foreach ( $array as $arr ){ if ( !is_array($arr) ){ if ( $arr==$value ) return TRUE; } else{ if ( in_multiarray ( $value, $arr ) ) return TRUE; } } return FALSE; } function wcas_str2slug($string) { $converter = array( '' => 'a', '' => 'b', '' => 'v', '' => 'g', '' => 'd', '' => 'e', '' => 'yo', '' => 'zh', '' => 'z', '' => 'i', '' => 'j', '' => 'k', '' => 'l', '' => 'm', '' => 'n', '' => 'o', '' => 'p', '' => 'r', '' => 's', '' => 't', '' => 'u', '' => 'f', '' => 'h', '' => 'c', '' => 'ch', '' => 'sh', '' => 'shch', '' => '', '' => 'y', '' => '', '' => 'eh', '' => 'yu', '' => 'ya', '' => 'a', '' => 'b', '' => 'v', '' => 'g', '' => 'd', '' => 'e', '' => 'yo', '' => 'zh', '' => 'z', '' => 'i', '' => 'j', '' => 'k', '' => 'l', '' => 'm', '' => 'n', '' => 'o', '' => 'p', '' => 'r', '' => 's', '' => 't', '' => 'u', '' => 'f', '' => 'h', '' => 'c', '' => 'ch', '' => 'sh', '' => 'shch', '' => '', '' => 'y', '' => '', '' => 'eh', '' => 'yu', '' => 'ya', ); $str = strtr($string, $converter); $str = strtolower($str); $str = preg_replace('|[^-a-z0-9_]+|', '-', $str); $str = preg_replace('|-{2,}|', '-', $str); $str = trim($str, "-"); return $str; } 

Function Calls

date 1

Variables

None

Stats

MD5 346555f412c35c903917d44afce63dc3
Eval Count 0
Decode Time 122 ms