ArticleCateAction.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class ArticleCateAction extends CommonAction{
  10. public function index()
  11. {
  12. $condition['is_delete'] = 0;
  13. //$condition['pid'] = 0;
  14. $this->assign("default_map",$condition);
  15. if(intval($_REQUEST['action_id'])!='')
  16. {
  17. $action_id= intval($_REQUEST['action_id']);
  18. }
  19. $this->assign('action_id',$action_id);
  20. //列表过滤器,生成查询Map对象
  21. $map = $this->_search ();
  22. //追加默认参数
  23. if($this->get("default_map"))
  24. $map = array_merge($map,$this->get("default_map"));
  25. if (method_exists ( $this, '_filter' )) {
  26. $this->_filter ( $map );
  27. }
  28. $name=$this->getActionName();
  29. $model = D ($name);
  30. if (! empty ( $model )) {
  31. $this->_list ( $model, $map );
  32. }
  33. /*$list = $this->get("list");
  34. $result = array();
  35. $row = 0;
  36. foreach($list as $k=>$v)
  37. {
  38. $v['level'] = -1;
  39. $v['title'] = $v['title'];
  40. $result[$row] = $v;
  41. $row++;
  42. $sub_cate = M(MODULE_NAME)->where(array("id"=>array("in",D(MODULE_NAME)->getChildIds($v['id'])),'is_delete'=>0))->findAll();
  43. $sub_cate = D(MODULE_NAME)->toFormatTree($sub_cate);
  44. foreach($sub_cate as $kk=>$vv)
  45. {
  46. $vv['title'] = $vv['title_show'];
  47. $result[$row] = $vv;
  48. $row++;
  49. }
  50. }
  51. //dump($result);exit;
  52. $this->assign("list",$result);*/
  53. $this->display ();
  54. return;
  55. }
  56. public function trash()
  57. {
  58. $condition['is_delete'] = 1;
  59. $this->assign("default_map",$condition);
  60. parent::index();
  61. }
  62. public function add()
  63. {
  64. /*$cate_tree = M(MODULE_NAME)->where('is_delete = 0')->findAll();
  65. $cate_tree = D(MODULE_NAME)->toFormatTree($cate_tree);
  66. // var_dump($cate_tree);
  67. $this->assign("cate_tree",$cate_tree);*/
  68. $this->assign("new_sort", M(MODULE_NAME)->where("is_delete=0")->max("sort")+1);
  69. $this->display();
  70. }
  71. public function edit() {
  72. $id = intval($_REQUEST ['id']);
  73. $condition['is_delete'] = 0;
  74. $condition['id'] = $id;
  75. $vo = M(MODULE_NAME)->where($condition)->find();
  76. $this->assign ( 'vo', $vo );
  77. $ids = D(MODULE_NAME)->getChildIds($id);
  78. $ids[] = $id;
  79. $condition['is_delete'] = 0;
  80. $condition['id'] = array('not in',$ids);
  81. $cate_tree = M(MODULE_NAME)->where($condition)->findAll();
  82. $cate_tree = D(MODULE_NAME)->toFormatTree($cate_tree);
  83. $this->assign("cate_tree",$cate_tree);
  84. $this->display ();
  85. }
  86. public function insert() {
  87. B('FilterString');
  88. $data = M(MODULE_NAME)->create ();
  89. //开始验证有效性
  90. $this->assign("jumpUrl",u(MODULE_NAME."/add"));
  91. if(!check_empty($data['title']))
  92. {
  93. $this->error(L("ARTICLECATE_TITLE_EMPTY_TIP"));
  94. }
  95. //开始同步type_id
  96. if($data['pid']>0)
  97. {
  98. $data['type_id'] = M("ArticleCate")->where("id=".$data['pid'])->getField("type_id");
  99. }
  100. // 更新数据
  101. $log_info = $data['title'];
  102. $data['seo_title'] = strim($data['seo_title']);
  103. if(!$this->check_bs($data['seo_title'])){
  104. $this->error("SEO标识 已经存在或和前台模块名称一样",0,$log_info.L("UPDATE_FAILED"));
  105. }
  106. if($data['title']=='主播协议' || $data['title']=='隐私政策'){
  107. $cate_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."article_cate where title = '".$data['title']."'");
  108. if($cate_id){
  109. $this->error("分类名称已存在,请重新填写!");
  110. }
  111. }
  112. $data['title'] = strim($data['title']);
  113. $list=M(MODULE_NAME)->add($data);
  114. if (false !== $list) {
  115. $this->create_httpd();
  116. //成功提示
  117. save_log($log_info.L("INSERT_SUCCESS"),1);
  118. clear_auto_cache("cache_shop_acate_tree");
  119. clear_auto_cache("deal_shop_acate_belone_ids");
  120. clear_auto_cache("get_help_cache");
  121. $this->success(L("INSERT_SUCCESS"));
  122. } else {
  123. //错误提示
  124. save_log($log_info.L("INSERT_FAILED"),0);
  125. $this->error(L("INSERT_FAILED"));
  126. }
  127. }
  128. public function set_sort()
  129. {
  130. $id = intval($_REQUEST['id']);
  131. $sort = intval($_REQUEST['sort']);
  132. $log_info = M(MODULE_NAME)->where("id=".$id)->getField("title");
  133. if(!check_sort($sort))
  134. {
  135. $this->error(l("SORT_FAILED"),1);
  136. }
  137. M(MODULE_NAME)->where("id=".$id)->setField("sort",$sort);
  138. clear_auto_cache("cache_shop_acate_tree");
  139. clear_auto_cache("get_help_cache");
  140. save_log($log_info.l("SORT_SUCCESS"),1);
  141. $this->success(l("SORT_SUCCESS"),1);
  142. }
  143. public function set_effect()
  144. {
  145. $id = intval($_REQUEST['id']);
  146. $ajax = intval($_REQUEST['ajax']);
  147. $info = M(MODULE_NAME)->where("id=".$id)->getField("title");
  148. $c_is_effect = M(MODULE_NAME)->where("id=".$id)->getField("is_effect"); //当前状态
  149. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  150. M(MODULE_NAME)->where("id=".$id)->setField("is_effect",$n_is_effect);
  151. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  152. clear_auto_cache("cache_shop_acate_tree");
  153. clear_auto_cache("deal_shop_acate_belone_ids");
  154. clear_auto_cache("get_help_cache");
  155. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  156. }
  157. public function update() {
  158. B('FilterString');
  159. $data = M(MODULE_NAME)->create ();
  160. $log_info = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("title");
  161. //开始验证有效性
  162. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  163. $seo_title = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("seo_title");
  164. $data['seo_title'] = strim($data['seo_title']);
  165. if(!$this->check_bs($data['seo_title'],$seo_title)){
  166. $this->error("SEO标识 已经存在或和前台模块名称一样",0,$log_info.L("UPDATE_FAILED"));
  167. }
  168. if(!check_empty($data['title']))
  169. {
  170. $this->error(L("ARTICLECATE_TITLE_EMPTY_TIP"));
  171. }
  172. if($data['title']=='主播协议' || $data['title']=='隐私政策'){
  173. $cate_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."article_cate where title = '".$data['title']."'");
  174. if($cate_id && $cate_id!=$data['id']){
  175. $this->error("分类名称已存在,请重新填写!");
  176. }
  177. }
  178. if($data['pid']>0)
  179. {
  180. $data['type_id'] = M("ArticleCate")->where("id=".$data['pid'])->getField("type_id");
  181. }
  182. //开始同步type_id
  183. $ids = D("ArticleCate")->getChildIds($data['id']);
  184. M("ArticleCate")->where(array("id"=>array("in",$ids)))->setField("type_id",$data['type_id']);
  185. $data['title'] = strim($data['title']);
  186. // 更新数据
  187. $list=M(MODULE_NAME)->save ($data);
  188. if (false !== $list) {
  189. $this->create_httpd();
  190. //成功提示
  191. save_log($log_info.L("UPDATE_SUCCESS"),1);
  192. clear_auto_cache("cache_shop_acate_tree");
  193. clear_auto_cache("deal_shop_acate_belone_ids");
  194. clear_auto_cache("get_help_cache");
  195. $this->success(L("UPDATE_SUCCESS"));
  196. } else {
  197. //错误提示
  198. save_log($log_info.L("UPDATE_FAILED"),0);
  199. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  200. }
  201. }
  202. public function delete() {
  203. //删除指定记录
  204. $ajax = intval($_REQUEST['ajax']);
  205. $id = $_REQUEST ['id'];
  206. if (isset ( $id )) {
  207. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  208. /*if(M("ArticleCate")->where(array ('pid' => array ('in', explode ( ',', $id ) ),'is_delete'=>0 ))->count()>0)
  209. {
  210. $result['info'] = l("SUB_ARTICLECATE_EXIST");
  211. $result['status'] = 0;
  212. ajax_return($result);
  213. }*/
  214. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  215. foreach($rel_data as $data)
  216. {
  217. $info[] = $data['title'];
  218. if($data['title']=='隐私政策' || $data['title']=='主播协议'){
  219. $result['status'] = 0;
  220. $result['info'] = '分类《隐私政策》或《主播协议》不能删除,请重新选择。';
  221. admin_ajax_return($result);
  222. }
  223. }
  224. if(M("Article")->where(array ('cate_id' => array ('in', explode ( ',', $id ) ),'is_delete'=>0 ))->count()>0)
  225. {
  226. $result['info'] = l("SUB_ARTICLE_EXIST");
  227. $result['status'] = 0;
  228. admin_ajax_return($result);
  229. }
  230. if($info) $info = implode(",",$info);
  231. $list = M(MODULE_NAME)->where ( $condition )->setField ( 'is_delete', 1 );
  232. if ($list!==false) {
  233. save_log($info.l("DELETE_SUCCESS"),1);
  234. clear_auto_cache("cache_shop_acate_tree");
  235. clear_auto_cache("deal_shop_acate_belone_ids");
  236. clear_auto_cache("get_help_cache");
  237. $result['info'] = "删除成功!";
  238. $result['status'] = 1;
  239. admin_ajax_return($result);
  240. } else {
  241. save_log($info.l("DELETE_FAILED"),0);
  242. $result['info'] = "删除失败!";
  243. $result['status'] = 0;
  244. admin_ajax_return($result);
  245. }
  246. } else {
  247. $this->error (l("INVALID_OPERATION"),$ajax);
  248. }
  249. }
  250. public function restore() {
  251. //删除指定记录
  252. $ajax = intval($_REQUEST['ajax']);
  253. $id = $_REQUEST ['id'];
  254. if (isset ( $id )) {
  255. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  256. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  257. foreach($rel_data as $data)
  258. {
  259. $info[] = $data['title'];
  260. }
  261. if($info) $info = implode(",",$info);
  262. $list = M(MODULE_NAME)->where ( $condition )->setField ( 'is_delete', 0 );
  263. if ($list!==false) {
  264. save_log($info.l("RESTORE_SUCCESS"),1);
  265. clear_auto_cache("cache_shop_acate_tree");
  266. clear_auto_cache("deal_shop_acate_belone_ids");
  267. clear_auto_cache("get_help_cache");
  268. $this->success (l("RESTORE_SUCCESS"),$ajax);
  269. } else {
  270. save_log($info.l("RESTORE_FAILED"),0);
  271. $this->error (l("RESTORE_FAILED"),$ajax);
  272. }
  273. } else {
  274. $this->error (l("INVALID_OPERATION"),$ajax);
  275. }
  276. }
  277. public function foreverdelete() {
  278. //彻底删除指定记录
  279. $ajax = intval($_REQUEST['ajax']);
  280. $id = $_REQUEST ['id'];
  281. if (isset ( $id )) {
  282. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  283. if(M("Article")->where(array ('cate_id' => array ('in', explode ( ',', $id ) ) ))->count()>0)
  284. {
  285. $this->error (l("SUB_ARTICLE_EXIST"),$ajax);
  286. }
  287. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  288. foreach($rel_data as $data)
  289. {
  290. $info[] = $data['title'];
  291. }
  292. if($info) $info = implode(",",$info);
  293. $list = M(MODULE_NAME)->where ( $condition )->delete();
  294. if ($list!==false) {
  295. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  296. clear_auto_cache("cache_shop_acate_tree");
  297. clear_auto_cache("deal_shop_acate_belone_ids");
  298. clear_auto_cache("get_help_cache");
  299. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  300. } else {
  301. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  302. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  303. }
  304. } else {
  305. $this->error (l("INVALID_OPERATION"),$ajax);
  306. }
  307. }
  308. public function get_bs(){
  309. $article_cates_bs= load_auto_cache("article_cates_bs",array(),false);
  310. $article_cates_bs=array_keys($article_cates_bs);
  311. return $article_cates_bs;
  312. }
  313. /*
  314. *
  315. */
  316. public function create_httpd(){
  317. $htppd=APP_ROOT_PATH.".htaccess";
  318. $content=file_get_contents($htppd);
  319. if(strpos($content,'title')==false){
  320. $htppd_old=APP_ROOT_PATH."public/rewrite_rule/.htaccess";
  321. $content=file_get_contents($htppd_old);
  322. }
  323. $article_cates_bs=$this->get_bs();
  324. $article_cates_bs=implode('|',$article_cates_bs);
  325. $str=trim($article_cates_bs,'|');
  326. $content=str_replace("title",$str,$content);
  327. file_put_contents($htppd,$content);
  328. }
  329. /*
  330. *
  331. */
  332. public function check_bs($bs,$seo_title){
  333. if(!$bs){
  334. return true;
  335. }
  336. $bs = strim($bs);
  337. $article_cates_bs=$this->get_bs();
  338. if($seo_title){
  339. foreach($article_cates_bs as $k=>$v){
  340. if($v==$seo_title){
  341. unset($article_cates_bs[$k]);
  342. }
  343. }
  344. }
  345. $article_cates_bs=array_merge($article_cates_bs,array('account','ajax','article_cate','article',
  346. 'avatar','cart','collocation','comment','deal_vote','deal','deals_cate',
  347. 'deals','faq','help','home','index','investor','message','news','notify',
  348. 'online_book','payment','project','referra','settings','user_message','user',
  349. 'vote'));
  350. if(in_array($bs,$article_cates_bs)){
  351. return false;
  352. }else{
  353. return true;
  354. }
  355. }
  356. }
  357. ?>