control.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <?php
  2. /**
  3. * 圈子父类
  4. *
  5. *********************************/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. /********************************** 前台control父类 **********************************************/
  8. class BaseCircleControl{
  9. protected $identity = 0; // 身份 0游客 1圈主 2管理 3成员 4申请中 5申请失败 6禁言
  10. protected $c_id = 0; // 圈子id
  11. protected $cm_info = array(); // Members of the information
  12. protected $m_readperm = 0; // Members read permissions
  13. protected $super = 0;
  14. /**
  15. * 构造函数
  16. */
  17. public function __construct(){
  18. /**
  19. * 验证圈子是否开启
  20. */
  21. if (C('circle_isuse') != '1'){
  22. @header('location: '.SHOP_SITE_URL);die;
  23. }
  24. /**
  25. * 读取通用、布局的语言包
  26. */
  27. Language::read('common');
  28. /**
  29. * 设置布局文件内容
  30. */
  31. Tpl::setLayout('circle_layout');
  32. /**
  33. * 查询是否是超管
  34. */
  35. $this->checkSuper();
  36. /**
  37. * 获取导航
  38. */
  39. Tpl::output('nav_list',($nav = F('nav')) ? $nav : rkcache('nav',true,'file'));
  40. }
  41. private function checkSuper() {
  42. if($_SESSION['is_login']){
  43. $super = Model('circle_member')->getSuperInfo(array('member_id' => $_SESSION['member_id']));
  44. $this->super = empty($super) ? 0 : 1;
  45. }
  46. Tpl::output('super', $this->super);
  47. }
  48. /**
  49. * 圈子信息
  50. */
  51. protected function circleInfo(){
  52. $this->circle_info = Model()->table('circle')->find($this->c_id);
  53. if(empty($this->circle_info)){
  54. showMessage(L('circle_group_not_exists'), '', '', 'error');
  55. }
  56. Tpl::output('circle_info', $this->circle_info);
  57. }
  58. /**
  59. * 圈主和管理信息
  60. */
  61. protected function manageList(){
  62. $prefix = 'circle_managelist';
  63. $manager_list = rcache($this->c_id, $prefix);
  64. if (empty($manager_list)) {
  65. $manager_list = Model()->table('circle_member')->where(array('circle_id'=>$this->c_id, 'is_identity'=>array('in', array(1,2))))->select();
  66. $manager_list = array_under_reset($manager_list, 'is_identity', 2);
  67. $manager_list[2] = array_under_reset($manager_list[2], 'member_id', 1);
  68. wcache($this->c_id,$manager_list,$prefix);
  69. }
  70. Tpl::output('creator', $manager_list[1][0]);
  71. Tpl::output('manager_list', $manager_list[2]);
  72. }
  73. /**
  74. * 会员信息
  75. */
  76. protected function memberInfo(){
  77. if($_SESSION['is_login']){
  78. $this->cm_info = Model()->table('circle_member')->where(array('circle_id'=>$this->c_id, 'member_id'=>$_SESSION['member_id']))->find();
  79. if(!empty($this->cm_info)){
  80. switch (intval($this->cm_info['cm_state'])){
  81. case 1:
  82. $this->identity = intval($this->cm_info['is_identity']);
  83. break;
  84. case 0:
  85. $this->identity = 4;
  86. break;
  87. case 2:
  88. $this->identity = 5;
  89. break;
  90. }
  91. // 禁言
  92. if($this->cm_info['is_allowspeak'] == 0){
  93. $this->identity = 6;
  94. }
  95. }
  96. Tpl::output('cm_info', $this->cm_info);
  97. }
  98. Tpl::output('identity', $this->identity);
  99. }
  100. /**
  101. * sidebar相关信息
  102. */
  103. protected function sidebar(){
  104. $prefix = 'circle_sidebar';
  105. $data = rcache($this->c_id, $prefix);
  106. if (empty($data)) {
  107. // 圈子所属分类
  108. $data['class_info'] = Model()->table('circle_class')->find($this->circle_info['class_id']);
  109. // 明星圈友
  110. $data['star_member'] = Model()->table('circle_member')->where(array('cm_state'=>1, 'circle_id'=>$this->c_id, 'is_star'=>1))->order('rand()')->limit(5)->select();
  111. // 最新加入
  112. $data['newest_member'] = Model()->table('circle_member')->where(array('cm_state'=>1, 'circle_id'=>$this->c_id))->order('cm_jointime desc')->limit(5)->select();
  113. // 友情圈子
  114. $data['friendship_list'] = Model()->table('circle_fs')->where(array('circle_id'=>$this->c_id, 'friendship_status'=>1))->order('friendship_sort asc')->select();
  115. }
  116. Tpl::output('class_info', $data['class_info']);
  117. Tpl::output('star_member', $data['star_member']);
  118. Tpl::output('newest_member', $data['newest_member']);
  119. Tpl::output('friendship_list', $data['friendship_list']);
  120. }
  121. /**
  122. * 最新话题/热门话题/人气回复
  123. */
  124. protected function themeTop(){
  125. $prefix = 'circle_themetop';
  126. $data = rcache('circle', $prefix);
  127. if (empty($data)) {
  128. $model = Model();
  129. // 最新话题
  130. $data['new_themelist'] = $model->table('circle_theme')->where(array('is_closed'=>0))->order('theme_id desc')->limit(10)->select();
  131. // 热门话题
  132. $data['hot_themelist'] = $model->table('circle_theme')->where(array('is_closed'=>0))->order('theme_browsecount desc')->limit(10)->select();
  133. // 人气回复
  134. $data['reply_themelist'] = $model->table('circle_theme')->where(array('is_closed'=>0))->order('theme_commentcount desc')->limit(10)->select();
  135. }
  136. Tpl::output('new_themelist', $data['new_themelist']);
  137. Tpl::output('hot_themelist', $data['hot_themelist']);
  138. Tpl::output('reply_themelist', $data['reply_themelist']);
  139. }
  140. /**
  141. * SEO
  142. */
  143. protected function circleSEO($title= '') {
  144. Tpl::output('html_title',$title.' '.C('circle_seotitle').'');
  145. Tpl::output('seo_keywords',C('circle_seokeywords'));
  146. Tpl::output('seo_description',C('circle_seodescription'));
  147. }
  148. /**
  149. * Read permissions
  150. */
  151. protected function readPermissions($cm_info){
  152. $data = rkcache('circle_level') ? rkcache('circle_level') : rkcache('circle_level', true);
  153. $rs = array();
  154. $rs[0] = 0;
  155. $rs[0] = L('circle_no_limit');
  156. foreach ($data as $v){
  157. $rs[$v['mld_id']] = $v['mld_name'];
  158. }
  159. switch ($cm_info['is_identity']){
  160. case 1:
  161. case 2:
  162. $rs['255'] = L('circle_administrator');
  163. $this->m_readperm = 255;
  164. return $rs;
  165. break;
  166. case 3:
  167. $rs = array_slice($rs, 0, intval($cm_info['cm_level'])+1, true);
  168. $this->m_readperm = $cm_info['cm_level'];
  169. return $rs;
  170. break;
  171. }
  172. }
  173. /**
  174. * breadcrumb navigation
  175. */
  176. protected function breadcrumd($param = ''){
  177. $crumd = array(
  178. 0=>array(
  179. 'link'=>CIRCLE_SITE_URL,
  180. 'title'=>L('nc_index')
  181. ),
  182. 1=>array(
  183. 'link'=>CIRCLE_SITE_URL.'/index.php?act=group&c_id='.$this->c_id,
  184. 'title'=>$this->circle_info['circle_name']
  185. ),
  186. );
  187. if(!empty($this->theme_info)){
  188. $crumd[2] = array(
  189. 'link'=>CIRCLE_SITE_URL.'/index.php?act=theme&op=theme_detail&c_id='.$this->c_id.'&t_id='.$this->t_id,
  190. 'title'=>$this->theme_info['theme_name']
  191. );
  192. }
  193. if(empty($param)){
  194. unset($crumd[(count($crumd)-1)]['link']);
  195. }else{
  196. $crumd[]['title'] = $param;
  197. }
  198. Tpl::output('breadcrumd', $crumd);
  199. }
  200. }
  201. class BaseCircleThemeControl extends BaseCircleControl{
  202. protected $circle_info = array(); // 圈子详细信息
  203. protected $t_id = 0; // 话题id
  204. protected $theme_info = array(); // 话题详细信息
  205. protected $r_id = 0; // 回复id
  206. protected $reply_info = array(); // reply info
  207. protected $cm_info = array(); // Members of the information
  208. public function __construct(){
  209. parent::__construct();
  210. Language::read('circle');
  211. $this->c_id = intval($_GET['c_id']);
  212. if($this->c_id <= 0){
  213. @header("location: ".CIRCLE_SITE_URL);
  214. }
  215. Tpl::output('c_id', $this->c_id);
  216. }
  217. /**
  218. * 话题信息
  219. */
  220. protected function themeInfo(){
  221. $this->t_id = intval($_GET['t_id']);
  222. if($this->t_id <= 0){
  223. @header("location: ".CIRCLE_SITE_URL);
  224. }
  225. Tpl::output('t_id', $this->t_id);
  226. $this->theme_info = Model()->table('circle_theme')->where(array('circle_id'=>$this->c_id, 'theme_id'=>$this->t_id))->find();
  227. if(empty($this->theme_info)){
  228. showMessage(L('circle_theme_not_exists'), '', '', 'error');
  229. }
  230. Tpl::output('theme_info', $this->theme_info);
  231. }
  232. /**
  233. * 验证回复
  234. */
  235. protected function checkReplySelf(){
  236. $this->t_id = intval($_GET['t_id']);
  237. if($this->t_id <= 0){
  238. showDialog(L('wrong_argument'));
  239. }
  240. Tpl::output('t_id', $this->t_id);
  241. $this->r_id = intval($_GET['r_id']);
  242. if($this->r_id <= 0){
  243. showDialog(L('wrong_argument'));
  244. }
  245. Tpl::output('r_id', $this->r_id);
  246. $this->reply_info = Model()->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id, 'member_id'=>$_SESSION['member_id']))->find();
  247. if(empty($this->reply_info)){
  248. showDialog(L('wrong_argument'));
  249. }
  250. Tpl::output('reply_info', $this->reply_info);
  251. }
  252. /**
  253. * 验证话题
  254. */
  255. protected function checkThemeSelf(){
  256. $this->t_id = intval($_GET['t_id']);
  257. if($this->t_id <= 0){
  258. showDialog(L('wrong_argument'));
  259. }
  260. Tpl::output('t_id', $this->t_id);
  261. $this->theme_info = Model()->table('circle_theme')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  262. if(empty($this->theme_info)){
  263. showDialog(L('wrong_argument'));
  264. }
  265. Tpl::output('theme_info', $this->theme_info);
  266. }
  267. }
  268. class BaseCircleManageControl extends BaseCircleControl{
  269. protected $circle_info = array(); // 圈子详细信息
  270. protected $t_id = 0; // 话题id
  271. protected $theme_info = array(); // 话题详细信息
  272. protected $identity = 0; // 身份 0游客 1圈主 2管理 3成员
  273. protected $cm_info = array(); // 会员信息
  274. public function __construct(){
  275. parent::__construct();
  276. $this->c_id = intval($_GET['c_id']);
  277. if($this->c_id <= 0){
  278. @header("location: ".CIRCLE_SITE_URL);
  279. }
  280. Tpl::output('c_id', $this->c_id);
  281. }
  282. /**
  283. * 圈子信息
  284. */
  285. protected function circleInfo(){
  286. // 圈子信息
  287. $this->circle_info = Model()->table('circle')->find($this->c_id);
  288. if(empty($this->circle_info)) @header("location: ".CIRCLE_SITE_URL);
  289. Tpl::output('circle_info', $this->circle_info);
  290. }
  291. /**
  292. * 会员信息
  293. */
  294. protected function circleMemberInfo(){
  295. // 会员信息
  296. $this->cm_info = Model()->table('circle_member')->where(array('circle_id'=>$this->c_id, 'member_id'=>$_SESSION['member_id']))->find();
  297. if(!empty($this->cm_info)){
  298. $this->identity = $this->cm_info['is_identity'];
  299. Tpl::output('cm_info', $this->cm_info);
  300. }
  301. if(in_array($this->identity, array(0,3))){
  302. @header("location: ".CIRCLE_SITE_URL);
  303. }
  304. Tpl::output('identity', $this->identity);
  305. }
  306. /**
  307. * 去除圈主
  308. */
  309. protected function removeCreator($array){
  310. return array_diff($array, array($this->cm_info['member_id']));
  311. }
  312. /**
  313. * 去除圈主和管理
  314. */
  315. protected function removeManager($array){
  316. $where = array();
  317. $where['is_identity'] = array('in', array(1,2));
  318. $where['circle_id'] = $this->c_id;
  319. $cm_info = Model()->table('circle_member')->where($where)->select();
  320. if(empty($cm_info)){
  321. return $array;
  322. }
  323. foreach ($cm_info as $val){
  324. $array = array_diff($array, array($val['member_id']));
  325. }
  326. return $array;
  327. }
  328. /**
  329. * 身份验证
  330. */
  331. protected function checkIdentity($type){ // c圈主 m管理 cm圈主和管理
  332. $this->cm_info = Model()->table('circle_member')->where(array('circle_id'=>$this->c_id, 'member_id'=>$_SESSION['member_id']))->find();
  333. $identity = intval($this->cm_info['is_identity']); $sign = false;
  334. switch ($type){
  335. case 'c':
  336. if($identity != 1) $sign = true;
  337. break;
  338. case 'm':
  339. if($identity != 2) $sign = true;
  340. break;
  341. case 'cm':
  342. if($identity != 1 && $identity != 2) $sign = true;
  343. break;
  344. default:
  345. $sign = true;
  346. break;
  347. }
  348. if ($this->super) {
  349. $sign = false;
  350. }
  351. if($sign){
  352. return L('circle_permission_denied');
  353. }
  354. }
  355. /**
  356. * 会员加入的圈子
  357. */
  358. protected function memberJoinCircle(){
  359. // 所属圈子信息
  360. $circle_array = Model()->table('circle,circle_member')->field('circle.*,circle_member.is_identity')
  361. ->join('inner')->on('circle.circle_id=circle_member.circle_id')
  362. ->where(array('circle_member.member_id'=>$_SESSION['member_id']))->select();
  363. Tpl::output('circle_array', $circle_array);
  364. }
  365. /**
  366. * Top Navigation
  367. */
  368. protected function sidebar_menu($sign, $child_sign=''){
  369. $menu = array(
  370. 'index'=>array('menu_name'=>L('circle_basic_setting'), 'menu_url'=>'index.php?act=manage&c_id='.$this->c_id),
  371. 'member'=>array('menu_name'=>L('circle_member_manage'), 'menu_url'=>'index.php?act=manage&op=member_manage&c_id='.$this->c_id),
  372. 'applying'=>array('menu_name'=>L('circle_wait_apply'), 'menu_url'=>'index.php?act=manage&op=applying&c_id='.$this->c_id),
  373. 'level'=>array('menu_name'=>L('circle_member_level'), 'menu_url'=>'index.php?act=manage_level&op=level&c_id='.$this->c_id),
  374. 'class'=>array('menu_name'=>L('circle_tclass'), 'menu_url'=>'index.php?act=manage&op=class&c_id='.$this->c_id),
  375. 'inform'=>array(
  376. 'menu_name'=>L('circle_inform'),
  377. 'menu_url'=>'index.php?act=manage_inform&op=inform&c_id='.$this->c_id,
  378. 'menu_child'=>array(
  379. 'untreated'=>array('name'=>L('circle_inform_untreated'), 'url'=>'index.php?act=manage_inform&op=inform&c_id='.$this->c_id),
  380. 'treated'=>array('name'=>L('circle_inform_treated'), 'url'=>'index.php?act=manage_inform&op=inform&type=treated&c_id='.$this->c_id)
  381. ),
  382. ),
  383. 'managerapply'=>array('menu_name'=>L('circle_mapply'), 'menu_url'=>'index.php?act=manage_mapply&c_id='.$this->c_id),
  384. 'friendship'=>array('menu_name'=>L('fcircle'), 'menu_url'=>'index.php?act=manage&op=friendship&c_id='.$this->c_id)
  385. );
  386. if($this->identity == 2){
  387. unset($menu['index']);unset($menu['member']);unset($menu['level']);unset($menu['class']);unset($menu['friendship']);
  388. unset($menu['inform']['menu_child']['untreated']);unset($menu['managerapply']);
  389. }
  390. Tpl::output('sidebar_menu', $menu);
  391. Tpl::output('sidebar_sign', $sign);
  392. Tpl::output('sidebar_child_sign', $child_sign);
  393. }
  394. }
  395. class BaseCirclePersonalControl extends BaseCircleControl{
  396. protected $m_id = 0; // memeber ID
  397. public function __construct(){
  398. parent::__construct();
  399. if(!$_SESSION['is_login']){
  400. @header("location: ".CIRCLE_SITE_URL);
  401. }
  402. $this->m_id = $_SESSION['member_id'];
  403. // member information
  404. $this->circleMemberInfo();
  405. }
  406. /**
  407. * member information
  408. */
  409. protected function circleMemberInfo(){
  410. // member information list
  411. $circlemember_list = Model()->table('circle_member')->where(array('member_id'=>$this->m_id))->select();
  412. $data = array();
  413. $data['cm_thcount'] = 0;
  414. $data['cm_comcount'] = 0;
  415. $data['member_id'] = $_SESSION['member_id'];
  416. $data['member_name'] = $_SESSION['member_name'];
  417. if(!empty($circlemember_list)){
  418. foreach ($circlemember_list as $val){
  419. $data['cm_thcount'] += $val['cm_thcount'];
  420. $data['cm_comcount'] += $val['cm_comcount'];
  421. }
  422. }
  423. Tpl::output('cm_info', $data);
  424. }
  425. }