Index.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. <link rel="bookmark" type="image/x-icon" href="https://boofly.cn/favicon.ico" />
  46. <link rel="shortcut icon" type="image/x-icon" href="https://boofly.cn/favicon.ico" />'. $strBody . '<script>
  47. if (window.HTMLElement) {
  48. if (Object.getOwnPropertyNames(HTMLElement.prototype).indexOf(\'dataset\') === -1) {
  49. Object.defineProperty(HTMLElement.prototype, \'dataset\', {
  50. get: function () {
  51. var attributes = this.attributes // 获取节点的所有属性
  52. var name = []
  53. var value = [] // 定义两个数组保存属性名和属性值
  54. var obj = {} // 定义一个空对象
  55. for (var i = 0; i < attributes.length; i++) { // 遍历节点的所有属性
  56. if (attributes[i].nodeName.slice(0, 5) === \'data-\') { // 如果属性名的前面5个字符符合"data-"
  57. // 取出属性名的"data-"的后面的字符串放入name数组中
  58. name.push(attributes[i].nodeName.slice(5));
  59. // 取出对应的属性值放入value数组中
  60. value.push(attributes[i].nodeValue);
  61. }
  62. }
  63. for (var j = 0; j < name.length; j++) { // 遍历name和value数组
  64. obj[name[j]] = value[j]; // 将属性名和属性值保存到obj中
  65. }
  66. return obj // 返回对象
  67. }
  68. })
  69. }
  70. }</script></html>';
  71. $redis->set($keyDomain, $str, 60 * 60 * 3);
  72. }
  73. echo $str;
  74. }
  75. }