3v4l.org

run code in 300+ PHP versions simultaneously
<?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 */ private $orderId; /** * 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 cislo objednavky * * Timto cislem bude oznacen vyplneny dotaznik * * @param Int $orderId cislo objednavky */ public 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); } 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; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'HEUREKA_BASE_URL'
          2        SEND_VAL                                                 'http%3A%2F%2Fwww.heureka.cz%2Fdirect%2Fdotaznik%2Fobjednavka.php'
          3        DO_ICALL                                                 
   29     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'HEUREKA_BASE_URL_SK'
          6        SEND_VAL                                                 'http%3A%2F%2Fwww.heureka.sk%2Fdirect%2Fdotaznik%2Fobjednavka.php'
          7        DO_ICALL                                                 
   35     8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'HEUREKA_LANGUAGE_CZ'
         10        SEND_VAL                                                 1
         11        DO_ICALL                                                 
   36    12        INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'HEUREKA_LANGUAGE_SK'
         14        SEND_VAL                                                 2
         15        DO_ICALL                                                 
  199    16      > RETURN                                                   1

Class HeurekaOvereno:
Function heurekaovereno:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  HeurekaOvereno
number of ops:  7
compiled vars:  !0 = $apiKey, !1 = $languageId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   85     2        ASSIGN_OBJ                                               'apiKey'
          3        OP_DATA                                                  !0
   86     4        ASSIGN_OBJ                                               'languageId'
          5        OP_DATA                                                  !1
   87     6      > RETURN                                                   null

End of function heurekaovereno

Function setemail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  setEmail
number of ops:  4
compiled vars:  !0 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   RECV                                             !0      
   95     1        ASSIGN_OBJ                                               'email'
          2        OP_DATA                                                  !0
   96     3      > RETURN                                                   null

End of function setemail

Function addproduct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  addProduct
number of ops:  5
compiled vars:  !0 = $productName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   RECV                                             !0      
  107     1        FETCH_OBJ_W                                      $1      'products'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
  108     4      > RETURN                                                   null

End of function addproduct

Function addorderid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  addOrderId
number of ops:  4
compiled vars:  !0 = $orderId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  117     0  E >   RECV                                             !0      
  118     1        ASSIGN_OBJ                                               'orderId'
          2        OP_DATA                                                  !0
  119     3      > RETURN                                                   null

End of function addorderid

Function sendrequest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 41
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 41
Branch analysis from position: 51
Branch analysis from position: 41
filename:       /in/LBf8i
function name:  sendRequest
number of ops:  70
compiled vars:  !0 = $url, !1 = $parsed, !2 = $fp, !3 = $errno, !4 = $errstr, !5 = $return, !6 = $out, !7 = $returnParsed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  127     0  E >   RECV                                             !0      
  128     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
  129     5        INIT_FCALL                                               'fsockopen'
          6        FETCH_DIM_R                                      ~10     !1, 'host'
          7        SEND_VAL                                                 ~10
          8        SEND_VAL                                                 80
          9        SEND_REF                                                 !3
         10        SEND_REF                                                 !4
         11        SEND_VAL                                                 5
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !2, $11
  130    14        BOOL_NOT                                         ~13     !2
         15      > JMPZ                                                     ~13, ->23
  131    16    >   CONCAT                                           ~15     !4, '+%28'
         17        CONCAT                                           ~16     ~15, !3
         18        CONCAT                                           ~17     ~16, '%29'
         19        ASSIGN_OBJ                                               'errstr'
         20        OP_DATA                                                  ~17
  132    21      > RETURN                                                   <false>
         22*       JMP                                                      ->69
  134    23    >   ASSIGN                                                   !5, ''
  135    24        FETCH_DIM_R                                      ~19     !1, 'path'
         25        CONCAT                                           ~20     'GET+', ~19
         26        CONCAT                                           ~21     ~20, '%3F'
         27        FETCH_DIM_R                                      ~22     !1, 'query'
         28        CONCAT                                           ~23     ~21, ~22
         29        CONCAT                                           ~24     ~23, '+HTTP%2F1.1%0D%0A'
  136    30        CONCAT                                           ~25     ~24, 'Host%3A+'
         31        FETCH_DIM_R                                      ~26     !1, 'host'
         32        CONCAT                                           ~27     ~25, ~26
         33        CONCAT                                           ~28     ~27, '%0D%0A'
  137    34        CONCAT                                           ~29     ~28, 'Connection%3A+Close%0D%0A%0D%0A'
  135    35        ASSIGN                                                   !6, ~29
  138    36        INIT_FCALL                                               'fputs'
         37        SEND_VAR                                                 !2
         38        SEND_VAR                                                 !6
         39        DO_ICALL                                                 
  139    40      > JMP                                                      ->46
  140    41    >   INIT_FCALL                                               'fgets'
         42        SEND_VAR                                                 !2
         43        SEND_VAL                                                 128
         44        DO_ICALL                                         $32     
         45        ASSIGN_OP                                     8          !5, $32
  139    46    >   INIT_FCALL                                               'feof'
         47        SEND_VAR                                                 !2
         48        DO_ICALL                                         $34     
         49        BOOL_NOT                                         ~35     $34
         50      > JMPNZ                                                    ~35, ->41
  142    51    >   INIT_FCALL                                               'fclose'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                                 
  143    54        INIT_FCALL                                               'explode'
         55        SEND_VAL                                                 '%0D%0A%0D%0A'
         56        SEND_VAR                                                 !5
         57        DO_ICALL                                         $37     
         58        ASSIGN                                                   !7, $37
  145    59        ISSET_ISEMPTY_DIM_OBJ                         1          !7, 1
         60      > JMPZ                                                     ~39, ->63
         61    >   QM_ASSIGN                                        ~40     ''
         62      > JMP                                                      ->68
         63    >   INIT_FCALL                                               'trim'
         64        FETCH_DIM_R                                      ~41     !7, 1
         65        SEND_VAL                                                 ~41
         66        DO_ICALL                                         $42     
         67        QM_ASSIGN                                        ~40     $42
         68    > > RETURN                                                   ~40
  147    69*     > RETURN                                                   null

