Index.php 3.2 KB

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