title ); # send the file to the browser as a download header( "Pragma: public" ); header( "Expires: 0" ); header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header( "Cache-Control: public" ); header( "Content-Description: File Transfer" ); header( "Content-type: application/octet-stream" ); header( "Content-Disposition: attachment; filename=\"" . $name . ".txt\"" ); header( "Content-Transfer-Encoding: utf-8" ); header( "Content-Length: " . strlen( $string ) ); echo $string; exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_reset_csvs() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } global $wpdb; $table = $wpdb->prefix . 'postmeta'; $wpdb->delete( $table, array( 'meta_key' => ATKP_SHOP_POSTTYPE . '_updatedon' ) ); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_import_demo() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } if ( ! file_exists( get_home_path() . '/../demo-data.sql' ) ) { return; } $democontent = file_get_contents( get_home_path() . '/../demo-data.sql' ); $demoparts = explode( '-newline-', $democontent ); global $wpdb; foreach ( $demoparts as $demopart ) { if ( $demopart == '' ) { continue; } $demoquery = str_replace( '-tblprefix-', $wpdb->prefix, $demopart ); $wpdb->query( $demoquery ); } header( 'Refresh:5; url=' . $_SERVER['HTTP_REFERER'], true, 303 ); //header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_reset_products() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } global $wpdb; $table = $wpdb->prefix . 'postmeta'; $wpdb->delete( $table, array( 'meta_key' => ATKP_PRODUCT_POSTTYPE . '_updatedon' ) ); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_reset_settings() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } global $wpdb; echo $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'options` where option_name like \'atkp_%\'' ); echo $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'comments` where comment_post_ID in (select ID FROM `' . $wpdb->prefix . 'posts` where post_type like \'atkp_%\')' ); echo $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'term_relationships` where object_id in (select ID FROM `' . $wpdb->prefix . 'posts` where post_type like \'atkp_%\')' ); echo $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'postmeta` where meta_key like \'atkp_%\'' ); echo $wpdb->query( 'DELETE FROM `' . $wpdb->prefix . 'posts` where post_type like \'atkp_%\'' ); echo $wpdb->query( 'DROP TABLE `' . strtolower( $wpdb->prefix . ATKP_PLUGIN_PREFIX . '_productdata' ) . '`' ); echo $wpdb->query( 'DROP TABLE `' . strtolower( $wpdb->prefix . ATKP_PLUGIN_PREFIX . '_offertable' ) . '`' ); //header( 'Refresh:5; url='.$_SERVER['HTTP_REFERER'], true, 303); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_import_offers() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } // // $atkp_offertable_helper = new atkp_offertable_helper(); // // //manuelle angebote in die neue angebote tabelle übertragen // $page = 1; // $posts_per_page = 50; // do{ // // $posts_found = array( // 'posts_per_page' => $posts_per_page, // 'paged' => $page, // 'post_status' => array( 'draft', 'publish' ), // 'post_type' => ATKP_PRODUCT_POSTTYPE, // // 'meta_query' => array( // 'relation' => 'AND', // array( // 'key' => ATKP_PRODUCT_POSTTYPE . '_offers', // 'compare' => 'EXISTS', // ), // array( // 'key' => ATKP_PRODUCT_POSTTYPE . '_offersimported', // 'compare' => 'NOT EXISTS', // ) // ) // ); // $posts = new WP_Query( $posts_found ); // // while ( $posts->have_posts() ) { // $posts->the_post(); // // $post_id = get_the_ID(); // // //echo $post_id;exit; // // $offers = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_offers' ); // // if ( $offers != null ) { // $xx = 1; // foreach($offers as $offer) // $offer->id = $xx++; // // $atkp_offertable_helper->update_offers_by_productid($post_id, $offers, true); // } // // ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_offersimported', true ); // } // // wp_reset_postdata(); // // $page++; // }while(count($posts->posts) === $posts_per_page); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_reset_lists() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } global $wpdb; $table = $wpdb->prefix . 'postmeta'; $wpdb->delete( $table, array( 'meta_key' => ATKP_LIST_POSTTYPE . '_updatedon' ) ); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_clear_transient() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } global $wpdb; $result = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name LIKE '_transient_" . ATKP_PLUGIN_PREFIX . "_%'" ); foreach ( $result as $row ) { delete_transient( str_replace( '_transient_', '', $row->option_name ), true ); } header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_clear_logfile() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } if ( file_exists( ATKP_LOGFILE ) ) { unlink( ATKP_LOGFILE ); } header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_sendmessages() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-sendmessages', false ) ) { throw new Exception( 'Nonce invalid' ); } $cron = new atkp_cronjob_new( array() ); $cron->send_datamail( true ); header( 'Location: ' . $_SERVER['HTTP_REFERER'] ); exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_download_logfile() { try { $nounce = ATKPTools::get_get_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-download-log', false ) ) { throw new Exception( 'Nonce invalid' ); } $string = ''; if ( file_exists( ATKP_LOGFILE ) ) { $string = file_get_contents( ATKP_LOGFILE ); } $name = sanitize_title( 'affiliate-toolkit-log.txt' ); # send the file to the browser as a download header( "Pragma: public" ); header( "Expires: 0" ); header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header( "Cache-Control: public" ); header( "Content-Description: File Transfer" ); header( "Content-type: text/plain" ); header( "Content-Disposition: attachment; filename=\"" . $name . ".txt\"" ); header( "Content-Transfer-Encoding: utf-8" ); header( "Content-Length: " . strlen( $string ) ); echo $string; exit; } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_create_list() { try { $nounce = ATKPTools::get_post_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-import-nonce', false ) ) { throw new Exception( 'Nonce invalid' ); } $shopid = ATKPTools::get_post_parameter( 'shop', 'string' ); $searchterm = ATKPTools::get_post_parameter( 'searchterm', 'string' ); $listtype = ATKPTools::get_post_parameter( 'listtype', 'string' ); $title = ATKPTools::get_post_parameter( 'title', 'string' ); $department = ATKPTools::get_post_parameter( 'department', 'string' ); $sortby = ATKPTools::get_post_parameter( 'sortby', 'string' ); $loadmoreoffers = ATKPTools::get_post_parameter( 'loadmoreoffers', 'bool' ); //shop: shop, title: title, department: department, sortby:sortby, browsenode:browsenodeid, searchterm: keyword, listtype: source, loadmoreoffers: loadmoreoffers $post_id = ATKPTools::create_list( $title, $shopid, $listtype, $searchterm, $department, $sortby, $loadmoreoffers ); $listservice = new atkp_listservice( array() ); $shop = $shopid != '' ? atkp_shop::load( $shopid, true ) : null; $listservice->update_lists( $shop, array( $post_id ) ); $gif_data[] = array( 'postid' => $post_id, 'title' => get_the_title( $post_id ), 'edit_url' => get_edit_post_link( $post_id ), ); wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_import_product() { try { $nounce = ATKPTools::get_post_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-import-nonce' ) ) { throw new Exception( 'Nonce invalid' ); } $shopid = ATKPTools::get_post_parameter( 'shop', 'string' ); $asin = ATKPTools::get_post_parameter( 'asin', 'string' ); $asintype = ATKPTools::get_post_parameter( 'asintype', 'string' ); $title = ATKPTools::get_post_parameter( 'title', 'string' ); $status = ATKPTools::get_post_parameter( 'status', 'string' ); $importurl = ATKPTools::get_post_parameter( 'importurl', 'allhtml' ); $brand = ATKPTools::get_post_parameter( 'brand', 'string' ); $mpn = ATKPTools::get_post_parameter( 'mpn', 'string' ); if ( $shopid == '' ) { throw new Exception( 'shop required' ); } if ( $asin == '' ) { throw new Exception( 'asin required' ); } $globaltools = new atkp_global_tools(); $gif_data = $globaltools->atkp_import_product( $shopid, $asin, $asintype, $title, $status, $importurl, $brand, $mpn ); wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_get_object() { try { $nounce = ATKPTools::get_post_parameter( 'request_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, 'atkp-get-nonce' ) ) { throw new Exception( 'Nonce invalid' ); } $post_type = ATKPTools::get_post_parameter( 'post_type', 'string' ); $id = ATKPTools::get_post_parameter( 'post_id', 'string' ); if ( $post_type == '' ) { throw new Exception( 'post_type required' ); } if ( $id == '' ) { throw new Exception( 'id required' ); } $gif_data[] = array(); switch ( $post_type ) { case ATKP_PRODUCT_POSTTYPE: case ATKP_LIST_POSTTYPE: $gif_data['post_id'] = $id; $gif_data['post_type'] = $post_type; $gif_data['title'] = get_the_title( $id ); $gif_data['edit_url'] = get_edit_post_link( $id ); break; default: throw new exception( 'unknown posttype: ' . $post_type ); } wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_frontend_search_products() { try { $azproducts = $this->localSearch( true ); if ( $azproducts != null ) { wp_send_json( $azproducts ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_live_addean_backend() { try { $html = $this->addeantoproduct(); $gif_data[] = array( 'html' => $html, ); wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_live_search_backend() { try { $html = $this->liveSearchBackend(); $gif_data[] = array( 'html' => $html, ); wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_live_search_render() { try { $html = $this->liveSearch(); $gif_data[] = array( 'html' => $html, ); wp_send_json( $gif_data ); } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_search_local_products() { try { $azproducts = $this->localSearch(); if ( $azproducts != null ) { wp_send_json( $azproducts ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_search_products() { try { $azproducts = $this->quickSearch( 'product' ); if ( $azproducts != null ) { wp_send_json( $azproducts ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_search_filters() { try { $azproducts = $this->quickSearch( 'filter' ); if ( $azproducts != null ) { wp_send_json( $azproducts ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_search_departments() { try { $azproducts = $this->quickSearch( 'department' ); if ( $azproducts != null ) { wp_send_json( $azproducts ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function atkp_search_browsenodes() { try { $aznodes = $this->quickSearch( 'browsenode' ); if ( $aznodes != null ) { wp_send_json( $aznodes ); } } catch ( Exception $e ) { ATKPLog::LogError( $e->getMessage() ); $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function addeantoproduct() { $productid = ATKPTools::get_post_parameter( 'productid', 'int' ); $ean = ATKPTools::get_post_parameter( 'ean', 'string' ); $eans = ATKPTools::get_post_setting( $productid, ATKP_PRODUCT_POSTTYPE . '_ean' ); $eanarray = explode( ',', $eans ); $neweanarray = explode( ',', $ean ); foreach ( $neweanarray as $newean ) { if ( ! in_array( $newean, $eanarray ) ) { array_push( $eanarray, $newean ); } } $eanarray = array_filter( $eanarray, function ( $value ) { return $value !== ''; } ); $eans = implode( ',', $eanarray ); ATKPTools::set_post_setting( $productid, ATKP_PRODUCT_POSTTYPE . '_ean', $eans ); } function liveSearchBackend() { $shopid = ATKPTools::get_post_parameter( 'shopid', 'int' ); $keyword = ATKPTools::get_post_parameter( 'keyword', 'string' ); $searchoption = ATKPTools::get_post_parameter( 'searchoption', 'string' ); $asintype = ATKPTools::get_post_parameter( 'asintype', 'string' ); if ( $keyword == '' ) { return __( 'Search term is required', ATKP_PLUGIN_PREFIX ); } $shop = atkp_shop::load( $shopid ); $resultVal = ''; if ( $shop != null && $shop->provider != null ) { $resultVal = '
| ' . __( 'Image', ATKP_PLUGIN_PREFIX ) . ' | ' . __( 'Title', ATKP_PLUGIN_PREFIX ) . ' | ' . __( 'Status', ATKP_PLUGIN_PREFIX ) . ' | |
|---|---|---|---|
|
' . ( isset( $product['imageurl'] ) ? ' |
' . $product['title'] . '
' . __( 'Unique ID', ATKP_PLUGIN_PREFIX ) . ': ' . $asin . ', EAN: ' . ( isset( $product['ean'] ) ? $product['ean'] : '-' ) . ', ' . __( 'Articlenumber', ATKP_PLUGIN_PREFIX ) . ': ' . ( isset( $product['articlenumber'] ) ? $product['articlenumber'] : '-' ) . ' ' . ( isset( $product['saleprice'] ) ? ', ' . sprintf( __( 'Price: %s', ATKP_PLUGIN_PREFIX ), $product['saleprice'] ) : '' ) . ' ' . __( 'View product', ATKP_PLUGIN_PREFIX ) . ' |
' . ( $this->get_product_status( $searchoption, $product, $asin2 ) ) . ' |
';
$result .= '' . __( 'Product imported.', ATKP_PLUGIN_PREFIX ) . '