You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

994 lines
43 KiB

  1. <?php
  2. /*
  3. * @copyright Leyun internet Technology(Shanghai)Co.,Ltd
  4. * @license http://www.dzzoffice.com/licenses/license.txt
  5. * @package DzzOffice
  6. * @link http://www.dzzoffice.com
  7. * @author zyx(zyx@dzz.cc)
  8. */
  9. if (!defined('IN_DZZ')) {
  10. exit('Access Denied');
  11. }
  12. global $_G;
  13. $uid = $_G['uid'];
  14. $operation = isset($_GET['operation']) ? trim($_GET['operation']) : '';
  15. if ($operation == 'upload') {//上传图片文件
  16. include libfile('class/uploadhandler');
  17. $options = array('accept_file_types' => '/\.(gif|jpe?g|png)$/i',
  18. 'upload_dir' => $_G['setting']['attachdir'] . 'cache/',
  19. 'upload_url' => $_G['setting']['attachurl'] . 'cache/',
  20. 'thumbnail' => array('max-width' => 40, 'max-height' => 40));
  21. $upload_handler = new uploadhandler($options);
  22. exit();
  23. } elseif ($operation == 'uploads') {//上传新文件(指新建)
  24. $container = trim($_GET['container']);
  25. $space = dzzgetspace($uid);
  26. $space['self'] = intval($space['self']);
  27. $bz = isset($_GET['bz']) ? trim($_GET['bz']) : '';
  28. require_once dzz_libfile('class/UploadHandler');
  29. //上传类型
  30. $allowedExtensions = $space['attachextensions'] ? explode(',', $space['attachextensions']) : array();
  31. $sizeLimit = ($space['maxattachsize']);
  32. $options = array('accept_file_types' => $allowedExtensions ? ("/(\.|\/)(" . implode('|', $allowedExtensions) . ")$/i") : "/.+$/i",
  33. 'max_file_size' => $sizeLimit ? $sizeLimit : null,
  34. 'upload_dir' => $_G['setting']['attachdir'] . 'cache/',
  35. 'upload_url' => $_G['setting']['attachurl'] . 'cache/',
  36. );
  37. $upload_handler = new UploadHandler($options);
  38. exit();
  39. } elseif ($operation == 'uploadfiles') {//上传文件(单纯的上传)
  40. $space = dzzgetspace($uid);
  41. $space['self'] = intval($space['self']);
  42. require_once libfile('class/uploadhandler', '', 'core');
  43. //上传类型
  44. $allowedExtensions = $space['attachextensions'] ? explode(',', $space['attachextensions']) : array();
  45. $sizeLimit = ($space['maxattachsize']);
  46. $options = array('accept_file_types' => $allowedExtensions ? ("/(\.|\/)(" . implode('|', $allowedExtensions) . ")$/i") : "/.+$/i",
  47. 'max_file_size' => $sizeLimit ? $sizeLimit : null,
  48. 'upload_dir' => $_G['setting']['attachdir'] . 'cache/',
  49. 'upload_url' => $_G['setting']['attachurl'] . 'cache/',
  50. );
  51. $upload_handler = new UploadHandler($options);
  52. exit();
  53. } elseif ($operation == 'app') {
  54. $applist = $_GET['data'];
  55. //获取已安装应用
  56. $app = C::t('app_market')->fetch_all_by_appid($applist);
  57. $applist_1 = array();
  58. foreach ($app as $key => $value) {
  59. if ($value['isshow'] < 1) continue;
  60. if ($value['available'] < 1) continue;
  61. if ($value['system'] == 2) continue;
  62. $applist_1[$key] = $value;
  63. }
  64. exit(json_encode($applist_1));
  65. } elseif ($operation == 'selectperm') {
  66. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : '';
  67. $gid = isset($_GET['gid']) ? intval($_GET['gid']) : '';
  68. $inherit = true;//是否允许继承上级权限
  69. //如果是顶级群组的文件夹权限不允许继承上级权限
  70. if ($gid && $orginfo = C::t('organization')->fetch($gid)) {
  71. if ($fid == $orginfo['fid']) {
  72. $inherit = false;
  73. } else {
  74. $folderinfo = C::t('folder')->fetch($fid);
  75. $inheritperm = DB::result_first("select perm from %t where fid = %d", array('folder', $folderinfo['pfid']));
  76. }
  77. } else {
  78. $folderinfo = C::t('folder')->fetch($fid);
  79. }
  80. //是否是新建权限
  81. $new = (isset($_GET['new']) && $_GET['new']) ? 1 : 0;
  82. $setting = (isset($_GET['setting']) && $_GET['setting']) ? 1 : 0;
  83. //获取权限
  84. $groupperm = intval(C::t('folder')->fetch_perm_by_fid($fid));
  85. //获取权限组
  86. $permgroups = C::t('resources_permgroup')->fetch_all();
  87. $perms = get_permsarray();//获取所有权限
  88. //设置权限
  89. if (isset($_GET['permsubmit']) && $_GET['permsubmit']) {
  90. $perms = isset($_GET['selectperm']) ? $_GET['selectperm'] : array();
  91. $perm = 0;
  92. if (!empty($perms)) {
  93. foreach ($perms as $v) {
  94. $perm += intval($v);
  95. }
  96. $perm += 1;
  97. }
  98. if ($perm == $groupperm) exit(json_encode(array('success' => true)));
  99. if (!$inherit && !$perm) exit(json_encode(array('error' => true)));
  100. $fid = intval($_GET['fid']);
  101. if (C::t('folder')->update($fid, array('perm' => $perm))) {
  102. //如果是编辑权限,增加相关事件
  103. if (!$new) {
  104. //增加群组事件
  105. if ($orginfo && !$inherit) {
  106. $eventdata = array('username' => getglobal('username'), 'uid' => getglobal('uid'), 'folder' => $orginfo['orgname']);
  107. C::t('resources_event')->addevent_by_pfid($fid, 'set_group_perm', 'setperm', $eventdata, $gid, '', $orginfo['orgname']);
  108. } else {//增加文件夹事件
  109. $rid = C::t('resources')->fetch_rid_by_fid($fid);
  110. $path = C::t('resources_path')->fetch_pathby_pfid($fid);
  111. $realpath = preg_replace('/dzz:(.+?):/', '', $path);
  112. $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($fid, $gid);
  113. $eventdata = array('username' => getglobal('username'), 'uid' => getglobal('uid'), 'position' => $realpath, 'hash' => $hash);
  114. C::t('resources_event')->addevent_by_pfid($fid, 'set_folder_perm', 'setperm', $eventdata, $gid, $rid, $folderinfo['fname']);
  115. }
  116. }
  117. exit(json_encode(array('success' => true, 'perm' => $perm)));
  118. } else {
  119. exit(json_encode(array('error' => true)));
  120. }
  121. }
  122. } elseif ($operation == 'addgroup') {//添加群组
  123. if (isset($_GET['arr'])) {
  124. $arr = $_GET['arr'];
  125. $groupname = isset($arr['orgname']) ? getstr($arr['orgname']) : '';
  126. $img = isset($arr['aid']) ? trim($arr['aid']) : '';
  127. $groupmemorysetting = getglobal('groupmemorySpace', 'setting');
  128. //if (!$img) exit(json_encode(array('error' => true, 'msg' => '请选择或者上传一张图片,作为群组头像', 'pos' => 'img')));
  129. if (preg_match('/^\s*$/', $groupname)) exit(json_encode(array('error' => true, 'msg' => '群组名不能为空', 'pos' => 'name')));
  130. if (!C::t('organization')->chk_by_orgname($groupname, 1)) showTips(array('error' => true, 'msg' => '群组名已被占用', 'pos' => 'name'), 'json');
  131. $setarr = array(
  132. 'orgname' => $groupname,
  133. 'aid' => $img,
  134. 'desc' => htmlspecialchars(trim($arr['desc'])),
  135. 'type' => 1,
  136. 'dateline' => TIMESTAMP,
  137. 'maxspacesize' => $groupmemorysetting,
  138. 'manageon' => 1,
  139. 'diron' => 1
  140. );
  141. if ($return = C::t('organization')->insert_by_orgid($setarr)) {
  142. if ($return) exit(json_encode(array('success' => true, 'gid' => $return)));
  143. else exit(json_encode(array('error' => true, 'msg' => lang('create_group_failed'))));
  144. } else {
  145. exit(json_encode(array('error' => true)));
  146. }
  147. }
  148. } elseif ($operation == 'newFolder') {//新建文件夹
  149. $fid = isset($_GET['fid']) ? trim($_GET['fid']) : '';
  150. $bz = isset($_GET['bz']) ? trim($_GET['bz']) : '';
  151. $folderinfo = C::t('folder')->fetch($fid);
  152. $noperm = 1;
  153. if ($folderinfo['gid'] && C::t('organization_admin')->chk_memberperm($folderinfo['gid'])) {
  154. $noperm = 0;
  155. $inheritperm = DB::result_first("select perm from %t where fid = %d", array('folder', $fid));
  156. }
  157. $name = !empty($_GET['foldername']) ? trim($_GET['foldername']) : lang('newfolder');
  158. if (isset($_GET['createfolder'])) {
  159. $perm = 0;
  160. $fname = IO::name_filter(getstr($name, 80));
  161. if ($bz) {
  162. $fid = $bz;
  163. } else {
  164. $fid = intval($fid);
  165. $perms = isset($_GET['selectperm']) ? $_GET['selectperm'] : array();
  166. if (!empty($perms) && $perms) {
  167. foreach ($perms as $v) {
  168. $perm += intval($v);
  169. }
  170. $perm += 1;
  171. }
  172. }
  173. if ($arr = IO::CreateFolder($fid, $fname, $perm)) {
  174. if ($arr['error']) {
  175. } else {
  176. $arr = array_merge($arr['icoarr'], $arr['folderarr']);
  177. $arr['msg'] = 'success';
  178. }
  179. } else {
  180. $arr = array();
  181. $arr['error'] = lang('failure_newfolder');
  182. }
  183. exit(json_encode($arr));
  184. } else {
  185. $permgroups = C::t('resources_permgroup')->fetch_all(true);
  186. $perms = get_permsarray();//获取所有权限
  187. $permselect = true;
  188. }
  189. } elseif ($operation == 'newLink') {//新建连接
  190. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : '';
  191. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  192. $arr = array('error' => lang('no_privilege'));
  193. }
  194. } elseif ($operation == 'linkadd') {
  195. if (isset($_GET['createlink']) && $_GET['createlink']) {
  196. $link = isset($_GET['link']) ? trim($_GET['link']) : '';
  197. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : '';
  198. //检查网址合法性
  199. if (!preg_match("/^(http|ftp|https|mms)\:\/\/.{5,300}$/i", ($link))) {
  200. $link = 'http://' . preg_replace("/^(http|ftp|https|mms)\:\/\//i", '', $link);
  201. }
  202. if (!preg_match("/^(http|ftp|https|mms)\:\/\/.{4,300}$/i", ($link))) {
  203. $arr['error'] = lang('invalid_format_url');
  204. } else {
  205. $ext = strtolower(substr(strrchr($link, '.'), 1, 10));
  206. $isimage = in_array(strtoupper($ext), $imageexts) ? 1 : 0;
  207. $ismusic = 0;
  208. //是图片时处理
  209. if ($isimage) {
  210. if (!perm_check::checkperm_Container($fid, 'upload')) {
  211. $arr['error'] = lang('target_not_accept_image');
  212. }
  213. if ($data = io_dzz::linktoimage($link, $fid)) {
  214. if ($data['error']) $arr['error'] = $data['error'];
  215. else {
  216. $arr = $data;
  217. $arr['msg'] = 'success';
  218. }
  219. }
  220. } else {
  221. //试图作为视频处理
  222. if ($data = io_dzz::linktovideo($link, $fid)) {
  223. if (!perm_check::checkperm_Container($fid, 'upload')) {
  224. $arr['error'] = lang('target_not_accept_video');
  225. } else {
  226. if ($data['error']) $arr['error'] = $data['error'];
  227. else {
  228. $arr = $data;
  229. $arr['msg'] = 'success';
  230. }
  231. }
  232. }
  233. //作为网址处理
  234. if (!perm_check::checkperm_Container($fid, 'upload')) {
  235. $arr['error'] = lang('target_not_accept_link');
  236. } else {
  237. if ($data = io_dzz::linktourl($link, $fid)) {
  238. if ($data['error']) {
  239. $arr['error'] = $data['error'];
  240. } else {
  241. $arr = $data;
  242. $arr['msg'] = 'success';
  243. }
  244. } else {
  245. $arr['error'] = lang('network_error');
  246. }
  247. }
  248. }
  249. }
  250. }
  251. exit(json_encode($arr));
  252. } elseif ($operation == 'showtips') {
  253. $msgtext = isset($_GET['msg']) ? trim($_GET['msg']) : lang('system_unknow_error');
  254. } elseif ($operation == 'dzzdocument' || $operation == 'txt') {//新建文档
  255. if ($operation == 'dzzdocument') {
  256. $ext = 'dzzdoc';
  257. } else {
  258. $ext = 'txt';
  259. }
  260. $name = lang('new_' . $ext);
  261. $filename = $name . '.' . $ext;
  262. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : '';
  263. if ($arr = IO::upload_by_content(' ', $fid, $filename)) {
  264. if ($arr['error']) {
  265. } else {
  266. $arr['msg'] = 'success';
  267. }
  268. } else {
  269. $arr = array();
  270. $arr['error'] = lang('failure_newfolder');
  271. }
  272. } elseif ($operation == 'newIco') {//新建文件
  273. $type = trim($_GET['type']);
  274. $bzpath = isset($_GET['bz']) ? trim($_GET['bz']) : '';
  275. $fid = intval($_GET['fid']);
  276. $filename = '';
  277. $bz = getBzByPath($fid);
  278. switch ($type) {
  279. case 'newTxt':
  280. $filename = lang('new_txt') . '.txt';
  281. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  282. exit(json_encode(array('error' => lang('privilege'))));
  283. }
  284. $content = ' ';
  285. break;
  286. case 'newDzzDoc':
  287. $filename = lang('new_dzzdoc') . '.dzzdoc';
  288. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  289. exit(json_encode(array('error' => lang('privilege'))));
  290. }
  291. $content = ' ';
  292. break;
  293. case 'newDoc':
  294. $filename = lang('new_word') . '.docx';
  295. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  296. exit(json_encode(array('error' => lang('privilege'))));
  297. }
  298. $content = file_get_contents(DZZ_ROOT . './dzz/images/newfile/word.docx');
  299. break;
  300. case 'newExcel':
  301. $filename = lang('new_excel') . '.xlsx';
  302. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  303. exit(json_encode(array('error' => lang('privilege'))));
  304. }
  305. $content = file_get_contents(DZZ_ROOT . './dzz/images/newfile/excel.xlsx');
  306. break;
  307. case 'newPowerPoint':
  308. $filename = lang('new_PowerPoint') . '.pptx';
  309. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  310. exit(json_encode(array('error' => lang('privilege'))));
  311. }
  312. $content = file_get_contents(DZZ_ROOT . './dzz/images/newfile/ppt.pptx');
  313. break;
  314. case 'newpdf':
  315. $filename = lang('new_pdf') . '.pdf';
  316. if (!perm_check::checkperm_Container($fid, 'upload', $bz)) {
  317. exit(json_encode(array('error' => lang('privilege'))));
  318. }
  319. $content = file_get_contents(DZZ_ROOT . './dzz/images/newfile/pdf.pdf');
  320. break;
  321. }
  322. if ($bzpath) {
  323. $fid = $bzpath;
  324. }
  325. if ($arr = IO::upload_by_content($content, $fid, $filename)) {
  326. if ($arr['error']) {
  327. } else {
  328. $arr['msg'] = 'success';
  329. }
  330. } else {
  331. $arr = array();
  332. $arr['error'] = lang('new_failure');
  333. }
  334. exit(json_encode($arr));
  335. } elseif ($operation == 'getfid') {//获取路径对应目录
  336. $path = isset($_GET['name']) ? trim($_GET['name']) : '';
  337. $prefix = isset($_GET['prefix']) ? trim($_GET['prefix']) : '';
  338. $arr = array();
  339. if ($fid = C::t('resources_path')->fetch_by_path($path, $prefix)) {
  340. if (preg_match('/c_\d+/', $fid)) {
  341. $arr['cid'] = str_replace('c_', '', $fid);
  342. } else {
  343. $folderarr = C::t('folder')->fetch($fid);
  344. if ($folderarr['gid']) {
  345. $arr['gid'] = $folderarr['gid'];
  346. if ($folderarr['flag'] != 'organization') {
  347. $arr['fid'] = $fid;
  348. }
  349. } else {
  350. $arr['fid'] = $fid;
  351. }
  352. }
  353. exit(json_encode(array('success' => $arr, 'json')));
  354. } else {
  355. exit(json_encode(array('error' => true, 'json')));
  356. }
  357. } elseif ($operation == 'uploadfile') {//上传文件获取相关文件信息
  358. $rid = isset($_GET['rid']) ? trim($_GET['rid']) : '';
  359. if ($rid) {
  360. $arr = C::t('resources')->fetch_by_rid($rid);
  361. } else {
  362. $arr = array('error' => lang('system_busy'));
  363. }
  364. } elseif ($operation == 'getfolder') {//获取文件夹信息
  365. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : '';
  366. if ($fid) {
  367. $arr = C::t('resources')->fetch_by_oid($fid);
  368. } else {
  369. $arr = array('error' => lang('system_busy'));
  370. }
  371. } elseif ($operation == 'collect') {//收藏与取消收藏
  372. $paths = $_GET['paths'];
  373. //collect参数为1为收藏,否则为取消收藏,未接收到此参数,默认为收藏
  374. $collect = isset($_GET['collect']) ? $_GET['collect'] : 1;
  375. $rids = array();
  376. foreach ($paths as $v) {
  377. $rids[] = dzzdecode($v);
  378. }
  379. if ($collect) {//加入收藏
  380. $return = C::t('resources_collect')->add_collect_by_rid($rids);
  381. exit(json_encode($return));
  382. } else {//取消收藏
  383. $return = C::t('resources_collect')->delete_usercollect_by_rid($rids);
  384. exit(json_encode($return));
  385. }
  386. } elseif ($operation == 'tag') {
  387. $rid = isset($_GET['rid']) ? $_GET['rid'] : '';
  388. if (!$fileinfo = C::t('resources')->fetch_info_by_rid($rid)) {
  389. showTips(array('error' => true), 'json');
  390. }
  391. $tags = C::t('resources_tag')->fetch_tag_by_rid($rid);
  392. if (isset($_GET['addtag']) && $_GET['addtag']) {
  393. $tags = isset($_GET['tags']) ? $_GET['tags'] : '';
  394. $tagsarr = array_filter(explode(',', $tags));
  395. if (empty($tagsarr)) {
  396. exit(json_encode(array('error' => lang('tag_name_ismust'))));
  397. }
  398. $tagsubmit = array();
  399. foreach ($tagsarr as $v) {
  400. $tagsubmit[] = getstr($v);
  401. }
  402. if ($insert = C::t('resources_tag')->insert_data($rid, $tagsubmit)) {
  403. $statisarr = array(
  404. 'uid' => $uid,
  405. 'edits' => 1,
  406. 'editdateline' => TIMESTAMP
  407. );
  408. C::t('resources_statis')->add_statis_by_rid($rid, $statisarr);
  409. showTips(array('success' => true, 'tagsadd' => $insert['add'], 'tagsdel' => $insert['del']), 'json');
  410. } else {
  411. showTips(array('error' => true), 'json');
  412. }
  413. } else {
  414. $tagarr = array();
  415. $tagval = array();
  416. foreach ($tags as $v) {
  417. $tagarr[] = array('name' => $v['tagname']);
  418. $tagval[] = $v['tagname'];
  419. }
  420. $tagstr = htmlspecialchars(json_encode($tagarr));
  421. $tagval = implode(',', $tagval);
  422. }
  423. } elseif ($operation == 'comment') {
  424. include_once libfile('function/code');
  425. include_once libfile('function/use');
  426. $fid = intval($_GET['fid']);
  427. $rid = trim($_GET['rid']);
  428. $msg = isset($_GET['msg']) ? censor($_GET['msg']) : '';
  429. //获得提醒用户
  430. $at_users = array();
  431. $message = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $msg);
  432. $appid = C::t('app_market')->fetch_appid_by_mod('{dzzscript}?mod=' . MOD_NAME, 1);
  433. if ($rid) {
  434. if (!$file = C::t('resources')->fetch_info_by_rid($rid)) {
  435. exit(json_encode(array('error' => '未查询到该文件信息')));
  436. } else {
  437. if (!perm_check::checkperm_Container($file['oid'], 'comment')) {
  438. exit(json_encode(array('error' => lang('file_comment_no_privilege'))));
  439. }
  440. $eventdata = array('msg' => $msg);
  441. if ($insert = C::t('resources_event')->addevent_by_pfid($file['pfid'], 'add_comment', 'addcomment', $eventdata, $file['gid'], $rid, $file['name'], 1)) {
  442. $return = array(
  443. 'username' => getglobal('username'),
  444. 'uid' => getglobal('uid'),
  445. 'dateline' => dgmdate(TIMESTAMP, 'u'),
  446. 'msg' => dzzcode($message),
  447. 'commentid' => $insert,
  448. 'avatar' => avatar_block($_G['uid'])
  449. );
  450. if ($file['uid'] != getglobal('uid')) {
  451. $notevars = array(
  452. 'from_id' => $appid,
  453. 'from_idtype' => 'app',
  454. 'url' => ($file['gid'] > 0) ? $_G['siteurl'] . MOD_URL . '#group&do=file&gid=' . $file['gid'] . '&fid=' . $file['pfid'] : $_G['siteurl'] . MOD_URL . '#home&do=file&fid=' . $file['pfid'],
  455. 'author' => getglobal('username'),
  456. 'authorid' => getglobal('uid'),
  457. 'dataline' => dgmdate(TIMESTAMP),
  458. 'fname' => getstr($file['name'], 31),
  459. 'comment' => ($message) ? getstr(dzzcode($message)) : '',
  460. );
  461. $action = 'explorer_comment_mydoc';
  462. $type = 'explorer_comment_mydoc_' . $file['pfid'];
  463. dzz_notification::notification_add($file['uid'], $type, $action, $notevars, 1, 'dzz/explorer');
  464. }
  465. if ($at_users) {//提醒相关人员
  466. foreach ($at_users as $uid) {
  467. if ($uid != getglobal('uid')) {
  468. //发送通知
  469. $notevars = array(
  470. 'from_id' => $appid,
  471. 'from_idtype' => 'app',
  472. 'url' => ($file['gid'] > 0) ? $_G['siteurl'] . MOD_URL . '#group&do=file&gid=' . $file['gid'] . '&fid=' . $file['pfid'] : $_G['siteurl'] . MOD_URL . '#home&do=file&fid=' . $file['pfid'],
  473. 'author' => getglobal('username'),
  474. 'authorid' => getglobal('uid'),
  475. 'dataline' => dgmdate(TIMESTAMP),
  476. 'fname' => getstr($file['name'], 31),
  477. 'comment' => ($message) ? getstr($message) : '',
  478. );
  479. $action = 'explorer_comment_at';
  480. $type = 'explorer_comment_at' . $file['pfid'];
  481. dzz_notification::notification_add($uid, $type, $action, $notevars, 0, MOD_PATH);
  482. }
  483. }
  484. }
  485. showTips(array('success' => true, 'return' => $return, 'json'));
  486. }
  487. }
  488. } else {
  489. if (!$folder = C::t('folder')->fetch($fid)) {
  490. exit(json_encode(array('error' => '没有查询到该文件夹信息')));
  491. } else {
  492. if (!perm_check::checkperm_Container($fid, 'comment')) {
  493. exit(json_encode(array('error' => lang('folder_comment_no_privilege'))));
  494. }
  495. $rid = C::t('resources')->fetch_rid_by_fid($fid);
  496. $eventdata = array('msg' => $msg);
  497. if ($insert = C::t('resources_event')->addevent_by_pfid($fid, 'add_comment', 'addcomment', $eventdata, $folder['gid'], ($rid) ? $rid : '', $folder['fname'], 1)) {
  498. $return = array(
  499. 'username' => getglobal('username'),
  500. 'uid' => getglobal('uid'),
  501. 'dateline' => dgmdate(TIMESTAMP, 'u'),
  502. 'msg' => dzzcode($message),
  503. 'commentid' => $insert,
  504. 'avatar' => avatar_block($_G['uid'])
  505. );
  506. if ($folder['uid'] != getglobal('uid')) {
  507. $notevars = array(
  508. 'from_id' => $appid,
  509. 'from_idtype' => 'app',
  510. 'url' => ($folder['gid'] > 0) ? $_G['siteurl'] . MOD_URL . '#group&do=file&gid=' . $folder['gid'] . '&fid=' . $folder['fid'] : $_G['siteurl'] . MOD_URL . '#home&do=file&fid=' . $folder['fid'],
  511. 'author' => getglobal('username'),
  512. 'authorid' => getglobal('uid'),
  513. 'dataline' => dgmdate(TIMESTAMP),
  514. 'fname' => getstr($folder['fname'], 31),
  515. 'comment' => ($message) ? getstr(dzzcode($message)) : '',
  516. );
  517. $action = 'explorer_comment_mydoc';
  518. $type = 'explorer_comment_mydoc_' . $fid;
  519. dzz_notification::notification_add($folder['uid'], $type, $action, $notevars, 0, 'dzz/explorer');
  520. }
  521. if ($at_users) {//提醒相关人员
  522. foreach ($at_users as $uid) {
  523. if ($uid != getglobal('uid')) {
  524. //发送通知
  525. $notevars = array(
  526. 'from_id' => $appid,
  527. 'from_idtype' => 'app',
  528. 'url' => ($folder['gid'] > 0) ? $_G['siteurl'] . MOD_URL . '#group&do=file&gid=' . $folder['gid'] . '&fid=' . $folder['fid'] : $_G['siteurl'] . MOD_URL . '#home&do=file&fid=' . $folder['fid'],
  529. 'author' => getglobal('username'),
  530. 'authorid' => getglobal('uid'),
  531. 'dataline' => dgmdate(TIMESTAMP),
  532. 'fname' => getstr($folder['fname'], 31),
  533. 'comment' => ($message) ? getstr($message) : '',
  534. );
  535. $action = 'explorer_comment_at';
  536. $type = 'explorer_comment_at_' . $fid;
  537. dzz_notification::notification_add($uid, $type, $action, $notevars, 0, MOD_PATH);
  538. }
  539. }
  540. }
  541. showTips(array('success' => true, 'return' => $return, 'json'));
  542. }
  543. }
  544. }
  545. } elseif ($operation == 'addsearchcat') {//增加类型筛选
  546. $id = isset($_GET['id']) ? intval($_GET['id']) : '';
  547. if ($id) {
  548. $cat = C::t('resources_cat')->fetch_by_id($id);
  549. $cattidarr = explode(',', $cat['tag']);
  550. $tags = '';
  551. foreach (C::t('tag')->fetch_tag_by_tid($cattidarr, 'explorer') as $v) {
  552. $tags .= $v['tagname'] . ',';
  553. }
  554. $cat['tag'] = substr($tags, 0, -1);
  555. }
  556. if (isset($_GET['editcatsearch'])) {
  557. $id = $_GET['editcatsearch'];
  558. $arr = $_GET['arr'];
  559. if (!$arr['catname'] || preg_match('/^\s*$/', $arr['catname'])) {
  560. exit(json_encode(array('error' => true, 'msg' => lang('name_is_must'))));
  561. }
  562. $catoldid = DB::result_first("select id from %t where catname = %s and uid = %d", array('resources_cat', $arr['catname'], $uid));
  563. if ($catoldid && $catoldid != $id) {
  564. exit(json_encode(array('error' => true, 'msg' => lang('typename_must_only'))));
  565. }
  566. //处理后缀名
  567. if ($arr['ext']) {
  568. $qualifiedExt = array();
  569. $extarr = explode(',', $arr['ext']);
  570. foreach ($extarr as $v) {
  571. if (!preg_match('/^\.\w+$/', $v)) {
  572. $v = '.' . strtolower($v);
  573. }
  574. if (preg_match('/^\.\w+$/', $v)) {
  575. $qualifiedExt[] = strtolower($v);
  576. }
  577. }
  578. $qualifiedExt = array_unique($qualifiedExt);
  579. $arr['ext'] = implode(',', $qualifiedExt);
  580. }
  581. if (!$arr['ext']) {
  582. exit(json_encode(array('error' => true, 'msg' => lang('cat_is_must'))));
  583. }
  584. if (C::t('resources_cat')->update($id, $arr)) {
  585. exit(json_encode(array('success' => true)));
  586. } else {
  587. exit(json_encode(array('error' => true)));
  588. }
  589. }
  590. if (isset($_GET['addcatsearch'])) {
  591. $arr = $_GET['arr'];
  592. //处理名称
  593. if (!$arr['catname'] || preg_match('/^\s*$/', $arr['catname'])) {
  594. exit(json_encode(array('error' => true, 'msg' => lang('name_is_must'))));
  595. }
  596. if (DB::result_first("select count(*) from %t where catname = %s and uid = %d", array('resources_cat', $arr['catname'], $uid)) > 0) {
  597. exit(json_encode(array('error' => true, 'msg' => lang('typename_must_only'))));
  598. }
  599. //处理处理后缀名
  600. if ($arr['ext']) {
  601. $qualifiedExt = array();
  602. $extarr = explode(',', $arr['ext']);
  603. foreach ($extarr as $v) {
  604. if (!preg_match('/^\.\w+$/', $v)) {
  605. $v = '.' . strtolower($v);
  606. }
  607. if (preg_match('/^\.\w+$/', $v)) {
  608. $qualifiedExt[] = strtolower($v);
  609. }
  610. }
  611. $qualifiedExt = array_unique($qualifiedExt);
  612. $arr['ext'] = implode(',', $qualifiedExt);
  613. }
  614. if (!$arr['ext']) {
  615. exit(json_encode(array('error' => true, 'msg' => lang('cat_is_error'))));
  616. }
  617. $arr['uid'] = $uid;
  618. $insert = C::t('resources_cat')->insert_cat($arr);
  619. if ($insert['success']) {
  620. exit(json_encode(array('success' => true, 'insertid' => $insert['insert'])));
  621. } else {
  622. exit(json_encode(array('error' => true, 'msg' => $insert['msg'])));
  623. }
  624. }
  625. } elseif ($operation == 'delsearchcat') {//删除筛选类型
  626. $catid = isset($_GET['id']) ? intval($_GET['id']) : '';
  627. if ($_GET['delcat']) {
  628. if (C::t('resources_cat')->del_by_id($catid)) {
  629. $previd = C::t('resources_cat')->fetch_rencent_id($catid);
  630. exit(json_encode(array('success' => true, 'catid' => $catid, 'previd' => $previd)));
  631. } else {
  632. exit(json_encode(array('error' => true)));
  633. }
  634. } else {
  635. exit(json_encode(array('error' => true)));
  636. }
  637. } elseif ($operation == 'share') {//分享
  638. $bz = isset($_GET['bz']) ? trim($_GET['bz']) : '';
  639. $table = isset($_GET['table']) ? trim($_GET['table']) : '';
  640. if (isset($_GET['paths'])) {
  641. $patharr = explode(',', $_GET['paths']);
  642. //判断是否是分享id
  643. if (count($patharr) == 1 && preg_match('/^\d+$/', $patharr[0])) {
  644. $shareid = $patharr[0];
  645. } else {
  646. $rids = array();
  647. foreach ($patharr as $v) {
  648. $rids[] = dzzdecode($v);
  649. }
  650. $files = implode(',', $rids);
  651. }
  652. } else {
  653. $files = $_GET['rid'];
  654. }
  655. if (isset($_GET['share'])) {
  656. if (isset($_GET['delshare']) && $_GET['delshare'] == 1 && isset($_GET['do']) && $_GET['do'] == 'del') {
  657. $id = isset($_GET['id']) ? intval($_GET['id']) : '';
  658. $return = C::t('shares')->delete_by_id($id);
  659. if ($return['success']) {
  660. showTips(array('success' => true, 'shareid' => $id));
  661. } else {
  662. showTips(array('error' => $return['error']));
  663. }
  664. } else {
  665. $share = $_GET['share'];
  666. $share['filepath'] = trim($_GET['rid']);
  667. $share['title'] = getstr($share['title']);
  668. if ($share['endtime']) $share['endtime'] = strtotime($share['endtime']) + 24 * 60 * 60;
  669. if ($share['password']) $share['password'] = dzzencode($share['password']);
  670. $share['times'] = intval($share['times']);
  671. $perm = isset($_GET['perm']) ? $_GET['perm'] : [];
  672. if (is_array($perm)) {
  673. $share['perm'] = implode(',', $perm);
  674. }
  675. if (isset($_GET['id']) && $_GET['id']) $id = intval($_GET['id']);
  676. if ($id) {
  677. if ($ret = C::t('shares')->update_by_id($id, $share,$bz)) {
  678. showTips(array('success' => true, 'shareurl' => C::t('shorturl')->getShortUrl('index.php?mod=shares&sid=' . dzzencode($ret)), 'shareid' => $ret));
  679. } elseif ($ret['error']) {
  680. showTips(array('error' => $ret['error']), 'json');
  681. } else {
  682. showTips(array('error' => lang('create_share_failer') . '!'), 'json');
  683. }
  684. } else {
  685. if($bz) {
  686. $bzinfo = IO::getMeta($files);
  687. if ($share['error']) showTips(array('error' => $share['error']), 'json');
  688. $share['type'] = $bzinfo['type'];
  689. }
  690. $ret = C::t('shares')->insert($share,$bz);
  691. if ($ret['success']) {
  692. showTips(array('success' => true, 'shareurl' => C::t('shorturl')->getShortUrl('index.php?mod=shares&sid=' . dzzencode($ret['success'])), 'shareid' => $ret['success']));
  693. } elseif ($ret['error']) {
  694. showTips(array('error' => $ret['error']), 'json');
  695. } else {
  696. showTips(array('error' => lang('create_share_failer') . '!'), 'json');
  697. }
  698. }
  699. }
  700. } else {
  701. if ($shareid) {
  702. if ($share = C::t('shares')->fetch($shareid)) {
  703. $share['shareurl'] = C::t('shorturl')->getShortUrl('index.php?mod=shares&sid=' . dzzencode($share['id']));
  704. if ($share['password']) $share['password'] = dzzdecode($share['password']);
  705. if ($share['status'] >= -2) {
  706. if ($share['endtime'] && $share['endtime'] < TIMESTAMP) $share['status'] = -1;
  707. elseif ($share['times'] && $share['times'] <= $share['count']) $share['status'] = -2;
  708. else $share['status'] = 0;
  709. }
  710. if ($share['endtime']) $share['endtime'] = dgmdate($share['endtime'], 'Y-m-d');
  711. if (!$share['times']) {
  712. $share['times'] = '';
  713. }
  714. $files = $share['filepath'];
  715. $share['perm'] = explode(',', $share['perm']);
  716. if($share['pfid']==-1) {
  717. $bz = 1;
  718. }
  719. }
  720. } else {
  721. if ($share = C::t('shares')->fetch_by_path($files)) {
  722. $share['shareurl'] = C::t('shorturl')->getShortUrl('index.php?mod=shares&sid=' . dzzencode($share['id']));
  723. if ($share['password']) $share['password'] = dzzdecode($share['password']);
  724. if ($share['status'] >= -2) {
  725. if ($share['endtime'] && $share['endtime'] < TIMESTAMP) $share['status'] = -1;
  726. elseif ($share['times'] && $share['times'] <= $share['count']) $share['status'] = -2;
  727. else $share['status'] = 0;
  728. }
  729. if ($share['endtime']) $share['endtime'] = dgmdate($share['endtime'], 'Y-m-d');
  730. if (!$share['times']) {
  731. $share['times'] = '';
  732. }
  733. $share['perm'] = explode(',', $share['perm']);
  734. if($share['pfid']==-1) {
  735. $bz = 1;
  736. }
  737. } else {
  738. if($bz) {
  739. $share = IO::getMeta($files);
  740. if ($share['error']) {
  741. $arr = array('error' => $share['error']);
  742. } else {
  743. $share['title'] = $share['name'];
  744. }
  745. } else {
  746. $rids = explode(',', $files);
  747. //默认单个文件分享
  748. $more = false;
  749. //多个文件分享
  750. if (count($rids) > 1) $more = true;
  751. $filenames = array();
  752. $gidarr = array();
  753. foreach (DB::fetch_all("select pfid,name,gid from %t where rid in(%n)", array('resources', $rids)) as $v) {
  754. if (!perm_check::checkperm_Container($v['pfid'], 'share')) {
  755. $arr = array('error' => lang('no_privilege'));
  756. } else {
  757. $gidarr[] = $v['gid'];
  758. $filenames[] = $v['name'];
  759. }
  760. }
  761. //判断文件来源
  762. if (count(array_unique($gidarr)) > 1) {
  763. $arr = array('error' => lang('share_notallow_from_different_zone'));
  764. }
  765. //自动生成分享标题
  766. if ($more) {
  767. $share['title'] = $filenames[0] . lang('more_file_or_folder');
  768. } else {
  769. $share['title'] = $filenames[0];
  770. }
  771. }
  772. }
  773. }
  774. }
  775. } elseif ($operation == 'property') {//属性
  776. $paths = isset($_GET['paths']) ? trim($_GET['paths']) : '';
  777. $bz = isset($_GET['bz']) ? trim($_GET['bz']) : '';
  778. $fid = 0;
  779. if (preg_match('/fid_/', $paths)) {
  780. $fid = preg_replace('/fid_/', '', $paths);
  781. }
  782. if ($bz) {
  783. if ($fid) {
  784. $propertys = IO::getMeta($fid);
  785. if ($propertys['error']) {
  786. showmessage($propertys['error']);
  787. }
  788. if (!$_G['adminid'] && $propertys['uid'] != $_G['uid']) {
  789. showmessage(lang('no_privilege'));
  790. }
  791. $contains = IO::getContains($propertys['path']);
  792. $propertys['type'] = lang('type_folder');
  793. $propertys['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contains['size']), 'size' => $contains['size']));
  794. $propertys['contain'] = lang('property_info_contain', array('filenum' => $contains['contain'][0], 'foldernum' => $contains['contain'][1]));
  795. } elseif (strpos($paths, ',') !== false) {
  796. $patharr = explode(',', $paths);
  797. $rids = array();
  798. foreach ($patharr as $v) {
  799. $rids[] = dzzdecode($v);
  800. }
  801. $size = 0;
  802. $contents = array(0, 0);
  803. foreach ($rids as $icoid) {
  804. if (!$icoarr = IO::getMeta($icoid)) continue;
  805. if ($icoarr['error']) {
  806. showmessage($icoarr['error']);
  807. } else {
  808. switch ($icoarr['type']) {
  809. case 'folder':
  810. $contains = IO::getContains($icoarr['path']);
  811. $size += intval($contains['size']);
  812. $contents[0] += $contains['contain'][0];
  813. $contents[1] += $contains['contain'][1] + 1;
  814. break;
  815. default:
  816. $size += $icoarr['size'];
  817. $contents[0] += 1;
  818. break;
  819. }
  820. }
  821. }
  822. $propertys['ffsize'] = lang('property_info_size', array('fsize' => formatsize($size), 'size' => $size));
  823. $propertys['contain'] = lang('property_info_contain', array('filenum' => $contents[0], 'foldernum' => $contents[1]));
  824. } else {
  825. $paths = dzzdecode($paths);
  826. $propertys = IO::getMeta($paths);
  827. if ($propertys['error']) {
  828. showmessage($propertys['error']);
  829. }
  830. if (!$_G['adminid'] && $propertys['uid'] != $_G['uid']) {
  831. showmessage(lang('no_privilege'));
  832. }
  833. if ($propertys['type'] == 'folder') {
  834. $contains = IO::getContains($propertys['path']);
  835. $propertys['type'] = lang('type_folder');
  836. $propertys['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contains['size']), 'size' => $contains['size']));
  837. $propertys['contain'] = lang('property_info_contain', array('filenum' => $contains['contain'][0], 'foldernum' => $contains['contain'][1]));
  838. }
  839. }
  840. $propertys['type'] = $propertys['ftype'];
  841. } else {
  842. if (intval($fid)) {
  843. if ($rid = C::t('resources')->fetch_rid_by_fid($fid)) {
  844. $propertys = C::t('resources')->get_property_by_rid($rid);
  845. } else {
  846. $propertys = C::t('resources')->get_property_by_fid($fid);
  847. }
  848. } else {
  849. $patharr = explode(',', $paths);
  850. $rids = array();
  851. foreach ($patharr as $v) {
  852. $rids[] = dzzdecode($v);
  853. }
  854. $propertys = C::t('resources')->get_property_by_rid($rids);
  855. if (!$propertys['ismulti']) {
  856. $attrdata = C::t('resources_attr')->fetch_by_rid($propertys['rid'], $propertys['vid']);
  857. if ($_G['adminid'] && $attrdata['aid']) {
  858. $attachment = IO::getStream('attach::' . $attrdata['aid']);
  859. }
  860. }
  861. }
  862. if ($propertys['error']) {
  863. $error = $propertys['error'];
  864. }
  865. }
  866. } elseif ($operation == 'editFileVersionInfo') {
  867. $rid = isset($_GET['rid']) ? trim($_GET['rid']) : '';
  868. $vid = isset($_GET['vid']) ? intval($_GET['vid']) : 0;
  869. $versioninfo = C::t('resources_version')->get_versioninfo_by_rid_vid($rid, $vid);
  870. } elseif ($operation == 'infoversion') {
  871. $rid = isset($_GET['rid']) ? trim($_GET['rid']) : '';
  872. $vid = isset($_GET['vid']) ? intval($_GET['vid']) : 0;
  873. $versioninfo = C::t('resources_version')->get_versioninfo_by_rid_vid($rid, $vid);
  874. if ($versioninfo['rid']) {
  875. $propertys = C::t('resources')->get_property_by_rid($versioninfo['rid']);
  876. } else {
  877. $error = lang('file_not_exist');
  878. }
  879. if ($versioninfo['aid']) {
  880. $attachment = IO::getFileUri('attach::' . $versioninfo['aid']);
  881. }
  882. } elseif ($operation == 'deletethisversion') {
  883. $rid = isset($_GET['rid']) ? trim($_GET['rid']) : '';
  884. $vid = isset($_GET['vid']) ? intval($_GET['vid']) : 0;
  885. if (!$rid || !$vid) {
  886. exit(json_encode(array('error' => 'access denied')));
  887. }
  888. $fileinfo = C::t('resources')->get_property_by_rid($rid);
  889. if ($fileinfo['editperm']) {
  890. if (C::t('resources_version')->delete_by_vid($vid, $rid, true)) {
  891. exit(json_encode(array('msg' => 'success')));
  892. } else {
  893. exit(json_encode(array('error' => '该版本不存在或最后一个不能删除')));
  894. }
  895. } else {
  896. exit(json_encode(array('error' => lang('no_privilege'))));
  897. }
  898. } elseif ($operation == 'addIndex') {//索引文件
  899. global $_G;
  900. $indexarr = array(
  901. 'id' => $_GET['rid'] . '_' . intval($_GET['vid']),
  902. 'name' => $_GET['filename'],
  903. 'username' => $_GET['username'],
  904. 'type' => $_GET['filetype'],
  905. 'flag' => 'explorer',
  906. 'vid' => intval($_GET['vid']),
  907. 'gid' => intval($_GET['gid']),
  908. 'uid' => intval($_GET['uid']),
  909. 'aid' => isset($_GET['aid']) ? intval($_GET['aid']) : 0,
  910. 'md5' => isset($_GET['md5']) ? trim($_GET['md5']) : '',
  911. 'readperm' => 0
  912. );
  913. $fid = intval($_GET['pfid']);
  914. $folderdata = C::t('folder')->fetch($fid);
  915. $perm = $folderdata['perm_inherit'];
  916. if (perm_binPerm::havePower('read2', $perm)) {
  917. $indexarr['readperm'] = 2;
  918. } elseif (perm_binPerm::havePower('read1', $perm)) {
  919. $indexarr['readperm'] = 1;
  920. } else {
  921. $indexarr['readperm'] = 0;
  922. }
  923. $return = Hook::listen('solraddfile', $indexarr);
  924. if ($return[0]['error']) {
  925. exit(json_encode($return[0]));
  926. } else {
  927. exit(json_encode(array('success' => true)));
  928. }
  929. } elseif ($operation == 'updateIndex') {
  930. $arr = isset($_GET['arr']) ? $_GET['arr'] : '';
  931. if (empty($arr)) {
  932. exit(json_encode(array('error' => '缺少数据')));
  933. }
  934. $rid = isset($arr['rid']) ? trim($arr['rid']) : '';
  935. if (!$rid) exit(json_encode(array('error' => '缺少数据')));
  936. $vid = isset($arr['vid']) ? intval($_GET['vid']) : 0;
  937. $result = Hook::listen('solredit', $setarr);
  938. if ($result[0]['error']) {
  939. exit(json_encode(array('error' => $result[0]['error'])));
  940. } else {
  941. exit(json_encode(array('success' => true)));
  942. }
  943. } elseif ($operation == 'deleteIndex') {
  944. $rids = $_GET['rids'];
  945. $ids = array();
  946. foreach ($rids as $v) {
  947. $ids[] = $v . '_' . '0';
  948. }
  949. Hook::listen('solrdel', $ids);
  950. exit(json_encode(array('success' => true)));
  951. }
  952. include template('ajax');