* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage factory */ /** * creator class * * implement specialized create function. * * @version 1.3.0 */ class wbFactory_patForms { /** * call counter * @var int */ private static $count = 0; /** * special creator for Image manager * * @static * @access private * @param array $params mixed parameter to modify the creation process * @return object $obj reference to the created object * @see create() */ public function &create( &$params ) { $baseDir = wbFactory::getParam( 'baseDir' ); if( !self::$count ) { $incDirs = array( $baseDir, wbFactory::getParam( 'systemDir' ) ); foreach( $incDirs as $incDir ) { // configure include dir $moduleDir = $incDir . '/' . wbFactory::getParam( 'includeDir' ) . '/patExtension/Forms'; patForms::addModuleBaseDir( $moduleDir ); } // configure gettext domain $sess = patSession::singleton(); $lang = 'C'; if( $sess->has( 'wb:lang' ) ) { $lang = $sess->get( 'wb:lang' ); $lang = $lang['lang']; } patForms::setLocale( $lang, $baseDir . '/var/lang' ); // set some static properties patForms::setDefaultEncoding( 'utf-8' ); } ++self::$count; $sess =& wbFactory::singleton( 'patSession' ); $baseDir = $baseDir . '/templates'; if( isset( $params['base_dir'] ) ) { $baseDir = $params['base_dir']; } // make sure patTemplate is setup if( isset( $params['tmpl'] ) ) { $tmpl =& $params['tmpl']; } else { $tmpl =& wbFactory::singleton( 'patTemplate' ); } $tmpl->readTemplatesFromInput( 'formErrors.tmpl' ); $formParams = array( 'id' => 'form', 'name' => 'form', 'accept-charset' => 'utf-8', 'enctype' => 'multipart/form-data' ); if( isset( $params['elements'] ) ) { $obj = patForms::createForm( $params['elements'], $formParams ); } else { if( !isset( $params['template'] ) ) { $params['template'] = 'form'; } $obj = self::StartFormFromTemplate( $baseDir, $tmpl, $params ); } // configure native language support if( $sess->has( 'wb:lang' ) ) { $lang = $sess->get( 'wb:lang' ); $obj->setLocale( $lang['form'] ); patForms::setStaticProperty( 'locale', $lang['form'] ); } // apply attribute filter $filter =& patForms::createAttributeFilter( 'Gettext' ); $obj->applyAttributeFilter( $filter ); return $obj; } /** * use template parser to create form * * @static * @access private * @return object $obj reference to the created object */ function &StartFormFromTemplate( $baseDir, &$tmpl, &$params ) { wbFactory::includeClass( 'patForms_Parser' ); patForms_Parser::setStaticProperty( 'tmpl', $tmpl ); patForms_Parser::setNamespace( 'patForms' ); patForms_Parser::setPlaceHolder( '%s' ); patForms_Parser::setCacheDir( wbFactory::getParam( 'baseDir' ) . '/' . wbFactory::getParam( 'varDir' ) . '/cache/forms' ); patForms_Parser::setBaseDir( $baseDir ); // use datasources or switch on cache if( isset( $params['datasource'] ) && $params['datasource'] ) { $formDs =& wbFactory::singleton( 'wbFormDatasource' ); $formDs->load( explode( ',', $params['datasource'] ) ); patForms_Parser::addNamespace( 'wb', $formDs ); } $tmplDir = ''; if( isset( $params['template_dir'] ) ) { $tmplDir = $params['template_dir']; } else if( is_callable( array( $this, 'getTemplateDir' ) ) ) { $tmplDir = $this->getTemplateDir(); wbDebugger::addMsg( 'Deprecated', 'using getTemplateDir is deprecated!', 'tmpldir' ); } // resolv destination :-/ $desPrefix = array(); // in systemDir? $sys = wbFactory::getParam( 'systemDir' ); if( substr( $baseDir, 0, strlen( $sys ) ) == $sys ) { $rest = explode( '/', substr( $baseDir, strlen( $sys ) ) ); $varDir = 'var'; } // in baseDir else { $rest = explode( '/', substr( $baseDir, strlen( wbFactory::getParam( 'baseDir' ) ) ) ); $varDir = wbFactory::getParam( 'varDir' ); } // find relative path for( $i = 0; $i < count( $rest ); ++$i ) { if( empty( $rest[$i] ) ) { continue; } array_push( $desPrefix, '..' ); } $path = explode( '/', $tmplDir ); array_push( $path, $params['template'] ); $src = implode( '/', $path ) .'.ftmpl'; $des = implode( '/', $desPrefix ) . '/' . $varDir . '/cache/forms/' . implode( '_', $path ) . '.tmpl'; /* $placeholder = '%s'; patForms_Parser::setStaticProperty( 'placeholder', $placeholder ); */ $obj =& patForms_Parser::createFormFromTemplate( 'patTemplateRenderer', $src, $des ); return $obj; } } ?>