remote.ctrl.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. load()->func('communication');
  7. load()->model('attachment');
  8. $dos = array('display', 'save', 'test_setting', 'upload_remote');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. $_W['page']['title'] = '远程附件 - 公众号选项';
  11. $remote = $_W['setting']['remote_complete_info'][$_W['uniacid']];
  12. if ($do == 'upload_remote') {
  13. if (!empty($_W['setting']['remote_complete_info'][$_W['uniacid']]['type'])) {
  14. $result = file_dir_remote_upload(ATTACHMENT_ROOT . 'images/' . $_W['uniacid']);
  15. if (is_error($result)) {
  16. itoast($result['message'], url('profile/remote'), 'info');
  17. } else {
  18. itoast('上传成功!', url('profile/remote'), 'success');
  19. }
  20. } else {
  21. itoast('请先填写并开启远程附件设置。', '', 'info');
  22. }
  23. }
  24. if ($do == 'display') {
  25. $safe_path = safe_gpc_path(IA_ROOT . '/attachment/images/' . $_W['uniacid']);
  26. if (!empty($safe_path)) {
  27. $local_attachment = file_tree($safe_path);
  28. foreach ($local_attachment as $key => $attachment) {
  29. if (!file_is_image($attachment)) {
  30. unset($local_attachment[$key]);
  31. }
  32. }
  33. unset($attachment);
  34. } else {
  35. $local_attachment = array();
  36. }
  37. }
  38. if ($do == 'save'){
  39. $remote_data = array(
  40. 'type' => $_GPC['type'],
  41. 'qiniu' => array(
  42. 'accesskey' => $_GPC['qiniu']['accesskey'],
  43. 'secretkey' => strexists($_GPC['qiniu']['secretkey'], '*') ? $remote['qiniu']['secretkey'] : trim($_GPC['qiniu']['secretkey']),
  44. 'bucket' => $_GPC['qiniu']['bucket'],
  45. 'url' => $_GPC['qiniu']['url'],
  46. )
  47. );
  48. if ($remote_data['type'] == ATTACH_QINIU) {
  49. if (empty($remote_data['qiniu']['accesskey'])) {
  50. itoast ('请填写Accesskey', referer (), 'info');
  51. }
  52. if (empty($remote_data['qiniu']['secretkey'])) {
  53. itoast ('secretkey', referer (), 'info');
  54. }
  55. if (empty($remote_data['qiniu']['bucket'])) {
  56. itoast ('请填写bucket', referer (), 'info');
  57. }
  58. if (empty($remote_data['qiniu']['url'])) {
  59. itoast ('请填写url', referer (), 'info');
  60. } else {
  61. $remote_data['qiniu']['url'] = strexists ($remote_data['qiniu']['url'], 'http') ? trim ($remote_data['qiniu']['url'], '/') : 'http://' . trim ($remote_data['qiniu']['url'], '/');
  62. }
  63. $auth = attachment_qiniu_auth ($remote_data['qiniu']['accesskey'], $remote_data['qiniu']['secretkey'], $remote_data['qiniu']['bucket']);
  64. if (is_error ($auth)) {
  65. $message = $auth['message']['error'] == 'bad token' ? 'Accesskey或Secretkey填写错误, 请检查后重新提交' : 'bucket填写错误或是bucket所对应的存储区域选择错误,请检查后重新提交';
  66. itoast ($message, referer (), 'info');
  67. }
  68. }
  69. $_W['setting']['remote_complete_info'][$_W['uniacid']] = $remote_data;
  70. setting_save($_W['setting']['remote_complete_info'], 'remote');
  71. itoast('保存成功', '', 'success');
  72. }
  73. if ($do == 'test_setting') {
  74. $type = $_GPC['type'];
  75. if ($type == ATTACH_QINIU) {
  76. $_GPC['secretkey'] = strexists($_GPC['secretkey'], '*') ? $remote['qiniu']['secretkey'] : $_GPC['secretkey'];
  77. $auth= attachment_qiniu_auth(trim($_GPC['accesskey']), trim($_GPC['secretkey']), trim($_GPC['bucket']));
  78. if (is_error($auth)) {
  79. iajax(-1, '配置失败,请检查配置。注:请检查存储区域是否选择的是和bucket对应<br/>的区域', '');
  80. }
  81. $url = $_GPC['url'];
  82. $url = strexists($url, 'http') ? trim($url, '/') : 'http://'.trim($url, '/');
  83. $filename = 'MicroEngine.ico';
  84. $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
  85. if (is_error($response)) {
  86. iajax(-1, '配置失败,七牛访问url错误');
  87. }
  88. if (intval($response['code']) != 200) {
  89. iajax(-1, '配置失败,七牛访问url错误,请保证bucket为公共读取的');
  90. }
  91. $image = getimagesizefromstring($response['content']);
  92. if (!empty($image) && strexists($image['mime'], 'image')) {
  93. iajax(0,'配置成功');
  94. } else {
  95. iajax(-1, '配置失败,七牛访问url错误');
  96. }
  97. }
  98. }
  99. template('profile/remote');