array('handler' => array('site')) ); protected $_handlers = array(); public function getConfig($field = false) { if (empty($this->_config)) { $config = Zend_Registry::get('config'); if (isset($config->sitemapXml)) { $this->_config = $config->sitemapXml->toArray(); } else { $this->_config = $this->_defaultConfig; } } return parent::getConfig($field); } 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() { $sitemap = Qs_SiteMap::getFromDb(array('full' => true, 'filter' => $this->getConfig('filter'))); $xml = new App_Sitemap_Xml_Writer(); $xml->start(); $this->_writeXmlSitemap($xml, $sitemap); $xml->end(); $xml->finish(); $xml->output(); } protected function _writeXmlSitemap($xml, $sitemap) { foreach ($sitemap as $page) { 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']); } } } }