Esempio n. 1
0
 /**
  * Prepares and executes requests by given request_paths values
  *
  * @param array $info
  * @param Varien_Http_Adapter_Curl $adapter
  */
 protected function _executeRequests(array $info, Varien_Http_Adapter_Curl $adapter)
 {
     $storeId = $info['store_id'];
     $options = array(CURLOPT_USERAGENT => self::USER_AGENT, CURLOPT_SSL_VERIFYPEER => 0);
     $threads = $this->_getCrawlerThreads($storeId);
     if (!$threads) {
         $threads = 1;
     }
     if (!empty($info['cookie'])) {
         $options[CURLOPT_COOKIE] = $info['cookie'];
     }
     $urls = array();
     $offset = 0;
     Mage::getSingleton('core/session')->setCrawlerOffset($offset);
     while ($rewrites = $this->_getResource()->getRequestPaths($storeId)) {
         foreach ($rewrites as $rewriteRow) {
             $url = $this->_getUrlByRewriteRow($rewriteRow, $info['base_url'], $storeId);
             $urls[] = $url;
             if (count($urls) == $threads) {
                 $adapter->multiRequest($urls, $options);
                 $urls = array();
             }
         }
         $offset += self::BATCH_SIZE;
         Mage::getSingleton('core/session')->setCrawlerOffset($offset);
     }
     if (!empty($urls)) {
         $adapter->multiRequest($urls, $options);
     }
 }
Esempio n. 2
0
 public function ipnPostSubmit()
 {
     // Give PAP access to the data so it can handle any needed commissions
     try {
         $papModel = Mage::getModel('pap/pap');
         $postData = $this->getIpnFormData();
         $customdata = explode('~~~a469ccb0-767c-4fed-96de-99427e1783aa~~~', $postData['custom']);
         $saleData = isset($customdata[0]) ? $customdata[0] : null;
         $cookieValue = isset($customdata[1]) ? $customdata[1] : null;
         // Convert the JSON data into a usable array
         $saleData = json_decode($saleData);
         $saleData = $this->ForceArray($saleData);
         $sReq = '';
         foreach ($this->getIpnFormData() as $k => $v) {
             $sReq .= '&' . $k . '=' . urlencode(stripslashes($v));
         }
         //append ipn commdn
         $sReq .= "&cmd=_notify-validate";
         $sReq = substr($sReq, 1);
         $http = new Varien_Http_Adapter_Curl();
         $http->write(Zend_Http_Client::POST, $this->getPaypalUrl(), '1.1', array(), $sReq);
         $response = $http->read();
         $response = preg_split('/^\\r?$/m', $response, 2);
         $response = trim($response[1]);
         if ($response == 'VERIFIED') {
             $papModel->registerSaleDetails($saleData, isset($cookieValue) ? $cookieValue : null);
         }
     } catch (Exception $e) {
         Mage::log('Caught exception while trying to log PayPal sale: ' . $e->getMessage() . "\n");
     }
     // let the base class go on to do whatever processing it was going to do
     parent::ipnPostSubmit();
 }
