Index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: TABLE ME
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-25 17:23
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\home\controller;
  13. use app\BaseController;
  14. use app\BaseViewController;
  15. use app\model\api\Site;
  16. use app\model\Api\SiteProduct;
  17. use app\model\system\Sys;
  18. use app\Request;
  19. use library\services\UtilService;
  20. use library\utils\AdvertUtils;
  21. use library\utils\Icon;
  22. use think\Cache;
  23. class Index extends BaseViewController
  24. {
  25. private $version = '1.0';
  26. public function index(Request $request){
  27. $domain = $request->domain();
  28. $redis = \think\facade\Cache::store('redis');
  29. $keyDomain = md5($domain . $this->version);
  30. $content = $redis->get($keyDomain);
  31. if(!empty($content)){
  32. return $content;
  33. } else {
  34. $strBody = '';
  35. $txt = file_get_contents(app()->getRootPath() . 'public/index.html');
  36. preg_match('/\<link(.*?)<\/body>/is', $txt, $match);
  37. if (!empty($match[0])) {
  38. $strBody = $match[0];
  39. }
  40. $str = '<!DOCTYPE html><html><head>
  41. <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
  42. <title>星选联盟</title>
  43. <meta name="keywords" content="星选联盟">
  44. <meta name="description" content="星选联盟">
  45. <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  46. <link rel="bookmark" type="image/x-icon" href="https://www.boofly.cn/favicon/favicon.ico" />
  47. <link rel="shortcut icon" type="image/x-icon" href="https://www.boofly.cn/favicon/favicon.ico" />'. $strBody . '<script>
  48. if (window.HTMLElement) {
  49. if (Object.getOwnPropertyNames(HTMLElement.prototype).indexOf(\'dataset\') === -1) {
  50. Object.defineProperty(HTMLElement.prototype, \'dataset\', {
  51. get: function () {
  52. var attributes = this.attributes // 获取节点的所有属性
  53. var name = []
  54. var value = [] // 定义两个数组保存属性名和属性值
  55. var obj = {} // 定义一个空对象
  56. for (var i = 0; i < attributes.length; i++) { // 遍历节点的所有属性
  57. if (attributes[i].nodeName.slice(0, 5) === \'data-\') { // 如果属性名的前面5个字符符合"data-"
  58. // 取出属性名的"data-"的后面的字符串放入name数组中
  59. name.push(attributes[i].nodeName.slice(5));
  60. // 取出对应的属性值放入value数组中
  61. value.push(attributes[i].nodeValue);
  62. }
  63. }
  64. for (var j = 0; j < name.length; j++) { // 遍历name和value数组
  65. obj[name[j]] = value[j]; // 将属性名和属性值保存到obj中
  66. }
  67. return obj // 返回对象
  68. }
  69. })
  70. }
  71. }</script></html>';
  72. $redis->set($keyDomain, $str, 60 * 60 * 3);
  73. }
  74. echo $str;
  75. }
  76. }