AdminbaseAction.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <?php
  2. /**
  3. *
  4. * Adminbase (后台公共模块)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class AdminbaseAction extends Action
  9. {
  10. protected $mod,$Config,$sysConfig,$nav,$menudata,$cache_model,$categorys,$module,$moduleid,$Type,$Urlrule,$Lang;
  11. function _initialize()
  12. {
  13. $this->sysConfig = F('sys.config');
  14. $this->menudata = F('Menu');
  15. $this->module = F('Module');
  16. $this->Type =F('Type');
  17. $this->Urlrule =F('Urlrule');
  18. $this->mod = F('Mod');
  19. if(APP_LANG){
  20. $this->Lang = F('Lang');
  21. if($_GET['l']){
  22. if($this->Lang[$_GET['l']]['id']){
  23. $_SESSION['YP_lang'] = $_GET['l'];
  24. $_SESSION['YP_langid'] = $this->Lang[$_GET['l']]['id'];
  25. }else{
  26. $this->error ( L ( 'NO_LANG' ) );
  27. }
  28. }elseif(!$_SESSION['YP_lang'] || !$_SESSION['YP_langid']){
  29. $_SESSION['YP_lang'] = $this->sysConfig['DEFAULT_LANG'];
  30. $_SESSION['YP_langid'] = $this->Lang[$this->sysConfig['DEFAULT_LANG']]['id'];
  31. }
  32. define('LANG_NAME',$_SESSION['YP_lang']);
  33. define('LANG_ID',$_SESSION['YP_langid']);
  34. $this->assign('l',LANG_NAME);
  35. $this->assign('langid',LANG_ID);
  36. $this->categorys = F('Category_'.LANG_NAME);
  37. $this->Config = F('Config_'.LANG_NAME);
  38. $this->assign('Lang',$this->Lang);
  39. }else{
  40. $this->Config = F('Config');
  41. $this->categorys = F('Category');
  42. }
  43. $this->assign('module_name',MODULE_NAME);
  44. $this->assign('action_name',ACTION_NAME);
  45. $this->cache_model=array('Lang','Menu','Config','Module','Role','Category','Posid','Field','Type','Urlrule','Dbsource');
  46. C('HOME_ISHTML',$this->sysConfig['HOME_ISHTML']);
  47. C('PAGE_LISTROWS',$this->sysConfig['PAGE_LISTROWS']);
  48. C('URL_LANG',$this->sysConfig['DEFAULT_LANG']);
  49. C('URL_M',$this->sysConfig['URL_MODEL']);
  50. C('URL_M_PATHINFO_DEPR',$this->sysConfig['URL_PATHINFO_DEPR']);
  51. C('URL_M_HTML_SUFFIX',$this->sysConfig['URL_HTML_SUFFIX']);
  52. C('URL_URLRULE',$this->sysConfig['URL_URLRULE']);
  53. C('ADMIN_ACCESS',$this->sysConfig['ADMIN_ACCESS']);
  54. // 用户权限检查
  55. if (C ( 'USER_AUTH_ON' ) && !in_array(MODULE_NAME,explode(',',C('NOT_AUTH_MODULE')))) {
  56. import ( '@.ORG.RBAC' );
  57. if (! RBAC::AccessDecision ('Admin')) {
  58. //检查认证识别号
  59. if (! $_SESSION [C ( 'USER_AUTH_KEY' )]) {
  60. //跳转到认证网关
  61. redirect ( PHP_FILE . C ( 'USER_AUTH_GATEWAY' ) );
  62. }
  63. // 没有权限 抛出错误
  64. if (C ( 'RBAC_ERROR_PAGE' )) {
  65. // 定义权限错误页面
  66. redirect ( C ( 'RBAC_ERROR_PAGE' ) );
  67. } else {
  68. if (C ( 'GUEST_AUTH_ON' )) {
  69. $this->assign ( 'jumpUrl', PHP_FILE . C ( 'USER_AUTH_GATEWAY' ) );
  70. }
  71. // 提示错误信息
  72. $this->error ( L ( '_VALID_ACCESS_' ) );
  73. }
  74. }
  75. }
  76. $menuid = intval($_GET['menuid']);
  77. if(empty($menuid)) $menuid = cookie('menuid');
  78. if(!empty($menuid)){
  79. $this->nav = $this->getnav($menuid,1);
  80. if($this->nav)$this->assign('nav', $this->nav);
  81. }
  82. if($this->mod[MODULE_NAME]){
  83. $this->moduleid = $this->mod[MODULE_NAME];
  84. $this->m = $this->module[$this->moduleid];
  85. $this->assign('moduleid',$this->moduleid);
  86. $this->Type = F('Type');
  87. $this->assign('Type',$this->Type);
  88. if($this->module[$this->moduleid]['type']==1 && ACTION_NAME=='index'){
  89. if($this->categorys){
  90. foreach ($this->categorys as $r){
  91. if($_SESSION['groupid']!=1 && !in_array($_SESSION['groupid'],explode(',',$r['postgroup']))) continue;
  92. if($r['moduleid'] != $this->moduleid || $r['child']){
  93. $arr= explode(",",$r['arrchildid']);
  94. $show=0;
  95. foreach((array)$arr as $rr){
  96. if($this->categorys[$rr]['moduleid'] ==$this->moduleid) $show=1;
  97. }
  98. if(empty($show))continue;
  99. $r['disabled'] = $r['child'] ? ' disabled' : '';
  100. }else{
  101. $r['disabled'] = '';
  102. }
  103. $array[] = $r;
  104. }
  105. import ( '@.ORG.Tree' );
  106. $str = "<option value='\$id' \$disabled \$selected>\$spacer \$catname</option>";
  107. $tree = new Tree ($array);
  108. $select_categorys = $tree->get_tree(0, $str);
  109. $this->assign('select_categorys', $select_categorys);
  110. $this->assign('categorys', $this->categorys);
  111. }
  112. $this->assign('posids', F('Posid'));
  113. }
  114. }
  115. import("@.ORG.Form");
  116. $this->assign('Form', new Form());
  117. }
  118. function getnav($menuid,$isnav=0){
  119. if($menuid){
  120. $bnav = $this->menudata[$menuid];
  121. if(empty($bnav['action']))$bnav['action'] ='index';
  122. $array = array('menuid'=> $bnav['id']);
  123. parse_str($bnav['data'],$c);
  124. $bnav['data'] = $c + $array;
  125. }
  126. if($this->menudata){
  127. $accessList = $_SESSION['_ACCESS_LIST'];
  128. foreach($this->menudata as $key=>$module) {
  129. if($module['parentid'] != $menuid || $module['status']==0) continue;
  130. if(isset($accessList[strtoupper('Admin')][strtoupper($module['model'])]) || $_SESSION[C('ADMIN_AUTH_KEY')]) {
  131. //设置模块访问权限$module['access'] = 1;
  132. if(empty($module['action'])) $module['action']='index';
  133. //检测动作权限
  134. if(isset($accessList[strtoupper('Admin')][strtoupper($module['model'])][strtoupper($module['action'])]) || $_SESSION[C('ADMIN_AUTH_KEY')]){
  135. $nav[$key] = $module;
  136. if($isnav){
  137. $array=array('menuid'=> $nav[$key]['parentid']);
  138. cookie('menuid',$nav[$key]['parentid']);
  139. //$_SESSION['menuid'] = $nav[$key]['parentid'];
  140. }else{
  141. $array=array('menuid'=> $nav[$key]['id']);
  142. }
  143. if(empty($menuid) && empty($isnav)) $array=array();
  144. $c=array();
  145. parse_str($nav[$key]['data'],$c);
  146. $nav[$key]['data'] = $c + $array;
  147. }
  148. }
  149. }
  150. }
  151. $navdata['bnav']=$bnav;
  152. $navdata['nav']=$nav;
  153. return $navdata;
  154. }
  155. function _list($modelname, $map = '', $sortBy = '', $asc = false ,$listRows = 15) {
  156. $model = M($modelname);
  157. $id=$model->getPk ();
  158. $this->assign ( 'pkid', $id );
  159. if (isset ( $_REQUEST ['order'] )) {
  160. $order = $_REQUEST ['order'];
  161. } else {
  162. $order = ! empty ( $sortBy ) ? $sortBy : $id;
  163. }
  164. if (isset ( $_REQUEST ['sort'])) {
  165. $_REQUEST ['sort']=='asc' ? $sort = 'asc' : $sort = 'desc';
  166. } else {
  167. $sort = $asc ? 'asc' : 'desc';
  168. }
  169. $_REQUEST ['sort'] = $sort;
  170. $_REQUEST ['order'] = $order;
  171. $keyword=$_REQUEST['keyword'];
  172. $searchtype=$_REQUEST['searchtype'];
  173. $groupid =intval($_REQUEST['groupid']);
  174. $catid =intval($_REQUEST['catid']);
  175. $posid =intval($_REQUEST['posid']);
  176. $typeid =intval($_REQUEST['typeid']);
  177. if(APP_LANG)if($this->moduleid)$map['lang']=array('eq',LANG_ID);
  178. if(!empty($keyword) && !empty($searchtype)){
  179. $map[$searchtype]=array('like','%'.$keyword.'%');
  180. }
  181. if($groupid)$map['groupid']=$groupid;
  182. if($catid)$map['catid']=$catid;
  183. if($posid)$map['posid']=$posid;
  184. if($typeid) $map['typeid']=$typeid;
  185. $tables = $model->getDbFields();
  186. foreach($_REQUEST['map'] as $key=>$res){
  187. if( ($res==='0' || $res>0) || !empty($res) ){
  188. if($_REQUEST['maptype'][$key]){
  189. $map[$key]=array($_REQUEST['maptype'][$key],$res);
  190. }else{
  191. $map[$key]=intval($res);
  192. }
  193. $_REQUEST[$key]=$res;
  194. }else{
  195. unset($_REQUEST[$key]);
  196. }
  197. }
  198. $this->assign($_REQUEST);
  199. //取得满足条件的记录总数
  200. $count = $model->where ( $map )->count ( $id );//echo $model->getLastsql();
  201. if ($count > 0) {
  202. import ( "@.ORG.Page" );
  203. //创建分页对象
  204. if (! empty ( $_REQUEST ['listRows'] )) {
  205. $listRows = $_REQUEST ['listRows'];
  206. }
  207. $page = new Page ( $count, $listRows );
  208. //分页查询数据
  209. $field=$this->module[$this->moduleid]['listfields'];
  210. $field= (empty($field) || $field=='*') ? '*' : 'id,catid,url,posid,title,thumb,title_style,userid,username,hits,createtime,updatetime,status,listorder' ;
  211. $voList = $model->field($field)->where($map)->order( "`" . $order . "` " . $sort)->limit($page->firstRow . ',' . $page->listRows)->select ( );
  212. //分页跳转的时候保证查询条件
  213. foreach ( $map as $key => $val ) {
  214. if (! is_array ( $val )) {
  215. $page->parameter .= "$key=" . urlencode ( $val ) . "&";
  216. }
  217. }
  218. $map[C('VAR_PAGE')]='{$page}';
  219. unset($map['lang']);
  220. $map['lang']=LANG_ID;
  221. $map['listRows']=$listRows;
  222. $page->urlrule = U($modelname.'/index', $map);
  223. //分页显示
  224. $page = $page->show ();
  225. //列表排序显示
  226. $sortImg = $sort; //排序图标
  227. $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示
  228. $sort = $sort == 'desc' ? 1 : 0; //排序方式
  229. //模板赋值显示
  230. $this->assign ( 'list', $voList );
  231. $this->assign ( 'page', $page );
  232. }
  233. return;
  234. }
  235. /**
  236. * 添加
  237. *
  238. */
  239. function add() {
  240. $name = MODULE_NAME;
  241. $this->display ('edit');
  242. }
  243. function insert() {
  244. if($_POST['setup']) $_POST['setup']=array2string($_POST['setup']);
  245. $name = MODULE_NAME;
  246. $model = D ($name);
  247. if (false === $model->create ()) {
  248. $this->error ( $model->getError () );
  249. }
  250. $id = $model->add();
  251. if ($id !==false) {
  252. if(in_array($name,$this->cache_model)) savecache($name);
  253. if($_POST['aid']){
  254. $Attachment =M('Attachment');
  255. $aids = implode(',',$_POST['aid']);
  256. $data['id']= $id;
  257. $data['catid']= intval($_POST['catid']);
  258. $data['status']= '1';
  259. $Attachment->where("aid in (".$aids.")")->save($data);
  260. }
  261. if($_POST['isajax'])$this->assign('dialog','1');
  262. $jumpUrl = $_POST['forward'] ? $_POST['forward'] : U(MODULE_NAME.'/index');
  263. $this->assign ( 'jumpUrl',$jumpUrl );
  264. $this->success (L('add_ok'));
  265. } else {
  266. $this->error (L('add_error').': '.$model->getDbError());
  267. }
  268. }
  269. /**
  270. * 更新
  271. *
  272. */
  273. function edit() {
  274. $name = MODULE_NAME;
  275. $model = M ( $name );
  276. $pk=ucfirst($model->getPk ());
  277. $id = intval($_REQUEST [$model->getPk ()]);
  278. if(empty($id)) $this->error(L('do_empty'));
  279. $do='getBy'.$pk;
  280. $vo = $model->$do ( $id );
  281. if($vo['setup']) $vo['setup']=string2array($vo['setup']);
  282. $this->assign ( 'vo', $vo );
  283. $this->display ();
  284. }
  285. function update() {
  286. if($_POST['setup']) $_POST['setup']=array2string($_POST['setup']);
  287. $name = MODULE_NAME;
  288. $model = D ( $name );
  289. if (false === $model->create ()) {
  290. $this->error ( $model->getError () );
  291. }
  292. if (false !== $model->save ()) {
  293. if(in_array($name,$this->cache_model)) savecache($name);
  294. if($_POST['aid']){
  295. $Attachment =M('Attachment');
  296. $aids = implode(',',$_POST['aid']);
  297. $data['id']= $_POST['id'];
  298. $data['catid']= intval($_POST['catid']);
  299. $data['status']= '1';
  300. $Attachment->where("aid in (".$aids.")")->save($data);
  301. }
  302. if($_POST['isajax'])$this->assign('dialog','1');
  303. $jumpUrl = $_POST['forward'] ? $_POST['forward'] : U(MODULE_NAME.'/index');
  304. $this->assign ( 'jumpUrl', $jumpUrl);
  305. $this->success (L('edit_ok'));
  306. } else {
  307. $this->success (L('edit_error').': '.$model->getDbError());
  308. }
  309. }
  310. /**
  311. * 删除
  312. *
  313. */
  314. function delete(){
  315. $name = MODULE_NAME;
  316. $model = M ( $name );
  317. $pk = $model->getPk ();
  318. $id = $_REQUEST [$pk];
  319. if (isset ( $id )) {
  320. if(false!==$model->delete($id)){
  321. if(in_array($name,$this->cache_model)) savecache($name);
  322. if($this->moduleid){
  323. $fields = $model->getDbFields();
  324. delattach(array('moduleid'=>$this->moduleid,'id'=>$id));
  325. if($fields['keywords']){
  326. $olddata = $model->field('keywords')->find($id);
  327. $where['name']=array('in',$olddata['keywords']);
  328. $where['moduleid']=array('eq',$this->moduleid);
  329. if(APP_LANG)$where['lang']=array('eq',LANG_ID);
  330. M('Tags')->where($where)->setDec('num');
  331. M('Tags_data')->where("id=".$id)->delete();
  332. }
  333. }
  334. if($name=='Order')M('Order_data')->where('order_id='.$id)->delete();
  335. $this->success(L('delete_ok'));
  336. }else{
  337. $this->error(L('delete_error').': '.$model->getDbError());
  338. }
  339. }else{
  340. $this->error (L('do_empty'));
  341. }
  342. }
  343. /**
  344. * 批量删除
  345. *
  346. */
  347. function deleteall(){
  348. $name = MODULE_NAME;
  349. $model = M ( $name );
  350. $ids=$_POST['ids'];
  351. if(!empty($ids) && is_array($ids)){
  352. $id=implode(',',$ids);
  353. if(false!==$model->delete($id)){
  354. if(in_array($name,$this->cache_model)) savecache($name);
  355. if($this->moduleid){
  356. $fields = $model->getDbFields();
  357. delattach("moduleid=$this->moduleid and id in($id)");
  358. if($fields['keywords']){
  359. $olddata = $model->field('keywords')->where("id in($id)")->select();
  360. foreach((array)$olddata as $r){
  361. $where['name']=array('in',$r['keywords']);
  362. $where['moduleid']=array('eq',$this->moduleid);
  363. if(APP_LANG)$where['lang']=array('eq',LANG_ID);
  364. M('Tags')->where($where)->setDec('num');
  365. }
  366. M('Tags_data')->where("id in($id)")->delete();
  367. M('Tags')->where('num<=0')->delete();
  368. }
  369. }
  370. if($name=='Order')M('Order_data')->where('order_id in('.$id.')')->delete();
  371. $this->success(L('delete_ok'));
  372. }else{
  373. $this->error(L('delete_error').': '.$model->getDbError());
  374. }
  375. }else{
  376. $this->error(L('do_empty'));
  377. }
  378. }
  379. /**
  380. * 批量操作
  381. *
  382. */
  383. public function listorder()
  384. {
  385. $name = MODULE_NAME;
  386. $model = M ( $name );
  387. $pk = $model->getPk ();
  388. $ids = $_POST['listorders'];
  389. foreach($ids as $key=>$r) {
  390. $data['listorder']=$r;
  391. $model->where($pk .'='.$key)->save($data);
  392. }
  393. if(in_array($name,$this->cache_model)) savecache($name);
  394. $this->success (L('do_ok'));
  395. }
  396. /*状态*/
  397. public function status(){
  398. $name = MODULE_NAME;
  399. $model = D ($name);
  400. $_GET = get_safe_replace($_GET);
  401. if($model->save($_GET)){
  402. savecache(MODULE_NAME);
  403. $this->success(L('do_ok'));
  404. }else{
  405. $this->error(L('do_error'));
  406. }
  407. }
  408. /**
  409. * 默认操作
  410. *
  411. */
  412. public function index() {
  413. $name = MODULE_NAME;
  414. $model = M ($name);
  415. $id=$model->getPk ();
  416. $count = $model->where($_REQUEST['where'])->count();
  417. import ( "@.ORG.Page" );
  418. $p = new Page ( $count, 15 );
  419. unset($_GET[C('VAR_PAGE')]);
  420. $map=$_GET;
  421. $map[C('VAR_PAGE')]='{$page}';
  422. $p->urlrule = U($name.'/index',$map);
  423. $page = $p->show ();
  424. $list = $model->where($_REQUEST['where'])->order("$id desc")->limit($p->firstRow . ',' . $p->listRows)->select();
  425. $this->assign('list', $list);
  426. $this->assign ( 'page', $page );
  427. $this->display();
  428. }
  429. public function create_show($id,$module)
  430. {
  431. C('DEFAULT_THEME_NAME',$this->sysConfig['DEFAULT_THEME']);
  432. C('HTML_FILE_SUFFIX',$this->sysConfig['HTML_FILE_SUFFIX']);
  433. C('TMPL_FILE_NAME',str_replace('Admin/Default','Home/'.$this->sysConfig['DEFAULT_THEME'],C('TMPL_FILE_NAME')));
  434. if(APP_LANG){
  435. C('TMPL_CACHFILE_SUFFIX','_'.LANG_NAME.'.php');
  436. $lang = C('URL_LANG')!=LANG_NAME ? $lang = LANG_NAME.'/' : '';
  437. L(include LANG_PATH.LANG_NAME.'/common.php');
  438. $T = F('config_'.LANG_NAME,'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  439. }else{
  440. L(include LANG_PATH.$this->sysConfig['DEFAULT_LANG'].'/common.php');
  441. $T = F('config_'.$this->sysConfig['DEFAULT_LANG'],'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  442. }
  443. $this->assign('T',$T);
  444. foreach((array)$this->module as $r){
  445. if($r['issearch'])$search_module[$r['name']] = L($r['name']);
  446. }
  447. $this->assign('search_module',$search_module);
  448. $this->assign ( 'form',new Form());
  449. $p =1;
  450. $id=intval($id);
  451. if(empty($id)) $this->success (L('do_empty'));;
  452. $this->assign($this->Config);
  453. $this->assign('Categorys',$this->categorys);
  454. $this->assign('Module',$this->module);
  455. $this->assign('Type',$this->Type);
  456. $this->assign('module_name',$module);
  457. $dao= M($module);
  458. $data = $dao->find($id);
  459. $catid = $data['catid'];
  460. $this->assign('catid',$catid);
  461. $cat = $this->categorys[$data['catid']];
  462. $this->assign ($cat);
  463. $bcid = explode(",",$cat['arrparentid']);
  464. $bcid = $bcid[1];
  465. if($bcid == '') $bcid=intval($catid);
  466. $this->assign('bcid',$bcid);
  467. $seo_title = $data['title'].'-'.$cat['catname'];
  468. $this->assign ('seo_title',$seo_title);
  469. $this->assign ('seo_keywords',$data['keywords']);
  470. $this->assign ('seo_description',$data['description']);
  471. $fields = F($this->mod[$module].'_Field');
  472. foreach($data as $key=>$c_d){
  473. $setup='';
  474. $fields[$key]['setup'] =$setup=string2array($fields[$key]['setup']);
  475. if($setup['fieldtype']=='varchar' && $fields[$key]['type']!='text'){
  476. $data[$key.'_old_val'] =$data[$key];
  477. $data[$key]=fieldoption($fields[$key],$data[$key]);
  478. }elseif($fields[$key]['type']=='images' || $fields[$key]['type']=='files'){
  479. $p_data=explode(':::',$data[$key]);
  480. $data[$key]=array();
  481. foreach($p_data as $k=>$res){
  482. $p_data_arr=explode('|',$res);
  483. $data[$key][$k]['filepath'] = $p_data_arr[0];
  484. $data[$key][$k]['filename'] = $p_data_arr[1];
  485. }
  486. unset($p_data);
  487. unset($p_data_arr);
  488. }
  489. unset($setup);
  490. }
  491. $this->assign('fields',$fields);
  492. $this->assign ('form',new Form());
  493. $urlrule = geturl($cat,$data,$this->Urlrule);
  494. if(!empty($data['template'])){
  495. $template = $cat['module'].'_'.$data['template'];
  496. }elseif(!empty($cat['template_show'])){
  497. $template = $cat['module'].'_'.$cat['template_show'];
  498. }else{
  499. $template = $cat['module'].'_show';
  500. }
  501. //手动分页
  502. $CONTENT_POS = strpos($data['content'], '[page]');
  503. if($CONTENT_POS !== false){
  504. $pageurls=array();
  505. $contents = array_filter(explode('[page]',$data['content']));
  506. $pagenumber = count($contents);
  507. for($i=1; $i<=$pagenumber; $i++) {
  508. $pageurls[$i] = str_replace('{$page}',$i,$urlrule);
  509. }
  510. //生成分页
  511. foreach ($pageurls as $p=>$urls) {
  512. $pages = content_pages($pagenumber,$p, $pageurls);
  513. $this->assign ('pages',$pages);
  514. $data['content'] = $contents[$p-1];
  515. $this->assign ($data);
  516. $url= ($p > 1 ) ? $urls[1] : $urls[0];
  517. if(strstr($url,C('HTML_FILE_SUFFIX'))){
  518. $filename = basename($url,C('HTML_FILE_SUFFIX'));
  519. $dir = dirname($url).'/';
  520. }else{
  521. $filename = 'index';
  522. $dir= $url;
  523. }
  524. $dir = substr($dir,strlen(__ROOT__.'/'));
  525. $this->buildHtml($filename,$dir,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/'.$template.C('TMPL_TEMPLATE_SUFFIX'));
  526. }
  527. }else{
  528. $url = str_replace('{$page}', $p, $urlrule[0]);
  529. if(strstr($url,C('HTML_FILE_SUFFIX'))){
  530. $filename = basename($url,C('HTML_FILE_SUFFIX'));
  531. $dir = dirname($url).'/';
  532. }else{
  533. $filename = 'index';
  534. $dir= $url;
  535. }
  536. $this->assign ('pages','');
  537. $this->assign ($data);
  538. $dir = substr($dir,strlen(__ROOT__.'/'));
  539. $this->buildHtml($filename,$dir,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/'.$template.C('TMPL_TEMPLATE_SUFFIX'));
  540. }
  541. return true;
  542. }
  543. public function create_list($catid,$p=1,$count=0)
  544. {
  545. C('DEFAULT_THEME_NAME',$this->sysConfig['DEFAULT_THEME']);
  546. C('HTML_FILE_SUFFIX',$this->sysConfig['HTML_FILE_SUFFIX']);
  547. C('TMPL_FILE_NAME',str_replace('Admin/Default','Home/'.$this->sysConfig['DEFAULT_THEME'],C('TMPL_FILE_NAME')));
  548. if(APP_LANG){
  549. C('TMPL_CACHFILE_SUFFIX','_'.LANG_NAME.'.php');
  550. $lang = C('URL_LANG')!=LANG_NAME ? $lang = LANG_NAME.'/' : '';
  551. L(include LANG_PATH.LANG_NAME.'/common.php');
  552. $T = F('config_'.LANG_NAME,'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  553. }else{
  554. L(include LANG_PATH.$this->sysConfig['DEFAULT_LANG'].'/common.php');
  555. $T = F('config_'.$this->sysConfig['DEFAULT_LANG'],'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  556. }
  557. $this->assign('T',$T);
  558. foreach((array)$this->module as $r){
  559. if($r['issearch'])$search_module[$r['name']] = L($r['name']);
  560. }
  561. $this->assign('search_module',$search_module);
  562. $this->assign ( 'form',new Form());
  563. $this->assign($this->Config);
  564. $this->assign('Categorys',$this->categorys);
  565. $this->assign('Module',$this->module);
  566. $this->assign('Type',$this->Type);
  567. $catid =intval($catid);
  568. if(empty($catid)) $this->success (L('do_empty'));
  569. $cat = $this->categorys[$catid];
  570. $this->assign('catid',$catid);
  571. if($cat['type']) return;
  572. if(empty($cat['ishtml'])) return;
  573. unset($cat['id']);
  574. $this->assign($cat);
  575. $cat['id']=$catid;
  576. $bcid = explode(",",$cat['arrparentid']);
  577. $bcid = $bcid[1];
  578. if($bcid == '') $bcid=intval($catid);
  579. $this->assign('bcid',$bcid);
  580. $urlrule = geturl($cat,'',$this->Urlrule);
  581. $url= ($p > 1 ) ? $urlrule[1] : $urlrule[0];
  582. $url = str_replace('{$page}', $p, $url);
  583. if(strstr($url,C('HTML_FILE_SUFFIX'))){
  584. $filename = basename($url,C('HTML_FILE_SUFFIX'));
  585. $dir = dirname($url).'/';
  586. }else{
  587. $filename = 'index';
  588. $dir= $url;
  589. }
  590. $dir = substr($dir,strlen(__ROOT__.'/'));
  591. if(empty($module))$module=$cat['module'];
  592. $this->assign('module_name',$module);
  593. $this->assign ( 'fields', F($cat['moduleid'].'_Field') );
  594. $this->assign ( 'form',new Form());
  595. if($cat['moduleid']==1){
  596. $cat['listtype']=2;
  597. $module = $cat['module'];
  598. $dao= M($module);
  599. $data = $dao->find($catid);
  600. $seo_title = $cat['title'] ? $cat['title'] : $data['title'];
  601. $this->assign ('seo_title',$seo_title);
  602. $this->assign ('seo_keywords',$data['keywords']);
  603. $this->assign ('seo_description',$data['description']);
  604. $template = $cat['template_list']? $cat['template_list'] : 'index';
  605. //手动分页
  606. $CONTENT_POS = strpos($data['content'], '[page]');
  607. if($CONTENT_POS !== false){
  608. $contents = array_filter(explode('[page]',$data['content']));
  609. $pagenumber = count($contents);
  610. for($i=1; $i<=$pagenumber; $i++) {
  611. $pageurls[$i] = str_replace('{$page}',$i,$urlrule);
  612. }
  613. //生成分页
  614. foreach ($pageurls as $p=>$urls) {
  615. $pages = content_pages($pagenumber,$p, $pageurls);
  616. $this->assign ('pages',$pages);
  617. $data['content'] = $contents[$p-1];
  618. $this->assign ($data);
  619. if($p > 1)$filename = basename($pageurls[$p]['1'],C('HTML_FILE_SUFFIX'));
  620. //$this->buildHtml($filename,$dir,'Home/'.$template);
  621. $r=$this->buildHtml($filename,$dir,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Page_'.$template.C('TMPL_TEMPLATE_SUFFIX'));
  622. }
  623. }else{
  624. $this->assign($data);
  625. //$r=$this->buildHtml($filename,$dir,'Home/'.$template);
  626. $r=$this->buildHtml($filename,$dir,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Page_'.$template.C('TMPL_TEMPLATE_SUFFIX'));
  627. }
  628. }else{
  629. $seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];
  630. $this->assign ('seo_title',$seo_title);
  631. $this->assign ('seo_keywords',$cat['keywords']);
  632. $this->assign ('seo_description',$cat['description']);
  633. if($cat['listtype']==1){
  634. $template_r = 'index';
  635. }else{
  636. $where = " status=1 ";
  637. if($cat['child']){
  638. $where .= " and catid in(".$cat['arrchildid'].")";
  639. }else{
  640. $where .= " and catid=".$catid;
  641. }
  642. $module = $cat['module'];
  643. $dao= M($module);
  644. if(empty($count))$count = $dao->where($where)->count();
  645. if($count){
  646. import ( "@.ORG.Page" );
  647. $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
  648. $page = new Page ( $count, $listRows ,$p );
  649. $page->urlrule = $urlrule;
  650. $pages = $page->show();
  651. $field = $this->module[$this->mod[$module]]['listfields'];
  652. $field = $field ? $field : 'id,catid,userid,url,username,title,title_style,keywords,description,thumb,createtime,hits';
  653. $list = $dao->field($field)->where($where)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
  654. $this->assign('pages',$pages);
  655. $this->assign('list',$list);
  656. }
  657. $template_r = 'list';
  658. }
  659. $template = $cat['template_list']? $cat['template_list'] : $template_r;
  660. $r=$this->buildHtml($filename,$dir,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/'.$cat['module'].'_'.$template.C('TMPL_TEMPLATE_SUFFIX'));
  661. }
  662. if($r) return true;
  663. }
  664. public function create_index($sitemap)
  665. {
  666. C('HTML_FILE_SUFFIX',$this->sysConfig['HTML_FILE_SUFFIX']);
  667. C('DEFAULT_THEME_NAME',$this->sysConfig['DEFAULT_THEME']);
  668. C('TMPL_FILE_NAME',str_replace('Admin/Default','Home/'.$this->sysConfig['DEFAULT_THEME'],C('TMPL_FILE_NAME')));
  669. if(APP_LANG){
  670. C('TMPL_CACHFILE_SUFFIX','_'.LANG_NAME.'.php');
  671. $lang = C('URL_LANG')!=LANG_NAME ? $lang = LANG_NAME.'/' : '';
  672. L(include LANG_PATH.LANG_NAME.'/common.php');
  673. $T = F('config_'.LANG_NAME,'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  674. }else{
  675. L(include LANG_PATH.$this->sysConfig['DEFAULT_LANG'].'/common.php');
  676. $T = F('config_'.$this->sysConfig['DEFAULT_LANG'],'', './Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');
  677. }
  678. $this->assign('T',$T);
  679. foreach((array)$this->module as $r){
  680. if($r['issearch'])$search_module[$r['name']] = L($r['name']);
  681. }
  682. $this->assign('search_module',$search_module);
  683. $this->assign ( 'form',new Form());
  684. $this->assign('Module',$this->module);
  685. $this->assign('Type',$this->Type);
  686. $this->assign($this->Config);
  687. $this->assign('Categorys',$this->categorys);
  688. //$r=$this->buildHtml('index','./','Home/Index_index');
  689. if(empty($sitemap)){
  690. $this->assign('ishome','home');
  691. if(!$this->sysConfig['HOME_ISHTML']) $this->error(L('NO_HOME_ISHTML'));
  692. $this->assign('bcid',0);
  693. $r=$this->buildHtml('index','./'.$lang,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Index_index'.C('TMPL_TEMPLATE_SUFFIX'));
  694. }else{
  695. $this->assign('sitemap','1');
  696. $r=$this->buildHtml('sitemap','./'.$lang,'./Ainaphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Sitemap'.C('TMPL_TEMPLATE_SUFFIX'));
  697. }
  698. if($r) return true;
  699. }
  700. function clisthtml($id){
  701. $pagesize= 10;
  702. $p = max(intval($p), 1);
  703. $j = 1;
  704. do {
  705. $this->create_list($id,$p);
  706. $j++;
  707. $p++;
  708. $pages = isset($pages) ? $pages : PAGESTOTAL;
  709. } while ($j <= $pages && $j < $pagesize);
  710. }
  711. }
  712. ?>