Index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace addons\nkeditor\controller;
  3. use app\common\model\Attachment;
  4. use GuzzleHttp\Client;
  5. use think\addons\Controller;
  6. class Index extends Controller
  7. {
  8. public function index()
  9. {
  10. $this->error('该插件暂无前台页面');
  11. }
  12. /**
  13. * 文件列表
  14. */
  15. public function attachment()
  16. {
  17. $model = new Attachment;
  18. $page = $this->request->request('page');
  19. $fileType = $this->request->request('fileType');
  20. $module = $this->request->param('module');
  21. $pagesize = 15;
  22. $config = get_addon_config('nkeditor');
  23. $type = [];
  24. $imageSuffix = ['png', 'jpg', 'jpeg', 'gif', 'bmp'];
  25. if ($fileType == 'image') {
  26. $type = $imageSuffix;
  27. } else if ($fileType == 'flash') {
  28. $type = ['swf', 'flv'];
  29. } else if ($fileType == 'media') {
  30. $type = ['swf', 'flv'];
  31. } else if ($fileType == 'file') {
  32. }
  33. if ($module == 'admin') {
  34. $auth = \app\admin\library\Auth::instance();
  35. if (!$auth->id) {
  36. $this->error('请登录后再操作!');
  37. } else {
  38. $mode = $config['attachmentmode_admin'];
  39. }
  40. if ($mode == 'all') {
  41. } else {
  42. if (!$auth->isSuperAdmin()) {
  43. $adminIds = $mode == 'auth' ? $auth->getChildrenAdminIds(true) : [$auth->id];
  44. $model->where('admin_id', 'in', $adminIds);
  45. }
  46. }
  47. } else {
  48. if (!$this->auth->id) {
  49. $this->error('请登录后再操作!');
  50. } else {
  51. $mode = $config['attachmentmode_index'];
  52. }
  53. if ($mode == 'all') {
  54. } else {
  55. $model->where('user_id', 'in', [$this->auth->id]);
  56. }
  57. }
  58. if ($type) {
  59. $model->where('imagetype', 'in', $type);
  60. }
  61. $list = $model
  62. ->order('id', 'desc')
  63. ->paginate($pagesize);
  64. $items = $list->items();
  65. $data = [];
  66. $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
  67. foreach ($items as $k => &$v) {
  68. $v['fullurl'] = $v['storage'] == 'local' ? $cdnurl . $v['url'] : cdnurl($v['url']);
  69. $v['imagetype'] = strtolower($v['imagetype']);
  70. $data[] = [
  71. 'width' => $v['imagewidth'],
  72. 'height' => $v['imageheight'],
  73. 'filesize' => $v['filesize'],
  74. 'oriURL' => $v['fullurl'],
  75. 'thumbURL' => !in_array($v['imagetype'], $imageSuffix) ? "https://tool.fastadmin.net/icon/{$v['imagetype']}.png" : $v['fullurl'],
  76. ];
  77. }
  78. $result = [
  79. 'code' => '000',
  80. 'count' => $list->total(),
  81. 'page' => $page,
  82. 'pagesize' => $pagesize,
  83. 'extra' => '',
  84. 'data' => $data
  85. ];
  86. return json($result);
  87. }
  88. public function download()
  89. {
  90. $url = $this->request->request("url");
  91. $client = new Client();
  92. $response = $client->get($url, ['verify' => false]);
  93. return $response->getBody();
  94. }
  95. }