Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Default content and product sitemaps and robots.txt generation for absolute paths

givanzbe73915d48e9
diff --git a/app/controller/feed/index.php b/app/controller/feed/index.php
index 1d473dc..757b665 100755
--- a/app/controller/feed/index.php
+++ b/app/controller/feed/index.php
@@ -30,10 +30,24 @@ class Index extends Base {
$rss = $this->request->get['rss'] ?? false;
if ($rss) {
- $rss = Str::sanitizeFilename($rss);
- header('Content-type: text/xml');
+ $rss = Str::sanitizeFilename($rss);
+ $xml = "/feed/{$rss}.xml";
+ $theme = $this->view->getTheme();
- return "/feed/{$rss}.xml";
+ foreach ([$theme, 'default'] as $t) {
+ $file = DIR_THEME . $t . DS . $xml;
+
+ if (file_exists($file)) {
+ header('Content-type: text/xml');
+
+ $this->view->setTheme($t);
+ $this->view->pubDate = date('r');
+
+ return $xml;
+ }
+ }
+
+ $this->notFound(true);
}
}
}
diff --git a/app/controller/feed/manifest.php b/app/controller/feed/manifest.php
index 1f3e2e1..a53c041 100755
--- a/app/controller/feed/manifest.php
+++ b/app/controller/feed/manifest.php
@@ -92,8 +92,7 @@ class Manifest extends Base {
],*/
];
- header('Content-type: application/json; charset=utf-8');
-
- die(json_encode($manifest));
+ $this->view->json = $manifest;
+ $this->response->setType('json');
}
}
diff --git a/app/controller/feed/robots.php b/app/controller/feed/robots.php
new file mode 100644
index 0000000..4c0b1f4
--- /dev/null
+++ b/app/controller/feed/robots.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller\Feed;
+
+use Vvveb\Controller\Base;
+
+class Robots extends Base {
+ function index() {
+ $text = '';
+ $robots = DIR_PUBLIC . 'vrobots.txt';
+
+ if (file_exists($robots)) {
+ $text = @file_get_contents($robots);
+ }
+
+ $host = ' https://' . $_SERVER['HTTP_HOST'] ?? '' . (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '');
+
+ // change sitemap urls to absolute
+ if ($host) {
+ $text = preg_replace('@(sitemap):\s+/@', "$1: $host/", $text);
+ }
+
+ $this->view->text = $text;
+
+ $this->response->setType('text');
+ }
+}
diff --git a/config/routes.php b/config/routes.php
index 7f4208c..405e996 100755
--- a/config/routes.php
+++ b/config/routes.php
@@ -117,7 +117,8 @@ return [
'/checkout/confirm/#id#' => ['module' => 'checkout/order/index'],
//feeds
- '/feed/{rss}' => ['module' => 'feed/index'],
+ '/feed/{rss}' => ['module' => 'feed/index'],
+ '/robots.txt' => ['module' => 'feed/robots/index'],
/*
'/feed/posts' => ['module' => 'feed/posts'],
'/feed/products' => ['module' => 'feed/products'],
@@ -167,10 +168,6 @@ return [
//archive day
//'/#year#/#month#/#day#'=> ['module' => 'content/archive/index'],
- //feed
- '/feed' => ['module' => 'feed'],
- '/feed/comments' => ['module' => 'feed/comments/index'],
-
//Cron
'/run-cron/{key}' => ['module' => 'cron/index'],
];
diff --git a/public/robots.txt b/public/robots.txt
deleted file mode 100755
index 07e40f0..0000000
--- a/public/robots.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-User-agent: *
-Disallow: /search/
-Disallow: /user/*
-Disallow: /cart/*
-Disallow: /checkout/*
-Disallow: /filters-*/
-Disallow: /shop/*/*/filters-*
-
-User-agent: Expanse
-Crawl-Delay: 3600
-
-Sitemap: /sitemap.xml
-Sitemap: /news-sitemap.xml
diff --git a/public/themes/default/feed/index.xsl b/public/themes/default/feed/index.xsl
new file mode 100755
index 0000000..6c0fdca
--- /dev/null
+++ b/public/themes/default/feed/index.xsl
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet
+ version="2.0"
+ xmlns:html="http://www.w3.org/TR/html40"
+ xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
+ xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
+ xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+>
+ <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
+
+ <xsl:template match="/">
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XML Sitemap</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <style type="text/css">
+ table {
+ border-color:#ccc;
+ }
+ tr:nth-child(odd) td {
+ background-color: #eee !important;
+ }
+ th {
+ text-align:left;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="content">
+ <h1>XML Vvveb Sitemap</h1>
+ <p>
+ Generated by <a href="https://vvveb.com" target="_blank" rel="noopener noreferrer">Vvveb</a>
+ </p>
+ <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &gt; 0">
+ <table width="100%">
+ <thead>
+ <tr>
+ <th>Sitemap</th>
+ <th>Last Modified</th>
+ </tr>
+ </thead>
+ <tbody>
+ <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
+ <xsl:variable name="sitemapURL">
+ <xsl:value-of select="sitemap:loc"/>
+ </xsl:variable>
+ <tr>
+ <td>
+ <a href="{$sitemapURL}"><xsl:value-of select="sitemap:loc"/></a>
+ </td>
+ <td>
+ <xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"/>
+ </td>
+ </tr>
+ </xsl:for-each>
+ </tbody>
+ </table>
+ </xsl:if>
+ <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &lt; 1">
+ <table width="100%">
+ <thead>
+ <tr>
+ <th>URL</th>
+ <th>Images</th>
+ <th>Last Mod.</th>
+ </tr>
+ </thead>
+ <tbody>
+ <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
+ <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
+ <xsl:for-each select="sitemap:urlset/sitemap:url">
+ <tr>
+ <td>
+ <xsl:variable name="itemURL">
+ <xsl:value-of select="sitemap:loc"/>
+ </xsl:variable>
+ <a href="{$itemURL}">
+ <xsl:value-of select="sitemap:loc"/>
+ </a>
+ </td>
+ <td>
+ <xsl:value-of select="count(image:image)"/>
+ </td>
+ <td>
+ <xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"/>
+ </td>
+ </tr>
+ </xsl:for-each>
+ </tbody>
+ </table>
+ </xsl:if>
+ </div>
+ </body>
+ </html>
+ </xsl:template>
+ </xsl:stylesheet>
diff --git a/public/themes/default/feed/page-sitemap.xml b/public/themes/default/feed/page-sitemap.xml
new file mode 100644
index 0000000..68f1572
--- /dev/null
+++ b/public/themes/default/feed/page-sitemap.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This sitemap was dynamically generated by Vvveb -->
+
+<?xml-stylesheet type="text/xsl" href="/themes/default/feed/index.xsl"?>
+<urlset
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
+ data-v-component-posts="page-sitemap"
+ data-v-limit="10000"
+ data-v-direction="desc"
+ data-v-order_by="updated_at"
+ data-v-type="page"
+>
+ <url data-v-post="post">
+ <loc data-v-post-full-url="name">https://vvveb.com/page/about</loc>
+ <lastmod data-v-post-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+ <url data-v-post="post">
+ <loc data-v-post-full-url="name">https://vvveb.com/page/services</loc>
+ <lastmod data-v-post-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+</urlset>
diff --git a/public/themes/default/feed/post-sitemap.xml b/public/themes/default/feed/post-sitemap.xml
new file mode 100644
index 0000000..f201bb0
--- /dev/null
+++ b/public/themes/default/feed/post-sitemap.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This sitemap was dynamically generated by Vvveb -->
+
+<?xml-stylesheet type="text/xsl" href="/themes/default/feed/index.xsl"?>
+<urlset
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
+ data-v-component-posts="page-sitemap"
+ data-v-limit="10000"
+ data-v-direction="desc"
+ data-v-order_by="updated_at"
+ data-v-type="post"
+>
+ <url data-v-post="post">
+ <loc data-v-post-full-url="name">https://vvveb.com/page/about</loc>
+ <lastmod data-v-post-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+ <url data-v-post="post">
+ <loc data-v-post-full-url="name">https://vvveb.com/page/services</loc>
+ <lastmod data-v-post-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+</urlset>
diff --git a/public/themes/default/feed/product-sitemap.xml b/public/themes/default/feed/product-sitemap.xml
new file mode 100644
index 0000000..7bd51b6
--- /dev/null
+++ b/public/themes/default/feed/product-sitemap.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This sitemap was dynamically generated by Vvveb -->
+
+<?xml-stylesheet type="text/xsl" href="/themes/default/feed/index.xsl"?>
+<urlset
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
+ data-v-component-products="page-sitemap"
+ data-v-limit="10000"
+ data-v-direction="desc"
+ data-v-order_by="updated_at"
+ data-v-type="product"
+>
+ <url data-v-product="product">
+ <loc data-v-product-full-url="name">https://vvveb.com/page/about</loc>
+ <lastmod data-v-product-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+ <url data-v-product="product">
+ <loc data-v-product-full-url="name">https://vvveb.com/page/services</loc>
+ <lastmod data-v-product-pubDate="date">2023-05-26T12:37:22+00:00</lastmod>
+ <changefreq>weekly</changefreq>
+ <priority>0.7</priority>
+ </url>
+</urlset>
diff --git a/public/vrobots.txt b/public/vrobots.txt
new file mode 100755
index 0000000..12b77a2
--- /dev/null
+++ b/public/vrobots.txt
@@ -0,0 +1,11 @@
+user-agent: *
+disallow: /search/
+disallow: /user/*
+disallow: /cart/*
+disallow: /checkout/*
+disallow: /filters-*/
+disallow: /shop/*/*/filters-*
+
+sitemap: /feed/page-sitemap
+sitemap: /feed/post-sitemap
+sitemap: /feed/product-sitemap