Esempio n. 3
0
 /**
  * This method will send call to external end points using GET or POST method
  * 
  * @param type $apiType url that needs to be called
  * @param type $requestType GET or POST
  * @param type $data model data that needs to be send with url 
  * @return type json
  * @throws Exception
  */
 public function send($apiType, $requestType, $data)
 {
     $curlAdapter = new Varien_Http_Adapter_Curl();
     $curlAdapter->setConfig(array('timeout' => 20));
     $body_param = Mage::helper('core')->jsonEncode($data);
     $header = $this->getHeader();
     try {
         $curlAdapter->write($requestType, $apiType, '1.1', $header, $body_param);
         $result = $curlAdapter->read();
         $response = preg_split('/^\\r?$/m', $result, 2);
         $response = trim($response[1]);
         $res = NULL;
         if (!is_null($response) && !empty($response)) {
             $res = Mage::helper('core')->jsonDecode($response);
         } else {
             Mage::log('Encountered problems trying to contact Terapeak');
             Mage::log($curlAdapter->getError());
         }
     } catch (Exception $e) {
         //eat the execption. We should not crash the magento instance if our extention throws exceptions
         Mage::log('Exception when trying to send data to Terapeak:');
         Mage::log($e);
     }
     return $res;
 }
 public function requestUrls($urls, $verbose = true)
 {
     $adapter = new Varien_Http_Adapter_Curl();
     $options = array(CURLOPT_USERAGENT => self::USER_AGENT, CURLOPT_HEADER => true);
     $multiResult = $adapter->multiRequest($urls, $options);
     foreach ($multiResult as $urlId => $content) {
         $urlModel = Mage::getModel('fpc/crawler_url')->load($urlId);
         $this->_removeDublicates($urlModel);
         $matches = array();
         preg_match('/Fpc-Cache-Id: (' . Mirasvit_Fpc_Model_Processor::REQUEST_ID_PREFIX . '[a-z0-9]{32})/', $content, $matches);
         if (count($matches) == 2) {
             $cacheId = $matches[1];
             if ($urlModel->getCacheId() != $cacheId) {
                 $urlModel->setCacheId($cacheId)->save();
             }
             if ($verbose) {
                 echo 'CACHED ' . $urls[$urlId] . PHP_EOL;
             }
         } else {
             if ($verbose) {
                 echo 'REMOVED ' . $urls[$urlId] . PHP_EOL;
             }
             $urlModel->delete();
         }
     }
     return $this;
 }
Esempio n. 5
0
 public function isValidVies($taxvat, $countryCode)
 {
     if ('UK' === $countryCode) {
         $countryCode = 'GB';
     }
     if (!isset($this->_patterns[$countryCode])) {
         $this->_message = 'The provided CountryCode is invalid for the VAT number';
         return false;
     }
     //        $vies  = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
     //        $check = new firecheckoutCheckVat($countryCode, $taxvat);
     //        try {
     //            $ret = $vies->checkVat($check);
     //        } catch (SoapFault $e) {
     //            $ret = $e->faultstring;
     //            $pattern = '/\{ \'([A-Z_]*)\' \}/';
     //            $n = preg_match($pattern, $ret, $matches);
     //            $ret = $matches[1];
     //            $faults = array(
     //              'INVALID_INPUT'       => 'The provided CountryCode is invalid or the VAT number is empty',
     //              'SERVICE_UNAVAILABLE' => 'The SOAP service is unavailable, try again later',
     //              'MS_UNAVAILABLE'      => 'The Member State service is unavailable, try again later or with another Member State',
     //              'TIMEOUT'             => 'The Member State service could not be reached in time, try again later or with another Member State',
     //              'SERVER_BUSY'         => 'The service cannot process your request. Try again later.'
     //            );
     //            $this->_message = $faults[$ret];
     //            return false;
     //        }
     //        return true;
     try {
         $http = new Varien_Http_Adapter_Curl();
         $http->setConfig(array('timeout' => 30));
         $http->write(Zend_Http_Client::POST, 'http://ec.europa.eu/taxation_customs/vies/viesquer.do', '1.1', array(), http_build_query(array('ms' => $countryCode, 'iso' => $countryCode, 'vat' => $taxvat)));
         $response = $http->read();
         $http->close();
     } catch (Exception $e) {
         throw $e;
     }
     $response = str_replace(array("\n", "\r", "\t"), '', $response);
     if (empty($response) || strstr($response, 'Yes, valid VAT number')) {
         // if service is not available of correct vat number
         return true;
     } elseif (strstr($response, 'No, invalid VAT number')) {
         $this->_message = 'Invalid VAT number';
     } elseif (strstr($response, 'Service unavailable')) {
         $this->_message = 'The VAT validation service unavailable. Please re-submit your request later.';
     } elseif (strstr($response, 'Member State service unavailable')) {
         $this->_message = 'The VAT validation service unavailable. Please re-submit your request later.';
     } elseif (strstr($response, 'Error: Incomplete')) {
         $this->_message = 'The provided CountryCode is invalid or the VAT number is empty';
     } elseif (strstr($response, 'Request time-out')) {
         $this->_message = 'The VAT validation service cannot process your request. Try again later.';
     } elseif (strstr($response, 'System busy')) {
         $this->_message = 'The VAT validation service cannot process your request. Try again later.';
     } else {
         $this->_message = 'Unknown VAT validation service message. Try again later.';
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Talk to new relic
  * 
  * @param string $restPoint
  * @return string
  */
 public function talkToNewRelic($restPoint)
 {
     $headers = array('x-api-key:' . $this->_api_key);
     $http = new Varien_Http_Adapter_Curl();
     $http->write('GET', 'https://api.newrelic.com/api/v1/accounts/' . $this->_account_Id . '/' . $restPoint . '.xml', '1.1', $headers);
     $response = $http->read();
     $response = Zend_Http_Response::extractBody($response);
     return $response;
 }
Esempio n. 7
0
 protected function _loadUrl($url)
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 30));
     $curl->write(Zend_Http_Client::GET, $url, '1.0');
     $text = $curl->read();
     $text = preg_split('/^\\r?$/m', $text, 2);
     $text = trim($text[1]);
     return $text;
 }
