/** * Gets the status of the entered donation code from the donation code script * * @param string $host * @param string $donation_code * * @return int */ private static function getDonationCodeStatus($host, $donation_code) { $donation_code_check = 0; if (JHttpFactory::getAvailableDriver(new Registry()) == false) { return -2; } if (!empty($host) and !empty($donation_code)) { // First try it with the main validation server and with HTTPS $url_check = 'https://check.kubik-rubik.de/donationcode/validation.php?key=' . rawurlencode($donation_code) . '&host=' . rawurlencode($host); try { $donation_code_request = JHttpFactory::getHttp()->get($url_check); } catch (Exception $e) { // Try it with the fall back server and without HTTPS $url_check_fallback = 'http://check.kubik-rubik.eu/donationcode/validation.php?key=' . rawurlencode($donation_code) . '&host=' . rawurlencode($host); try { $donation_code_request = JHttpFactory::getHttp()->get($url_check_fallback); } catch (Exception $e) { return -1; } } if (!empty($donation_code_request->body)) { if (preg_match('@(error|access denied)@i', $donation_code_request->body)) { return -1; } $donation_code_check = (int) $donation_code_request->body; } } return $donation_code_check; }
/** * */ public function __construct() { jimport('joomla.http.factory'); if (!class_exists('JHttpFactory')) { throw new BadFunctionCallException(JchPlatformUtility::translate('JHttpFactory not present. Please upgrade your version of Joomla. Exiting plugin...')); } $aOptions = array('follow_location' => true); $oOptions = new JRegistry($aOptions); $this->oHttpAdapter = JHttpFactory::getAvailableDriver($oOptions); }
private function getDonationCodeStatus($host, $donation_code) { $donation_code_check = 0; if (JHttpFactory::getAvailableDriver(new JRegistry()) == false) { $donation_code_check = -2; } else { if (!empty($host) and !empty($donation_code)) { $url_check = 'https://joomla-extensions.kubik-rubik.de/scripts/je_kr_donation_code_check/je_kr_check_code.php?key=' . rawurlencode($donation_code) . '&host=' . rawurlencode($host); $donation_code_request = JHttpFactory::getHttp()->get($url_check); if (!empty($donation_code_request->body)) { $donation_code_check = $donation_code_request->body; } } if (preg_match('@(error|access denied)@i', $donation_code_check)) { $donation_code_check = -1; } } return $donation_code_check; }
/** * Constructor. * * @param JRegistry $options Client options object. If the registry contains any headers.* elements, * these will be added to the request headers. * @param JHttpTransport $transport The HTTP transport object. * * @since 11.3 */ public function __construct(JRegistry $options = null, JHttpTransport $transport = null) { $this->options = isset($options) ? $options : new JRegistry(); $this->transport = isset($transport) ? $transport : JHttpFactory::getAvailableDriver($this->options); }
/** * Tests the getAvailableDriver method. * * @return void * * @since 3.4 */ public function testGetAvailableDriver() { $this->assertFalse(JHttpFactory::getAvailableDriver(new \Joomla\Registry\Registry(), array()), 'Passing an empty array should return false due to there being no adapters to test'); $this->assertFalse(JHttpFactory::getAvailableDriver(new \Joomla\Registry\Registry(), array('fopen')), 'A false should be returned if a class is not present or supported'); }
/** * This function loads the content of the provided URL. It uses the JHttp class of the Joomla! API and the factory * class of Joomla! 3 which was backported for Joomla! 2.5 * * The socket transport driver is used to determine whether a called URL exists at all. The timeout of 5 seconds * helps to reduce the loading time of the request process. * * @param string $url * @param bool $socket * * @return bool|int|JHttpResponse */ private function getPageContent($url, $socket = false) { $content = new stdClass(); // We need the factory class which helps us to determine all supported adapters by the used server if (!class_exists('JHttpFactory')) { include JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jhttpfactory.php'; } if (!empty($socket) and $http_socket = JHttpFactory::getAvailableDriver(new JRegistry(), 'socket')) { $content = $http_socket->request('HEAD', new JUri($url), null, null, 5, $this->_user_agent); // We don't need the content, only the response code if the socket transport driver is used return $content->code; } else { // Normal query check with available handlers - cURL has always priority - use allow_url_fopen only as fallback // Normally you should get the content like this: // $jhttp_factory = JHttpFactory::getHttp(); // $content = $jhttp_factory->get($url); // But so we can not set the user agent which is required on many websites (servers) to make the request valid if ($http_curl = JHttpFactory::getAvailableDriver(new JRegistry(), 'curl')) { $content = $http_curl->request('GET', new JUri($url), null, null, 5, $this->_user_agent); } elseif ($http_fopen = JHttpFactory::getAvailableDriver(new JRegistry(), 'stream')) { $content = $http_fopen->request('GET', new JUri($url), null, null, 5, $this->_user_agent); } } // Code 200? Everything okay, go on! if (!empty($content) and $content->code == 200) { return $content; } else { return false; } }
/** * Helper wrapper method for getAvailableDriver * * @param Registry $options Option for creating http transport object. * @param mixed $default Adapter (string) or queue of adapters (array) to use. * * @return JHttpTransport Interface sub-class * * @see JHttpFactory::getAvailableDriver() * @since 3.4 */ public function getAvailableDriver(Registry $options, $default = null) { return JHttpFactory::getAvailableDriver($options, $default); }