* @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_Page extends wbFormDatasource { /** * default values of used attributes * @access private * @var array $_atts */ var $_atts = array( 'type' => 'pages', ); /** * template base directory * @access private * @var string $_tmplDir */ var $_confDir = ''; /** * patConfiguration object * @access private * @var string $_conf */ var $_conf; /** * implement this method * * @access private * @param integer $id * @return boolean $result true on success * @see */ function getValues() { $this->_confDir = wbFactory::getParam( 'baseDir' ) . '/' . wbFactory::getParam( 'configDir' ); $values = array( array( 'label' => _('... select a source page'), 'value' => '' ) ); $this->_conf =& wbFactory::create( 'patConfiguration' ); $this->_conf->setConfigDir( $this->_confDir ); switch( $this->_atts['type'] ) { case 'standard': $folder = 'pagesStandard'; break; default: $folder = 'pages'; break; } $this->_addPages( $folder, '', $values ); $this->_conf->clearConfigValue(); return $values; } /** * add templates from directory * * recursive * * @access private * @param string $base working directory * @param string $dir * @param array $values result values * @return boolean $result true on success * @see */ function _addPages( $base, $dir, &$values ) { if( !is_dir( $this->_confDir . '/' . $base . '/' . $dir ) ) { wbDebugger::addMsg( 'FormDS', 'Could not open directory: ' . $this->_confDir . '/' . $base . '/' . $dir, 'Pages' ); return false; } $d = dir( $this->_confDir . '/' . $base . '/' . $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->_confDir . '/'. $base .'/' . $dir . $entry ) ) { $this->_addPages( $base, $dir . $entry, $values ); continue; } // see whether it is a template file $page = explode( '.', $entry ); $ext = array_pop( $page ); // skip unknown extensions if( $ext != 'xml' ) { continue; } $page = implode( '.', $page ); // load page confiuration to extract title $this->_conf->loadConfig( $base . '/' . $dir . $page . '.xml' ); $conf = $this->_conf->getConfigValue( 'page' ); array_push( $values, array( 'value' => $dir . $page, 'label' => $dir . $conf['title'] ) ); } $d->close(); return true; } } ?>