PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/src/applications/my/controller/FreshController.php

https://gitlab.com/wuhang2003/phpwind
PHP | 265 lines | 206 code | 35 blank | 24 comment | 34 complexity | d6801162e6f46b0874b8c4ad5471aae4 MD5 | raw file
  1. <?php
  2. defined('WEKIT_VERSION') || exit('Forbidden');
  3. Wind::import('SRV:attention.srv.PwFreshDisplay');
  4. Wind::import('SRV:attention.srv.dataSource.PwFetchAttentionFresh');
  5. /**
  6. * Enter description here ...
  7. *
  8. * @copyright ©2003-2103 phpwind.com
  9. * @license http://www.windframework.com
  10. * @version $Id: FreshController.php 28843 2013-05-28 01:57:37Z jieyin $
  11. * @package wind
  12. */
  13. class FreshController extends PwBaseController {
  14. /* (non-PHPdoc)
  15. * @see PwBaseController::beforeAction()
  16. */
  17. public function beforeAction($handlerAdapter) {
  18. parent::beforeAction($handlerAdapter);
  19. if (!$this->loginUser->isExists()) {
  20. $this->forwardAction('u/login/run', array('backurl' => WindUrlHelper::createUrl('my/fresh/run')));
  21. }
  22. }
  23. /* (non-PHPdoc)
  24. * @see WindController::run()
  25. */
  26. public function run() {
  27. $page = intval($this->getInput('page', 'get'));
  28. $page < 1 && $page = 1;
  29. $perpage = 20;
  30. list($start, $limit) = Pw::page2limit($page, $perpage);
  31. $gid = $this->getInput('gid');
  32. $url = array();
  33. if ($gid) {
  34. $url['gid'] = $gid;
  35. $current = $gid;
  36. $user = Wekit::load('attention.PwAttentionType')->getUserByType($this->loginUser->uid, $gid, 2000);
  37. $uids = array_keys($user);
  38. $count = $this->_getService()->countAttentionFreshByUid($this->loginUser->uid, $uids);
  39. Wind::import('SRV:attention.srv.dataSource.PwFetchAttentionFreshByUid');
  40. $dataSource = new PwFetchAttentionFreshByUid($this->loginUser->uid, $uids, $limit, $start);
  41. } else {
  42. $current = 'all';
  43. $count = $this->_getService()->countAttentionFresh($this->loginUser->uid);
  44. if ($count > 200) {
  45. $count > 250 && Wekit::load('attention.PwFresh')->deleteAttentionFresh($this->loginUser->uid, $count - 200);
  46. $count = 200;
  47. }
  48. Wind::import('SRV:attention.srv.dataSource.PwFetchAttentionFresh');
  49. $dataSource = new PwFetchAttentionFresh($this->loginUser->uid, $limit, $start);
  50. }
  51. $freshDisplay = new PwFreshDisplay($dataSource);
  52. $fresh = $freshDisplay->gather();
  53. $type = Wekit::load('attention.srv.PwAttentionService')->getAllType($this->loginUser->uid);
  54. $unpost = '';
  55. !$this->loginUser->info['lastpost'] && $this->loginUser->info['lastpost'] = $this->loginUser->info['regdate'];
  56. $tmp = Pw::getTime() - $this->loginUser->info['lastpost'];
  57. if ($tmp > 31536000) {
  58. $unpost = floor($tmp / 31536000) . '年多';
  59. } elseif ($tmp > 2592000) {
  60. $unpost = floor($tmp / 2592000) . '个多月';
  61. } elseif ($tmp > 172800) {
  62. $unpost = floor($tmp / 86400) . '天';
  63. }
  64. $type = Wekit::load('attention.srv.PwAttentionService')->getAllType($this->loginUser->uid);
  65. $allowUpload = $this->loginUser->getPermission('allow_upload');
  66. if ($imgextsize = Pw::subArray(Wekit::C('attachment', 'extsize'), array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
  67. $maxSize = max($imgextsize) . ' KB';
  68. $filetypes = '*.' . implode(';*.', array_keys($imgextsize));
  69. $attachnum = intval(Wekit::C('attachment', 'attachnum'));
  70. if ($perday = $this->loginUser->getPermission('uploads_perday')) {
  71. $todayupload = $this->loginUser->info['lastpost'] < Pw::getTdtime() ? 0 : $this->loginUser->info['todayupload'];
  72. $attachnum = max(min($attachnum, $perday - $todayupload), 0);
  73. $attachnum == 0 && $allowUpload = 0;
  74. }
  75. } else {
  76. $allowUpload = $attachnum = $maxSize = 0;
  77. $filetypes = '';
  78. }
  79. $this->setOutput($allowUpload, 'allowUpload');
  80. $this->setOutput($attachnum, 'attachnum');
  81. $this->setOutput($maxSize, 'maxSize');
  82. $this->setOutput($filetypes, 'filetypes');
  83. $this->setOutput($current, 'currents');
  84. $this->setOutput($type, 'type');
  85. $this->setOutput($unpost, 'unpost');
  86. $this->setOutput($fresh, 'freshdb');
  87. $this->setOutput($this->loginUser->getPermission('fresh_delete'), 'freshDelete');
  88. $this->setOutput($page, 'page');
  89. $this->setOutput($perpage, 'perpage');
  90. $this->setOutput($count, 'count');
  91. $this->setOutput($url, 'url');
  92. // seo设置
  93. Wind::import('SRV:seo.bo.PwSeoBo');
  94. $seoBo = PwSeoBo::getInstance();
  95. $lang = Wind::getComponent('i18n');
  96. $seoBo->setCustomSeo($lang->getMessage('SEO:bbs.fresh.run.title'), '', '');
  97. Wekit::setV('seo', $seoBo);
  98. }
  99. public function replyAction() {
  100. $id = $this->getInput('id');
  101. Wind::import('SRV:attention.srv.PwFreshReplyList');
  102. $reply = new PwFreshReplyList($id);
  103. $fresh = $reply->getData();
  104. $replies = $reply->getReplies(7);
  105. $replies = Wekit::load('forum.srv.PwThreadService')->displayReplylist($replies);
  106. $count = count($replies);
  107. if ($count > 6) {
  108. $replies = array_slice($replies, 0, 6, true);
  109. }
  110. $this->setOutput($count, 'count');
  111. $this->setOutPut($replies, 'replies');
  112. $this->setOutPut($fresh, 'fresh');
  113. }
  114. public function doreplyAction() {
  115. $id = $this->getInput('id');
  116. $content = $this->getInput('content', 'post');
  117. $transmit = $this->getInput('transmit', 'post');
  118. Wind::import('SRV:attention.srv.PwFreshReplyPost');
  119. $reply = new PwFreshReplyPost($id, $this->loginUser);
  120. if (($result = $reply->check()) !== true) {
  121. $this->showError($result->getError());
  122. }
  123. $reply->setContent($content);
  124. $reply->setIsTransmit($transmit);
  125. if (($result = $reply->execute()) instanceof PwError) {
  126. $this->showError($result->getError());
  127. }
  128. if (!$reply->getIscheck()) {
  129. $this->showError('BBS:post.reply.ischeck');
  130. }
  131. $content = Wekit::load('forum.srv.PwThreadService')->displayContent($content, $reply->getIsuseubb(), $reply->getRemindUser());
  132. /*
  133. $content = WindSecurity::escapeHTML($content);
  134. if ($reply->getIsuseubb()) {
  135. Wind::import('LIB:ubb.PwSimpleUbbCode');
  136. Wind::import('LIB:ubb.config.PwUbbCodeConvertThread');
  137. $content = PwSimpleUbbCode::convert($content, 140, new PwUbbCodeConvertThread());
  138. }*/
  139. $fresh = array();
  140. if ($transmit && ($newId = $reply->getNewFreshSrcId())) {
  141. Wind::import('SRV:attention.srv.dataSource.PwFetchFreshByTypeAndSrcId');
  142. $data = $reply->getData();
  143. $freshDisplay = new PwFreshDisplay(new PwFetchFreshByTypeAndSrcId($data['type'] == 3 ? 3 : 2, array($newId)));
  144. $fresh = $freshDisplay->gather();
  145. $fresh = current($fresh);
  146. }
  147. $this->setOutPut(Pw::getTime(), 'timestamp');
  148. $this->setOutPut($content, 'content');
  149. $this->setOutPut($this->loginUser->uid, 'uid');
  150. $this->setOutPut($this->loginUser->username, 'username');
  151. $this->setOutPut($fresh, 'fresh');
  152. }
  153. public function readAction() {
  154. Wind::import('SRV:forum.bo.PwThreadBo');
  155. $id = $this->getInput('id');
  156. $fresh = $this->_getService()->getFresh($id);
  157. if ($fresh['type'] == 1) {
  158. $thread = new PwThreadBo($fresh['src_id']);
  159. $array = $thread->info;
  160. $array['pid'] = 0;
  161. } else {
  162. $array = $this->_getThread()->getPost($fresh['src_id']);
  163. $thread = new PwThreadBo($array['tid']);
  164. }
  165. Wind::import('LIB:ubb.PwUbbCode');
  166. Wind::import('LIB:ubb.config.PwUbbCodeConvertThread');
  167. $array['content'] = WindSecurity::escapeHTML($array['content']);
  168. $array['content'] = str_replace("\n", '<br />', $array['content']);
  169. $array['useubb'] && $array['content'] = PwUbbCode::convert($array['content'], new PwUbbCodeConvertThread($thread, $array, $this->loginUser));
  170. echo $array['content'];
  171. $this->setTemplate('');
  172. //$this->setOutPut($array['content'], 'data');
  173. //$this->showMessage('success');
  174. }
  175. public function postAction() {
  176. $fid = $this->getInput('fid');
  177. $_getHtml = $this->getInput('_getHtml', 'get');
  178. list($content, $topictype, $subtopictype) = $this->getInput(array('content', 'topictype', 'sub_topictype'), 'post');
  179. Wind::import('SRV:forum.srv.post.PwTopicPost');
  180. Wind::import('SRV:forum.srv.PwPost');
  181. $postAction = new PwTopicPost($fid);
  182. $pwpost = new PwPost($postAction);
  183. $this->runHook('c_fresh_post', $pwpost);
  184. if (($result = $pwpost->check()) !== true) {
  185. $this->showError($result->getError());
  186. }
  187. $postDm = $pwpost->getDm();
  188. $postDm->setTitle(Pw::substrs(Pw::stripWindCode($content), 30))
  189. ->setContent($content);
  190. $topictype_id = $subtopictype ? $subtopictype : $topictype;
  191. $topictype_id && $postDm->setTopictype($topictype_id);
  192. if (($result = $pwpost->execute($postDm)) !== true) {
  193. $data = $result->getData();
  194. $data && $this->addMessage($data, 'data');
  195. $this->showError($result->getError());
  196. }
  197. if (!$postDm->getField('ischeck')) {
  198. $this->showMessage('BBS:post.topic.ischeck');
  199. } elseif ($_getHtml == 1) {
  200. Wind::import('SRV:attention.srv.dataSource.PwFetchFreshByTypeAndSrcId');
  201. $freshDisplay = new PwFreshDisplay(new PwFetchFreshByTypeAndSrcId(1, array($pwpost->getNewId())));
  202. $fresh = $freshDisplay->gather();
  203. $fresh = current($fresh);
  204. $this->setOutput($fresh, 'fresh');
  205. } else {
  206. $this->showMessage('success');
  207. }
  208. }
  209. public function deleteAction() {
  210. $id = $this->getInput('id', 'post');
  211. if (!$id) {
  212. $this->showError('operate.select');
  213. }
  214. if (!$this->loginUser->getPermission('fresh_delete')) {
  215. $this->showError('permission.fresh.delete.deny');
  216. }
  217. Wind::import('SRV:attention.srv.operation.PwDeleteFresh');
  218. Wind::import('SRV:attention.srv.dataSource.PwGetFreshById');
  219. $srv = new PwDeleteFresh(new PwGetFreshById($id), $this->loginUser);
  220. $srv->setIsDeductCredit(true)
  221. ->execute();
  222. $this->showMessage('success');
  223. }
  224. protected function _getService() {
  225. return Wekit::load('attention.PwFresh');
  226. }
  227. protected function _getThread() {
  228. return Wekit::load('forum.PwThread');
  229. }
  230. }