本文整理汇总了PHP中Sitemap::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Sitemap::render方法的具体用法?PHP Sitemap::render怎么用?PHP Sitemap::render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sitemap
的用法示例。
在下文中一共展示了Sitemap::render方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
public function action_index()
{
$cache_key = 'sourcemap-sitemap';
$ttl = 60 * 60 * 24;
if ($cached = Cache::instance()->get($cache_key)) {
$xml = $cached;
} else {
// Sitemap instance.
$sitemap = new Sitemap();
// basics
$urls = array('home' => array('', 0.9, 'daily', time()), 'register' => array('register/', 0.6, 'yearly'), 'browse' => array('browse/', 0.7, 'daily', time()), 'login' => array('auth/login', 0.5, 'yearly'), 'about' => array('info/', 0.7, 'monthly'), 'api' => array('info/api', 0.7, 'monthly'), 'contact' => array('info/contact', 0.8, 'monthly'));
// categories
$cats = Sourcemap_Taxonomy::arr();
$nms = array();
foreach ($cats as $i => $cat) {
$slug = Sourcemap_Taxonomy::slugify($cat->name);
$urls['browse-' . $cat->name] = array('browse/' . $slug . '/', 0.7);
}
// public maps
$o = 0;
$l = 100;
while (($results = Sourcemap_Search::find(array('o' => $o, 'l' => $l))) && $results->hits_ret) {
foreach ($results->results as $i => $r) {
$urls['sc-' . $r->id] = array('view/' . $r->id, 0.5, 'daily', $r->modified);
}
$o += $l;
}
$defaults = array(false, 0.5, 'daily', false);
foreach ($urls as $k => $urld) {
foreach ($defaults as $i => $d) {
if (!isset($urld[$i])) {
$urld[$i] = $d;
}
}
list($loc, $priority, $freq, $lastmod) = $urld;
$new_url = new Sitemap_URL();
$new_url->set_loc(URL::site($loc, true))->set_priority($priority)->set_change_frequency($freq);
if ($lastmod) {
$new_url->set_last_mod($lastmod);
}
$sitemap->add($new_url);
}
$xml = $sitemap->render();
Cache::instance()->set($cache_key, $xml, $ttl);
}
header('Content-Type: application/xml');
$this->response = $xml;
die($this->response);
}
示例2: test_root
/**
* @test
* @group sitemap
*/
public function test_root()
{
// Base Sitemap
$sitemap = new Sitemap();
// Create basic Mobile Sitemap
$instance = new Sitemap_URL(new Sitemap_Geo());
$instance->set_loc('http://google.com');
$sitemap->add($instance);
// Load the end XML
$xml = new SimpleXMLElement($sitemap->render());
// Namespaces.
$namespaces = $xml->getDocNamespaces();
$this->assertSame(TRUE, isset($namespaces['geo']));
$this->assertSame('http://www.google.com/geo/schemas/sitemap/1.0', $namespaces['geo']);
}
示例3: _execute
protected function _execute(array $params)
{
$categories = ORM::factory('Category')->fetchActive();
$products = ORM::factory('Product')->fetchActive();
$pages = ORM::factory('Page')->fetchActive();
$sitemap = new Sitemap();
$url = new Sitemap_URL();
$page = ORM::factory('Page')->where('url', '=', '')->find();
$url->set_loc("http://cosm.by")->set_last_mod(strtotime($page->updated_at))->set_priority(1);
$sitemap->add($url);
foreach ($pages as $page) {
if ($page->url) {
$url->set_loc("http://cosm.by/page/" . $page->url)->set_last_mod(strtotime($page->updated_at))->set_change_frequency('monthly')->set_priority(0.2);
$sitemap->add($url);
}
}
$PDO = ORM::factory('Brand')->PDO();
$brandsQuery = "SELECT br.id, br.url FROM brand br\r\n\t\t\t\t\t\tLEFT JOIN product pr ON pr.brand_id = br.id\r\n\t\t\t\t\t\tWHERE pr.active = 1\r\n\t\t\t\t\t\tGROUP BY br.id\r\n\t\t\t\t\t\tHAVING COUNT(pr.id) > 0";
$brands = $PDO->query($brandsQuery)->fetchAll(PDO::FETCH_ASSOC);
foreach ($brands as $brand) {
$url->set_loc("http://cosm.by/brand/" . $brand['url'])->set_change_frequency('monthly')->set_priority(0.5);
$sitemap->add($url);
}
foreach ($brands as $brand) {
$query = "SELECT line.url, line.name, product.updated_at FROM categories\r\n\t\t\t\t\tLEFT JOIN product ON product.category_id = categories.id\r\n\t\t\t\t\tLEFT JOIN line ON line.id = product.line_id\r\n\t\t\t\t\tWHERE product.brand_id = {$brand['id']}\r\n\t\t\t\t\tAND product.active = 1\r\n\t\t\t\t\tGROUP BY line.id\r\n\t\t\t\t\tHAVING COUNT(product.id) > 0\r\n\t\t\t\t\tORDER BY line.name ASC";
$brandCategories = $PDO->query($query)->fetchAll(PDO::FETCH_ASSOC);
foreach ($brandCategories as $category) {
$url->set_loc("http://cosm.by/brand/" . $brand['url'] . "/" . $category['url'])->set_last_mod(strtotime($category['updated_at']))->set_change_frequency('weekly');
$sitemap->add($url);
}
}
foreach ($categories as $category) {
$url->set_loc("http://cosm.by/" . $category->url)->set_last_mod(strtotime($category->updated_at))->set_change_frequency('weekly');
$sitemap->add($url);
}
foreach ($products as $product) {
$url->set_loc("https://cosm.by" . $product->getSiteUrl())->set_last_mod(strtotime($product->updated_at))->set_change_frequency('daily')->set_priority(1);
$sitemap->add($url);
}
$response = $sitemap->render();
file_put_contents('sitemap.xml', $response);
}
示例4: action_index
public function action_index()
{
$this->auto_render = FALSE;
// Sitemap instance.
$sitemap = new Sitemap();
// New basic sitemap.
$sitemap_url = new Sitemap_URL();
// Set base url
$base_url = "http://{$this->config['global']['server_domain']}/";
// Config urls
$urls = array(array('url' => $base_url, 'frequency' => 'daily'), array('url' => $base_url . 'contact', 'frequency' => 'yearly'), array('url' => $base_url . 'about', 'frequency' => 'yearly'), array('url' => $base_url . 'contact', 'frequency' => 'yearly'));
// Adds categories urls
$categories = ORM::factory('category')->find_all();
foreach ($categories as $category) {
$urls[] = array('url' => $base_url . '?&category_id=' . $category->id, 'frequency' => 'daily');
}
// Adds jobtypes urls
$jobtypes = ORM::factory('jobtype')->find_all();
foreach ($jobtypes as $jobtype) {
$urls[] = array('url' => $base_url . '?&jobtype_id=' . $jobtype->id, 'frequency' => 'daily');
}
// Get all active ads
$ads = ORM::factory('ad');
$ads = $ads->where('active', '=', 1)->limit(500)->offset(0)->order_by('id', 'DESC')->find_all()->as_array('id', 'title');
foreach ($ads as $id => $title) {
$urls[] = array('url' => Helper_Utils::get_ad_url($title, $id), 'frequency' => 'yearly');
}
// Adds each url to the sitemap xml structure
foreach ($urls as $url) {
$sitemap_url->set_loc($url['url'])->set_last_mod(time())->set_change_frequency($url['frequency'])->set_priority(1);
$sitemap->add($sitemap_url);
}
// Render the output.
$output = $sitemap->render();
// __toString is also supported.
header('Content-Type: text/xml');
echo $sitemap;
die;
}
示例5: xml
public function xml()
{
$sitemap = new Sitemap();
//create new sitemap
$www = $_SERVER['SERVER_NAME'];
$pages = ORM::factory('page')->where('status_id', 2)->find_all();
foreach ($pages as $page) {
if ($page->seoURL == "") {
$url = 'http://' . $www . "/";
} else {
$url = 'http://' . $www . "/" . $page->seoURL . ".html";
}
$sitemap->add_url($url, date('Y-m-d'), 'weekly', 1);
//url, last modified, change frequency, priority
}
$sitemap->location = 'http://' . $www . '/sitemap.xml';
//not necessary really since this url is assumed
echo $sitemap->render();
//will output the sitemap and add an xml header
$sitemap->ping_google();
//tell Google about the sitemap
$this->auto_render = false;
}
示例6: _generate
protected function _generate()
{
$_common_set = array();
$this->pages_uris = Helper_Page::parse_to_base_uri(ORM::factory('page')->find_all());
$pages = $this->get_pages();
foreach ($pages as $item) {
$item = $this->set_default_values($item);
$_set = array();
if ($item['type'] == 'static') {
$_set[] = $this->_page_item($item);
} elseif ($item['type'] == 'module') {
switch ($item['data']) {
case 'cities':
case 'contacts':
case 'chart':
case 'feedback':
case 'playlist':
case 'search':
$_set[] = $this->_page_item($item);
break;
case 'news':
$_set = $this->_news_items($item);
break;
case 'programs':
$_set = $this->_programs_items($item);
break;
case 'staff':
$_set = $this->_staff_items($item);
break;
}
}
if ($item['sm_separate_file'] == 1 and !empty($_set)) {
$sitemap = new Sitemap();
foreach ($_set as $_item) {
$sitemap_url = new Sitemap_URL();
$sitemap_url->set_loc($_item['loc'])->set_change_frequency($_item['changefreq'])->set_priority(str_replace(',', '.', $_item['priority']));
if (!empty($_item['lastmod'])) {
$_unix_time = strtotime($_item['lastmod']);
$sitemap_url->set_last_mod($_unix_time);
}
$sitemap->add($sitemap_url);
unset($sitemap_url);
}
$this->write_to_file($this->sitemap_directory . DIRECTORY_SEPARATOR . 'part_' . uniqid() . '.xml', $sitemap->render());
unset($sitemap);
} else {
$_common_set = array_merge($_common_set, $_set);
}
}
if (!empty($_common_set)) {
$sitemap = new Sitemap();
foreach ($_common_set as $_item) {
$sitemap_url = new Sitemap_URL();
$sitemap_url->set_loc($_item['loc'])->set_change_frequency($_item['changefreq'])->set_priority(str_replace(',', '.', $_item['priority']));
if (!empty($_item['lastmod'])) {
$_unix_time = strtotime($_item['lastmod']);
$sitemap_url->set_last_mod($_unix_time);
}
$sitemap->add($sitemap_url);
unset($sitemap_url);
}
$this->write_to_file($this->sitemap_directory . DIRECTORY_SEPARATOR . uniqid('common_') . '.xml', $sitemap->render());
unset($sitemap);
}
}
示例7: Sitemap
<?php
require_once '../classes/Sitemap.php5';
require_once '../classes/Sitemap/URL.php5';
require_once '../classes/Sitemap/Index.php5';
require_once '../classes/XML/Node.php5';
require_once '../classes/XML/Builder.php5';
try {
$sitemap = new Sitemap();
$sitemap->add('http://localhost/dev/0.8/SitemapGenerator/test1', '2012-12-24');
$sitemap->setUrl('http://localhost/dev/0.8/SitemapGenerator/get.php5?part=0');
#$sitemap->save( 'sitemap.xml.bz', 1, 10, 'bz' );
#$sitemap->save( 'sitemap.xml.gz', 1, 10, 'gz' );
$compression = NULL;
'gz';
$maxMegabytes = 0.001;
$maxUrls = 0;
print '<xmp>' . $sitemap->render($maxUrls, $maxMegabytes, $compression);
die;
$index = new Sitemap_Index();
$index->addSitemap($sitemap);
print '<xmp>' . $index->render();
} catch (Exception $e) {
UI_HTML_Exception_Page::display($e);
}
示例8: function
Route::get('sitemap.xml', function () {
$sitemap = new Sitemap();
// set item's url, date, priority, freq
$sitemap->add(URL::to(), '2012-12-16T19:45:53+00:00', '1.0', 'monthly');
$sitemap->add(URL::to('kamer-verhuren'), '2012-12-16T19:45:53+00:00', '0.9', 'monthly');
$sitemap->add(URL::to('kamer-huren'), '2012-12-16T19:45:53+00:00', '0.9', 'monthly');
$posts = Room::where_not_null('city')->group_by('city')->order_by('city', 'asc')->get();
foreach ($posts as $post) {
$sitemap->add('http://kamergenood.nl/kamer-huren/' . Str::slug($post->city), $post->created_at, '0.8', 'always');
}
$sitemap->add(URL::to('over'), '2012-12-16T19:45:53+00:00', '0.7', 'monthly');
$sitemap->add(URL::to('contact'), '2012-12-16T19:45:53+00:00', '0.6', 'monthly');
$sitemap->add(URL::to('sitemap'), '2012-12-16T19:45:53+00:00', '0.4', 'daily');
$sitemap->add(URL::to('voorwaarden'), '2012-12-16T19:45:53+00:00', '0.3', 'yearly');
// show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
return $sitemap->render('xml');
});
Route::get('feed', function () {
$posts = DB::table('users')->order_by('created_at', 'desc')->get();
$feed = new Feed();
$feed->title = 'Your title';
$feed->description = 'Your description';
$feed->link = URL::to('feed');
$feed->pubdate = '12-12-12';
$feed->lang = 'en';
foreach ($posts as $post) {
$feed->add($post->email, $post->email, $post->name, $post->created_at, $post->created_at);
}
return $feed->render('atom');
});
Route::controller(array('admin.room', 'admin.photo', 'admin'));
示例9: sitemapAction
/**
* Renders and prints sitemap XML.
* For gzip compression add paramter "compression" with compression method "bzip" or "gzip" as value.
* Appending a name paramter with a file name will name your download file if you request via browser.
* @access public
* @return void
* @todo Create zend route from ./sitemap.xml to site/sitemap
* @todo Create zend route from ./sitemap.xml.gz to site/sitemap/compression/gzip/name/sitemap.xml.gz
* @todo Create zend route from ./sitemap.xml.bz2 to site/sitemap/compression/bzip/name/sitemap.xml.bz2
* @todo add support for sitemap index
*/
public function sitemapAction()
{
$compression = $this->getParam('compression');
# $page = (integer) $this->getParam( 'page' );
$pathGenerator = __DIR__ . '/libraries/SitemapGenerator/classes/';
require_once $pathGenerator . 'Sitemap.php';
require_once $pathGenerator . 'Sitemap/URL.php';
require_once $pathGenerator . 'XML/Builder.php';
require_once $pathGenerator . 'XML/Node.php';
// Here we start the object cache id
$sitemapObjectCacheIdSource = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$sitemapObjectCacheId = 'sitemap_' . md5($sitemapObjectCacheIdSource);
// try to load the cached value
$erfurtObjectCache = OntoWiki::getInstance()->erfurt->getCache();
$erfurtQueryCache = OntoWiki::getInstance()->erfurt->getQueryCache();
$sitemapXml = $erfurtObjectCache->load($sitemapObjectCacheId);
if ($sitemapXml === false) {
$erfurtQueryCache->startTransaction($sitemapObjectCacheId);
$siteConfig = $this->_getSiteConfig();
$this->_loadModel();
$query = '
SELECT DISTINCT ?resourceUri ?modified
WHERE {
?resourceUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type.
OPTIONAL {?resourceUri <http://purl.org/dc/terms/modified> ?modified }
FILTER strstarts(str(?resourceUri), "' . $siteConfig['model'] . '")
} ';
//OPTIONAL {?resourceUri <http://purl.org/dc/terms/modified> ?modified }
//?resourceUri <http://purl.org/dc/terms/modified> ?modified
$results = $this->_model->sparqlQuery($query);
$sitemap = new Sitemap();
foreach ($results as $result) {
$url = new Sitemap_URL($result['resourceUri']);
if (isset($result['modified']) && strlen($result['modified'])) {
$url->setDatetime($result['modified']);
}
$sitemap->addUrl($url);
}
$sitemapXml = $sitemap->render();
// save the page body as an object value for the object cache
$erfurtObjectCache->save($sitemapXml, $sitemapObjectCacheId);
// close the object cache transaction
$erfurtQueryCache->endTransaction($sitemapObjectCacheId);
}
$contentType = "application/xml";
// compression has been requested
if (strlen(trim($compression))) {
switch (strtolower($compression)) {
case 'bzip':
$sitemapXml = bzcompress($sitemapXml);
$contentType = "application/x-bzip";
header('Content-Encoding: bzip2');
break;
case 'gzip':
$sitemapXml = gzencode($sitemapXml);
$contentType = "application/x-gzip";
header('Content-Encoding: gzip');
break;
}
}
header('Content-Length: ' . strlen($sitemapXml));
header("Content-Type: " . $contentType);
print $sitemapXml;
exit;
}
示例10: test_render_gzip
/**
* @test
* @group sitemap
*/
public function test_render_gzip()
{
// Basic URL
$url = new Sitemap_URL();
$url->set_loc('http://example.com');
// Add the sitemap url.
$instance = new Sitemap();
$instance->add($url);
// Enable gzip compression
$instance->gzip = TRUE;
$instance->compression = 9;
// Via render
$render = $instance->render();
// Via __toString
$tostring = (string) $instance;
$this->assertSame(TRUE, NULL !== http_inflate($render));
$this->assertSame(TRUE, NULL !== http_inflate($tostring));
}
示例11: build
//.........这里部分代码省略.........
}
//инфографика главные
$url->set_loc($site . '/kz/infographs')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/ru/infographs')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/en/infographs')->set_priority($priority);
$sitemap->add($url);
//инфографика
foreach ($langs as $lang) {
$result = DB::select('id', 'title_' . $lang)->from('infographs')->where('published', '=', '1')->execute();
foreach ($result as $lists) {
if ($lists['title_' . $lang] != '') {
$url->set_loc($site . '/' . $lang . '/infographs/view/' . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
}
}
//благодарности главные
$url->set_loc($site . '/kz/thanks')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/ru/thanks')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/en/thanks')->set_priority($priority);
$sitemap->add($url);
//полезные ссылки главные
$url->set_loc($site . '/kz/links')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/ru/links')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/en/links')->set_priority($priority);
$sitemap->add($url);
//календарь главные
$url->set_loc($site . '/kz/calendar')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/ru/calendar')->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . '/en/calendar')->set_priority($priority);
$sitemap->add($url);
//календарь
$results_list = DB::select('id', 'day', 'month')->from('calendar')->execute();
foreach ($results_list as $lists) {
foreach ($langs as $lang) {
$month = (int) $lists['month'];
$day = (int) $lists['day'];
if ($month < 10) {
$month = "0" . $month;
}
if ($day < 10) {
$day = "0" . $day;
}
$url->set_loc($site . "/" . $lang . "/calendar/event/" . $month . "/" . $day)->set_priority($priority);
$sitemap->add($url);
$url->set_loc($site . "/" . $lang . "/calendar/event/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
}
//книги
$results_list = DB::select('books.id', 'books.type', 'books.published', 'books.show_ru', 'books.show_en', "books.show_kz", "books.category_id")->from('books')->join('library_categories')->on('books.category_id', '=', 'library_categories.id')->execute();
foreach ($results_list as $lists) {
foreach ($langs as $lang) {
if ($lists['published'] == 1 and $lists['show_' . $lang] == 1) {
if ($lists['category_id'] == 20 or $lists['category_id'] == 23 or $lists['category_id'] == 24 or $lists['category_id'] == 25 or $lists['category_id'] == 26 or $lists['category_id'] == 45 or $lists['category_id'] == 28 or $lists['category_id'] == 30) {
$url->set_loc($site . "/" . $lang . "/books/education/view/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
if ($lists['type'] != 'txt') {
$url->set_loc($site . "/" . $lang . "/books/education/read/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
} elseif ($lists['category_id'] == 18 or $lists['category_id'] == 43) {
$url->set_loc($site . "/" . $lang . "/books/president/view/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
if ($lists['type'] != 'txt') {
$url->set_loc($site . "/" . $lang . "/books/president/read/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
} else {
$url->set_loc($site . "/" . $lang . "/books/library/view/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
if ($lists['type'] != 'txt') {
$url->set_loc($site . "/" . $lang . "/books/library/read/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
}
}
}
}
//позиции экспертов
$results_list = DB::select('id')->from('biography_categories')->execute();
foreach ($results_list as $lists) {
foreach ($langs as $lang) {
$url->set_loc($site . "/" . $lang . "/biography/" . $lists['id'])->set_priority($priority);
$sitemap->add($url);
}
}
// Генерируем xml
$response = urldecode($sitemap->render()) . '<!-- Generated - ' . date('d.m.Y H:i:s') . ' -->';
//Записываем в файл
file_put_contents('sitemap.xml', $response);
}