123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- <?php
- /**
- *
- * Createhtml(生成静态页)
- *
- */
- if(!defined("Ainaphp")) exit("Access Denied");
- class CreatehtmlAction extends AdminbaseAction {
- protected $module;
- public function _initialize()
- {
- parent::_initialize();
- foreach ((array)$this->module as $rw){
- if($rw['type']==1 && $rw['status']==1) $data['module'][$rw['id']] = $rw;
- }
- $this->module=$data['module'];
- $this->assign('module',$this->module);
- $this->assign('menuid',intval($_GET['menuid']));
- }
- public function index()
- {
- $this->display('Createhtml:index');
- }
- public function docreateindex()
- {
- $this->create_index();
- $this->assign ( 'jumpUrl', U(MODULE_NAME.'/index') );
- $this->success(L('index_create_OK'));
- }
- public function createlist()
- {
- $moduleid = intval($_GET['moduleid']);
- if($this->categorys){
- foreach ($this->categorys as $r){
- if($r['type']==1 && $r['ishtml']==0) continue;
- if($moduleid && $r['moduleid'] != $moduleid) continue;
- if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
- if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
- if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
- $array[] = $r;
- }
- import ( '@.ORG.Tree' );
- $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
- $tree = new Tree ($array);
- $tree->icon = array(' '.L('tree_1'),' '.L('tree_2'),' '.L('tree_3'));
- $select_categorys = $tree->get_tree(0, $str);
- $this->assign('select_categorys', $select_categorys);
- }
- $this->display('Createhtml:show');
- }
- public function doCreatelist()
- {
- $this->assign ( 'waitSecond', 0);
- extract($_GET,EXTR_SKIP);
- $moduleid = intval($_GET['moduleid']);
- $doid = $doid ? intval($doid) : 0;
- $count = intval($_GET['count']);
- if($dosubmit!=1){
- $catids=array();
- if($_GET['catids'][0]){
- $catids = $_SESSION['catids'] = $_GET['catids'];
- }else{
- foreach($this->categorys as $id=>$cat) {
- if($cat['type']!=0 || $cat['ishtml']!=1) continue;
- if($moduleid){
- if($cat['moduleid']!=$moduleid) continue;
- }
- $catids[] = $id;
- }
- $catids = $_SESSION['catids'] = $catids;
- }
- }else{
- $catids =$_SESSION['catids'];
- }
- if(!isset($catids[$doid])){
- unset($_SESSION['catids']);
- $forward = U("Createhtml/createlist");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }else{
- $id = $catids[$doid];
- if(empty($count)){
- $module = $this->categorys[$id]['module'];
- $dao= M($module);
- $where['status']=1;
- if(empty($this->categorys[$id]['listtype'])){
- if($this->categorys[$id]['child']){
- $where['catid']=array('in',$this->categorys[$id]['arrchildid']);
- }else{
- $where['catid']=$id;
- }
- $count = $dao->where($where)->count();
- }else{
- $count=1;
- }
- }
- if(empty($pages)){
- $cat_pagesize = !empty($this->categorys[$id]['pagesize']) ? $this->categorys[$id]['pagesize'] : C('PAGE_LISTROWS');
- $pages = ceil($count/$cat_pagesize);
- }
- $p = max(intval($p), 1);
- $j = 1;
- do {
- $this->create_list($id,$p,$count);
- $j++;
- $p++;
- $pages = isset($pages) ? $pages : PAGESTOTAL;
- } while ($p <= $pages && $j < $pagesize);
- if($p <= $pages) {
- $endpage = intval($p+$pagesize);
- $percent = round($p/$pages, 2)*100;
- $urlarray=array(
- 'count' => $count,
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'pages' => $pages,
- 'p' => $p,
- 'pagesize' => $pagesize,
- 'iscreatehtml'=>1,
- );
- $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$pages.L('create_update_list_num').$p.L('items_list').$percent.L('items1');
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- } else {
- $doid++;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'p' => 1,
- 'pagesize' => $pagesize,
- 'iscreatehtml'=>1,
- );
- $message = L('start_updating').$this->categorys[$id]['catname']." ...";
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- }
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- }
- }
- public function doUpdateurl()
- {
- $this->assign ( 'waitSecond', 0);
- $moduleid = intval($_GET['moduleid']);
- extract($_GET,EXTR_SKIP);
- if($moduleid<=0 && $catids[0] <= 0){
- if($this->module && !$_SESSION['moduleids']){
- foreach($this->module as $moduleid=>$r){
- $tablename=C('DB_PREFIX').$this->module[$moduleid]['name'];
- $db=D('');
- $db = DB::getInstance();
- $tables = $db->getTables();
- $Fields=$db->getFields($tablename);
- foreach ( $Fields as $key =>$r){
- if($key=='url') $_SESSION['moduleids'][] = $moduleid;
- }
- }
- }
- $doid = $doid ? intval($doid) : 0;
- if(!isset($_SESSION['moduleids'][$doid])){
- unset($_SESSION['moduleids']);
- $forward = U("Createhtml/updateurl");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }else{
- $moduleid = $_SESSION['moduleids'][$doid];
- $module=$this->module[$moduleid]['name'];
- $dao = M($module);
- $p = max(intval($p), 1);
- $start = $pagesize*($p-1);
- if(!isset($count)){
- $count = $dao->where($where)->count();
- }
- $pages = ceil($count/$pagesize);
- if($count){
- $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
- foreach($list as $r) {
- if($r['islink']) continue;
- $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
- unset($r['catid']);
- $r['url'] = $url['0'];
- $dao->save($r);
- }
- }
- if($pages > $p) {
- $p++;
- $creatednum = $start + count($list);
- $percent = round($creatednum/$count, 2)*100;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'count' => $count,
- 'pages' => $pages,
- 'p' => $p,
- 'pagesize' => $pagesize,
- );
- $message = L('updating').$this->module[$moduleid]['title'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- } else {
- $doid++;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'p' => 1,
- 'pagesize' => $pagesize,
- );
- $message = L('start_updating').$this->module[$moduleid]['title']." ...";
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- }
- }
- }elseif($moduleid){
- $module=$this->module[$moduleid]['name'];
- $dao = M($module);
- $p = max(intval($p), 1);
- $start = $pagesize*($p-1);
- if(is_array($catids) && $catids[0] > 0){
- $cids = implode(',',$catids);
- $where = " catid IN($cids) ";
- $_SESSION['catids'] = $catids;
- }
- if(!$catids && $_SESSION['catids'] && $_SESSION['catids'][0] > 0){
- $catids = implode(',',$_SESSION['catids']);;
- $where = " catid IN($catids) ";
- }
- if(!isset($count)){
- $count = $dao->where($where)->count();
- }
- $pages = ceil($count/$pagesize);
- if($count){
- $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
- foreach($list as $r) {
- if($r['islink']) continue;
- $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
- unset($r['catid']);
- $r['url'] = $url['0'];
- $dao->save($r);
- }
- }
- if($pages > $p) {
- $p++;
- $creatednum = $start + count($list);
- $percent = round($creatednum/$count, 2)*100;
- $urlarray=array(
- 'moduleid' => $moduleid,
- 'dosubmit' => 1,
- 'count' => $count,
- 'pages' => $pages,
- 'p' => $p,
- 'pagesize' => $pagesize,
- );
- $message = L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
- $forward = U("Createhtml/updateurl",$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- } else {
- unset($_SESSION['catids']);
- $forward = U("Createhtml/updateurl");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }
- }else{
- //按照栏目更新url
- extract($_GET,EXTR_SKIP);
- $doid = $doid ? intval($doid) : 0;
- if(empty($_SESSION['catids']) && $catids){
- if($catids[0] == 0) {
- foreach($this->categorys as $id=>$cat) {
- if($cat['child'] || $cat['type']!=0 || $cat['module']=='Page') continue;
- $catids[] = $id;
- }
- }
- $_SESSION['catids'] = $catids;
- }else{
- $catids =$_SESSION['catids'];
- }
- if(!isset($catids[$doid])){
- unset($_SESSION['catids']);
- $forward = U("Createhtml/updateurl");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }elseif($catids[$doid]<=0){
- $forward = U("Createhtml/updateurl");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }else{
- $id = $catids[$doid];
- $module=$this->categorys[$id]['module'];
- $dao = M($module);
- $where = "catid=$id";
- $p = max(intval($p), 1);
- $start = $pagesize*($p-1);
- if(!isset($count)){
- $count = $dao->where($where)->count();
- }
- $pages = ceil($count/$pagesize);
- if($count){
- $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
- foreach($list as $r) {
- if($r['islink']) continue;
- $url = geturl($this->categorys[$r['catid']],$r,$this->Urlrule);
- unset($r['catid']);
- $r['url'] = $url['0'];
- $dao->save($r);
- }
- }
- if($pages > $p) {
- $p++;
- $creatednum = $start + count($list);
- $percent = round($creatednum/$count, 2)*100;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'count' => $count,
- 'pages' => $pages,
- 'p' => $p,
- 'pagesize' => $pagesize,
- );
- $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- } else {
- $doid++;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'p' => 1,
- 'pagesize' => $pagesize,
- );
- $message = L('start_updating').$this->categorys[$id]['catname']." ...";
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- }
- }
- }
- }
- public function updateurl()
- {
- $moduleid = intval($_GET['moduleid']);
- $this->assign('moduleid',$moduleid);
- if($this->categorys){
- foreach ($this->categorys as $r){
- if($r['type']==1 && $r['ishtml']==0) continue;
- if($_GET['moduleid'] && $r['moduleid'] != $_GET['moduleid']) continue;
- if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
- if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
- if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
- if($r['child'] && ACTION_NAME!='Createlist'){
- $r['disabled'] = 'disabled';
- }else{
- $r['disabled'] = '';
- }
- $array[] = $r;
- }
- import ( '@.ORG.Tree' );
- $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
- $tree = new Tree ($array);
- $tree->icon = array(' '.L('tree_1'),' '.L('tree_2'),' '.L('tree_3'));
- $select_categorys = $tree->get_tree(0, $str);
- $this->assign('select_categorys', $select_categorys);
- }
- $this->display('Createhtml:show');
- }
- public function createshow()
- {
- $moduleid = intval($_GET['moduleid']);
- if($this->categorys){
- foreach ($this->categorys as $r){
- if($r['type']==1 && $r['ishtml']==0) continue;
- if($moduleid && $r['moduleid'] != $moduleid) continue;
- if(ACTION_NAME=='Updateurl' && $r['module']=='Page') continue;
- if(ACTION_NAME=='Createlist' && $r['ishtml']!=1) continue;
- if((ACTION_NAME=='Createshow' && $r['ishtml']!=1) || (ACTION_NAME=='Createshow' && $r['module']=='Page')) continue;
- if($r['child'] && ACTION_NAME!='Createlist'){
- $r['disabled'] = 'disabled';
- }else{
- $r['disabled'] = '';
- }
- $array[] = $r;
- }
- import ( '@.ORG.Tree' );
- $str = "<option value='\$id' \$disabled>\$spacer \$catname</option>";
- $tree = new Tree ($array);
- $tree->icon = array(' '.L('tree_1'),' '.L('tree_2'),' '.L('tree_3'));
- $select_categorys = $tree->get_tree(0, $str);
- $this->assign('select_categorys', $select_categorys);
- }
- $this->display('Createhtml:show');
- }
- public function doCreateshow()
- {
- $this->assign ( 'waitSecond', 0);
- extract($_GET,EXTR_SKIP);
- $moduleid = intval($_GET['moduleid']);
- $doid = $doid ? intval($doid) : 0;
- if($dosubmit!=1){
- if($catids[0] == 0) {
- $catids=array();
- foreach($this->categorys as $id=>$cat) {
- if($cat['child'] || $cat['type']!=0 || $cat['module']=='Page' || $cat['ishtml']!=1) continue;
- if($moduleid){
- if($cat['moduleid']!=$moduleid) continue;
- }
- $catids[] = $id;
- }
- }
- $_SESSION['catids'] = $catids;
- }else{
- $catids =$_SESSION['catids'];
- }
- if(!isset($catids[$doid])){
- unset($_SESSION['catids']);
- $forward = U("Createhtml/Createshow");
- $this->assign ( 'jumpUrl', $forward);
- $this->success(L('create_update_success'));
- }else{
- $id = $catids[$doid];
- $module=$this->categorys[$id]['module'];
- $dao = M($module);
- $where = "catid=$id";
- $p = max(intval($p), 1);
- $start = $pagesize*($p-1);
- if(!isset($count)){
- $count = $dao->where($where)->count();
- }
- $pages = ceil($count/$pagesize);
- if($count){
- $list = $dao->field('id,catid,url')->where($where)->limit($start . ',' . $pagesize)->select();
- foreach($list as $r) {
- if($r['islink']) continue;
- $module = $this->categorys[$r['catid']]['module'];
- $this->create_show($r['id'],$module);
- }
- }
- if($pages > $p) {
- $p++;
- $creatednum = $start + count($list);
- $percent = round($creatednum/$count, 2)*100;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'count' => $count,
- 'pages' => $pages,
- 'p' => $p,
- 'pagesize' => $pagesize,
- 'iscreatehtml'=>1,
- );
- $message = L('updating').$this->categorys[$id]['catname'].L('create_update_count').$count.L('create_update_num').$creatednum.L('items').$percent.L('items1');
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- } else {
- $doid++;
- $urlarray=array(
- 'doid' => $doid,
- 'dosubmit' => 1,
- 'p' => 1,
- 'pagesize' => $pagesize,
- 'iscreatehtml'=>1,
- );
- $message = L('start_updating').$this->categorys[$id]['catname']." ...";
- $forward = U("Createhtml/".ACTION_NAME,$urlarray);
- $this->assign ( 'jumpUrl', $forward);
- $this->success($message);
- }
- }
- }
- public function createsitemap()
- {
- foreach((array)$this->module as $r){
- if($r['issearch'])$search_module[$r['name']] = $r;
- }
- $this->assign('module',$search_module);
- $xmlmap=file_exists('./sitemap.xml');
- $htmlmap=file_exists('./sitemap.html');
- $this->assign('siteurl',$this->Config['site_url']);
- $this->assign('xmlmap',$xmlmap);
- $this->assign('htmlmap',$htmlmap);
- $this->assign('yesorno',array(0 => L('no'),1 => L('yes')));
- $this->display('Createhtml:sitemap');
- }
- public function docreatesitemap()
- {
- if($_GET['htmlmap']){
- $r = $this->create_index(1);
- }
- if($_GET['xmlmap']){
- import("@.ORG.Cxml");
- $array=array();
- $array[0]['NodeName']['value'] ='url';
- $array[0]['loc']['value']=$this->Config['site_url'];
- $array[0]['lastmod']['value']= date('Y-m-d',time());
- $array[0]['changefreq']['value'] ='weekly';
- $array[0]['priority']['value'] =1;
- foreach((array)$this->module as $r){
- if($r['issearch']){
- $num = intval($_GET[$r['name']]);
- if(!$num) continue;
- $data = M($r['name'])->field('id,title,url,createtime')->where("status=1")->order('id desc')->limit('0,'.$num)->select();
- foreach($data as $key=> $res){
- $arraya[$key]['NodeName']['value'] ='url';
- $arraya[$key]['loc']['value'] = $this->Config['site_url'].$res['url'];
- $arraya[$key]['lastmod']['value'] = date('Y-m-d',$res['createtime']);
- $arraya[$key]['changefreq']['value'] ='weekly';
- $arraya[$key]['priority']['value'] =0.7;
- }
- $array =array_merge($array,$arraya);
- }
- }
- $Cxml = new Cxml();
- $Cxml->root='urlset';
- $Cxml->root_attributes=array('xmlns'=>'http://www.sitemaps.org/schemas/sitemap/0.9');
- $xmldata = $Cxml->Cxml($array,'./sitemap.xml');
- $d=file_exists('./sitemap.xml');;
- }
- if(($_GET['htmlmap'] && $r) || ($_GET['xmlmap']&& $d)){$this->success(L('DO_OK'));}else{$this->error(L('Create error.'));}
- }
- }
- ?>
|