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 */ 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; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5WOHQ
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                                                 
  218    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/5WOHQ
function name:  HeurekaOvereno
number of ops:  7
compiled vars:  !0 = $apiKey, !1 = $languageId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   92     2        ASSIGN_OBJ                                               'apiKey'
          3        OP_DATA                                                  !0
   93     4        ASSIGN_OBJ                                               'languageId'
          5        OP_DATA                                                  !1
   94     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/5WOHQ
function name:  setEmail
number of ops:  4
compiled vars:  !0 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   RECV                                             !0      
  102     1        ASSIGN_OBJ                                               'email'
          2        OP_DATA                                                  !0
  103     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/5WOHQ
function name:  addProduct
number of ops:  5
compiled vars:  !0 = $productName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   RECV                                             !0      
  114     1        FETCH_OBJ_W                                      $1      'products'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
  115     4      > RETURN                                                   null

End of function addproduct

Function addproductitemid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5WOHQ
function name:  addProductItemId
number of ops:  5
compiled vars:  !0 = $itemId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  122     0  E >   RECV                                             !0      
  123     1        FETCH_OBJ_W                                      $1      'productsItemId'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
  124     4      > RETURN                                                   null

End of function addproductitemid

Function addorderid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5WOHQ
function name:  addOrderId
number of ops:  4
compiled vars:  !0 = $orderId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  133     0  E >   RECV                                             !0      
  134     1        ASSIGN_OBJ                                               'orderId'
          2        OP_DATA                                                  !0
  135     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/5WOHQ
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
-------------------------------------------------------------------------------------
  143     0  E >   RECV                                             !0      
  144     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
  145     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
  146    14        BOOL_NOT                                         ~13     !2
         15      > JMPZ                                                     ~13, ->23
  147    16    >   CONCAT                                           ~15     !4, '+%28'
         17        CONCAT                                           ~16     ~15, !3
         18        CONCAT                                           ~17     ~16, '%29'
         19        ASSIGN_OBJ                                               'errstr'
         20        OP_DATA                                                  ~17
  148    21      > RETURN                                                   <false>
         22*       JMP                                                      ->69
  150    23    >   ASSIGN                                                   !5, ''
  151    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'
  152    30        CONCAT                                           ~25     ~24, 'Host%3A+'
         31        FETCH_DIM_R                                      ~26     !1, 'host'
         32        CONCAT                                           ~27     ~25, ~26
         33        CONCAT                                           ~28     ~27, '%0D%0A'
  153    34        CONCAT                                           ~29     ~28, 'Connection%3A+Close%0D%0A%0D%0A'
  151    35        ASSIGN                                                   !6, ~29
  154    36        INIT_FCALL                                               'fputs'
         37        SEND_VAR                                                 !2
         38        SEND_VAR                                                 !6
         39        DO_ICALL                                                 
  155    40      > JMP                                                      ->46
  156    41    >   INIT_FCALL                                               'fgets'
         42        SEND_VAR                                                 !2
         43        SEND_VAL                                                 128
         44        DO_ICALL                                         $32     
         45        ASSIGN_OP                                     8          !5, $32
  155    46    >   INIT_FCALL                                               'feof'
         47        SEND_VAR                                                 !2
         48        DO_ICALL                                         $34     
         49        BOOL_NOT                                         ~35     $34
         50      > JMPNZ                                                    ~35, ->41
  158    51    >   INIT_FCALL                                               'fclose'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                                 
  159    54        INIT_FCALL                                               'explode'
         55        SEND_VAL                                                 '%0D%0A%0D%0A'
         56        SEND_VAR                                                 !5
         57        DO_ICALL                                         $37     
         58        ASSIGN                                                   !7, $37
  161    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
  163    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/5WOHQ
function name:  getUrl
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  171     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
  172    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 = 77) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 36
