* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage install */ /** * make tool: menu * * load menu.xml * add page data to menu items * save menu as serailized array to cache data * * @version 1.0.1 * @package wombatSite * @subpackage install */ class wbMaker_Menu extends wbMaker { /** * information * * @access private * @var array $_info */ var $_info = array( 'maker' => 'Menu', 'state' => 'new', 'brief' => 'Collect menu-information from menu- and page-files and cache it for easy access', 'msg' => '' ); /** * location of cache file * * relative to varDir * * @access private * @var string $_cacheFile */ var $_cacheFile = 'content/menu.ser'; /** * found pages * * @access private * @var array $_pages */ var $_pages = array(); /** * patConfiguration object * * @access private * @var array $_conf */ var $_conf; /** * configuration folder * * @access private * @var string $_confDir */ var $_confDir = 'conf'; /** * bring birth! * * @access public * @return boolean $result true on success */ function __construct() { $this->_conf =& wbFactory::singleton( 'patConfiguration' ); $this->_confDir = $this->_conf->getConfigDir(); } /** * php4 constructor wrapper * * @access public * @see __construct() */ function wbMaker_Menu() { $this->__construct(); } /** * run... * * @access public * @return boolean true on success, false if any target has failed (or patError object on error!) */ function make() { if( file_exists( $this->_confDir . '/menu.xml' ) ) { $menuFile = 'menu.xml'; } else { wbDebugger::addMsg( 'Make', '"menu.xml" was not found!', 'Menu' ); $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Requied menu configuration not found!'; return false; } $this->_conf->loadConfig( $menuFile ); $menu = $this->_conf->getConfigValue( 'menu' ); $res = $this->_addMeta2Menu( $menu ); if( patErrorManager::isError( $res ) ) { return $res; } if( !$res ) { $this->_info['msg'] = 'Could not transform menu configuration - check "menu.xml" and used pages!'; return false; } // save cache file $ser = serialize( $menu ); $cacheFile = wbFactory::getParam( 'baseDir' ) . '/' . wbFactory::getParam( 'varDir' ) . '/' . $this->_cacheFile; $fp = fopen( $cacheFile, 'w' ); if( !$fp ) { patErrorManager::raiseWarning( 'wbMaker:Menu:2', 'Saving menu cache failed', 'Could not open "'. $cacheFile .'" for writing!' ); $this->_info['msg'] = 'Could not store menu cache - check file permissions!'; return false; } fwrite( $fp, $ser ); fclose( $fp ); @chmod( $cacheFile, 0666 ); $this->_info['state'] = 'made'; $this->_info['msg'] = 'Cached '. count( $this->_pages ) .' menu items in: "'. $cacheFile.'"!'; return true; } /** * add meta data to menu * * recursive * * @access public * @param array $menu * @return boolean true on success */ function _addMeta2Menu( &$menu ) { for( $i = 0; $i < count( $menu ); ++$i ) { if( !file_exists( $this->_confDir . '/pages/' . $menu[$i]['page'] . '.xml' ) ) { patErrorManager::raiseWarning( 'wbMaker:Menu:1', 'Menu config is corrupt!', 'Could not found page-config for page "' . $menu[$i]['page'] . '"!' ); return false; } $this->_conf->loadConfig( '/pages/'. $menu[$i]['page'] . '.xml' ); $page = $this->_conf->getConfigValue( 'page' ); array_push( $this->_pages, $menu[$i]['page'] ); $menu[$i]['title'] = $menu[$i]['page']; if( isset( $page['title'] ) ) { $menu[$i]['title'] = $page['title']; } $menu[$i]['brief'] = $menu[$i]['title']; if( isset( $page['brief'] ) ) { $menu[$i]['brief'] = $page['brief']; } if( isset( $menu[$i]['menu'] ) && !empty( $menu[$i]['menu'] ) ) { $res = $this->_addMeta2Menu( $menu[$i]['menu'] ); if( patErrorManager::isError( $res ) ) { return false; } if( !$res ) { return false; } } } return true; } } ?>