theme.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. <?php
  2. /**
  3. * 圈子首页
  4. *
  5. *
  6. *********************************/
  7. defined('InShopNC') or exit('Access Invalid!');
  8. class themeControl extends BaseCircleThemeControl{
  9. protected $c_id = 0; // 圈子id
  10. protected $identity = 0; // 身份 0游客 1圈主 2管理 3成员 4申请中 5申请失败
  11. protected $circle_info = array();
  12. public function __construct(){
  13. parent::__construct();
  14. $this->c_id = intval($_GET['c_id']);
  15. if($this->c_id <= 0){
  16. @header("location: ".CIRCLE_SITE_URL);
  17. }
  18. Tpl::output('c_id', $this->c_id);
  19. }
  20. /**
  21. * ajax获取话题详细信息 话题列表页使用
  22. */
  23. public function ajax_themeinfoOp(){
  24. // 话题信息
  25. $this->themeInfo();
  26. $data = $this->theme_info;
  27. $model = Model();
  28. // 话题商品
  29. $goods_list = $model->table('circle_thg')->where(array('theme_id'=>$this->t_id, 'reply_id'=>0))->select();
  30. $goods_list = tidyThemeGoods($goods_list, 'themegoods_id');
  31. $data['goods_list'] = $goods_list;
  32. // 附件
  33. $affix_list = $model->table('circle_affix')->where(array('affix_type'=>1, 'theme_id'=>$this->t_id))->select();
  34. if(!empty($affix_list)){
  35. foreach ($affix_list as $key=>$val){
  36. $affix_list[$key]['affix_filename'] = themeImageUrl($val['affix_filename']);
  37. $affix_list[$key]['affix_filethumb'] = themeImageUrl($val['affix_filethumb']);
  38. }
  39. }
  40. $data['affix_list'] = $affix_list;
  41. // 访问数增加
  42. $model->table('circle_theme')->update(array('theme_id'=>$this->t_id, 'theme_browsecount'=>array('exp', 'theme_browsecount+1')));
  43. $data['theme_content'] = ubb($data['theme_content']);
  44. if($data['theme_edittime'] != ''){
  45. $data['theme_edittime'] = @date('Y-m-d H:i', $data['theme_edittime']);
  46. }
  47. // 是否赞过话题
  48. $data['theme_nolike'] = 1;
  49. if (isset($_SESSION['member_id'])) {
  50. // 是否赞过话题
  51. $like_info = $model->table('circle_like')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  52. if(empty($like_info)){
  53. $data['theme_nolike'] = 1;
  54. }else{
  55. $data['theme_nolike'] = 0;
  56. }
  57. }
  58. if (strtoupper(CHARSET) == 'GBK'){
  59. $data = Language::getUTF8($data);
  60. }
  61. echo json_encode($data);exit;
  62. }
  63. /**
  64. * ajax获取回复相关信息 话题列表页使用
  65. */
  66. public function ajax_quickreplyOp(){
  67. // 话题信息
  68. $this->themeInfo();
  69. $data = array();
  70. $data['form_action'] = CIRCLE_SITE_URL.'/index.php?act=theme&op=save_reply&type=quick&c_id='.$this->c_id.'&t_id='.$this->t_id;
  71. $data['member_avatar'] = getMemberAvatarForID($_SESSION['member_id']); // 头像
  72. // 回复
  73. $reply_list = Model()->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'circle_id'=>$this->c_id))->order('reply_id desc')->limit(5)->select();
  74. if(!empty($reply_list)){
  75. foreach($reply_list as $key=>$val){
  76. $reply_list[$key]['member_avatar'] = getMemberAvatarForID($val['member_id']);
  77. $reply_list[$key]['reply_addtime'] = date('Y-m-d H:i', $val['reply_addtime']);
  78. $reply_list[$key]['reply_content'] = removeUBBTag($val['reply_content']);
  79. }
  80. }
  81. $data['reply_list'] = $reply_list;
  82. $data['c_istalk'] = intval(C('circle_istalk'));
  83. $data['c_contentleast'] = intval(C('circle_contentleast'));
  84. if(intval(C('circle_contentleast')) > 0){
  85. $data['c_contentmsg'] = sprintf(L('nc_content_min_length'), intval(C('circle_contentleast')));
  86. }else{
  87. $data['c_contentmsg'] = L('nc_content_not_null');
  88. }
  89. if (strtoupper(CHARSET) == 'GBK'){
  90. $data = Language::getUTF8($data);
  91. }
  92. echo json_encode($data);exit;
  93. }
  94. /**
  95. * 保存话题
  96. */
  97. public function save_themeOp(){
  98. if(chksubmit()){
  99. // Reply function does close,throw error.
  100. if(!intval(C('circle_istalk'))){
  101. showDialog(L('circle_theme_cannot_be_published'));
  102. }
  103. // checked cookie of SEC
  104. if(cookie(circle_intervaltime)){
  105. showDialog(L('circle_operation_too_frequent'));
  106. }
  107. // 会员信息
  108. $this->memberInfo();
  109. // 圈子信息
  110. $this->circleInfo();
  111. // 不是圈子成员不能发帖
  112. if(!in_array($this->identity, array(1,2,3))){
  113. showDialog(L('circle_no_join_ban_release'));
  114. }
  115. $model = Model();
  116. // 主题分类
  117. $thclass_id = intval($_POST['thtype']);
  118. $thclass_name = '';
  119. if($thclass_id > 0){
  120. $thclass_info = $model->table('circle_thclass')->find($thclass_id);
  121. $thclass_name = $thclass_info['thclass_name'];
  122. }
  123. /**
  124. * 验证
  125. */
  126. $obj_validate = new Validator();
  127. $validate_arr[] = array("input"=>$_POST["name"], "require"=>"true","message"=>Language::get('nc_name_not_null'));
  128. $validate_arr[] = array("input"=>$_POST["name"], "validator"=>'Length',"min"=>4,"max"=>30,"message"=>Language::get('nc_name_min_max_length'));
  129. $validate_arr[] = array("input"=>$_POST["themecontent"], "require"=>"true","message"=>Language::get('nc_content_not_null'));
  130. if(intval(C('circle_contentleast')) > 0) $validate_arr[] = array("input"=>$_POST["themecontent"],"validator"=>'Length',"min"=>intval(C('circle_contentleast')),"message"=>Language::get('circle_contentleast'));
  131. $obj_validate -> validateparam = $validate_arr;
  132. $error = $obj_validate->validate();
  133. if ($error != ''){
  134. showDialog($error,'','error');
  135. }
  136. $insert = array();
  137. $insert['theme_name'] = circleCenterCensor($_POST['name']);
  138. $insert['theme_content']= circleCenterCensor($_POST['themecontent']);
  139. $insert['circle_id'] = $this->c_id;
  140. $insert['circle_name'] = $this->circle_info['circle_name'];
  141. $insert['thclass_id'] = $thclass_id;
  142. $insert['thclass_name'] = $thclass_name;
  143. $insert['member_id'] = $_SESSION['member_id'];
  144. $insert['member_name'] = $_SESSION['member_name'];
  145. $insert['is_identity'] = $this->identity;
  146. $insert['theme_addtime']= time();
  147. $insert['lastspeak_time']= time();
  148. $insert['theme_readperm']= intval($_POST['readperm']);
  149. $insert['theme_special']= intval($_GET['sp']);
  150. $themeid = $model->table('circle_theme')->insert($insert);
  151. if($themeid){
  152. $has_goods = 0; // 存在商品标记
  153. $has_affix = 0;// 存在附件标记
  154. // 插入话题商品
  155. if(!empty($_POST['goods'])){
  156. $goods_insert = array();
  157. foreach ($_POST['goods'] as $key=>$val){
  158. $p = array();
  159. $p['theme_id'] = $themeid;
  160. $p['reply_id'] = 0;
  161. $p['circle_id'] = $this->c_id;
  162. $p['goods_id'] = $val['id'];
  163. $p['goods_name'] = $val['name'];
  164. $p['goods_price'] = $val['price'];
  165. $p['goods_image'] = $val['image'];
  166. $p['store_id'] = $val['storeid'];
  167. $p['thg_type'] = $val['type'];
  168. $p['thg_url'] = ($val['type'] == 1)?$val['uri']:'';
  169. $goods_insert[] = $p;
  170. }
  171. $rs = $model->table('circle_thg')->insertAll($goods_insert);
  172. $has_goods = 1;
  173. }
  174. // 更新话题附件
  175. $model->table('circle_affix')->where(array('affix_type'=>1, 'member_id'=>$_SESSION['member_id'], 'theme_id'=>0))->update(array('theme_id'=>$themeid, 'circle_id'=>$this->c_id));
  176. // 更新话题信息
  177. $affixe_count = $model->table('circle_affix')->where(array('affix_type'=>1, 'member_id'=>$_SESSION['member_id'], 'theme_id'=>$themeid))->count();
  178. if($affixe_count > 0){
  179. $has_affix = 1;
  180. }
  181. if($has_goods || $has_affix){
  182. $update = array();
  183. $update['theme_id'] = $themeid;
  184. $update['has_goods'] = $has_goods;
  185. $update['has_affix'] = $has_affix;
  186. $model->table('circle_theme')->update($update);
  187. }
  188. // 更新圈子表话题数
  189. $update = array(
  190. 'circle_id'=>$this->c_id,
  191. 'circle_thcount'=>array('exp', 'circle_thcount+1')
  192. );
  193. $model->table('circle')->update($update);
  194. // 更新用户相关信息
  195. $update = array(
  196. 'cm_thcount'=>array('exp', 'cm_thcount+1'),
  197. 'cm_lastspeaktime'=>time()
  198. );
  199. $model->table('circle_member')->where(array('member_id'=>$_SESSION['member_id'], 'circle_id'=>$this->c_id))->update($update);
  200. // Special theme
  201. if($_GET['sp'] == 1){
  202. $insert = array();
  203. $insert['theme_id'] = $themeid;
  204. $insert['poll_multiple'] = intval($_POST['multiple']);
  205. $insert['poll_startime'] = time();
  206. $insert['poll_endtime'] = intval($_POST['days'])!=0?time()+intval($_POST['days'])*60*60*12:0;
  207. $insert['poll_days'] = intval($_POST['days']);
  208. $model->table('circle_thpoll')->insert($insert);
  209. if(!empty($_POST['polloption'])){
  210. $insert_array = array();
  211. foreach ($_POST['polloption'] as $val){
  212. if ($val == '') continue;
  213. $option = array();
  214. $option['theme_id'] = $themeid;
  215. $option['pollop_option']= $val;
  216. $insert_array[] = $option;
  217. }
  218. $model->table('circle_thpolloption')->insertAll($insert_array);
  219. }
  220. }
  221. // set cookie of SEC
  222. if(intval(C('circle_intervaltime')) > 0){
  223. setNcCookie('circle_intervaltime', true, intval(C('circle_intervaltime')));
  224. }
  225. // Experience
  226. $param = array();
  227. $param['member_id'] = $_SESSION['member_id'];
  228. $param['member_name'] = $_SESSION['member_name'];
  229. $param['circle_id'] = $this->c_id;
  230. $param['type'] = 'release';
  231. $param['itemid'] = $themeid;
  232. Model('circle_exp')->saveExp($param);
  233. showDialog(L('nc_release_op_succ'), CIRCLE_SITE_URL.'/index.php?act=theme&op=theme_detail&c_id='.$this->c_id.'&t_id='.$themeid, 'succ');
  234. }else{
  235. showDialog(L('nc_release_op_fail'));
  236. }
  237. }
  238. @header("location: ".CIRCLE_SITE_URL);
  239. }
  240. /**
  241. * Submit voting options
  242. */
  243. public function save_votepollOp(){
  244. if(chksubmit()){
  245. $model = Model();
  246. // check theme
  247. $this->themeInfo();
  248. // Verify the vote ended or not
  249. $poll_info = $model->table('circle_thpoll')->find($this->t_id);
  250. if(empty($poll_info)){
  251. showDialog(L('wrong_argument'));
  252. }
  253. if($poll_info['poll_endtime'] != 0 && time() > $poll_info['poll_endtime']){
  254. showDialog(L('circle_poll_has_end'));
  255. }
  256. $voter_info = $model->table('circle_thpollvoter')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  257. if(!empty($voter_info)){
  258. showDialog(L('circle_poll_has_join'));
  259. }
  260. $pollopid = $_POST['pollopid'];
  261. foreach ((array)$pollopid as $key=>$val){
  262. if(!is_numeric($val)) unset($pollopid[$key]);
  263. }
  264. if(empty($pollopid)){
  265. showDialog(L('circle_poll_choose_options'));
  266. }
  267. // Verify the voting options exist
  268. $option_list = $model->table('circle_thpolloption')->where(array('pollop_id'=>array('in', $pollopid), 'theme_id'=>$this->t_id))->select();
  269. if(empty($option_list)){
  270. showDialog(L('circle_poll_choose_options'));
  271. }
  272. $options = '';
  273. foreach ($option_list as $val){
  274. $options .= $val['pollop_option'].' ';
  275. $update = array();
  276. $update['pollop_id'] = $val['pollop_id'];
  277. $update['pollop_votes'] = array('exp', 'pollop_votes+1');
  278. $update['pollop_votername'] = array('exp', '"'.$_SESSION['member_name'].' '.$val['pollop_votername'].'"');
  279. $model->table('circle_thpolloption')->update($update); //
  280. }
  281. // Recorded personal information
  282. $insert = array();
  283. $insert['theme_id'] = $this->t_id;
  284. $insert['member_id'] = $_SESSION['member_id'];
  285. $insert['member_name'] = $_SESSION['member_name'];
  286. $insert['pollvo_options'] = $options;
  287. $insert['pollvo_time'] = time();
  288. $model->table('circle_thpollvoter')->insert($insert);
  289. // Update the total number of votes
  290. $update = array();
  291. $update['theme_id'] = $this->t_id;
  292. $update['poll_voters'] = array('exp', 'poll_voters+'.count($option_list));
  293. $model->table('circle_thpoll')->update($update);
  294. showDialog(L('circle_poll_success'), 'reload', 'succ');
  295. }
  296. }
  297. /**
  298. * 选择商品
  299. */
  300. public function choose_goodsOp(){
  301. $model = Model();
  302. // 三个月内 已购买的商品
  303. $order_goods = $model->table('order_goods,order')
  304. ->field('order_goods.goods_id,order_goods.goods_name,order_goods.goods_image,order_goods.goods_price,order.store_id as store_id')
  305. ->join('inner join')->on('order_goods.order_id=order.order_id')
  306. ->where(array('order.buyer_id'=>$_SESSION['member_id'], 'order.order_state'=>40, 'finnshed_time'=>array('gt',time()-60*60*24*30*3)))
  307. ->distinct(true)->select();
  308. // 收藏的商品
  309. $favorites_goods = $model->table('goods,favorites')
  310. ->field('goods.goods_id,goods.goods_name,goods.goods_image,goods.goods_price as goods_price,goods.store_id')
  311. ->join('inner join')->on('goods.goods_id=favorites.fav_id')
  312. ->where(array('favorites.fav_type'=>'goods', 'favorites.member_id'=>$_SESSION['member_id']))
  313. ->distinct(true)->select();
  314. Tpl::output('order_goods', $order_goods);
  315. Tpl::output('favorites_goods', $favorites_goods);
  316. Tpl::showpage('theme.choose_goods', 'null_layout');
  317. }
  318. /**
  319. * According to the product link to add goods
  320. */
  321. public function check_linkOp(){
  322. $url = html_entity_decode($_GET['link']);
  323. if(empty($url)) {
  324. echo 'false';exit;
  325. }
  326. $model_goods_info = Model('goods_info_by_url');
  327. $result = $model_goods_info->get_goods_info_by_url($url);
  328. if($result) {
  329. if ($result) {
  330. $result['type'] = ($result['type'] == 'taobao') ? 1 : 0;
  331. }
  332. echo json_encode($result);exit;
  333. }else{
  334. echo 'false';exit;
  335. }
  336. }
  337. // /**
  338. // * Get taobao product information
  339. // *
  340. // * @param string $link
  341. // */
  342. // private function getTaobaoGoodsInfo($link){
  343. // require(BASE_DATA_PATH.DS.'api'.DS.'taobao'.DS.'index.php');
  344. // $taobao_api = new taobao_item;
  345. // $taobao_goods_info = $taobao_api->fetch($link);
  346. // if(!$taobao_goods_info) return false;
  347. // $item_img = (array)$taobao_goods_info['item_imgs'];
  348. // $item_img = (array)$item_img['item_img'][0];
  349. // $item_img = $item_img['url'];
  350. // $url_array = explode('.',$item_img);
  351. // $ext = end($url_array);
  352. // $item_img = $item_img.'_40x40.'.$ext;
  353. // $return = array();
  354. // $return['id'] = 0;
  355. // $return['name'] = $taobao_goods_info['title'];
  356. // $return['price'] = $taobao_goods_info['price'];
  357. // $return['storeid'] = 0;
  358. // $return['img'] = $item_img;
  359. // $return['image'] = $item_img;
  360. // $return['uri'] = $link;
  361. // $return['type'] = 1;
  362. // return $return;
  363. // }
  364. // /**
  365. // * Get self product information
  366. // *
  367. // * @param string $link
  368. // */
  369. // private function getSelfGoodsInfo($link){
  370. // $array = parse_url($link);
  371. // if(isset($array['query'])){
  372. // // Not open the pseudo static
  373. // parse_str($array['query'],$arr);
  374. // $id = $arr['goods_id'];
  375. // }else{
  376. // // Open the pseudo static
  377. // $id = preg_replace('/\/item-(\d+)\.html/i', '$1', $array['path']);
  378. // }
  379. // if(!is_numeric($id)) return false;
  380. // $goods_info = Model()->table('goods')->field('goods_id,goods_name,goods_store_price,goods_image,store_id')->find($id);
  381. // if(empty($goods_info)) return false;
  382. // $return = array();
  383. // $return['id'] = $goods_info['goods_id'];
  384. // $return['name'] = $goods_info['goods_name'];
  385. // $return['price'] = $goods_info['goods_store_price'];
  386. // $return['storeid'] = $goods_info['store_id'];
  387. // $return['img'] = thumb($goods_info, 60);
  388. // $return['image'] = $goods_info['goods_image'];
  389. // $return['uri'] = $link;
  390. // $return['type'] = 0;
  391. // return $return;
  392. // }
  393. /**
  394. * Get link domain
  395. *
  396. * @param string $link
  397. */
  398. private function getDomain($link){
  399. $url = parse_url($link);
  400. if(!isset($url['host'])) return false;
  401. $domain = explode('.', $url['host'], 2);
  402. return $domain[1];
  403. }
  404. /**
  405. * 上传图片
  406. */
  407. public function choose_imageOp(){
  408. $model = Model();
  409. $where = array();
  410. if(intval($_GET['class_id']) > 0){
  411. $where['ac_id'] = intval($_GET['class_id']);
  412. }
  413. $where['member_id'] = $_SESSION['member_id'];
  414. $pic_list = $model->table('sns_albumpic')->where($where)->page(6)->select();
  415. Tpl::output('show_page', $model->showpage('2'));
  416. Tpl::output('pic_list', $pic_list);
  417. $class_list = $model->table('sns_albumclass')->where(array('member_id'=>$_SESSION['member_id']))->select();
  418. Tpl::output('class_list', $class_list);
  419. Tpl::showpage('theme.choose_image', 'null_layout');
  420. }
  421. /**
  422. * 附件批量上传 话题
  423. */
  424. public function image_uploadOp(){
  425. $data['msg'] = 'error';
  426. $data['origin_file_name'] = $_FILES['test_file']['name'];
  427. // 验证已上传附件数量 最大10个
  428. $where = array();
  429. $where['member_id'] = $_SESSION['member_id'];
  430. if($_GET['type'] == 'reply'){
  431. $where['affix_type']= 2;
  432. $where['reply_id'] = 0;
  433. }else{
  434. $where['affix_type']= 1;
  435. $where['theme_id'] = 0;
  436. }
  437. $count = Model()->table('circle_affix')->where($where)->count();
  438. if($count < 10){
  439. $partpath = themePartPath($_SESSION['member_id']);
  440. $upload = new UploadFile();
  441. $upload->set('default_dir', ATTACH_CIRCLE.'/theme/'.$partpath);
  442. $upload->set('thumb_width', 1024);
  443. $upload->set('thumb_height', 160);
  444. $upload->set('thumb_ext', '_160x160');
  445. $result = $upload->upfile('test_file'); // 暂时的名字
  446. if ($result){
  447. $insert = array();
  448. $insert['affix_filename'] = $partpath.'/'.$upload->file_name;
  449. $insert['affix_filethumb'] = $partpath.'/'.$upload->thumb_image;
  450. $insert['affix_filesize'] = intval($_FILES['test_file']['size']);
  451. $insert['affix_addtime'] = time();
  452. $insert['affix_type'] = ($_GET['type'] == 'reply')?2:1;
  453. $insert['member_id'] = $_SESSION['member_id'];
  454. $insert['theme_id'] = $this->t_id;
  455. $insert['reply_id'] = 0;
  456. $insert['circle_id'] = $this->c_id;
  457. $id = Model()->table('circle_affix')->insert($insert);
  458. if($id){
  459. $data['msg'] = 'success';
  460. $data['file_id'] = $id;
  461. $data['file_name'] = $upload->file_name;
  462. $data['file_url'] = themeImageUrl($partpath.'/'.$upload->thumb_image);
  463. $data['file_insert']= themeImageUrl($partpath.'/'.$upload->file_name);
  464. }
  465. }
  466. }
  467. echo json_encode($data);exit;
  468. }
  469. /**
  470. * 附件删除
  471. */
  472. public function delimgOp(){
  473. $id = intval($_GET['id']);
  474. if($id > 0){
  475. $affix_info = Model()->table('circle_affix')->where(array('member_id'=>$_SESSION['member_id'], 'affix_id'=>$id))->find();
  476. if(!empty($affix_info)){
  477. @unlink(themeImagePath($affix_info['affix_filename']));
  478. @unlink(themeImagePath($affix_info['affix_filethumb']));
  479. Model()->table('circle_affix')->delete($id);
  480. echo true;
  481. }
  482. }
  483. }
  484. /**
  485. * 获得未使用附件
  486. */
  487. public function unused_imgOp(){
  488. $affix_list = Model()->table('circle_affix')->field('affix_id,affix_filename,affix_filethumb')->where(array('member_id'=>$_SESSION['member_id'], 'affix_type'=>1, 'theme_id'=>0))->select();
  489. if(!empty($affix_list)){
  490. $affix_array = array();
  491. foreach($affix_list as $key=>$val){
  492. $affix_array[$key]['file_id'] = $val['affix_id'];
  493. $affix_array[$key]['file_url'] = themeImageUrl($val['affix_filethumb']);
  494. $affix_array[$key]['file_insert'] = themeImageUrl($val['affix_filename']);
  495. }
  496. }
  497. echo json_encode($affix_array);
  498. }
  499. /**
  500. * 话题详细页
  501. */
  502. public function theme_detailOp(){
  503. // 圈子信息
  504. $this->circleInfo();
  505. // 圈主和管理信息
  506. $this->manageList();
  507. // 会员信息
  508. $this->memberInfo();
  509. // sidebar相关
  510. $this->sidebar();
  511. // 话题信息
  512. $this->themeInfo();
  513. // Verify the read permissions
  514. $this->readPermissions($this->cm_info);
  515. if($this->m_readperm < $this->theme_info['theme_readperm']){
  516. showMessage(L('circle_Insufficient_permissions'), CIRCLE_SITE_URL, '', 'error');
  517. }
  518. $model = Model();
  519. // 话题被浏览数增加
  520. $model->table('circle_theme')->update(array('theme_id'=>$this->t_id, 'theme_browsecount'=>array('exp', 'theme_browsecount+1')));
  521. // 回复列表
  522. $where = array();
  523. $where['theme_id'] = $this->t_id;
  524. if($_GET['only_id'] != ''){
  525. $where['member_id'] = intval($_GET['only_id']);
  526. }
  527. $reply_info = $model->table('circle_threply')->where($where)->page(15)->order('reply_id asc')->select();
  528. Tpl::output('reply_info', $reply_info);
  529. Tpl::output('show_page', $model->showpage(2));
  530. $replyid_array = array();
  531. $memberid_array = array();
  532. if(!empty($reply_info)){
  533. foreach($reply_info as $val){
  534. $replyid_array[] = $val['reply_id'];
  535. $memberid_array[] = $val['member_id'];
  536. }
  537. }
  538. $replyid_array[] = 0;
  539. ksort($replyid_array);
  540. $memberid_array[] = $this->theme_info['member_id'];
  541. $memberid_array = array_unique($memberid_array);
  542. ksort($memberid_array);
  543. $where = array();
  544. $where['theme_id'] = $this->t_id;
  545. $where['reply_id'] = array('in', $replyid_array);
  546. // goods
  547. $goods_array = $model->table('circle_thg')->where($where)->select();
  548. $goods_array = tidyThemeGoods($goods_array, 'reply_id', 2);
  549. Tpl::output('goods_list', $goods_array[0]); unset($goods_array[0]);
  550. Tpl::output('reply_goods', $goods_array);
  551. // affix
  552. $affix_array = $model->table('circle_affix')->where($where)->select();
  553. if(!empty($affix_array)){
  554. $affix_list = array();
  555. $reply_affix = array();
  556. foreach($affix_array as $val){
  557. if($val['affix_type'] == 1){
  558. $affix_list[] = $val;
  559. }else{
  560. $reply_affix[$val['reply_id']][] = $val;
  561. }
  562. }
  563. Tpl::output('affix_list', $affix_list);
  564. Tpl::output('reply_affix', $reply_affix);
  565. }
  566. // member
  567. $member_list = $model->table('circle_member')->field('member_id,cm_level,cm_levelname')->where(array('circle_id'=>$this->c_id, 'member_id'=>array('in', $memberid_array)))->select();
  568. $member_list = array_under_reset($member_list, 'member_id');
  569. Tpl::output('member_list', $member_list);
  570. // 是否赞过话题
  571. $theme_nolike = 1;
  572. if (isset($_SESSION['member_id'])) {
  573. // 是否赞过话题
  574. $like_info = $model->table('circle_like')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  575. if(empty($like_info)){
  576. $theme_nolike = 1;
  577. }else{
  578. $theme_nolike = 0;
  579. }
  580. }
  581. Tpl::output('theme_onlike', $theme_nolike);
  582. $this->circleSEO($this->theme_info['theme_name']);
  583. // Special theme
  584. if($this->theme_info['theme_special'] == 1){
  585. $poll_info = $model->table('circle_thpoll')->find($this->t_id);
  586. Tpl::output('poll_info', $poll_info);
  587. $option_list = $model->table('circle_thpolloption')->where(array('theme_id'=>$this->t_id))->order('pollop_sort asc')->select();
  588. Tpl::output('option_list', $option_list);
  589. // Verify the vote ended or not
  590. if($poll_info['poll_endtime'] == 0 || $poll_info['poll_endtime'] > time()){
  591. Tpl::output('vote_end', false);
  592. // Whether members have had voted
  593. $voter_info = $model->table('circle_thpollvoter')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  594. if(!empty($voter_info)){
  595. Tpl::output('partake', true);
  596. }else{
  597. Tpl::output('partake', false);
  598. }
  599. }else {
  600. Tpl::output('vote_end', true);
  601. }
  602. }
  603. // breadcrumb navigation
  604. $this->breadcrumd();
  605. Tpl::showpage('theme.detail');
  606. }
  607. /**
  608. * 发布话题
  609. */
  610. public function new_themeOp(){
  611. // 圈子信息
  612. $this->circleInfo();
  613. // 圈主和管理信息
  614. $this->manageList();
  615. // 会员信息
  616. $this->memberInfo();
  617. // 不是圈子成员不能发帖
  618. if(!in_array($this->identity, array(1,2,3))){
  619. showDialog(L('circle_no_join_ban_release'));
  620. }
  621. // 话题分类
  622. $where = array();
  623. $where['circle_id'] = $this->c_id;
  624. $where['thclass_status']= 1;
  625. $thclass_list = Model()->table('circle_thclass')->where($where)->select();
  626. $thclass_list = array_under_reset($thclass_list, 'thclass_id');
  627. Tpl::output('thclass_list', $thclass_list);
  628. // Read Permission
  629. $readperm = $this->readPermissions($this->cm_info);
  630. Tpl::output('readperm', $readperm);
  631. $this->circleSEO(L('circle_release_theme'));
  632. if($_GET['sp'] == 1){
  633. // breadcrumb navigation
  634. $this->breadcrumd(L('circle_new_poll'));
  635. Tpl::showpage('theme.new_poll');
  636. }else{
  637. // breadcrumb navigation
  638. $this->breadcrumd(L('circle_new_theme'));
  639. Tpl::showpage('theme.new_theme');
  640. }
  641. }
  642. /**
  643. * 编辑话题
  644. */
  645. public function edit_themeOp(){
  646. $model = Model();
  647. // 验证话题
  648. $this->checkThemeSelf();
  649. if(chksubmit()){
  650. /**
  651. * 验证
  652. */
  653. $obj_validate = new Validator();
  654. $validate_arr[] = array("input"=>$_POST["name"], "require"=>"true","message"=>Language::get('nc_name_not_null'));
  655. $validate_arr[] = array("input"=>$_POST["name"], "validator"=>'Length',"min"=>4,"max"=>30,"message"=>Language::get('nc_name_min_max_length'));
  656. $validate_arr[] = array("input"=>$_POST["themecontent"], "require"=>"true","message"=>Language::get('nc_content_not_null'));
  657. if(intval(C('circle_contentleast')) > 0) $validate_arr[] = array("input"=>$_POST["themecontent"],"validator"=>'Length',"min"=>intval(C('circle_contentleast')),"message"=>Language::get('circle_contentleast'));
  658. $obj_validate -> validateparam = $validate_arr;
  659. $error = $obj_validate->validate();
  660. if ($error != ''){
  661. showDialog($error,'','error');
  662. }
  663. // 主题分类
  664. $thclass_id = intval($_POST['thtype']);
  665. $thclass_name = '';
  666. if($thclass_id > 0){
  667. $thclass_info = $model->table('circle_thclass')->find($thclass_id);
  668. $thclass_name = $thclass_info['thclass_name'];
  669. }
  670. $model = Model();
  671. $update = array();
  672. $update['theme_id'] = $this->t_id;
  673. $update['theme_name'] = circleCenterCensor($_POST['name']);
  674. $update['theme_content'] = circleCenterCensor($_POST['themecontent']);
  675. $update['thclass_id'] = $thclass_id;
  676. $update['thclass_name'] = $thclass_name;
  677. $update['theme_editname'] = $_SESSION['member_name'];
  678. $update['theme_edittime'] = time();
  679. $update['theme_readperm'] = intval($_POST['readperm']);
  680. $rs = $model->table('circle_theme')->update($update);
  681. if($rs){
  682. $has_goods = 0; // 存在商品标记
  683. $has_affix = 0;// 存在附件标记
  684. // 删除原有商品
  685. $goods_list = Model()->table('circle_thg')->where(array('theme_id'=>$this->t_id, 'reply_id'=>0))->delete();
  686. // 插入话题商品
  687. if(!empty($_POST['goods'])){
  688. $goods_insert = array();
  689. foreach ($_POST['goods'] as $key=>$val){
  690. $p = array();
  691. $p['theme_id'] = $this->t_id;
  692. $p['reply_id'] = 0;
  693. $p['circle_id'] = $this->c_id;
  694. $p['goods_id'] = $val['id'];
  695. $p['goods_name'] = $val['name'];
  696. $p['goods_price'] = $val['price'];
  697. $p['goods_image'] = $val['image'];
  698. $p['store_id'] = $val['storeid'];
  699. $p['thg_type'] = $val['type'];
  700. $p['thg_url'] = ($val['type'] == 1)?$val['uri']:'';
  701. $goods_insert[] = $p;
  702. }
  703. $rs = $model->table('circle_thg')->insertAll($goods_insert);
  704. $has_goods = 1;
  705. }
  706. // 更新话题附件
  707. $model->table('circle_affix')->where(array('affix_type'=>1, 'member_id'=>$_SESSION['member_id'], 'theme_id'=>0))->update(array('theme_id'=>$this->t_id, 'circle_id'=>$this->c_id));
  708. // 更新话题信息
  709. $affixe_count = $model->table('circle_affix')->where(array('affix_type'=>1, 'member_id'=>$_SESSION['member_id'], 'theme_id'=>$this->t_id))->count();
  710. if($affixe_count > 0){
  711. $has_affix = 1;
  712. }
  713. if($has_goods || $has_affix){
  714. $update = array();
  715. $update['theme_id'] = $this->t_id;
  716. $update['has_goods'] = $has_goods;
  717. $update['has_affix'] = $has_affix;
  718. $model->table('circle_theme')->update($update);
  719. }
  720. // Special theme
  721. if($_GET['sp'] == 1){
  722. // Update the vote
  723. $update = array();
  724. $update['theme_id'] = $this->t_id;
  725. $update['poll_multiple'] = intval($_POST['multiple']);
  726. $update['poll_startime'] = time();
  727. $update['poll_endtime'] = intval($_POST['days'])!=0?time()+intval($_POST['days'])*60*60*12:0;
  728. $update['poll_days'] = intval($_POST['days']);
  729. $model->table('circle_thpoll')->update($update);
  730. // Update the voting options
  731. if(!empty($_POST['polloption'])){
  732. $insert_array = array();
  733. foreach ($_POST['polloption'] as $key=>$val){
  734. $option_info = $model->table('circle_thpolloption')->where(array('pollop_id'=>$key, 'theme_id'=>$this->t_id))->find();
  735. if(!empty($option_info)){
  736. $update = array();
  737. $update['pollop_id'] = $key;
  738. $update['pollop_option']= $val;
  739. $update['pollop_sort'] = $_POST['pollsort'][$key];
  740. $model->table('circle_thpolloption')->update($update);
  741. }else{
  742. if ($val == '') continue;
  743. $i = array();
  744. $i['theme_id'] = $this->t_id;
  745. $i['pollop_option'] = $val;
  746. $i['pollop_sort'] = $_POST['pollsort'][$key];
  747. $insert_array[] = $i;
  748. }
  749. }
  750. if(!empty($insert_array)) $model->table('circle_thpolloption')->insertAll($insert_array);
  751. }
  752. }
  753. showDialog(L('nc_deit_op_succ'), CIRCLE_SITE_URL.'/index.php?act=theme&op=theme_detail&c_id='.$this->c_id.'&t_id='.$this->t_id, 'succ');
  754. }else{
  755. showDialog(L('nc_deit_op_fail'));
  756. }
  757. }
  758. // 圈子信息
  759. $this->circleInfo();
  760. // 圈主和管理信息
  761. $this->manageList();
  762. // 会员信息
  763. $this->memberInfo();
  764. // 话题商品
  765. $goods_list = $model->table('circle_thg')->where(array('theme_id'=>$this->t_id, 'reply_id'=>0))->select();
  766. $goods_list = tidyThemeGoods($goods_list, 'themegoods_id');
  767. Tpl::output('goods_list', $goods_list);
  768. // 话题附件
  769. $affix_list = $model->table('circle_affix')->where(array('affix_type'=>1, 'theme_id'=>$this->t_id))->select();
  770. Tpl::output('affix_list', $affix_list);
  771. // 话题分类
  772. $where = array();
  773. $where['circle_id'] = $this->c_id;
  774. $where['thclass_status']= 1;
  775. $thclass_list = $model->table('circle_thclass')->where($where)->select();
  776. $thclass_list = array_under_reset($thclass_list, 'thclass_id');
  777. Tpl::output('thclass_list', $thclass_list);
  778. // Members of the information
  779. $this->memberInfo();
  780. // Read Permission
  781. $readperm = $this->readPermissions($this->cm_info);
  782. Tpl::output('readperm', $readperm);
  783. $this->circleSEO(L('nc_edit_theme'));
  784. // breadcrumb navigation
  785. $this->breadcrumd(L('nc_edit_theme'));
  786. if($this->theme_info['theme_special'] == 1){
  787. $poll_info = $model->table('circle_thpoll')->find($this->t_id);
  788. Tpl::output('poll_info', $poll_info);
  789. $option_list = $model->table('circle_thpolloption')->where(array('theme_id'=>$this->t_id))->order('pollop_sort asc')->select();
  790. Tpl::output('option_list', $option_list);
  791. Tpl::showpage('theme.edit_themepoll');
  792. }else{
  793. Tpl::showpage('theme.edit_theme');
  794. }
  795. }
  796. /**
  797. * 赞
  798. */
  799. public function ajax_likeyesOp(){
  800. // 话题信息
  801. $this->themeInfo();
  802. $like_info = Model()->table('circle_like')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  803. if(empty($like_info)){
  804. // 插入话题赞表
  805. Model()->table('circle_like')->insert(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id'], 'circle_id'=>$this->c_id));
  806. // 更新赞数量
  807. Model()->table('circle_theme')->update(array('theme_id'=>$this->t_id, 'theme_likecount'=>array('exp', 'theme_likecount+1')));
  808. echo 'true';
  809. }else{
  810. echo 'false';
  811. }
  812. exit;
  813. }
  814. /**
  815. * 取消赞
  816. */
  817. public function ajax_likenoOp(){
  818. // 话题信息
  819. $this->themeInfo();
  820. $like_info = Model()->table('circle_like')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->find();
  821. if(empty($like_info)){
  822. echo 'false';
  823. }else{
  824. // 删除话题赞表信息
  825. Model()->table('circle_like')->where(array('theme_id'=>$this->t_id, 'member_id'=>$_SESSION['member_id']))->delete();
  826. // 更新赞数量
  827. Model()->table('circle_theme')->update(array('theme_id'=>$this->t_id, 'theme_likecount'=>array('exp', 'theme_likecount-1')));
  828. echo 'true';
  829. }
  830. exit;
  831. }
  832. /**
  833. * 高级回复
  834. */
  835. public function replyOp(){
  836. // 圈子信息
  837. $this->circleInfo();
  838. // 圈主和管理信息
  839. $this->manageList();
  840. // 会员信息
  841. $this->memberInfo();
  842. // 不是圈子成员不能发帖
  843. if(!in_array($this->identity, array(1,2,3))){
  844. showDialog(L('circle_no_join_ban_reply'));
  845. }
  846. // 话题信息
  847. $this->themeInfo();
  848. if($_GET['answer_id'] != ''){
  849. $reply_info = Model()->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'reply_id'=>intval($_GET['answer_id'])))->find();
  850. if(!empty($reply_info)) Tpl::output('answer', $reply_info);
  851. }
  852. // 附件信息
  853. $where = array();
  854. $where['member_id'] = $_SESSION['member_id'];
  855. $where['affix_type']= 2;
  856. $where['reply_id'] = 0;
  857. $affix_list = Model()->table('circle_affix')->where($where)->select();
  858. Tpl::output('affix_list', $affix_list);
  859. $this->circleSEO(L('nc_reply_theme'));
  860. // breadcrumb navigation
  861. $this->breadcrumd(L('nc_advanced_reply'));
  862. Tpl::showpage('theme.reply');
  863. }
  864. /**
  865. * 编辑回复
  866. */
  867. public function edit_replyOp(){
  868. // 验证回复信息
  869. $this->checkReplySelf();
  870. if(chksubmit()){
  871. /**
  872. * 验证
  873. */
  874. $obj_validate = new Validator();
  875. $obj_validate->validateparam = array(
  876. array("input"=>$_POST["replycontent"], "require"=>"true", "message"=>L('circle_reply_not_null')),
  877. );
  878. $error = $obj_validate->validate();
  879. if($error != ''){
  880. showDialog($error);
  881. }else{
  882. $model = Model();
  883. $update = array();
  884. $update['theme_id'] = $this->t_id;
  885. $update['reply_id'] = $this->r_id;
  886. $update['member_id'] = $_SESSION['member_id'];
  887. $update['member_name'] = $_SESSION['member_name'];
  888. $update['reply_content']= circleCenterCensor($_POST['replycontent']);
  889. $update['reply_addtime']= time();
  890. $update['is_closed'] = 0;
  891. $rs = $model->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id))->update($update);
  892. if($rs){
  893. // 删除原有商品
  894. $goods_list = Model()->table('circle_thg')->where(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id))->delete();
  895. // 插入话题商品
  896. if(!empty($_POST['goods'])){
  897. $goods_insert = array();
  898. foreach ($_POST['goods'] as $key=>$val){
  899. $p = array();
  900. $p['theme_id'] = $this->t_id;
  901. $p['reply_id'] = $this->r_id;
  902. $p['circle_id'] = $this->c_id;
  903. $p['goods_id'] = $val['id'];
  904. $p['goods_name'] = $val['name'];
  905. $p['goods_price'] = $val['price'];
  906. $p['goods_image'] = $val['image'];
  907. $p['store_id'] = $val['storeid'];
  908. $p['thg_type'] = $val['type'];
  909. $p['thg_url'] = ($val['type'] == 1)?$val['uri']:'';
  910. $goods_insert[] = $p;
  911. }
  912. $rs = $model->table('circle_thg')->insertAll($goods_insert);
  913. }
  914. // 更新话题附件
  915. $model->table('circle_affix')->where(array('affix_type'=>2, 'member_id'=>$_SESSION['member_id'], 'reply_id'=>0))->update(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id, 'circle_id'=>$this->c_id));
  916. showDialog(L('nc_common_op_succ'), 'index.php?act=theme&op=theme_detail&c_id='.$this->c_id.'&t_id='.$this->t_id, 'succ');
  917. }
  918. }
  919. }
  920. // 圈子信息
  921. $this->circleInfo();
  922. // 圈主和管理信息
  923. $this->manageList();
  924. // 会员信息
  925. $this->memberInfo();
  926. // 话题信息
  927. $this->themeInfo();
  928. // 附件信息
  929. $where = array();
  930. $where['member_id'] = $_SESSION['member_id'];
  931. $where['affix_type']= 2;
  932. $where['reply_id'] = array('in', array(0,$this->r_id));
  933. $where['theme_id'] = array('in', array(0,$this->t_id));
  934. $affix_list = Model()->table('circle_affix')->where($where)->select();
  935. Tpl::output('affix_list', $affix_list);
  936. // 商品信息
  937. $where = array();
  938. $where['theme_id'] = $this->t_id;
  939. $where['reply_id'] = $this->r_id;
  940. $goods_list = Model()->table('circle_thg')->where($where)->select();
  941. $goods_list = tidyThemeGoods($goods_list, 'themegoods_id');
  942. Tpl::output('goods_list', $goods_list);
  943. $this->circleSEO(L('nc_edit_theme'));
  944. // breadcrumb navigation
  945. $this->breadcrumd(L('nc_edit_reply'));
  946. Tpl::showpage('theme.edit_reply');
  947. }
  948. /**
  949. * 话题回复保存
  950. */
  951. public function save_replyOp(){
  952. // Reply function does close,throw error.
  953. if(!intval(C('circle_istalk'))){
  954. showDialog(L('circle_has_been_closed_reply'));
  955. }
  956. // checked cookie of SEC
  957. if(cookie(circle_intervaltime)){
  958. showDialog(L('circle_operation_too_frequent'));
  959. }
  960. // 会员信息
  961. $this->memberInfo();
  962. // 不是圈子成员不能发帖
  963. if(!in_array($this->identity, array(1,2,3))){
  964. showDialog(L('circle_no_join_ban_reply'));
  965. }
  966. // 话题信息
  967. $this->themeInfo();
  968. if(chksubmit()){
  969. /**
  970. * 验证
  971. */
  972. $obj_validate = new Validator();
  973. $obj_validate->validateparam = array(
  974. array("input"=>$_POST["replycontent"], "require"=>"true", "message"=>L('circle_reply_not_null')),
  975. );
  976. $error = $obj_validate->validate();
  977. if($error != ''){
  978. showDialog($error);
  979. }else{
  980. $model = Model();
  981. $insert = array();
  982. $insert['theme_id'] = $this->t_id;
  983. $insert['circle_id'] = $this->c_id;
  984. $insert['member_id'] = $_SESSION['member_id'];
  985. $insert['member_name'] = $_SESSION['member_name'];
  986. $insert['reply_content']= circleCenterCensor($_POST['replycontent']);
  987. $insert['reply_addtime']= time();
  988. $insert['is_closed'] = 0;
  989. // 回复楼层验证
  990. if($_POST['answer_id'] != ''){
  991. $reply_info = Model()->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'reply_id'=>intval($_POST['answer_id'])))->find();
  992. if(!empty($reply_info)) {
  993. $insert['reply_replyid'] = $reply_info['reply_id'];
  994. $insert['reply_replyname'] = $reply_info['member_name'];
  995. }
  996. }
  997. $reply_id = $model->table('circle_threply')->insert($insert);
  998. if($reply_id){
  999. if($_GET['type'] == 'adv'){
  1000. // 插入话题商品
  1001. if(!empty($_POST['goods'])){
  1002. $goods_insert = array();
  1003. foreach ($_POST['goods'] as $key=>$val){
  1004. $p = array();
  1005. $p['theme_id'] = $this->t_id;
  1006. $p['reply_id'] = $reply_id;
  1007. $p['circle_id'] = $this->c_id;
  1008. $p['goods_id'] = $val['id'];
  1009. $p['goods_name'] = $val['name'];
  1010. $p['goods_price'] = $val['price'];
  1011. $p['goods_image'] = $val['image'];
  1012. $p['store_id'] = $val['storeid'];
  1013. $p['thg_type'] = $val['type'];
  1014. $p['thg_url'] = ($val['type'] == 1)?$val['uri']:'';
  1015. $goods_insert[] = $p;
  1016. }
  1017. $rs = $model->table('circle_thg')->insertAll($goods_insert);
  1018. }
  1019. // 更新话题附件
  1020. $model->table('circle_affix')->where(array('affix_type'=>2, 'member_id'=>$_SESSION['member_id'], 'reply_id'=>0))->update(array('theme_id'=>$this->t_id, 'reply_id'=>$reply_id, 'circle_id'=>$this->c_id));
  1021. }
  1022. // 话题被回复数增加 最后发言人发言时间
  1023. $update = array();
  1024. $update['theme_id'] = $this->t_id;
  1025. $update['theme_commentcount'] = array('exp', 'theme_commentcount+1');
  1026. $update['lastspeak_id'] = $_SESSION['member_id'];
  1027. $update['lastspeak_name'] = $_SESSION['member_name'];
  1028. $update['lastspeak_time'] = time();
  1029. $model->table('circle_theme')->update($update);
  1030. // 成员回复数增加 最后回复时间
  1031. $model->table('circle_member')->where(array('member_id'=>$_SESSION['member_id'], 'circle_id'=>$this->c_id))->update(array('cm_comcount'=>array('exp', 'cm_comcount+1'), 'cm_lastspeaktime'=>time()));
  1032. // set cookie of SEC
  1033. if(intval(C('circle_intervaltime')) > 0){
  1034. setNcCookie('circle_intervaltime', true, intval(C('circle_intervaltime')));
  1035. }
  1036. if($this->theme_info['member_id'] != $_SESSION['member_id']){
  1037. // Experience for replyer
  1038. $param = array();
  1039. $param['member_id'] = $_SESSION['member_id'];
  1040. $param['member_name'] = $_SESSION['member_name'];
  1041. $param['circle_id'] = $this->c_id;
  1042. $param['theme_id'] = $this->t_id;
  1043. $param['type'] = 'reply';
  1044. $param['itemid'] = $this->t_id.','.$reply_id;
  1045. Model('circle_exp')->saveExp($param);
  1046. // Experience for releaser
  1047. $param = array();
  1048. $param['member_id'] = $this->theme_info['member_id'];
  1049. $param['member_name'] = $this->theme_info['member_name'];
  1050. $param['theme_id'] = $this->t_id;
  1051. $param['circle_id'] = $this->c_id;
  1052. $param['type'] = 'replied';
  1053. $param['itemid'] = $this->t_id;
  1054. Model('circle_exp')->saveExp($param);
  1055. }
  1056. if($_GET['type'] == 'quick'){
  1057. showDialog(L('nc_common_op_succ'), '', 'succ', '$(\'li[nctype="li'.$this->t_id.'"]\').find(\'.quick-reply-2\').removeClass(\'t\').html(\'\').end().find(\'.quick-reply-list-2\').remove().end().end().find(\'a[nctype="reply"]\').click().click();');
  1058. }else{
  1059. showDialog(L('nc_common_op_succ'), 'index.php?act=theme&op=theme_detail&c_id='.$this->c_id.'&t_id='.$this->t_id, 'succ');
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. /**
  1066. * 删除回复
  1067. */
  1068. public function del_replyOp(){
  1069. // 验证回复
  1070. $this->checkReplySelf();
  1071. $model = Model();
  1072. // 删除商品
  1073. $goods_list = $model->table('circle_thg')->where(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id))->delete();
  1074. // 删除附件
  1075. $where = array();
  1076. $where['affix_type']= 2;
  1077. $where['member_id'] = $_SESSION['member_id'];
  1078. $where['theme_id'] = $this->t_id;
  1079. $where['reply_id'] = $this->r_id;
  1080. $affix_list = $model->table('circle_affix')->where($where)->select();
  1081. if($affix_list){
  1082. foreach ($affix_list as $val){
  1083. @unlink(themeImagePath($val['affix_filename']));
  1084. @unlink(themeImagePath($val['affix_filethumb']));
  1085. }
  1086. $model->table('circle_affix')->where($where)->delete();
  1087. }
  1088. // The recycle bin add delete records
  1089. $param = array();
  1090. $param['theme_id'] = $this->t_id;
  1091. $param['reply_id'] = $this->r_id;
  1092. $param['op_id'] = $_SESSION['member_id'];
  1093. $param['op_name'] = $_SESSION['member_name'];
  1094. $param['type'] = 'reply';
  1095. Model('circle_recycle')->saveRecycle($param);
  1096. // 删除回复
  1097. $model->table('circle_threply')->where(array('theme_id'=>$this->t_id, 'reply_id'=>$this->r_id, 'member_id'=>$_SESSION['member_id']))->delete();
  1098. // Experience
  1099. if(intval($this->reply_info['reply_exp']) > 0){
  1100. $param = array();
  1101. $param['member_id'] = $_SESSION['member_id'];
  1102. $param['member_name'] = $_SESSION['member_name'];
  1103. $param['circle_id'] = $this->c_id;
  1104. $param['itemid'] = $this->t_id.','.$this->r_id;
  1105. $param['type'] = 'delReplied';
  1106. $param['exp'] = $this->reply_info['reply_exp'];
  1107. Model('circle_exp')->saveExp($param);
  1108. }
  1109. showDialog(L('nc_common_op_succ'), 'reload', 'succ');
  1110. }
  1111. }