3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * Objednavka dotazniku spokojenosti * * Ukazka pouziti * * Nazvy produktu preferujeme v kódování UTF-8. Pokud název produktu * převést nedokážete, poradíme si s WINDOWS-1250 i ISO-8859-2 * * <code> * $overeno = new HeurekaOvereno('API_KLIC'); * // pro slovenske obchody $overeno = new HeurekaOvereno('API_KLIC', HEUREKA_LANGUAGE_SK); * $overeno->setEmail('ondrej.cech@heureka.cz'); * $overeno->addProduct('Nokia N95'); * if (false === $overeno->send()) { * print 'Chyba volání HEUREKA API: ' . $overeno->getLastError(); * } * </code> * * @author Ondrej Cech <ondrej.cech@heureka.cz> */ /** * Zakladni URL * * @var String */ define('HEUREKA_BASE_URL', 'http://www.heureka.cz/direct/dotaznik/objednavka.php'); define('HEUREKA_BASE_URL_SK', 'http://www.heureka.sk/direct/dotaznik/objednavka.php'); /** * Identifikator jazykovych mutaci * * @var Int */ define('HEUREKA_LANGUAGE_CZ', 1); define('HEUREKA_LANGUAGE_SK', 2); class HeurekaOvereno { /** * API klic pro identifikaci obchodu * * @var String */ var $apiKey; /** * Email zakaznika * * @var String */ var $email; /** * Pole objednanych produktu * * @var Array */ var $products = array(); /** * Cislo objednavky * * @var Int */ var $orderId; /** * Pole objednanych produktu - podle itemId * * @var Array */ var $productsItemId = array(); /** * Chybove hlaseni * * @var String */ var $errstr = NULL; /** * ID jazykove mutace * * @var int */ var $languageId = 1; /** * Konstruktor tridy * * @param String $apiKey API klic pro identifikaci obchodu */ function HeurekaOvereno ($apiKey, $languageId = HEUREKA_LANGUAGE_CZ) { $this->apiKey = $apiKey; $this->languageId = $languageId; } /** * Setter pro email * * @param String $email Email zakaznika, kteremu bude odeslat dotaznik */ function setEmail ($email) { $this->email = $email; } /** * Pridava objednane produkty do pozadavku * * Nazvy produktu preferujeme v kódování UTF-8. Pokud název produktu * převést nedokážete, poradíme si s WINDOWS-1250 i ISO-8859-2 * * @param String $productName Nazev objednaneho produktu */ function addProduct ($productName) { $this->products[] = $productName; } /** * Pridava item ID nakoupeneho produktu * * @param string itemId Item ID produktu */ function addProductItemId ($itemId) { $this->productsItemId[] = $itemId; } /** * Pridava cislo objednavky * * Timto cislem bude oznacen vyplneny dotaznik * * @param Int $orderId cislo objednavky */ function addOrderId ($orderId) { $this->orderId = $orderId; } /** * Provadi HTTP pozadavek na server * * @param String $url Volana URL adresa * @return String Odpoved ze serveru */ function sendRequest ($url) { $parsed = parse_url($url); $fp = fsockopen($parsed['host'], 80, $errno, $errstr, 5); if (!$fp) { $this->errstr = $errstr . ' (' . $errno . ')'; return false; } else { $return = ''; $out = "GET " . $parsed['path'] . "?" . $parsed['query'] . " HTTP/1.1\r\n" . "Host: " . $parsed['host'] . "\r\n" . "Connection: Close\r\n\r\n"; fputs($fp, $out); while (!feof($fp)) { $return .= fgets($fp, 128); } fclose($fp); $returnParsed = explode("\r\n\r\n", $return); return empty($returnParsed[1]) ? '' : trim($returnParsed[1]); } } /** * Vraci URL pro zadanou jazykovou mutaci * * @return String */ function getUrl () { return HEUREKA_LANGUAGE_CZ == (int) $this->languageId ? HEUREKA_BASE_URL : HEUREKA_BASE_URL_SK; } /** * Odesila pozadavek na objednani dotazniku * * @return Bool true */ function send () { if (empty($this->email)) { $this->errstr = 'Je nutné vyplnit elektronickou adresu'; return false; } // Stavime URL $url = $this->getUrl() . '?id=' . $this->apiKey . '&email=' . urlencode($this->email); foreach ($this->products as $product) { $url .= '&produkt[]=' . urlencode($product); } foreach ($this->productsItemId as $itemId) { $url .= '&itemId[]=' . urlencode($itemId); } if (isset($this->orderId)) { $url .= '&orderid=' . urlencode($this->orderId); } // Odesilame pozadavek a kontrolujeme stav $contents = $this->sendRequest($url); if (false === $contents) { $this->errstr = 'Nepodarilo se odeslat pozadavek'; return false; } elseif ('ok' == $contents) { return true; } else { $this->errstr = $contents; return false; } } /** * Vraci posledni chybove hlaseni * * @return String Chybove hlsaeni */ function getLastError () { return $this->errstr; } }
Output for 7.0.0 - 7.1.0
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; HeurekaOvereno has a deprecated constructor in /in/5WOHQ on line 38
Output for 4.3.0 - 4.4.9, 5.1.3 - 5.6.28
Output for 5.0.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 45 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 51 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 57 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 64 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 71 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 78 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5WOHQ on line 84