当前位置: 首页>>代码示例>>PHP>>正文


PHP Sitemap::add方法代码示例

本文整理汇总了PHP中Sitemap::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Sitemap::add方法的具体用法?PHP Sitemap::add怎么用?PHP Sitemap::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sitemap的用法示例。


在下文中一共展示了Sitemap::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
 }
开发者ID:hkilter,项目名称:OpenSupplyChains,代码行数:49,代码来源:sitemap.php

示例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']);
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:19,代码来源:GeoTest.php

示例3: 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;
 }
开发者ID:hbarroso,项目名称:Goworkat,代码行数:39,代码来源:sitemap.php

示例4: _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);
 }
开发者ID:ariol,项目名称:adminshop,代码行数:42,代码来源:Sitemap.php

示例5: _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);
     }
 }
开发者ID:greor,项目名称:satin-spb,代码行数:65,代码来源:sitemap.php

示例6: 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);
}
开发者ID:cfrancois7,项目名称:site.ontowiki,代码行数:25,代码来源:index.php

示例7: Sitemap

 function action_index()
 {
     $this->auto_render = FALSE;
     $sitemap = new Sitemap();
     $base_url = 'http://www.as-avtoservice.ru/';
     // Basic urls
     $base_urls = Kohana::$config->load('settings.sitemap_urls');
     foreach ($base_urls as $u) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $u);
         $sitemap->add($url);
     }
     // Standart contents
     $content = ORM::factory('content_site');
     foreach ($content->where('active', '!=', 0)->find_all() as $c) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $c->url);
         //$unix_time = strtotime($c->date);
         //$url->set_last_mod($unix_time);
         $sitemap->add($url);
     }
     // Shops page
     $shop = ORM::factory('service')->where('type', '=', 2);
     foreach ($shop->find_all() as $s) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'shops/' . $s->id);
         //$unix_time = (int) strtotime($s->date_create);
         //$url->set_last_mod($unix_time);
         $sitemap->add($url);
     }
     // Services page
     $service = ORM::factory('service')->where('type', '=', 1);
     foreach ($service->find_all() as $s) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'services/' . $s->id);
         $sitemap->add($url);
     }
     unset($s);
     // Service news
     $service_all_news_urls = array();
     $news_service = ORM::factory('newsservice')->where('active', '=', 1);
     foreach ($news_service->find_all() as $news) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'services/' . $news->service->id . '/news/' . $news->id);
         $sitemap->add($url);
         if (!array_key_exists($news->service->id, $service_all_news_urls)) {
             $service_all_news_urls[$news->service->id] = 'services/' . $news->service->id . '/news';
         }
     }
     unset($news);
     foreach ($service_all_news_urls as $all_news_url) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $all_news_url);
         $sitemap->add($url);
     }
     // Site news
     $news_portal = ORM::factory('newsportal')->where('active', '!=', 0);
     foreach ($news_portal->find_all() as $news) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'news/association/' . $news->id);
         $sitemap->add($url);
     }
     unset($news);
     // World news
     $news_world = ORM::factory('newsworld')->where('active', '!=', 0)->find_all();
     if (count($news_world) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'news/world');
         $sitemap->add($url);
         foreach ($news_world as $news) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'news/world/' . $news->id);
             $sitemap->add($url);
         }
     }
     // Articles
     $article = ORM::factory('content_article')->where('active', '!=', 0)->find_all();
     if (count($article) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'articles');
         $sitemap->add($url);
         foreach ($article as $a) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'articles/' . $a->id);
             $sitemap->add($url);
         }
     }
     // Reviews
     $service_all_reviews_urls = array();
     $review = ORM::factory('review')->where('active', '!=', 0)->find_all();
     if (count($review) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'reviews');
         $sitemap->add($url);
         foreach ($review as $r) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/' . $r->service->id . '/reviews/' . $r->id);
             $sitemap->add($url);
             if (!array_key_exists($r->service->id, $service_all_reviews_urls)) {
                 $service_all_reviews_urls[$r->service->id] = 'services/' . $r->service->id . '/reviews';
//.........这里部分代码省略.........
开发者ID:Alexander711,项目名称:naav1,代码行数:101,代码来源:sitemap.php

示例8: function

    return View::make('pages.sitemap');
});
Route::get('faq', function () {
    return View::make('pages.faq');
});
Route::get('contact', function () {
    return View::make('pages.contact');
});
Route::post('contact', 'site@contact');
Route::get('hash', function () {
    return Hash::make('jacco123');
});
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();
开发者ID:sanneterpstra,项目名称:Kamergenood,代码行数:31,代码来源:routes.php