Esempio n. 8
0
 /**
  * Check if survey url valid (exists) or not
  *
  * @return boolen
  */
 public static function isSurveyUrlValid()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 5))->write(Zend_Http_Client::GET, self::getSurveyUrl(), '1.0');
     $response = $curl->read();
     if (Zend_Http_Response::extractCode($response) == 200) {
         return true;
     }
     return false;
 }
Esempio n. 9
0
 /**
  * If file is accessible return true or false
  *
  * @return bool
  */
 private function _isFileAccessible()
 {
     $defaultUnsecureBaseURL = (string) Mage::getConfig()->getNode('default/' . Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL);
     $http = new Varien_Http_Adapter_Curl();
     $http->setConfig(array('timeout' => $this->_verificationTimeOut));
     $http->write(Zend_Http_Client::POST, $defaultUnsecureBaseURL . $this->_filePath);
     $responseBody = $http->read();
     $responseCode = Zend_Http_Response::extractCode($responseBody);
     $http->close();
     return $responseCode == 200;
 }
Esempio n. 10
0
 public function createApiPost($path, $data)
 {
     try {
         $config = array('timeout' => 30);
         $http = new Varien_Http_Adapter_Curl();
         $feed_url = self::YOTPO_API_URL . DS . $this->app_key . DS . $path;
         $http->setConfig($config);
         $http->write(Zend_Http_Client::POST, $feed_url, '1.1', array('Content-Type: application/json'), json_encode($data));
         $resData = $http->read();
     } catch (Exception $e) {
         Mage::log('error: ' . $e);
     }
 }
Esempio n. 11
0
 /**
  * Do the API call
  *
  * @param string $methodName
  * @param array $request
  * @return array
  * @throws Mage_Core_Exception
  */
 public function call($methodName, array $request)
 {
     $request = $this->_addMethodToRequest($methodName, $request);
     $eachCallRequest = $this->_prepareEachCallRequest($methodName);
     if ($this->getUseCertAuthentication()) {
         if ($key = array_search('SIGNATURE', $eachCallRequest)) {
             unset($eachCallRequest[$key]);
         }
     }
     $request = $this->_exportToRequest($eachCallRequest, $request);
     $debugData = array('url' => $this->getApiEndpoint(), $methodName => $request);
     try {
         $http = new Varien_Http_Adapter_Curl();
         $config = array('timeout' => 30, 'verifypeer' => $this->_config->verifyPeer);
         if ($this->getUseProxy()) {
             $config['proxy'] = $this->getProxyHost() . ':' . $this->getProxyPort();
         }
         if ($this->getUseCertAuthentication()) {
             $config['ssl_cert'] = $this->getApiCertificate();
         }
         $http->setConfig($config);
         $http->write(Zend_Http_Client::POST, $this->getApiEndpoint(), '1.1', $this->_headers, $this->_buildQuery($request));
         $response = $http->read();
     } catch (Exception $e) {
         $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         $this->_debug($debugData);
         throw $e;
     }
     $response = preg_split('/^\\r?$/m', $response);
     $response = trim(end($response));
     $response = $this->_deformatNVP($response);
     $debugData['response'] = $response;
     $this->_debug($debugData);
     $response = $this->_postProcessResponse($response);
     // handle transport error
     if ($http->getErrno()) {
         Mage::logException(new Exception(sprintf('PayPal NVP CURL connection error #%s: %s', $http->getErrno(), $http->getError())));
         $http->close();
         Mage::throwException(Mage::helper('paypal')->__('Unable to communicate with the PayPal gateway.'));
     }
     // cUrl resource must be closed after checking it for errors
     $http->close();
     if (!$this->_validateResponse($methodName, $response)) {
         Mage::logException(new Exception(Mage::helper('paypal')->__("PayPal response hasn't required fields.")));
         Mage::throwException(Mage::helper('paypal')->__('There was an error processing your order. Please contact us or try again later.'));
     }
     $this->_callErrors = array();
     if ($this->_isCallSuccessful($response)) {
         if ($this->_rawResponseNeeded) {
             $this->setRawSuccessResponseData($response);
         }
         return $response;
     }
     $this->_handleCallErrors($response);
     return $response;
 }
