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; } function atkp_search_products() { try { $azproducts = $this->quickSearch('product'); if($azproducts != null) { wp_send_json( $azproducts); } } catch(Exception $e) { $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) { $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) { $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) { $gif_data[] = array( 'error' => 'An error has occurred.', 'message' => $e->getMessage(), ); wp_send_json( $gif_data ); } } function quickSearch($searchType) { $shopid = ATKPTools::get_post_parameter('shop', 'string'); $keyword = ATKPTools::get_post_parameter('keyword', 'string'); $nounce = ATKPTools::get_post_parameter('request_nonce', 'string'); if ( !wp_verify_nonce( $nounce, 'atkp-search-nonce' ) ) throw new Exception('Nonce invalid'); if($shopid == '') throw new Exception('shop required'); if($keyword == '' && $searchType != 'department' && $searchType != 'filter') throw new Exception('keyword required'); require_once ATKP_PLUGIN_DIR.'/includes/shopproviders/atkp_shop_provider_base.php'; $shopids = explode('_', $shopid); $webservice = ATKPTools::get_post_setting($shopids[0], ATKP_SHOP_POSTTYPE.'_access_webservice'); $myprovider = atkp_shop_provider_base::retrieve_provider($webservice); if(isset($myprovider)) { $myprovider->checklogon($shopids[0], $shopid); if($searchType == 'department') return $myprovider->retrieve_departments(); else if($searchType == 'filter') return $myprovider->retrieve_filters(); else if($searchType == 'browsenode') return $myprovider->retrieve_browsenodes($keyword); else return $myprovider->quick_search($keyword, $searchType); } } } ?>