#1 June 28, 2015 2:13pm

florianuhlemann
Member
From: Germany
Registered: June 26, 2015
Posts: 21
Website

Sitemap: missing module-subpages and showing hidden pages

I've encountered something that I'd like to fix.

- sitemap does not include the subitems of the modules (i.e. trees -> tree1, tree2, tree3) Did I break this with my modification of the link structure?
- sitemap does include hidden pages though they shouldnt, I assume?
- it's not showing the date the page was last changed
- additional note: I'd like to add a SEO meta description field for each separate module-subpage. its currently getting it from its parent-object, the modulepage itself. any chance to get that done without much trouble?

How do I go about fixing these issues?

/core/inc/bigtree/cms.php

/*
            Function: drawXMLSitemap
                Outputs an XML sitemap.
        */
       
        static function drawXMLSitemap() {
            header("Content-type: text/xml");
            echo '<?xml version="1.0" encoding="UTF-8" ?>';
            echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
            $q = sqlquery("SELECT id,template,external,path FROM bigtree_pages WHERE archived = '' AND (publish_at >= NOW() OR publish_at IS NULL) ORDER BY id ASC");

            while ($f = sqlfetch($q)) {
                if ($f["template"] || strpos($f["external"],DOMAIN)) {   
                    if (!$f["template"]) {
                        $link = static::getInternalPageLink($f["external"]);
                    } else {
                        $link = WWW_ROOT.$f["path"].(($f["id"] > 0) ? "/" : ""); // Fix sitemap adding trailing slashes to home
                    }
                   
                    echo "<url><loc>".$link."</loc></url>\n";
                   
                    // Added routed template support
                    $tf = sqlfetch(sqlquery("SELECT bigtree_modules.class AS module_class FROM bigtree_templates JOIN bigtree_modules ON bigtree_modules.id = bigtree_templates.module WHERE bigtree_templates.id = '".$f["template"]."'"));
                    if ($tf["module_class"]) {
                        $mod = new $tf["module_class"];
                        if (method_exists($mod,"getSitemap")) {
                            $subnav = $mod->getSitemap($f);
                            foreach ($subnav as $s) {
                                echo "<url><loc>".$s["link"]."</loc></url>\n";
                            }
                        }
                        $mod = $subnav = null;
                    }
                }
            }
            echo '</urlset>';
            die();
        }

Last edited by florianuhlemann (June 28, 2015 4:41pm)

Offline

#2 June 29, 2015 9:16am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Sitemap: missing module-subpages and showing hidden pages

- sitemap does not include the subitems of the modules (i.e. trees -> tree1, tree2, tree3) Did I break this with my modification of the link structure?

No, you didn't break this, it's just not implemented in the demo site. You must implement a getSitemap method in your module's class file to have it create sitemap entries. In the case of the Trees example module, add this method to the DemoTrees class:

