From 2f1ffb3fb7c2676ea0b226d4e9eb1fc9f69a6b25 Mon Sep 17 00:00:00 2001 From: ma7 Date: Wed, 25 Jun 2014 10:14:04 +0430 Subject: [PATCH] update --- README.md | 2 - README.txt | 54 ++++ ZarinpalZarinGate.php | 260 ------------------ images/logo.png | Bin 0 -> 9484 bytes index.php | 334 +++++++++++++++++++++++ lib/nusoap.php => nusoap.php | 515 +++++++++++++---------------------- 6 files changed, 573 insertions(+), 592 deletions(-) delete mode 100644 README.md create mode 100644 README.txt delete mode 100644 ZarinpalZarinGate.php create mode 100644 images/logo.png create mode 100644 index.php rename lib/nusoap.php => nusoap.php (94%) diff --git a/README.md b/README.md deleted file mode 100644 index ee43263..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -ZarinGate-WooCommece-V2 -======================= diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..f02dd07 --- /dev/null +++ b/README.txt @@ -0,0 +1,54 @@ +=== Zarinpal Woocommerce Payment Gateway === +Contributors: Amini7 +Donate link: http://masoudamini.ir/ +Tags: zarinpal,Woocommerce,Payment,Gateway,farsi,persian,زرین پال,پرداخت,ووکامرس,درگاه +Requires at least: 3.0.1 +Tested up to: 3.9 +Stable tag: 4.3 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +افزونه درگاه پرداخت زرین پال برای ووکامرس (زرین گیت) + +== Description == + +افزونه درگاه پرداخت زرین پال برای ووکامرس (زرین گیت) + + + +== Installation == + +This section describes how to install the plugin and get it working. + +e.g. + +1. Upload `WebGate-WooCommerce-V2/index.php` to the `/wp-content/plugins/` directory +2. Activate the plugin through the 'Plugins' menu in WordPress +3.Enter your merchantID in setting + +== Frequently Asked Questions == + + + +== Screenshots == + + + +== Changelog == + += 1.0 = +* First Release + + + +== Upgrade Notice == + += 1.0 = + + + + +== A brief Markdown Example == + + +`` diff --git a/ZarinpalZarinGate.php b/ZarinpalZarinGate.php deleted file mode 100644 index 6ca9d83..0000000 --- a/ZarinpalZarinGate.php +++ /dev/null @@ -1,260 +0,0 @@ - id = 'zarinpalzg'; - $this -> method_title = __('زرین پال - زرین گیت', 'zarinpalzg'); - $this -> has_fields = false; - $this -> init_form_fields(); - $this -> init_settings(); - $this -> title = $this -> settings['title']; - $this -> merchant = $this -> settings['merchant']; - $this -> redirect_page_id = $this -> settings['redirect_page_id']; - - $this -> msg['message'] = ""; - $this -> msg['class'] = ""; - add_action('init', array(&$this, 'check_zarinpalzg_response')); - add_action('valid-zarinpalzg-request', array(&$this, 'successful_request')); - - if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) { - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) ); - } else { - add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) ); - } - - - add_action('woocommerce_receipt_zarinpalzg', array(&$this, 'receipt_page')); - add_action('woocommerce_thankyou_zarinpalzg',array(&$this, 'thankyou_page')); - } - - function init_form_fields(){ - - $this -> form_fields = array( - 'enabled' => array( - 'title' => __('فعال سازی/غیر فعال سازی', 'zarinpalzg'), - 'type' => 'checkbox', - 'label' => __('فعال سازی درگاه پرداخت زرین پال - زرین گیت', 'zarinpalzg'), - 'default' => 'no'), - 'title' => array( - 'title' => __('عنوان:', 'zarinpalzg'), - 'type'=> 'text', - 'description' => __('عنوانی که کاربر در هنگام پرداخت مشاهده می کند', 'zarinpalzg'), - 'default' => __('پرداخت اینترنتی زرین پال - زرین گیت', 'zarinpalzg')), - 'description' => array( - 'title' => __('توضیحات:', 'zarinpalzg'), - 'type' => 'textarea', - 'description' => __('توضیحات قابل نمایش به کاربر در هنگام انتخاب درگاه پرداخت', 'zarinpalzg'), - 'default' => __('پرداخت از طریق درگاه زرین پال با کارت های عضو شتاب', 'zarinpalzg')), - 'merchant' => array( - 'title' => __('پین کد', 'zarinpalzg'), - 'type' => 'text', - 'description' => __('پین کد درگاه را وارد کنید')), - 'redirect_page_id' => array( - 'title' => __('صفحه بازگشت'), - 'type' => 'select', - 'options' => $this -> get_pages('انتخاب برگه'), - 'description' => "ادرس بازگشت از پرداخت در هنگام پرداخت" - ) - ); - - - } - /** - * Admin Panel Options - * - Options for bits like 'title' and availability on a country-by-country basis - **/ - public function admin_options(){ - echo '

'.__('درگاه زرین پال - زرین گیت', 'zarinpalzg').'

'; - echo '

'.__('درگاه زرین پال - زرین گیت').'

'; - echo ''; - $this -> generate_settings_html(); - echo '
'; - - } - /** - * There are no payment fields for zarinpalzg, but we want to show the description if set. - **/ - function payment_fields(){ - if($this -> description) echo wpautop(wptexturize($this -> description)); - } - /** - * Receipt Page - **/ - function receipt_page($order){ - echo '

'.__('با تشکر از سفارش شما. در حال انتقال به درگاه پرداخت...', 'zarinpalzg').'

