id if the example * * @author Stephan Schmidt * @package patTemplate * @subpackage Examples */ /** * needs the section configuration */ require_once 'index_sections.php'; if( !isset( $_GET['example'] ) ) die( 'No example selected.' ); $exampleId = $_GET['example']; $section = getExampleSection( $exampleId ); $example = getExample( $exampleId ); $exampleFile = $exampleId.'.php'; $nav = array( 'output' => 'Output', 'source' => 'PHP Source', 'templates' => 'Template source', 'dump' => 'Template Dump', ); /** * add tabs */ if( isset( $example['tabs'] ) ) { foreach( $example['tabs'] as $tabId => $tabData ) { $nav[$tabId] = $tabData['title']; } } ?> <?PHP echo $appName; ?> example
$tabData ) { switch( $tabData['type'] ) { case 'phpsource': echo ''; break; default: echo '
unknown content type '.$tabData['type'].'.
'; break; } } } ?> ' . ' ' . '  '; foreach( $nav as $navId => $navTitle ) { $html .= ''.$navTitle.'' . ' '; } $html .= '  ' . ' ' . ''; echo $html; } /** * get the example section * * @access public * @param string example id * @return string section title */ function getExampleSection( $id ) { global $sections; foreach( $sections as $title => $spec ) { if( strncmp( $spec['basename'], $id, strlen( $spec['basename'] ) ) === 0 ) return $title; } return false; } /** * get the example section * * @access public * @param string example id * @return string section title */ function getExample( $id ) { global $sections; foreach( $sections as $title => $spec ) { if( strncmp( $spec['basename'], $id, strlen( $spec['basename'] ) ) !== 0 ) continue; foreach( $spec['pages'] as $name => $data ) { if( $id != $spec['basename'].$name ) continue; if( !isset( $data['templates'] ) ) { $data['templates'] = array( $id.'.tmpl' ); } return $data; } } return false; } /** * Display a template * * @access public */ function displayTemplate( $file, $namespace = 'patTemplate', $customTags = array() ) { $tags = array( 'tmpl' => 'tmplTag', 'sub' => 'subTag', 'link' => 'linkTag', 'var' => 'varTag', 'comment' => 'commentTag', ); $tags = array_merge( $customTags, $tags ); $tmpl = implode( '', file( 'templates/'.$file ) ); $tmpl = str_replace( "\t", ' ', $tmpl ); $tmpl = htmlspecialchars( $tmpl ); $tmpl = str_replace( ' ', ' ', $tmpl ); $tmpl = nl2br( $tmpl ); foreach( $tags as $tag => $class ) { $tmpl = preg_replace( '/(<\/?'.$namespace.':'.$tag.'.*>)/Ui', '\1', $tmpl ); $tmpl = str_replace( $namespace.':'.$tag, '##namespace##:'.$tag, $tmpl ); } $tmpl = preg_replace( '/(<\/?'.$namespace.':.*>)/Ui', '\1', $tmpl ); $tmpl = str_replace( '##namespace##', $namespace, $tmpl ); $tmpl = preg_replace( '/(<!--.*-->)/msU', '\1', $tmpl ); echo '
'; echo 'Source of templates/'.$file.''; echo $tmpl; echo '
'; } ?>