2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-02-25 02:06:39 +01:00
|
|
|
* This should extend DropdownField
|
2007-07-19 12:40:05 +02:00
|
|
|
*/
|
|
|
|
class TemplateList extends DropdownField {
|
|
|
|
|
|
|
|
protected $templatePath;
|
|
|
|
|
|
|
|
function __construct( $name, $title, $value, $path, $form = null ) {
|
|
|
|
$this->templatePath = $path;
|
|
|
|
parent::__construct( $name, $title, $this->getTemplates(), $value, $form );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getTemplates() {
|
2008-02-25 02:06:39 +01:00
|
|
|
$templates = array( "" => "None" );
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
$absPath = Director::baseFolder();
|
|
|
|
if( $absPath{strlen($absPath)-1} != "/" )
|
|
|
|
$absPath .= "/";
|
|
|
|
|
|
|
|
$absPath .= $this->templatePath;
|
|
|
|
if(is_dir($absPath)) {
|
|
|
|
$templateDir = opendir( $absPath );
|
|
|
|
|
|
|
|
// read all files in the directory
|
|
|
|
while( ( $templateFile = readdir( $templateDir ) ) !== false ) {
|
|
|
|
// *.ss files are templates
|
|
|
|
if( preg_match( '/(.*)\.ss$/', $templateFile, $match ) )
|
|
|
|
$templates[$match[1]] = $match[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $templates;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setController( $controller ) {
|
|
|
|
$this->controller = $controller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|