* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage formDatasource */ /** * form datasource which finds all static templates * * @version 0.1 * @package wombatSite * @subpackage formDatasource */ class wbFormDatasource_StaticTemplate extends wbFormDatasource { /** * default values of used attributes * @access private * @var array $_atts */ var $_atts = array( ); /** * template base directory * @access private * @var string $_tmplDir */ var $_tmplDir = ''; /** * implement this method * * @access private * @param integer $id * @return boolean $result true on success * @see */ function getValues() { $this->_tmplDir = wbFactory::getParam( 'baseDir' ) . '/templates/static'; $values = array( array( 'label' => _('... select a static HTML template'), 'value' => '' ) ); $this->_addTemplates( '', $values ); return $values; } /** * add templates from directory * * recursive * * @access private * @param string $dir * @return boolean $result true on success * @see */ function _addTemplates( $dir, &$values ) { if( !is_dir( $this->_tmplDir . '/' . $dir ) ) { wbDebugger::addMsg( 'FormDS', 'Could not open directory: ' . $this->_tmplDir . '/' . $dir, 'StaticTemplate' ); return false; } $d = dir( $this->_tmplDir . '/' . $dir ); // append slash :-( if( !empty( $dir ) ) { $dir .= '/'; } // read dir while( ( $entry = $d->read() ) !== false ) { // skip hidden files if( $entry[0] == '.' ) { continue; } if( is_dir( $this->_tmplDir . '/' . $dir . $entry ) ) { $this->_addTemplates( $dir . $entry, $values ); continue; } // see whether it is a template file $tmpl = explode( '.', $entry ); $ext = array_pop( $tmpl ); // skip unknown extensions if( $ext != 'tmpl' ) { continue; } $tmpl = implode( '.', $tmpl ); array_push( $values, array( 'value' => $dir . $tmpl, 'label' => $dir . $tmpl ) ); } $d->close(); return true; } } ?>