'index',
'$Module/$Class' => 'parsePage'
);
/**
* An array of files to ignore from the listing
*
* @var array
*/
static $ignored_files = array('.', '..', '.DS_Store', '.svn', '.git');
/**
* Documentation Home
*
* Displays a welcome message as well as links to the sapphire sections and the
* installed modules
*/
function index() {
$this->writeHeader();
$base = Director::baseURL();
// write the main content (sapphire) on the left
echo "
";
echo "
Sapphire
";
$this->generateNestedTree('sapphire');
echo "
";
echo "
";
$modules = scandir(BASE_PATH);
// generate a list of module documentation (not core)
if($modules) {
foreach($modules as $module) {
// skip sapphire since this is on the left
$ignored_modules = array('sapphire', 'assets', 'themes');
if(!in_array($module, $ignored_modules) && !in_array($module, self::$ignored_files) && is_dir(BASE_PATH .'/'. $module)) {
echo "
". $module ."
";
// see if docs folder is present
$subfolders = scandir(BASE_PATH .'/'. $module);
if($subfolders && in_array('doc', $subfolders)) {
$this->generateNestedTree($module);
}
else {
echo "
No Documentation For Module
";
}
echo "
";
}
}
}
// for each of the modules. Display them here
echo "
";
$this->writeFooter();
}
/**
* @todo - This is nasty, ripped out of DebugView.
*/
function writeHeader() {
echo '
' . htmlentities($_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI']) . '
";
echo '
';
$this->writeFooter();
}
/**
* Find a documentation page within a given module.
*
* @todo Currently this only works on pages - eg if you go /dev/docs/Forms/ it won't show the
* overall forms page
*
* @param String - Name of Module
* @param String - Name of doc page
*
* @return String|false - File path
*/
private function findPage($path, $name) {
// open docs folder
$handle = opendir($path);
if($handle) {
while (false !== ($file = readdir($handle))) {
if(!in_array($file, self::$ignored_files)) {
if(is_dir($path.$file)) {
// keep looking down the tree
return $this->findPage($path.$file, $name);
}
elseif(strtolower($file) == strtolower($name)) {
return $path .'/'. $file;
}
}
}
}
return false;
}
/**
* Generate a nested tree for a given folder via recursion
*
* @param String - module to generate
*/
private function generateNestedTree($module) {
$path = BASE_PATH . '/'. $module .'/doc/';
return (is_dir($path)) ? $this->recursivelyGenerateTree($path, $module) : false;
}
/**
* Recursive method to generate the tree
*
* @param String - folder to work through
* @param String - module we're working through
*/
private function recursivelyGenerateTree($path, $module) {
echo "
";
$handle = opendir($path);
if($handle) {
while (false !== ($file = readdir($handle))) {
if(!in_array($file, self::$ignored_files)) {
$newPath = $path.$file;
// if the file is a dir nest the pages
if(is_dir($newPath)) {
// if this has a number
echo "
";
}
/**
* Take a file name and generate a 'nice' title for it
*
* @todo find a nicer way of removing the numbers.
*
* @param String
* @return String
*/
private function formatStringForTitle($title) {
// remove numbers if used.
if(substr($title, 2, 1) == '-') $title = substr($title, 3);
// change - to spaces
$title = str_ireplace('-', ' ', $title);
return $title;
}
}