SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/SitemapGenPages.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. use Sprout\Helpers\Navigation;
  17. use Sprout\Helpers\Pagenode;
  18. use Sprout\Helpers\TreenodeInMenuMatcher;
  19.  
  20.  
  21. class SitemapGenPages extends SitemapGen
  22. {
  23.  
  24. /**
  25.   * Loads content page URLs and calls {@see SitemapGenPages::childrenPages} to output their XML URLs in the sitemap
  26.   * @return void Outputs XML directly
  27.   */
  28. public function generate()
  29. {
  30. $root = Navigation::getRootNode();
  31. $root->filterChildren(new TreenodeInMenuMatcher());
  32. $this->childrenPages($root, 0.9);
  33. }
  34.  
  35.  
  36. /**
  37.   * Outputs XML URLs for the children of a page in the sitemap, recursively until all descendents have been output
  38.   * @param Pagenode $node The page which should have its children/descendents output
  39.   * @param float $prio Priority for matching pages; the deeper the pages are, the lower priority they are given
  40.   * @return void Outputs XML directly
  41.   */
  42. private function childrenPages(Pagenode $node, $prio)
  43. {
  44. foreach ($node->children as $child) {
  45. $this->url($child->getFriendlyUrlNoprefix(), $child['date_modified'], NULL, $prio);
  46. $this->childrenPages($child, $prio - 0.1);
  47. }
  48. }
  49.  
  50. }