Index.php 3.0 KB

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