Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a template to render the slide repository page

  • Loading branch information...
commit acc1de41b417b42a390c22d42cab5876abd9dda6 1 parent 8cf6b06
@Seldaek authored
View
1  README.mdown
@@ -48,6 +48,7 @@ Changelog
- Auto-sizing to the browser dimensions
- Added page up, page down support for prev/next slide, and home/end to go to the begining or end of presentaiton
- Animations are going the right way now when using overview/direct input and going backwards
+ - Added a template to render the slide repository page
- JS Alerts are now cleared when changing slide, but stay visible longer
- Fixed bug preventing "0" to be used to switch to slides
View
5 src/config.dist.php
@@ -1,4 +1,7 @@
<?php
// directory where the slide decks are placed (*.html is scanned)
-$dir = dirname(__FILE__);
+$dir = dirname(__FILE__);
+
+// the php template that will render the base repository page
+$repositoryTemplate = 'repo.php';
View
45 src/index.php
@@ -13,6 +13,7 @@
// init
$dir = dirname(__FILE__).'/';
+$repositoryTemplate = 'repo.php';
if (file_exists($dir.'config.php')) {
include $dir.'config.php';
$dir = rtrim($dir, '/').'/';
@@ -22,14 +23,11 @@
$file = $dir . (isset($_GET['file']) ? basename($_GET['file']) : 'index.html');
// list slide decks if none is not found
-if (!file_exists($file) || !is_file($file)) {
- echo '<h1>This is a Slippy Repository</h1><p>You can find the source for this application on <a href="http://github.com/Seldaek/slippy">github</a>, and browse the available slide decks in the list below.</p>';
- echo '<form action="" method="GET"><select name="file">';
- foreach(array_reverse(glob($dir.'*.html')) as $file) {
- $file = htmlentities(basename($file));
- echo '<option value="'.$file.'">'.$file.'</option>';
- }
- echo '</select><input type="submit" value="Start" /></form>';
+if (!file_exists($file) || !is_file($file) || !is_readable($file)) {
+ $decks = array_reverse(glob($dir.'*.html'));
+ $decks = fetchDecksData($decks);
+
+ include $repositoryTemplate;
die;
}
@@ -45,4 +43,35 @@ function slippy_recode($match) {
$whitespace = preg_replace('#^\r?\n?([ \t]*).*#s', '$1', $match[2]);
$output = preg_replace('/^'.preg_quote($whitespace, '/').'/m', '', $match[2]);
return $match[1] . htmlspecialchars($output) . $match[3];
+}
+
+/**
+ * Fetches the data of each deck file passed to it
+ */
+function fetchDecksData($decks)
+{
+ foreach ($decks as $idx => $file) {
+ $decks[$idx] = array(
+ 'file' => $file,
+ 'filename' => basename($file, '.html'),
+ );
+ $content = file_get_contents($file);
+ $content = preg_replace('#</head>.*#s', '</head>', $content) . '</html>';
+ if ($content = simplexml_load_string($content)) {
+ foreach ($content->head->meta as $meta) {
+ if (!$meta->attributes()->name) {
+ continue;
+ }
+ $name = $meta->attributes()->name->__toString();
+ if (in_array($name, array('venue', 'date', 'author', 'email'))) {
+ $decks[$idx][$name] = $meta->attributes()->content->__toString();
+ }
+ }
+ $decks[$idx]['topic'] = $content->head->title->__toString();
+ }
+ if (!isset($decks[$idx]['topic']) || !$decks[$idx]['topic']) {
+ $decks[$idx]['topic'] = $decks[$idx]['filename'];
+ }
+ }
+ return $decks;
}
View
33 src/repo.php
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Slippy Slides Repository</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <style type="text/css">
+ body {
+ font: 12px Arial, sans-serif;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>This is a Slippy Repository</h1>
+
+ <p>You can find the sources for this application on <a href="http://github.com/Seldaek/slippy">github</a>, and browse the available slide decks in the list below.</p>
+
+ <ul>
+ <?php
+ foreach ($decks as $deck) {
+ echo '<li>';
+ echo '<h2><a href="?file='.htmlspecialchars(urlencode(basename($deck['file']))).'">'.$deck['topic'].'</a></h2>';
+ if (isset($deck['date'])) {
+ echo $deck['date'];
+ }
+ if (isset($deck['venue'])) {
+ echo ' @ '.$deck['venue'];
+ }
+ echo '</li>';
+ }
+ ?>
+ </ul>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.