From cbbd9b46e4f243345639294af7ea35d046f22b5a Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Sat, 23 Apr 2016 19:57:01 -0400 Subject: [PATCH] all in one php --- examples/index.php | 60 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/examples/index.php b/examples/index.php index 3c981e0..2fea75a 100755 --- a/examples/index.php +++ b/examples/index.php @@ -21,8 +21,50 @@ echo $Parsedown->text(file_get_contents('README'.$language.'.md')); - $dirs = array_filter(glob('../??/'), 'is_dir'); - foreach ($dirs as &$folder) { + if (empty($_GET)) { + // Load all the chapters + $dirs = array_filter(glob('../??/'), 'is_dir'); + foreach ($dirs as &$folder) { + $chp = ''; + preg_match("/\.\.\/(\d\d)\//", $folder, $matches); + if (count($matches) > 0) { + $chp = $matches[1]; + } + + if (file_exists($folder.'TITLE'.$language.'.md') and file_exists($folder.'SUMMARY'.$language.'.md')) { + echo ''; + echo $Parsedown->text(file_get_contents($folder.'TITLE'.$language.'.md')); + echo ''; + + if (file_exists($folder.'SUMMARY'.$language.'.md')) { + echo $Parsedown->text(file_get_contents($folder.'SUMMARY'.$language.'.md')); + } + + $shaders = array_reverse(glob($folder.'*.frag')); + $shadersTotal = min(count($shaders), 3); + + if ($shadersTotal > 0) { + echo '
'; + } + + if (file_exists($folder.'featured_examples.php') and file_exists('FEATURED'.$language.'.md')) { + include($folder.'featured_examples.php'); + } + + echo '

See more examples of this chapter

'; + } + } + } elseif ( !empty($_GET['chapter'])) { + $chp = $_GET['chapter']; + $folder = '../'.$chp.'/'; + if (file_exists($folder.'TITLE'.$language.'.md') and file_exists($folder.'SUMMARY'.$language.'.md')) { echo $Parsedown->text(file_get_contents($folder.'TITLE'.$language.'.md')); @@ -36,15 +78,12 @@ if ($shadersTotal > 0) { echo '
0) { - echo $matches[1].'/'.basename($shaders[$i], '.frag'); - if ($i != $shadersTotal-1) { - echo ','; - } + echo $chp.'/'.basename($shaders[$i], '.frag'); + if ($i != $shadersTotal-1) { + echo ','; } } - echo '" data-properties="clickRun:edior,hoverPreview:false,showAuthor:false,openFrameIcon:false">
'; + echo '" data-properties="clickRun:edior,showAuthor:false,openFrameIcon:false">'; } @@ -54,8 +93,7 @@ } } } - - + echo '