Branch analysis from position: 26
filename:       /in/5WOHQ
function name:  send
number of ops:  63
compiled vars:  !0 = $url, !1 = $product, !2 = $itemId, !3 = $contents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  180     0  E >   ISSET_ISEMPTY_PROP_OBJ                                   'email'
          1      > JMPZ                                                     ~4, ->5
  181     2    >   ASSIGN_OBJ                                               'errstr'
          3        OP_DATA                                                  'Je+nutn%C3%A9+vyplnit+elektronickou+adresu'
  182     4      > RETURN                                                   <false>
  186     5    >   INIT_METHOD_CALL                                         'getUrl'
          6        DO_FCALL                                      0  $6      
          7        CONCAT                                           ~7      $6, '%3Fid%3D'
          8        FETCH_OBJ_R                                      ~8      'apiKey'
          9        CONCAT                                           ~9      ~7, ~8
         10        CONCAT                                           ~10     ~9, '%26email%3D'
         11        INIT_FCALL                                               'urlencode'
         12        FETCH_OBJ_R                                      ~11     'email'
         13        SEND_VAL                                                 ~11
         14        DO_ICALL                                         $12     
         15        CONCAT                                           ~13     ~10, $12
         16        ASSIGN                                                   !0, ~13
  187    17        FETCH_OBJ_R                                      ~15     'products'
         18      > FE_RESET_R                                       $16     ~15, ->26
         19    > > FE_FETCH_R                                               $16, !1, ->26
  188    20    >   INIT_FCALL                                               'urlencode'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $17     
         23        CONCAT                                           ~18     '%26produkt%5B%5D%3D', $17
         24        ASSIGN_OP                                     8          !0, ~18
  187    25      > JMP                                                      ->19
         26    >   FE_FREE                                                  $16
  190    27        FETCH_OBJ_R                                      ~20     'productsItemId'
         28      > FE_RESET_R                                       $21     ~20, ->36
         29    > > FE_FETCH_R                                               $21, !2, ->36
  191    30    >   INIT_FCALL                                               'urlencode'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $22     
         33        CONCAT                                           ~23     '%26itemId%5B%5D%3D', $22
         34        ASSIGN_OP                                     8          !0, ~23
  190    35      > JMP                                                      ->29
         36    >   FE_FREE                                                  $21
  193    37        ISSET_ISEMPTY_PROP_OBJ                                   'orderId'
         38      > JMPZ                                                     ~25, ->45
  194    39    >   INIT_FCALL                                               'urlencode'
         40        FETCH_OBJ_R                                      ~26     'orderId'
         41        SEND_VAL                                                 ~26
         42        DO_ICALL                                         $27     
         43        CONCAT                                           ~28     '%26orderid%3D', $27
         44        ASSIGN_OP                                     8          !0, ~28
  198    45    >   INIT_METHOD_CALL                                         'sendRequest'
         46        SEND_VAR_EX                                              !0
         47        DO_FCALL                                      0  $30     
         48        ASSIGN                                                   !3, $30
  199    49        TYPE_CHECK                                    4          !3
         50      > JMPZ                                                     ~32, ->55
  200    51    >   ASSIGN_OBJ                                               'errstr'
         52        OP_DATA                                                  'Nepodarilo+se+odeslat+pozadavek'
  201    53      > RETURN                                                   <false>
         54*       JMP                                                      ->62
  202    55    >   IS_EQUAL                                                 !3, 'ok'
         56      > JMPZ                                                     ~34, ->59
  203    57    > > RETURN                                                   <true>
         58*       JMP                                                      ->62
  205    59    >   ASSIGN_OBJ                                               'errstr'
         60        OP_DATA                                                  !3
  206    61      > RETURN                                                   <false>
  208    62*     > 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/5WOHQ
function name:  getLastError
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  216     0  E >   FETCH_OBJ_R                                      ~0      'errstr'
          1      > RETURN                                                   ~0
  217     2*     > RETURN                                                   null

End of function getlasterror

End of class HeurekaOvereno.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.55 ms | 1416 KiB | 33 Q