PageRenderTime 44ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/src/applications/bbs/controller/ManageController.php

https://gitlab.com/wuhang2003/phpwind
PHP | 432 lines | 365 code | 32 blank | 35 comment | 74 complexity | 212ff2e0643dcda727e31f8686cbba2d MD5 | raw file
  1. <?php
  2. Wind::import('SRV:forum.srv.dataSource.PwFetchTopicByTid');
  3. Wind::import('SRV:forum.srv.PwThreadManage');
  4. /**
  5. * 帖子-管理操作
  6. *
  7. * @author peihong <jhqblxt@gmail.com> Dec 2, 2011
  8. * @copyright ©2003-2103 phpwind.com
  9. * @license http://www.phpwind.com
  10. * @version $Id: ManageController.php 24747 2013-02-20 03:13:43Z jieyin $
  11. * @package src.applications.bbs.controller
  12. */
  13. class ManageController extends PwBaseController {
  14. public $action;
  15. protected $singleData = array();
  16. protected $manage;
  17. protected $doAction;
  18. protected $doCancel = array();
  19. /**
  20. * preprocessing before any manage action
  21. *
  22. * @see base/PwBaseController::beforeAction()
  23. */
  24. public function beforeAction($handlerAdapter) {
  25. parent::beforeAction($handlerAdapter);
  26. if (!$this->loginUser->isExists()) {
  27. $this->showError('login.not');
  28. }
  29. $this->action = $handlerAdapter->getAction();
  30. $this->manage = $this->_getManage($this->action);
  31. if (($result = $this->manage->check()) !== true) {
  32. if (false === $result) $this->showError(new PwError('BBS:manage.permission.deny'));
  33. $this->showError($result->getError());
  34. }
  35. }
  36. /**
  37. * manage action
  38. */
  39. public function manageAction() {
  40. if (!$this->doAction) {
  41. $reason = Wekit::C()->site->get('managereasons', '');
  42. $this->setOutput(explode("\n", $reason), 'manageReason');
  43. $this->setOutput($this->action, 'action');
  44. $this->setTemplate('manage_threads');
  45. } else {
  46. if ($this->manage->user->getPermission('force_operate_reason')) {
  47. $reason = $this->getInput('reason', 'post');
  48. $reason or $this->showError('BBS:manage.error.empty.reason');
  49. }
  50. $sendnotice = $this->getInput('sendnotice', 'post');
  51. $this->manage->execute();
  52. if ($sendnotice) {
  53. $this->_sendMessage($this->action, $this->manage->getData());
  54. }
  55. $this->showMessage('operate.success');
  56. }
  57. }
  58. /**
  59. * get manage handler
  60. *
  61. * @param $action
  62. */
  63. protected function _getManage($action) {
  64. $tids = $this->getInput('tids', 'post');
  65. $tid = $this->getInput('tid', 'post');
  66. if ($tids && !is_array($tids)) {
  67. $tids = explode(',', $tids);
  68. } elseif (!$tids && $tid) {
  69. $tids = array($tid);
  70. }
  71. $manage = new PwThreadManage(new PwFetchTopicByTid($tids), $this->loginUser);
  72. if (strpos($action,'do') === 0 && $action != 'down') {
  73. $this->doAction = true;
  74. } else {
  75. $this->doAction = false;
  76. $this->setOutput('帖子操作', 'title');
  77. $this->setOutput(count($manage->getData()), 'count');
  78. if (count($data = $manage->getData()) == 1) {
  79. $this->singleData = current($data);
  80. }
  81. }
  82. switch ($action) {
  83. case 'delete':
  84. case 'dodelete':
  85. $do = $this->_getDeleteManage($manage);
  86. break;
  87. case 'ban':
  88. case 'doban':
  89. $do = $this->_getBanManage($manage);
  90. break;
  91. case 'topped':
  92. case 'digest':
  93. case 'highlight':
  94. case 'up':
  95. case 'lock':
  96. case 'down':
  97. case 'docombined':
  98. $do = $this->_getCombinedManage($manage);
  99. break;
  100. case 'copy':
  101. case 'docopy':
  102. $do = $this->_getCopyManage($manage);
  103. break;
  104. case 'move':
  105. case 'domove':
  106. $do = $this->_getMoveManage($manage);
  107. break;
  108. case 'type':
  109. case 'dotype':
  110. $do = $this->_getTypeManage($manage);
  111. break;
  112. default:
  113. $do = null;
  114. break;
  115. }
  116. if (is_array($do)) {
  117. foreach ($do as $do1) {
  118. $manage->appendDo($do1);
  119. }
  120. } else {
  121. $manage->appendDo($do);
  122. }
  123. return $manage;
  124. }
  125. protected function _getCombinedManage($manage) {
  126. $do = array();
  127. if (!$this->doAction) {
  128. $operateThread = $manage->getPermission();
  129. $method = sprintf('_get%sManage', ucfirst($this->action));
  130. $do[] = $this->$method($manage);
  131. $others = $this->_getOtherActions($this->action);
  132. foreach ($others as $key => $value) {
  133. $method = sprintf('_get%sManage', ucfirst($value));
  134. $op = $this->$method($manage);
  135. if ($op->check($operateThread) !== true) {
  136. unset($operateThread[$value]);
  137. }
  138. }
  139. $this->setOutput($operateThread, 'operateThread');
  140. $this->setOutput('docombined', 'doaction');
  141. } else {
  142. $actions = $this->getInput('actions', 'post');
  143. foreach ((array)$actions as $key => $value) {
  144. $method = sprintf('_get%sManage', ucfirst($value));
  145. $do[] = $this->$method($manage);
  146. }
  147. }
  148. return $do;
  149. }
  150. protected function _getOtherActions($action) {
  151. $a1 = array('topped', 'digest', 'up', 'highlight');
  152. $a2 = array('lock', 'down');
  153. if (in_array($action, $a1)) {
  154. return array_diff($a1, array($action));
  155. }
  156. if (in_array($action, $a2)) {
  157. return array_diff($a2, array($action));
  158. }
  159. return array();
  160. }
  161. protected function _getDigestManage($manage) {
  162. Wind::import('SRV:forum.srv.manage.PwThreadManageDoDigest');
  163. $do = new PwThreadManageDoDigest($manage);
  164. if (!$this->doAction) {
  165. } else {
  166. $digest = $this->getInput('digest', 'post');
  167. $do->setDigest($digest);
  168. $do->setReason(htmlentities($this->getInput('reason', 'post')));
  169. !$digest && $this->doCancel[] = 'dodigest';
  170. }
  171. return $do;
  172. }
  173. protected function _getToppedManage($manage) {
  174. Wind::import('SRV:forum.srv.manage.PwThreadManageDoTopped');
  175. $do = new PwThreadManageDoTopped($manage);
  176. if (!$this->doAction) {
  177. $selectedFids = array();
  178. if ($this->singleData) {
  179. $defaultTopped = $this->singleData['topped'];
  180. $sort = Wekit::load('forum.PwSpecialSort')->getSpecialSortByTid($this->singleData['tid']);
  181. $defaultTopped == 3 && $selectedFids = array_keys($sort);
  182. $current = current($sort);
  183. $toppedOvertime = $current['end_time'] ? Pw::time2str($current['end_time'], 'Y-m-d') : '';
  184. } else {
  185. $defaultTopped = 1;
  186. $toppedOvertime = '';
  187. }
  188. $operateThread = $manage->getPermission();
  189. $forumOption = $operateThread['topped_type'] > 2 ? Wekit::load('forum.srv.PwForumService')->getForumOption($selectedFids) : '';
  190. $this->setOutput($toppedOvertime, 'toppedOvertime');
  191. $this->setOutput($defaultTopped, 'defaultTopped');
  192. $this->setOutput($forumOption, 'forumOption');
  193. } else {
  194. list($topped, $toppedOvertime, $toppedFids) = $this->getInput(array('topped', 'topped_overtime', 'topped_fids'), 'post');
  195. $do->setTopped($topped);
  196. $do->setFids($toppedFids);
  197. $do->setOvertime($toppedOvertime);
  198. $do->setReason(htmlentities($this->getInput('reason', 'post')));
  199. !$topped && $this->doCancel[] = 'dotopped';
  200. }
  201. return $do;
  202. }
  203. protected function _getUpManage($manage) {
  204. Wind::import('SRV:forum.srv.manage.PwThreadManageDoUp');
  205. $do = new PwThreadManageDoUp($manage);
  206. if (!$this->doAction) {
  207. } else {
  208. $uptime = $this->getInput('uptime', 'post');
  209. $do->setUptime($uptime);
  210. $do->setReason(htmlentities($this->getInput('reason', 'post')));
  211. }
  212. return $do;
  213. }
  214. protected function _getHighlightManage($manage) {
  215. Wind::import('SRV:forum.srv.manage.PwThreadManageDoHighlight');
  216. $do = new PwThreadManageDoHighlight($manage);
  217. if (!$this->doAction) {
  218. if ($this->singleData) {
  219. Wind::import("LIB:utility.PwHighlight");
  220. $hightlight = new PwHighlight();
  221. $hightlightStyle = $hightlight->parseHighlight($this->singleData['highlight']);
  222. $overtime = Wekit::load('forum.PwOvertime')->getOvertimeByTidAndType($this->singleData['tid'], 'highlight');
  223. $hightlightOvertime = ($overtime && $overtime['overtime']) ? Pw::time2str($overtime['overtime'], 'Y-m-d') : '';
  224. } else {
  225. $hightlightStyle = array('color' => '#F50');
  226. $hightlightOvertime = '';
  227. }
  228. $this->setOutput($hightlightStyle, 'hightlightStyle');
  229. $this->setOutput($hightlightOvertime, 'hightlightOvertime');
  230. } else {
  231. list($bold, $italic, $underline, $color, $highlightOvertime) = $this->getInput(array('bold', 'italic', 'underline', 'color', 'highlight_overtime'), 'post');
  232. Wind::import("LIB:utility.PwHighlight");
  233. $hightlight = new PwHighlight();
  234. $hightlight->setColor($color);
  235. $hightlight->setBold($bold);
  236. $hightlight->setItalic($italic);
  237. $hightlight->setUnderline($underline);
  238. $do->setHighlight($hightlight->getHighlight());
  239. $do->setOvertime($highlightOvertime);
  240. $do->setReason(htmlentities($this->getInput('reason', 'post')));
  241. if (!$color && !$bold && !$italic && !$underline) $this->doCancel[] = 'dohighlight';
  242. }
  243. return $do;
  244. }
  245. protected function _getDeleteManage($manage) {
  246. Wind::import('SRV:forum.srv.manage.PwThreadManageDoDeleteTopic');
  247. $do = new PwThreadManageDoDeleteTopic($manage);
  248. if (!$this->doAction) {
  249. $this->setOutput('dodelete', 'doaction');
  250. } else {
  251. $deductCredit = $this->getInput('deductCredit', 'post');
  252. $do->setIsDeductCredit($deductCredit)
  253. ->setReason(htmlentities($this->getInput('reason', 'post')));
  254. }
  255. return $do;
  256. }
  257. protected function _getDownManage($manage) {
  258. Wind::import('SRV:forum.srv.manage.PwThreadManageDoDown');
  259. $do = new PwThreadManageDoDown($manage);
  260. if (!$this->doAction) {
  261. } else {
  262. list($downtime, $downed) = $this->getInput(array('downtime', 'downed'), 'post');
  263. $do->setDowntime($downtime)->setDowned($downed)->setReason(htmlentities($this->getInput('reason', 'post')));
  264. }
  265. return $do;
  266. }
  267. protected function _getLockManage($manage) {
  268. Wind::import('SRV:forum.srv.manage.PwThreadManageDoLock');
  269. $do = new PwThreadManageDoLock($manage);
  270. if (!$this->doAction) {
  271. if ($this->singleData) {
  272. $defaultLocked = Pw::getstatus($this->singleData['tpcstatus'], PwThread::STATUS_CLOSED) ? 2 : 1;
  273. } else {
  274. $defaultLocked = 1;
  275. }
  276. $this->setOutput($defaultLocked, 'defaultLocked');
  277. } else {
  278. $locked = $this->getInput('locked', 'post');
  279. $do->setLocked($locked)->setReason(htmlentities($this->getInput('reason', 'post')));
  280. !$locked && $this->doCancel[] = 'dolock';
  281. }
  282. return $do;
  283. }
  284. protected function _getMoveManage($manage) {
  285. Wind::import('SRV:forum.srv.manage.PwThreadManageDoMove');
  286. $do = new PwThreadManageDoMove($manage);
  287. if (!$this->doAction) {
  288. $this->setOutput($this->_getFroumService()->getForumOption($do->fid), 'option_html');
  289. $this->setOutput('domove', 'doaction');
  290. } else {
  291. list($fid, $topictype) = $this->getInput(array('fid', 'topictype'), 'post');
  292. $do->setFid($fid)->setTopictype($topictype)->setReason(htmlentities($this->getInput('reason', 'post')));
  293. }
  294. return $do;
  295. }
  296. protected function _getTypeManage($manage) {
  297. Wind::import('SRV:forum.srv.manage.PwThreadManageDoType');
  298. $do = new PwThreadManageDoType($manage);
  299. if (!$this->doAction) {
  300. $topicTypes = $do->getTopicTypes();
  301. $this->setOutput($topicTypes,'topicTypes');
  302. $this->setOutput('dotype', 'doaction');
  303. } else {
  304. list($topicType, $subTopicType) = $this->getInput(array('topictype', 'sub_topictype'), 'post');
  305. $do->setTopictype($topicType, $subTopicType);
  306. $do->setReason(htmlentities($this->getInput('reason', 'post')));
  307. }
  308. return $do;
  309. }
  310. protected function _getCopyManage($manage) {
  311. Wind::import('SRV:forum.srv.manage.PwThreadManageDoCopy');
  312. $do = new PwThreadManageDoCopy($manage);
  313. if (!$this->doAction) {
  314. $this->setOutput('docopy', 'doaction');
  315. $this->setOutput($this->_getFroumService()->getForumOption($do->fid), 'option_html');
  316. } else {
  317. list($fid, $topictype) = $this->getInput(array('fid', 'topictype'), 'post');
  318. $do->setFid($fid)->setTopictype($topictype)->setReason(htmlentities($this->getInput('reason', 'post')));
  319. }
  320. return $do;
  321. }
  322. /**
  323. * ban manage
  324. *
  325. * @return PwThreadManageDoBan
  326. */
  327. protected function _getBanManage($manage) {
  328. Wind::import('SRV:forum.srv.manage.PwThreadManageDoBan');
  329. $do = new PwThreadManageDoBan($manage, $this->loginUser);
  330. if ($this->doAction) {
  331. $banInfo = new stdClass();
  332. $banInfo->types = $this->getInput('types', 'post');
  333. $banInfo->end_time = $this->getInput('end_time', 'post');
  334. $banInfo->reason = htmlentities($this->getInput('reason', 'post'));
  335. $banInfo->ban_range = intval($this->getInput('ban_range', 'post'));
  336. $banInfo->sendNotice = intval($this->getInput('sendnotice', 'post'));
  337. $do->setBanInfo($banInfo)->setBanUids($this->getInput('uids', 'post'))->setDeletes($this->getInput('delete', 'post'));
  338. } else {
  339. /* @var $banService PwUserBanService */
  340. $banService = Wekit::load('user.srv.PwUserBanService');
  341. $uid = $this->getInput('uid', 'get');
  342. if ($uid) {
  343. $do->setBanUids($uid);
  344. }
  345. $info = $do->getBanUsers();
  346. $this->setOutput($banService->getBanType(), 'types');
  347. $this->setOutput($info, 'userNames');
  348. $this->setOutput(count($info), 'count');
  349. $this->setOutput($do->getRight(), 'right');
  350. $this->setOutput('doban', 'doaction');
  351. $this->setOutput('用户禁止', 'title');
  352. }
  353. return $do;
  354. }
  355. /* (non-PHPdoc)
  356. * @see WindController::resolvedActionMethod()
  357. */
  358. public function resolvedActionMethod($handlerAdapter) {
  359. return $this->resolvedActionName('manage');
  360. }
  361. /**
  362. * send messages
  363. */
  364. protected function _sendMessage($action, $threads) {
  365. if (!is_array($threads) || !$threads || !$action || $action == 'doban') return false;
  366. $noticeService = Wekit::load('message.srv.PwNoticeService');
  367. $reason = htmlentities($this->getInput('reason', 'post'));
  368. foreach ($threads as $thread) {
  369. $params = array();
  370. $params['manageUsername'] = $this->manage->user->username;
  371. $params['manageUserid'] = $this->manage->user->uid;
  372. $params['manageThreadTitle'] = $thread['subject'];
  373. $params['manageThreadId'] = $thread['tid'];
  374. //$this->params['_other']['reason'] && $params['manageReason'] = $this->params['_other']['reason'];
  375. $reason && $params['manageReason'] = $reason;
  376. if ($action == 'docombined') {
  377. $actions = $this->getInput('actions', 'post');
  378. $tmp = array();
  379. foreach ($actions as $v){
  380. $tmp[] = $this->_getManageActionName('do' . $v);
  381. }
  382. $tmp && $params['manageTypeString'] = implode(',', $tmp);
  383. } else {
  384. $params['manageTypeString'] = $this->_getManageActionName($action);
  385. }
  386. $noticeService->sendNotice($thread['created_userid'], 'threadmanage', $thread['tid'], $params);
  387. }
  388. }
  389. protected function _getManageActionName($action) {
  390. $resource = Wind::getComponent('i18n');
  391. $message = $resource->getMessage("BBS:manage.operate.name.$action");
  392. if (in_array($action, $this->doCancel)) {
  393. $message = $resource->getMessage("BBS:manage.operate.action.cancel") . $message;
  394. }
  395. return $message;
  396. }
  397. protected function _getFroumService() {
  398. return Wekit::load('forum.srv.PwForumService');
  399. }
  400. }