Esempio n. 12
0
 /**
  * Make a call to Payment Bridge service with given request parameters
  *
  * @param array $request
  * @return array
  * @throws Mage_Core_Exception
  */
 protected function _call(array $request)
 {
     $response = null;
     $debugData = array('request' => $request);
     try {
         $http = new Varien_Http_Adapter_Curl();
         $config = array('timeout' => 30);
         $http->setConfig($config);
         $http->write(Zend_Http_Client::POST, $this->getPbridgeEndpoint(), '1.1', array(), $this->_prepareRequestParams($request));
         $response = $http->read();
         $http->close();
     } catch (Exception $e) {
         $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         $this->_debug($debugData);
         throw $e;
     }
     $this->_debug($response);
     if ($response) {
         $response = preg_split('/^\\r?$/m', $response, 2);
         $response = Mage::helper('core')->jsonDecode(trim($response[1]));
         $debugData['result'] = $response;
         $this->_debug($debugData);
         if ($http->getErrno()) {
             Mage::logException(new Exception(sprintf('Payment Bridge CURL connection error #%s: %s', $http->getErrno(), $http->getError())));
             Mage::throwException(Mage::helper('enterprise_pbridge')->__('Unable to communicate with Payment Bridge service.'));
         }
         if (isset($response['status']) && $response['status'] == 'Success') {
             $this->_response = $response;
             return true;
         }
     }
     $this->_handleError($response);
     $this->_response = $response;
     return false;
 }
Esempio n. 13
0
 public function sendRequest($request, $parameters = array())
 {
     if (!$this->code || !$this->username || !$this->password) {
         return false;
     }
     if ($request != 'verifyUser' && !$this->session) {
         return false;
     }
     $parameters['sessionKey'] = $this->session;
     $parameters['request'] = $request;
     $parameters['version'] = '1.0';
     $parameters['clientCode'] = $this->code;
     $url = $this->getUrl();
     $http = new Varien_Http_Adapter_Curl();
     $http->setConfig(array('timeout' => 100));
     //        $http->write(Zend_Http_Client::POST, $parameters);
     $http->write(Zend_Http_Client::POST, $url, CURL_HTTP_VERSION_1_0, array(), $parameters);
     $responseBody = Zend_Http_Response::extractBody($http->read());
     $http->close();
     if (Mage::getStoreConfig('eepohs_erply/general/log_requests')) {
         Mage::log("REQUEST URL: " . $url . "\nREQUEST PARAMETERS:\n" . print_r($parameters, true) . "\nRESPONSE:\n" . $responseBody, null, self::REQUEST_LOG);
     }
     //        $http = new Varien_Http_Adapter_Curl();
     //        $config = array('timeout' => 30);
     //
     //        $http->setConfig($config);
     //        $http->write(Zend_Http_Client::POST, $url, '1.0', array(), http_build_query($parameters));
     //        $content = Zend_Http_Response::extractBody($http->read());
     //        print_r(Zend_Http_Response::extractHeaders($http->read()));
     //return $content;
     //        $ch = curl_init();
     //        curl_setopt($ch, CURLOPT_URL, $url);
     //        curl_setopt($ch, CURLOPT_HEADER, 1);
     //        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
     //        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     //        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     //        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     //        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //        curl_setopt($ch, CURLOPT_POST, true);
     //        curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
     //
     //        if (curl_exec($ch) === false)
     //            return false;
     //
     //        $content = curl_multi_getcontent($ch);
     //        curl_close($ch);
     //        list($header1, $header2, $body) = explode("\r\n\r\n", $content, 3);
     return $responseBody;
 }
