Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. # połącz z Allegro i sprawdź czy jest nowa wersja listy kategorii
  2. if(!isset($_POST) || count($_POST) < 1)
  3. {
  4. try {
  5. $api = new allegro($allegro);
  6. }
  7. catch(Exception $e) {
  8. $tpl->ERROR = htmlspecialchars($e->getMessage());
  9. $blad = true;
  10. }
  11. if(!$blad)
  12. {
  13. $wersja_zdalna = $api->wersjaKategorii();
  14. if(!isset($allegro['catgversion']) || $wersja_zdalna != $allegro['catgversion'] || $_GET['reload'] === '1'
  15. || !file_exists('../../cache/allegro_cat_'.$allegro['countrycode'].'.dat') || !file_exists('../../cache/allegro_idx_'.$allegro['countrycode'].'.dat'))
  16. {
  17. $paczka = 50;
  18. settype($kategorie, array());
  19. $ilosc = ceil($api->iloscKategorii() / $paczka);
  20. echo '<div id="pgrsbar">'.$LNG['m_allegro']['%UpdateProgress%'].'</div>';
  21. ob_flush();
  22. flush();
  23. for($offset=0; $offset<=$ilosc; $offset++)
  24. {
  25. $new = $api->fragmentListyKategorii($paczka, $offset);
  26. unset($kategorie['ver-key']);
  27. unset($kategorie['ver-str']);
  28. $kategorie = array_merge_recursive($kategorie, $new);
  29. }
  30. unset($new);
  31. # zapisz kategorie i zbuduj indeksy kategorii
  32. file_put_contents('../../cache/allegro_cat_'.$allegro['countrycode'].'.dat', serialize($kategorie));
  33. @chmod('../../cache/allegro_cat_'.$allegro['countrycode'].'.dat', 0666);
  34. settype($indeksy, array());
  35. foreach($kategorie['cats-list'] as $k => $v) $indeksy[$v['cat-parent']][$v['cat-position']] = $k;
  36. file_put_contents('../../cache/allegro_idx_'.$allegro['countrycode'].'.dat', serialize($indeksy));
  37. @chmod('../../cache/allegro_idx_'.$allegro['countrycode'].'.dat', 0666);
  38. # zapisz info o wersji do pliku konfiguracyjnego szablonu
  39. $dom = new DOMDocument('1.0', 'UTF-8');
  40. $dom->formatOutput = true;
  41. $dom->load($cpath.$_GET['cf'].'/config.xml');
  42. $nodes = $dom->getElementsByTagName('catgversion');
  43. if($nodes->length > 0)
  44. foreach($nodes as $node)
  45. $dom->getElementsByTagName('allegro')->item(0)->removeChild($node);
  46. $text = $dom->createTextNode($wersja_zdalna);
  47. $node = $dom->createElement('catgversion');
  48. $node->appendChild($text);
  49. $dom->getElementsByTagName('allegro')->item(0)->appendChild($node);
  50. $dom->save($cpath.$_GET['cf'].'/config.xml');
  51. }//update
  52.  
  53.  
  54. public function fragmentListyKategorii($paczka=50, $offset=0)
  55. {
  56. unset($params);
  57. $params = array(
  58. 'country-id' => $this->config['countrycode'],
  59. 'local-version' => $this->versionKey,
  60. 'webapi-key' => $this->config['webapicode'],
  61. 'package-element' => intval($paczka),
  62. 'offset' => intval($offset),
  63. );
  64. $buff = $this->SOAPclient->call('doGetCatsDataLimit', $params, 'urn:AllegroWebApi', '#catsdatalimit');
  65. if($this->SOAPclient->getError())
  66. {
  67. throw new Exception('Błąd podczas pobierania listy kategorii z Allegro: '.$this->SOAPclient->getError());
  68. return false;
  69. }
  70. return $buff;
  71. }
Add Comment
Please, Sign In to add comment