* @license PHP License * @package WB * @subpackage datasource */ WBClass::load('WBDatasource_Sitemap' ); /** * Datasource Sitemap Page * * @version 0.1.0 * @package WB * @subpackage datasource */ class WBDatasource_Sitemap_Page extends WBDatasource_Sitemap { /** * Find all the URLs * * Walk through all the pages etc. to find all URLs to be added to the sitemap. */ public function find() { $loader = WBParam::get('wb/config/loader/service/site', 'File'); $this->setPath(''); $this->setPriority(1); $this->notify(); if ($loader != 'File') { $this->configLoader = WBClass::create('WBConfig_Loader_' . WBParam::get('wb/config/loader/service/site', 'File')); $this->addPages2Sitemap(); return; } // add pages from page configuration folders $etcDir = WBParam::get('wb/dir/base') . '/' . WBParam::get( 'wb/dir/config', 'etc' ); if (is_dir($etcDir . '/site/page')) { $this->addPageDir2Sitemap($etcDir . '/site/page'); } $this->addPageDir2Sitemap($etcDir . '-default/site/page'); } /** * list pages in sitemap * * Recursive method to load find all page configurations and add them * to sitemap. * * @param string $path */ private function addPages2Sitemap($path = '') { $path = trim($path, '/'); $branch = array_pop(explode('/', $path)); if (strncmp('__', $branch, 2) == 0) { return; } $prio = 1.1 - (count(explode('/', $path)) / 10); $this->setPath($path); $this->setPriority($prio); $this->notify(); // try to find children if (!empty($path)) { $path = '/' . $path; } $children = $this->configLoader->ls('site/page' . $path); if (empty($children)) { return; } foreach ($children as $child) { $child = substr($child, 10); $this->addPages2Sitemap($child); } } /** * add pages to sitemap * * Recursively scans folder for page definitions. It also makes sure, that each page * will be added just once. * * @uses display() * @param string $dir * @param string $prefix * @todo move to WBConfig_Loader_File */ protected function addPageDir2Sitemap($dir, $prefix = '') { $iter = new DirectoryIterator($dir); foreach ($iter as $page) { if ($page->isDot()) { continue; } if ($page->isDir()) { $this->addPageDir2Sitemap($page->getPathname(), $prefix . $page->getFilename() . '/'); continue; } $name = explode('.', $page->getFilename()); if (array_pop($name) != 'xml') { continue; } $name = implode('.', $name); // skip index and default pages if (strncmp($name, '__', 2) == 0) { continue; } $path = $prefix . $name; $prio = 1.1 - (count(explode('/', $path)) / 10); $this->setPath($path); $this->setPriority($prio); $this->notify(); } } }