/** * @param Sitemap_URL $object */ public function add(Sitemap_URL $object) { $url = $object->create(); // Decorate the urlset $object->root($this->_root); // Append URL to root element $this->_root->appendChild($this->_xml->importNode($url, TRUE)); }
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); }
/** * @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']); }
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); }
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; }
public function addUrl(Sitemap_URL $url) { foreach ($this->urls as $entry) { if ($entry->getLocation() === $url->getLocation()) { return FALSE; } } $this->urls[] = $url; if ($url->getDatetime()) { if (!$this->datetime) { $this->datetime = $url->getDatetime(); } else { $timestamp = strtotime($url->getDatetime()); if ($timestamp > strtotime($this->datetime)) { $this->datetime = $url->getDatetime(); } } } return TRUE; }
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); } }
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'; } } } foreach ($service_all_reviews_urls as $all_reviews_url) { $url = new Sitemap_URL(); $url->set_loc($base_url . $all_reviews_url); $sitemap->add($url); } // Services stocks (акции) $service_all_stocks_urls = array(); $stock = ORM::factory('stock')->where('active', '!=', 0)->find_all(); if (count($stock) > 0) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'stocks'); $sitemap->add($url); foreach ($stock as $s) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/' . $s->service->id . '/stocks/' . $s->id); $sitemap->add($url); if (!array_key_exists($s->service->id, $service_all_stocks_urls)) { $service_all_stocks_urls[$s->service->id] = 'services/' . $s->service->id . '/stocks'; } } } foreach ($service_all_stocks_urls as $all_stocks_url) { $url = new Sitemap_URL(); $url->set_loc($base_url . $all_stocks_url); $sitemap->add($url); } // Services Vacancies (вакансии) $service_all_vacancies_urls = array(); foreach (ORM::factory('vacancy')->get_vacancies() as $v) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/' . $v->service->id . '/vacancies/' . $v->id); $sitemap->add($url); if (!array_key_exists($v->service->id, $service_all_vacancies_urls)) { $service_all_vacancies_urls[$v->service->id] = 'services/' . $v->service->id . '/vacancies'; } } foreach ($service_all_vacancies_urls as $all_vacancies_url) { $url = new Sitemap_URL(); $url->set_loc($base_url . $all_vacancies_url); $sitemap->add($url); } // Q&A (запросы пользователей) $question = ORM::factory('question')->where('active', '!=', 0)->find_all(); if (count($question) > 0) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'messages'); $sitemap->add($url); foreach ($question as $q) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'messages/' . $q->id); $sitemap->add($url); } } $geo_params = Geography::get_geography_params(); // Tags pages // Auto tags and search pages foreach ($geo_params['cities']['has_cars'] as $city) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'filter/auto/city_' . $city['city_id']); $sitemap->add($url); foreach ($city['cars'] as $car_id) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/search/car_' . $car_id . '/city_' . $city['city_id']); $sitemap->add($url); } } unset($city); // Works tags and search pages foreach ($geo_params['cities']['has_works'] as $city) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'filter/work/city_' . $city['city_id']); $sitemap->add($url); foreach ($city['works'] as $work_id) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/search/work_' . $work_id . '/city_' . $city['city_id']); $sitemap->add($url); } } unset($city); // Districts tags and search pages foreach ($geo_params['cities']['has_district'] as $city) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'filter/district/city_' . $city['city_id']); $sitemap->add($url); } unset($city); foreach ($geo_params['districts'] as $id => $value) { if (!empty($value['cars']) or !empty($value['works'])) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/search/district_' . $id); $sitemap->add($url); } } // Metro stations tags and search pages foreach ($geo_params['cities']['has_metro'] as $city) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'filter/metro/city_' . $city['city_id']); $sitemap->add($url); } foreach ($geo_params['metro_stations'] as $id => $value) { if (!empty($value['cars']) or !empty($value['works'])) { $url = new Sitemap_URL(); $url->set_loc($base_url . 'services/search/metro_' . $id); $sitemap->add($url); } } $this->response->headers('Content-type', 'text/xml'); $this->response->body($sitemap); }
/** * 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; }
/** * @test * @group sitemap * @expectedException RuntimeException */ public function test_create_without_loc() { $instance = new Sitemap_URL(); $return = $instance->create(); }
/** * @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)); }
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); } } } //книги главная $url->set_loc($site . '/kz/books')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/books')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/books')->set_priority($priority); $sitemap->add($url); //историческое образование $url->set_loc($site . '/kz/books/education')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/books/education')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/books/education')->set_priority($priority); $sitemap->add($url); //библиотека главная $url->set_loc($site . '/kz/books/library')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/books/library')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/books/library')->set_priority($priority); $sitemap->add($url); //книги //ссылки вида $site/{{lang}}/books/library/{{view|read}}/{{id}} //здесь нужно смотреть не по title а по переводу. если в поле show_$lang 1, то страница есть //$results_list = DB::select('id','show_kz','show_ru','show_en')->from('books')->execute(); /* foreach ($results_list as $lists) { foreach ($langs as $lang) { //из-за того, что не все переводы существуют, проверяем на наличие title //если есть, добавляем урл if ($lists['show_'.$lang]== 1) { $url->set_loc($site."/".$lang."/books/library/view/".$lists['id']) ->set_priority($priority); $sitemap->add($url); $url->set_loc($site."/".$lang."/books/library/read/".$lists['id']) ->set_priority($priority); $sitemap->add($url); } } }*/ //организации //ссылки вида $site/{{lang}}/organization/show/{{id}} //также нужно проверить, есть ли страница->смотрим в таблицу pages $results_list = DB::select('organizations.page_id', 'organizations.title_kz', 'organizations.title_ru', 'organizations.title_en', 'pages.id')->from('organizations')->join('pages')->on('organizations.page_id', '=', 'pages.id')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { //из-за того, что не все переводы существуют, проверяем на наличие title //если есть, добавляем урл if ($lists['title_' . $lang] != '') { $url->set_loc($site . "/" . $lang . "/organization/show/" . $lists['page_id'])->set_priority($priority); $sitemap->add($url); } } } //дебаты главная $url->set_loc($site . '/kz/debate')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/debate')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/debate')->set_priority($priority); $sitemap->add($url); //дебаты $results_list = DB::select('id')->from('debates')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { $url->set_loc($site . "/" . $lang . "/debate/view/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } //брифинги главная $url->set_loc($site . '/kz/briefings')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/briefings')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/briefings')->set_priority($priority); $sitemap->add($url); //брифинги $results_list = DB::select('id')->from('briefings')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { $url->set_loc($site . "/" . $lang . "/briefings/view/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } //цифровые образовательные ресурсы главная $url->set_loc($site . '/kz/scorm')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/scorm')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/scorm')->set_priority($priority); $sitemap->add($url); //цифровые образовательные ресурсы $results_list = DB::select('id', 'published')->from('educations')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { if ($lists['published'] == 1) { $url->set_loc($site . "/" . $lang . "/scorm/course/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } } //ЕНТ главная $url->set_loc($site . '/kz/ent')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/ent')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/ent')->set_priority($priority); $sitemap->add($url); //ЕНТ $results_list = DB::select('id', 'published')->from('ent')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { if ($lists['published'] == 1) { $url->set_loc($site . "/" . $lang . "/ent/test/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } } //фотогалерея главные $url->set_loc($site . '/kz/photosets')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/photosets')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/photosets')->set_priority($priority); $sitemap->add($url); //категории фотогалереи $results_list = DB::select('id')->from('photosets_categories')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { $url->set_loc($site . "/" . $lang . "/photosets/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } //фотогалерея $results_list = DB::select('id', 'published')->from('photosets')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { if ($lists['published'] == 1) { $url->set_loc($site . "/" . $lang . "/photosets/view/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } } //видео главные $url->set_loc($site . '/kz/video')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/video')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/video')->set_priority($priority); $sitemap->add($url); //видео $results_list = DB::select('id', 'title')->from('video')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { if ($lists['title'] != '') { $url->set_loc($site . "/" . $lang . "/video/view/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } } //video категории $results_list = DB::select('id')->from('categories')->execute(); foreach ($results_list as $lists) { foreach ($langs as $lang) { $url->set_loc($site . "/" . $lang . "/video/" . $lists['id'])->set_priority($priority); $sitemap->add($url); } } //аудио главные $url->set_loc($site . '/kz/audio')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/ru/audio')->set_priority($priority); $sitemap->add($url); $url->set_loc($site . '/en/audio')->set_priority($priority); $sitemap->add($url); //нужно посчитать страницы с аудио отдельно по языкам foreach ($langs as $lang) { $result = DB::select('id')->from('audio')->where('show_' . $lang, '=', '1')->and_where('published', '=', '1')->and_where('storage_id', '>', '0')->execute(); $count_of_el = ceil(count($result)) / 12 + 1; //12 - число записей на странице/ +1 - т.к. будем начинать со второй страницы => если не добавим, одну потеряем for ($i = 2; $i <= $count_of_el; $i++) { $url->set_loc($site . '/' . $lang . '/audio/page-' . $i)->set_priority($priority); $sitemap->add($url); } } //инфографика главные $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); }