End of function sendrequest

Function geturl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  getUrl
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  155     0  E >   FETCH_CONSTANT                                   ~0      'HEUREKA_LANGUAGE_CZ'
          1        FETCH_OBJ_R                                      ~1      'languageId'
          2        CAST                                          4  ~2      ~1
          3        IS_EQUAL                                                 ~0, ~2
          4      > JMPZ                                                     ~3, ->8
          5    >   FETCH_CONSTANT                                   ~4      'HEUREKA_BASE_URL'
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->10
          8    >   FETCH_CONSTANT                                   ~6      'HEUREKA_BASE_URL_SK'
          9        QM_ASSIGN                                        ~5      ~6
         10    > > RETURN                                                   ~5
  156    11*     > RETURN                                                   null

End of function geturl

Function send:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 26
filename:       /in/LBf8i
function name:  send
number of ops:  53
compiled vars:  !0 = $url, !1 = $product, !2 = $contents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  164     0  E >   ISSET_ISEMPTY_PROP_OBJ                                   'email'
          1      > JMPZ                                                     ~3, ->5
  165     2    >   ASSIGN_OBJ                                               'errstr'
          3        OP_DATA                                                  'Je+nutn%C3%A9+vyplnit+elektronickou+adresu'
  166     4      > RETURN                                                   <false>
  170     5    >   INIT_METHOD_CALL                                         'getUrl'
          6        DO_FCALL                                      0  $5      
          7        CONCAT                                           ~6      $5, '%3Fid%3D'
          8        FETCH_OBJ_R                                      ~7      'apiKey'
          9        CONCAT                                           ~8      ~6, ~7
         10        CONCAT                                           ~9      ~8, '%26email%3D'
         11        INIT_FCALL                                               'urlencode'
         12        FETCH_OBJ_R                                      ~10     'email'
         13        SEND_VAL                                                 ~10
         14        DO_ICALL                                         $11     
         15        CONCAT                                           ~12     ~9, $11
         16        ASSIGN                                                   !0, ~12
  171    17        FETCH_OBJ_R                                      ~14     'products'
         18      > FE_RESET_R                                       $15     ~14, ->26
         19    > > FE_FETCH_R                                               $15, !1, ->26
  172    20    >   INIT_FCALL                                               'urlencode'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $16     
         23        CONCAT                                           ~17     '%26produkt%5B%5D%3D', $16
         24        ASSIGN_OP                                     8          !0, ~17
  171    25      > JMP                                                      ->19
         26    >   FE_FREE                                                  $15
  174    27        ISSET_ISEMPTY_PROP_OBJ                                   'orderId'
         28      > JMPZ                                                     ~19, ->35
  175    29    >   INIT_FCALL                                               'urlencode'
         30        FETCH_OBJ_R                                      ~20     'orderId'
         31        SEND_VAL                                                 ~20
         32        DO_ICALL                                         $21     
         33        CONCAT                                           ~22     '%26orderid%3D', $21
         34        ASSIGN_OP                                     8          !0, ~22
  179    35    >   INIT_METHOD_CALL                                         'sendRequest'
         36        SEND_VAR_EX                                              !0
         37        DO_FCALL                                      0  $24     
         38        ASSIGN                                                   !2, $24
  180    39        TYPE_CHECK                                    4          !2
         40      > JMPZ                                                     ~26, ->45
  181    41    >   ASSIGN_OBJ                                               'errstr'
         42        OP_DATA                                                  'Nepodarilo+se+odeslat+pozadavek'
  182    43      > RETURN                                                   <false>
         44*       JMP                                                      ->52
  183    45    >   IS_EQUAL                                                 !2, 'ok'
         46      > JMPZ                                                     ~28, ->49
  184    47    > > RETURN                                                   <true>
         48*       JMP                                                      ->52
  186    49    >   ASSIGN_OBJ                                               'errstr'
         50        OP_DATA                                                  !2
  187    51      > RETURN                                                   <false>
  189    52*     > RETURN                                                   null

End of function send

Function getlasterror:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBf8i
function name:  getLastError
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  197     0  E >   FETCH_OBJ_R                                      ~0      'errstr'
          1      > RETURN                                                   ~0
  198     2*     > RETURN                                                   null

End of function getlasterror

End of class HeurekaOvereno.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.53 ms | 1416 KiB | 33 Q