app) || !isset($config->app->virtualSitemap)) { return false; } $virtualSitemap = $config->app->virtualSitemap->toArray(); self::_prepareVirtual($virtualSitemap); foreach ($virtualSitemap as $item) { self::_prepareItem($sitemap, $item); } self::_callDynamicHandlers($sitemap); } public static function _prepareItem(&$sitemap, &$item) { if (!isset($item['pageQuery'])) { $sitemap [] = $item; return true; } if (false === ($pages = call_user_func_array('Qs_SiteMap::find', $item['pageQuery']))) { return true; } foreach ($pages as $page) { $name = self::_alias2PageSub($page['fullAlias']); if (isset($item['sub'])) { foreach ($item['sub'] as $subData) { if (isset($subData['targetPageQuery'])) { if (false !== ($targetPage = call_user_func_array('Qs_SiteMap::findFirst', $subData['targetPageQuery']))) { foreach (array('menuTitle', 'fullAlias', 'url', 'source') as $field) { if (array_key_exists($field, $targetPage) && !array_key_exists($field, $subData)) { $subData[$field] = $targetPage[$field]; } } } unset($subData['targetPageQuery']); } Qs_Array::set($sitemap, $name . '[' . $subData['fullAlias'] . ']', $subData); } } $name = self::_alias2PageRightSub($page['fullAlias']); if (isset($item['rightSub'])) { foreach ($item['rightSub'] as $subData) { Qs_Array::set($sitemap, $name . '[' . $subData['fullAlias'] . ']', $subData); } } if (isset($item['dynamicHandler'])) { $name = self::_alias2Page($page['fullAlias']); Qs_Array::set($sitemap, $name . '[dynamicHandler]', $item['dynamicHandler']); } } } protected function _callDynamicHandlers(&$sitemap) { foreach ($sitemap as &$item) { if (isset($item['dynamicHandler'])) { $class = array_shift($item['dynamicHandler']); $method = array_shift($item['dynamicHandler']); $arguments = array_merge(array($item), $item['dynamicHandler']); $obj = new $class(); $obj->$method($item); unset($class); } if (isset($item['sub'])) { self::_callDynamicHandlers($item['sub']); } } } protected function _alias2PageRightSub($alias) { $parts = explode('/', $alias); $name = array_shift($parts); while (($alias = array_shift($parts))) { $name .= '[sub][' . $alias . ']'; } return $name . '[rightSub]'; } protected function _alias2Page($alias) { $parts = explode('/', $alias); $name = array_shift($parts); while (($alias = array_shift($parts))) { $name .= '[sub][' . $alias . ']'; } return $name; } protected function _alias2PageSub($alias) { $parts = explode('/', $alias); $name = array_shift($parts); while (($alias = array_shift($parts))) { $name .= '[sub][' . $alias . ']'; } return $name . '[sub]'; } }