Esempio n. 14
0
 /**
  * Perform a CURL call and log request end response to logfile
  *
  * @param array $params
  * @return mixed
  */
 public function call($params, $url)
 {
     try {
         $http = new Varien_Http_Adapter_Curl();
         $config = array('timeout' => 30);
         $http->setConfig($config);
         $http->write(Zend_Http_Client::POST, $url, '1.1', array(), http_build_query($params));
         $response = $http->read();
         $response = substr($response, strpos($response, "<?xml"), strlen($response));
         return $response;
     } catch (Exception $e) {
         Mage::logException($e);
         Mage::throwException(Mage::helper('ops')->__('Barclaycard server is temporarily not available, please try again later.'));
     }
 }
Esempio n. 15
0
 public function getClientData()
 {
     $eadesignUrl = 'https://www.eadesign.ro/';
     $extension = 'Eadesigndev_Awb';
     $moduleVersion = Mage::getConfig()->getModuleConfig($extension)->version;
     $baseUrl = 'track/index/update?url=' . Mage::getBaseUrl();
     $version = '&version=' . $moduleVersion;
     $moduleExtension = '&extension=' . $extension;
     $url = $eadesignUrl . $baseUrl . $version . $moduleExtension;
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 3));
     $curl->write(Zend_Http_Client::GET, $url, '1.0');
     $curl->read();
     $curl->close();
 }
Esempio n. 16
0
 /**
  * @param array $url
  * @return array
  */
 public function getCurlOptions($url)
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 5));
     $curl->write(Zend_Http_Client::GET, $url);
     $response = $curl->read();
     if ($response === false) {
         return false;
     }
     $response = preg_split('/^\\r?$/m', $response, 2);
     $response = trim($response[1]);
     $options = explode("\n", $response);
     $curl->close();
     return $options;
 }
Esempio n. 17
0
 /**
  * Central method for making a post operation against this Solr Server
  *
  * @param string $url
  * @param string $rawPost
  * @param int|bool $timeout Read timeout in seconds
  * @param string $contentType
  *
  * @return Apache_Solr_Response
  */
 protected function _sendRawPost($url, $rawPost, $timeout = false, $contentType = 'text/xml; charset=UTF-8')
 {
     $headers = array('Content-Type: ' . $contentType);
     $this->_setBasicAdapterOptions($timeout);
     $this->_curlAdapter->addOptions(array(CURLOPT_HEADER => 1))->write(Zend_Http_Client::POST, $url, '1.1', $headers, $rawPost);
     return $this->_getResponse();
 }
Esempio n. 18
0
 /**
  * Read html from the store feed
  *
  * @return string
  */
 private function getContent()
 {
     $data = NULL;
     if (!extension_loaded('curl')) {
         return $data;
     }
     $url = Mage::helper('belvgall')->getStoreUrl();
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 2, 'header' => FALSE));
     $curl->write(Zend_Http_Client::GET, $url, '1.0');
     $data = $curl->read();
     if ($data === FALSE) {
         return NULL;
     }
     $curl->close();
     return $data;
 }
Esempio n. 19
0
 public function getFeedData($feedUrl)
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->write(Zend_Http_Client::GET, $feedUrl, '1.0');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         return false;
     }
     return $xml;
 }
Esempio n. 20
0
 public function getFeed($url, $params = array())
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->write(Zend_Http_Client::POST, $url, '1.1', array(), http_build_query($params));
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         return false;
     }
     return $xml;
 }
 /**
  * @param ResultCollection $results
  */
 public function check(ResultCollection $results)
 {
     $result = $results->createResult();
     $filePath = 'app/etc/local.xml';
     $defaultUnsecureBaseURL = (string) \Mage::getConfig()->getNode('default/' . \Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL);
     $http = new \Varien_Http_Adapter_Curl();
     $http->setConfig(array('timeout' => $this->_verificationTimeOut));
     $http->write(\Zend_Http_Client::POST, $defaultUnsecureBaseURL . $filePath);
     $responseBody = $http->read();
     $responseCode = \Zend_Http_Response::extractCode($responseBody);
     $http->close();
     if ($responseCode === 200) {
         $result->setStatus(Result::STATUS_ERROR);
         $result->setMessage("<error>{$filePath} can be accessed from outside!</error>");
     } else {
         $result->setStatus(Result::STATUS_OK);
         $result->setMessage("<info><comment>{$filePath}</comment> cannot be accessed from outside.</info>");
     }
 }
