array('handler' => array('site')) ); protected $_handlers = array(); public function getHandler($name) { if (!array_key_exists($name, $this->_handlers)) { $file = BASE_PATH . '/App/Doc/' . ucfirst($name) . '.php'; if (file_exists($file)) { $class = 'App_Doc_' . ucfirst($name); $this->_handlers[$name] = new $class(); } else { $this->_handlers[$name] = false; } } return $this->_handlers[$name]; } public function exec() { if (null !== ($filter = $this->getConfig('filter'))) { $sitemap = Qs_SiteMap::getFromDb(array('filter' => $filter->toArray())); } else { $sitemap = Qs_SiteMap::getFromDb(); } $xml = new App_Sitemap_Xml_Writer(); $xml->start(); $this->_writeXmlSitemap($xml, $sitemap); $xml->end(); $xml->finish(); $xml->output(); } public static function deleteSiteMap() { $filePath = WWW_PATH . '/' . 'sitemap.xml'; if (file_exists($filePath)) { unlink($filePath); } } protected function _writeXmlSitemap(App_Sitemap_Xml_Writer $xml, $sitemap) { foreach ($sitemap as $page) { if ('y' != $page['isIndexing']) { continue; } /** @var $doc App_Doc_SIte */ if (false === ($doc = $this->getHandler($page['handler']))) { Qs_Debug::log('Unknown page handler "' . $page['handler'] . '" for page "' . $page['fullAlias'] . '"'); continue; } $doc->setOptions($page); $xml->writeUrl((('y' == $page['isSecure']) ? BASE_URL_HTTPS : BASE_URL_HTTP) . '/' . $page['fullAlias']); foreach ($page['items'] as $item) { $item['doc'] = $doc; if ($itemObject = Qs_SiteMap::createPageItemView($item)) { if (method_exists($itemObject, 'writeXmlSitemap')) { $itemObject->writeXmlSitemap($xml); } unset($itemObject); } } if ($page['final'] == 'n' && isset($page['sub']) && !empty($page['sub'])) { $this->_writeXmlSitemap($xml, $page['sub']); } } return $this; } }