123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
-
- namespace app\home\controller;
-
- use core\basic\Controller;
- use app\home\model\SitemapModel;
- use core\basic\Url;
-
- class SitemapController extends Controller{
-
- protected $model;
-
- public function __construct(){
- $this->model = new SitemapModel();
- cookie('city','');
- }
-
- public function index()
- {
- header("Content-type:text/xml;charset=utf-8");
- $str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
-
- $str .= '<urlset xmlns= "http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" ;
- $str .= $this->makeNode('', date('Y-m-d'), '1.00', 'always');
-
- $sorts = $this->model->getSorts();
- $Parser = new ParserController();
-
- $wildcard = $this->config('wildcard');
- $city_suffix = $this->config('city_suffix');
- $city_suffix = $city_suffix ? '.html' : '/';
- $model = model('admin.system.City');
- $city = $model->getAllList();
- $domain = get_http_host();
- $cur_city = array_filter($city, function($t) use ($domain) { return $t['isurl'] == $domain; });
- if( $wildcard || !empty($cur_city) ){
- foreach ($sorts as $value) {
- if ($value->outlink) {
- continue;
- } elseif ($value->type == 1) {
- $link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
- $str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
- } else {
- $link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
- $str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
- $contents = $this->model->getSortContent($value->scode);
- foreach ($contents as $value2) {
- if ($value2->outlink) {
- continue;
- } else {
- $link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
- }
- $str .= $this->makeNode($link, date('Y-m-d', strtotime($value2->date)), '0.60', 'daily');
- }
- }
- }
- }else{
- cookie('city','');
- foreach ($city as $c) {
- $str .= $this->makeNode( '/'.$c['etitle'] . $city_suffix, date('Y-m-d'), '1.00', 'always');
- }
- if( $this->config('open_citymap') ){
- array_unshift($city,['etitle'=>'','isurl'=>'']);
- }else{
- $city = ['etitle'=>'','isurl'=>''];
- }
- foreach( $city as $item ){
- if( $item['isurl'] !=='' ){
- continue;
- }
- $url = $item['etitle'] ? '/'.$item['etitle'] : '';
-
-
-
-
- foreach ($sorts as $value) {
- if ($value->outlink) {
- continue;
- } elseif ($value->type == 1) {
- $link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
- $str .= $this->makeNode( $url . $link, date('Y-m-d'), '0.80', 'daily');
- } else {
- $link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
- $str .= $this->makeNode( $url . $link, date('Y-m-d'), '0.80', 'daily');
- $contents = $this->model->getSortContent($value->scode);
- foreach ($contents as $value2) {
- if ($value2->outlink) {
- continue;
- } else {
- $link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
- }
- $str .= $this->makeNode( $url . $link, date('Y-m-d', strtotime($value2->date)), '0.60', 'daily');
- }
- }
- }
- }
- }
- echo $str . "\n</urlset>";
- }
-
-
- private function makeNode($link, $date, $priority = 0.60, $changefreq = 'always')
- {
- $node = '
- <url>
- <loc>' . get_http_url() . $link . '</loc>
- <priority>' . $priority . '</priority>
- <lastmod>' . $date . '</lastmod>
- <changefreq>' . $changefreq . '</changefreq>
- </url>';
- return $node;
- }
-
-
- public function linkTxt()
- {
- header("Content-type:text/plain;charset=utf-8");
- $sorts = $this->model->getSorts();
- $Parser = new ParserController();
- $str = get_http_url() . "\n";
-
- $wildcard = $this->config('wildcard');
- $city_suffix = $this->config('city_suffix');
- $city_suffix = $city_suffix ? '.html' : '/';
- $model = model('admin.system.City');
- $city = $model->getAllList();
- $domain = get_http_host();
- $cur_city = array_filter($city, function($t) use ($domain) { return $t['isurl'] == $domain; });
- if( $wildcard || !empty($cur_city) ){
- foreach ($sorts as $value) {
- if ($value->outlink) {
- continue;
- } elseif ($value->type == 1) {
- $link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
- $str .= get_http_url() . $link . "\n";
- } else {
- $link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
- $str .= get_http_url() . $link . "\n";
- $contents = $this->model->getSortContent($value->scode);
- foreach ($contents as $value2) {
- if ($value2->outlink) {
- continue;
- } else {
- $link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
- }
- $str .= get_http_url() . $link . "\n";
- }
- }
- }
- }else{
- cookie('city','');
- foreach ($city as $c) {
- $str .= get_http_url() .'/'. $c['etitle'] . $city_suffix . "\n";
- }
- if( $this->config('open_citymap') ){
- array_unshift($city,['etitle'=>'','isurl'=>'']);
- }else{
- $city = ['etitle'=>'','isurl'=>''];
- }
- foreach( $city as $item ){
- if( $item['isurl'] !=='' ){
- continue;
- }
- $url = $item['etitle'] ? '/'.$item['etitle'] : '';
-
- foreach ($sorts as $value) {
- if ($value->outlink) {
- continue;
- } elseif ($value->type == 1) {
- $link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
- $str .= get_http_url() . $url . $link . "\n";
- } else {
- $link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
- $str .= get_http_url() . $url . $link . "\n";
- $contents = $this->model->getSortContent($value->scode);
- foreach ($contents as $value2) {
- if ($value2->outlink) {
- continue;
- } else {
- $link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
- }
- $str .= get_http_url() . $url . $link . "\n";
- }
- }
- }
- }
- }
- echo $str;
- }
- }
|