ContentAction.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. /**
  3. *
  4. * Content(内容管理模块)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class ContentAction extends AdminbaseAction
  9. {
  10. protected $dao,$fields;
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. $module =$this->module[$this->moduleid]['name'];
  15. $this->dao = D($module);
  16. $fields = F($this->moduleid.'_Field');
  17. foreach($fields as $key => $res){
  18. $res['setup']=string2array($res['setup']);
  19. $this->fields[$key]=$res;
  20. }
  21. unset($fields);
  22. unset($res);
  23. $this->assign ('fields',$this->fields);
  24. }
  25. /**
  26. * 列表
  27. *
  28. */
  29. public function index()
  30. {
  31. $template = file_exists(THEME_PATH.MODULE_NAME.'_index.html') ? MODULE_NAME.':index' : 'Content:index';
  32. $this->_list(MODULE_NAME);
  33. $this->display ($template);
  34. }
  35. public function add()
  36. {
  37. $vo['catid']= intval($_GET['catid']);
  38. $form=new Form($vo);
  39. $form->isadmin=1;
  40. $this->assign ( 'form', $form );
  41. $template = file_exists(THEME_PATH.MODULE_NAME.'_edit.html') ? MODULE_NAME.':edit' : 'Content:edit';
  42. $this->display ( $template);
  43. }
  44. public function edit()
  45. {
  46. $id = $_REQUEST ['id'];
  47. if(MODULE_NAME=='Page'){
  48. $Page=D('Page');
  49. $p = $Page->find($id);
  50. if(empty($p)){
  51. $data['id']=$id;
  52. $data['title'] = $this->categorys[$id]['catname'];
  53. $data['keywords'] = $this->categorys[$id]['keywords'];
  54. $Page->add($data);
  55. }
  56. }
  57. $vo = $this->dao->getById ( $id );
  58. $vo['content'] = htmlspecialchars($vo['content']);
  59. $data = M("Article")->where("catid = ".$vo['catid'])->order("id asc")->limit(1)->find();
  60. $datas = getimagesize($this->Config['site_url'].'/'.$data['thumb']);
  61. $form=new Form($vo);
  62. $this->assign ( 'vo', $vo );
  63. $this->assign ( 'datas', $datas );
  64. $this->assign ( 'form', $form );
  65. $template = file_exists(THEME_PATH.MODULE_NAME.'_edit.html') ? MODULE_NAME.':edit' : 'Content:edit';
  66. $this->display ( $template);
  67. }
  68. /**
  69. * 录入
  70. *
  71. */
  72. public function insert($module='',$fields=array(),$userid=0,$username='',$groupid=0)
  73. {
  74. $model = $module ? M($module) : $this->dao;
  75. $fields = $fields ? $fields : $this->fields ;
  76. if($fields['verifyCode']['status'] && (md5($_POST['verifyCode']) != $_SESSION['verify'])){
  77. $this->assign ( 'jumpUrl','javascript:history.go(-1);');
  78. $this->error(L('error_verify'));
  79. }
  80. $_POST = checkfield($fields,$_POST);
  81. if(empty($_POST)) $this->error (L('do_empty'));
  82. $_POST['createtime'] = time();
  83. $_POST['updatetime'] = $_POST['createtime'];
  84. $_POST['userid'] = $module ? $userid : $_SESSION['userid'];
  85. $_POST['username'] = $module ? $username : $_SESSION['username'];
  86. if($_POST['style_color']) $_POST['style_color'] = 'color:'.$_POST['style_color'];
  87. if($_POST['style_bold']) $_POST['style_bold'] = ';font-weight:'.$_POST['style_bold'];
  88. if($_POST['style_color'] || $_POST['style_bold'] ) $_POST['title_style'] = $_POST['style_color'].$_POST['style_bold'];
  89. $module = $module? $module : MODULE_NAME ;
  90. if(GROUP_NAME=='User')$_POST['status'] = $this->Role[$groupid]['allowpostverify'] ? 1 : 0;
  91. if (false === $model->create ()) {
  92. $this->error ( $model->getError () );
  93. }
  94. $_POST['id'] = $id= $model->add();
  95. if ($id !==false) {
  96. $catid = $module =='Page' ? $id : $_POST['catid'];
  97. if($_POST['aid']) {
  98. $Attachment =M('Attachment');
  99. $aids = implode(',',$_POST['aid']);
  100. $data['id']=$id;
  101. $data['catid']= $catid;
  102. $data['status']= '1';
  103. $Attachment->where("aid in (".$aids.")")->save($data);
  104. }
  105. $tablename=C('DB_PREFIX').strtolower($module);
  106. $db=D('');
  107. $db = DB::getInstance();
  108. $tables = $db->getTables();
  109. $Fields=$db->getFields($tablename);
  110. if(isset($Fields['url'])){
  111. $data='';
  112. $cat = $this->categorys[$catid];
  113. $url = geturl($cat,$_POST,$this->Urlrule);
  114. $data['id']= $id;
  115. $data['url']= $url[0];
  116. $model->save($data);
  117. }
  118. if($_POST['keywords'] && $module !='Page'){
  119. $keywordsarr=explode(',',$_POST['keywords']);
  120. $i=0;
  121. $tagsdata =M('Tags_data');
  122. $tagsdata->where("id=".$id)->delete();
  123. foreach((array)$keywordsarr as $tagname){
  124. if($tagname){
  125. $tagidarr=$tagdatas=$where=array();
  126. $where['name']=array('eq',$tagname);
  127. $where['moduleid']=array('eq',$cat['moduleid']);
  128. $tagid=M('Tags')->where($where)->field('id')->find();
  129. $tagidarr['id']=$id;
  130. if($tagid){
  131. $num = $tagsdata->where("tagid=".$tagid[id])->count();
  132. $tagdatas['num']=$num+1;
  133. M('Tags')->where("id=".$tagid[id])->save($tagdatas);
  134. $tagidarr['tagid']=$tagid['id'];
  135. }else{
  136. $tagdatas['moduleid']=$cat['moduleid'];
  137. $tagdatas['name'] = $tagname;
  138. $tagdatas['slug'] = Pinyin($tagname);
  139. $tagdatas['num']=1;
  140. $tagdatas['lang']=$_POST['lang'];
  141. $tagdatas['module']= $cat['module'];
  142. $tagidarr['tagid']=M('Tags')->add($tagdatas);
  143. }
  144. $i++;
  145. $tagsdata->add($tagidarr);
  146. }
  147. }
  148. }
  149. if($cat['presentpoint']){
  150. $user =M('User');
  151. if($cat['presentpoint']>0) $user->where("id=".$_POST['userid'])->setInc('point',$cat['presentpoint']);
  152. if($cat['presentpoint']<0) $user->where("id=".$_POST['userid'])->setDec('point',$cat['presentpoint']);
  153. }
  154. if($cat['ishtml'] && $_POST['status']){
  155. if($module!='Page' && $_POST['status']) $this->create_show($id,$module);
  156. $arrparentid = array_filter(explode(',',$cat['arrparentid'].','.$cat['id']));
  157. foreach($arrparentid as $catid) {
  158. if($this->categorys[$catid]['ishtml']) $this->clisthtml($catid);
  159. }
  160. }
  161. if($this->sysConfig['HOME_ISHTML']) $this->create_index();
  162. if(GROUP_NAME=='Admin'){
  163. $this->assign ( 'jumpUrl', U($module.'/index') );
  164. }elseif(GROUP_NAME=='User'){
  165. $this->assign ( 'jumpUrl',$_SERVER['HTTP_REFERER']);
  166. //$this->assign ( 'jumpUrl', U(GROUP_NAME.'-'.MODULE_NAME.'/add?moduleid='.$cat['moduleid']) );
  167. }
  168. $this->success (L('add_ok'));
  169. } else {
  170. $this->error (L('add_error').': '.$model->getDbError());
  171. }
  172. }
  173. function update($module='',$fields=array(),$userid=0,$username='')
  174. {
  175. $model = $module ? M($module) : $this->dao;
  176. $fields = $fields ? $fields : $this->fields ;
  177. if($fields['verifyCode']['status'] && (md5($_POST['verifyCode']) != $_SESSION['verify'])){
  178. $this->assign ( 'jumpUrl','javascript:history.go(-1);');
  179. $this->error(L('error_verify'));
  180. }
  181. $_POST = checkfield($fields,$_POST);
  182. if(empty($_POST)) $this->error (L('do_empty'));
  183. $_POST['updatetime'] = time();
  184. if($_POST['style_color']) $_POST['style_color'] = 'color:'.$_POST['style_color'];
  185. if($_POST['style_bold']) $_POST['style_bold'] = ';font-weight:'.$_POST['style_bold'];
  186. if($_POST['style_color'] || $_POST['style_bold'] ) $_POST['title_style'] = $_POST['style_color'].$_POST['style_bold'];
  187. $cat = $this->categorys[$_POST['catid']];
  188. $module = $module? $module : MODULE_NAME ;
  189. $_POST['url'] = geturl($cat,$_POST,$this->Urlrule);
  190. $_POST['url'] =$_POST['url'][0];
  191. $olddata = $model->find($_POST['id']);
  192. if (false === $model->create ()) {
  193. $this->error ( $model->getError () );
  194. }
  195. // 更新数据
  196. $list=$model->save ();
  197. if (false !== $list) {
  198. $id= $_POST['id'];
  199. $catid = $module =='Page' ? $id : $_POST['catid'];
  200. if($olddata['keywords']!=$_POST['keywords'] && $module !='Page'){
  201. $tagidarr=$tagdatas=$where=array();
  202. $where['name']=array('in',$olddata['keywords']);
  203. $where['moduleid']=array('eq',$cat['moduleid']);
  204. $where['lang']=array('eq',$_POST['lang']);
  205. M('Tags')->where($where)->setDec('num');
  206. $tagsdata =M('Tags_data');
  207. $tagsdata->where("id=".$id)->delete();
  208. $keywordsarr=explode(',',$_POST['keywords']);
  209. foreach((array)$keywordsarr as $tagname){
  210. if($tagname){
  211. $tagidarr=$tagdatas=$where=array();
  212. $where['name']=array('eq',$tagname);
  213. $where['moduleid']=array('eq',$cat['moduleid']);
  214. $where['lang']=array('eq',$_POST['lang']);
  215. $tagid=M('Tags')->where($where)->field('id')->find();
  216. $tagidarr['id']=$id;
  217. if($tagid['id']>0){
  218. M('Tags')->where("id=".$tagid[id])->setInc('num'); ;
  219. $tagidarr['tagid']=$tagid['id'];
  220. }else{
  221. $tagdatas['moduleid']=$cat['moduleid'];
  222. $tagdatas['name'] = $tagname;
  223. $tagdatas['slug'] = Pinyin($tagname);
  224. $tagdatas['num']=1;
  225. $tagdatas['lang']=$_POST['lang'];
  226. $tagdatas['module']= $cat['module'];
  227. $tagidarr['tagid']=M('Tags')->add($tagdatas);
  228. }
  229. $tagsdata->add($tagidarr);
  230. }
  231. }
  232. M('Tags')->where('num<=0')->delete();
  233. }
  234. if($_POST['aid']) {
  235. $Attachment =M('Attachment');
  236. $aids = implode(',',$_POST['aid']);
  237. $data['id']= $id;
  238. $data['catid']= $catid;
  239. $data['status']= '1';
  240. $Attachment->where("aid in (".$aids.")")->save($data);
  241. }
  242. $cat = $this->categorys[$catid];
  243. if($cat['ishtml']){
  244. if($module!='Page' && $_POST['status']) $this->create_show($_POST['id'],$module);
  245. $arrparentid = array_filter(explode(',',$cat['arrparentid'].','.$cat['id']));
  246. foreach($arrparentid as $catid) {
  247. if($this->categorys[$catid]['ishtml']) $this->clisthtml($catid);
  248. }
  249. }
  250. if($this->sysConfig['HOME_ISHTML']) $this->create_index();
  251. $this->assign ( 'jumpUrl', $_POST['forward'] );
  252. $this->success (L('edit_ok'));
  253. } else {
  254. //错误提示
  255. $this->success (L('edit_error').': '.$model->getDbError());
  256. }
  257. }
  258. function statusallok(){
  259. $module = MODULE_NAME;
  260. $model = M ( $module );
  261. $ids=$_POST['ids'];
  262. if(!empty($ids) && is_array($ids)){
  263. $id=implode(',',$ids);
  264. $data = $model->select($id);
  265. if($data){
  266. foreach($data as $key=>$r){
  267. $model->save(array(id=>$r['id'],status=>1));
  268. if($this->categorys[$r['catid']]['ishtml'] && $r['status'])$this->create_show($r['id'],$module);
  269. }
  270. $cat = $this->categorys[$r['catid']];
  271. if($cat['ishtml']){
  272. if($this->sysConfig['HOME_ISHTML']) $this->create_index();
  273. $arrparentid = array_filter(explode(',',$cat['arrparentid'].','.$cat['id']));
  274. foreach($arrparentid as $catid) {
  275. if($this->categorys[$catid]['ishtml']) $this->clisthtml($catid);
  276. }
  277. }
  278. $this->success(L('do_ok'));
  279. }else{
  280. $this->error(L('do_error').': '.$model->getDbError());
  281. }
  282. }else{
  283. $this->error(L('do_empty'));
  284. }
  285. }
  286. /*状态*/
  287. public function status(){
  288. $module = MODULE_NAME;
  289. $model = D ($module);
  290. if($model->save($_GET)){
  291. $_POST ='';
  292. $_POST = $model->find($_GET['id']);
  293. $cat = $this->categorys[$_POST['catid']];
  294. if($cat['ishtml']){
  295. if($module!='Page' && $_POST['status']) $this->create_show($_POST['id'],$module);
  296. if($this->sysConfig['HOME_ISHTML']) $this->create_index();
  297. $arrparentid = array_filter(explode(',',$cat['arrparentid'].','.$cat['id']));
  298. foreach($arrparentid as $catid) {
  299. if($this->categorys[$catid]['ishtml']) $this->clisthtml($catid);
  300. }
  301. }
  302. $this->success(L('do_ok'));
  303. }else{
  304. $this->error(L('do_error'));
  305. }
  306. }
  307. //获取图片大小
  308. function get_img(){
  309. $cid = $_POST['cid'];
  310. $model = $_POST['model'];
  311. $data = M($model)->where("catid = ".$cid)->order("id asc")->limit(1)->find();
  312. $datas = getimagesize($this->Config['site_url'].'/'.$data['thumb']);
  313. if(!$datas){$datas = array('','');}
  314. echo json_encode($datas);
  315. }
  316. }?>