PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/code/apps/wap/Lib/Action/IndexAction.class.php

http://thinksns-2.googlecode.com/
PHP | 463 lines | 379 code | 56 blank | 28 comment | 54 complexity | 7a052d3131c504403a1b73b9e3e5d52a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class IndexAction extends BaseAction {
  3. // ????
  4. public function index($uid = 0) {
  5. $data['user_id'] = $uid <= 0 ? $this->mid : $uid;
  6. $data['page'] = $this->_page;
  7. // ????
  8. $profile = api('User')->data($data)->show();
  9. $this->assign('profile', $profile[0]);
  10. // ????
  11. $weibolist = api('Statuses')->data($data)->friends_timeline();
  12. $weibolist = $this->__formatByFavorite($weibolist);
  13. $weibolist = $this->__formatByContent($weibolist);
  14. $this->assign('weibolist', $weibolist);
  15. $this->display('index');
  16. }
  17. // ????
  18. public function publicsquare() {
  19. $data['page'] = $this->_page;
  20. $weibolist = api('Statuses')->data($data)->public_timeline();
  21. $weibolist = $this->__formatByFavorite($weibolist);
  22. $weibolist = $this->__formatByContent($weibolist);
  23. $this->assign('weibolist', $weibolist);
  24. $this->display();
  25. }
  26. // XX???
  27. public function weibo() {
  28. $data['user_id'] = $_GET['uid'] <= 0 ? $this->mid : $_GET['uid'];
  29. $data['page'] = $this->_page;
  30. // ????
  31. $profile = api('User')->data($data)->show();
  32. $this->assign('profile', $profile[0]);
  33. // ????
  34. $weibolist = api('Statuses')->data($data)->user_timeline();
  35. $weibolist = $this->__formatByFavorite($weibolist);
  36. $weibolist = $this->__formatByContent($weibolist);
  37. $this->assign('weibolist', $weibolist);
  38. $this->assign('hideUsername', '1');
  39. $this->display();
  40. }
  41. // @?
  42. public function atMe() {
  43. $data['page'] = $this->_page;
  44. // ????
  45. $profile = api('User')->data($data)->show();
  46. $this->assign('profile', $profile[0]);
  47. // @XX?????
  48. $weibolist = api('Statuses')->data($data)->mentions();
  49. $weibolist = $this->__formatByFavorite($weibolist);
  50. $weibolist = $this->__formatByContent($weibolist);
  51. $this->assign('weibolist', $weibolist);
  52. $this->display('weibo');
  53. }
  54. // ????
  55. public function favorite() {
  56. $data['page'] = $this->_page;
  57. // ????
  58. $profile = api('User')->data($data)->show();
  59. $this->assign('profile', $profile[0]);
  60. // ????
  61. $weibolist = api('Favorites')->data($data)->index();
  62. foreach ($weibolist as $k => $v) {
  63. $weibolist[$k]['is_favorite'] = 1;
  64. }
  65. $this->assign('weibolist', $weibolist);
  66. $this->display('weibo');
  67. }
  68. private function __formatByFavorite($weibolist) {
  69. $ids = implode(',', getSubByKey($weibolist, 'weibo_id'));
  70. $favorite = D('Favorite','weibo')->isFavorite($ids, $this->mid);
  71. foreach ($weibolist as $k => $v) {
  72. if ( in_array($v['weibo_id'], $favorite) ) {
  73. $weibolist[$k]['is_favorite'] = 1;
  74. }else {
  75. $weibolist[$k]['is_favorite'] = 0;
  76. }
  77. }
  78. return $weibolist;
  79. }
  80. private function __formatByContent($weibolist) {
  81. $self_url = urlencode($this->_self_url);
  82. foreach ($weibolist as $k => $v) {
  83. $weibolist[$k]['content'] = wapFormatContent($v['content'], true, $self_url);
  84. if ( isset($v['transpond_data']['content']) ) {
  85. $weibolist[$k]['transpond_data']['content'] = wapFormatContent($v['transpond_data']['content'], true, $self_url);
  86. }
  87. }
  88. return $weibolist;
  89. }
  90. private function __formatByComment($comment) {
  91. $self_url = urlencode($this->_self_url);
  92. foreach ($comment as $k => $v) {
  93. $comment[$k]['content'] = wapFormatComment($v['content'], true, $self_url);
  94. }
  95. return $comment;
  96. }
  97. // ????
  98. public function following() {
  99. $this->__followlist('following');
  100. }
  101. // ??
  102. public function topic() {
  103. $topic = D('Topic','weibo')->getHot();
  104. $this->assign('topic', $topic);
  105. $this->display();
  106. }
  107. // ????
  108. public function followers() {
  109. $this->__followlist('followers');
  110. }
  111. // ????
  112. public function detail() {
  113. $data['id'] = intval($_GET['weibo_id']);
  114. $detail = api('Statuses')->data($data)->show();
  115. $detail = $detail[0];
  116. $detail['is_favorite'] = api('Favorites')->data($data)->isFavorite() ? 1 : 0;
  117. $detail['content'] = wapFormatContent($detail['content'], true, urlencode($this->_self_url));
  118. $this->assign('weibo', $detail);
  119. $data['page'] = $this->_page;
  120. $comment = api('Statuses')->data($data)->comments();
  121. $comment = $this->__formatByComment($comment);
  122. $this->assign('comment', $comment);
  123. $this->display();
  124. }
  125. // ??
  126. public function image() {
  127. $weibo_id = intval($_GET['weibo_id']);
  128. if ($weibo_id <= 0) {
  129. redirect(U('wap/Index/index'), 3, '????');
  130. }
  131. $weibo = api('Statuses')->data(array('id'=>$weibo_id))->show();
  132. $weibo = $weibo[0];
  133. $image = intval($weibo['transpond_id']) == 0 ? $weibo['type_data'] : $weibo['transpond_data']['type_data'];
  134. if (empty($image)) {
  135. redirect(U('wap/Index/index'), 3, '?????');
  136. }
  137. $this->assign('weibo_id',$weibo_id);
  138. $this->assign('image', $image);
  139. $this->display();
  140. }
  141. private function __followlist($type) {
  142. $data['user_id'] = $_GET['uid'] <= 0 ? $this->mid : $_GET['uid'];
  143. $data['page'] = $this->_page;
  144. // ????
  145. $profile = api('User')->data($data)->show();
  146. $this->assign('profile', $profile[0]);
  147. // ??OR????
  148. $followlist = api('Statuses')->data($data)->$type();
  149. $this->assign('userlist', $followlist);
  150. $this->assign('type', $type);
  151. $this->display('followlist');
  152. }
  153. public function doFollow() {
  154. $user_id = intval($_GET['user_id']);
  155. if ( !in_array($_GET['from'], array('following', 'followers', 'search', 'weibo')) ||
  156. !in_array($_GET['type'], array('follow', 'unfollow')) ||
  157. $user_id <= 0 ) {
  158. redirect(U('wap/Index/index'), 3, '????');
  159. }
  160. $data['user_id'] = $user_id;
  161. $method = $_GET['type'] == 'follow' ? 'create' : 'destroy';
  162. switch ($_GET['from']) {
  163. case 'search':
  164. $target = U('wap/Index/doSearch',array('key'=>$_REQUEST['key'],'page'=>$_REQUEST['page'],'user'=>'1'));
  165. break;
  166. case 'weibo':
  167. $target = U('wap/Index/weibo', array('uid'=>$user_id));
  168. break;
  169. default:
  170. $target = U('wap/Index/'.$_GET['from']);
  171. }
  172. if ( api('Friendships')->data($data)->$method() ) {
  173. redirect($target, 1, '????');
  174. }else {
  175. redirect($target, 3, '????');
  176. }
  177. }
  178. public function post() {
  179. // ??????????
  180. $this->assign('keyword', isset($_REQUEST['key']) ? '#'.$_REQUEST['key'].'# ' : '');
  181. $this->display();
  182. }
  183. public function doPost() {
  184. if ( empty($_POST['content']) && $_FILES['pic'] ) {
  185. $_POST['content'] = '????';
  186. }
  187. if ( empty($_POST['content']) && !$_FILES['pic'] ) {
  188. redirect(U('wap/Index/index'), 3, '??????');
  189. }
  190. if (isset($_POST['nosplit'])) {
  191. $this->assign('content', $_POST['content']);
  192. $this->index();
  193. }
  194. $data = array();
  195. // ????
  196. $length = mb_strlen($_POST['content'], 'UTF8');
  197. $parts = ceil($length/140);
  198. if (!isset($_POST['split']) && $length > 140) {
  199. // ?????????
  200. if($_FILES['pic']){
  201. $data['pic'] = $_FILES['pic'];
  202. $data['content'] = '????';
  203. $data['from'] = $this->_type_wap;
  204. $res = api('Statuses')->data($data)->upload();
  205. }
  206. // ????????
  207. $this->assign('content', $_POST['content']);
  208. $this->assign('length', $length);
  209. $this->assign('parts', $parts);
  210. $this->display('split');
  211. }else {
  212. $api_method = 'update';
  213. if ($_FILES['pic']) {
  214. $data['pic'] = $_FILES['pic'];
  215. $api_method = 'upload';
  216. }
  217. // ???????
  218. for ($i = 1; $i <= $parts; $i++) {
  219. $sub_content = mb_substr($_POST['content'], 0, 140, 'UTF8');
  220. $data['content'] = $sub_content;
  221. $data['from'] = $this->_type_wap;
  222. $_POST['content'] = mb_substr($_POST['content'], 140, -1, 'UTF8');
  223. $res = api('Statuses')->data($data)->$api_method();
  224. if (!$res) {
  225. redirect(U('wap/Index/index'), 3, '??????????');
  226. }
  227. }
  228. redirect(U('wap/Index/index'), 1, '????');
  229. }
  230. }
  231. public function comment() {
  232. $weibo_id = intval($_GET['weibo_id']);
  233. $comment_id = intval($_GET['comment_id']);
  234. $uid = intval($_GET['uid']);
  235. if ( $weibo_id <= 0 || $comment_id <= 0 || $uid <= 0 ) {
  236. redirect(U('wap/Index/index'), 3, '????');
  237. }
  238. $this->assign('weibo_id', $weibo_id);
  239. $this->assign('comment_id', $comment_id);
  240. $this->assign('uname', getUserName($uid));
  241. $this->display();
  242. }
  243. public function doComment() {
  244. if ( ($weibo_id = intval($_POST['weibo_id'])) <= 0 ) {
  245. redirect(U('wap/Index/index'), 3, '????');
  246. }
  247. if ( empty($_POST['content']) ) {
  248. redirect(U('wap/Index/detail',array('weibo_id'=>$weibo_id)), 3, '??????');
  249. }
  250. // ???140?
  251. $_POST['content'] = mb_substr($_POST['content'], 0, 140, 'UTF8');
  252. $data['weibo_id'] = $weibo_id;
  253. $data['comment_content'] = $_POST['content'];
  254. $data['from'] = $this->_type_wap;
  255. $data['reply_comment_id'] = intval($_POST['comment_id']);
  256. $data['transpond'] = intval($_POST['transpond']);
  257. $res = api('Statuses')->data($data)->comment();
  258. if ($res) {
  259. redirect(U('wap/Index/detail', array('weibo_id'=>$weibo_id)), 1, '????');
  260. }else {
  261. redirect(U('wap/Index/detail', array('weibo_id'=>$weibo_id)), 3, '????, ?????');
  262. }
  263. }
  264. public function forward() {
  265. $weibo_id = intval($_GET['weibo_id']);
  266. if ( $weibo_id <= 0 ) {
  267. redirect(U('wap/Index/index'), 3, '????');
  268. }
  269. $data['id'] = $weibo_id;
  270. $weibo = api('Statuses')->data($data)->show();
  271. $weibo = $weibo[0];
  272. if (!$weibo) {
  273. redirect(U('wap/Index/index'), 3, '????');
  274. }
  275. $this->assign('weibo', $weibo);
  276. $this->display();
  277. }
  278. public function doForward() {
  279. $weibo_id = intval($_POST['weibo_id']);
  280. if ($weibo_id <= 0) {
  281. redirect(U('wap/Index/detail',array('weibo_id'=>$weibo_id)), 3, '????');
  282. }
  283. if (empty($_POST['content'])) {
  284. redirect(U('wap/Index/detail',array('weibo_id'=>$weibo_id)), 3, '??????');
  285. }
  286. $data['id'] = $weibo_id;
  287. $weibo = api('Statuses')->data($data)->show();
  288. unset($data);
  289. $weibo = $weibo[0];
  290. if ( empty($weibo) ) {
  291. redirect(U('wap/Index/index'), 3, '????');
  292. }
  293. // ????????
  294. if ( $weibo['transpond_id'] != 0 ) {
  295. $_POST['content'] .= "//@{$weibo['uname']}:{$weibo['content']}";
  296. }
  297. // ???140?
  298. $_POST['content'] = mb_substr($_POST['content'], 0, 140, 'UTF8');
  299. $data['content'] = $_POST['content'];
  300. $data['from'] = $this->_type_wap;
  301. $data['transpond_id'] = $weibo['transpond_id'] ? $weibo['transpond_id'] : $weibo_id;
  302. if (intval($_POST['isComment']) == 1) {
  303. $weibo = api('Statuses')->data(array('id'=>$weibo_id))->show();
  304. $weibo = $weibo[0];
  305. $data['reply_data'] = $weibo['weibo_id'];
  306. if ( !empty($weibo['transpond_data']) ) {
  307. $data['reply_data'] .= ',' . $weibo['transpond_data']['weibo_id'];
  308. }
  309. }
  310. $res = api('Statuses')->data($data)->repost();
  311. if ($res) {
  312. redirect(U('wap/Index/detail', array('weibo_id'=>$weibo_id)), 1, '????');
  313. }else {
  314. redirect(U('wap/Index/detail', array('weibo_id'=>$weibo_id)), 3, '????, ?????');
  315. }
  316. }
  317. public function doSearch() {
  318. if ( empty($_REQUEST['key']) ) {
  319. redirect(U('wap/Index/search'), 3, '??????');
  320. }
  321. if ( isset($_REQUEST['user']) ) {
  322. $method = 'searchuser';
  323. $display = 'searchuser';
  324. }else {
  325. $method = 'search';
  326. $display = 'searchweibo';
  327. }
  328. $data['key'] = $_REQUEST['key'];
  329. $data['page'] = $this->_page;
  330. $res = api('Statuses')->data($data)->$method();
  331. if ($display == 'searchuser') {
  332. $userlist = array();
  333. foreach ($res as $k => $v) {
  334. $userlist[$k]['user'] = $v;
  335. }
  336. $this->assign('userlist', $userlist);
  337. $this->assign('type', 'search');
  338. }else {
  339. $res = $this->__formatByFavorite($res);
  340. $res = $this->__formatByContent($res);
  341. $this->assign('weibolist', $res);
  342. }
  343. $this->assign('keyword', $_REQUEST['key']);
  344. $this->display($display);
  345. }
  346. public function doDelete() {
  347. $weibo_id = intval($_GET['weibo_id']);
  348. if ($weibo_id <= 0) {
  349. redirect(U('wap/Index/index', 3, '????'));
  350. }
  351. if ( !in_array($_GET['from'], array('index','weibo','doSearch','atMe','favorite')) ) {
  352. $_GET['from'] = 'index';
  353. }
  354. $target = U('wap/Index/'.$_GET['from'], array('key'=>$_GET['key'],'page'=>$_GET['page']));
  355. $data['id'] = $weibo_id;
  356. $res = api('Statuses')->data($data)->destroy();
  357. if ($res) {
  358. redirect($target, 1, '????');
  359. }else {
  360. redirect($target, 3, '??????????');
  361. }
  362. }
  363. public function doFavorite() {
  364. $weibo_id = intval($_GET['weibo_id']);
  365. if ($weibo_id <= 0) {
  366. redirect(U('wap/Index/index', 3, '????'));
  367. }
  368. if ( !in_array($_GET['from'], array('index','detail','weibo','doSearch','atMe','favorite')) ) {
  369. $_GET['from'] = 'index';
  370. }
  371. $_GET['key'] = urlencode($_GET['key']);
  372. $target = U('wap/Index/'.$_GET['from'], array('weibo_id'=>$weibo_id, 'key'=>$_GET['key'],'page'=>$_GET['page']));
  373. $data['id'] = $weibo_id;
  374. $res = api('Favorites')->data($data)->create();
  375. if ($res) {
  376. redirect($target, 1, '????');
  377. }else {
  378. redirect($target, 3, '??????????');
  379. }
  380. }
  381. public function doUnFavorite() {
  382. $weibo_id = intval($_GET['weibo_id']);
  383. if ($weibo_id <= 0) {
  384. redirect(U('wap/Index/index', 3, '????'));
  385. }
  386. if ( !in_array($_GET['from'], array('index','detail','weibo','doSearch','atMe','favorite')) ) {
  387. $_GET['from'] = 'index';
  388. }
  389. $_GET['key'] = urlencode($_GET['key']);
  390. $target = U('wap/Index/'.$_GET['from'], array('weibo_id'=>$weibo_id, 'key'=>$_GET['key'],'page'=>$_GET['page']));
  391. $data['id'] = $weibo_id;
  392. $res = api('Favorites')->data($data)->destroy();
  393. if ($res) {
  394. redirect($target, 1, '????');
  395. }else {
  396. redirect($target, 3, '??????????');
  397. }
  398. }
  399. public function urlalert() {
  400. if( !isset($_GET['url']) || !isset($_GET['from_url']) ) {
  401. redirect(U('wap/Index/index'), 3, '????');
  402. }
  403. $this->assign('url', $_GET['url']);
  404. $this->assign('from_url', $_GET['from_url']);
  405. $this->display();
  406. }
  407. }