function getSitemap($page) {
    $base_link = WWW_ROOT.$page["path"]."/";
    $items = $this->getAll("title ASC");
    $links = array();
    foreach ($items as $item) {
        $links[] = array("title" => $item["title"],"link" =>$base_link.$item["route"]."/";
    }
    return $links;
}

- sitemap does include hidden pages though they shouldnt, I assume?

It is intended behavior for the site to include pages that are hidden from navigation -- those pages are still meant to be findable, just not in the navigation. If you want to hide a page from search engines there's a checkbox in the page's SEO tab that will pass a "X-Robots-Tag: noindex" header to prevent search engines from indexing it.

- it's not showing the date the page was last changed

Where are you expecting this to be shown?

- additional note: I'd like to add a SEO meta description field for each separate module-subpage. its currently getting it from its parent-object, the modulepage itself. any chance to get that done without much trouble?

Yep, that's no problem at all. Just add a column to the database table, edit the form and add an SEO meta description field, and then on the page where you draw the individual entry  you do something like this:

<?php
    $item = $moduleClass->getByRoute($bigtree["commands"][0]);
    $bigtree["page"]["meta_description"] = $item["meta_description"];

Since the layout is loaded AFTER your template you can change the page's meta description even though it's drawn in the header.

Offline

#3 June 29, 2015 12:09pm

florianuhlemann
Member
From: Germany
Registered: June 26, 2015
Posts: 21
Website

Re: Sitemap: missing module-subpages and showing hidden pages

Tim! Thanks again for such great help. Learning a lot here smile
This system is so versatile, yet capable. I love it. I hope I'm in a position to say something like that! tongue

Sitemap now includes module-items. Perfect.
Module-items now have their own meta-description. Perfect for proper SEO. smile

Left to do: implementing the "last modified value" into the sitemap. I'll figure this out by myself. I promise. smile
it should look like this: (maybe include priority and refresh-tags as well, but last mod should help imho with ranking.)

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://anywebpage.tld/</loc>
<lastmod>2015-06-28</lastmod>
</url>
</urlset>

I'd still like the "SEO-hidden" pages to no show up in the sitemap, so I'll try any figure this if-case out by myself as well. Should have enough information now to actually accomplish such "baby steps". Will post the result of both and what I edited.

Offline

#4 June 29, 2015 3:06pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Sitemap: missing module-subpages and showing hidden pages

The best way to go about having the SEO hidden pages not showing up in the sitemap is to override the sitemap drawing method by having a custom child class of BigTreeCMS.

https://www.bigtreecms.org/docs/dev-gui … ding-core/

In BigTree 4.2 this process changed a bit as the "main" CMS class is now considered BigTreeCMSBase, so you'll extend it with:

<?php
    class MyCustomCMS extends BigTreeCMSBase {
        function drawXLMSitemap() {
             // custom code
        }
    }

BigTree will then create "extend" your custom class by saying "class BigTreeCMS extends MyCustomCMS {}". It does this because in 4.2 many methods of BigTreeCMS became static methods -- code that simply references BigTreeCMS::method would no longer call your custom class, so we changed a bit how the class extensions worked.

It's all a bit complicated at first, but it works really well once you get going!

Offline

#5 June 29, 2015 3:18pm

florianuhlemann
Member
From: Germany
Registered: June 26, 2015
Posts: 21
Website

Re: Sitemap: missing module-subpages and showing hidden pages

Okay. So I would copy the original function into my custom override class file (file name irrelevant?) and try small adjustments at first to find out if it works properly then implement the hidden check and pull the last mod data? Sounds easy, but is probably 5hrs of work for me smile

I'll try this tomorrow. Today I fiddled around with multiple callout types and proper style integration. Plus the fixes from your last feedbacks. They worked like a charm.

Offline

#6 June 29, 2015 3:19pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Sitemap: missing module-subpages and showing hidden pages

Yep, just copy the drawXMLSitemap method from the BigTreeCMSBase class and do your tweaks in your extension class.

Offline

#7 June 30, 2015 11:41am

florianuhlemann
Member
From: Germany
Registered: June 26, 2015
Posts: 21
Website

Re: Sitemap: missing module-subpages and showing hidden pages

timbuckingham wrote:

Yep, just copy the drawXMLSitemap method from the BigTreeCMSBase class and do your tweaks in your extension class.

I did so. The file I'm using is in the folder /custom/inc/required/cms.php

When I open the sitemap.xml file via the browser it states

Fatal error: Cannot make static method BigTreeCMSBase::drawXMLSitemap() non static in class MyCustomCMS in /var/www/html/custom/inc/required/cms.php on line 0

if I change the function to "static function drawXMLSitemap()" it works again, but it does not seem to replace the one in BigTreeCMSBase (cms.php from core)

What am I doing wrong? *confused*

Offline

#8 June 30, 2015 12:08pm

florianuhlemann
Member
From: Germany
Registered: June 26, 2015
Posts: 21
Website

Re: Sitemap: missing module-subpages and showing hidden pages

Figured it out.

Changed these in the settings.php:

define("BIGTREE_CUSTOM_BASE_CLASS","MyCustomCMS");
define("BIGTREE_CUSTOM_ADMIN_CLASS",false);
define("BIGTREE_CUSTOM_BASE_CLASS_PATH","../custom/inc/mycustomcms.php");
define("BIGTREE_CUSTOM_ADMIN_CLASS_PATH",false);

and now it works. smile

BTW, Here's my code snippet for the custom Sitemap. I also added a table to the tree-module-elements so that I can pull their date of last change. it's auto updated by the mysql table itself when anyone writes to it. thus i didn't need to implement the updating function into bigtree.

class MyCustomCMS extends BigTreeCMSBase {
        static function drawXMLSitemap() {
                    header("Content-type: text/xml");
                    echo '<?xml version="1.0" encoding="UTF-8" ?>';
                    echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
                    $q = sqlquery("SELECT id,template,external,updated_at,seo_invisible,path FROM bigtree_pages WHERE archived = '' AND (publish_at >= NOW() OR publish_at IS NULL) ORDER BY id ASC");


                    while ($f = sqlfetch($q)) {
                        if (($f["template"] || strpos($f["external"],DOMAIN)) && !($f["seo_invisible"] == "on")) {   
                            if (!$f["template"]) {
                                $link = static::getInternalPageLink($f["external"]);
                            } else {
                                $link = WWW_ROOT.$f["path"].(($f["id"] > 0) ? "/" : ""); // Fix sitemap adding trailing slashes to home
                            }

                            $lastmod = substr($f["updated_at"], 0, 10);
                            echo "<url><loc>".$link."</loc><lastmod>".$lastmod."</lastmod></url>\n";
                           
                            // Added routed template support
                            $tf = sqlfetch(sqlquery("SELECT bigtree_modules.class AS module_class FROM bigtree_templates JOIN bigtree_modules ON bigtree_modules.id = bigtree_templates.module WHERE bigtree_templates.id = '".$f["template"]."'"));
                            if ($tf["module_class"]) {
                                $mod = new $tf["module_class"];
                                if (method_exists($mod,"getSitemap")) {
                                    $subnav = $mod->getSitemap($f);
                                    foreach ($subnav as $s) {
                                        $lastmod = substr($s["updated_at"], 0, 10);
                                        echo "<url><loc>".$s["link"]."</loc><lastmod>".$lastmod."</lastmod></url>\n";
                                    }
                                }
                                $mod = $subnav = null;
                            }
                        }
                    }
                    echo '</urlset>';
                    die();
                }

    }

Last edited by florianuhlemann (July 4, 2015 10:26am)

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.