utils.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. require_once __DIR__ . '/project.php';
  3. require_once __DIR__ . '/config.php';
  4. require_once __DIR__ . '/user_settings.php';
  5. require_once __DIR__ . '/api.php';
  6. require_once __DIR__ . '/page_structure.php';
  7. load_settings($_COOKIE);
  8. require_once __DIR__ . '/lang/' . $settings['language'] . '.php';
  9. function get_string($path) {
  10. global $strings;
  11. $pointer = &$strings;
  12. $levels = explode('.', $path);
  13. foreach ($levels as $level) {
  14. if (!isset($pointer[$level])) return false;
  15. $pointer = &$pointer[$level];
  16. }
  17. return $pointer;
  18. }
  19. function get_proxy_url($url) {
  20. return BASE_URL . '/proxy/' . substr($url, 8);
  21. }
  22. function get_closest_mode() {
  23. global $settings;
  24. if (
  25. $settings['show-r15'] == 'on'
  26. && ($settings['show-r18'] == 'on' || $settings['show-r18g'] == 'on')
  27. ) return 'all';
  28. return 'safe';
  29. }
  30. function get_xrestrict_string($xRestrict) {
  31. return [false, 'R-18' , 'R-18G'][$xRestrict];
  32. }
  33. function artwork_is_hidden($artwork) {
  34. global $settings;
  35. if ($artwork->sl >= 4 && (SSFW_ONLY || $settings['show-r15'] == 'off')) return 'r15';
  36. else if ($artwork->xRestrict == 1 && (SFW_ONLY || $settings['show-r18'] == 'off')) return 'r18';
  37. else if ($artwork->xRestrict == 2 && (SFW_ONLY || $settings['show-r18g'] == 'off')) return 'r18g';
  38. else if ($artwork->aiType == 2 && $settings['show-aigc'] == 'off') return 'aigc';
  39. return false;
  40. }
  41. function die_with_message($status_code, $message) {
  42. http_response_code($status_code);
  43. $title = get_string('error');
  44. render_page_header($title); ?>
  45. <div class="container container-small center">
  46. <h1><?= $title ?></h1>
  47. <p><?= $message ?></p>
  48. </div><?php
  49. render_page_footer();
  50. die;
  51. }
  52. function render_collapsed_content($page_count, $button_text, callable $render_page) {
  53. for ($page = 0; $page < $page_count; $page ++) {
  54. if ($page > 0) echo '<details class="collapsed"><summary>' . $button_text .'</summary>';
  55. call_user_func($render_page, $page);
  56. }
  57. echo str_repeat('</details>', $page_count - 1);
  58. }
  59. function format_date($date_string, $timezone = 'UTC') {
  60. global $settings;
  61. $date = new DateTime($date_string, new DateTimeZone($timezone));
  62. $date->setTimezone(new DateTimeZone($settings['timezone']));
  63. return $date->format(get_string('date-format'));
  64. }