Esempio n. 22
0
 public function getFeedData()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 1));
     $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
     $data = $curl->read();
     if ($data === false || Zend_Http_Response::extractCode($data) !== 200) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         return false;
     }
     return $xml;
 }
Esempio n. 23
0
 public function getFeedData()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 2));
     $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $json = json_decode($data);
     } catch (Exception $e) {
         return false;
     }
     return $json;
 }
 public function getFeedData()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 1));
     $curl->write(Zend_Http_Client::GET, self::URI_EXTENSIONS, '1.0');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         return false;
     }
     return $xml;
 }
Esempio n. 25
0
 public function getNotificationData()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 2));
     $curl->write(Zend_Http_Client::GET, $this->getMagestoreUrl(), '1.0');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         return false;
     }
     return $xml;
 }
Esempio n. 26
0
 /**
  * Retrieve feed data as XML element
  *
  * @return SimpleXMLElement
  */
 public function getFeedData()
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 60));
     $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         Ebizmarts_SagePaySuite_Log::we($e);
         return false;
     }
     return $xml;
 }
Esempio n. 27
0
 public function load()
 {
     // we expect <var name="uri">http://...</var>
     $uri = $this->getVar('uri');
     // validate input parameter
     if (!Zend_Uri::check($uri)) {
         $this->addException("Expecting a valid 'uri' parameter");
     }
     // use Varien curl adapter
     $http = new Varien_Http_Adapter_Curl();
     // send GET request
     $http->write('GET', $uri);
     // read the remote file
     $data = $http->read();
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     // save contents into container
     $this->setData($data);
     return $this;
 }
Esempio n. 28
0
 protected function _makeRequest($ping)
 {
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 20));
     $curl->write(Zend_Http_Client::GET, $ping, '1.1');
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $code = $curl->getInfo(CURLINFO_HTTP_CODE);
     if ($code == 200) {
         return $code;
     } else {
         Mage::log("Submission to: " . $ping . " failed, HTTP response code was not 200");
         Mage::log("Response error: " . $data);
         // uncomment to debug raw submission response
         return false;
     }
     //TODO: handle timeout?
 }
Esempio n. 29
0
 /**
  * Send request to the remote server
  *
  * @param string        $method
  * @param Zend_Uri_Http $url
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as text
  */
 public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '')
 {
     if ($method == Zend_Http_Client::PUT) {
         // not working, cop-out and used a system call to curl. (ugh)
         curl_setopt($this->_getResource(), CURLOPT_CUSTOMREQUEST, "PUT");
         //curl_setopt($this->_getResource(), CURLOPT_PUT, true); // some version of curl allows this, rarher than the above ?
         //curl_setopt($this->_getResource(), CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT') );
         curl_setopt($this->_getResource(), CURLOPT_POSTFIELDS, json_encode($body));
         curl_setopt($this->_getResource(), CURLOPT_VERBOSE, true);
     }
     return parent::write($method, $url, $http_ver, $headers, $body);
 }
Esempio n. 30
0
 public function getFeedData()
 {
     $dataModules = Mage::helper('devopennotify')->devopensourceModulesLoaded();
     $jsonModules = json_encode($dataModules);
     $curl = new Varien_Http_Adapter_Curl();
     $curl->setConfig(array('timeout' => 2));
     $headers = array("Content-Type: application/json", "Accept: application/json", "Content-Length: " . strlen($jsonModules));
     $curl->write(Zend_Http_Client::POST, self::DEVOPENSOURCE_URL_NOTIFICATIONS, null, $headers, $jsonModules);
     $data = $curl->read();
     if ($data === false) {
         return false;
     }
     $data = preg_split('/^\\r?$/m', $data, 2);
     $data = trim($data[1]);
     $curl->close();
     try {
         $json = json_decode($data);
     } catch (Exception $e) {
         return false;
     }
     return $json;
 }