CreatehtmlAction.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. /**
  3. *
  4. * Createhtml(生成静态页)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class CreatehtmlAction extends AdminbaseAction {
  9. protected $module;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. foreach ((array)$this->module as $rw){
  14. if($rw['type']==1 && $rw['status']==1) $data['module'][$rw['id']] = $rw;
  15. }
  16. $this->module=$data['module'];
  17. $this->assign('module',$this->module);
  18. $this->assign('menuid',intval($_GET['menuid']));
  19. }
  20. public function index()
  21. {
  22. $this->display('Createhtml:index');
  23. }
  24. public function docreateindex()
  25. {
  26. $this->create_index();
  27. $this->assign ( 'jumpUrl', U(MODULE_NAME.'/index') );
  28. $this->success(L('index_create_OK'));
  29. }
  30. public function createlist()
  31. {
  32. $moduleid = intval($_GET['moduleid']);
  33. if($this->categorys){
  34. foreach ($this->categorys as $r){
  35. if($r['type']==1 && $r['ishtml']==0) continue;
  36. if($moduleid && $r['moduleid'] != $moduleid) continue;
  37. if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
  38. if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
  39. if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
  40. $array[] = $r;
  41. }
  42. import ( '@.ORG.Tree' );
  43. $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
  44. $tree = new Tree ($array);
  45. $tree->icon = array('&nbsp;&nbsp;&nbsp;'.L('tree_1'),'&nbsp;&nbsp;&nbsp;'.L('tree_2'),'&nbsp;&nbsp;&nbsp;'.L('tree_3'));
  46. $select_categorys = $tree->get_tree(0, $str);
  47. $this->assign('select_categorys', $select_categorys);
  48. }
  49. $this->display('Createhtml:show');
  50. }
  51. public function doCreatelist()
  52. {
  53. $this->assign ( 'waitSecond', 0);
  54. extract($_GET,EXTR_SKIP);
  55. $moduleid = intval($_GET['moduleid']);
  56. $doid = $doid ? intval($doid) : 0;
  57. $count = intval($_GET['count']);
  58. if($dosubmit!=1){
  59. $catids=array();
  60. if($_GET['catids'][0]){
  61. $catids = $_SESSION['catids'] = $_GET['catids'];
  62. }else{
  63. foreach($this->categorys as $id=>$cat) {
  64. if($cat['type']!=0 || $cat['ishtml']!=1) continue;
  65. if($moduleid){
  66. if($cat['moduleid']!=$moduleid) continue;
  67. }
  68. $catids[] = $id;
  69. }
  70. $catids = $_SESSION['catids'] = $catids;
  71. }
  72. }else{
  73. $catids =$_SESSION['catids'];
  74. }
  75. if(!isset($catids[$doid])){
  76. unset($_SESSION['catids']);
  77. $forward = U("Createhtml/createlist");
  78. $this->assign ( 'jumpUrl', $forward);
  79. $this->success(L('create_update_success'));
  80. }else{
  81. $id = $catids[$doid];
  82. if(empty($count)){
  83. $module = $this->categorys[$id]['module'];
  84. $dao= M($module);
  85. $where['status']=1;
  86. if(empty($this->categorys[$id]['listtype'])){
  87. if($this->categorys[$id]['child']){
  88. $where['catid']=array('in',$this->categorys[$id]['arrchildid']);
  89. }else{
  90. $where['catid']=$id;
  91. }
  92. $count = $dao->where($where)->count();
  93. }else{
  94. $count=1;
  95. }
  96. }
  97. if(empty($pages)){
  98. $cat_pagesize = !empty($this->categorys[$id]['pagesize']) ? $this->categorys[$id]['pagesize'] : C('PAGE_LISTROWS');
  99. $pages = ceil($count/$cat_pagesize);
  100. }
  101. $p = max(intval($p), 1);
  102. $j = 1;
  103. do {
  104. $this->create_list($id,$p,$count);
  105. $j++;
  106. $p++;
  107. $pages = isset($pages) ? $pages : PAGESTOTAL;
  108. } while ($p <= $pages && $j < $pagesize);
  109. if($p <= $pages) {
  110. $endpage = intval($p+$pagesize);
  111. $percent = round($p/$pages, 2)*100;
  112. $urlarray=array(
  113. 'count' => $count,
  114. 'doid' => $doid,
  115. 'dosubmit' => 1,
  116. 'pages' => $pages,
  117. 'p' => $p,
  118. 'pagesize' => $pagesize,
  119. 'iscreatehtml'=>1,
  120. );
  121. $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$pages.L('create_update_list_num').$p.L('items_list').$percent.L('items1');
  122. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  123. } else {
  124. $doid++;
  125. $urlarray=array(
  126. 'doid' => $doid,
  127. 'dosubmit' => 1,
  128. 'p' => 1,
  129. 'pagesize' => $pagesize,
  130. 'iscreatehtml'=>1,
  131. );
  132. $message = L('start_updating').$this->categorys[$id]['catname']." ...";
  133. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  134. }
  135. $this->assign ( 'jumpUrl', $forward);
  136. $this->success($message);
  137. }
  138. }
  139. public function doUpdateurl()
  140. {
  141. $this->assign ( 'waitSecond', 0);
  142. $moduleid = intval($_GET['moduleid']);
  143. extract($_GET,EXTR_SKIP);
  144. if($moduleid<=0 && $catids[0] <= 0){
  145. if($this->module && !$_SESSION['moduleids']){
  146. foreach($this->module as $moduleid=>$r){
  147. $tablename=C('DB_PREFIX').$this->module[$moduleid]['name'];
  148. $db=D('');
  149. $db = DB::getInstance();
  150. $tables = $db->getTables();
  151. $Fields=$db->getFields($tablename);
  152. foreach ( $Fields as $key =>$r){
  153. if($key=='url') $_SESSION['moduleids'][] = $moduleid;
  154. }
  155. }
  156. }
  157. $doid = $doid ? intval($doid) : 0;
  158. if(!isset($_SESSION['moduleids'][$doid])){
  159. unset($_SESSION['moduleids']);
  160. $forward = U("Createhtml/updateurl");
  161. $this->assign ( 'jumpUrl', $forward);
  162. $this->success(L('create_update_success'));
  163. }else{
  164. $moduleid = $_SESSION['moduleids'][$doid];
  165. $module=$this->module[$moduleid]['name'];
  166. $dao = M($module);
  167. $p = max(intval($p), 1);
  168. $start = $pagesize*($p-1);
  169. if(!isset($count)){
  170. $count = $dao->where($where)->count();
  171. }
  172. $pages = ceil($count/$pagesize);
  173. if($count){
  174. $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
  175. foreach($list as $r) {
  176. if($r['islink']) continue;
  177. $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
  178. unset($r['catid']);
  179. $r['url'] = $url['0'];
  180. $dao->save($r);
  181. }
  182. }
  183. if($pages > $p) {
  184. $p++;
  185. $creatednum = $start + count($list);
  186. $percent = round($creatednum/$count, 2)*100;
  187. $urlarray=array(
  188. 'doid' => $doid,
  189. 'dosubmit' => 1,
  190. 'count' => $count,
  191. 'pages' => $pages,
  192. 'p' => $p,
  193. 'pagesize' => $pagesize,
  194. );
  195. $message = L('updating').$this->module[$moduleid]['title'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
  196. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  197. $this->assign ( 'jumpUrl', $forward);
  198. $this->success($message);
  199. } else {
  200. $doid++;
  201. $urlarray=array(
  202. 'doid' => $doid,
  203. 'dosubmit' => 1,
  204. 'p' => 1,
  205. 'pagesize' => $pagesize,
  206. );
  207. $message = L('start_updating').$this->module[$moduleid]['title']." ...";
  208. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  209. $this->assign ( 'jumpUrl', $forward);
  210. $this->success($message);
  211. }
  212. }
  213. }elseif($moduleid){
  214. $module=$this->module[$moduleid]['name'];
  215. $dao = M($module);
  216. $p = max(intval($p), 1);
  217. $start = $pagesize*($p-1);
  218. if(is_array($catids) && $catids[0] > 0){
  219. $cids = implode(',',$catids);
  220. $where = " catid IN($cids) ";
  221. $_SESSION['catids'] = $catids;
  222. }
  223. if(!$catids && $_SESSION['catids'] && $_SESSION['catids'][0] > 0){
  224. $catids = implode(',',$_SESSION['catids']);;
  225. $where = " catid IN($catids) ";
  226. }
  227. if(!isset($count)){
  228. $count = $dao->where($where)->count();
  229. }
  230. $pages = ceil($count/$pagesize);
  231. if($count){
  232. $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
  233. foreach($list as $r) {
  234. if($r['islink']) continue;
  235. $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
  236. unset($r['catid']);
  237. $r['url'] = $url['0'];
  238. $dao->save($r);
  239. }
  240. }
  241. if($pages > $p) {
  242. $p++;
  243. $creatednum = $start + count($list);
  244. $percent = round($creatednum/$count, 2)*100;
  245. $urlarray=array(
  246. 'moduleid' => $moduleid,
  247. 'dosubmit' => 1,
  248. 'count' => $count,
  249. 'pages' => $pages,
  250. 'p' => $p,
  251. 'pagesize' => $pagesize,
  252. );
  253. $message = L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
  254. $forward = U("Createhtml/updateurl",$urlarray);
  255. $this->assign ( 'jumpUrl', $forward);
  256. $this->success($message);
  257. } else {
  258. unset($_SESSION['catids']);
  259. $forward = U("Createhtml/updateurl");
  260. $this->assign ( 'jumpUrl', $forward);
  261. $this->success(L('create_update_success'));
  262. }
  263. }else{
  264. //按照栏目更新url
  265. extract($_GET,EXTR_SKIP);
  266. $doid = $doid ? intval($doid) : 0;
  267. if(empty($_SESSION['catids']) && $catids){
  268. if($catids[0] == 0) {
  269. foreach($this->categorys as $id=>$cat) {
  270. if($cat['child'] || $cat['type']!=0 || $cat['module']=='Page') continue;
  271. $catids[] = $id;
  272. }
  273. }
  274. $_SESSION['catids'] = $catids;
  275. }else{
  276. $catids =$_SESSION['catids'];
  277. }
  278. if(!isset($catids[$doid])){
  279. unset($_SESSION['catids']);
  280. $forward = U("Createhtml/updateurl");
  281. $this->assign ( 'jumpUrl', $forward);
  282. $this->success(L('create_update_success'));
  283. }elseif($catids[$doid]<=0){
  284. $forward = U("Createhtml/updateurl");
  285. $this->assign ( 'jumpUrl', $forward);
  286. $this->success(L('create_update_success'));
  287. }else{
  288. $id = $catids[$doid];
  289. $module=$this->categorys[$id]['module'];
  290. $dao = M($module);
  291. $where = "catid=$id";
  292. $p = max(intval($p), 1);
  293. $start = $pagesize*($p-1);
  294. if(!isset($count)){
  295. $count = $dao->where($where)->count();
  296. }
  297. $pages = ceil($count/$pagesize);
  298. if($count){
  299. $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
  300. foreach($list as $r) {
  301. if($r['islink']) continue;
  302. $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
  303. unset($r['catid']);
  304. $r['url'] = $url['0'];
  305. $dao->save($r);
  306. }
  307. }
  308. if($pages > $p) {
  309. $p++;
  310. $creatednum = $start + count($list);
  311. $percent = round($creatednum/$count, 2)*100;
  312. $urlarray=array(
  313. 'doid' => $doid,
  314. 'dosubmit' => 1,
  315. 'count' => $count,
  316. 'pages' => $pages,
  317. 'p' => $p,
  318. 'pagesize' => $pagesize,
  319. );
  320. $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
  321. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  322. $this->assign ( 'jumpUrl', $forward);
  323. $this->success($message);
  324. } else {
  325. $doid++;
  326. $urlarray=array(
  327. 'doid' => $doid,
  328. 'dosubmit' => 1,
  329. 'p' => 1,
  330. 'pagesize' => $pagesize,
  331. );
  332. $message = L('start_updating').$this->categorys[$id]['catname']." ...";
  333. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  334. $this->assign ( 'jumpUrl', $forward);
  335. $this->success($message);
  336. }
  337. }
  338. }
  339. }
  340. public function updateurl()
  341. {
  342. $moduleid = intval($_GET['moduleid']);
  343. $this->assign('moduleid',$moduleid);
  344. if($this->categorys){
  345. foreach ($this->categorys as $r){
  346. if($r['type']==1 && $r['ishtml']==0) continue;
  347. if($_GET['moduleid'] && $r['moduleid'] != $_GET['moduleid']) continue;
  348. if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
  349. if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
  350. if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
  351. if($r['child'] && ACTION_NAME!='Createlist'){
  352. $r['disabled'] = 'disabled';
  353. }else{
  354. $r['disabled'] = '';
  355. }
  356. $array[] = $r;
  357. }
  358. import ( '@.ORG.Tree' );
  359. $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
  360. $tree = new Tree ($array);
  361. $tree->icon = array('&nbsp;&nbsp;&nbsp;'.L('tree_1'),'&nbsp;&nbsp;&nbsp;'.L('tree_2'),'&nbsp;&nbsp;&nbsp;'.L('tree_3'));
  362. $select_categorys = $tree->get_tree(0, $str);
  363. $this->assign('select_categorys', $select_categorys);
  364. }
  365. $this->display('Createhtml:show');
  366. }
  367. public function createshow()
  368. {
  369. $moduleid = intval($_GET['moduleid']);
  370. if($this->categorys){
  371. foreach ($this->categorys as $r){
  372. if($r['type']==1 && $r['ishtml']==0) continue;
  373. if($moduleid && $r['moduleid'] != $moduleid) continue;
  374. if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
  375. if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
  376. if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
  377. if($r['child'] && ACTION_NAME!='Createlist'){
  378. $r['disabled'] = 'disabled';
  379. }else{
  380. $r['disabled'] = '';
  381. }
  382. $array[] = $r;
  383. }
  384. import ( '@.ORG.Tree' );
  385. $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
  386. $tree = new Tree ($array);
  387. $tree->icon = array('&nbsp;&nbsp;&nbsp;'.L('tree_1'),'&nbsp;&nbsp;&nbsp;'.L('tree_2'),'&nbsp;&nbsp;&nbsp;'.L('tree_3'));
  388. $select_categorys = $tree->get_tree(0, $str);
  389. $this->assign('select_categorys', $select_categorys);
  390. }
  391. $this->display('Createhtml:show');
  392. }
  393. public function doCreateshow()
  394. {
  395. $this->assign ( 'waitSecond', 0);
  396. extract($_GET,EXTR_SKIP);
  397. $moduleid = intval($_GET['moduleid']);
  398. $doid = $doid ? intval($doid) : 0;
  399. if($dosubmit!=1){
  400. if($catids[0] == 0) {
  401. $catids=array();
  402. foreach($this->categorys as $id=>$cat) {
  403. if($cat['child'] || $cat['type']!=0 || $cat['module']=='Page' || $cat['ishtml']!=1) continue;
  404. if($moduleid){
  405. if($cat['moduleid']!=$moduleid) continue;
  406. }
  407. $catids[] = $id;
  408. }
  409. }
  410. $_SESSION['catids'] = $catids;
  411. }else{
  412. $catids =$_SESSION['catids'];
  413. }
  414. if(!isset($catids[$doid])){
  415. unset($_SESSION['catids']);
  416. $forward = U("Createhtml/Createshow");
  417. $this->assign ( 'jumpUrl', $forward);
  418. $this->success(L('create_update_success'));
  419. }else{
  420. $id = $catids[$doid];
  421. $module=$this->categorys[$id]['module'];
  422. $dao = M($module);
  423. $where = "catid=$id";
  424. $p = max(intval($p), 1);
  425. $start = $pagesize*($p-1);
  426. if(!isset($count)){
  427. $count = $dao->where($where)->count();
  428. }
  429. $pages = ceil($count/$pagesize);
  430. if($count){
  431. $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
  432. foreach($list as $r) {
  433. if($r['islink']) continue;
  434. $module = $this->categorys[$r['catid']]['module'];
  435. $this->create_show($r['id'],$module);
  436. }
  437. }
  438. if($pages > $p) {
  439. $p++;
  440. $creatednum = $start + count($list);
  441. $percent = round($creatednum/$count, 2)*100;
  442. $urlarray=array(
  443. 'doid' => $doid,
  444. 'dosubmit' => 1,
  445. 'count' => $count,
  446. 'pages' => $pages,
  447. 'p' => $p,
  448. 'pagesize' => $pagesize,
  449. 'iscreatehtml'=>1,
  450. );
  451. $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
  452. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  453. $this->assign ( 'jumpUrl', $forward);
  454. $this->success($message);
  455. } else {
  456. $doid++;
  457. $urlarray=array(
  458. 'doid' => $doid,
  459. 'dosubmit' => 1,
  460. 'p' => 1,
  461. 'pagesize' => $pagesize,
  462. 'iscreatehtml'=>1,
  463. );
  464. $message = L('start_updating').$this->categorys[$id]['catname']." ...";
  465. $forward = U("Createhtml/".ACTION_NAME,$urlarray);
  466. $this->assign ( 'jumpUrl', $forward);
  467. $this->success($message);
  468. }
  469. }
  470. }
  471. public function createsitemap()
  472. {
  473. foreach((array)$this->module as $r){
  474. if($r['issearch'])$search_module[$r['name']] = $r;
  475. }
  476. $this->assign('module',$search_module);
  477. $xmlmap=file_exists('./sitemap.xml');
  478. $htmlmap=file_exists('./sitemap.html');
  479. $this->assign('siteurl',$this->Config['site_url']);
  480. $this->assign('xmlmap',$xmlmap);
  481. $this->assign('htmlmap',$htmlmap);
  482. $this->assign('yesorno',array(0 => L('no'),1 => L('yes')));
  483. $this->display('Createhtml:sitemap');
  484. }
  485. public function docreatesitemap()
  486. {
  487. if($_GET['htmlmap']){
  488. $r = $this->create_index(1);
  489. }
  490. if($_GET['xmlmap']){
  491. import("@.ORG.Cxml");
  492. $array=array();
  493. $array[0]['NodeName']['value'] ='url';
  494. $array[0]['loc']['value']=$this->Config['site_url'];
  495. $array[0]['lastmod']['value']= date('Y-m-d',time());
  496. $array[0]['changefreq']['value'] ='weekly';
  497. $array[0]['priority']['value'] =1;
  498. foreach((array)$this->module as $r){
  499. if($r['issearch']){
  500. $num = intval($_GET[$r['name']]);
  501. if(!$num) continue;
  502. $data = M($r['name'])->field('id,title,url,createtime')->where("status=1")->order('id desc')->limit('0,'.$num)->select();
  503. foreach($data as $key=> $res){
  504. $arraya[$key]['NodeName']['value'] ='url';
  505. $arraya[$key]['loc']['value'] = $this->Config['site_url'].$res['url'];
  506. $arraya[$key]['lastmod']['value'] = date('Y-m-d',$res['createtime']);
  507. $arraya[$key]['changefreq']['value'] ='weekly';
  508. $arraya[$key]['priority']['value'] =0.7;
  509. }
  510. $array =array_merge($array,$arraya);
  511. }
  512. }
  513. $Cxml = new Cxml();
  514. $Cxml->root='urlset';
  515. $Cxml->root_attributes=array('xmlns'=>'http://www.sitemaps.org/schemas/sitemap/0.9');
  516. $xmldata = $Cxml->Cxml($array,'./sitemap.xml');
  517. $d=file_exists('./sitemap.xml');;
  518. }
  519. if(($_GET['htmlmap'] && $r) || ($_GET['xmlmap']&& $d)){$this->success(L('DO_OK'));}else{$this->error(L('Create error.'));}
  520. }
  521. }
  522. ?>