function.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. $IMAGE_VERIFICATION = true;
  3. function pdoConnect()
  4. {
  5. return new PDO('mysql:host=' . $GLOBALS['DB_HOST'] . ';dbname=' . $GLOBALS['DB_NAME'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASS']);
  6. }
  7. function get_http_type()
  8. {
  9. $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  10. return $http_type;
  11. }
  12. function titleChange()
  13. {
  14. $title = '';
  15. if (!empty(getInfo($_GET['page']))) $title = getInfo($_GET['page']) . ' - ';
  16. $title = $title . getInfo('title');
  17. return '<script>$(document).attr("title","' . $title . '");</script>';
  18. }
  19. function listActive($pageName)
  20. {
  21. ?>
  22. <script>
  23. pageArr = ['homePage', 'submitPage', 'morePage', 'aboutPage'];
  24. for (let i = 0; i < pageArr.length; i++) {
  25. if ($("#" + pageArr[i]).hasClass("mdui-list-item-active")) {
  26. $("#" + pageArr[i]).removeClass("mdui-list-item-active");
  27. }
  28. }
  29. $("#<?php echo $pageName; ?>Page").addClass("mdui-list-item-active");
  30. </script>
  31. <?php
  32. }
  33. function getInfo($name)
  34. {
  35. try {
  36. $pdo = pdoConnect();
  37. $stmt = $pdo->prepare("select * from loveway_config where name = ?");
  38. $stmt->bindValue(1, $name);
  39. if ($stmt->execute()) {
  40. $rows = $stmt->fetchAll();
  41. return $rows[0]['value'];
  42. } else {
  43. return 'database connection failed';
  44. }
  45. } catch (Exception $e) {
  46. include('./pages/err.php');
  47. //echo $e->getMessage();
  48. }
  49. }
  50. function hideSomethings()
  51. {
  52. ?>
  53. <script>
  54. $('#appbar').css('display', 'none');
  55. $('#main-drawer').css('display', 'none');
  56. setTimeout(function() {
  57. inst.close();
  58. }, 50);
  59. </script>
  60. <?php
  61. }
  62. ?>