示例9: 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));
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:22,代码来源:DataTest.php

示例10: build

 public static function build()
 {
     //урл корня
     $site = 'http://e-history.kz';
     //объявляем массив языков
     $langs = array('kz', 'ru', 'en');
     // Создаем экземпляр класса Sitemap
     $sitemap = new Sitemap();
     // Добавляем URL.
     $url = new Sitemap_URL();
     // Объявляем приоритет для второстепенных страниц
     $priority = "0.7";
     //Добавляем необходимые урлы к нашей карте сайта
     //сначала главные страницы
     $url->set_loc($site . "/kz")->set_priority(1);
     $sitemap->add($url);
     $url->set_loc($site . "/ru")->set_priority(1);
     $sitemap->add($url);
     $url->set_loc($site . "/en")->set_priority(1);
     $sitemap->add($url);
     //директории
     //ссылки вида http://$site/{{lang}}/contents/list/{{id}}
     $results_list = DB::select('id')->from('pages')->execute();
     foreach ($results_list as $lists) {
         foreach ($langs as $lang) {
             $url->set_loc($site . "/" . $lang . "/contents/list/" . $lists['id'])->set_priority($priority);
             $sitemap->add($url);
         }
     }
     //контент
     //ссылки вида http://$site/{{lang}}/contents/view/{{id}}
     $results_list = DB::select('id', 'title_kz', 'title_ru', 'title_en')->from('pages_contents')->execute();
     foreach ($results_list as $lists) {
         foreach ($langs as $lang) {
             //из-за того, что не все переводы существуют, проверяем на наличие title
             //если есть, добавляем урл
             if ($lists['title_' . $lang] !== '') {
                 $url->set_loc($site . "/" . $lang . "/contents/view/" . $lists['id'])->set_priority($priority);
                 $sitemap->add($url);
             }
         }
     }
     //страница публикации
     $url->set_loc($site . '/kz/publications')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/ru/publications')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/en/publications')->set_priority($priority);
     $sitemap->add($url);
     //список публикаций
     //ссылки вида http://$site/{{lang}}/publications/view/{{id}}
     $results_list = DB::select('id', 'title_kz', 'title_ru', 'title_en')->from('publications')->execute();
     foreach ($results_list as $lists) {
         foreach ($langs as $lang) {
             //из-за того, что не все переводы существуют, проверяем на наличие title
             //если есть, добавляем урл
             if ($lists['title_' . $lang] !== '') {
                 $url->set_loc($site . "/" . $lang . "/publications/view/" . $lists['id'])->set_priority($priority);
                 $sitemap->add($url);
             }
         }
     }
     //персоналии главная
     $url->set_loc($site . '/kz/biography')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/ru/biography')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/en/biography')->set_priority($priority);
     $sitemap->add($url);
     //персоналии
     //ссылки вида $site/{{lang}}/biography/view/{{id}}
     $results_list = DB::select('id', 'name_kz', 'name_ru', 'name_en')->from('biography')->where('published', '=', 1)->execute();
     foreach ($results_list as $lists) {
         foreach ($langs as $lang) {
             //из-за того, что не все переводы существуют, проверяем на наличие title
             //если есть, добавляем урл
             if ($lists['name_' . $lang] != '') {
                 $url->set_loc($site . "/" . $lang . "/biography/view/" . $lists['id'])->set_priority($priority);
                 $sitemap->add($url);
             }
         }
     }
     //экспертное мнение - главная
     $url->set_loc($site . '/kz/expert')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/ru/expert')->set_priority($priority);
     $sitemap->add($url);
     $url->set_loc($site . '/en/expert')->set_priority($priority);
     $sitemap->add($url);
     //'экспертное мнение
     //ссылки вида $site/{{lang}}/expert/view/{{id}}
     $results_list = DB::select('id', 'title_kz', 'title_ru', 'title_en')->from('expert_opinions')->execute();
     foreach ($results_list as $lists) {
         foreach ($langs as $lang) {
             //из-за того, что не все переводы существуют, проверяем на наличие title
             //если есть, добавляем урл
             if ($lists['title_' . $lang] !== '') {
                 $url->set_loc($site . "/" . $lang . "/expert/view/" . $lists['id'])->set_priority($priority);
                 $sitemap->add($url);
             }
//.........这里部分代码省略.........
开发者ID:HappyKennyD,项目名称:teest,代码行数:101,代码来源:SitemapGen.php


注:本文中的Sitemap::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。