Index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\CardModel;
  5. use app\model\SettingModel;
  6. use Cassandra\Set;
  7. use think\facade\View;
  8. use think\Request;
  9. class Index extends BaseController
  10. {
  11. function index(Request $request, $s = ''): string
  12. {
  13. $title = SettingModel::Config('title', 'Mtab书签');
  14. View::assign("title", $title);
  15. View::assign("keywords", SettingModel::Config('keywords', 'Mtab书签'));
  16. View::assign("description", SettingModel::Config('description', 'Mtab书签'));
  17. View::assign("version", app_version);
  18. $customHead = SettingModel::Config('customHead', '');
  19. if (SettingModel::Config('pwa', 0) == '1') {
  20. $customHead .= '<link rel="manifest" href="/manifest.json">';
  21. }
  22. View::assign("customHead", $customHead);
  23. View::assign("favicon", SettingModel::Config('favicon', SettingModel::Config('logo', '/favicon.ico')));
  24. return View::fetch("dist/index.html");
  25. }
  26. function all(): \think\response\Json
  27. {
  28. $app = app();
  29. $ids = $this->request->post("ids", []);
  30. $dt = [];
  31. if (!in_array("link", $ids)) {
  32. $dt['link'] = (new Link($app))->get()->getData()['data'];
  33. }
  34. if (!in_array("tabbar", $ids)) {
  35. $dt['tabbar'] = (new Tabbar($app))->get()->getData()['data'];
  36. }
  37. if (!in_array("config", $ids)) {
  38. $dt['config'] = (new Config($app))->get()->getData()['data'];
  39. }
  40. $card = CardModel::where("status", 1)->field('name_en,status')->select()->toArray();
  41. $dt['card'] = $card;
  42. $dt['site'] = (new Api($app))->site()->getData()['data'];
  43. return $this->success("ok", $dt);
  44. }
  45. function privacy(): string
  46. {
  47. $content = $this->systemSetting("privacy", "");
  48. return View::fetch('/privacy', ['content' => $content, 'title' => $this->systemSetting("title", ''), 'logo' => $this->systemSetting('logo', '')]);
  49. }
  50. function favicon()
  51. {
  52. //从配置中获取logo
  53. $favicon = $this->systemSetting('logo');
  54. $file = public_path() . $favicon;
  55. if (file_exists($file) && is_file($file)) {
  56. return download($file)->mimeType(\PluginStaticSystem::mimeType($file))->force(false)->expire(60 * 60 * 24);
  57. }
  58. return redirect("/static/mtab.png");
  59. }
  60. function manifest(): \think\response\Json
  61. {
  62. $manifest = [
  63. 'name' => SettingModel::Config('title', 'Mtab书签'),
  64. 'short_name' => SettingModel::Config('title', 'Mtab书签'),
  65. 'description' => SettingModel::Config('description', 'Mtab书签'),
  66. 'manifest_version' => 2,
  67. 'version' => app_version,
  68. 'theme_color' => SettingModel::Config('theme_color', '#141414'),
  69. 'icons' => [
  70. [
  71. 'src' => SettingModel::Config('favicon', SettingModel::Config('logo', '/favicon.ico')),
  72. 'sizes' => '144x144'
  73. ]
  74. ],
  75. 'display' => 'standalone',
  76. 'orientation' => 'portrait',
  77. 'start_url' => '/',
  78. 'scope' => '/',
  79. 'permissions' => [
  80. 'geolocation',
  81. 'notifications'
  82. ]
  83. ];
  84. return json($manifest);
  85. }
  86. }