* @license PHP License * @package WB * @subpackage datasource */ WBClass::load('WBDatasource_Sitemap' ); /** * Datasource Sitemap Menu * * Add menu items to sitemap * * @version 0.1.0 * @package WB * @subpackage datasource */ class WBDatasource_Sitemap_Menu extends WBDatasource_Sitemap { /** * Tree menu * @var WBDatasource_TreeMenu */ private $treeMenu; /** * Default configuration * * @var array */ protected $config = array( 'root' => 1, 'treemenu' => '', 'priority' => 1.1, 'maxlevel' => -1 ); /** * pages found so far * @var array */ private $pages = array( '[[SERVICE_HTML]]' => true ); /** * Find all the URLs * * Get recent blog posts */ public function find() { $this->init(); $url = $this->treeMenu->getUrlId(''); $base = $this->treeMenu->getMenuCurrent($url); $this->addItem($base); $this->listChildren($base); } /** * Add menu item to sitemap * * Verify item and add to sitemap * * @param array $item * @param int $level */ private function addItem($item, $level = 1) { $urlid = $this->treeMenu->getUrlId($item['url']); if (empty($urlid)) { return; } $path = $item['url']; if (0 != strncmp('[[SERVICE_HTML]]', $path, 16)) { return; } if (isset($this->pages[$urlid])) { return; } $this->pages[$urlid] = true; // check permissions: requiregroup if (!empty($item['requiregroup'])) { return; } // check permissions: requireuser if ('user' == $item['requireuser']) { return; } $prio = $this->config['priority'] - ($level * 0.1); $path = substr($path, 16); $this->setPath($path); $this->setPriority(min(1.0, $prio)); $this->notify(); } /** * List children of menu item * * Recursive function to dig into nested menues * * @param array $item * @param int $level */ private function listChildren($item, $level = 1) { // reached max level? if (0 < $this->config['maxlevel'] && $level > $this->config['maxlevel']) { return; } $children = $this->treeMenu->getMenuChildren($item); foreach ($children as $child) { if (empty($child['url'])) { continue; } $this->addItem($child, $level + 1); $this->listChildren($child, $level + 1); } } /** * Start menu and setup config */ private function init() { $this->config['priority'] = floatval($this->config['priority']); $this->config['maxlevel'] = intval($this->config['maxlevel']); $treeMenu = 'WBDatasource_TreeMenu'; if (!empty($this->config['treemenu'])) { $treeMenu .= '_' . $this->config['treemenu']; } $this->treeMenu = WBClass::create($treeMenu); $this->treeMenu->setRoot($this->config['root']); } }