commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Core / Payment / PaymentExpressUtils.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24 */
25
26
27 /*
28 * PxPay Functionality Copyright (C) 2008 Lucas Baker, Logistic Information Systems Limited (Logis)
29 * PxAccess Functionality Copyright (C) 2008 Eileen McNaughton
30 * Licensed to CiviCRM under the Academic Free License version 3.0.
31 *
32 * Grateful acknowledgements go to Donald Lobo for invaluable assistance
33 * in creating this payment processor module
34 */
35
36 /**
37 * Class CRM_Core_Payment_PaymentExpressUtils
38 */
39 class CRM_Core_Payment_PaymentExpressUtils {
40
41 /**
42 * @param $element
43 * @param null $value
44 *
45 * @return string
46 */
47 public static function _valueXml($element, $value = NULL) {
48 $nl = "\n";
49
50 if (is_array($element)) {
51 $xml = '';
52 foreach ($element as $elem => $value) {
53 $xml .= self::_valueXml($elem, $value);
54 }
55 return $xml;
56 }
57 return "<" . $element . ">" . $value . "</" . $element . ">" . $nl;
58 }
59
60 /**
61 * @param $xml
62 * @param string $name
63 *
64 * @return mixed
65 */
66 public static function _xmlElement($xml, $name) {
67 $value = preg_replace('/.*<' . $name . '[^>]*>(.*)<\/' . $name . '>.*/', '\1', $xml);
68 return $value;
69 }
70
71 /**
72 * @param $xml
73 * @param string $name
74 *
75 * @return mixed|null
76 */
77 public static function _xmlAttribute($xml, $name) {
78 $value = preg_replace('/<.*' . $name . '="([^"]*)".*>/', '\1', $xml);
79 return $value != $xml ? $value : NULL;
80 }
81
82 /**
83 * @param $query
84 * @param $url
85 *
86 * @return resource
87 */
88 public static function &_initCURL($query, $url) {
89 $curl = curl_init();
90
91 curl_setopt($curl, CURLOPT_URL, $url);
92 curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE);
93 curl_setopt($curl, CURLOPT_POST, TRUE);
94 curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
95 curl_setopt($curl, CURLOPT_TIMEOUT, 30);
96 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
97 if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
98 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, FALSE);
99 }
100 curl_setopt($curl, CURLOPT_HEADER, 0);
101 curl_setopt($curl, CURLOPT_SSLVERSION, 0);
102
103 if (strtoupper(substr(@php_uname('s'), 0, 3)) === 'WIN') {
104 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'));
105 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL') ? 2 : 0);
106 }
107 return $curl;
108 }
109
110 }