'; - echo $this -> generate_zarinpalzg_form($order); - } - /** - * Process the payment and return the result - **/ - function process_payment($order_id){ - $order = &new WC_Order($order_id); - return array('result' => 'success', 'redirect' => add_query_arg('order', - $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id')))) - ); - } - /** - * Check for valid zarinpalzg server callback - **/ - function check_zarinpalzg_response(){ - global $woocommerce; - $order_id=$_SESSION['zarinpalzg_id']; - $order = new WC_Order($order_id); - $au = $_GET['Authority']; - $st = $_GET['Status']; - if($order_id != '' AND $au !='' AND $st == "OK" ){ - if($order -> status !=='completed'){ - - - $merchantID = $this -> merchant; - - $amount = round($order -> order_total/10); - include_once("lib/nusoap.php"); - $client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl'); - $res = $client->call("PaymentVerification", array( - array( - 'MerchantID' => $merchantID , - 'Authority' => $au , - 'Amount' => $amount - ) - )); - - if ($res['Status'] == 100) - { - $_SESSION['zarinpalzg_id'] = ''; - $output[status] = 1; - $output[message] ='پرداخت با موفقیت انجام گردید.'; - $order -> payment_complete(); - $order -> add_order_note('پرداخت انجام گردید
کد رهگیری بانک: '.$res['RefID']); - $order -> add_order_note($this->msg['message']); - $woocommerce -> cart -> empty_cart(); - } - else - { - - $output[status] = 0; - $output[message]= 'پرداخت توسط زرین پال تایید نشد‌.'.$res['Status']; - } - - - - if ($output[status] == 0) - $order -> add_order_note($output[message]); - - - -} -} - -} - - - - - function showMessage($content){ - return '
'.$this -> msg['message'].'
'.$content; - } - /** - * Generate zarinpalzg button link - **/ - - public function generate_zarinpalzg_form($order_id){ - global $woocommerce; - $order = &new WC_Order($order_id); - $redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id); - $_SESSION['zarinpalzg_id'] = $order_id; - $merchantID = trim($this -> merchant); - $amount = round($order -> order_total/10); - $invoice_id=date('Y').date('H').date('i').date('s').$order_id; - $callBackUrl = $redirect_url; - include_once("lib/nusoap.php"); - $client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl'); - $res = $client->call('PaymentRequest', array( - array( - 'MerchantID' => $merchantID , - 'Amount' => $amount , - 'Description' => $order_id , - 'Email' => '' , - 'Mobile' => '' , - 'CallbackURL' => $callBackUrl - - ) - )); - if ($res['Status'] == 100) - { - header('location: https://www.zarinpal.com/pg/StartPay/' . $res['Authority'] .'/ZarinGate'); - exit; - } - else - { - $this -> msg['class'] = 'error'; - echo $this -> msg['message'] = 'در اتصال به درگاه زرین پال مشکلی به وجود آمد٬ لطفا از درگاه سایر بانک‌ها استفاده نمایید.'.$res['Status']; - - } - - - - - - - if($this -> msg['class']=='error') - $order -> add_order_note($this->msg['message']); - - } - - - // get all pages - function get_pages($title = false, $indent = true) { - $wp_pages = get_pages('sort_column=menu_order'); - $page_list = array(); - if ($title) $page_list[] = $title; - foreach ($wp_pages as $page) { - $prefix = ''; - // show indented child pages? - if ($indent) { - $has_parent = $page->post_parent; - while($has_parent) { - $prefix .= ' - '; - $next_page = get_page($has_parent); - $has_parent = $next_page->post_parent; - } - } - // add to page list array array - $page_list[$page->ID] = $prefix . $page->post_title; - } - return $page_list; - } - - } - - /** - * Add the Gateway to WooCommerce - **/ - function woocommerce_add_zarinpalzg_gateway($methods) { - $methods[] = 'WC_zarinpalzg_Pay'; - return $methods; - } - - add_filter('woocommerce_payment_gateways', 'woocommerce_add_zarinpalzg_gateway' ); -} - -?> diff --git a/images/logo.png b/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..fedced197d3116dd67dbf913e21d7170a36c89bf GIT binary patch literal 9484 zcmWkzWmFzJ5M7Fv;x2{a?jKT|LUDI@cbDSs?heJ>rMSDhLve@V4)1$ElAJx+WN#*S z=FTQzax$Wb@Obb503eEs{Zs(ABH$tb2LrB)T_MuI&1X9?bw>aop8vl@#ei?R;I4?RNKQw&wW!od) zaweaytP4*mm-sd8cEn$MfZe@wI->Bfo$$ z)A^F?{19PMhb+(t*civJvFuznCD`r7>EWzV<+`_k4NP zV-FN0>+cmr5rjAL{pz4cUEwcC6+BTxK%>VvFF?TBEpHZ_V28xetNaIv*ADqvA1=Fx zs@?B1)Q@2}bbaF0PzZx?HPUD}?6jaq;vO+5v}NcP`{ z)8%H!t1)~+LrmRAIIy68D<+1)KEc}Wbe|Ip$7)F`5XuMfYE&v9+rsV)r)piH(ENnE zKeI!*3KHoP{t#1>Qj=L0Dh! zX&9AC%Zkc2%f2YzD32+{lbyvkuW?6{;yX~iI zmre0SYIdiNZ?=?e@#e3N!{@JFjBiSB*3ZRvq6lg*^$27zYY3A#JOga@wmbxkLu*&^ zLfU--LWTNC`YGFiaV;}E`3oXZBFK^EgIc>}yVir&gZUIN6vPyg(kIdv=?c;-IE?)GwOaZGtp7)eF^> zHMHwRDzhrd7uzb^icyPOWD;b`vlmVKYOb0_no65-Yxb96)~cGUo4oW*4X{m{2derm z5;_vRTD_v)cwrGkR*=dGGzh#M8yqmWRJb=))2 zA?rEgtU1)#>LADIzG0!i^7}LVUviR|EVnAWWrbw@OdAhL84VfZR4bQinhRaa9`rA< z`R@4~a(4N4c{ny%Hq~{A&AoNo+QJ7F$XDaF{w7H))O(B=|W?9Z^dI>ffzA^?2o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zFE-ytE;lCtgIK5l$3LRkg%Zx23b#vQw=pWZgJpY zF@(H%|5FsKo8}J}8$KxDKm}$IC3q#Rj)zF(6ch?ZMr2vsuF+Q3)*~}B@(PNIbA@i2 zs?|F5RpsTRrlyCJHbSVtARZ15&;N?p-7WBmXtULsc42-#wyFA`>QuaR#sI_h>DV?^^N0&0%-{e?QR!Jrj(SFgbE4@9)TCpU^YXd zpsb8pTu?9#wyL;@NRd~6C~DUK>BD8`OLVHtzpcM}dp{{Z8rn4;9v#(zuEFh==j3cb0Q4gp z9TJn1-~aCchizy;t$*Kv5uA=703RpY&e#s$Grf2S83QIva-ja%GNgEfiN9Dc1@lJ? zJo}IB>*&8f9B&i;ty80OWk|`OqovJ&(0dw-c4N|wc^%((m|L-O;qiqAeuDLZA3Tka rhQ>3QFSNF`X{}m_yEp$oA4q@>uTdcVM*0u'.urldecode($_GET['msg']).''.$content; + } + + class WC_Zarinpalwg_Pay extends WC_Payment_Gateway { + protected $msg = array(); + public function __construct(){ + // Go wild in here + $this -> id = 'zarinpalzg'; + $this -> method_title = __('زرین پال', 'mrova'); + $this -> icon = WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/logo.png'; + $this -> has_fields = false; + $this -> init_form_fields(); + $this -> init_settings(); + $this -> title = $this -> settings['title']; + + $this -> merchantid = $this -> settings['merchantid']; + $this -> redirect_page_id = $this -> settings['redirect_page_id']; + + $this -> msg['reversal'] = ""; + $this -> msg['status'] = ""; + $this -> msg['message'] = ""; + $this -> msg['class'] = ""; + + add_action( 'woocommerce_api_wc_zarinpalzg_pay' , array( $this, 'check_zarinpalzg_response' ) ); + add_action('valid-zarinpalzg-request', array($this, 'successful_request')); + if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) { + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + } else { + add_action( 'woocommerce_update_options_payment_gateways', array( $this, 'process_admin_options' ) ); + } + add_action('woocommerce_receipt_zarinpalzg', array($this, 'receipt_page')); + add_action('woocommerce_thankyou_zarinpalzg',array($this, 'thankyou_page')); + } + + function init_form_fields(){ + + $this -> form_fields = array( + 'enabled' => array( + 'title' => __('فعال / غیر فعال کردن', 'mrova'), + 'type' => 'checkbox', + 'label' => __('انتخاب وضعیت درگاه پرداخت زرین پال', 'mrova'), + 'default' => 'no'), + 'title' => array( + 'title' => __('عنوان درگاه', 'mrova'), + 'type'=> 'text', + 'description' => __('عنوان درگاه در هنگام انتخاب درگاه پرداخت', 'mrova'), + 'default' => __('پرداخت از طریق درگاه پرداخت زرین پال', 'mrova')), + 'description' => array( + 'title' => __('توضیحات درگاه', 'mrova'), + 'type' => 'textarea', + 'description' => __('توضیحات نوشته شده در زیر لوگوی درگاه هنگام پرداخت', 'mrova'), + 'default' => __('پرداخت با استفاده از درگاه برداخت زرین پال از طریق کلبه کارت های بانکی عضو شتاب', 'mrova')), + 'merchantid' => array( + 'title' => __('شناسه درگاه', 'mrova'), + 'type' => 'text', + 'description' => __('شناسه درگاه يا همان MerchantID')), + 'redirect_page_id' => array( + 'title' => __('برگه بازگشت'), + 'type' => 'select', + 'options' => $this -> get_pages('انتخاب برگه'), + 'description' => __('ادرس بازگشت از پرداخت در هنگام پرداخت') + ) + ); + + + } + /** + * Admin Panel Options + * - Options for bits like 'title' and availability on a country-by-country basis + **/ + public function admin_options(){ + echo '

'.__('درگاه پرداخت زرین پال', 'mrova').'

'; + + echo ''; + $this -> generate_settings_html(); + echo '
'; + + } + /** + * There are no payment fields for zarinpalzg, but we want to show the description if set. + **/ + function payment_fields(){ + if($this -> description) echo wpautop(wptexturize($this -> description)); + } + /** + * Receipt Page + **/ + function receipt_page($order){ + echo '

'.__('از سفارش شما متشکريم ، تا انتقال به درگاه پرداخت چند لحظه منتظر بمانيد ...', 'mrova').'

'; + echo $this -> generate_zarinpalzg_form($order); + } + /** + * Process the payment and return the result + **/ + function process_payment($order_id){ + $order = new WC_Order($order_id); + return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url( true )); + } + /** + * Check for valid zarinpalzg server callback + **/ + function check_zarinpalzg_response(){ + global $woocommerce; + $client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl'); + $client->soap_defencoding = 'UTF-8'; + $Status = $_GET['Status']; + $Authority = $_GET['Authority']; + + $MerchantID = $this -> merchantid; + $order_id = $woocommerce->session->zarinpalzg_woo_id; + $order = new WC_Order($order_id); + if($Status != "OK"){ +print_r($Status); + $this -> msg['status'] = -1; + $this -> msg['message']= 'خطا در عمليات پرداخت ! عمليا پرداخت با موفقيت به پايان نرسيده است !'; + } + if( $Status == "OK") + { + if($order -> status !=='completed') + { + + $result = $client->call("PaymentVerification", array( + array( + 'MerchantID' => $MerchantID , + 'Authority' => $Authority , + 'Amount' => $order->order_total + ) + )); + + + + // Check for a fault + $Status2 = $result['Status']; + $PayPrice = $result['verifyPaymentResult']['PayementedPrice']; + + if(strtolower($Status2) == 100 ) + { + unset($woocommerce->session->zarinpalzg_woo_id); + $this -> msg['status'] = 1; + $this -> msg['message'] ='پرداخت با موفقیت انجام گردید.'; + $order -> payment_complete(); + $order -> add_order_note('پرداخت انجام گردید
شماره رسيد پرداخت: '.$result['RefID'] ); + $order -> add_order_note($this -> msg['message']); + $woocommerce -> cart -> empty_cart(); + } + else + { + $this -> msg['status'] = -88; + $this -> msg['message'] = 'خطايي در اعتبار سنجي پرداخت به وجود آمده است ! وضعيت خطا : '.$Status2; + } + + } + + }else + { + $this -> msg['status'] = -80; + $this -> msg['message'] = 'خطا در عمليات پرداخت ! عمليات پرداخت با موفقيت به پايان نرسيده است !'; + } + + + + if ($this -> msg['status'] == 1){ + + $this -> msg['class']='success'; + } + else + { + $order -> add_order_note($this -> msg['message']); + $this -> msg['class']='error'; + } + $redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id); + //For wooCoomerce 2.0 + $redirect_url = add_query_arg( array('msg'=> urlencode($this -> msg['message']), 'type'=>$this -> msg['class']), $redirect_url ); + + wp_redirect( $redirect_url ); + exit; +} + + + + + /** + * Generate zarinpalzg button link + **/ + + public function generate_zarinpalzg_form($order_id){ + global $woocommerce; + $order = &new WC_Order($order_id); + $redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id); + $redirect_url = add_query_arg( 'wc-api', get_class( $this ), $redirect_url ); + + + + $client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl'); + $client->soap_defencoding = 'UTF-8'; + $MerchantID = $this -> merchantid; + $orderId=rand(1, 9999999999999); + unset($woocommerce->session->zarinpalzg_woo_id); + $woocommerce->session->zarinpalzg_woo_id = $order_id; + $amount = str_replace(".00", "", $order -> order_total);; + $callBackUrl = $redirect_url; + $payerId = '0'; + + + $result = $client->call("PaymentRequest", array( + array( + 'MerchantID' => $MerchantID , + 'Amount' => $amount , + 'Description' => 'پرداخت سفارش شماره '. $order_id , + 'Email' => $order->billing_email , + 'Mobile' => $order->billing_phone , + 'CallbackURL' => $callBackUrl + + ) + )); + + + // Check for a fault + if ($client->fault) { + echo '

Fault

';
+            print_r($result);
+            echo '
'; + } + else { + // Check for errors + + $Status2 = $result['Status']; + $PayPath = 'https://www.zarinpal.com/pg/StartPay/' . $result['Authority'] .'/ZarinGate'; + if ($Status2 != 100 ) { + $this -> msg['class'] = 'error'; + $this -> msg['message'] = $Status; + echo '
در اتصال به درگاه پرداخت خطايي رخ داده است ! وضعيت خطا : '.$Status2.'
'; + } + else { + // Display the result + + $send_atu=""; + echo ' +
+ +
'.$send_atu ; + } + } + + + + if($this -> msg['class']=='error') + $order -> add_order_note($this->msg['message']); + + } + + private function western_to_persian($str) { + $alphabet = array ( + 'Û°' => '۰', 'Û±' => '۱', 'Û²' => '۲', 'Û³' => '۳', 'Û´' => '۴', 'Ûµ' => '۵', 'Û¶' => '۶', 'Û·' => '۷', 'Û¸' => '۸', + 'Û¹' => '۹', 'Ø¢' => 'آ', 'ا' => 'ا', 'Ø£' => 'أ', 'Ø¥' => 'إ', 'ؤ' => 'ؤ', 'ئ' => 'ئ', 'Ø¡' => 'ء', 'ب' => 'ب', + 'Ù¾' => 'پ', 'ت' => 'ت', 'Ø«' => 'ث', 'ج' => 'ج', 'Ú†' => 'چ', 'Ø­' => 'ح', 'Ø®' => 'خ', 'د' => 'د', 'Ø°' => 'ذ', + 'ر' => 'ر', 'ز' => 'ز', 'Ú˜' => 'ژ', 'س' => 'س', 'Ø´' => 'ش', 'ص' => 'ص', 'ض' => 'ض', 'Ø·' => 'ط', 'ظ' => 'ظ', + 'ع' => 'ع', 'غ' => 'غ', 'ف' => 'ف', 'Ù‚' => 'ق', 'Ú©' => 'ک', 'Ú¯' => 'گ', 'Ù„' => 'ل', 'Ù…' => 'م', 'Ù†' => 'ن', + 'Ùˆ' => 'و', 'Ù‡' => 'ه', 'ÛŒ' => 'ی', 'ÙŠ' => 'ي', 'Û€' => 'ۀ', 'Ø©' => 'ة', 'ÙŽ' => 'َ', 'ُ' => 'ُ', 'ِ' => 'ِ', + 'Ù‘' => 'ّ', 'Ù‹' => 'ً', 'ÙŒ' => 'ٌ', 'ٍ' => 'ٍ', 'ØŒ' => '،', 'Ø›' => '؛', ',' => ',', 'ØŸ' => '؟' + ); + + foreach($alphabet as $western => $fa) + $str = str_replace($western, $fa, $str); + + return $str; +} + // get all pages + function get_pages($title = false, $indent = true) { + $wp_pages = get_pages('sort_column=menu_order'); + $page_list = array(); + if ($title) $page_list[] = $title; + foreach ($wp_pages as $page) { + $prefix = ''; + // show indented child pages? + if ($indent) { + $has_parent = $page->post_parent; + while($has_parent) { + $prefix .= ' - '; + $next_page = get_page($has_parent); + $has_parent = $next_page->post_parent; + } + } + // add to page list array array + $page_list[$page->ID] = $prefix . $page->post_title; + } + return $page_list; + } + + } + + /** + * Add the Gateway to WooCommerce + **/ + function woocommerce_add_zarinpalzg_gateway($methods) { + $methods[] = 'WC_Zarinpalwg_Pay'; + return $methods; + } + + add_filter('woocommerce_payment_gateways', 'woocommerce_add_zarinpalzg_gateway' ); +} + +?> diff --git a/lib/nusoap.php b/nusoap.php similarity index 94% rename from lib/nusoap.php rename to nusoap.php index 15c8581..3ae62bb 100644 --- a/lib/nusoap.php +++ b/nusoap.php @@ -1,7 +1,7 @@ globalDebugLevel = 9; /** * @@ -79,7 +90,7 @@ * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_base { @@ -96,14 +107,14 @@ class nusoap_base { * @var string * @access private */ - var $version = '0.9.5'; + var $version = '0.7.3'; /** * CVS revision for HTTP headers. * * @var string * @access private */ - var $revision = '$Revision: 1.123 $'; + var $revision = '$Revision: 1.114 $'; /** * Current error string (manipulated by getError/setError) * @@ -223,7 +234,7 @@ class nusoap_base { * @access public */ function nusoap_base() { - $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; + $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel; } /** @@ -233,7 +244,7 @@ function nusoap_base() { * @access public */ function getGlobalDebugLevel() { - return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; + return $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel; } /** @@ -243,7 +254,7 @@ function getGlobalDebugLevel() { * @access public */ function setGlobalDebugLevel($level) { - $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; + $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel = $level; } /** @@ -561,7 +572,7 @@ function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=fals case (is_array($val) || $type): // detect if struct or array $valueType = $this->isArraySimpleOrStruct($val); - if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ + if($valueType=='arraySimple' || ereg('^ArrayOf',$type)){ $this->debug("serialize_val: serialize array"); $i = 0; if(is_array($val) && count($val)> 0){ @@ -764,7 +775,7 @@ function contractQname($qname){ */ function expandQname($qname){ // get element prefix - if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ + if(strpos($qname,':') && !ereg('^http://',$qname)){ // get unqualified name $name = substr(strstr($qname,':'),1); // get ns prefix @@ -896,24 +907,14 @@ function __toString() { /** * convert unix timestamp to ISO 8601 compliant date string * -* @param int $timestamp Unix time stamp +* @param string $timestamp Unix time stamp * @param boolean $utc Whether the time stamp is UTC or local -* @return mixed ISO 8601 date string or false * @access public */ function timestamp_to_iso8601($timestamp,$utc=true){ $datestr = date('Y-m-d\TH:i:sO',$timestamp); - $pos = strrpos($datestr, "+"); - if ($pos === FALSE) { - $pos = strrpos($datestr, "-"); - } - if ($pos !== FALSE) { - if (strlen($datestr) == $pos + 5) { - $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); - } - } if($utc){ - $pattern = '/'. + $eregStr = '([0-9]{4})-'. // centuries & years CCYY- '([0-9]{2})-'. // months MM- '([0-9]{2})'. // days DD @@ -921,10 +922,9 @@ function timestamp_to_iso8601($timestamp,$utc=true){ '([0-9]{2}):'. // hours hh: '([0-9]{2}):'. // minutes mm: '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's - '/'; + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's - if(preg_match($pattern,$datestr,$regs)){ + if(ereg($eregStr,$datestr,$regs)){ return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); } return false; @@ -937,11 +937,10 @@ function timestamp_to_iso8601($timestamp,$utc=true){ * convert ISO 8601 compliant date string to unix timestamp * * @param string $datestr ISO 8601 compliant date string -* @return mixed Unix timestamp (int) or false * @access public */ function iso8601_to_timestamp($datestr){ - $pattern = '/'. + $eregStr = '([0-9]{4})-'. // centuries & years CCYY- '([0-9]{2})-'. // months MM- '([0-9]{2})'. // days DD @@ -949,9 +948,8 @@ function iso8601_to_timestamp($datestr){ '([0-9]{2}):'. // hours hh: '([0-9]{2}):'. // minutes mm: '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's - '/'; - if(preg_match($pattern,$datestr,$regs)){ + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's + if(ereg($eregStr,$datestr,$regs)){ // not utc if($regs[8] != 'Z'){ $op = substr($regs[8],0,1); @@ -1001,7 +999,7 @@ function usleepWindows($usec) * Mainly used for returning faults from deployed functions * in a server instance. * @author Dietrich Ayala -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_fault extends nusoap_base { @@ -1089,7 +1087,7 @@ class soap_fault extends nusoap_fault { * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_xmlschema extends nusoap_base { @@ -1279,7 +1277,7 @@ function schemaStartElement($parser, $name, $attrs) { if(count($attrs) > 0){ foreach($attrs as $k => $v){ // if ns declarations, add to class level array of valid namespaces - if(preg_match('/^xmlns/',$k)){ + if(ereg("^xmlns",$k)){ //$this->xdebug("$k: $v"); //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); if($ns_prefix = substr(strrchr($k,':'),1)){ @@ -1324,7 +1322,6 @@ function schemaStartElement($parser, $name, $attrs) { $this->xdebug("parsing attribute:"); $this->appendDebug($this->varDump($attrs)); if (!isset($attrs['form'])) { - // TODO: handle globals $attrs['form'] = $this->schemaInfo['attributeFormDefault']; } if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { @@ -1374,7 +1371,6 @@ function schemaStartElement($parser, $name, $attrs) { } break; case 'complexContent': // (optional) content for a complexType - $this->xdebug("do nothing for element $name"); break; case 'complexType': array_push($this->complexTypeStack, $this->currentComplexType); @@ -1393,7 +1389,7 @@ function schemaStartElement($parser, $name, $attrs) { // minOccurs="0" maxOccurs="unbounded" /> // // - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ + if(isset($attrs['base']) && ereg(':Array$',$attrs['base'])){ $this->xdebug('complexType is unusual array'); $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; } else { @@ -1413,24 +1409,18 @@ function schemaStartElement($parser, $name, $attrs) { // minOccurs="0" maxOccurs="unbounded" /> // // - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ + if(isset($attrs['base']) && ereg(':Array$',$attrs['base'])){ $this->xdebug('complexType is unusual array'); $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; } else { $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; } } - $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; break; case 'element': array_push($this->elementStack, $this->currentElement); if (!isset($attrs['form'])) { - if ($this->currentComplexType) { - $attrs['form'] = $this->schemaInfo['elementFormDefault']; - } else { - // global - $attrs['form'] = 'qualified'; - } + $attrs['form'] = $this->schemaInfo['elementFormDefault']; } if(isset($attrs['type'])){ $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); @@ -1484,38 +1474,22 @@ function schemaStartElement($parser, $name, $attrs) { case 'extension': // simpleContent or complexContent type extension $this->xdebug('extension ' . $attrs['base']); if ($this->currentComplexType) { - $ns = $this->getPrefix($attrs['base']); - if ($ns == '') { - $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; - } else { - $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; - } - } else { - $this->xdebug('no current complexType to set extensionBase'); + $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; } break; case 'import': if (isset($attrs['schemaLocation'])) { - $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); + //$this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); } else { - $this->xdebug('import namespace ' . $attrs['namespace']); + //$this->xdebug('import namespace ' . $attrs['namespace']); $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); if (! $this->getPrefixFromNamespace($attrs['namespace'])) { $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; } } break; - case 'include': - if (isset($attrs['schemaLocation'])) { - $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); - $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); - } else { - $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); - } - break; case 'list': // simpleType value list - $this->xdebug("do nothing for element $name"); break; case 'restriction': // simpleType, simpleContent or complexContent value restriction $this->xdebug('restriction ' . $attrs['base']); @@ -1542,11 +1516,6 @@ function schemaStartElement($parser, $name, $attrs) { } break; case 'simpleContent': // (optional) content for a complexType - if ($this->currentComplexType) { // This should *always* be - $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; - } else { - $this->xdebug("do nothing for element $name because there is no current complexType"); - } break; case 'simpleType': array_push($this->simpleTypeStack, $this->currentSimpleType); @@ -1566,10 +1535,9 @@ function schemaStartElement($parser, $name, $attrs) { } break; case 'union': // simpleType type list - $this->xdebug("do nothing for element $name"); break; default: - $this->xdebug("do not have any logic to process element $name"); + //$this->xdebug("do not have anything to do for element $name"); } } @@ -1597,7 +1565,6 @@ function schemaEndElement($parser, $name) { // move on... if($name == 'complexType'){ $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); - $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); $this->currentComplexType = array_pop($this->complexTypeStack); //$this->currentElement = false; } @@ -1607,7 +1574,6 @@ function schemaEndElement($parser, $name) { } if($name == 'simpleType'){ $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); - $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); $this->currentSimpleType = array_pop($this->simpleTypeStack); } } @@ -1844,9 +1810,6 @@ function getTypeDef($type){ if (isset($etype['elements'])) { $this->elements[$type]['elements'] = $etype['elements']; } - if (isset($etype['extensionBase'])) { - $this->elements[$type]['extensionBase'] = $etype['extensionBase']; - } } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') { $this->xdebug("in getTypeDef, element $type is an XSD type"); $this->elements[$type]['phpType'] = 'scalar'; @@ -1856,7 +1819,7 @@ function getTypeDef($type){ } elseif(isset($this->attributes[$type])){ $this->xdebug("in getTypeDef, found attribute $type"); return $this->attributes[$type]; - } elseif (preg_match('/_ContainedType$/', $type)) { + } elseif (ereg('_ContainedType$', $type)) { $this->xdebug("in getTypeDef, have an untyped element $type"); $typeDef['typeClass'] = 'simpleType'; $typeDef['phpType'] = 'scalar'; @@ -2061,7 +2024,7 @@ class XMLSchema extends nusoap_xmlschema { * xsd:anyType and user-defined types. * * @author Dietrich Ayala -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class soapval extends nusoap_base { @@ -2163,7 +2126,7 @@ function decode(){ * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class soap_transport_http extends nusoap_base { @@ -2220,7 +2183,7 @@ function soap_transport_http($url, $curl_options = NULL, $use_curl = false){ $this->ch_options = $curl_options; } $this->use_curl = $use_curl; - preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); + ereg('\$Revisio' . 'n: ([^ ]+)', $this->revision, $rev); $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')'); } @@ -2396,7 +2359,7 @@ function connect($connection_timeout=0,$response_timeout=30){ } else if ($this->io_method() == 'curl') { if (!extension_loaded('curl')) { // $this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS'); - $this->setError('The PHP cURL Extension is required for HTTPS or NLTM. You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.'); + $this->setError('The PHP cURL Extension is required for HTTPS or NLTM. You will need to re-build or update your PHP to included cURL.'); return false; } // Avoid warnings when PHP does not have these options @@ -2711,8 +2674,8 @@ function setEncoding($enc='gzip, deflate') { $this->setHeader('Connection', 'close'); $this->persistentConnection = false; } - // deprecated as of PHP 5.3.0 - //set_magic_quotes_runtime(0); + set_magic_quotes_runtime(0); + // deprecated $this->encoding = $enc; } } @@ -2845,9 +2808,7 @@ function buildPayload($data, $cookie_str = '') { // debugging guides. // add content-length header - if ($this->request_method != 'GET') { - $this->setHeader('Content-Length', strlen($data)); - } + $this->setHeader('Content-Length', strlen($data)); // start building outgoing payload: if ($this->proxy) { @@ -2985,7 +2946,7 @@ function getResponse(){ } } // remove 100 headers - if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) { + if (isset($lb) && ereg('^HTTP/1.1 100',$data)) { unset($lb); $data = ''; }// @@ -3151,7 +3112,7 @@ function getResponse(){ if ($data == '') { // have nothing left; just remove 100 header(s) $data = $savedata; - while (preg_match('/^HTTP\/1.1 100/',$data)) { + while (ereg('^HTTP/1.1 100',$data)) { if ($pos = strpos($data,"\r\n\r\n")) { $data = ltrim(substr($data,$pos)); } elseif($pos = strpos($data,"\n\n") ) { @@ -3355,7 +3316,7 @@ function usePersistentConnection(){ */ function parseCookie($cookie_str) { $cookie_str = str_replace('; ', ';', $cookie_str) . ';'; - $data = preg_split('/;/', $cookie_str); + $data = split(';', $cookie_str); $value_str = $data[0]; $cookie_param = 'domain='; @@ -3468,7 +3429,7 @@ function getCookiesForRequest($cookies, $secure=false) { * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_server extends nusoap_base { @@ -3694,14 +3655,6 @@ function nusoap_server($wsdl=false){ function service($data){ global $HTTP_SERVER_VARS; - if (isset($_SERVER['REQUEST_METHOD'])) { - $rm = $_SERVER['REQUEST_METHOD']; - } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { - $rm = $HTTP_SERVER_VARS['REQUEST_METHOD']; - } else { - $rm = ''; - } - if (isset($_SERVER['QUERY_STRING'])) { $qs = $_SERVER['QUERY_STRING']; } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { @@ -3709,38 +3662,19 @@ function service($data){ } else { $qs = ''; } - $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data)); + $this->debug("In service, query string=$qs"); - if ($rm == 'POST') { - $this->debug("In service, invoke the request"); - $this->parse_request($data); - if (! $this->fault) { - $this->invoke_method(); - } - if (! $this->fault) { - $this->serialize_return(); - } - $this->send_response(); - } elseif (preg_match('/wsdl/', $qs) ){ + if (ereg('wsdl', $qs) ){ $this->debug("In service, this is a request for WSDL"); - if ($this->externalWSDLURL){ - if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL - $this->debug("In service, re-direct for WSDL"); + if($this->externalWSDLURL){ + if (strpos($this->externalWSDLURL,"://")!==false) { // assume URL header('Location: '.$this->externalWSDLURL); } else { // assume file - $this->debug("In service, use file passthru for WSDL"); header("Content-Type: text/xml\r\n"); - $pos = strpos($this->externalWSDLURL, "file://"); - if ($pos === false) { - $filename = $this->externalWSDLURL; - } else { - $filename = substr($this->externalWSDLURL, $pos + 7); - } $fp = fopen($this->externalWSDLURL, 'r'); fpassthru($fp); } } elseif ($this->wsdl) { - $this->debug("In service, serialize WSDL"); header("Content-Type: text/xml; charset=ISO-8859-1\r\n"); print $this->wsdl->serialize($this->debug_flag); if ($this->debug_flag) { @@ -3749,17 +3683,22 @@ function service($data){ print $this->getDebugAsXMLComment(); } } else { - $this->debug("In service, there is no WSDL"); header("Content-Type: text/html; charset=ISO-8859-1\r\n"); print "This service does not provide WSDL"; } - } elseif ($this->wsdl) { - $this->debug("In service, return Web description"); + } elseif ($data == '' && $this->wsdl) { + $this->debug("In service, there is no data, so return Web description"); print $this->wsdl->webDescription(); } else { - $this->debug("In service, no Web description"); - header("Content-Type: text/html; charset=ISO-8859-1\r\n"); - print "This service does not provide a Web description"; + $this->debug("In service, invoke the request"); + $this->parse_request($data); + if (! $this->fault) { + $this->invoke_method(); + } + if (! $this->fault) { + $this->serialize_return(); + } + $this->send_response(); } } @@ -3796,7 +3735,7 @@ function parse_http_headers() { // get the character encoding of the incoming request if(isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')){ $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1)); - if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){ + if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){ $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; @@ -3825,7 +3764,7 @@ function parse_http_headers() { $enc = substr(strstr($v, '='), 1); $enc = str_replace('"', '', $enc); $enc = str_replace('\\', '', $enc); - if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) { + if (eregi('^(ISO-8859-1|US-ASCII|UTF-8)$', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; @@ -3859,7 +3798,7 @@ function parse_http_headers() { $enc = substr(strstr($v, '='), 1); $enc = str_replace('"', '', $enc); $enc = str_replace('\\', '', $enc); - if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) { + if (eregi('^(ISO-8859-1|US-ASCII|UTF-8)$', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; @@ -3951,17 +3890,6 @@ function parse_request($data='') { function invoke_method() { $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction); - // - // if you are debugging in this area of the code, your service uses a class to implement methods, - // you use SOAP RPC, and the client is .NET, please be aware of the following... - // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the - // method name. that is fine for naming the .NET methods. it is not fine for properly constructing - // the XML request and reading the XML response. you need to add the RequestElementName and - // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe - // generates for the method. these parameters are used to specify the correct XML element names - // for .NET to use, i.e. the names with the '.' in them. - // - $orig_methodname = $this->methodname; if ($this->wsdl) { if ($this->opData = $this->wsdl->getOperationData($this->methodname)) { $this->debug('in invoke_method, found WSDL operation=' . $this->methodname); @@ -3983,6 +3911,8 @@ function invoke_method() { // if a . is present in $this->methodname, we see if there is a class in scope, // which could be referred to. We will also distinguish between two deliminators, // to allow methods to be called a the class or an instance + $class = ''; + $method = ''; if (strpos($this->methodname, '..') > 0) { $delim = '..'; } else if (strpos($this->methodname, '.') > 0) { @@ -3990,23 +3920,13 @@ function invoke_method() { } else { $delim = ''; } - $this->debug("in invoke_method, delim=$delim"); - $class = ''; - $method = ''; - if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) { - $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim)); - if (class_exists($try_class)) { - // get the class and method name - $class = $try_class; - $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim)); - $this->debug("in invoke_method, class=$class method=$method delim=$delim"); - } else { - $this->debug("in invoke_method, class=$try_class not found"); - } - } else { - $try_class = ''; - $this->debug("in invoke_method, no class to try"); + if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1 && + class_exists(substr($this->methodname, 0, strpos($this->methodname, $delim)))) { + // get the class and method name + $class = substr($this->methodname, 0, strpos($this->methodname, $delim)); + $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim)); + $this->debug("in invoke_method, class=$class method=$method delim=$delim"); } // does method exist? @@ -4014,7 +3934,7 @@ function invoke_method() { if (!function_exists($this->methodname)) { $this->debug("in invoke_method, function '$this->methodname' not found!"); $this->result = 'fault: method not found'; - $this->fault('SOAP-ENV:Client',"method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')"); + $this->fault('SOAP-ENV:Client',"method '$this->methodname' not defined in service"); return; } } else { @@ -4022,7 +3942,7 @@ function invoke_method() { if (!in_array($method_to_compare, get_class_methods($class))) { $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!"); $this->result = 'fault: method not found'; - $this->fault('SOAP-ENV:Client',"method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')"); + $this->fault('SOAP-ENV:Client',"method '$this->methodname' not defined in service"); return; } } @@ -4108,7 +4028,7 @@ function invoke_method() { function serialize_return() { $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI); // if fault - if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) { + if (isset($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) { $this->debug('got a fault object from method'); $this->fault = $this->methodreturn; return; @@ -4157,17 +4077,9 @@ function serialize_return() { $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']); if ($this->opData['output']['use'] == 'literal') { // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace - if ($this->methodURI) { - $payload = 'methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'methodname."Response>"; - } else { - $payload = '<'.$this->methodname.'Response>'.$return_val.'methodname.'Response>'; - } + $payload = 'methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'methodname."Response>"; } else { - if ($this->methodURI) { - $payload = 'methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'methodname."Response>"; - } else { - $payload = '<'.$this->methodname.'Response>'.$return_val.'methodname.'Response>'; - } + $payload = 'methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'methodname."Response>"; } } else { $this->debug('style is not rpc for serialization: assume document'); @@ -4182,8 +4094,8 @@ function serialize_return() { //if($this->debug_flag){ $this->appendDebug($this->wsdl->getDebug()); // } - if (isset($this->opData['output']['encodingStyle'])) { - $encodingStyle = $this->opData['output']['encodingStyle']; + if (isset($opData['output']['encodingStyle'])) { + $encodingStyle = $opData['output']['encodingStyle']; } else { $encodingStyle = ''; } @@ -4224,7 +4136,7 @@ function send_response() { $payload .= $this->getDebugAsXMLComment(); } $this->outgoing_headers[] = "Server: $this->title Server v$this->version"; - preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); + ereg('\$Revisio' . 'n: ([^ ]+)', $this->revision, $rev); $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".$rev[1].")"; // Let the Web server decide about this //$this->outgoing_headers[] = "Connection: Close\r\n"; @@ -4304,12 +4216,7 @@ function verify_method($operation,$request){ * @access private */ function parseRequest($headers, $data) { - $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:'); - $this->appendDebug($this->varDump($headers)); - if (!isset($headers['content-type'])) { - $this->setError('Request not of type text/xml (no content-type header)'); - return false; - } + $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' and type ' . $headers['content-type']); if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Request not of type text/xml'); return false; @@ -4317,7 +4224,7 @@ function parseRequest($headers, $data) { if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); - if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){ + if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){ $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; @@ -4457,7 +4364,7 @@ function register($name,$in=array(),$out=array(),$namespace=false,$soapaction=fa if(false == $use) { $use = "encoded"; } - if ($use == 'encoded' && $encodingStyle == '') { + if ($use == 'encoded' && $encodingStyle = '') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; } @@ -4591,7 +4498,7 @@ class soap_server extends nusoap_server { * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class wsdl extends nusoap_base { @@ -4805,7 +4712,7 @@ function parseWSDL($wsdl = '') { $this->appendDebug($tr->getDebug()); // catch errors if($err = $tr->getError() ){ - $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err; + $errstr = 'HTTP ERROR: '.$err; $this->debug($errstr); $this->setError($errstr); unset($tr); @@ -4884,7 +4791,7 @@ function start_element($parser, $name, $attrs) $this->currentSchema->schemaStartElement($parser, $name, $attrs); $this->appendDebug($this->currentSchema->getDebug()); $this->currentSchema->clearDebug(); - } elseif (preg_match('/schema$/', $name)) { + } elseif (ereg('schema$', $name)) { $this->debug('Parsing WSDL schema'); // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")"); $this->status = 'schema'; @@ -4903,7 +4810,7 @@ function start_element($parser, $name, $attrs) if (count($attrs) > 0) { // register namespace declarations foreach($attrs as $k => $v) { - if (preg_match('/^xmlns/',$k)) { + if (ereg("^xmlns", $k)) { if ($ns_prefix = substr(strrchr($k, ':'), 1)) { $this->namespaces[$ns_prefix] = $v; } else { @@ -4928,7 +4835,7 @@ function start_element($parser, $name, $attrs) $attrs = array(); } // get element prefix, namespace and name - if (preg_match('/:/', $name)) { + if (ereg(':', $name)) { // get ns prefix $prefix = substr($name, 0, strpos($name, ':')); // get ns @@ -5093,7 +5000,7 @@ function start_element($parser, $name, $attrs) */ function end_element($parser, $name){ // unset schema status - if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) { + if (/*ereg('types$', $name) ||*/ ereg('schema$', $name)) { $this->status = ""; $this->appendDebug($this->currentSchema->getDebug()); $this->currentSchema->clearDebug(); @@ -5131,7 +5038,7 @@ function character_data($parser, $data) $this->documentation .= $data; } } - + /** * if authenticating, set user credentials here * @@ -5160,40 +5067,30 @@ function getBindingData($binding) /** * returns an assoc array of operation names => operation data * - * @param string $portName WSDL port name * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported) * @return array * @access public */ - function getOperations($portName = '', $bindingType = 'soap') { + function getOperations($bindingType = 'soap') { $ops = array(); if ($bindingType == 'soap') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; } elseif ($bindingType == 'soap12') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; - } else { - $this->debug("getOperations bindingType $bindingType may not be supported"); } - $this->debug("getOperations for port '$portName' bindingType $bindingType"); // loop thru ports foreach($this->ports as $port => $portData) { - $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); - if ($portName == '' || $port == $portName) { - // binding type of port matches parameter - if ($portData['bindingType'] == $bindingType) { - $this->debug("getOperations found port $port bindingType $bindingType"); - //$this->debug("port data: " . $this->varDump($portData)); - //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); - // merge bindings - if (isset($this->bindings[ $portData['binding'] ]['operations'])) { - $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']); - } + // binding type of port matches parameter + if ($portData['bindingType'] == $bindingType) { + //$this->debug("getOperations for port $port"); + //$this->debug("port data: " . $this->varDump($portData)); + //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); + // merge bindings + if (isset($this->bindings[ $portData['binding'] ]['operations'])) { + $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']); } } - } - if (count($ops) == 0) { - $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType"); - } + } return $ops; } @@ -5295,10 +5192,9 @@ function getTypeDef($type, $ns) { for ($i = 0; $i < count($this->schemas[$ns]); $i++) { $xs = &$this->schemas[$ns][$i]; $t = $xs->getTypeDef($type); - $this->appendDebug($xs->getDebug()); - $xs->clearDebug(); + //$this->appendDebug($xs->getDebug()); + //$xs->clearDebug(); if ($t) { - $this->debug("in getTypeDef: found type $type"); if (!isset($t['phpType'])) { // get info for type to tack onto the element $uqType = substr($t['type'], strrpos($t['type'], ':') + 1); @@ -5316,14 +5212,11 @@ function getTypeDef($type, $ns) { if (isset($etype['attrs'])) { $t['attrs'] = $etype['attrs']; } - } else { - $this->debug("did not find type for [element] $type"); } } return $t; } } - $this->debug("in getTypeDef: did not find type $type"); } else { $this->debug("in getTypeDef: do not have schema for namespace $ns"); } @@ -5362,9 +5255,8 @@ function webDescription(){ background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; } .title { font-family: arial; font-size: 26px; color: #ffffff; - background-color: #999999; width: 100%; - margin-left: 0px; margin-right: 0px; - padding-top: 10px; padding-bottom: 10px;} + background-color: #999999; width: 105%; margin-left: 0px; + padding-top: 10px; padding-bottom: 10px; padding-left: 15px;} .hidden { position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px; font-family: arial; overflow: hidden; width: 600; @@ -5653,8 +5545,18 @@ function parametersMatchWrapped($type, &$parameters) { if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { $elements = 0; $matches = 0; + $change = false; + if ($this->isArraySimpleOrStruct($parameters) == 'arraySimple' && count($parameters) == count($typeDef['elements'])) { + $this->debug("in parametersMatchWrapped: (wrapped return value kludge) correct number of elements in simple array, so change array and wrap"); + $change = true; + } foreach ($typeDef['elements'] as $name => $attrs) { - if (isset($parameters[$name])) { + if ($change) { + $this->debug("in parametersMatchWrapped: change parameter $element to name $name"); + $parameters[$name] = $parameters[$elements]; + unset($parameters[$elements]); + $matches++; + } elseif (isset($parameters[$name])) { $this->debug("in parametersMatchWrapped: have parameter named $name"); $matches++; } else { @@ -5730,14 +5632,7 @@ function serializeRPCParameters($operation, $direction, $parameters, $bindingTyp // check for Microsoft-style wrapped parameters if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) { $this->debug('check whether the caller has wrapped the parameters'); - if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) { - // TODO: consider checking here for double-wrapping, when - // service function wraps, then NuSOAP wraps again - $this->debug("change simple array to associative with 'parameters' element"); - $parameters['parameters'] = $parameters[0]; - unset($parameters[0]); - } - if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) { + if ((($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) || ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1)) { $this->debug('check whether caller\'s parameters match the wrapped ones'); if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) { $this->debug('wrap the parameters for the caller'); @@ -6022,11 +5917,6 @@ function serializeType($name, $type, $value, $use='encoded', $encodingStyle=fals $uqType = substr($uqType, 0, -1); } } - if (!isset($typeDef['phpType'])) { - $this->setError("$type ($uqType) has no phpType."); - $this->debug("in serializeType: $type ($uqType) has no phpType."); - return false; - } $phpType = $typeDef['phpType']; $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); // if php type == struct, map value to the element names @@ -6048,7 +5938,7 @@ function serializeType($name, $type, $value, $use='encoded', $encodingStyle=fals } if (is_null($value)) { if ($use == 'literal') { - // TODO: depends on minOccurs and nillable + // TODO: depends on minOccurs $xml = "<$elementName$elementNS/>"; } else { $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; @@ -6070,18 +5960,8 @@ function serializeType($name, $type, $value, $use='encoded', $encodingStyle=fals } else { $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>"; } - - if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') { - if (isset($value['!'])) { - $xml .= $value['!']; - $this->debug("in serializeType: serialized simpleContent for type $type"); - } else { - $this->debug("in serializeType: no simpleContent to serialize for type $type"); - } - } else { - // complexContent - $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); - } + + $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); $xml .= ""; } else { $this->debug("in serializeType: phpType is struct, but value is not an array"); @@ -6191,21 +6071,7 @@ function serializeType($name, $type, $value, $use='encoded', $encodingStyle=fals * @access private */ function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) { - $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType"); $xml = ''; - if (isset($typeDef['extensionBase'])) { - $nsx = $this->getPrefix($typeDef['extensionBase']); - $uqTypex = $this->getLocalPart($typeDef['extensionBase']); - if ($this->getNamespaceFromPrefix($nsx)) { - $nsx = $this->getNamespaceFromPrefix($nsx); - } - if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { - $this->debug("serialize attributes for extension base $nsx:$uqTypex"); - $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex); - } else { - $this->debug("extension base $nsx:$uqTypex is not a supported type"); - } - } if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) { $this->debug("serialize attributes for XML Schema type $ns:$uqType"); if (is_array($value)) { @@ -6238,6 +6104,19 @@ function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) { } else { $this->debug("no attributes to serialize for XML Schema type $ns:$uqType"); } + if (isset($typeDef['extensionBase'])) { + $ns = $this->getPrefix($typeDef['extensionBase']); + $uqType = $this->getLocalPart($typeDef['extensionBase']); + if ($this->getNamespaceFromPrefix($ns)) { + $ns = $this->getNamespaceFromPrefix($ns); + } + if ($typeDef = $this->getTypeDef($uqType, $ns)) { + $this->debug("serialize attributes for extension base $ns:$uqType"); + $xml .= $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType); + } else { + $this->debug("extension base $ns:$uqType is not a supported type"); + } + } return $xml; } @@ -6254,21 +6133,7 @@ function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) { * @access private */ function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) { - $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType"); $xml = ''; - if (isset($typeDef['extensionBase'])) { - $nsx = $this->getPrefix($typeDef['extensionBase']); - $uqTypex = $this->getLocalPart($typeDef['extensionBase']); - if ($this->getNamespaceFromPrefix($nsx)) { - $nsx = $this->getNamespaceFromPrefix($nsx); - } - if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { - $this->debug("serialize elements for extension base $nsx:$uqTypex"); - $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle); - } else { - $this->debug("extension base $nsx:$uqTypex is not a supported type"); - } - } if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType"); if (is_array($value)) { @@ -6325,12 +6190,7 @@ function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='enco } } } else { - if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') { - // do nothing - } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') { - // TODO: serialize a nil correctly, but for now serialize schema-defined type - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); - } elseif (isset($attrs['type']) || isset($attrs['ref'])) { + if (isset($attrs['type']) || isset($attrs['ref'])) { // serialize schema-defined type $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); } else { @@ -6344,6 +6204,19 @@ function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='enco } else { $this->debug("no elements to serialize for XML Schema type $ns:$uqType"); } + if (isset($typeDef['extensionBase'])) { + $ns = $this->getPrefix($typeDef['extensionBase']); + $uqType = $this->getLocalPart($typeDef['extensionBase']); + if ($this->getNamespaceFromPrefix($ns)) { + $ns = $this->getNamespaceFromPrefix($ns); + } + if ($typeDef = $this->getTypeDef($uqType, $ns)) { + $this->debug("serialize elements for extension base $ns:$uqType"); + $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); + } else { + $this->debug("extension base $ns:$uqType is not a supported type"); + } + } return $xml; } @@ -6449,7 +6322,7 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa if ($style == 'document') { $elements = array(); foreach ($in as $n => $t) { - $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); + $elements[$n] = array('name' => $n, 'type' => $t); } $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements); $this->addElement(array('name' => $name, 'type' => $name . 'RequestType')); @@ -6457,7 +6330,7 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa $elements = array(); foreach ($out as $n => $t) { - $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); + $elements[$n] = array('name' => $n, 'type' => $t); } $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements); $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified')); @@ -6526,7 +6399,7 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_parser extends nusoap_base { @@ -6629,8 +6502,6 @@ function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){ $this->debug("XML payload:\n" . $xml); $this->setError($err); } else { - $this->debug('in nusoap_parser ctor, message:'); - $this->appendDebug($this->varDump($this->message)); $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name); // get final value $this->soapresponse = $this->message[$this->root_struct]['result']; @@ -6696,16 +6567,16 @@ function start_element($parser, $name, $attrs) { $name = substr(strstr($name,':'),1); } // set status - if ($name == 'Envelope' && $this->status == '') { + if($name == 'Envelope'){ $this->status = 'envelope'; - } elseif ($name == 'Header' && $this->status == 'envelope') { + } elseif($name == 'Header' && $this->status = 'envelope'){ $this->root_header = $pos; $this->status = 'header'; - } elseif ($name == 'Body' && $this->status == 'envelope'){ + } elseif($name == 'Body' && $this->status = 'envelope'){ $this->status = 'body'; $this->body_position = $pos; // set method - } elseif($this->status == 'body' && $pos == ($this->body_position+1)) { + } elseif($this->status == 'body' && $pos == ($this->body_position+1)){ $this->status = 'method'; $this->root_struct_name = $name; $this->root_struct = $pos; @@ -6726,7 +6597,7 @@ function start_element($parser, $name, $attrs) { $key_localpart = $this->getLocalPart($key); // if ns declarations, add to class level array of valid namespaces if($key_prefix == 'xmlns'){ - if(preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/',$value)){ + if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){ $this->XMLSchemaVersion = $value; $this->namespaces['xsd'] = $this->XMLSchemaVersion; $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance'; @@ -6762,8 +6633,8 @@ function start_element($parser, $name, $attrs) { [5] length ::= nextDimension* Digit+ [6] nextDimension ::= Digit+ ',' */ - $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/'; - if(preg_match($expr,$value,$regs)){ + $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]'; + if(ereg($expr,$value,$regs)){ $this->message[$pos]['typePrefix'] = $regs[1]; $this->message[$pos]['arrayTypePrefix'] = $regs[1]; if (isset($this->namespaces[$regs[1]])) { @@ -6906,17 +6777,15 @@ function end_element($parser, $name) { $this->document .= ""; } // switch status - if ($pos == $this->root_struct){ + if($pos == $this->root_struct){ $this->status = 'body'; $this->root_struct_namespace = $this->message[$pos]['namespace']; - } elseif ($pos == $this->root_header) { - $this->status = 'envelope'; - } elseif ($name == 'Body' && $this->status == 'body') { + } elseif($name == 'Body'){ $this->status = 'envelope'; - } elseif ($name == 'Header' && $this->status == 'header') { // will never happen + } elseif($name == 'Header'){ $this->status = 'envelope'; - } elseif ($name == 'Envelope' && $this->status == 'envelope') { - $this->status = ''; + } elseif($name == 'Envelope'){ + // } // set parent back to my parent $this->parent = $this->message[$pos]['parent']; @@ -7177,7 +7046,7 @@ class soap_parser extends nusoap_parser { * * @author Dietrich Ayala * @author Scott Nichol -* @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $ +* @version $Id: nusoap.php,v 1.114 2007/11/06 15:17:46 snichol Exp $ * @access public */ class nusoap_client extends nusoap_base { @@ -7196,7 +7065,6 @@ class nusoap_client extends nusoap_base { var $proxyport = ''; var $proxyusername = ''; var $proxypassword = ''; - var $portName = ''; // port name to use in WSDL var $xml_encoding = ''; // character set encoding of incoming (response) messages var $http_encoding = false; var $timeout = 0; // HTTP connection timeout @@ -7242,17 +7110,17 @@ class nusoap_client extends nusoap_base { * constructor * * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object) - * @param mixed $wsdl optional, set to 'wsdl' or true if using WSDL - * @param string $proxyhost optional - * @param string $proxyport optional - * @param string $proxyusername optional - * @param string $proxypassword optional + * @param bool $wsdl optional, set to true if using WSDL + * @param int $portName optional portName in WSDL document + * @param string $proxyhost + * @param string $proxyport + * @param string $proxyusername + * @param string $proxypassword * @param integer $timeout set the connection timeout * @param integer $response_timeout set the response timeout - * @param string $portName optional portName in WSDL document * @access public */ - function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = ''){ + function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30){ parent::nusoap_base(); $this->endpoint = $endpoint; $this->proxyhost = $proxyhost; @@ -7261,7 +7129,6 @@ function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = f $this->proxypassword = $proxypassword; $this->timeout = $timeout; $this->response_timeout = $response_timeout; - $this->portName = $portName; $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout"); $this->appendDebug('endpoint=' . $this->varDump($endpoint)); @@ -7308,7 +7175,7 @@ function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = f * @param boolean $rpcParams optional (no longer used) * @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override) * @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override) - * @return mixed response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors + * @return mixed response from SOAP call * @access public */ function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){ @@ -7385,8 +7252,8 @@ function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAc // operation not in WSDL $this->appendDebug($this->wsdl->getDebug()); $this->wsdl->clearDebug(); - $this->setError('operation '.$operation.' not present in WSDL.'); - $this->debug("operation '$operation' not present in WSDL."); + $this->setError( 'operation '.$operation.' not present.'); + $this->debug("operation '$operation' not present."); return false; } else { // no WSDL @@ -7499,24 +7366,16 @@ function checkWSDL() { $this->debug('checkWSDL'); // catch errors if ($errstr = $this->wsdl->getError()) { - $this->appendDebug($this->wsdl->getDebug()); - $this->wsdl->clearDebug(); $this->debug('got wsdl error: '.$errstr); $this->setError('wsdl error: '.$errstr); - } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap')) { - $this->appendDebug($this->wsdl->getDebug()); - $this->wsdl->clearDebug(); + } elseif ($this->operations = $this->wsdl->getOperations('soap')) { $this->bindingType = 'soap'; $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType); - } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) { - $this->appendDebug($this->wsdl->getDebug()); - $this->wsdl->clearDebug(); + } elseif ($this->operations = $this->wsdl->getOperations('soap12')) { $this->bindingType = 'soap12'; $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType); $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************'); } else { - $this->appendDebug($this->wsdl->getDebug()); - $this->wsdl->clearDebug(); $this->debug('getOperations returned false'); $this->setError('no operations defined in the WSDL document!'); } @@ -7529,7 +7388,7 @@ function checkWSDL() { */ function loadWSDL() { $this->debug('instantiating wsdl class with doc: '.$this->wsdlFile); - $this->wsdl = new wsdl('',$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout,$this->curl_options,$this->use_curl); + $this->wsdl =& new wsdl('',$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout,$this->curl_options,$this->use_curl); $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest); $this->wsdl->fetchWSDL($this->wsdlFile); $this->checkWSDL(); @@ -7573,7 +7432,7 @@ function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) { // detect transport switch(true){ // http(s) - case preg_match('/^http/',$this->endpoint): + case ereg('^http',$this->endpoint): $this->debug('transporting via HTTP'); if($this->persistentConnection == true && is_object($this->persistentConnection)){ $http =& $this->persistentConnection; @@ -7595,10 +7454,10 @@ function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) { $http->setEncoding($this->http_encoding); } $this->debug('sending message, length='.strlen($msg)); - if(preg_match('/^http:/',$this->endpoint)){ + if(ereg('^http:',$this->endpoint)){ //if(strpos($this->endpoint,'http:')){ $this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies); - } elseif(preg_match('/^https/',$this->endpoint)){ + } elseif(ereg('^https',$this->endpoint)){ //} elseif(strpos($this->endpoint,'https:')){ //if(phpversion() == '4.3.0-dev'){ //$response = $http->send($msg,$timeout,$response_timeout); @@ -7650,10 +7509,6 @@ function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) { function parseResponse($headers, $data) { $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:'); $this->appendDebug($this->varDump($headers)); - if (!isset($headers['content-type'])) { - $this->setError('Response not of type text/xml (no content-type header)'); - return false; - } if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Response not of type text/xml: ' . $headers['content-type']); return false; @@ -7661,7 +7516,7 @@ function parseResponse($headers, $data) { if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); - if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){ + if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){ $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; @@ -8145,4 +8000,4 @@ function UpdateCookies($cookies) { class soapclient extends nusoap_client { } } - +?>