PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/core/module/album.module.php

https://github.com/alin40404/FanweShare
PHP | 415 lines | 343 code | 68 blank | 4 comment | 49 complexity | 12f4bcf92d3d8afd4445d00a0e57985f MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. class AlbumModule
  3. {
  4. public function index()
  5. {
  6. global $_FANWE;
  7. //专辑flash
  8. $flash_album = FS("Album")->getFlashAlbums(3);
  9. //推荐专辑
  10. $best_album = FS("Album")->getBestAlbums(6);
  11. //最新专辑作者
  12. $new_users = FS("Album")->getNewUsers(6);
  13. //最热专辑作者
  14. $hot_users = FS("Album")->getHotUsers(6);
  15. $page_args = array();
  16. $sort = $_FANWE['request']['sort'];
  17. switch($sort)
  18. {
  19. case 'new':
  20. $page_args['sort'] = 'new';
  21. $order = " ORDER BY share_id DESC";
  22. break;
  23. default:
  24. $sort = 'hot';
  25. $page_args['sort'] = 'hot';
  26. $order = " ORDER BY collect_count DESC";
  27. break;
  28. }
  29. $sql = 'SELECT COUNT(DISTINCT share_id) FROM '.FDB::table('album_share');
  30. $count = FDB::resultFirst($sql);
  31. $share_list = array();
  32. $share_display = array();
  33. if($count > 0)
  34. {
  35. $pager = buildPage('album/'.ACTION_NAME,$page_args,$count,$_FANWE['page'],40);
  36. $share_list = FDB::fetchAll('SELECT * FROM '.FDB::table('share').'
  37. WHERE status = 1 AND type = \'album_item\''.$order.' LIMIT '.$pager['limit']);
  38. $share_list = FS('Share')->getShareDetailList($share_list,false,false,false,true,2);
  39. $col = 4;
  40. $index = 0;
  41. $share_display = array();
  42. foreach($share_list as $share)
  43. {
  44. $share['empty_content'] = sprintf(lang('album','rel_album_empty_content'),$share['title']);
  45. $mod = $index % $col;
  46. $share_display['col'.$mod][] = $share;
  47. $index++;
  48. }
  49. }
  50. include template('page/album/album_index');
  51. display();
  52. }
  53. public function show()
  54. {
  55. global $_FANWE;
  56. $id = (int)$_FANWE['request']['id'];
  57. if(!$id)
  58. exit;
  59. $album = FS("Album")->getAlbumById($id);
  60. if(empty($album))
  61. fHeader("location: ".FU('album'));
  62. $album_share = FS("Share")->getShareById($album['share_id']);
  63. $album_comments = FS('Share')->getShareCommentList($album['share_id'],'0,5');
  64. $album_cate = $_FANWE['cache']['albums']['category'][$album['cid']];
  65. $_FANWE['nav_title'] = $album['title'].' - '.$album_cate['name'].$_FANWE['nav_title'];
  66. $album_user = FS('User')->getUserById($album['uid']);
  67. $is_follow_user = false;
  68. $is_best_album = false;
  69. if($_FANWE['uid'] > 0 && $_FANWE['uid'] != $album['uid'])
  70. {
  71. $is_best_album = FS('Album')->getIsBest($id,$_FANWE['uid']);
  72. }
  73. $is_manage_album = false;
  74. if($_FANWE['uid'] == $album['uid'])
  75. $is_manage_album = true;
  76. $show_types = array(1,2,3);
  77. $show_type = (int)$_FANWE['request']['type'];
  78. if(!in_array($show_type,$show_types))
  79. $show_type = $album['show_type'];
  80. switch($show_type)
  81. {
  82. case 1:
  83. $page_size = 39;
  84. $page_col_num = 4;
  85. $page_col_class = '';
  86. break;
  87. case 3:
  88. $page_size = 19;
  89. $page_col_num = 2;
  90. $page_col_class = 'two_c';
  91. break;
  92. case 2:
  93. default:
  94. $page_size = 29;
  95. $page_col_num = 3;
  96. $page_col_class = 'three_c';
  97. break;
  98. }
  99. $page_args = array();
  100. $page_args['id'] = $id;
  101. $page_args['type'] = $show_type;
  102. $count = $album['share_count'];
  103. $share_display = array();
  104. if($count > 0)
  105. {
  106. $sid = (int)$_FANWE['request']['sid'];
  107. $pager = buildPage('album/show',$page_args,$count,$_FANWE['page'],$page_size);
  108. $share_ids = array();
  109. if($sid > 0)
  110. {
  111. $sql = 'SELECT share_id FROM '.FDB::table('album_share').'
  112. WHERE album_id = '.$id.' AND share_id = '.$sid;
  113. $sid = (int)FDB::resultFirst($sql);
  114. $share_ids[] = $sid;
  115. }
  116. $res = FDB::query('SELECT share_id FROM '.FDB::table('album_share').'
  117. WHERE album_id = '.$id.' ORDER BY share_id DESC LIMIT '.$pager['limit']);
  118. while($data = FDB::fetch($res))
  119. {
  120. if($data['share_id'] != $sid)
  121. $share_ids[] = $data['share_id'];
  122. }
  123. if(count($share_ids) > 0)
  124. {
  125. $share_ids = implode(',',$share_ids);
  126. $share_list = FDB::fetchAll('SELECT * FROM '.FDB::table('share').'
  127. WHERE share_id IN ('.$share_ids.') ORDER BY share_id DESC');
  128. $share_list = FS('Share')->getShareDetailList($share_list,false,false,false,true,2);
  129. if($sid > 0)
  130. {
  131. $share = $share_list[$sid];
  132. unset($share_list[$sid]);
  133. array_unshift($share_list,$share);
  134. }
  135. $index = 0;
  136. foreach($share_list as $share)
  137. {
  138. $share['empty_content'] = sprintf(lang('album','rel_album_empty_content'),$share['title']);
  139. $mod = $index % $page_col_num;
  140. $share_display['col'.$mod][] = $share;
  141. $index++;
  142. }
  143. }
  144. }
  145. $other_album = array();
  146. if($album_user['albums'] > 1)
  147. {
  148. $sql = 'SELECT * FROM '.FDB::table('album').'
  149. WHERE uid = '.$album_user['uid'].' AND img_count > 0 AND id <> '.$id.' LIMIT 0,3';
  150. $res = FDB::query($sql);
  151. while($data = FDB::fetch($res))
  152. {
  153. $data['imgs'] = array();
  154. if(!empty($data['cache_data']))
  155. {
  156. $cache_data = fStripslashes(unserialize($data['cache_data']));
  157. $data['imgs'] = $cache_data['imgs'];
  158. unset($data['cache_data']);
  159. }
  160. $data['url'] = FU('album/show',array('id'=>$data['id']));
  161. $other_album[] = $data;
  162. }
  163. }
  164. include template('page/album/album_show');
  165. display();
  166. }
  167. public function category()
  168. {
  169. global $_FANWE;
  170. global $_FANWE;
  171. $id = (int)$_FANWE['request']['id'];
  172. if(!$id)
  173. fHeader("location: ".FU('album'));
  174. if(!isset($_FANWE['cache']['albums']['category'][$id]))
  175. fHeader("location: ".FU('album'));
  176. $album_cate = $_FANWE['cache']['albums']['category'][$id];
  177. $_FANWE['nav_title'] = $album_cate['name'].$_FANWE['nav_title'];
  178. $page_args = array();
  179. $page_args['id'] = $id;
  180. $sort = $_FANWE['request']['sort'];
  181. switch($sort)
  182. {
  183. case 'new':
  184. $page_args['sort'] = 'new';
  185. $order = " ORDER BY s.share_id DESC";
  186. break;
  187. default:
  188. $sort = 'hot';
  189. $page_args['sort'] = 'hot';
  190. $order = " ORDER BY s.collect_count DESC";
  191. break;
  192. }
  193. $where = ' WHERE a.cid = '.$id;
  194. $sql = 'SELECT COUNT(DISTINCT share_id) FROM '.FDB::table('album_share').' AS a '.$where;
  195. $count = FDB::resultFirst($sql);
  196. $share_list = array();
  197. $share_display = array();
  198. if($count > 0)
  199. {
  200. $pager = buildPage('album/'.ACTION_NAME,$page_args,$count,$_FANWE['page'],40);
  201. $share_list = FDB::fetchAll('SELECT * FROM '.FDB::table('album_share').' AS a
  202. INNER JOIN '.FDB::table('share').' AS s ON s.share_id = a.share_id '.$where.'
  203. AND s.status = 1 AND s.type = \'album_item\''.$order.' LIMIT '.$pager['limit']);
  204. $share_list = FS('Share')->getShareDetailList($share_list,false,false,false,true,2);
  205. $col = 4;
  206. $index = 0;
  207. $share_display = array();
  208. foreach($share_list as $share)
  209. {
  210. $share['empty_content'] = sprintf(lang('album','rel_album_empty_content'),$share['title']);
  211. $mod = $index % $col;
  212. $share_display['col'.$mod][] = $share;
  213. $index++;
  214. }
  215. }
  216. include template('page/album/album_category');
  217. display();
  218. }
  219. public function tag()
  220. {
  221. global $_FANWE;
  222. global $_FANWE;
  223. $tag = trim($_FANWE['request']['tag']);
  224. if(empty($tag))
  225. fHeader("location: ".FU('album'));
  226. }
  227. public function create()
  228. {
  229. global $_FANWE;
  230. if($_FANWE['uid'] == 0)
  231. fHeader("location: ".FU('user/login'));
  232. include template('page/album/album_create');
  233. display();
  234. }
  235. public function edit()
  236. {
  237. global $_FANWE;
  238. if($_FANWE['uid'] == 0)
  239. fHeader("location: ".FU('user/login'));
  240. $id = (int)$_FANWE['request']['id'];
  241. if(!$id)
  242. fHeader("location: ".FU('album'));
  243. $album = FS("Album")->getAlbumById($id);
  244. if(empty($album) || $album['uid'] != $_FANWE['uid'])
  245. fHeader("location: ".FU('album'));
  246. $album['tags'] = implode(' ',$album['tags']);
  247. include template('page/album/album_edit');
  248. display();
  249. }
  250. public function save()
  251. {
  252. global $_FANWE;
  253. if($_FANWE['uid'] == 0)
  254. fHeader("location: ".FU('user/login'));
  255. $id = (int)$_FANWE['request']['id'];
  256. if($id > 0)
  257. {
  258. $album = FS("Album")->getAlbumById($id);
  259. if(empty($album) || $album['uid'] != $_FANWE['uid'])
  260. fHeader("location: ".FU('album'));
  261. }
  262. $data = array(
  263. 'title' => trim($_FANWE['request']['title']),
  264. 'content' => trim($_FANWE['request']['content']),
  265. 'cid' => (int)$_FANWE['request']['cid'],
  266. 'show_type' => (int)$_FANWE['request']['show_type'],
  267. 'tags' => trim($_FANWE['request']['tags']),
  268. );
  269. $vservice = FS('Validate');
  270. $validate = array(
  271. array('title','required',lang('album','name_require')),
  272. array('title','max_length',lang('album','name_max'),60),
  273. array('content','max_length',lang('album','content_max'),1000),
  274. array('cid','min',lang('album','cid_min'),1),
  275. array('show_type','min',lang('album','show_type_min'),1),
  276. );
  277. if(!$vservice->validation($validate,$data))
  278. exit($vservice->getError());
  279. if(!isset($_FANWE['cache']['albums']['category'][$data['cid']]))
  280. exit;
  281. if(!checkIpOperation("add_share",SHARE_INTERVAL_TIME))
  282. {
  283. showError('提交失败',lang('share','interval_tips'),-1);
  284. }
  285. $check_result = FS('Share')->checkWord($_FANWE['request']['title'],'title');
  286. if($check_result['error_code'] == 1)
  287. {
  288. showError('提交失败',$check_result['error_msg'],-1);
  289. }
  290. $check_result = FS('Share')->checkWord($_FANWE['request']['content'],'content');
  291. if($check_result['error_code'] == 1)
  292. {
  293. showError('提交失败',$check_result['error_msg'],-1);
  294. }
  295. $check_result = FS('Share')->checkWord($_FANWE['request']['tags'],'tag');
  296. if($check_result['error_code'] == 1)
  297. {
  298. showError('提交失败',$check_result['error_msg'],-1);
  299. }
  300. $tags = str_replace('***','',$_FANWE['request']['tags']);
  301. $tags = str_replace(' ',' ',$tags);
  302. $tags = explode(' ',$tags);
  303. $tags = array_unique($tags);
  304. if(count($tags) > $_FANWE['cache']['albums']['setting']['album_tag_count'])
  305. exit;
  306. if($id > 0)
  307. {
  308. $data['title'] = htmlspecialchars($_FANWE['request']['title']);
  309. $data['content'] = htmlspecialchars($_FANWE['request']['content']);
  310. $data['tags'] = implode(' ',$tags);
  311. FDB::update('album',$data,'id = '.$id);
  312. FS('Share')->updateShare($album['share_id'],$data['title'],$data['content']);
  313. FS("Album")->saveTags($id,$tags);
  314. if($data['cid'] != $album['cid'])
  315. {
  316. FDB::query('UPDATE '.FDB::table("album_share").' SET cid = '.$data['cid'].' WHERE album_id = '.$id);
  317. }
  318. $url = FU('album/show',array('id'=>$id));
  319. fHeader('location: '.$url);
  320. exit;
  321. }
  322. $_FANWE['request']['uid'] = $_FANWE['uid'];
  323. $_FANWE['request']['type'] = 'album';
  324. $share = FS('Share')->submit($_FANWE['request']);
  325. if($share['status'])
  326. {
  327. $data['title'] = htmlspecialchars($_FANWE['request']['title']);
  328. $data['content'] = htmlspecialchars($_FANWE['request']['content']);
  329. $data['tags'] = implode(' ',$tags);
  330. $data['uid'] = $_FANWE['uid'];
  331. $data['share_id'] = $share['share_id'];
  332. $data['create_day'] = getTodayTime();
  333. $data['create_time'] = TIME_UTC;
  334. $aid = FDB::insert('album',$data,true);
  335. FS("Album")->saveTags($aid,$tags);
  336. FDB::query('UPDATE '.FDB::table('share').' SET rec_id = '.$aid.'
  337. WHERE share_id = '.$share['share_id']);
  338. FDB::query("update ".FDB::table("user_count")." set albums = albums + 1 where uid = ".$_FANWE['uid']);
  339. FS('Medal')->runAuto($_FANWE['uid'],'albums');
  340. $url = FU('album/show',array('id'=>$aid));
  341. fHeader('location: '.$url);
  342. }
  343. else
  344. showError('提交失败','添加数据失败',-1);
  345. }
  346. }
  347. ?>