* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage install */ /** * make tool: menu * * load meta information for all applications * - add meta info to application names * - store serialized arrays of application menus * * @version 1.0.0 * @package wombatSite * @subpackage install */ class wbMaker_AdminMenu extends wbMaker { /** * information * * @access private * @var array $_info */ var $_info = array( 'maker' => 'AminMenu', 'state' => 'new', 'brief' => 'Collect menu-information from application meta information', 'msg' => '' ); /** * location of cache file * * relative to varDir * * @access private * @var string $_cacheFile */ var $_cacheFile = 'admin/menu/%s.ser'; /** * list of applications found * * @access private * @var array $_apps */ var $_apps = array(); /** * admin config from current site * * @access private * @var array $_conf */ var $_config; /** * patConfiguration * * @access private * @var object $_conf */ var $_conf; /** * bring birth! * * @access public * @return boolean $result true on success */ function __construct() { // need a copy $this->_conf =& wbFactory::create( 'patConfiguration' ); $this->_conf->loadConfig( 'admin.xml' ); $this->_config = $this->_conf->getConfigValue(); $this->_conf->clearConfigValue(); } /** * php4 constructor wrapper * * @access public * @see __construct() */ function wbMaker_AdminMenu() { $this->__construct(); } /** * run... * * @access public * @return boolean true on success, false if any target has failed (or patError object on error!) */ function make() { $baseDir = wbFactory::getParam( 'baseDir' ); // cread directories $var = $baseDir . '/' . wbFactory::getParam( 'varDir' ); $cacheDir = explode( '/', $this->_cacheFile ); array_pop( $cacheDir ); for( $i = 0; $i < count( $cacheDir ); ++$i ) { $dir = implode( '/', array_slice( $cacheDir, 0, ($i + 1 ) ) ); if( !is_dir( $var . '/' . $dir ) ) { wbDebugger::addMsg( 'Make', 'Make new directory: "'. $var . '/' . $dir .'".', 'AdminMenu' ); if( !mkdir( $var . '/' . $dir, 0777 ) ) { return patErrorManager::raiseError( 'wbMaker:AdminMenu:4', 'Make failed', 'Could not create new directory; "' . $var . '/' . $dir . '"!' ); } } } $appInfo = array(); $appMenu = array(); // crawl through menu foreach( $this->_config['menu'] as $menu ) { $found = false; $configDir = $baseDir . '/conf'; $configFile = '/admin/app/' . $menu['app'] . '.xml'; if( file_exists( $configDir . $configFile ) ) { $this->_conf->setConfigDir( $baseDir . '/conf' ); $found = true; } else { $configDir = wbFactory::getParam( 'systemDir' ) . '/' . wbFactory::getParam( 'adminDir' ) . '/conf'; $configFile = '/app/' . $menu['app'] . '.xml'; if( file_exists( $configDir . $configFile ) ) { $this->_conf->setConfigDir( $configDir ); $found = true; } } if( !$found ) { continue; } $this->_conf->loadConfig( $configFile ); $info = $this->_conf->getConfigValue(); $appName = $info['app']['name']; $appMenu[$appName] = array(); if( isset( $info['app']['menu'] ) ) { $appMenu[$appName] = $info['app']['menu']; } for( $i = 0; $i < count( $appMenu[$appName] ); ++$i ) { $appMenu[$appName][$i]['app'] = $appName . '/' . $appMenu[$appName][$i]['name']; } $appInfo[$appName] = array( 'title' => $info['app']['title'], 'brief' => $info['app']['brief'] ); array_push( $this->_apps, $appName ); $this->_conf->clearConfigValue(); } /* // start config reader $configDir = wbFactory::getParam( 'systemDir' ) . '/' . wbFactory::getParam( 'adminDir' ) . '/conf'; $this->_conf->setConfigDir( $configDir ); // load all application definitions $dh = dir( $configDir . '/app' ); if( !$dh ) { return patErrorManager::raiseError( 'wbMaker:AdminMenu:1', 'Make failed', 'Could not open configuration folder: "' . $configDir . '/app"!' ); } $appInfo = array(); $appMenu = array(); // load all files while( false !== ( $entry = $dh->read() ) ) { if( $entry[0] == '.' ) { continue; } if( is_dir( $configDir . '/app/' . $entry ) ) { continue; } $this->_conf->loadConfig( '/app/' . $entry ); $info = $this->_conf->getConfigValue(); $appName = $info['app']['name']; $appMenu[$appName] = array(); if( isset( $info['app']['menu'] ) ) { $appMenu[$appName] = $info['app']['menu']; } for( $i = 0; $i < count( $appMenu[$appName] ); ++$i ) { $appMenu[$appName][$i]['app'] = $appName . '/' . $appMenu[$appName][$i]['name']; } $appInfo[$appName] = array( 'title' => $info['app']['title'], 'brief' => $info['app']['brief'] ); array_push( $this->_apps, $appName ); $this->_conf->clearConfigValue(); } */ // cache all $cacheFile = wbFactory::getParam( 'baseDir' ) . '/' . wbFactory::getParam( 'varDir' ) . '/' . $this->_cacheFile; // save app info $ser = serialize( $appInfo ); $file = sprintf( $cacheFile, 'info' ); $fp = fopen( $file, 'w' ); if( !$fp ) { return patErrorManager::raiseError( 'wbMaker:AdminMenu:2', 'Saving menu cache failed', 'Could not open "'. $file .'" for writing!' ); } fwrite( $fp, $ser ); fclose( $fp ); chmod( $file, 0666 ); wbDebugger::addMsg( 'Make', 'Save info file: "'. $file .'".', 'AdminMenu' ); // save app menu $ser = serialize( $appMenu ); $file = sprintf( $cacheFile, 'menu' ); $fp = fopen( $file, 'w' ); if( !$fp ) { return patErrorManager::raiseError( 'wbMaker:AdminMenu:3', 'Saving menu cache failed', 'Could not open "'. $file .'" for writing!' ); } fwrite( $fp, $ser ); fclose( $fp ); @chmod( $file, 0666 ); wbDebugger::addMsg( 'Make', 'Save menu file: "'. $file .'".', 'AdminMenu' ); $this->_info['state'] = 'made'; $this->_info['msg'] = 'Cached admin menu of "'. implode( '", "', $this->_apps ) .'"!'; return true; } } ?>