Loginbg.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 后台登录背景图插件
  13. // +----------------------------------------------------------------------
  14. namespace addons\loginbg;
  15. use think\Addons;
  16. class Loginbg extends Addons
  17. {
  18. //安装
  19. public function install()
  20. {
  21. return true;
  22. }
  23. //卸载
  24. public function uninstall()
  25. {
  26. return true;
  27. }
  28. public function adminLoginStyle()
  29. {
  30. $config = $this->getAddonConfig();
  31. if ($config['mode'] == 'random' || $config['mode'] == 'daily') {
  32. $gettime = $config['mode'] == 'random' ? mt_rand(-1, 7) : 0;
  33. $json_string = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=' . $gettime . '&n=1');
  34. $data = json_decode($json_string);
  35. $background = "https://www.bing.com" . $data->{"images"}[0]->{"urlbase"} . "_1920x1080.jpg";
  36. } else {
  37. $background = $config['pic'];
  38. }
  39. $this->assign('background', $background);
  40. return $this->fetch('loginbg');
  41. }
  42. }