$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 ' . __('added successfully') . '<br/>'; } if (!empty($_POST['engines'])) { // submit sitemaps to search engines $result .= "<pre>"; $result .= $sitemap->submitSitemap(''); $result .= "</pre>"; } $result .= __('Memory peak usage: ') . number_format(memory_get_peak_usage() / (1024 * 1024), 2) . "MB"; $time2 = explode(" ", microtime()); $time2 = $time2[1]; $result .= '<br/>' . __('Execution time: ') . number_format($time2 - $time) . "s<br/>"; $result .= __('Done') . '<br/>'; $result .= __('Look at') . ' <a href="' . $_POST['filename'] . '" target="_blank"> sitemap.xml </a> <br/>'; rcms_showAdminMessage($result); } else { $frm = new InputForm('', 'post', __('Submit'), '', '', '', 'mainfrm'); $frm->addbreak(__('Information') . ' sitemap'); if (is_file(RCMS_ROOT_PATH . 'sitemap.xml')) { $frm->addrow(__('Look at') . ' <a href="sitemap.xml" target="_blank"> sitemap.xml </a> '); }
$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 $sitemap->updateRobots(); // submit sitemaps to search engines $result = $sitemap->submitSitemap("yahooAppId"); // shows each search engine submitting status echo "<pre>"; print_r($result); echo "</pre>"; } catch (Exception $exc) { echo $exc->getTraceAsString(); } echo "Memory peak usage: " . number_format(memory_get_peak_usage() / (1024 * 1024), 2) . "MB"; $time2 = explode(" ", microtime()); $time2 = $time2[1]; echo "<br>Execution time: " . number_format($time2 - $time) . "s"; ?> </body> </html>
/** * * 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'; }
Error::$pathToFile = LOCAL_PATH . 'logs/sitemap.log'; Error::setFileLogging(TRUE); DB::initialize('mysql', 'localhost', NULL, 'venginse_admin', 'venginse', 'YqPffTfB'); DB::executeQuery('SET NAMES utf8', 'cp_utf8'); $q = 'SELECT s_hostname, s_dbname, s_path, s_gziped FROM sites WHERE s_indexed = 1'; DB::executeQuery($q, 'sites'); $rows = DB::fetchResults('sites'); if (!empty($rows)) { $tsize = sizeof($rows); $Sitemap = new SitemapGenerator('venginse_all'); for ($i = 0; $i < $tsize; $i++) { $q = 'SELECT c_value FROM ' . $rows[$i]['s_dbname'] . '.const WHERE c_name = "siteClosed" LIMIT 1'; DB::executeQuery($q, 'close'); $row = DB::fetchOne('close'); if ($row == '0') { $Sitemap->setParams($rows[$i]); if ($Sitemap->buildSitemap()) { $Sitemap->writeSitemap(); $Sitemap->submitSitemap(); } sleep(100); } } unset($Sitemap); } Error::deInitialize(); DB::deInitialize();