Ejemplo n.º 1
0
 public function sendSitemap($domain = '')
 {
     if ($domain == '') {
         $domain = rex_yrewrite::getHost();
     }
     $sitemap = [];
     if (isset(rex_yrewrite::$domainsByName[$domain])) {
         $domain = rex_yrewrite::$domainsByName[$domain];
         $domain_article_id = $domain->getStartId();
         $paths = 0;
         if ($dai = rex_article::get($domain_article_id)) {
             $paths = count($dai->getParentTree());
         }
         foreach (rex_yrewrite::$paths['paths'][$domain->getName()] as $article_id => $path) {
             foreach ($domain->getClangs() as $clang_id) {
                 if (($article = rex_article::get($article_id, $clang_id)) && self::checkArticlePerm($article) && ($article->getValue('yrewrite_index') == 1 || $article->isOnline() && $article->getValue('yrewrite_index') == 0)) {
                     $changefreq = $article->getValue('yrewrite_changefreq');
                     if (!in_array($changefreq, self::$changefreq)) {
                         $changefreq = self::$changefreq_default;
                     }
                     $priority = $article->getValue('yrewrite_priority');
                     if (!in_array($priority, self::$priority)) {
                         $article_paths = count($article->getParentTree());
                         $prio = $article_paths - $paths - 1;
                         if ($prio < 0) {
                             $prio = 0;
                         }
                         if (isset(self::$priority[$prio])) {
                             $priority = self::$priority[$prio];
                         } else {
                             $priority = self::$priority_default;
                         }
                     }
                     $sitemap[] = "\n" . '<url>' . "\n" . '<loc>' . rex_yrewrite::getFullPath($path[$clang_id]) . '</loc>' . "\n" . '<lastmod>' . date(DATE_W3C, $article->getValue('updatedate')) . '</lastmod>' . "\n" . '<changefreq>' . $changefreq . '</changefreq>' . "\n" . '<priority>' . $priority . '</priority>' . "\n" . '</url>';
                 }
             }
         }
     }
     header('Content-Type: application/xml');
     $content = '<?xml version="1.0" encoding="UTF-8"?>';
     $content .= "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     $content .= implode("\n", $sitemap);
     $content .= "\n" . '</urlset>';
     echo $content;
     exit;
 }