Пример #1
0
 public function actionIndex()
 {
     $domain = 'http://' . $_SERVER['SERVER_NAME'];
     $time = explode(" ", microtime());
     $time = $time[1];
     // create object
     $sitemap = new SitemapGenerator($domain . '/', ROOT_PATH);
     // will create also compressed (gzipped) sitemap
     $sitemap->createGZipFile = true;
     $urls = array();
     $urls[] = array($domain, date('c'), 'daily', '1');
     $urls[] = array($this->createAbsoluteUrl('video/index'), date('c'), 'daily', '1');
     //danh muc
     $query = "SELECT id, alias FROM tbl_category";
     $result = $this->db->createCommand($query)->queryAll();
     foreach ($result as $item) {
         $url = $this->createAbsoluteUrl('category/index', array('alias' => $item['alias']));
         if ($item['id'] == 20) {
             $url = $domain . '/reviews.html';
         }
         $urls[] = array($url, date('c'), 'daily', '0.9');
     }
     //topic tag
     $query = "SELECT id, alias FROM tbl_tags";
     $result = $this->db->createCommand($query)->queryAll();
     foreach ($result as $item) {
         $url = $this->createAbsoluteUrl('tag/index', array('alias' => $item['alias']));
         $urls[] = array($url, date('c'), 'daily', '0.7');
     }
     //danh sach bai viet
     $query = "SELECT id, alias, cate_id FROM tbl_archive ORDER BY id DESC";
     $result = $this->db->createCommand($query)->queryAll();
     foreach ($result as $item) {
         $url = $this->createAbsoluteUrl('detail/index', $item);
         $urls[] = array($url);
     }
     //danh sach bai viet
     $query = "SELECT id, alias FROM tbl_youtube ORDER BY id DESC";
     $result = $this->db->createCommand($query)->queryAll();
     foreach ($result as $item) {
         $url = $this->createAbsoluteUrl('video/detail', array('alias' => $item['alias']));
         $urls[] = array($url);
     }
     if ($_GET['test'] == 1) {
         echo count($urls);
         die;
     }
     header('Content-type: application/xml');
     // add many URLs at one time
     $sitemap->addUrls($urls);
     try {
         // create sitemap
         $sitemap->createSitemap();
         // write sitemap as file
         $sitemap->writeSitemap();
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
     }
 }
include 'SitemapGenerator.php';
// create object
$sitemap = new SitemapGenerator("http://your.app.com/", "../");
// will create also compressed (gzipped) sitemap
$sitemap->createGZipFile = true;
// determine how many urls should be put into one file
$sitemap->maxURLsPerSitemap = 10000;
// sitemap file name
$sitemap->sitemapFileName = "sitemap.xml";
// sitemap index file name
$sitemap->sitemapIndexFileName = "sitemap-index.xml";
// robots file name
$sitemap->robotsFileName = "robots.txt";
$urls = array(array("http://your.app.com", date('c'), 'daily', '1'), array("http://your.app.com/mainpage1", date('c'), 'daily', '0.5'), array("http://your.app.com/mainpage2", date('c'), 'daily'), array("http://your.app.com/mainpage3", date('c')), array("http://your.app.com/mainpage4"));
// add many URLs at one time
$sitemap->addUrls($urls);
// add urls one by one
$sitemap->addUrl("http://your.app.com/page1", date('c'), 'daily', '0.5');
$sitemap->addUrl("http://your.app.com/page2", date('c'), 'daily');
$sitemap->addUrl("http://your.app.com/page3", date('c'));
$sitemap->addUrl("http://your.app.com/page4");
$sitemap->addUrl("http://your.app.com/page/subpage1", date('c'), 'daily', '0.4');
$sitemap->addUrl("http://your.app.com/page/subpage2", date('c'), 'daily');
$sitemap->addUrl("http://your.app.com/page/subpage3", date('c'));
$sitemap->addUrl("http://your.app.com/page/subpage4");
try {
    // create sitemap
    $sitemap->createSitemap();
    // write sitemap as file
    $sitemap->writeSitemap();
    // update robots.txt file