$type), null); } else if (is_array($adminPageQuery) && count($adminPageQuery) <= $filterParams) { $emptyParams = $filterParams - count($adminPageQuery); if ($emptyParams > 0) { $adminPageQuery = array_merge($adminPageQuery, array_fill(0, $emptyParams, null)); } } else { throw new Qs_Exception('Wrong "adminPageQuery"'); } if (!$fullAlias) { $params = $adminPageQuery; $params[] = 'fullAlias'; $fullAlias = call_user_func_array('Qs_SiteMap::findFirst', $params); } $link['fullAlias'] = $fullAlias; if (!empty($link['urlParams'])) { $link['fullAlias'] .= '?' . http_build_query($link['urlParams']); } } if (!isset($link['alias'])) { $link['alias'] = basename($link['fullAlias']); } $link['source'] = static::SOURCE_VIRTUAL; } return true; } public static function prepare(&$sitemap) { /** @var $virtualSitemap Zend_Config */ if (null === ($virtualSitemap = Qs_Application::getConfig('sitemap')->get('virtualSitemap'))) { return false; } $virtualSitemap = $virtualSitemap->toArray(); self::_prepareVirtual($virtualSitemap); foreach ($virtualSitemap as $item) { self::_prepareItem($sitemap, $item); } self::_callDynamicHandlers($sitemap); return true; } public static function _prepareItem(&$sitemap, &$item) { if (!isset($item['pageQuery'])) { $sitemap [] = $item; return true; } if (!self::_getSuMode()) { $item['pageQuery'][0]['system'] = 'n'; } 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']); } } return true; } protected static 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 static 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 static function _alias2PageSub($alias) { $parts = explode('/', $alias); $name = array_shift($parts); while (($alias = array_shift($parts))) { $name .= '[sub][' . $alias . ']'; } return $name . '[sub]'; } protected static function _getSuMode() { if (is_callable('App_Admin_Auth::getInstance')) { return App_Admin_Auth::getInstance()->getSuMode(); } return false; } }