Skrypty statystyk Listy Dyskusyjnej Mandragoratu Wandystanu https://wandystan.eu/statistics/doc/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

54 wiersze
1.9 KiB

  1. <?php
  2. /*
  3. * Common functions and definitions
  4. * Copyright (C) 2020 Polyna <https://wandystan.eu/B196>
  5. *
  6. * This file is part of LDMW statistical scripts.
  7. *
  8. * LDMW statistical scripts are free software: you can redistribute them
  9. * and/or modify them under the terms of the GNU Affero General Public
  10. * License as published by the Free Software Foundation, either version 3
  11. * of the License, or (at your option) any later version.
  12. *
  13. * LDMW statistical scripts are distributed in the hope that they will be
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with LDMW statistical scripts. If not, see
  20. * <https://www.gnu.org/licenses/>.
  21. */
  22. define('REGEXP_ISO8601_DATE', '\d{4}(-\d{2}|-?(\d{2}-?\d{2}|W\d{2}(-\d)?|\d{3}))');
  23. define('REGEXP_ISO8601_INTERVAL', 'P(\d+Y(\d+M)?(\d+D)?|\d+M(\d+D)?|\d+[DW])');
  24. define('REGEXP_ISO8601_DATE_OR_INTERVAL', '(' . REGEXP_ISO8601_DATE . '|' . REGEXP_ISO8601_INTERVAL . ')');
  25. function exit_error($message) {
  26. http_response_code(500);
  27. header('Content-type: text/plain; charset=utf-8');
  28. print 'ERROR: ' . $message . PHP_EOL;
  29. exit;
  30. }
  31. function exit_error_handler($exception) {
  32. exit_error($exception->getMessage());
  33. }
  34. set_exception_handler('exit_error_handler');
  35. function load_remote_dom_document($uri) {
  36. $content = file_get_contents($uri);
  37. $document = new DOMDocument;
  38. if ($content === false)
  39. throw new Exception("Cannot load remote URI: $uri");
  40. if (! $document->loadHTML($content, LIBXML_NOWARNING | LIBXML_NOERROR))
  41. throw new Exception("Cannot parse remote URI as HTML: $uri");
  42. return $document;
  43. }
  44. function starts_with($haystack, $needle) {
  45. return substr_compare($haystack, $needle, 0, strlen($needle)) === 0;
  46. }