Search

Hello,

I am very new to Symphony CMS, and trying to accomplish a simple task, to create a dynamic sitemap. So far i managed to install Phill Gray's Sitemap XML extension, that generates the sitemap.xml in the root directory. Until here it's working as it should.

The next thing i'm trying to accomplish is to use the extension's query for selecting the pages to be included in the sitemap, in two frontend pages, sitemap-xml and sitemap-html. The two sitemaps are already made, but they are static, and i want to turn them into dynamic sitemaps, using the query from the extension:

$pages = Symphony::Database()->fetch("SELECT p.* FROM sym_pages AS p ORDER BY p.sortorder ASC"); $datasources = Symphony::Database()->fetch("SELECT * FROM sym_sitemap_xml");

$this->typeindex = explode(',', trim(pregreplace('/ /', '', Symphony::Configuration()->get('indextype', 'sitemapxml')), ','));

$this->typeglobal = explode(',', trim(pregreplace('/ /', '', Symphony::Configuration()->get('global', 'sitemap_xml')), ','));

$this->typelastmod = explode(',', trim(pregreplace('/ /', '', Symphony::Configuration()->get('lastmod', 'sitemap_xml')), ','));

$this->typechangefreq = explode(',', trim(pregreplace('/ /', '', Symphony::Configuration()->get('changefreq', 'sitemap_xml')), ','));

foreach($pages as $page) { $pagetypes = Symphony::Database()->fetchCol('type', "SELECT type FROM sym_pages_types WHERE pageid = '".$page['id']."' ORDER BY type ASC");

    $page['url'] = '/' . Administration::instance()->resolvePagePath($page['id']);
$page['types'] = $page_types;
$page['is_home'] = (count(array_intersect($page['types'], $this->type_index))) ? true : false;              
$page['is_global'] = (count(array_intersect($page['types'], $this->type_global)) > 0) ? true : false;

foreach($page['types'] as $type) {
    if ($type == 'high')    $page['priority'] = '1.00';
    elseif ($type == 'mid')  $page['priority'] = '0.50';
    elseif ($type == 'low')  $page['priority'] = '0.10';
    elseif (is_numeric($type)) $page['priority'] = $type;
}

$this->_pages[] = $page;

}

Do far, i've created a datasource, data.sitemap.php, and it contains:

<?php

require_once(TOOLKIT . '/class.datasource.php');

Class datasourcesitemap extends Datasource{

    public $dsParamROOTELEMENT = 'sitemap';

    public function __construct(&$parent, $env=NULL, $process_params=true){
        parent::__construct($parent, $env, $process_params);
        $this->_dependencies = array();
    }

    public function about(){
        return array(
            'name' => 'Sitemap',
            'author' => array(
                'name' => 'Sitemap',
                'website' => 'http://example.com',
                'email' => 'webmaster@localhost'),
            'version' => 'Symphony 2.2.5',
            'release-date' => '2013-08-21T10:22:55+00:00'
        );
    }

    public function allowEditorToParse(){
        return false;
    }

    public function grab(&$param_pool=NULL){
        $result = new XMLElement($this->dsParamROOTELEMENT);

        // fetch all pages
        $pages = Symphony::Database()->fetch("SELECT p.* FROM `sym_pages` AS p ORDER BY p.sortorder ASC");
        $datasources = Symphony::Database()->fetch("SELECT * FROM `sym_sitemap_xml`");

        // get values from config: remove spaces, remove any trailing commas and split into an array
        $this->type_index = explode(',', trim(preg_replace('/ /', '', Symphony::Configuration()->get('index_type', 'sitemap_xml')), ','));
        $this->type_global = explode(',', trim(preg_replace('/ /', '', Symphony::Configuration()->get('global', 'sitemap_xml')), ','));
        $this->type_lastmod = explode(',', trim(preg_replace('/ /', '', Symphony::Configuration()->get('lastmod', 'sitemap_xml')), ','));
        $this->type_changefreq = explode(',', trim(preg_replace('/ /', '', Symphony::Configuration()->get('changefreq', 'sitemap_xml')), ','));

        // supplement list of pages with additional meta data
        foreach($pages as $page) {
            $page_types = Symphony::Database()->fetchCol('type', "SELECT `type` FROM `sym_pages_types` WHERE page_id = '".$page['id']."' ORDER BY `type` ASC");

            $page['url'] = '/' . Administration::instance()->resolvePagePath($page['id']);
            $page['types'] = $page_types;

            $page['is_home'] = (count(array_intersect($page['types'], $this->type_index))) ? true : false;
            $page['is_global'] = (count(array_intersect($page['types'], $this->type_global)) > 0) ? true : false;

            // Set priority level
            foreach($page['types'] as $type) {
                if ($type == 'high')    $page['priority'] = '1.00';
                elseif ($type == 'mid')  $page['priority'] = '0.50';
                elseif ($type == 'low')  $page['priority'] = '0.10';
                elseif (is_numeric($type)) $page['priority'] = $type;
            }

            $page_node = new XMLElement("page", $page['id']);
            $page_node->setAttributeArray(array(
                "handle" => $page["handle"],
                "url"   => $page['url'],
                "types" => $page['types'],
                "is_home" => $page['is_home'],
                "is_global" => $page['is_global'],
                "priority" => $page['priority']
            ));
            $result->appendChild($page_node);
        }

        return $result;
    }

}

Furthermode, i've created the page sitemap-html.xsl in the /workspace/pages/ directory, containing:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:import href="../utilities/master.xsl"/>

<xsl:variable name="class-pagetype" select="'about'" />

<xsl:template match="/data">
    <div id="main">

        <div class="main_wrapper wrapper">

            <xsl:call-template name="breadcrumbs"/>

            <div id="content_column">

                <div class="markdown sitemap">
                    <h2>Home</h2>

                    <ul>
                        <xsl:for-each select="sitemap/entry">
                            <li><xsl:value-of select="title"/>
                            </li>
                        </xsl:for-each>
                    </ul>

                </div>

            </div>

            <div class="base_column clear"/>

        </div>

     </div>
</xsl:template>

The problem is, that the page template receives nothing from the data source, and have no idea why.

What am i doing wrong?

I would highly appreciate, if someone could point me in the right direction.

Thanks,

Can someone please point me in the right direction?

Thank you in advance!

Is your datasource attached to the page? If not, the page won't receive the data.

And as you're new to symphony and it looks like you're editing the datasource-php-file manually (which you shouldn't have to) you might want to read this at first: http://www.getsymphony.com/learn/concepts/view/data-sources/

Thank you Roman, i figured it out! Glad you helped me after all, i really appreciate it!

Cheers

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details