* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage extension */ /** * base class for all modules * * @version 1.0.0 * @package wombatSite * @subpackage extension */ class wbModule { /** * name of this page * @access protected * @var string $_page */ var $_page = null; /** * name of this part * @access protected * @var string $_part */ var $_part = null; /** * basic directory * @access protected * @var string $_baseDir */ var $_baseDir = null; /** * request variables * @access protected * @var array $_request */ var $_request = array(); /** * page parameter * @access protected * @var array $_params */ var $_params = array( 'tmpldir' => '.' ); /** * default values for request variables * @access protected * @var array $_requestDefaults * @see $_request */ var $_requestDefaults = array(); /** * patTemplate object * @access protected * @var object $_tmpl */ var $_tmpl = null; /** * empty constructor! * * @access public * @return boolean $result true on success */ function __construct() { } /** * empty constructor! * * @access public * @see __construct() */ function wbModule() { $this->__construct(); } /** * inform the module about the page and part * * @access public * @param string @page name of the page * @param string @page name of the part * @return boolean $result true on success */ function setContext( $page, $part ) { $this->_page = $page; $this->_part = $part; return true; } /** * set root directory * * @access public * @param string @dir * @return boolean $result true on success */ function setRoot( $dir ) { $this->_baseDir = $dir; return true; } /** * set request variables * * @access public * @param array $request * @return boolean $result true on success */ function setRequest( &$request ) { $this->_request =& $request; foreach( $this->_requestDefaults as $key => $value ) { if( !isset( $this->_request[$key] ) ) { $this->_request[$key] = $value; } } return true; } /** * set additional page paramameter * * @access private * @param array $params associative list of parameter * @return boolean $result true on success */ function setParams( $params ) { foreach( $params as $key => $value ) { $this->_params[$key] = $value; } return true; } /** * set additional page paramameter * * @access protected * @param array $params associative list of parameter * @return boolean $result true on success */ function getParam( $name ) { if( isset( $this->_params[$name] ) ) { return $this->_params[$name]; } return NULL; } /** * check whether parameter are required * * @access protected * @param array $params associative list of parameter * @return boolean $result true on success or patError on failure */ function _checkRequiredParams( $params ) { foreach( $params as $p ) { if( !isset( $this->_params[$p] ) ) { return patErrorManager::raiseWarning( 'wbModule:1', 'Parameter is missing', 'Configuration error - parameter "'.$p.'" is required!' ); } if( empty( $this->_params[$p] ) ) { return patErrorManager::raiseWarning( 'wbModule:2', 'Parameter is empty', 'Configuration error - parameter "'.$p.'" is empty!' ); } } return true; } /** * checkReload * * @access protected * @return boolean $result true on reload */ function _checkReload() { $sess =& wbFactory::singleton( 'patSession' ); // create checksum from request vars $req = $this->_request; ksort( $req ); $req = serialize( $req ); $newChecksum = md5( $req ); // get saved checksum $checksum = $sess->get( 'wbModule_reload' ); if( $newChecksum == $checksum ) { return true; } $sess->set( 'wbModule_reload', $newChecksum ); return false; } /** * load templates * - wrapper for patTemplate-readTemplateFromInput() * * @access protected * @param string $name name of template file, without trailing '.tmpl' * @return boolean $result true on success */ function _loadTemplates( $name ) { if( !$this->_tmpl ) { $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); } $this->_tmpl->readTemplatesFromInput( $this->_params['tmpldir'] . '/' . $name . '.tmpl' ); return true; } } ?>