コード例 #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();
     }
 }
コード例 #2
0
ファイル: sitemap.php プロジェクト: Parashutik/ReloadCMS
 foreach ($modules as $module) {
     if ($module != 'module' and $module != 'sitemap') {
         $chfr = $_POST['changefreq'][$module];
         $prio = $_POST['priority'][$module];
         include_once 'sitemap/' . $module . '.php';
     }
 }
 $sitemap->sitemapFileName = $_POST['filename'];
 $result = $sitemap->sitemapFileName . '&nbsp;' . __('added successfully') . '<br/>';
 if (!empty($_POST['gz'])) {
     $sitemap->createGZipFile = true;
     $result .= $_POST['filename'] . '.gz&nbsp;' . __('added successfully') . '<br/>';
 }
 $sitemap->createSitemap();
 // create sitemap in memory
 $sitemap->writeSitemap();
 // write sitemap as file
 if (isset($_POST['robots_txt'])) {
     file_write_contents(RCMS_ROOT_PATH . 'robots.txt', $_POST['robots_txt']);
 }
 //save robots.txt
 if (!empty($_POST['robots'])) {
     //build new robots.txt
     rcms_delete_files(RCMS_ROOT_PATH . 'robots.txt');
     $sitemap->updateRobots();
     $result .= 'robots.txt&nbsp;' . __('added successfully') . '<br/>';
 }
 if (!empty($_POST['engines'])) {
     // submit sitemaps to search engines
     $result .= "<pre>";
     $result .= $sitemap->submitSitemap('');
コード例 #3
0
 /**
  * 
  * generate sitemap
  */
 public static function generate($force = FALSE)
 {
     //start time
     $start_time = microtime(TRUE);
     $site_url = Core::config('general.base_url');
     // include class
     require Kohana::find_file('vendor/sitemap', 'SitemapGenerator');
     // create object
     $sitemap = new SitemapGenerator($site_url, DOCROOT);
     // 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';
     //users
     $users = new Model_User();
     $users = $users->select('seoname')->select('created')->where('status', '=', Model_User::STATUS_ACTIVE)->find_all();
     foreach ($users as $user) {
         $url = Route::url('profile', array('seoname' => $user->seoname));
         $sitemap->addUrl($url, date('c', Date::mysql2unix($user->created)), 'monthly', '0.5');
     }
     //pages CMS
     $pages = new Model_Content();
     $pages = $pages->select('seotitle')->where('type', '=', 'page')->where('status', '=', '1')->find_all();
     foreach ($pages as $page) {
         $url = Route::url('page', array('seotitle' => $page->seotitle));
         $sitemap->addUrl($url, date('c', Date::mysql2unix($page->created)), 'monthly', '0.5');
     }
     //FAQ CMS
     if (core::config('general.faq') == 1) {
         $pages = new Model_Content();
         $pages = $pages->select('seotitle')->where('type', '=', 'help')->where('status', '=', '1')->find_all();
         $sitemap->addUrl(Route::url('faq'), date('c'), 'monthly', '0.5');
         foreach ($pages as $page) {
             $url = Route::url('faq', array('seotitle' => $page->seotitle));
             $sitemap->addUrl($url, date('c', Date::mysql2unix($page->created)), 'monthly', '0.5');
         }
     }
     //locations
     $locs = new Model_Location();
     $locs = $locs->select('seoname')->where('id_location', '!=', 1)->find_all();
     //categories
     $cats = new Model_Category();
     $cats = $cats->select('seoname')->where('id_category', '!=', 1)->find_all();
     foreach ($cats as $cat) {
         $url = Route::url('list', array('category' => $cat->seoname));
         $sitemap->addUrl($url, date('c'), 'daily', '0.7');
         //adding the categories->locations
         foreach ($locs as $loc) {
             $url = Route::url('list', array('category' => $cat->seoname, 'location' => $loc->seoname));
             $sitemap->addUrl($url, date('c'), 'weekly', '0.5');
         }
     }
     //all the ads
     $ads = DB::select('a.seotitle')->select(array('c.seoname', 'category'))->from(array('ads', 'a'))->join(array('categories', 'c'), 'INNER')->on('a.id_category', '=', 'c.id_category')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->as_object()->execute();
     foreach ($ads as $a) {
         $url = Route::url('ad', array('category' => $a->category, 'seotitle' => $a->seotitle));
         $sitemap->addUrl($url, date('c'), 'monthly', '0.5');
     }
     //all the blog posts
     if (core::config('general.blog') == 1) {
         $sitemap->addUrl(Route::url('blog'), date('c'), 'daily', '0.7');
         $posts = new Model_Post();
         $posts = $posts->where('status', '=', 1)->where('id_forum', 'IS', NULL)->order_by('created', 'desc')->find_all();
         foreach ($posts as $post) {
             $url = Route::url('blog', array('seotitle' => $post->seotitle));
             $sitemap->addUrl($url, date('c'), 'monthly', '0.5');
         }
     }
     //all the forums and topics
     if (core::config('general.forums') == 1) {
         $sitemap->addUrl(Route::url('forum-home'), date('c'), 'monthly', '0.5');
         $forums = new Model_Forum();
         $forums = $forums->select('seoname')->find_all();
         foreach ($forums as $forum) {
             $url = Route::url('forum-list', array('forum' => $forum->seoname));
             $sitemap->addUrl($url, date('c'), 'daily', '0.7');
         }
         //all the topics
         $posts = new Model_Post();
         $posts = $posts->where('status', '=', Model_Post::STATUS_ACTIVE)->where('id_forum', 'IS NOT', NULL)->where('id_post_parent', 'IS', NULL)->order_by('created', 'desc')->find_all();
         foreach ($posts as $post) {
             $url = Route::url('forum-topic', array('seotitle' => $post->seotitle, 'forum' => $post->forum->seoname));
             $sitemap->addUrl($url, date('c'), 'daily', '0.7');
         }
     }
     try {
         // create sitemap
         $sitemap->createSitemap();
         // write sitemap as file
         $sitemap->writeSitemap();
         // update robots.txt file
         //$sitemap->updateRobots();
         // submit sitemaps to search engines
         $result = $sitemap->submitSitemap();
         // shows each search engine submitting status
         // echo '<pre>'.print_r($result,1).'</pre>';
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
     }
     $ret = 'Memory peak ' . round(memory_get_peak_usage() / (1024 * 1024), 2) . ' MB -';
     return $ret . ' Time: ' . round(microtime(TRUE) - $start_time, 2) . 's';
 }